SPH
|
Helper template for derivatives that define both the symmetrized and asymmetric variant. More...
#include <DerivativeHelpers.h>
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 () |
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).
Definition at line 40 of file DerivativeHelpers.h.
|
inlineexplicit |
Definition at line 49 of file DerivativeHelpers.h.
|
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.
|
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.
|
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.
idx | Index of the first interacting particle. |
neighs | Array containing all neighbours of idx-th particle. |
grads | Computed gradients of the SPH kernel for each particle pair. |
Implements IDerivative.
Definition at line 93 of file DerivativeHelpers.h.
|
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.
idx | Index of first interacting particle. |
neighs | Array of some neighbours of idx-th particle. May be empty. |
grads | Computed gradients of the SPH kernel for each particle pair. |
Implements ISymmetricDerivative.
Definition at line 109 of file DerivativeHelpers.h.
|
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.
input | Storage containing all the input quantities from which derivatives are computed. This storage is shared for all threads. |
results | Thread-local storage where the computed derivatives are saved. |
Implements IDerivative.
Definition at line 67 of file DerivativeHelpers.h.