Loading...
Searching...
No Matches
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
17
18namespace CubbyFlow
19{
28template <size_t N>
30{
31 public:
34
52 const Vector<double, N>& origin);
53
55 ~GridSystemData() override = default;
56
59
62
65
68
86 const Vector<double, N>& origin);
87
101
104
107
110
125 size_t AddScalarData(const std::shared_ptr<ScalarGridBuilder<N>>& builder,
126 double initialVal = 0.0);
127
143 const std::shared_ptr<VectorGridBuilder<N>>& builder,
145
161 const std::shared_ptr<ScalarGridBuilder<N>>& builder,
162 double initialVal = 0.0);
163
179 const std::shared_ptr<VectorGridBuilder<N>>& builder,
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
227
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
273using GridSystemData2Ptr = std::shared_ptr<GridSystemData2>;
274
276using GridSystemData3Ptr = std::shared_ptr<GridSystemData3>;
277} // namespace CubbyFlow
278
279#endif
N-D grid system data.
Definition GridSystemData.hpp:30
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.
Vector< double, N > Origin() const
Returns the origin of the grid.
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.
GridSystemData(const GridSystemData &other)
Copy constructor.
void Serialize(std::vector< uint8_t > *buffer) const override
Serialize the data to the given buffer.
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.
GridSystemData & operator=(GridSystemData &&other) noexcept
Move assignment operator.
void Deserialize(const std::vector< uint8_t > &buffer) override
Serialize the data from the given buffer.
size_t NumberOfAdvectableVectorData() const
Returns the number of advectable vector data.
GridSystemData()
Constructs empty grid system.
size_t NumberOfAdvectableScalarData() const
Returns the number of advectable scalar data.
size_t VelocityIndex() const
Returns the index of the velocity field.
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.
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.
Vector< size_t, N > Resolution() const
Returns the resolution of the grid.
Vector< double, N > GridSpacing() const
Return the grid spacing.
const std::shared_ptr< VectorGrid< N > > & AdvectableVectorDataAt(size_t idx) const
Returns the advectable vector data at given index.
size_t NumberOfVectorData() const
Returns the number of non-advectable vector data.
GridSystemData(const Vector< size_t, N > &resolution, const Vector< double, N > &gridSpacing, const Vector< double, N > &origin)
Constructs a grid system with given resolution, grid spacing and origin.
GridSystemData & operator=(const GridSystemData &other)
Copy assignment operator.
BoundingBox< double, N > GetBoundingBox() const
Returns the bounding box of the grid.
GridSystemData(GridSystemData &&other) noexcept
Move constructor.
const std::shared_ptr< VectorGrid< N > > & VectorDataAt(size_t idx) const
Returns the non-advectable vector data at given index.
const std::shared_ptr< FaceCenteredGrid< N > > & Velocity() const
Returns the velocity field.
size_t NumberOfScalarData() const
Returns the number of non-advectable scalar data.
~GridSystemData() override=default
Default virtual destructor.
const std::shared_ptr< ScalarGrid< N > > & ScalarDataAt(size_t idx) const
Returns the non-advectable scalar data at given index.
const std::shared_ptr< ScalarGrid< N > > & AdvectableScalarDataAt(size_t idx) const
Returns the advectable scalar data at given index.
Definition Matrix.hpp:30
Abstract base class for any serializable class.
Definition Serialization.hpp:22
Definition pybind11Utils.hpp:21
std::shared_ptr< GridSystemData2 > GridSystemData2Ptr
Shared pointer type of GridSystemData2.
Definition GridSystemData.hpp:273
std::shared_ptr< GridSystemData3 > GridSystemData3Ptr
Shared pointer type of GridSystemData3.
Definition GridSystemData.hpp:276
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738