Jet  v1.3.3
collocated_vector_grid2.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_COLLOCATED_VECTOR_GRID2_H_
8 #define INCLUDE_JET_COLLOCATED_VECTOR_GRID2_H_
9 
10 #include <jet/array2.h>
11 #include <jet/array_samplers2.h>
12 #include <jet/vector_grid2.h>
13 #include <vector>
14 
15 namespace jet {
16 
19  public:
22 
25 
27  virtual Size2 dataSize() const = 0;
28 
35  virtual Vector2D dataOrigin() const = 0;
36 
38  const Vector2D& operator()(size_t i, size_t j) const;
39 
41  Vector2D& operator()(size_t i, size_t j);
42 
44  double divergenceAtDataPoint(size_t i, size_t j) const;
45 
47  double curlAtDataPoint(size_t i, size_t j) const;
48 
51 
54 
57 
66  const std::function<void(size_t, size_t)>& func) const;
67 
78  const std::function<void(size_t, size_t)>& func) const;
79 
80  // VectorField2 implementations
81 
83  Vector2D sample(const Vector2D& x) const override;
84 
86  double divergence(const Vector2D& x) const override;
87 
89  double curl(const Vector2D& x) const override;
90 
97  std::function<Vector2D(const Vector2D&)> sampler() const override;
98 
99  protected:
102 
105 
107  void getData(std::vector<double>* data) const override;
108 
110  void setData(const std::vector<double>& data) override;
111 
112  private:
113  Array2<Vector2D> _data;
115  std::function<Vector2D(const Vector2D&)> _sampler;
116 
117  void onResize(
118  const Size2& resolution,
119  const Vector2D& gridSpacing,
120  const Vector2D& origin,
121  const Vector2D& initialValue) final;
122 
123  void resetSampler();
124 };
125 
127 typedef std::shared_ptr<CollocatedVectorGrid2> CollocatedVectorGrid2Ptr;
128 
129 } // namespace jet
130 
131 #endif // INCLUDE_JET_COLLOCATED_VECTOR_GRID2_H_
jet::CollocatedVectorGrid2::setCollocatedVectorGrid
void setCollocatedVectorGrid(const CollocatedVectorGrid2 &other)
Sets the data storage and predefined samplers with given grid.
jet::CollocatedVectorGrid2::dataAccessor
VectorDataAccessor dataAccessor()
Returns the read-write data array accessor.
array2.h
jet::Grid2::origin
const Vector2D & origin() const
Returns the grid origin.
jet::Vector2D
Vector2< double > Vector2D
Double-type 2D vector.
Definition: vector2.h:340
jet::CollocatedVectorGrid2::setData
void setData(const std::vector< double > &data) override
Sets the data from a continuous linear array.
jet::CollocatedVectorGrid2::~CollocatedVectorGrid2
virtual ~CollocatedVectorGrid2()
Default destructor.
jet::CollocatedVectorGrid2::dataPosition
DataPositionFunc dataPosition() const
Returns the function that maps data point to its position.
jet::CollocatedVectorGrid2::dataSize
virtual Size2 dataSize() const =0
Returns the actual data point size.
jet::CollocatedVectorGrid2::forEachDataPointIndex
void forEachDataPointIndex(const std::function< void(size_t, size_t)> &func) const
Invokes the given function func for each data point.
jet::CollocatedVectorGrid2::divergenceAtDataPoint
double divergenceAtDataPoint(size_t i, size_t j) const
Returns divergence at data point location.
jet::Grid2::DataPositionFunc
std::function< Vector2D(size_t, size_t)> DataPositionFunc
Function type for mapping data index to actual position.
Definition: grid2.h:33
jet::Array< T, 2 >
2-D array class.
Definition: array2.h:42
jet::CollocatedVectorGrid2Ptr
std::shared_ptr< CollocatedVectorGrid2 > CollocatedVectorGrid2Ptr
Shared pointer for the CollocatedVectorGrid2 type.
Definition: collocated_vector_grid2.h:127
jet::CollocatedVectorGrid2::dataOrigin
virtual Vector2D dataOrigin() const =0
Returns data position for the grid point at (0, 0).
jet::VectorGrid2
Abstract base class for 2-D vector grid structure.
Definition: vector_grid2.h:21
jet::LinearArraySampler< T, R, 2 >
2-D linear array sampler class.
Definition: array_samplers2.h:77
jet
Definition: advection_solver2.h:18
jet::ConstArrayAccessor< T, 2 >
2-D read-only array accessor class.
Definition: array_accessor2.h:261
jet::CollocatedVectorGrid2::operator()
const Vector2D & operator()(size_t i, size_t j) const
Returns the grid data at given data point.
jet::CollocatedVectorGrid2::curl
double curl(const Vector2D &x) const override
Returns curl at given position x.
jet::Vector< T, 2 >
2-D vector class.
Definition: vector2.h:24
jet::CollocatedVectorGrid2
Abstract base class for 2-D collocated vector grid structure.
Definition: collocated_vector_grid2.h:18
jet::CollocatedVectorGrid2::CollocatedVectorGrid2
CollocatedVectorGrid2()
Constructs an empty grid.
jet::CollocatedVectorGrid2::swapCollocatedVectorGrid
void swapCollocatedVectorGrid(CollocatedVectorGrid2 *other)
Swaps the data storage and predefined samplers with given grid.
jet::Size2
2-D size class.
Definition: size2.h:19
jet::CollocatedVectorGrid2::getData
void getData(std::vector< double > *data) const override
Fetches the data into a continuous linear array.
jet::ArrayAccessor< T, 2 >
2-D array accessor class.
Definition: array_accessor2.h:31
jet::CollocatedVectorGrid2::sampler
std::function< Vector2D(const Vector2D &)> sampler() const override
Returns the sampler function.
vector_grid2.h
jet::CollocatedVectorGrid2::curlAtDataPoint
double curlAtDataPoint(size_t i, size_t j) const
Returns curl at data point location.
jet::CollocatedVectorGrid2::constDataAccessor
ConstVectorDataAccessor constDataAccessor() const
Returns the read-only data array accessor.
array_samplers2.h
jet::Grid2::resolution
const Size2 & resolution() const
Returns the grid resolution.
jet::CollocatedVectorGrid2::divergence
double divergence(const Vector2D &x) const override
Returns divergence at given position x.
jet::CollocatedVectorGrid2::operator()
Vector2D & operator()(size_t i, size_t j)
Returns the grid data at given data point.
jet::Grid2::gridSpacing
const Vector2D & gridSpacing() const
Returns the grid spacing.
jet::CollocatedVectorGrid2::sample
Vector2D sample(const Vector2D &x) const override
Returns sampled value at given position x.
jet::CollocatedVectorGrid2::parallelForEachDataPointIndex
void parallelForEachDataPointIndex(const std::function< void(size_t, size_t)> &func) const
Invokes the given function func for each data point parallelly.