LevelSetLiquidSolver3.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_SOLVER3_HPP
12 #define CUBBYFLOW_LEVEL_SET_LIQUID_SOLVER3_HPP
13 
16 
17 namespace CubbyFlow
18 {
31 {
32  public:
33  class Builder;
34 
37 
39  LevelSetLiquidSolver3(const Vector3UZ& resolution,
40  const Vector3D& gridSpacing,
41  const Vector3D& gridOrigin);
42 
45 
47  LevelSetLiquidSolver3(LevelSetLiquidSolver3&&) noexcept = delete;
48 
50  ~LevelSetLiquidSolver3() override = default;
51 
54 
57 
59  [[nodiscard]] ScalarGrid3Ptr GetSignedDistanceField() const;
60 
62  [[nodiscard]] LevelSetSolver3Ptr GetLevelSetSolver() const;
63 
65  void SetLevelSetSolver(const LevelSetSolver3Ptr& 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]] ScalarField3Ptr 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  LevelSetSolver3Ptr m_levelSetSolver;
124  double m_minReinitializeDistance = 10.0;
125  bool m_isGlobalCompensationEnabled = false;
126  double m_lastKnownVolume = 0.0;
127 };
128 
130 using LevelSetLiquidSolver3Ptr = std::shared_ptr<LevelSetLiquidSolver3>;
131 
136  : public GridFluidSolverBuilderBase3<Builder>
137 {
138  public:
140  [[nodiscard]] LevelSetLiquidSolver3 Build() const;
141 
143  [[nodiscard]] LevelSetLiquidSolver3Ptr MakeShared() const;
144 };
145 } // namespace CubbyFlow
146 
147 #endif
void OnBeginAdvanceTimeStep(double timeIntervalInSeconds) override
Called at the beginning of the time-step.
LevelSetLiquidSolver3()
Default constructor.
Front-end to create LevelSetLiquidSolver3 objects step by step.
Definition: LevelSetLiquidSolver3.hpp:135
void SetMinReinitializeDistance(double distance)
Sets minimum reinitialization distance.
ScalarGrid3Ptr GetSignedDistanceField() const
Returns signed-distance field.
~LevelSetLiquidSolver3() override=default
Default virtual destructor.
std::shared_ptr< ScalarField3 > ScalarField3Ptr
Shared pointer for the ScalarField3 type.
Definition: ScalarField.hpp:70
void SetLevelSetSolver(const LevelSetSolver3Ptr &newSolver)
Sets the level set solver.
void SetIsGlobalCompensationEnabled(bool isEnabled)
Enables (or disables) global compensation feature flag.
ScalarField3Ptr GetFluidSDF() const override
Returns fluid region as a signed-distance field.
std::shared_ptr< ScalarGrid3 > ScalarGrid3Ptr
Shared pointer for the ScalarGrid3 type.
Definition: ScalarGrid.hpp:269
Base class for grid-based fluid solver builder.
Definition: GridFluidSolver3.hpp:315
std::shared_ptr< LevelSetLiquidSolver3 > LevelSetLiquidSolver3Ptr
Shared pointer type for the LevelSetLiquidSolver3.
Definition: LevelSetLiquidSolver3.hpp:130
Level set based 3-D liquid solver.
Definition: LevelSetLiquidSolver3.hpp:30
static Builder GetBuilder()
Returns builder fox LevelSetLiquidSolver3.
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
Abstract base class for grid-based 3-D fluid solver.
Definition: GridFluidSolver3.hpp:35
LevelSetLiquidSolver3 & operator=(const LevelSetLiquidSolver3 &)=delete
Deleted copy assignment operator.
void OnEndAdvanceTimeStep(double timeIntervalInSeconds) override
Called at the end of the time-step.
std::shared_ptr< LevelSetSolver3 > LevelSetSolver3Ptr
Shared pointer type for the LevelSetSolver3.
Definition: LevelSetSolver3.hpp:93
double ComputeVolume() const
Returns liquid volume measured by smeared Heaviside function.
void ComputeAdvection(double timeIntervalInSeconds) override
Customizes advection step.
LevelSetSolver3Ptr GetLevelSetSolver() const
Returns the level set solver.