SPH
Public Member Functions | List of all members
DerivativeTemplate< TDerived > Class Template Reference

Helper template for derivatives that define both the symmetrized and asymmetric variant. More...

#include <DerivativeHelpers.h>

Inheritance diagram for DerivativeTemplate< TDerived >:
ISymmetricDerivative IDerivative Polymorphic

Public Member Functions

 DerivativeTemplate (const RunSettings &settings, const Flags< DerivativeFlag > flags=EMPTY_FLAGS)
 
virtual void create (Accumulated &results) override final
 Emplace all needed buffers into shared storage. More...
 
virtual void initialize (const Storage &input, Accumulated &results) override final
 Initialize derivative before iterating over neighbours. More...
 
virtual bool equals (const IDerivative &other) const override final
 Returns true if this derivative is equal to the given derivative. More...
 
virtual void evalNeighs (const Size idx, ArrayView< const Size > neighs, ArrayView< const Vector > grads) override
 Compute derivatives of given particle. More...
 
virtual void evalSymmetric (const Size idx, ArrayView< const Size > neighs, ArrayView< const Vector > grads) override
 Compute a part of derivatives from interaction of particle pairs. More...
 
- Public Member Functions inherited from ISymmetricDerivative
virtual DerivativePhase phase () const final
 Symmetric derivatives are always in EVALUATION phase. More...
 
- Public Member Functions inherited from Polymorphic
virtual ~Polymorphic ()
 

Detailed Description

template<typename TDerived>
class DerivativeTemplate< TDerived >

Helper template for derivatives that define both the symmetrized and asymmetric variant.

This class template is mainly used to reduce the boilerplate code. It allows to easily implement the ISymmetricDerivative interface by defining a single function; the derived class must implement eval templated member function, taking the indices of the particles and the gradient as arguments. The template parameter is a bool, where false means asymmetric evaluation (only the first particle should be modified), and true means symmetric evaluation. The loop over the real neighbours (whether all neighbours or just undamaged particles is specified by the flags passed in the constructor) is automatically performed by DerivativeTemplate and does not have to be re-implemented by the derived classes.

Derived class must also implement functions additionalCreate and additionalInitialize. These functions have the same signatures are their virtual counterparts in IDerivative, they are used to initialize additional ArrayViews and other parameters specific for the derived class, without the need to override the virtual function and manually call the function of a parent (which is why the functions are marked as final).

Note
It is mandatory to implement the additional* function, even if the implementation is empty, so that it is ensured the correct function is called and avoid subtle bugs if the "overriding" function is misspelled.

Definition at line 40 of file DerivativeHelpers.h.

Constructor & Destructor Documentation

◆ DerivativeTemplate()

template<typename TDerived >
DerivativeTemplate< TDerived >::DerivativeTemplate ( const RunSettings settings,
const Flags< DerivativeFlag flags = EMPTY_FLAGS 
)
inlineexplicit

Definition at line 49 of file DerivativeHelpers.h.

Member Function Documentation

◆ create()

template<typename TDerived >
virtual void DerivativeTemplate< TDerived >::create ( Accumulated results)
inlinefinaloverridevirtual

Emplace all needed buffers into shared storage.

Called only once at the beginning of the run.

Implements IDerivative.

Definition at line 63 of file DerivativeHelpers.h.

◆ equals()

template<typename TDerived >
virtual bool DerivativeTemplate< TDerived >::equals ( const IDerivative other) const
inlinefinaloverridevirtual

Returns true if this derivative is equal to the given derivative.

This is always false if the derivative is a different type, but a derivative may also have an inner state and result in different value, even if the type is the same. This function is only used to check that we do not try to add two derivatives of the same type, but with different internal state.

Reimplemented from IDerivative.

Definition at line 85 of file DerivativeHelpers.h.

◆ evalNeighs()

template<typename TDerived >
virtual void DerivativeTemplate< TDerived >::evalNeighs ( const Size  idx,
ArrayView< const Size neighs,
ArrayView< const Vector grads 
)
inlineoverridevirtual

Compute derivatives of given particle.

Derivatives are computed by summing up pair-wise interaction between the given particle and its neighbours. Derivatives of the neighbours should not be modified by the function. Note that the given particle is NOT included in its own neighbours.

Parameters
idxIndex of the first interacting particle.
neighsArray containing all neighbours of idx-th particle.
gradsComputed gradients of the SPH kernel for each particle pair.

Implements IDerivative.

Definition at line 93 of file DerivativeHelpers.h.

◆ evalSymmetric()

template<typename TDerived >
virtual void DerivativeTemplate< TDerived >::evalSymmetric ( const Size  idx,
ArrayView< const Size neighs,
ArrayView< const Vector grads 
)
inlineoverridevirtual

Compute a part of derivatives from interaction of particle pairs.

The function computes derivatives of the given particle as well as all of its neighbours. Each particle pair is visited only once when evaluating the derivatives. Note that it computes only a part of the total sum, the rest of the sum is computed when executing the function for neighbouring particles. The derivatives are completed only after all particles have been processed.

Implementation must be consistent with evalNeighs, both must evaluate to the same derivative values. To ensure the derivative is internally consistent, consider using DerivativeTemplate helper class.

Parameters
idxIndex of first interacting particle.
neighsArray of some neighbours of idx-th particle. May be empty.
gradsComputed gradients of the SPH kernel for each particle pair.

Implements ISymmetricDerivative.

Definition at line 109 of file DerivativeHelpers.h.

◆ initialize()

template<typename TDerived >
virtual void DerivativeTemplate< TDerived >::initialize ( const Storage input,
Accumulated results 
)
inlinefinaloverridevirtual

Initialize derivative before iterating over neighbours.

All pointers and arrayviews used to access storage quantities must be initialized in this function, as they may have been invalidated.

Parameters
inputStorage containing all the input quantities from which derivatives are computed. This storage is shared for all threads.
resultsThread-local storage where the computed derivatives are saved.

Implements IDerivative.

Definition at line 67 of file DerivativeHelpers.h.


The documentation for this class was generated from the following file: