GridBackwardEulerDiffusionSolver2.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_BACKWARD_EULER_DIFFUSION_SOLVER2_HPP
12 #define CUBBYFLOW_GRID_BACKWARD_EULER_DIFFUSION_SOLVER2_HPP
13 
16 
17 namespace CubbyFlow
18 {
31 {
32  public:
33  enum class BoundaryType
34  {
35  Dirichlet,
36  Neumann
37  };
38 
41  BoundaryType boundaryType = BoundaryType::Neumann);
42 
45  const GridBackwardEulerDiffusionSolver2&) = delete;
46 
49  GridBackwardEulerDiffusionSolver2&&) noexcept = delete;
50 
52  ~GridBackwardEulerDiffusionSolver2() override = default;
53 
56  const GridBackwardEulerDiffusionSolver2&) = delete;
57 
60  GridBackwardEulerDiffusionSolver2&&) noexcept = delete;
61 
72  void Solve(const ScalarGrid2& source, double diffusionCoefficient,
73  double timeIntervalInSeconds, ScalarGrid2* dest,
74  const ScalarField2& boundarySDF =
75  ConstantScalarField2{ std::numeric_limits<double>::max() },
76  const ScalarField2& fluidSDF = ConstantScalarField2{
77  -std::numeric_limits<double>::max() }) override;
78 
89  void Solve(const CollocatedVectorGrid2& source, double diffusionCoefficient,
90  double timeIntervalInSeconds, CollocatedVectorGrid2* dest,
91  const ScalarField2& boundarySDF =
92  ConstantScalarField2{ std::numeric_limits<double>::max() },
93  const ScalarField2& fluidSDF = ConstantScalarField2{
94  -std::numeric_limits<double>::max() }) override;
95 
106  void Solve(const FaceCenteredGrid2& source, double diffusionCoefficient,
107  double timeIntervalInSeconds, FaceCenteredGrid2* dest,
108  const ScalarField2& boundarySDF =
109  ConstantScalarField2{ std::numeric_limits<double>::max() },
110  const ScalarField2& fluidSDF = ConstantScalarField2{
111  -std::numeric_limits<double>::max() }) override;
112 
115 
116  private:
117  void BuildMarkers(const Vector2UZ& size,
118  const std::function<Vector2D(size_t, size_t)>& pos,
119  const ScalarField2& boundarySDF,
120  const ScalarField2& fluidSDF);
121 
122  void BuildMatrix(const Vector2UZ& size, const Vector2D& c);
123 
124  void BuildVectors(const ConstArrayView2<double>& f, const Vector2D& c);
125 
126  void BuildVectors(const ConstArrayView2<Vector2D>& f, const Vector2D& c,
127  size_t component);
128 
129  BoundaryType m_boundaryType;
130  FDMLinearSystem2 m_system;
131  FDMLinearSystemSolver2Ptr m_systemSolver;
132  Array2<char> m_markers;
133 };
134 
137  std::shared_ptr<GridBackwardEulerDiffusionSolver2>;
138 } // namespace CubbyFlow
139 
140 #endif
std::shared_ptr< FDMLinearSystemSolver2 > FDMLinearSystemSolver2Ptr
Shared pointer type for the FDMLinearSystemSolver2.
Definition: FDMLinearSystemSolver2.hpp:52
Linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.hpp:40
BoundaryType
Definition: GridBackwardEulerDiffusionSolver2.hpp:33
Abstract base class for N-D scalar grid structure.
Definition: ScalarGrid.hpp:24
Abstract base class for N-D scalar field.
Definition: ScalarField.hpp:24
GridBackwardEulerDiffusionSolver2(BoundaryType boundaryType=BoundaryType::Neumann)
Constructs the solver with given boundary type.
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
Definition: Array-Impl.hpp:19
Vector2< double > Vector2D
Definition: Matrix.hpp:774
~GridBackwardEulerDiffusionSolver2() override=default
Default virtual destructor.
N-D face-centered (a.k.a MAC or staggered) grid.
Definition: FaceCenteredGrid.hpp:31
2-D grid-based backward Euler diffusion solver.
Definition: GridBackwardEulerDiffusionSolver2.hpp:30
GridBackwardEulerDiffusionSolver2 & operator=(const GridBackwardEulerDiffusionSolver2 &)=delete
Deleted copy assignment operator.
void Solve(const ScalarGrid2 &source, double diffusionCoefficient, double timeIntervalInSeconds, ScalarGrid2 *dest, const ScalarField2 &boundarySDF=ConstantScalarField2{ std::numeric_limits< double >::max() }, const ScalarField2 &fluidSDF=ConstantScalarField2{ -std::numeric_limits< double >::max() }) override
Generic N-dimensional array class interface.
Definition: Array.hpp:32
void SetLinearSystemSolver(const FDMLinearSystemSolver2Ptr &solver)
Sets the linear system solver for this diffusion solver.
std::shared_ptr< GridBackwardEulerDiffusionSolver2 > GridBackwardEulerDiffusionSolver2Ptr
Shared pointer type for the GridBackwardEulerDiffusionSolver2.
Definition: GridBackwardEulerDiffusionSolver2.hpp:137
Abstract base class for N-D collocated vector grid structure.
Definition: CollocatedVectorGrid.hpp:22
N-D constant scalar field.
Definition: ConstantScalarField.hpp:20
Abstract base class for 2-D grid-based diffusion equation solver.
Definition: GridDiffusionSolver2.hpp:30