SPHSolver2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: SPHSolver2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D SPH solver.
6 > Created Time: 2017/06/03
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_SPH_SOLVER2_H
10 #define CUBBYFLOW_SPH_SOLVER2_H
11 
14 
15 namespace CubbyFlow
16 {
31  {
32  public:
33  class Builder;
34 
36  SPHSolver2();
37 
38  virtual ~SPHSolver2();
39 
42  SPHSolver2(double targetDensity, double targetSpacing, double relativeKernelRadius);
43 
45  double GetEosExponent() const;
46 
54  void SetEosExponent(double newEosExponent);
55 
57  double GetNegativePressureScale() const;
58 
67  void SetNegativePressureScale(double newNegativePressureScale);
68 
70  double GetViscosityCoefficient() const;
71 
73  void SetViscosityCoefficient(double newViscosityCoefficient);
74 
76  double GetPseudoViscosityCoefficient() const;
77 
84  void SetPseudoViscosityCoefficient(double newPseudoViscosityCoefficient);
85 
87  double GetSpeedOfSound() const;
88 
96  void SetSpeedOfSound(double newSpeedOfSound);
97 
105  double GetTimeStepLimitScale() const;
106 
114  void SetTimeStepLimitScale(double newScale);
115 
118 
120  static Builder GetBuilder();
121 
122  protected:
124  unsigned int GetNumberOfSubTimeSteps(double timeIntervalInSeconds) const override;
125 
127  void AccumulateForces(double timeStepInSeconds) override;
128 
130  void OnBeginAdvanceTimeStep(double timeStepInSeconds) override;
131 
133  void OnEndAdvanceTimeStep(double timeStepInSeconds) override;
134 
137  virtual void AccumulateNonPressureForces(double timeStepInSeconds);
138 
141  virtual void AccumulatePressureForce(double timeStepInSeconds);
142 
144  void ComputePressure();
145 
148  const ConstArrayAccessor1<Vector2D>& positions,
149  const ConstArrayAccessor1<double>& densities,
150  const ConstArrayAccessor1<double>& pressures,
151  ArrayAccessor1<Vector2D> pressureForces);
152 
156 
158  void ComputePseudoViscosity(double timeStepInSeconds);
159 
160  private:
162  double m_eosExponent = 7.0;
163 
166  double m_negativePressureScale = 0.0;
167 
169  double m_viscosityCoefficient = 0.01;
170 
174  double m_pseudoViscosityCoefficient = 10.0;
175 
179  double m_speedOfSound = 100.0;
180 
182  double m_timeStepLimitScale = 1.0;
183  };
184 
186  using SPHSolver2Ptr = std::shared_ptr<SPHSolver2>;
187 
191  template <typename DerivedBuilder>
193  {
194  public:
196  DerivedBuilder& WithTargetDensity(double targetDensity);
197 
199  DerivedBuilder& WithTargetSpacing(double targetSpacing);
200 
202  DerivedBuilder& WithRelativeKernelRadius(double relativeKernelRadius);
203 
204  protected:
206  double m_targetSpacing = 0.1;
208  };
209 
210  template <typename T>
212  {
213  m_targetDensity = targetDensity;
214  return static_cast<T&>(*this);
215  }
216 
217  template <typename T>
219  {
220  m_targetSpacing = targetSpacing;
221  return static_cast<T&>(*this);
222  }
223 
224  template <typename T>
226  {
227  m_relativeKernelRadius = relativeKernelRadius;
228  return static_cast<T&>(*this);
229  }
230 
234  class SPHSolver2::Builder final : public SPHSolverBuilderBase2<SPHSolver2::Builder>
235  {
236  public:
238  SPHSolver2 Build() const;
239 
241  SPHSolver2Ptr MakeShared() const;
242  };
243 }
244 
245 #endif
constexpr double WATER_DENSITY
Water density.
Definition: Constants.h:159
void SetNegativePressureScale(double newNegativePressureScale)
Sets the negative pressure scale.
SPHSolver2 Build() const
Builds SPHSolver2.
std::shared_ptr< SPHSolver2 > SPHSolver2Ptr
Shared pointer type for the SPHSolver2.
Definition: SPHSolver2.h:186
virtual void AccumulatePressureForce(double timeStepInSeconds)
double m_targetDensity
Definition: SPHSolver2.h:205
Base class for SPH-based fluid solver builder.
Definition: SPHSolver2.h:192
SPHSystemData2Ptr GetSPHSystemData() const
Returns the SPH system data.
void OnEndAdvanceTimeStep(double timeStepInSeconds) override
Performs post-processing step before the simulation.
void SetEosExponent(double newEosExponent)
Sets the exponent part of the equation-of-state.
void ComputePseudoViscosity(double timeStepInSeconds)
Computes pseudo viscosity.
double GetNegativePressureScale() const
Returns the negative pressure scale.
double GetSpeedOfSound() const
Returns the speed of sound.
double GetViscosityCoefficient() const
Returns the viscosity coefficient.
virtual void AccumulateNonPressureForces(double timeStepInSeconds)
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
void SetViscosityCoefficient(double newViscosityCoefficient)
Sets the viscosity coefficient.
void SetPseudoViscosityCoefficient(double newPseudoViscosityCoefficient)
Sets the pseudo viscosity coefficient.
DerivedBuilder & WithRelativeKernelRadius(double relativeKernelRadius)
Returns builder with relative kernel radius.
Definition: SPHSolver2.h:225
double GetPseudoViscosityCoefficient() const
Returns the pseudo viscosity coefficient.
void AccumulateForces(double timeStepInSeconds) override
Accumulates the force to the forces array in the particle system.
Definition: pybind11Utils.h:24
void ComputePressure()
Computes the pressure.
Front-end to create SPHSolver2 objects step by step.
Definition: SPHSolver2.h:234
DerivedBuilder & WithTargetSpacing(double targetSpacing)
Returns builder with target spacing.
Definition: SPHSolver2.h:218
SPHSolver2Ptr MakeShared() const
Builds shared pointer of SPHSolver2 instance.
Basic 2-D particle system solver.
Definition: ParticleSystemSolver2.h:34
SPHSolver2()
Constructs a solver with empty particle set.
unsigned int GetNumberOfSubTimeSteps(double timeIntervalInSeconds) const override
Returns the number of sub-time-steps.
static Builder GetBuilder()
Returns builder fox SPHSolver2.
double GetTimeStepLimitScale() const
Multiplier that scales the max allowed time-step.
double m_targetSpacing
Definition: SPHSolver2.h:206
void SetTimeStepLimitScale(double newScale)
Sets the multiplier that scales the max allowed time-step.
1-D array accessor class.
Definition: ArrayAccessor1.h:28
void SetSpeedOfSound(double newSpeedOfSound)
Sets the speed of sound.
std::shared_ptr< SPHSystemData2 > SPHSystemData2Ptr
Shared pointer for the SPHSystemData2 type.
Definition: SPHSystemData2.h:220
DerivedBuilder & WithTargetDensity(double targetDensity)
Returns builder with target density.
Definition: SPHSolver2.h:211
double GetEosExponent() const
Returns the exponent part of the equation-of-state.
2-D SPH solver.
Definition: SPHSolver2.h:30
void OnBeginAdvanceTimeStep(double timeStepInSeconds) override
Performs pre-processing step before the simulation.
double m_relativeKernelRadius
Definition: SPHSolver2.h:207