CollocatedVectorGrid2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: CollocatedVectorGrid2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Abstract base class for 2-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_GRID2_H
10 #define CUBBYFLOW_COLLOCATED_VECTOR_GRID2_H
11 
12 #include <Core/Array/Array2.h>
14 #include <Core/Grid/VectorGrid2.h>
15 
16 namespace CubbyFlow
17 {
20  {
21  public:
24 
26  virtual ~CollocatedVectorGrid2();
27 
29  virtual Size2 GetDataSize() const = 0;
30 
37  virtual Vector2D GetDataOrigin() const = 0;
38 
40  const Vector2D& operator()(size_t i, size_t j) const;
41 
43  Vector2D& operator()(size_t i, size_t j);
44 
46  double DivergenceAtDataPoint(size_t i, size_t j) const;
47 
49  double CurlAtDataPoint(size_t i, size_t j) const;
50 
53 
56 
59 
67  void ForEachDataPointIndex(const std::function<void(size_t, size_t)>& func) const;
68 
77  void ParallelForEachDataPointIndex(const std::function<void(size_t, size_t)>& func) const;
78 
79  // VectorField2 implementations
81  Vector2D Sample(const Vector2D& x) const override;
82 
84  double Divergence(const Vector2D& x) const override;
85 
87  double Curl(const Vector2D& x) const override;
88 
95  std::function<Vector2D(const Vector2D&)> 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  Array2<Vector2D> m_data;
113  std::function<Vector2D(const Vector2D&)> m_sampler;
114 
115  void OnResize(
116  const Size2& resolution,
117  const Vector2D& gridSpacing,
118  const Vector2D& origin,
119  const Vector2D& initialValue) final;
120 
121  void ResetSampler();
122  };
123 
125  using CollocatedVectorGrid2Ptr = std::shared_ptr<CollocatedVectorGrid2>;
126 }
127 
128 #endif
2-D read-only array accessor class.
Definition: ArrayAccessor2.h:261
void ForEachDataPointIndex(const std::function< void(size_t, size_t)> &func) const
Invokes the given function func for each data point.
void SetCollocatedVectorGrid(const CollocatedVectorGrid2 &other)
Sets the data storage and predefined samplers with given grid.
DataPositionFunc GetDataPosition() const
Returns the function that maps data point to its position.
Abstract base class for 2-D vector grid structure.
Definition: VectorGrid2.h:19
Vector2D Sample(const Vector2D &x) const override
Returns sampled value at given position x.
virtual Size2 GetDataSize() const =0
Returns the actual data point size.
Abstract base class for 2-D collocated vector grid structure.
Definition: CollocatedVectorGrid2.h:19
2-D point class.
Definition: Point2.h:25
void SetData(const std::vector< double > &data) override
Sets the data from a continuous linear array.
void ParallelForEachDataPointIndex(const std::function< void(size_t, size_t)> &func) const
Invokes the given function func for each data point in parallel.
void GetData(std::vector< double > *data) const override
Fetches the data into a continuous linear array.
2-D array accessor class.
Definition: ArrayAccessor2.h:31
CollocatedVectorGrid2()
Constructs an empty grid.
VectorDataAccessor GetDataAccessor()
Returns the read-write data array accessor.
void SwapCollocatedVectorGrid(CollocatedVectorGrid2 *other)
Swaps the data storage and predefined samplers with given grid.
Definition: pybind11Utils.h:24
const Vector2D & operator()(size_t i, size_t j) const
Returns the grid data at given data point.
double Divergence(const Vector2D &x) const override
Returns divergence at given position x.
double DivergenceAtDataPoint(size_t i, size_t j) const
Returns divergence at data point location.
std::function< Vector2D(const Vector2D &)> Sampler() const override
Returns the sampler function.
2-D vector class.
Definition: Vector2.h:26
ConstVectorDataAccessor GetConstDataAccessor() const
Returns the read-only data array accessor.
std::shared_ptr< CollocatedVectorGrid2 > CollocatedVectorGrid2Ptr
Shared pointer for the CollocatedVectorGrid2 type.
Definition: CollocatedVectorGrid2.h:125
2-D array class.
Definition: Array2.h:42
2-D linear array sampler class.
Definition: ArraySamplers2.h:78
double CurlAtDataPoint(size_t i, size_t j) const
Returns curl at data point location.
virtual ~CollocatedVectorGrid2()
Default destructor.
virtual Vector2D GetDataOrigin() const =0
Returns data position for the grid point at (0, 0).
std::function< Vector2D(size_t, size_t)> DataPositionFunc
Function type for mapping data index to actual position.
Definition: Grid2.h:34
double Curl(const Vector2D &x) const override
Returns curl at given position x.