SPHinXsys  alpha version
constraint_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  * --------------------------------------------------------------------------*/
30 #ifndef CONSTRAINT_DYNAMICS_H
31 #define CONSTRAINT_DYNAMICS_H
32 
33 #include "all_particle_dynamics.h"
34 #include "general_dynamics.h"
35 #include "base_kernel.h"
36 #include "all_body_relations.h"
37 #include "solid_body.h"
38 #include "solid_particles.h"
39 #include "elastic_solid.h"
40 
41 namespace SPH
42 {
43  template <typename VariableType>
44  class BodySummation;
45  template <typename VariableType>
46  class BodyMoment;
47 
48  namespace solid_dynamics
49  {
50  //----------------------------------------------------------------------
51  // for general solid dynamics
52  //----------------------------------------------------------------------
53  typedef DataDelegateSimple<SolidBody, SolidParticles, Solid> SolidDataSimple;
54  typedef DataDelegateInner<SolidBody, SolidParticles, Solid> SolidDataInner;
55 
61  {
62  public:
63  // TODO: use only body part as argment since body can be referred from it already
65  virtual ~ConstrainSolidBodyRegion(){};
66 
67  protected:
68  StdLargeVec<Vecd> &pos_, &pos0_;
69  StdLargeVec<Vecd> &n_, &n0_;
70  StdLargeVec<Vecd> &vel_, &acc_;
71  virtual Vecd getDisplacement(Vecd &pos_0, Vecd &pos_n) { return pos_n; };
72  virtual Vecd getVelocity(Vecd &pos_0, Vecd &pos_n, Vecd &vel_n) { return Vecd(0); };
73  virtual Vecd getAcceleration(Vecd &pos_0, Vecd &pos_n, Vecd &acc) { return Vecd(0); };
74  virtual SimTK::Rotation getBodyRotation(Vecd &pos_0, Vecd &pos_n, Vecd &acc) { return SimTK::Rotation(); }
75  virtual void Update(size_t index_i, Real dt = 0.0) override;
76  };
77 
83  {
84  public:
87 
88  StdLargeVec<bool> &GetApplyConstrainToParticle() { return apply_constrain_to_particle_; }
89 
90  protected:
91  StdLargeVec<Vecd> &pos_, &pos0_;
92  StdLargeVec<Vecd> &vel_, &acc_;
93  StdLargeVec<bool> apply_constrain_to_particle_;
94 
95  virtual Vecd getDisplacement(Vecd &pos_0, Vecd &pos_n) { return pos_n; };
96  virtual void Update(size_t index_i, Real dt = 0.0) override;
97  };
98 
104  {
105  public:
106  PositionSolidBody(SPHBody &sph_body, BodyPartByParticle &body_part, Real start_time, Real end_time, Vecd pos_end_center);
107  virtual ~PositionSolidBody(){};
108  StdLargeVec<Vecd> &GetParticlePos0() { return pos0_; };
109  StdLargeVec<Vecd> &GetParticlePosN() { return pos_; };
110 
111  protected:
112  StdLargeVec<Vecd> &pos_, &pos0_;
113  StdLargeVec<Vecd> &vel_, &acc_;
114  Real start_time_, end_time_;
115  Vecd pos_0_center_, pos_end_center_, translation_;
116  Vecd getDisplacement(size_t index_i, Real dt);
117  virtual Vecd getVelocity() { return Vecd(0); };
118  virtual Vecd getAcceleration() { return Vecd(0); };
119  virtual SimTK::Rotation getBodyRotation() { return SimTK::Rotation(); }
120  virtual void Update(size_t index_i, Real dt = 0.0) override;
121  };
122 
128  {
129  public:
130  PositionScaleSolidBody(SPHBody &sph_body, BodyPartByParticle &body_part, Real start_time, Real end_time, Real end_scale);
131  virtual ~PositionScaleSolidBody(){};
132  StdLargeVec<Vecd> &GetParticlePos0() { return pos0_; };
133  StdLargeVec<Vecd> &GetParticlePosN() { return pos_; };
134 
135  protected:
136  StdLargeVec<Vecd> &pos_, &pos0_;
137  StdLargeVec<Vecd> &vel_, &acc_;
138  Real start_time_, end_time_, end_scale_;
139  Vecd pos_0_center_;
140  Vecd getDisplacement(size_t index_i, Real dt);
141  virtual Vecd getVelocity() { return Vecd(0); };
142  virtual Vecd getAcceleration() { return Vecd(0); };
143  virtual SimTK::Rotation getBodyRotation() { return SimTK::Rotation(); }
144  virtual void Update(size_t index_i, Real dt = 0.0) override;
145  };
146 
152  {
153  public:
154  TranslateSolidBody(SPHBody &sph_body, BodyPartByParticle &body_part, Real start_time, Real end_time, Vecd translation);
155  virtual ~TranslateSolidBody(){};
156 
157  protected:
158  StdLargeVec<Vecd> &pos_, &pos0_;
159  StdLargeVec<Vecd> pos_end_;
160  StdLargeVec<Vecd> &vel_, &acc_;
161  Real start_time_, end_time_;
162  Vecd translation_;
163  Vecd getDisplacement(size_t index_i, Real dt);
164  virtual Vecd getVelocity() { return Vecd(0); };
165  virtual Vecd getAcceleration() { return Vecd(0); };
166  virtual SimTK::Rotation getBodyRotation() { return SimTK::Rotation(); }
167  virtual void Update(size_t index_i, Real dt = 0.0) override;
168  };
169 
176  {
177  public:
178  TranslateSolidBodyPart(SPHBody &sph_body, BodyPartByParticle &body_part, Real start_time, Real end_time, Vecd translation, BoundingBox bbox);
179  virtual ~TranslateSolidBodyPart(){};
180 
181  protected:
182  BoundingBox bbox_;
183  virtual void Update(size_t index_i, Real dt = 0.0) override;
184  };
185 
191  {
192  public:
194  Vecd constrained_direction = Vecd(0))
195  : solid_dynamics::ConstrainSolidBodyRegion(sph_body, body_part),
196  constrain_matrix_(Matd(1.0))
197  {
198  for (int k = 0; k != Dimensions; ++k)
199  constrain_matrix_[k][k] = constrained_direction[k];
200  };
202 
203  protected:
204  Matd constrain_matrix_;
205  virtual Vecd getVelocity(Vecd &pos_0, Vecd &pos_n, Vecd &vel_n)
206  {
207  return constrain_matrix_ * vel_n;
208  };
209  };
210 
216  public SolidDataInner
217  {
218  public:
220  virtual ~SoftConstrainSolidBodyRegion(){};
221 
222  protected:
223  StdLargeVec<Real> &Vol_;
224  StdLargeVec<Vecd> &vel_, &acc_;
225  StdLargeVec<Vecd> vel_temp_, acc_temp_;
226  virtual void Interaction(size_t index_i, Real dt = 0.0) override;
227  virtual void Update(size_t index_i, Real dt = 0.0) override;
228  };
229 
235  {
236  public:
237  ConstrainSolidBodyRegion constraint_;
238  SoftConstrainSolidBodyRegion softening_;
239 
241  virtual ~ClampConstrainSolidBodyRegion(){};
242 
243  virtual void exec(Real dt = 0.0) override;
244  virtual void parallel_exec(Real dt = 0.0) override;
245  };
246 
252  {
253  public:
254  explicit ConstrainSolidBodyMassCenter(SPHBody &sph_body, Vecd constrain_direction = Vecd(1.0));
255  virtual ~ConstrainSolidBodyMassCenter(){};
256 
257  protected:
258  virtual void setupDynamics(Real dt = 0.0) override;
259  virtual void Update(size_t index_i, Real dt = 0.0) override;
260 
261  private:
262  Real total_mass_;
263  Matd correction_matrix_;
264  Vecd velocity_correction_;
265  StdLargeVec<Vecd> &vel_;
266  BodyMoment<Vecd> compute_total_momentum_;
267  };
268 
275  {
276  public:
278  SolidBodyPartForSimbody &body_part,
279  SimTK::MultibodySystem &MBsystem,
280  SimTK::MobilizedBody &mobod,
281  SimTK::Force::DiscreteForces &force_on_bodies,
282  SimTK::RungeKuttaMersonIntegrator &integ);
283  virtual ~ConstrainSolidBodyPartBySimBody(){};
284 
285  protected:
286  StdLargeVec<Vecd> &pos_, &pos0_, &vel_, &n_, &n0_;
287  SimTK::MultibodySystem &MBsystem_;
288  SimTK::MobilizedBody &mobod_;
289  SimTK::Force::DiscreteForces &force_on_bodies_;
290  SimTK::RungeKuttaMersonIntegrator &integ_;
291  const SimTK::State *simbody_state_;
292  Vec3d initial_mobod_origin_location_;
293 
294  virtual void setupDynamics(Real dt = 0.0) override;
295  void virtual Update(size_t index_i, Real dt = 0.0) override;
296  };
297 
304  : public PartDynamicsByParticleReduce<SimTK::SpatialVec, ReduceSum<SimTK::SpatialVec>>,
305  public SolidDataSimple
306  {
307  public:
309  SolidBodyPartForSimbody &body_part,
310  SimTK::MultibodySystem &MBsystem,
311  SimTK::MobilizedBody &mobod,
312  SimTK::Force::DiscreteForces &force_on_bodies,
313  SimTK::RungeKuttaMersonIntegrator &integ);
315 
316  protected:
317  StdLargeVec<Real> &mass_;
318  StdLargeVec<Vecd> &acc_, &acc_prior_, &pos_;
319  SimTK::MultibodySystem &MBsystem_;
320  SimTK::MobilizedBody &mobod_;
321  SimTK::Force::DiscreteForces &force_on_bodies_;
322  SimTK::RungeKuttaMersonIntegrator &integ_;
323  const SimTK::State *simbody_state_;
324  Vec3d current_mobod_origin_location_;
325 
326  virtual void SetupReduce() override;
327  virtual SimTK::SpatialVec ReduceFunction(size_t index_i, Real dt = 0.0) override;
328  };
329  }
330 }
331 #endif // CONSTRAINT_DYNAMICS_H
Translates the body in a given time interval -translation driven boundary condition; only moving the ...
Definition: constraint_dynamics.h:175
prepare data for inner particle dynamics
Definition: base_particle_dynamics.h:216
Constrain a solid body part with prescribed motion and smoothing to mimic the clamping effect...
Definition: constraint_dynamics.h:234
Simple particle dynamics without considering particle interaction.
Definition: particle_dynamics_algorithms.h:48
A body part with a collection of particles.
Definition: base_body_part.h:64
This is the particle dynamics aplliable for all type bodies.
Declaration of solidbody which is used for Solid BCs and derived from RealBody.
Definition: solid_body.h:46
Moves the body into a defined position in a given time interval - position driven boundary condition...
Definition: constraint_dynamics.h:103
Abstract class for body part simple particle dynamics.
Definition: particle_dynamics_bodypart.h:70
virtual void setupDynamics(Real dt=0.0) override
Definition: constraint_dynamics.cpp:351
Constrain the mass center of a solid body.
Definition: constraint_dynamics.h:251
A SolidBodyPart for coupling with Simbody. The mass, origin, and unit inertial matrix are computed...
Definition: solid_body.h:60
Abstract class for particle interaction involving in a body part with an extra update step...
Definition: particle_dynamics_bodypart.h:106
Constrain a solid body part from the motion computed from Simbody.
Definition: constraint_dynamics.h:274
Constrain the velocity of a solid body part.
Definition: constraint_dynamics.h:190
virtual void exec(Real dt=0.0) override
Definition: constraint_dynamics.cpp:299
Soft the constrain of a solid body part.
Definition: constraint_dynamics.h:215
Translates the body in a given time interval -translation driven boundary condition; only moving the ...
Definition: constraint_dynamics.h:151
Constrain the surface particles of a solid body part with prescribed motion.
Definition: constraint_dynamics.h:82
Constrain a solid body part with prescribed motion.
Definition: constraint_dynamics.h:60
Scales the body in a given time interval - position driven boundary condition.
Definition: constraint_dynamics.h:127
virtual void Update(size_t index_i, Real dt=0.0) override
Definition: solid_dynamics_supplementary.cpp:41
virtual void setupDynamics(Real dt=0.0) override
Definition: constraint_dynamics.cpp:323
SPHBody is a base body with basic data and functions. Its derived class can be a real fluid body...
Definition: base_body.h:61
Compute the force acting on the solid body part for applying to simbody forces latter.
Definition: constraint_dynamics.h:303
reduce operation in a Lagrangian contrained region.
Definition: particle_dynamics_bodypart.h:227
This is the derived class of base particles.
The abstract relation within a SPH body.
Definition: base_body_relation.h:117
prepare data for simple particle dynamics.
Definition: base_particle_dynamics.h:185
This is the base classes of kernel functions. Implementation will be implemented in derived classes...
These are classes for define properties of elastic solid materials. These classes are based on isotro...
This is the class for bodies used for solid BCs or Elastic structure.
Definition: solid_body_supplementary.cpp:9
The base class for all particle dynamics This class contains the only two interface functions availab...
Definition: base_particle_dynamics.h:145