GridFractionalSinglePhasePressureSolver2.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_FRACTIONAL_SINGLE_PHASE_PRESSURE_SOLVER2_HPP
12 #define CUBBYFLOW_FRACTIONAL_SINGLE_PHASE_PRESSURE_SOLVER2_HPP
13 
18 
19 namespace CubbyFlow
20 {
47  : public GridPressureSolver2
48 {
49  public:
52 
56 
59  GridFractionalSinglePhasePressureSolver2&&) noexcept = delete;
60 
62  ~GridFractionalSinglePhasePressureSolver2() override = default;
63 
67 
70  GridFractionalSinglePhasePressureSolver2&&) noexcept = delete;
71 
95  void Solve(
96  const FaceCenteredGrid2& input, double timeIntervalInSeconds,
97  FaceCenteredGrid2* output,
98  const ScalarField2& boundarySDF =
99  ConstantScalarField2{ std::numeric_limits<double>::max() },
100  const VectorField2& boundaryVelocity = ConstantVectorField2{ { 0, 0 } },
101  const ScalarField2& fluidSDF =
102  ConstantScalarField2{ -std::numeric_limits<double>::max() },
103  bool useCompressed = false) override;
104 
114  [[nodiscard]] GridBoundaryConditionSolver2Ptr
115  SuggestedBoundaryConditionSolver() const override;
116 
118  [[nodiscard]] const FDMLinearSystemSolver2Ptr& GetLinearSystemSolver()
119  const;
120 
123 
125  [[nodiscard]] const FDMVector2& GetPressure() const;
126 
127  private:
128  void BuildWeights(const FaceCenteredGrid2& input,
129  const ScalarField2& boundarySDF,
130  const VectorField2& boundaryVelocity,
131  const ScalarField2& fluidSDF);
132 
133  void DecompressSolution();
134 
135  void BuildSystem(const FaceCenteredGrid2& input, bool useCompressed);
136 
137  void ApplyPressureGradient(const FaceCenteredGrid2& input,
138  FaceCenteredGrid2* output);
139 
140  FDMLinearSystem2 m_system;
141  FDMCompressedLinearSystem2 m_compSystem;
142  FDMLinearSystemSolver2Ptr m_systemSolver;
143 
144  FDMMGLinearSystem2 m_mgSystem;
145  FDMMGSolver2Ptr m_mgSystemSolver;
146 
147  std::vector<Array2<double>> m_uWeights;
148  std::vector<Array2<double>> m_vWeights;
149  std::vector<Array2<double>> m_fluidSDF;
150 
151  std::function<Vector2D(const Vector2D&)> m_boundaryVel;
152 };
153 
156  std::shared_ptr<GridFractionalSinglePhasePressureSolver2>;
157 } // namespace CubbyFlow
158 
159 #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
GridFractionalSinglePhasePressureSolver2()
Default constructor.
Abstract base class for 2-D grid-based pressure solver.
Definition: GridPressureSolver2.hpp:29
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.
std::shared_ptr< GridBoundaryConditionSolver2 > GridBoundaryConditionSolver2Ptr
Shared pointer type for the GridBoundaryConditionSolver2.
Definition: GridBoundaryConditionSolver2.hpp:117
2-D fractional single-phase pressure solver.
Definition: GridFractionalSinglePhasePressureSolver2.hpp:46
Abstract base class for N-D scalar field.
Definition: ScalarField.hpp:24
const FDMLinearSystemSolver2Ptr & GetLinearSystemSolver() const
Returns the linear system solver.
Definition: pybind11Utils.hpp:20
std::shared_ptr< FDMMGSolver2 > FDMMGSolver2Ptr
Shared pointer type for the FDMMGSolver2.
Definition: FDMMGSolver2.hpp:55
Definition: Array-Impl.hpp:19
GridFractionalSinglePhasePressureSolver2 & operator=(const GridFractionalSinglePhasePressureSolver2 &)=delete
Deleted copy assignment operator.
const FDMVector2 & GetPressure() const
Returns the pressure field.
GridBoundaryConditionSolver2Ptr SuggestedBoundaryConditionSolver() const override
Returns the best boundary condition solver for this solver.
N-D face-centered (a.k.a MAC or staggered) grid.
Definition: FaceCenteredGrid.hpp:31
Compressed linear system (Ax=b) for 2-D finite differencing.
Definition: FDMLinearSystem2.hpp:59
void SetLinearSystemSolver(const FDMLinearSystemSolver2Ptr &solver)
Sets the linear system solver.
Abstract base class for N-D vector field.
Definition: VectorField.hpp:42
~GridFractionalSinglePhasePressureSolver2() override=default
Default virtual destructor.
N-D constant scalar field.
Definition: ConstantScalarField.hpp:20
Multigrid-syle 2-D linear system.
Definition: FDMMGLinearSystem2.hpp:26
std::shared_ptr< GridFractionalSinglePhasePressureSolver2 > GridFractionalSinglePhasePressureSolver2Ptr
Shared pointer type for the GridFractionalSinglePhasePressureSolver2.
Definition: GridFractionalSinglePhasePressureSolver2.hpp:156