SPH
Public Member Functions | List of all members
Quantity Class Reference

Generic container for storing scalar, vector or tensor quantity and its derivatives. More...

#include <Quantity.h>

Inheritance diagram for Quantity:
Noncopyable

Public Member Functions

 Quantity ()=default
 Constructs an empty quantity. More...
 
template<typename TValue >
 Quantity (const OrderEnum order, const TValue &defaultValue, const Size size)
 Creates a quantity given number of particles and default value of the quantity. More...
 
template<typename TValue >
 Quantity (const OrderEnum order, Array< TValue > &&values)
 Creates a quantity from an array of values. More...
 
OrderEnum getOrderEnum () const
 Returns the order of the quantity. More...
 
ValueEnum getValueEnum () const
 Returns the value order of the quantity. More...
 
Quantity clone (const Flags< VisitorEnum > flags) const
 Clones all buffers contained by the quantity, or optionally only selected ones. More...
 
Quantity createZeros (const Size particleCnt) const
 Creates a new quantity with the same type and order as this one. More...
 
void swap (Quantity &other, const Flags< VisitorEnum > flags)
 Swap quantity (or selected part of it) with other quantity. More...
 
INLINE Size size () const
 Returns the size of the quantity (number of particles) More...
 
template<typename TValue >
INLINE Array< TValue > & getValue ()
 Returns a reference to array of quantity values. More...
 
template<typename TValue >
INLINE const Array< TValue > & getValue () const
 Returns a reference to array of quantity values, const version. More...
 
void setOrder (const OrderEnum order)
 
template<typename TValue >
INLINE Array< TValue > & getDt ()
 Returns a reference to array of first derivatives of quantity. More...
 
template<typename TValue >
INLINE const Array< TValue > & getDt () const
 Returns a reference to array of first derivatives of quantity, const version. More...
 
template<typename TValue >
INLINE Array< TValue > & getD2t ()
 Returns a reference to array of second derivatives of quantity. More...
 
template<typename TValue >
INLINE const Array< TValue > & getD2t () const
 Returns a reference to array of second derivatives of quantity, const version. More...
 
template<typename TValue >
StaticArray< Array< TValue > &, 3 > getAll ()
 Returns all buffers of given type stored in this quantity. More...
 
template<typename TValue >
StaticArray< const Array< TValue > &, 3 > getAll () const
 
template<typename TIndexSequence >
void clamp (const TIndexSequence &sequence, const Interval range)
 
- Public Member Functions inherited from Noncopyable
 Noncopyable ()=default
 
 Noncopyable (const Noncopyable &)=delete
 
 Noncopyable (Noncopyable &&)=default
 
Noncopyableoperator= (const Noncopyable &)=delete
 
Noncopyableoperator= (Noncopyable &&)=default
 

Detailed Description

Generic container for storing scalar, vector or tensor quantity and its derivatives.

Contains current values of the quantity and all derivatives. Any quantity can have first and second derivatives stored together with quantity values. There is currently no limitation of quatity types and their order, i.e. it is possible to have index quantities with derivatives.

As the quantity can have data of different types, there is no direct way to access the arrays stored within (like operator [] for Array class, for example). To access the stored values, use on of the following:

  1. Templated member function getValue, getDt, getD2t These functions return the reference to stored arrays, provided the template type matches the type of the stored quantity. This is checked by assert. Type of the quantity can be checked by getValueEnum
  2. Function getAll; returns all arrays (values and derivatives) stored in the holder if the template type matches the holder type. The value type is checked by assert.
  3. If the quantity is stored in Storage object (which is expected, there is no reason to keep Quantity outside of Storage), it is possible to enumerate quantity values using iterate function (and related function - iteratePair, iterateWithPositions, ...). Utilizing generic lambdas, we can access the values of buffers in a generic way, provided the called operators and functions are defiend for all types.

Quantity cannot be easily resized, in order to enforce validity of parent Storage; the number of quantity values should be the same for all quantities and equal to the number of particles in the storage. To add or remove particles, use Storage::resize function, rather than manually resizing all quantities. Even though this is possible to do (using mentioned iterate function), it is not recommended, as Storage keeps the number of particles as a state and it would invalidate the Storage.

Definition at line 200 of file Quantity.h.

Constructor & Destructor Documentation

◆ Quantity() [1/3]

Quantity::Quantity ( )
default

Constructs an empty quantity.

Calling any member functions will cause assert, quantity can be then created using move constructor. The default constructor allows using Quantity in STL containers.

◆ Quantity() [2/3]

template<typename TValue >
Quantity::Quantity ( const OrderEnum  order,
const TValue &  defaultValue,
const Size  size 
)
inline

Creates a quantity given number of particles and default value of the quantity.

All values are set to the default value. If the type is 1st-order or 2nd-order, derivatives arrays resized to the same size as the array of values and set to zero.

Parameters
defaultValueValue assigned to all particles.
sizeSize of the array, equal to the number of particles.

Definition at line 226 of file Quantity.h.

◆ Quantity() [3/3]

template<typename TValue >
Quantity::Quantity ( const OrderEnum  order,
Array< TValue > &&  values 
)
inline

Creates a quantity from an array of values.

All derivatives are set to zero.

Definition at line 233 of file Quantity.h.

Member Function Documentation

◆ clamp()

template<typename TIndexSequence >
void Quantity::clamp ( const TIndexSequence &  sequence,
const Interval  range 
)
inline

Iterates through the quantity values using given integer sequence and clamps the visited values to given range.

Todo:
clamp derivatives as well

Definition at line 351 of file Quantity.h.

◆ clone()

Quantity Quantity::clone ( const Flags< VisitorEnum flags) const
inline

Clones all buffers contained by the quantity, or optionally only selected ones.

Definition at line 252 of file Quantity.h.

◆ createZeros()

Quantity Quantity::createZeros ( const Size  particleCnt) const
inline

Creates a new quantity with the same type and order as this one.

It creates specified number of particles and initializes them to zeros.

Definition at line 259 of file Quantity.h.

◆ getAll() [1/2]

template<typename TValue >
StaticArray<Array<TValue>&, 3> Quantity::getAll ( )
inline

Returns all buffers of given type stored in this quantity.

If the quantity is of different type, an empty array is returned. Buffers in array are ordered such that quantity values is the first element (zero index), first derivative is the second element etc.

Definition at line 338 of file Quantity.h.

◆ getAll() [2/2]

template<typename TValue >
StaticArray<const Array<TValue>&, 3> Quantity::getAll ( ) const
inline

Definition at line 343 of file Quantity.h.

◆ getD2t() [1/2]

template<typename TValue >
INLINE Array<TValue>& Quantity::getD2t ( )
inline

Returns a reference to array of second derivatives of quantity.

The type of the quantity must match the provided type and the quantity must be 2st order, checked by assert. To check whether the type and order match, use getValueEnum() and getOrderEnum(), respectively.

Definition at line 323 of file Quantity.h.

◆ getD2t() [2/2]

template<typename TValue >
INLINE const Array<TValue>& Quantity::getD2t ( ) const
inline

Returns a reference to array of second derivatives of quantity, const version.

Definition at line 329 of file Quantity.h.

◆ getDt() [1/2]

template<typename TValue >
INLINE Array<TValue>& Quantity::getDt ( )
inline

Returns a reference to array of first derivatives of quantity.

The type of the quantity must match the provided type and the quantity must be (at least) 1st order, checked by assert. To check whether the type and order match, use getValueEnum() and getOrderEnum(), respectively.

Definition at line 307 of file Quantity.h.

◆ getDt() [2/2]

template<typename TValue >
INLINE const Array<TValue>& Quantity::getDt ( ) const
inline

Returns a reference to array of first derivatives of quantity, const version.

Definition at line 313 of file Quantity.h.

◆ getOrderEnum()

OrderEnum Quantity::getOrderEnum ( ) const
inline

Returns the order of the quantity.

Zero order quantities contain only quantity values, first-order quantities contain values and first derivatives, and so on. The order is used by timestepping algorithm to advance the quantity values in time.

Definition at line 241 of file Quantity.h.

◆ getValue() [1/2]

template<typename TValue >
INLINE Array<TValue>& Quantity::getValue ( )
inline

Returns a reference to array of quantity values.

The type of the quantity must match the provided type, checked by assert. To check whether the type of the quantity match, use getValueEnum().

Definition at line 287 of file Quantity.h.

◆ getValue() [2/2]

template<typename TValue >
INLINE const Array<TValue>& Quantity::getValue ( ) const
inline

Returns a reference to array of quantity values, const version.

Definition at line 293 of file Quantity.h.

◆ getValueEnum()

ValueEnum Quantity::getValueEnum ( ) const
inline

Returns the value order of the quantity.

Definition at line 246 of file Quantity.h.

◆ setOrder()

void Quantity::setOrder ( const OrderEnum  order)
inline

Definition at line 297 of file Quantity.h.

◆ size()

INLINE Size Quantity::size ( ) const
inline

Returns the size of the quantity (number of particles)

Definition at line 278 of file Quantity.h.

◆ swap()

void Quantity::swap ( Quantity other,
const Flags< VisitorEnum flags 
)
inline

Swap quantity (or selected part of it) with other quantity.

Swapping only part of quantity (only derivatives for example) can be useful for some timestepping algorithms, such as predictor-corrector.

Definition at line 269 of file Quantity.h.


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