SPHinXsys  alpha version
general_dynamics.h
Go to the documentation of this file.
1 /* -------------------------------------------------------------------------*
2  * SPHinXsys *
3  * --------------------------------------------------------------------------*
4  * SPHinXsys (pronunciation: s'finksis) is an acronym from Smoothed Particle *
5  * Hydrodynamics for industrial compleX systems. It provides C++ APIs for *
6  * physical accurate simulation and aims to model coupled industrial dynamic *
7  * systems including fluid, solid, multi-body dynamics and beyond with SPH *
8  * (smoothed particle hydrodynamics), a meshless computational method using *
9  * particle discretization. *
10  * *
11  * SPHinXsys is partially funded by German Research Foundation *
12  * (Deutsche Forschungsgemeinschaft) DFG HU1527/6-1, HU1527/10-1 *
13  * and HU1527/12-1. *
14  * *
15  * Portions copyright (c) 2017-2020 Technical University of Munich and *
16  * the authors' affiliations. *
17  * *
18  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
19  * not use this file except in compliance with the License. You may obtain a *
20  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
21  * *
22  * --------------------------------------------------------------------------*/
29 #ifndef GENERAL_DYNAMICS_H
30 #define GENERAL_DYNAMICS_H
31 
32 #include "all_particle_dynamics.h"
33 #include "base_body.h"
34 #include "base_particles.h"
35 #include "external_force.h"
36 
37 #include <limits>
38 
39 namespace SPH
40 {
41  typedef DataDelegateSimple<SPHBody, BaseParticles, BaseMaterial> GeneralDataDelegateSimple;
42  typedef DataDelegateInner<SPHBody, BaseParticles, BaseMaterial> GeneralDataDelegateInner;
43  typedef DataDelegateContact<SPHBody, BaseParticles, BaseMaterial,
44  SPHBody, BaseParticles, BaseMaterial, DataDelegateEmptyBase>
45  GeneralDataDelegateContact;
54  : public ParticleDynamicsSimple,
56  {
57  private:
58  UniquePtrKeeper<Gravity> gravity_ptr_keeper_;
59 
60  public:
61  explicit TimeStepInitialization(SPHBody &sph_body);
62  TimeStepInitialization(SPHBody &sph_body, Gravity &gravity);
63  virtual ~TimeStepInitialization(){};
64 
65  protected:
66  StdLargeVec<Vecd> &pos_, &acc_prior_;
67  Gravity *gravity_;
68  virtual void setupDynamics(Real dt = 0.0) override;
69  virtual void Update(size_t index_i, Real dt = 0.0) override;
70  };
71 
77  : public ParticleDynamicsSimple,
79  {
80  public:
81  explicit RandomizeParticlePosition(SPHBody &sph_body);
82  virtual ~RandomizeParticlePosition(){};
83 
84  protected:
85  StdLargeVec<Vecd> &pos_;
86  Real randomize_scale_;
87  virtual void Update(size_t index_i, Real dt = 0.0) override;
88  };
89 
94  template <typename VariableType>
96  {
97  public:
98  explicit ParticleSmoothing(BaseBodyRelationInner &inner_relation, const std::string &variable_name)
99  : InteractionDynamicsWithUpdate(*inner_relation.sph_body_),
100  GeneralDataDelegateInner(inner_relation),
101  W0_(body_->sph_adaptation_->getKernel()->W0(Vecd(0))),
102  smoothed_(*particles_->getVariableByName<VariableType>(variable_name))
103  {
104  particles_->registerVariable(temp_, variable_name + "_temp");
105  }
106 
107  virtual ~ParticleSmoothing(){};
108 
109  protected:
110  const Real W0_;
111  StdLargeVec<VariableType> &smoothed_, temp_;
112 
113  virtual void Interaction(size_t index_i, Real dt = 0.0) override
114  {
115  Real weight = W0_;
116  VariableType summation = W0_ * smoothed_[index_i];
117  const Neighborhood &inner_neighborhood = inner_configuration_[index_i];
118  for (size_t n = 0; n != inner_neighborhood.current_size_; ++n)
119  {
120  size_t index_j = inner_neighborhood.j_[n];
121  summation += inner_neighborhood.W_ij_[n] * smoothed_[index_j];
122  weight += inner_neighborhood.W_ij_[n];
123  }
124  temp_[index_i] = summation / (weight + TinyReal);
125  };
126 
127  virtual void Update(size_t index_i, Real dt = 0.0) override
128  {
129  smoothed_[index_i] = temp_[index_i];
130  };
131  };
132 
137  class VelocityBoundCheck : public ParticleDynamicsReduce<bool, ReduceOR>,
139  {
140  public:
141  VelocityBoundCheck(SPHBody &sph_body, Real velocity_bound);
142  virtual ~VelocityBoundCheck(){};
143 
144  protected:
145  StdLargeVec<Vecd> &vel_;
146  Real velocity_bound_;
147  bool ReduceFunction(size_t index_i, Real dt = 0.0) override;
148  };
149 
154  class UpperFrontInXDirection : public ParticleDynamicsReduce<Real, ReduceMax>,
156  {
157  public:
158  explicit UpperFrontInXDirection(SPHBody &sph_body);
159  virtual ~UpperFrontInXDirection(){};
160 
161  protected:
162  StdLargeVec<Vecd> &pos_;
163  Real ReduceFunction(size_t index_i, Real dt = 0.0) override;
164  };
165 
170  class MaximumSpeed : public ParticleDynamicsReduce<Real, ReduceMax>,
172  {
173  public:
174  explicit MaximumSpeed(SPHBody &sph_body);
175  virtual ~MaximumSpeed(){};
176 
177  protected:
178  StdLargeVec<Vecd> &vel_;
179  Real ReduceFunction(size_t index_i, Real dt = 0.0) override;
180  };
181 
186  class BodyLowerBound : public ParticleDynamicsReduce<Vecd, ReduceLowerBound>,
188  {
189  public:
190  explicit BodyLowerBound(SPHBody &sph_body);
191  virtual ~BodyLowerBound(){};
192 
193  protected:
194  StdLargeVec<Vecd> &pos_;
195  Vecd ReduceFunction(size_t index_i, Real dt = 0.0) override;
196  };
197 
202  class BodyUpperBound : public ParticleDynamicsReduce<Vecd, ReduceUpperBound>,
204  {
205  public:
206  explicit BodyUpperBound(SPHBody &sph_body);
207  virtual ~BodyUpperBound(){};
208 
209  protected:
210  StdLargeVec<Vecd> &pos_;
211  Vecd ReduceFunction(size_t index_i, Real dt = 0.0) override;
212  };
213 
218  template <typename VariableType>
219  class BodySummation : public ParticleDynamicsReduce<VariableType, ReduceSum<VariableType>>,
221  {
222  public:
223  explicit BodySummation(SPHBody &sph_body, const std::string &variable_name)
225  GeneralDataDelegateSimple(sph_body),
226  variable_(*particles_->getVariableByName<VariableType>(variable_name))
227  {
228  this->initial_reference_ = VariableType(0);
229  };
230  virtual ~BodySummation(){};
231 
232  protected:
233  StdLargeVec<VariableType> &variable_;
234  VariableType ReduceFunction(size_t index_i, Real dt = 0.0) override
235  {
236  return variable_[index_i];
237  };
238  };
239 
244  template <typename VariableType>
245  class BodyMoment : public BodySummation<VariableType>
246  {
247  public:
248  explicit BodyMoment(SPHBody &sph_body, const std::string &variable_name)
249  : BodySummation<VariableType>(sph_body, variable_name),
250  mass_(this->particles_->mass_){};
251  virtual ~BodyMoment(){};
252 
253  protected:
254  StdLargeVec<Real> &mass_;
255  VariableType ReduceFunction(size_t index_i, Real dt = 0.0) override
256  {
257  return mass_[index_i] * this->variable_[index_i];
258  };
259  };
260 
266  : public ParticleDynamicsReduce<Real, ReduceSum<Real>>,
268  {
269  private:
270  UniquePtrKeeper<Gravity> gravity_ptr_keeper_;
271 
272  public:
273  explicit TotalMechanicalEnergy(SPHBody &sph_body);
274  TotalMechanicalEnergy(SPHBody &sph_body, Gravity &gravity_ptr);
275  virtual ~TotalMechanicalEnergy(){};
276 
277  protected:
278  StdLargeVec<Real> &mass_;
279  StdLargeVec<Vecd> &vel_, &pos_;
280  Gravity *gravity_;
281  Real ReduceFunction(size_t index_i, Real dt = 0.0) override;
282  };
283 }
284 #endif // GENERAL_DYNAMICS_H
A neighborhood around particle i.
Definition: neighbor_relation.h:47
Compute the total mechanical (kinematic and potential) energy.
Definition: general_dynamics.h:265
computing smoothed variable field by averaging with neighbors
Definition: general_dynamics.h:95
prepare data for inner particle dynamics
Definition: base_particle_dynamics.h:216
Get the maximum particle speed in a SPH body.
Definition: general_dynamics.h:170
virtual void setupDynamics(Real dt=0.0) override
Definition: general_dynamics.cpp:21
size_t current_size_
Definition: neighbor_relation.h:50
Simple particle dynamics without considering particle interaction.
Definition: particle_dynamics_algorithms.h:48
check whether particle velocity within a given bound
Definition: general_dynamics.h:137
initialize a time step for a body. including initialize particle acceleration induced by viscous...
Definition: general_dynamics.h:53
A wrapper to provide an ownership for a new derived object which previous often generated by new a ra...
Definition: ownership.h:90
Compute the moment of a body.
Definition: general_dynamics.h:245
This is the base classes of SPH bodies. The real body is for that with cell linked list and the ficti...
Base abstract class for reduce.
Definition: particle_dynamics_algorithms.h:69
Get the upper front In X Direction for a SPH body.
Definition: general_dynamics.h:154
VariableType initial_reference_
Definition: particle_dynamics_algorithms.h:104
StdLargeVec< Real > W_ij_
Definition: neighbor_relation.h:54
the upper bound of a body by reduced particle positions.
Definition: general_dynamics.h:202
This is the base class of SPH particles. The basic data of the particles is saved in separated large ...
Compute the summation of a particle variable in a body.
Definition: general_dynamics.h:219
SPHBody is a base body with basic data and functions. Its derived class can be a real fluid body...
Definition: base_body.h:61
Randomize the initial particle position.
Definition: general_dynamics.h:76
Here, we define the base external force class.
the lower bound of a body by reduced particle positions.
Definition: general_dynamics.h:186
This class includes an interaction and a update steps.
Definition: particle_dynamics_algorithms.h:160
The abstract relation within a SPH body.
Definition: base_body_relation.h:117
StdLargeVec< size_t > j_
Definition: neighbor_relation.h:53
ParticleConfiguration & inner_configuration_
Definition: base_particle_dynamics.h:222
The gravity force, derived class of External force.
Definition: external_force.h:55
Definition: solid_body_supplementary.cpp:9