CollocatedVectorGrid3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: CollocatedVectorGrid3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Abstract base class for 3-D collocated vector grid structure.
6 > Created Time: 2017/08/02
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_COLLOCATED_VECTOR_GRID3_H
10 #define CUBBYFLOW_COLLOCATED_VECTOR_GRID3_H
11 
12 #include <Core/Array/Array3.h>
14 #include <Core/Grid/VectorGrid3.h>
15 
16 namespace CubbyFlow
17 {
20  {
21  public:
24 
26  virtual ~CollocatedVectorGrid3();
27 
29  virtual Size3 GetDataSize() const = 0;
30 
37  virtual Vector3D GetDataOrigin() const = 0;
38 
40  const Vector3D& operator()(size_t i, size_t j, size_t k) const;
41 
43  Vector3D& operator()(size_t i, size_t j, size_t k);
44 
46  double DivergenceAtDataPoint(size_t i, size_t j, size_t k) const;
47 
49  Vector3D CurlAtDataPoint(size_t i, size_t j, size_t k) const;
50 
53 
56 
59 
67  void ForEachDataPointIndex(const std::function<void(size_t, size_t, size_t)>& func) const;
68 
77  void ParallelForEachDataPointIndex(const std::function<void(size_t, size_t, size_t)>& func) const;
78 
79  // VectorField3 implementations
81  Vector3D Sample(const Vector3D& x) const override;
82 
84  double Divergence(const Vector3D& x) const override;
85 
87  Vector3D Curl(const Vector3D& x) const override;
88 
95  std::function<Vector3D(const Vector3D&)> Sampler() const override;
96 
97  protected:
100 
103 
105  void GetData(std::vector<double>* data) const override;
106 
108  void SetData(const std::vector<double>& data) override;
109 
110  private:
111  Array3<Vector3D> m_data;
113  std::function<Vector3D(const Vector3D&)> m_sampler;
114 
115  void OnResize(
116  const Size3& resolution,
117  const Vector3D& gridSpacing,
118  const Vector3D& origin,
119  const Vector3D& initialValue) final;
120 
121  void ResetSampler();
122  };
123 
125  using CollocatedVectorGrid3Ptr = std::shared_ptr<CollocatedVectorGrid3>;
126 }
127 
128 #endif
3-D vector class.
Definition: Vector3.h:26
3-D array accessor class.
Definition: ArrayAccessor3.h:31
Abstract base class for 3-D collocated vector grid structure.
Definition: CollocatedVectorGrid3.h:19
std::function< Vector3D(size_t, size_t, size_t)> DataPositionFunc
Function type for mapping data index to actual position.
Definition: Grid3.h:34
3-D read-only array accessor class.
Definition: ArrayAccessor3.h:269
void ForEachDataPointIndex(const std::function< void(size_t, size_t, size_t)> &func) const
Invokes the given function func for each data point.
CollocatedVectorGrid3()
Constructs an empty grid.
const Vector3D & operator()(size_t i, size_t j, size_t k) const
Returns the grid data at given data point.
DataPositionFunc GetDataPosition() const
Returns the function that maps data point to its position.
Vector3D Curl(const Vector3D &x) const override
Returns curl at given position x.
void SetData(const std::vector< double > &data) override
Sets the data from a continuous linear array.
virtual Size3 GetDataSize() const =0
Returns the actual data point size.
ConstVectorDataAccessor GetConstDataAccessor() const
Returns the read-only data array accessor.
3-D point class.
Definition: Point3.h:26
std::shared_ptr< CollocatedVectorGrid3 > CollocatedVectorGrid3Ptr
Shared pointer for the CollocatedVectorGrid3 type.
Definition: CollocatedVectorGrid3.h:125
double DivergenceAtDataPoint(size_t i, size_t j, size_t k) const
Returns divergence at data point location.
Definition: pybind11Utils.h:24
double Divergence(const Vector3D &x) const override
Returns divergence at given position x.
Vector3D CurlAtDataPoint(size_t i, size_t j, size_t k) const
Returns curl at data point location.
Vector3D Sample(const Vector3D &x) const override
Returns sampled value at given position x.
void ParallelForEachDataPointIndex(const std::function< void(size_t, size_t, size_t)> &func) const
Invokes the given function func for each data point in parallel.
VectorDataAccessor GetDataAccessor()
Returns the read-write data array accessor.
virtual ~CollocatedVectorGrid3()
Default destructor.
3-D array class.
Definition: Array3.h:45
void GetData(std::vector< double > *data) const override
Fetches the data into a continuous linear array.
std::function< Vector3D(const Vector3D &)> Sampler() const override
Returns the sampler function.
void SwapCollocatedVectorGrid(CollocatedVectorGrid3 *other)
Swaps the data storage and predefined samplers with given grid.
Abstract base class for 3-D vector grid structure.
Definition: VectorGrid3.h:19
virtual Vector3D GetDataOrigin() const =0
Returns data position for the grid point at (0, 0, 0).
void SetCollocatedVectorGrid(const CollocatedVectorGrid3 &other)
Sets the data storage and predefined samplers with given grid.
3-D linear array sampler class.
Definition: ArraySamplers3.h:78