LevelSetLiquidSolver2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: LevelSetLiquidSolver2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Level set based 2-D liquid solver.
6 > Created Time: 2017/08/30
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_LEVEL_SET_LIQUID_SOLVER2_H
10 #define CUBBYFLOW_LEVEL_SET_LIQUID_SOLVER2_H
11 
14 
15 namespace CubbyFlow
16 {
29  {
30  public:
31  class Builder;
32 
35 
38  const Size2& resolution,
39  const Vector2D& gridSpacing,
40  const Vector2D& gridOrigin);
41 
43  virtual ~LevelSetLiquidSolver2();
44 
47 
50 
52  void SetLevelSetSolver(const LevelSetSolver2Ptr& newSolver);
53 
55  void SetMinReinitializeDistance(double distance);
56 
69  void SetIsGlobalCompensationEnabled(bool isEnabled);
70 
78  double ComputeVolume() const;
79 
81  static Builder GetBuilder();
82 
83  protected:
85  void OnBeginAdvanceTimeStep(double timeIntervalInSeconds) override;
86 
88  void OnEndAdvanceTimeStep(double timeIntervalInSeconds) override;
89 
91  void ComputeAdvection(double timeIntervalInSeconds) override;
92 
100  ScalarField2Ptr GetFluidSDF() const override;
101 
102  private:
103  size_t m_signedDistanceFieldId;
104  LevelSetSolver2Ptr m_levelSetSolver;
105  double m_minReinitializeDistance = 10.0;
106  bool m_isGlobalCompensationEnabled = false;
107  double m_lastKnownVolume = 0.0;
108 
109  void Reinitialize(double currentCFL);
110 
111  void ExtrapolateVelocityToAir(double currentCFL);
112 
113  void AddVolume(double volDiff);
114  };
115 
117  using LevelSetLiquidSolver2Ptr = std::shared_ptr<LevelSetLiquidSolver2>;
118 
122  class LevelSetLiquidSolver2::Builder final : public GridFluidSolverBuilderBase2<LevelSetLiquidSolver2::Builder>
123  {
124  public:
127 
130  };
131 }
132 
133 #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.h:303
LevelSetLiquidSolver2Ptr MakeShared() const
Builds shared pointer of LevelSetLiquidSolver2 instance.
LevelSetSolver2Ptr GetLevelSetSolver() const
Returns the level set solver.
std::shared_ptr< LevelSetLiquidSolver2 > LevelSetLiquidSolver2Ptr
Shared pointer type for the LevelSetLiquidSolver2.
Definition: LevelSetLiquidSolver2.h:117
Level set based 2-D liquid solver.
Definition: LevelSetLiquidSolver2.h:28
2-D point class.
Definition: Point2.h:25
virtual ~LevelSetLiquidSolver2()
Destructor.
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: ScalarField2.h:44
Definition: pybind11Utils.h:24
std::shared_ptr< ScalarGrid2 > ScalarGrid2Ptr
Shared pointer for the ScalarGrid2 type.
Definition: ScalarGrid2.h:179
double ComputeVolume() const
Returns liquid volume measured by smeared Heaviside function.
std::shared_ptr< LevelSetSolver2 > LevelSetSolver2Ptr
Shared pointer type for the LevelSetSolver2.
Definition: LevelSetSolver2.h:88
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.h:122
Abstract base class for grid-based 2-D fluid solver.
Definition: GridFluidSolver2.h:33
void ComputeAdvection(double timeIntervalInSeconds) override
Customizes advection step.
2-D vector class.
Definition: Vector2.h:26
void SetIsGlobalCompensationEnabled(bool isEnabled)
Enables (or disables) global compensation feature flag.
LevelSetLiquidSolver2 Build() const
Builds LevelSetLiquidSolver2.
void SetLevelSetSolver(const LevelSetSolver2Ptr &newSolver)
Sets the level set solver.