GridSinglePhasePressureSolver2.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_SINGLE_PHASE_PRESSURE_SOLVER2_HPP
12 #define CUBBYFLOW_SINGLE_PHASE_PRESSURE_SOLVER2_HPP
13 
18 
19 namespace CubbyFlow
20 {
36 {
37  public:
40 
43  delete;
44 
47  delete;
48 
50  ~GridSinglePhasePressureSolver2() override = default;
51 
54  const GridSinglePhasePressureSolver2&) = delete;
55 
58  GridSinglePhasePressureSolver2&&) noexcept = delete;
59 
83  void Solve(
84  const FaceCenteredGrid2& input, double timeIntervalInSeconds,
85  FaceCenteredGrid2* output,
86  const ScalarField2& boundarySDF =
87  ConstantScalarField2{ std::numeric_limits<double>::max() },
88  const VectorField2& boundaryVelocity = ConstantVectorField2{ { 0, 0 } },
89  const ScalarField2& fluidSDF =
90  ConstantScalarField2{ -std::numeric_limits<double>::max() },
91  bool useCompressed = false) override;
92 
103  [[nodiscard]] GridBoundaryConditionSolver2Ptr
104  SuggestedBoundaryConditionSolver() const override;
105 
107  [[nodiscard]] const FDMLinearSystemSolver2Ptr& GetLinearSystemSolver()
108  const;
109 
112 
114  [[nodiscard]] const FDMVector2& GetPressure() const;
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 DecompressSolution();
123 
124  virtual void BuildSystem(const FaceCenteredGrid2& input,
125  bool useCompressed);
126 
127  virtual void ApplyPressureGradient(const FaceCenteredGrid2& input,
128  FaceCenteredGrid2* output);
129 
130  FDMLinearSystem2 m_system;
131  FDMCompressedLinearSystem2 m_compSystem;
132  FDMLinearSystemSolver2Ptr m_systemSolver;
133 
134  FDMMGLinearSystem2 m_mgSystem;
135  FDMMGSolver2Ptr m_mgSystemSolver;
136 
137  std::vector<Array2<char>> m_markers;
138 };
139 
142  std::shared_ptr<GridSinglePhasePressureSolver2>;
143 } // namespace CubbyFlow
144 
145 #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
N-D constant vector field.
Definition: ConstantVectorField.hpp:20
Abstract base class for 2-D grid-based pressure solver.
Definition: GridPressureSolver2.hpp:29
std::shared_ptr< GridSinglePhasePressureSolver2 > GridSinglePhasePressureSolver2Ptr
Shared pointer type for the GridSinglePhasePressureSolver2.
Definition: GridSinglePhasePressureSolver2.hpp:142
GridSinglePhasePressureSolver2 & operator=(const GridSinglePhasePressureSolver2 &)=delete
Deleted copy assignment operator.
std::shared_ptr< GridBoundaryConditionSolver2 > GridBoundaryConditionSolver2Ptr
Shared pointer type for the GridBoundaryConditionSolver2.
Definition: GridBoundaryConditionSolver2.hpp:117
Abstract base class for N-D scalar field.
Definition: ScalarField.hpp:24
GridSinglePhasePressureSolver2()
Default constructor.
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
std::shared_ptr< FDMMGSolver2 > FDMMGSolver2Ptr
Shared pointer type for the FDMMGSolver2.
Definition: FDMMGSolver2.hpp:55
Definition: Array-Impl.hpp:19
Vector2< double > Vector2D
Definition: Matrix.hpp:774
N-D face-centered (a.k.a MAC or staggered) grid.
Definition: FaceCenteredGrid.hpp:31
void SetLinearSystemSolver(const FDMLinearSystemSolver2Ptr &solver)
Sets the linear system solver.
2-D single-phase pressure solver.
Definition: GridSinglePhasePressureSolver2.hpp:35
const FDMLinearSystemSolver2Ptr & GetLinearSystemSolver() const
Returns the linear system solver.
Compressed linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.hpp:59
~GridSinglePhasePressureSolver2() override=default
Default virtual destructor.
Abstract base class for N-D vector field.
Definition: VectorField.hpp:42
const FDMVector2 & GetPressure() const
Returns the pressure field.
N-D constant scalar field.
Definition: ConstantScalarField.hpp:20
Multigrid-syle 2-D linear system.
Definition: FDMMGLinearSystem2.hpp:26
void Solve(const FaceCenteredGrid2 &input, double timeIntervalInSeconds, FaceCenteredGrid2 *output, const ScalarField2 &boundarySDF=ConstantScalarField2{ std::numeric_limits< double >::max() }, const VectorField2 &boundaryVelocity=ConstantVectorField2{ { 0, 0 } }, const ScalarField2 &fluidSDF=ConstantScalarField2{ -std::numeric_limits< double >::max() }, bool useCompressed=false) override
Solves the pressure term and apply it to the velocity field.
GridBoundaryConditionSolver2Ptr SuggestedBoundaryConditionSolver() const override
Returns the best boundary condition solver for this solver.