Jet  v1.3.3
sph_solver3.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_SPH_SOLVER3_H_
8 #define INCLUDE_JET_SPH_SOLVER3_H_
9 
10 #include <jet/constants.h>
12 #include <jet/sph_system_data3.h>
13 
14 namespace jet {
15 
30  public:
31  class Builder;
32 
35 
39  double targetDensity,
40  double targetSpacing,
41  double relativeKernelRadius);
42 
43  virtual ~SphSolver3();
44 
46  double eosExponent() const;
47 
55  void setEosExponent(double newEosExponent);
56 
58  double negativePressureScale() const;
59 
68  void setNegativePressureScale(double newNegativePressureScale);
69 
71  double viscosityCoefficient() const;
72 
74  void setViscosityCoefficient(double newViscosityCoefficient);
75 
78 
85  void setPseudoViscosityCoefficient(double newPseudoViscosityCoefficient);
86 
88  double speedOfSound() const;
89 
97  void setSpeedOfSound(double newSpeedOfSound);
98 
106  double timeStepLimitScale() const;
107 
115  void setTimeStepLimitScale(double newScale);
116 
119 
121  static Builder builder();
122 
123  protected:
125  unsigned int numberOfSubTimeSteps(
126  double timeIntervalInSeconds) const override;
127 
129  void accumulateForces(double timeStepInSeconds) override;
130 
132  void onBeginAdvanceTimeStep(double timeStepInSeconds) override;
133 
135  void onEndAdvanceTimeStep(double timeStepInSeconds) override;
136 
139  virtual void accumulateNonPressureForces(double timeStepInSeconds);
140 
143  virtual void accumulatePressureForce(double timeStepInSeconds);
144 
147 
150  const ConstArrayAccessor1<Vector3D>& positions,
151  const ConstArrayAccessor1<double>& densities,
152  const ConstArrayAccessor1<double>& pressures,
153  ArrayAccessor1<Vector3D> pressureForces);
154 
158 
160  void computePseudoViscosity(double timeStepInSeconds);
161 
162  private:
164  double _eosExponent = 7.0;
165 
168  double _negativePressureScale = 0.0;
169 
171  double _viscosityCoefficient = 0.01;
172 
176  double _pseudoViscosityCoefficient = 10.0;
177 
181  double _speedOfSound = 100.0;
182 
184  double _timeStepLimitScale = 1.0;
185 };
186 
188 typedef std::shared_ptr<SphSolver3> SphSolver3Ptr;
189 
190 
194 template <typename DerivedBuilder>
196  public:
198  DerivedBuilder& withTargetDensity(double targetDensity);
199 
201  DerivedBuilder& withTargetSpacing(double targetSpacing);
202 
204  DerivedBuilder& withRelativeKernelRadius(double relativeKernelRadius);
205 
206  protected:
208  double _targetSpacing = 0.1;
209  double _relativeKernelRadius = 1.8;
210 };
211 
212 template <typename T>
214  _targetDensity = targetDensity;
215  return static_cast<T&>(*this);
216 }
217 
218 template <typename T>
220  _targetSpacing = targetSpacing;
221  return static_cast<T&>(*this);
222 }
223 
224 template <typename T>
226  double relativeKernelRadius) {
227  _relativeKernelRadius = relativeKernelRadius;
228  return static_cast<T&>(*this);
229 }
230 
235  : public SphSolverBuilderBase3<SphSolver3::Builder> {
236  public:
238  SphSolver3 build() const;
239 
242 };
243 
244 } // namespace jet
245 
246 #endif // INCLUDE_JET_SPH_SOLVER3_H_
jet::SphSolver3::speedOfSound
double speedOfSound() const
Returns the speed of sound.
jet::SphSolverBuilderBase3
Base class for SPH-based fluid solver builder.
Definition: sph_solver3.h:195
jet::SphSolver3::SphSolver3
SphSolver3()
Constructs a solver with empty particle set.
jet::SphSystemData3Ptr
std::shared_ptr< SphSystemData3 > SphSystemData3Ptr
Shared pointer for the SphSystemData3 type.
Definition: sph_system_data3.h:195
jet::SphSolver3::onBeginAdvanceTimeStep
void onBeginAdvanceTimeStep(double timeStepInSeconds) override
Performs pre-processing step before the simulation.
jet::SphSolver3::Builder::makeShared
SphSolver3Ptr makeShared() const
Builds shared pointer of SphSolver3 instance.
jet::SphSolverBuilderBase3::withRelativeKernelRadius
DerivedBuilder & withRelativeKernelRadius(double relativeKernelRadius)
Returns builder with relative kernel radius.
Definition: sph_solver3.h:225
jet::SphSolver3::viscosityCoefficient
double viscosityCoefficient() const
Returns the viscosity coefficient.
jet::SphSolver3::builder
static Builder builder()
Returns builder fox SphSolver3.
jet::SphSolver3::computePseudoViscosity
void computePseudoViscosity(double timeStepInSeconds)
Computes pseudo viscosity.
jet::SphSolver3::setNegativePressureScale
void setNegativePressureScale(double newNegativePressureScale)
Sets the negative pressure scale.
jet::SphSolver3::setTimeStepLimitScale
void setTimeStepLimitScale(double newScale)
Sets the multiplier that scales the max allowed time-step.
jet::ConstArrayAccessor< T, 1 >
1-D read-only array accessor class.
Definition: array_accessor1.h:184
jet::SphSolver3::accumulatePressureForce
void accumulatePressureForce(const ConstArrayAccessor1< Vector3D > &positions, const ConstArrayAccessor1< double > &densities, const ConstArrayAccessor1< double > &pressures, ArrayAccessor1< Vector3D > pressureForces)
Accumulates the pressure force to the given pressureForces array.
jet::SphSolver3::accumulateForces
void accumulateForces(double timeStepInSeconds) override
Accumulates the force to the forces array in the particle system.
jet::SphSolver3::timeStepLimitScale
double timeStepLimitScale() const
Multiplier that scales the max allowed time-step.
jet::SphSolver3::~SphSolver3
virtual ~SphSolver3()
particle_system_solver3.h
jet::SphSolver3::accumulatePressureForce
virtual void accumulatePressureForce(double timeStepInSeconds)
jet::SphSolver3::Builder::build
SphSolver3 build() const
Builds SphSolver3.
jet::SphSolver3::setPseudoViscosityCoefficient
void setPseudoViscosityCoefficient(double newPseudoViscosityCoefficient)
Sets the pseudo viscosity coefficient.
jet::SphSolver3::setViscosityCoefficient
void setViscosityCoefficient(double newViscosityCoefficient)
Sets the viscosity coefficient.
jet::SphSolver3::onEndAdvanceTimeStep
void onEndAdvanceTimeStep(double timeStepInSeconds) override
Performs post-processing step before the simulation.
jet::SphSolverBuilderBase3::_targetDensity
double _targetDensity
Definition: sph_solver3.h:207
jet
Definition: advection_solver2.h:18
jet::SphSolver3::sphSystemData
SphSystemData3Ptr sphSystemData() const
Returns the SPH system data.
jet::SphSolver3
3-D SPH solver.
Definition: sph_solver3.h:29
jet::ParticleSystemSolver3
Basic 3-D particle system solver.
Definition: particle_system_solver3.h:31
sph_system_data3.h
jet::SphSolver3::negativePressureScale
double negativePressureScale() const
Returns the negative pressure scale.
jet::SphSolver3Ptr
std::shared_ptr< SphSolver3 > SphSolver3Ptr
Shared pointer type for the SphSolver3.
Definition: sph_solver3.h:188
jet::SphSolverBuilderBase3::_relativeKernelRadius
double _relativeKernelRadius
Definition: sph_solver3.h:209
jet::SphSolverBuilderBase3::withTargetDensity
DerivedBuilder & withTargetDensity(double targetDensity)
Returns builder with target density.
Definition: sph_solver3.h:213
jet::SphSolverBuilderBase3::_targetSpacing
double _targetSpacing
Definition: sph_solver3.h:208
jet::SphSolver3::setSpeedOfSound
void setSpeedOfSound(double newSpeedOfSound)
Sets the speed of sound.
jet::SphSolverBuilderBase3::withTargetSpacing
DerivedBuilder & withTargetSpacing(double targetSpacing)
Returns builder with target spacing.
Definition: sph_solver3.h:219
constants.h
jet::SphSolver3::eosExponent
double eosExponent() const
Returns the exponent part of the equation-of-state.
jet::SphSolver3::Builder
Front-end to create SphSolver3 objects step by step.
Definition: sph_solver3.h:235
jet::SphSolver3::accumulateViscosityForce
void accumulateViscosityForce()
jet::SphSolver3::numberOfSubTimeSteps
unsigned int numberOfSubTimeSteps(double timeIntervalInSeconds) const override
Returns the number of sub-time-steps.
jet::SphSolver3::accumulateNonPressureForces
virtual void accumulateNonPressureForces(double timeStepInSeconds)
jet::kWaterDensity
constexpr double kWaterDensity
Water density.
Definition: constants.h:304
jet::SphSolver3::setEosExponent
void setEosExponent(double newEosExponent)
Sets the exponent part of the equation-of-state.
jet::SphSolver3::SphSolver3
SphSolver3(double targetDensity, double targetSpacing, double relativeKernelRadius)
jet::ArrayAccessor< T, 1 >
1-D array accessor class.
Definition: array_accessor1.h:27
jet::SphSolver3::pseudoViscosityCoefficient
double pseudoViscosityCoefficient() const
Returns the pseudo viscosity coefficient.
jet::SphSolver3::computePressure
void computePressure()
Computes the pressure.