LevelSetLiquidSolver2.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_LEVEL_SET_LIQUID_SOLVER2_HPP
12 #define CUBBYFLOW_LEVEL_SET_LIQUID_SOLVER2_HPP
13 
16 
17 namespace CubbyFlow
18 {
31 {
32  public:
33  class Builder;
34 
37 
39  LevelSetLiquidSolver2(const Vector2UZ& resolution,
40  const Vector2D& gridSpacing,
41  const Vector2D& gridOrigin);
42 
45 
47  LevelSetLiquidSolver2(LevelSetLiquidSolver2&&) noexcept = delete;
48 
50  ~LevelSetLiquidSolver2() override = default;
51 
54 
57 
59  [[nodiscard]] ScalarGrid2Ptr GetSignedDistanceField() const;
60 
62  [[nodiscard]] LevelSetSolver2Ptr GetLevelSetSolver() const;
63 
65  void SetLevelSetSolver(const LevelSetSolver2Ptr& newSolver);
66 
68  void SetMinReinitializeDistance(double distance);
69 
82  void SetIsGlobalCompensationEnabled(bool isEnabled);
83 
91  [[nodiscard]] double ComputeVolume() const;
92 
94  [[nodiscard]] static Builder GetBuilder();
95 
96  protected:
98  void OnBeginAdvanceTimeStep(double timeIntervalInSeconds) override;
99 
101  void OnEndAdvanceTimeStep(double timeIntervalInSeconds) override;
102 
104  void ComputeAdvection(double timeIntervalInSeconds) override;
105 
113  [[nodiscard]] ScalarField2Ptr GetFluidSDF() const override;
114 
115  private:
116  void Reinitialize(double currentCFL);
117 
118  void ExtrapolateVelocityToAir(double currentCFL);
119 
120  void AddVolume(double volDiff);
121 
122  size_t m_signedDistanceFieldId;
123  LevelSetSolver2Ptr m_levelSetSolver;
124  double m_minReinitializeDistance = 10.0;
125  bool m_isGlobalCompensationEnabled = false;
126  double m_lastKnownVolume = 0.0;
127 };
128 
130 using LevelSetLiquidSolver2Ptr = std::shared_ptr<LevelSetLiquidSolver2>;
131 
136  : public GridFluidSolverBuilderBase2<Builder>
137 {
138  public:
140  [[nodiscard]] LevelSetLiquidSolver2 Build() const;
141 
143  [[nodiscard]] LevelSetLiquidSolver2Ptr MakeShared() const;
144 };
145 } // namespace CubbyFlow
146 
147 #endif
ScalarField2Ptr GetFluidSDF() const override
Returns fluid region as a signed-distance field.
void OnEndAdvanceTimeStep(double timeIntervalInSeconds) override
Called at the end of the time-step.
void SetMinReinitializeDistance(double distance)
Sets minimum reinitialization distance.
Base class for grid-based fluid solver builder.
Definition: GridFluidSolver2.hpp:315
LevelSetSolver2Ptr GetLevelSetSolver() const
Returns the level set solver.
std::shared_ptr< LevelSetLiquidSolver2 > LevelSetLiquidSolver2Ptr
Shared pointer type for the LevelSetLiquidSolver2.
Definition: LevelSetLiquidSolver2.hpp:130
Level set based 2-D liquid solver.
Definition: LevelSetLiquidSolver2.hpp:30
static Builder GetBuilder()
Returns builder fox LevelSetLiquidSolver2.
ScalarGrid2Ptr GetSignedDistanceField() const
Returns signed-distance field.
std::shared_ptr< ScalarField2 > ScalarField2Ptr
Shared pointer for the ScalarField2 type.
Definition: ScalarField.hpp:67
Definition: Matrix.hpp:27
LevelSetLiquidSolver2 & operator=(const LevelSetLiquidSolver2 &)=delete
Deleted copy assignment operator.
Definition: pybind11Utils.hpp:20
std::shared_ptr< ScalarGrid2 > ScalarGrid2Ptr
Shared pointer for the ScalarGrid2 type.
Definition: ScalarGrid.hpp:266
double ComputeVolume() const
Returns liquid volume measured by smeared Heaviside function.
std::shared_ptr< LevelSetSolver2 > LevelSetSolver2Ptr
Shared pointer type for the LevelSetSolver2.
Definition: LevelSetSolver2.hpp:93
void OnBeginAdvanceTimeStep(double timeIntervalInSeconds) override
Called at the beginning of the time-step.
LevelSetLiquidSolver2()
Default constructor.
Front-end to create LevelSetLiquidSolver2 objects step by step.
Definition: LevelSetLiquidSolver2.hpp:135
Abstract base class for grid-based 2-D fluid solver.
Definition: GridFluidSolver2.hpp:35
void ComputeAdvection(double timeIntervalInSeconds) override
Customizes advection step.
~LevelSetLiquidSolver2() override=default
Default virtual destructor.
void SetIsGlobalCompensationEnabled(bool isEnabled)
Enables (or disables) global compensation feature flag.
void SetLevelSetSolver(const LevelSetSolver2Ptr &newSolver)
Sets the level set solver.