GridSystemData.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_GRID_SYSTM_DATA_HPP
12 #define CUBBYFLOW_GRID_SYSTM_DATA_HPP
13 
15 #include <Core/Grid/ScalarGrid.hpp>
17 
18 namespace CubbyFlow
19 {
28 template <size_t N>
30 {
31  public:
34 
50  GridSystemData(const Vector<size_t, N>& resolution,
51  const Vector<double, N>& gridSpacing,
52  const Vector<double, N>& origin);
53 
55  ~GridSystemData() override = default;
56 
58  GridSystemData(const GridSystemData& other);
59 
61  GridSystemData(GridSystemData&& other) noexcept;
62 
65 
67  GridSystemData& operator=(GridSystemData&& other) noexcept;
68 
84  void Resize(const Vector<size_t, N>& resolution,
85  const Vector<double, N>& gridSpacing,
86  const Vector<double, N>& origin);
87 
100  [[nodiscard]] Vector<size_t, N> Resolution() const;
101 
103  [[nodiscard]] Vector<double, N> GridSpacing() const;
104 
106  [[nodiscard]] Vector<double, N> Origin() const;
107 
109  [[nodiscard]] BoundingBox<double, N> GetBoundingBox() const;
110 
125  size_t AddScalarData(const std::shared_ptr<ScalarGridBuilder<N>>& builder,
126  double initialVal = 0.0);
127 
142  size_t AddVectorData(
143  const std::shared_ptr<VectorGridBuilder<N>>& builder,
144  const Vector<double, N>& initialVal = Vector<double, N>{});
145 
161  const std::shared_ptr<ScalarGridBuilder<N>>& builder,
162  double initialVal = 0.0);
163 
179  const std::shared_ptr<VectorGridBuilder<N>>& builder,
180  const Vector<double, N>& initialVal = Vector<double, N>{});
181 
190  [[nodiscard]] const std::shared_ptr<FaceCenteredGrid<N>>& Velocity() const;
191 
201  [[nodiscard]] size_t VelocityIndex() const;
202 
204  [[nodiscard]] const std::shared_ptr<ScalarGrid<N>>& ScalarDataAt(
205  size_t idx) const;
206 
208  [[nodiscard]] const std::shared_ptr<VectorGrid<N>>& VectorDataAt(
209  size_t idx) const;
210 
212  [[nodiscard]] const std::shared_ptr<ScalarGrid<N>>& AdvectableScalarDataAt(
213  size_t idx) const;
214 
216  [[nodiscard]] const std::shared_ptr<VectorGrid<N>>& AdvectableVectorDataAt(
217  size_t idx) const;
218 
220  [[nodiscard]] size_t NumberOfScalarData() const;
221 
223  [[nodiscard]] size_t NumberOfVectorData() const;
224 
226  [[nodiscard]] size_t NumberOfAdvectableScalarData() const;
227 
229  [[nodiscard]] size_t NumberOfAdvectableVectorData() const;
230 
232  void Serialize(std::vector<uint8_t>* buffer) const override;
233 
235  void Deserialize(const std::vector<uint8_t>& buffer) override;
236 
237  private:
238  template <size_t M = N>
239  static std::enable_if_t<M == 2, void> Serialize(
240  const GridSystemData<2>& grid, std::vector<uint8_t>* buffer);
241 
242  template <size_t M = N>
243  static std::enable_if_t<M == 3, void> Serialize(
244  const GridSystemData<3>& grid, std::vector<uint8_t>* buffer);
245 
246  template <size_t M = N>
247  static std::enable_if_t<M == 2, void> Deserialize(
248  const std::vector<uint8_t>& buffer, GridSystemData<2>& grid);
249 
250  template <size_t M = N>
251  static std::enable_if_t<M == 3, void> Deserialize(
252  const std::vector<uint8_t>& buffer, GridSystemData<3>& grid);
253 
254  Vector<size_t, N> m_resolution;
255  Vector<double, N> m_gridSpacing;
256  Vector<double, N> m_origin;
257 
258  std::shared_ptr<FaceCenteredGrid<N>> m_velocity;
259  size_t m_velocityIdx = 0;
260  std::vector<std::shared_ptr<ScalarGrid<N>>> m_scalarDataList;
261  std::vector<std::shared_ptr<VectorGrid<N>>> m_vectorDataList;
262  std::vector<std::shared_ptr<ScalarGrid<N>>> m_advectableScalarDataList;
263  std::vector<std::shared_ptr<VectorGrid<N>>> m_advectableVectorDataList;
264 };
265 
268 
271 
273 using GridSystemData2Ptr = std::shared_ptr<GridSystemData2>;
274 
276 using GridSystemData3Ptr = std::shared_ptr<GridSystemData3>;
277 } // namespace CubbyFlow
278 
279 #endif
size_t NumberOfScalarData() const
Returns the number of non-advectable scalar data.
Abstract base class for any serializable class.
Definition: Serialization.hpp:21
N-D grid system data.
Definition: GridSystemData.hpp:29
void Deserialize(const std::vector< uint8_t > &buffer) override
Serialize the data from the given buffer.
size_t NumberOfVectorData() const
Returns the number of non-advectable vector data.
GridSystemData()
Constructs empty grid system.
~GridSystemData() override=default
Default virtual destructor.
size_t VelocityIndex() const
Returns the index of the velocity field.
const std::shared_ptr< VectorGrid< N > > & VectorDataAt(size_t idx) const
Returns the non-advectable vector data at given index.
std::shared_ptr< GridSystemData2 > GridSystemData2Ptr
Shared pointer type of GridSystemData2.
Definition: GridSystemData.hpp:273
size_t AddScalarData(const std::shared_ptr< ScalarGridBuilder< N >> &builder, double initialVal=0.0)
Adds a non-advectable scalar data grid by passing its builder and initial value.
Abstract base class for N-D vector grid builder.
Definition: VectorGrid.hpp:117
size_t AddVectorData(const std::shared_ptr< VectorGridBuilder< N >> &builder, const Vector< double, N > &initialVal=Vector< double, N >{})
Adds a non-advectable vector data grid by passing its builder and initial value.
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
size_t NumberOfAdvectableScalarData() const
Returns the number of advectable scalar data.
GridSystemData & operator=(const GridSystemData &other)
Copy assignment operator.
size_t AddAdvectableVectorData(const std::shared_ptr< VectorGridBuilder< N >> &builder, const Vector< double, N > &initialVal=Vector< double, N >{})
Adds an advectable vector data grid by passing its builder and initial value.
const std::shared_ptr< VectorGrid< N > > & AdvectableVectorDataAt(size_t idx) const
Returns the advectable vector data at given index.
Abstract base class for N-D scalar grid builder.
Definition: ScalarGrid.hpp:273
Vector< double, N > Origin() const
Returns the origin of the grid.
std::shared_ptr< GridSystemData3 > GridSystemData3Ptr
Shared pointer type of GridSystemData3.
Definition: GridSystemData.hpp:276
BoundingBox< double, N > GetBoundingBox() const
Returns the bounding box of the grid.
Vector< double, N > GridSpacing() const
Return the grid spacing.
void Serialize(std::vector< uint8_t > *buffer) const override
Serialize the data to the given buffer.
size_t AddAdvectableScalarData(const std::shared_ptr< ScalarGridBuilder< N >> &builder, double initialVal=0.0)
Adds an advectable scalar data grid by passing its builder and initial value.
const std::shared_ptr< FaceCenteredGrid< N > > & Velocity() const
Returns the velocity field.
size_t NumberOfAdvectableVectorData() const
Returns the number of advectable vector data.
const std::shared_ptr< ScalarGrid< N > > & AdvectableScalarDataAt(size_t idx) const
Returns the advectable scalar data at given index.
const std::shared_ptr< ScalarGrid< N > > & ScalarDataAt(size_t idx) const
Returns the non-advectable scalar data at given index.
Vector< size_t, N > Resolution() const
Returns the resolution of the grid.
void Resize(const Vector< size_t, N > &resolution, const Vector< double, N > &gridSpacing, const Vector< double, N > &origin)
Resizes the whole system with given resolution, grid spacing, and origin.