SPHSolver3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: SPHSolver3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 3-D SPH solver.
6 > Created Time: 2017/06/03
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_SPH_SOLVER3_H
10 #define CUBBYFLOW_SPH_SOLVER3_H
11 
14 
15 namespace CubbyFlow
16 {
31  {
32  public:
33  class Builder;
34 
36  SPHSolver3();
37 
40  SPHSolver3(double targetDensity, double targetSpacing, double relativeKernelRadius);
41 
42  virtual ~SPHSolver3();
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<Vector3D>& positions,
149  const ConstArrayAccessor1<double>& densities,
150  const ConstArrayAccessor1<double>& pressures,
151  ArrayAccessor1<Vector3D> 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 SPHSolver3Ptr = std::shared_ptr<SPHSolver3>;
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 SPHSolver3::Builder final : public SPHSolverBuilderBase3<SPHSolver3::Builder>
235  {
236  public:
238  SPHSolver3 Build() const;
239 
241  SPHSolver3Ptr MakeShared() const;
242  };
243 }
244 
245 #endif
constexpr double WATER_DENSITY
Water density.
Definition: Constants.h:159
void OnBeginAdvanceTimeStep(double timeStepInSeconds) override
Performs pre-processing step before the simulation.
SPHSolver3 Build() const
Builds SPHSolver3.
DerivedBuilder & WithRelativeKernelRadius(double relativeKernelRadius)
Returns builder with relative kernel radius.
Definition: SPHSolver3.h:225
void SetTimeStepLimitScale(double newScale)
Sets the multiplier that scales the max allowed time-step.
void SetPseudoViscosityCoefficient(double newPseudoViscosityCoefficient)
Sets the pseudo viscosity coefficient.
void SetEosExponent(double newEosExponent)
Sets the exponent part of the equation-of-state.
DerivedBuilder & WithTargetSpacing(double targetSpacing)
Returns builder with target spacing.
Definition: SPHSolver3.h:218
double m_targetDensity
Definition: SPHSolver3.h:205
3-D SPH solver.
Definition: SPHSolver3.h:30
Basic 3-D particle system solver.
Definition: ParticleSystemSolver3.h:34
void SetSpeedOfSound(double newSpeedOfSound)
Sets the speed of sound.
void SetViscosityCoefficient(double newViscosityCoefficient)
Sets the viscosity coefficient.
double GetEosExponent() const
Returns the exponent part of the equation-of-state.
double m_targetSpacing
Definition: SPHSolver3.h:206
double GetNegativePressureScale() const
Returns the negative pressure scale.
SPHSolver3Ptr MakeShared() const
Builds shared pointer of SPHSolver3 instance.
1-D read-only array accessor class.
Definition: ArrayAccessor1.h:185
void OnEndAdvanceTimeStep(double timeStepInSeconds) override
Performs post-processing step before the simulation.
Definition: pybind11Utils.h:24
void AccumulateForces(double timeStepInSeconds) override
Accumulates the force to the forces array in the particle system.
DerivedBuilder & WithTargetDensity(double targetDensity)
Returns builder with target density.
Definition: SPHSolver3.h:211
Front-end to create SPHSolver3 objects step by step.
Definition: SPHSolver3.h:234
SPHSolver3()
Constructs a solver with empty particle set.
static Builder GetBuilder()
Returns builder fox SPHSolver3.
unsigned int GetNumberOfSubTimeSteps(double timeIntervalInSeconds) const override
Returns the number of sub-time-steps.
double GetSpeedOfSound() const
Returns the speed of sound.
double GetTimeStepLimitScale() const
Multiplier that scales the max allowed time-step.
1-D array accessor class.
Definition: ArrayAccessor1.h:28
void ComputePseudoViscosity(double timeStepInSeconds)
Computes pseudo viscosity.
Base class for SPH-based fluid solver builder.
Definition: SPHSolver3.h:192
SPHSystemData3Ptr GetSPHSystemData() const
Returns the SPH system data.
std::shared_ptr< SPHSolver3 > SPHSolver3Ptr
Shared pointer type for the SPHSolver3.
Definition: SPHSolver3.h:186
double GetViscosityCoefficient() const
Returns the viscosity coefficient.
double m_relativeKernelRadius
Definition: SPHSolver3.h:207
virtual void AccumulateNonPressureForces(double timeStepInSeconds)
double GetPseudoViscosityCoefficient() const
Returns the pseudo viscosity coefficient.
void SetNegativePressureScale(double newNegativePressureScale)
Sets the negative pressure scale.
void ComputePressure()
Computes the pressure.
std::shared_ptr< SPHSystemData3 > SPHSystemData3Ptr
Shared pointer for the SPHSystemData3 type.
Definition: SPHSystemData3.h:191
virtual void AccumulatePressureForce(double timeStepInSeconds)