CellCenteredScalarGrid.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_CELL_CENTERED_SCALAR_GRID_HPP
12 #define CUBBYFLOW_CELL_CENTERED_SCALAR_GRID_HPP
13 
14 #include <Core/Grid/ScalarGrid.hpp>
15 
16 namespace CubbyFlow
17 {
26 template <size_t N>
27 class CellCenteredScalarGrid final : public ScalarGrid<N>
28 {
29  public:
31 
32  class Builder;
33 
38 
40  CellCenteredScalarGrid() = default;
41 
45  const Vector<size_t, N>& resolution,
46  const Vector<double, N>& gridSpacing =
48  const Vector<double, N>& origin = Vector<double, N>{},
49  double initialValue = 0.0);
50 
52  ~CellCenteredScalarGrid() override = default;
53 
56 
59 
62 
65 
67  [[nodiscard]] Vector<size_t, N> DataSize() const override;
68 
72  [[nodiscard]] Vector<double, N> DataOrigin() const override;
73 
80  void Swap(Grid<N>* other) override;
81 
83  void Set(const CellCenteredScalarGrid& other);
84 
86  [[nodiscard]] std::shared_ptr<ScalarGrid<N>> Clone() const override;
87 
89  static Builder GetBuilder();
90 
91  protected:
94 };
95 
98 
101 
103 using CellCenteredScalarGrid2Ptr = std::shared_ptr<CellCenteredScalarGrid2>;
104 
106 using CellCenteredScalarGrid3Ptr = std::shared_ptr<CellCenteredScalarGrid3>;
107 
111 template <size_t N>
113 {
114  public:
116  Builder& WithResolution(const Vector<size_t, N>& resolution);
117 
119  Builder& WithGridSpacing(const Vector<double, N>& gridSpacing);
120 
122  Builder& WithOrigin(const Vector<double, N>& gridOrigin);
123 
125  Builder& WithInitialValue(double initialVal);
126 
128  CellCenteredScalarGrid<N> Build() const;
129 
131  std::shared_ptr<CellCenteredScalarGrid<N>> MakeShared() const;
132 
138  [[nodiscard]] std::shared_ptr<ScalarGrid<N>> Build(
139  const Vector<size_t, N>& resolution,
140  const Vector<double, N>& gridSpacing,
141  const Vector<double, N>& gridOrigin, double initialVal) const override;
142 
143  private:
146  Vector<double, N> m_gridOrigin = Vector<double, N>{};
147  double m_initialVal = 0.0;
148 };
149 } // namespace CubbyFlow
150 
151 #endif
#define CUBBYFLOW_GRID_TYPE_NAME(DerivedClassName, N)
Definition: Grid.hpp:195
std::shared_ptr< CellCenteredScalarGrid3 > CellCenteredScalarGrid3Ptr
Shared pointer for the CellCenteredScalarGrid3 type.
Definition: CellCenteredScalarGrid.hpp:106
void Set(const CellCenteredScalarGrid &other)
Sets the contents with the given other grid.
Abstract base class for N-D scalar grid structure.
Definition: ScalarGrid.hpp:24
Abstract base class for N-D cartesian grid structure.
Definition: Grid.hpp:58
Definition: Matrix.hpp:27
static std::enable_if_t< IsMatrixSizeStatic< Rows, Cols >), D > MakeConstant(ValueType val)
Makes a static matrix with constant entries.
Definition: MatrixDenseBase-Impl.hpp:152
Definition: pybind11Utils.hpp:20
~CellCenteredScalarGrid() override=default
Default virtual destructor.
static Builder GetBuilder()
Returns builder fox CellCenteredScalarGrid.
N-D Cell-centered scalar grid structure.
Definition: CellCenteredScalarGrid.hpp:27
Vector< double, N > DataOrigin() const override
std::shared_ptr< ScalarGrid< N > > Clone() const override
Returns the copy of the grid instance.
CellCenteredScalarGrid()=default
Constructs zero-sized grid.
Abstract base class for N-D scalar grid builder.
Definition: ScalarGrid.hpp:273
std::shared_ptr< CellCenteredScalarGrid2 > CellCenteredScalarGrid2Ptr
Shared pointer for the CellCenteredScalarGrid2 type.
Definition: CellCenteredScalarGrid.hpp:103
void Swap(Grid< N > *other) override
Swaps the contents with the given other grid.
CellCenteredScalarGrid & operator=(const CellCenteredScalarGrid &other)
Copy assignment operator.
Vector< size_t, N > DataSize() const override
Returns the actual data point size.
Front-end to create CellCenteredScalarGrid objects step by step.
Definition: CellCenteredScalarGrid.hpp:112