CellCenteredVectorGrid.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_VECTOR_GRID_HPP
12 #define CUBBYFLOW_CELL_CENTERED_VECTOR_GRID_HPP
13 
15 
16 namespace CubbyFlow
17 {
26 template <size_t N>
28 {
29  public:
31 
32  class Builder;
33 
40 
42  CellCenteredVectorGrid() = default;
43 
47  const Vector<size_t, N>& resolution,
48  const Vector<double, N>& gridSpacing =
50  const Vector<double, N>& origin = Vector<double, N>{},
51  const Vector<double, N>& initialValue = Vector<double, N>{});
52 
54  ~CellCenteredVectorGrid() override = default;
55 
58 
61 
64 
67 
69  [[nodiscard]] Vector<size_t, N> DataSize() const override;
70 
74  [[nodiscard]] Vector<double, N> DataOrigin() const override;
75 
82  void Swap(Grid<N>* other) override;
83 
85  void Set(const CellCenteredVectorGrid& other);
86 
88  void Fill(const Vector<double, N>& value,
89  ExecutionPolicy policy = ExecutionPolicy::Parallel) override;
90 
92  void Fill(
93  const std::function<Vector<double, N>(const Vector<double, N>&)>& func,
94  ExecutionPolicy policy = ExecutionPolicy::Parallel) override;
95 
97  [[nodiscard]] std::shared_ptr<VectorGrid<N>> Clone() const override;
98 
100  static Builder GetBuilder();
101 
102  protected:
105 };
106 
109 
112 
114 using CellCenteredVectorGrid2Ptr = std::shared_ptr<CellCenteredVectorGrid2>;
115 
117 using CellCenteredVectorGrid3Ptr = std::shared_ptr<CellCenteredVectorGrid3>;
118 
122 template <size_t N>
124 {
125  public:
127  Builder& WithResolution(const Vector<size_t, N>& resolution);
128 
130  Builder& WithGridSpacing(const Vector<double, N>& gridSpacing);
131 
133  Builder& WithOrigin(const Vector<double, N>& gridOrigin);
134 
136  Builder& WithInitialValue(const Vector<double, N>& initialVal);
137 
139  CellCenteredVectorGrid Build() const;
140 
142  std::shared_ptr<CellCenteredVectorGrid> MakeShared() const;
143 
149  [[nodiscard]] std::shared_ptr<VectorGrid<N>> Build(
150  const Vector<size_t, N>& resolution,
151  const Vector<double, N>& gridSpacing,
152  const Vector<double, N>& gridOrigin,
153  const Vector<double, N>& initialVal) const override;
154 
155  private:
158  Vector<double, N> m_gridOrigin;
159  Vector<double, N> m_initialVal;
160 };
161 } // namespace CubbyFlow
162 
163 #endif
#define CUBBYFLOW_GRID_TYPE_NAME(DerivedClassName, N)
Definition: Grid.hpp:195
std::shared_ptr< CellCenteredVectorGrid2 > CellCenteredVectorGrid2Ptr
Shared pointer for the CellCenteredVectorGrid2 type.
Definition: CellCenteredVectorGrid.hpp:114
Vector< size_t, N > DataSize() const override
Returns the actual data point size.
~CellCenteredVectorGrid() override=default
Default virtual destructor.
std::shared_ptr< CellCenteredVectorGrid3 > CellCenteredVectorGrid3Ptr
Shared pointer for the CellCenteredVectorGrid3 type.
Definition: CellCenteredVectorGrid.hpp:117
void Fill(const Vector< double, N > &value, ExecutionPolicy policy=ExecutionPolicy::Parallel) override
Fills the grid with given value.
Abstract base class for N-D cartesian grid structure.
Definition: Grid.hpp:58
Front-end to create CellCenteredVectorGrid objects step by step.
Definition: CellCenteredVectorGrid.hpp:123
CellCenteredVectorGrid()=default
Constructs zero-sized grid.
Abstract base class for N-D vector grid builder.
Definition: VectorGrid.hpp:117
Definition: Matrix.hpp:27
std::shared_ptr< VectorGrid< N > > Clone() const override
Returns the copy of the grid instance.
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
Vector< double, N > DataOrigin() const override
void Swap(Grid< N > *other) override
Swaps the contents with the given other grid.
N-D Cell-centered vector grid structure.
Definition: CellCenteredVectorGrid.hpp:27
ExecutionPolicy
Execution policy tag.
Definition: Parallel.hpp:17
Abstract base class for N-D collocated vector grid structure.
Definition: CollocatedVectorGrid.hpp:22
static Builder GetBuilder()
Returns builder fox CellCenteredVectorGrid.
CellCenteredVectorGrid & operator=(const CellCenteredVectorGrid &other)
Copy assignment operator.
void Set(const CellCenteredVectorGrid &other)
Sets the contents with the given other grid.