CubbyFlow::ScalarGrid< N > Class Template Referenceabstract

Abstract base class for N-D scalar grid structure. More...

#include <Core/Grid/ScalarGrid.hpp>

Inheritance diagram for CubbyFlow::ScalarGrid< N >:
CubbyFlow::ScalarField< N > CubbyFlow::Grid< N > CubbyFlow::Field< N > CubbyFlow::Serializable CubbyFlow::CellCenteredScalarGrid< N > CubbyFlow::VertexCenteredScalarGrid< N >

Public Types

using ScalarDataView = ArrayView< double, N >
 Read-write array view type. More...
 
using ConstScalarDataView = ArrayView< const double, N >
 Read-only array view type. More...
 

Public Member Functions

 ScalarGrid ()
 Constructs an empty grid. More...
 
 ~ScalarGrid () override=default
 Default virtual destructor. More...
 
 ScalarGrid (const ScalarGrid &other)
 Copy constructor. More...
 
 ScalarGrid (ScalarGrid &&other) noexcept
 Move constructor. More...
 
ScalarGridoperator= (const ScalarGrid &other)
 Copy assignment operator. More...
 
ScalarGridoperator= (ScalarGrid &&other) noexcept
 Move assignment operator. More...
 
virtual Vector< size_t, N > DataSize () const =0
 Returns the size of the grid data. More...
 
virtual Vector< double, N > DataOrigin () const =0
 Returns the origin of the grid data. More...
 
virtual std::shared_ptr< ScalarGridClone () const =0
 Returns the copy of the grid instance. More...
 
void Clear ()
 Clears the contents of the grid. More...
 
void Resize (const Vector< size_t, N > &resolution, const Vector< double, N > &gridSpacing=Vector< double, N >::MakeConstant(1), const Vector< double, N > &origin=Vector< double, N >{}, double initialValue=0.0)
 Resizes the grid using given parameters. More...
 
void Resize (const Vector< double, N > &gridSpacing, const Vector< double, N > &origin)
 Resizes the grid using given parameters. More...
 
const double & operator() (const Vector< size_t, N > &idx) const
 Returns the grid data at given data point. More...
 
double & operator() (const Vector< size_t, N > &idx)
 Returns the grid data at given data point. More...
 
template<typename... Indices>
const double & operator() (size_t i, Indices... indices) const
 Returns the grid data at given data point. More...
 
template<typename... Indices>
double & operator() (size_t i, Indices... indices)
 Returns the grid data at given data point. More...
 
Vector< double, N > GradientAtDataPoint (const Vector< size_t, N > &idx) const
 Returns the gradient vector at given data point. More...
 
template<typename... Indices>
Vector< double, N > GradientAtDataPoint (size_t i, Indices... indices) const
 Returns the gradient vector at given data point. More...
 
double LaplacianAtDataPoint (const Vector< size_t, N > &idx) const
 Returns the Laplacian at given data point. More...
 
template<typename... Indices>
double LaplacianAtDataPoint (size_t i, Indices... indices) const
 Returns the Laplacian at given data point. More...
 
ScalarDataView DataView ()
 Returns the read-write data array accessor. More...
 
ConstScalarDataView DataView () const
 Returns the read-only data array accessor. More...
 
GridDataPositionFunc< N > DataPosition () const
 Returns the function that maps data point to its position. More...
 
void Fill (double value, ExecutionPolicy policy=ExecutionPolicy::Parallel)
 Fills the grid with given value. More...
 
void Fill (const std::function< double(const Vector< double, N > &)> &func, ExecutionPolicy policy=ExecutionPolicy::Parallel)
 Fills the grid with given position-to-value mapping function. More...
 
void ForEachDataPointIndex (const std::function< void(const Vector< size_t, N > &)> &func) const
 Invokes the given function func for each data point. More...
 
template<size_t M = N>
std::enable_if_t< M==2, void > ForEachDataPointIndex (const std::function< void(size_t, size_t)> &func) const
 
template<size_t M = N>
std::enable_if_t< M==3, void > ForEachDataPointIndex (const std::function< void(size_t, size_t, size_t)> &func) const
 
void ParallelForEachDataPointIndex (const std::function< void(const Vector< size_t, N > &)> &func) const
 Invokes the given function func for each data point in parallel. More...
 
template<size_t M = N>
std::enable_if_t< M==2, void > ParallelForEachDataPointIndex (const std::function< void(size_t, size_t)> &func) const
 
template<size_t M = N>
std::enable_if_t< M==3, void > ParallelForEachDataPointIndex (const std::function< void(size_t, size_t, size_t)> &func) const
 
double Sample (const Vector< double, N > &x) const override
 Returns the sampled value at given position x. More...
 
std::function< double(const Vector< double, N > &)> Sampler () const override
 Returns the sampler function. More...
 
Vector< double, N > Gradient (const Vector< double, N > &x) const override
 Returns the gradient vector at given position x. More...
 
double Laplacian (const Vector< double, N > &x) const override
 Returns the Laplacian at given position x. More...
 
void Serialize (std::vector< uint8_t > *buffer) const override
 Serializes the grid instance to the output buffer. More...
 
void Deserialize (const std::vector< uint8_t > &buffer) override
 Deserializes the input buffer to the grid instance. More...
 
- Public Member Functions inherited from CubbyFlow::ScalarField< N >
 ScalarField ()=default
 Default constructor. More...
 
 ~ScalarField () override=default
 Default destructor. More...
 
 ScalarField (const ScalarField &)=default
 Default copy constructor. More...
 
 ScalarField (ScalarField &&) noexcept=default
 Default move constructor. More...
 
ScalarFieldoperator= (const ScalarField &)=default
 Default copy assignment operator. More...
 
ScalarFieldoperator= (ScalarField &&) noexcept=default
 Default move assignment operator. More...
 
- Public Member Functions inherited from CubbyFlow::Field< N >
 Field ()=default
 Default constructor. More...
 
virtual ~Field ()=default
 Default virtual destructor. More...
 
 Field (const Field &)=default
 Default copy constructor. More...
 
 Field (Field &&) noexcept=default
 Default move constructor. More...
 
Fieldoperator= (const Field &)=default
 Default copy assignment operator. More...
 
Fieldoperator= (Field &&) noexcept=default
 Default move assignment operator. More...
 
- Public Member Functions inherited from CubbyFlow::Grid< N >
 Grid ()=default
 Constructs an empty grid. More...
 
 ~Grid () override=default
 Default virtual destructor. More...
 
 Grid (const Grid &other)
 Copy constructor. More...
 
 Grid (Grid &&other) noexcept
 Move constructor. More...
 
Gridoperator= (const Grid &other)
 Copy assignment operator. More...
 
Gridoperator= (Grid &&other) noexcept
 Move assignment operator. More...
 
virtual std::string TypeName () const =0
 Returns the type name of derived grid. More...
 
const Vector< size_t, N > & Resolution () const
 Returns the grid resolution. More...
 
const Vector< double, N > & Origin () const
 Returns the grid origin. More...
 
const Vector< double, N > & GridSpacing () const
 Returns the grid spacing. More...
 
const BoundingBox< double, N > & GetBoundingBox () const
 Returns the bounding box of the grid. More...
 
GridDataPositionFunc< N > CellCenterPosition () const
 Returns the function that maps grid index to the cell-center position. More...
 
void ForEachCellIndex (const std::function< void(const Vector< size_t, N > &)> &func) const
 Invokes the given function func for each grid cell. More...
 
template<size_t M = N>
std::enable_if_t< M==2, void > ForEachCellIndex (const std::function< void(size_t, size_t)> &func) const
 
template<size_t M = N>
std::enable_if_t< M==3, void > ForEachCellIndex (const std::function< void(size_t, size_t, size_t)> &func) const
 
void ParallelForEachCellIndex (const std::function< void(const Vector< size_t, N > &)> &func) const
 Invokes the given function func for each grid cell in parallel. More...
 
template<size_t M = N>
std::enable_if_t< M==2, void > ParallelForEachCellIndex (const std::function< void(size_t, size_t)> &func) const
 
template<size_t M = N>
std::enable_if_t< M==3, void > ParallelForEachCellIndex (const std::function< void(size_t, size_t, size_t)> &func) const
 
bool HasSameShape (const Grid &other) const
 Returns true if resolution, grid-spacing and origin are same. More...
 
virtual void Swap (Grid *other)=0
 Swaps the data with other grid. More...
 
- Public Member Functions inherited from CubbyFlow::Serializable
 Serializable ()=default
 Default constructor. More...
 
 Serializable (const Serializable &)=default
 Default copy constructor. More...
 
 Serializable (Serializable &&) noexcept=default
 Default move constructor. More...
 
virtual ~Serializable ()=default
 Default virtual destructor. More...
 
Serializableoperator= (const Serializable &)=default
 Default copy assignment operator. More...
 
Serializableoperator= (Serializable &&) noexcept=default
 Default move assignment operator. More...
 

Protected Member Functions

void SwapScalarGrid (ScalarGrid *other)
 Swaps the data storage and predefined samplers with given grid. More...
 
void SetScalarGrid (const ScalarGrid &other)
 Sets the data storage and predefined samplers with given grid. More...
 
void GetData (Array1< double > &data) const override
 Fetches the data into a continuous linear array. More...
 
void SetData (const ConstArrayView1< double > &data) override
 Sets the data from a continuous linear array. More...
 
- Protected Member Functions inherited from CubbyFlow::Grid< N >
void SetSizeParameters (const Vector< size_t, N > &resolution, const Vector< double, N > &gridSpacing, const Vector< double, N > &origin)
 
void SwapGrid (Grid *other)
 Swaps the size parameters with given grid other. More...
 
void SetGrid (const Grid &other)
 Sets the size parameters with given grid other. More...
 

Detailed Description

template<size_t N>
class CubbyFlow::ScalarGrid< N >

Abstract base class for N-D scalar grid structure.

Member Typedef Documentation

◆ ConstScalarDataView

template<size_t N>
using CubbyFlow::ScalarGrid< N >::ConstScalarDataView = ArrayView<const double, N>

Read-only array view type.

◆ ScalarDataView

template<size_t N>
using CubbyFlow::ScalarGrid< N >::ScalarDataView = ArrayView<double, N>

Read-write array view type.

Constructor & Destructor Documentation

◆ ScalarGrid() [1/3]

template<size_t N>
CubbyFlow::ScalarGrid< N >::ScalarGrid ( )

Constructs an empty grid.

◆ ~ScalarGrid()

template<size_t N>
CubbyFlow::ScalarGrid< N >::~ScalarGrid ( )
overridedefault

Default virtual destructor.

◆ ScalarGrid() [2/3]

template<size_t N>
CubbyFlow::ScalarGrid< N >::ScalarGrid ( const ScalarGrid< N > &  other)

Copy constructor.

◆ ScalarGrid() [3/3]

template<size_t N>
CubbyFlow::ScalarGrid< N >::ScalarGrid ( ScalarGrid< N > &&  other)
noexcept

Move constructor.

Member Function Documentation

◆ Clear()

template<size_t N>
void CubbyFlow::ScalarGrid< N >::Clear ( )

Clears the contents of the grid.

◆ Clone()

template<size_t N>
virtual std::shared_ptr<ScalarGrid> CubbyFlow::ScalarGrid< N >::Clone ( ) const
pure virtual

Returns the copy of the grid instance.

Implemented in CubbyFlow::CellCenteredScalarGrid< N >, and CubbyFlow::VertexCenteredScalarGrid< N >.

◆ DataOrigin()

template<size_t N>
virtual Vector<double, N> CubbyFlow::ScalarGrid< N >::DataOrigin ( ) const
pure virtual

Returns the origin of the grid data.

This function returns data position for the grid point at (0, 0, ...). Note that this is different from origin() since origin() returns the lower corner point of the bounding box.

Implemented in CubbyFlow::VertexCenteredScalarGrid< N >, and CubbyFlow::CellCenteredScalarGrid< N >.

◆ DataPosition()

template<size_t N>
GridDataPositionFunc<N> CubbyFlow::ScalarGrid< N >::DataPosition ( ) const

Returns the function that maps data point to its position.

◆ DataSize()

template<size_t N>
virtual Vector<size_t, N> CubbyFlow::ScalarGrid< N >::DataSize ( ) const
pure virtual

Returns the size of the grid data.

This function returns the size of the grid data which is not necessarily equal to the grid resolution if the data is not stored at cell-center.

Implemented in CubbyFlow::VertexCenteredScalarGrid< N >, and CubbyFlow::CellCenteredScalarGrid< N >.

◆ DataView() [1/2]

template<size_t N>
ScalarDataView CubbyFlow::ScalarGrid< N >::DataView ( )

Returns the read-write data array accessor.

◆ DataView() [2/2]

template<size_t N>
ConstScalarDataView CubbyFlow::ScalarGrid< N >::DataView ( ) const

Returns the read-only data array accessor.

◆ Deserialize()

template<size_t N>
void CubbyFlow::ScalarGrid< N >::Deserialize ( const std::vector< uint8_t > &  buffer)
overridevirtual

Deserializes the input buffer to the grid instance.

Implements CubbyFlow::Serializable.

◆ Fill() [1/2]

template<size_t N>
void CubbyFlow::ScalarGrid< N >::Fill ( double  value,
ExecutionPolicy  policy = ExecutionPolicy::Parallel 
)

Fills the grid with given value.

◆ Fill() [2/2]

template<size_t N>
void CubbyFlow::ScalarGrid< N >::Fill ( const std::function< double(const Vector< double, N > &)> &  func,
ExecutionPolicy  policy = ExecutionPolicy::Parallel 
)

Fills the grid with given position-to-value mapping function.

◆ ForEachDataPointIndex() [1/3]

template<size_t N>
void CubbyFlow::ScalarGrid< N >::ForEachDataPointIndex ( const std::function< void(const Vector< size_t, N > &)> &  func) const

Invokes the given function func for each data point.

This function invokes the given function object func for each data point in serial manner. The input parameters are i, j, ... indices of a data point. The order of execution is i-first, j-next.

◆ ForEachDataPointIndex() [2/3]

template<size_t N>
template<size_t M = N>
std::enable_if_t<M == 2, void> CubbyFlow::ScalarGrid< N >::ForEachDataPointIndex ( const std::function< void(size_t, size_t)> &  func) const
inline

◆ ForEachDataPointIndex() [3/3]

template<size_t N>
template<size_t M = N>
std::enable_if_t<M == 3, void> CubbyFlow::ScalarGrid< N >::ForEachDataPointIndex ( const std::function< void(size_t, size_t, size_t)> &  func) const
inline

◆ GetData()

template<size_t N>
void CubbyFlow::ScalarGrid< N >::GetData ( Array1< double > &  data) const
overrideprotectedvirtual

Fetches the data into a continuous linear array.

Implements CubbyFlow::Grid< N >.

◆ Gradient()

template<size_t N>
Vector<double, N> CubbyFlow::ScalarGrid< N >::Gradient ( const Vector< double, N > &  x) const
overridevirtual

Returns the gradient vector at given position x.

Reimplemented from CubbyFlow::ScalarField< N >.

◆ GradientAtDataPoint() [1/2]

template<size_t N>
Vector<double, N> CubbyFlow::ScalarGrid< N >::GradientAtDataPoint ( const Vector< size_t, N > &  idx) const

Returns the gradient vector at given data point.

◆ GradientAtDataPoint() [2/2]

template<size_t N>
template<typename... Indices>
Vector<double, N> CubbyFlow::ScalarGrid< N >::GradientAtDataPoint ( size_t  i,
Indices...  indices 
) const
inline

Returns the gradient vector at given data point.

◆ Laplacian()

template<size_t N>
double CubbyFlow::ScalarGrid< N >::Laplacian ( const Vector< double, N > &  x) const
overridevirtual

Returns the Laplacian at given position x.

Reimplemented from CubbyFlow::ScalarField< N >.

◆ LaplacianAtDataPoint() [1/2]

template<size_t N>
double CubbyFlow::ScalarGrid< N >::LaplacianAtDataPoint ( const Vector< size_t, N > &  idx) const

Returns the Laplacian at given data point.

◆ LaplacianAtDataPoint() [2/2]

template<size_t N>
template<typename... Indices>
double CubbyFlow::ScalarGrid< N >::LaplacianAtDataPoint ( size_t  i,
Indices...  indices 
) const
inline

Returns the Laplacian at given data point.

◆ operator()() [1/4]

template<size_t N>
const double& CubbyFlow::ScalarGrid< N >::operator() ( const Vector< size_t, N > &  idx) const

Returns the grid data at given data point.

◆ operator()() [2/4]

template<size_t N>
double& CubbyFlow::ScalarGrid< N >::operator() ( const Vector< size_t, N > &  idx)

Returns the grid data at given data point.

◆ operator()() [3/4]

template<size_t N>
template<typename... Indices>
const double& CubbyFlow::ScalarGrid< N >::operator() ( size_t  i,
Indices...  indices 
) const
inline

Returns the grid data at given data point.

◆ operator()() [4/4]

template<size_t N>
template<typename... Indices>
double& CubbyFlow::ScalarGrid< N >::operator() ( size_t  i,
Indices...  indices 
)
inline

Returns the grid data at given data point.

◆ operator=() [1/2]

template<size_t N>
ScalarGrid& CubbyFlow::ScalarGrid< N >::operator= ( const ScalarGrid< N > &  other)

Copy assignment operator.

◆ operator=() [2/2]

template<size_t N>
ScalarGrid& CubbyFlow::ScalarGrid< N >::operator= ( ScalarGrid< N > &&  other)
noexcept

Move assignment operator.

◆ ParallelForEachDataPointIndex() [1/3]

template<size_t N>
void CubbyFlow::ScalarGrid< N >::ParallelForEachDataPointIndex ( const std::function< void(const Vector< size_t, N > &)> &  func) const

Invokes the given function func for each data point in parallel.

This function invokes the given function object func for each data point in parallel manner. The input parameters are i, j, ... indices of a data point. The order of execution can be arbitrary since it's multi-threaded.

◆ ParallelForEachDataPointIndex() [2/3]

template<size_t N>
template<size_t M = N>
std::enable_if_t<M == 2, void> CubbyFlow::ScalarGrid< N >::ParallelForEachDataPointIndex ( const std::function< void(size_t, size_t)> &  func) const
inline

◆ ParallelForEachDataPointIndex() [3/3]

template<size_t N>
template<size_t M = N>
std::enable_if_t<M == 3, void> CubbyFlow::ScalarGrid< N >::ParallelForEachDataPointIndex ( const std::function< void(size_t, size_t, size_t)> &  func) const
inline

◆ Resize() [1/2]

template<size_t N>
void CubbyFlow::ScalarGrid< N >::Resize ( const Vector< size_t, N > &  resolution,
const Vector< double, N > &  gridSpacing = Vector< double, N >::MakeConstant(1),
const Vector< double, N > &  origin = Vector< double, N >{},
double  initialValue = 0.0 
)

Resizes the grid using given parameters.

◆ Resize() [2/2]

template<size_t N>
void CubbyFlow::ScalarGrid< N >::Resize ( const Vector< double, N > &  gridSpacing,
const Vector< double, N > &  origin 
)

Resizes the grid using given parameters.

◆ Sample()

template<size_t N>
double CubbyFlow::ScalarGrid< N >::Sample ( const Vector< double, N > &  x) const
overridevirtual

Returns the sampled value at given position x.

This function returns the data sampled at arbitrary position x. The sampling function is linear.

Implements CubbyFlow::ScalarField< N >.

◆ Sampler()

template<size_t N>
std::function<double(const Vector<double, N>&)> CubbyFlow::ScalarGrid< N >::Sampler ( ) const
overridevirtual

Returns the sampler function.

This function returns the data sampler function object. The sampling function is linear.

Reimplemented from CubbyFlow::ScalarField< N >.

◆ Serialize()

template<size_t N>
void CubbyFlow::ScalarGrid< N >::Serialize ( std::vector< uint8_t > *  buffer) const
overridevirtual

Serializes the grid instance to the output buffer.

Implements CubbyFlow::Serializable.

◆ SetData()

template<size_t N>
void CubbyFlow::ScalarGrid< N >::SetData ( const ConstArrayView1< double > &  data)
overrideprotectedvirtual

Sets the data from a continuous linear array.

Implements CubbyFlow::Grid< N >.

◆ SetScalarGrid()

template<size_t N>
void CubbyFlow::ScalarGrid< N >::SetScalarGrid ( const ScalarGrid< N > &  other)
protected

Sets the data storage and predefined samplers with given grid.

◆ SwapScalarGrid()

template<size_t N>
void CubbyFlow::ScalarGrid< N >::SwapScalarGrid ( ScalarGrid< N > *  other)
protected

Swaps the data storage and predefined samplers with given grid.


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