SPHinXsys  alpha version
base_particle_dynamics.hpp
Go to the documentation of this file.
1 
7 #ifndef BASE_PARTICLE_DYNAMICS_HPP
8 #define BASE_PARTICLE_DYNAMICS_HPP
9 
10 #include "base_particle_dynamics.h"
11 #include "base_body.h"
12 
13 namespace SPH
14 {
15  //=================================================================================================//
16  template <class ReturnType>
17  ParticleDynamics<ReturnType>::ParticleDynamics(SPHBody &sph_body)
18  : GlobalStaticVariables(), sph_body_(&sph_body),
19  sph_adaptation_(sph_body.sph_adaptation_),
20  base_particles_(sph_body.base_particles_) {}
21  //=================================================================================================//
22  template <class BodyType,
23  class ParticlesType,
24  class MaterialType,
25  class ContactBodyType,
26  class ContactParticlesType,
27  class ContactMaterialType,
29  DataDelegateContact<BodyType, ParticlesType, MaterialType, ContactBodyType, ContactParticlesType, ContactMaterialType, BaseDataDelegateType>::
30  DataDelegateContact(BaseBodyRelationContact &body_contact_relation) : BaseDataDelegateType(*body_contact_relation.sph_body_)
31  {
32  RealBodyVector contact_sph_bodies = body_contact_relation.contact_bodies_;
33  for (size_t i = 0; i != contact_sph_bodies.size(); ++i)
34  {
35  contact_bodies_.push_back(DynamicCast<ContactBodyType>(this, contact_sph_bodies[i]));
36  contact_particles_.push_back(DynamicCast<ContactParticlesType>(this, contact_sph_bodies[i]->base_particles_));
37  contact_material_.push_back(DynamicCast<ContactMaterialType>(this, contact_sph_bodies[i]->base_material_));
38  contact_configuration_.push_back(&body_contact_relation.contact_configuration_[i]);
39  }
40  }
41  //=================================================================================================//
42  template <class ReturnType, typename ReduceOperation>
43  ReturnType ReduceIterator(size_t total_real_particles, ReturnType temp,
44  ReduceFunctor<ReturnType> &reduce_functor, ReduceOperation &reduce_operation, Real dt)
45  {
46  for (size_t i = 0; i < total_real_particles; ++i)
47  {
48  temp = reduce_operation(temp, reduce_functor(i, dt));
49  }
50  return temp;
51  }
52  //=================================================================================================//
53  template <class ReturnType, typename ReduceOperation>
54  ReturnType ReduceIterator_parallel(size_t total_real_particles, ReturnType temp,
55  ReduceFunctor<ReturnType> &reduce_functor, ReduceOperation &reduce_operation, Real dt)
56  {
57  return parallel_reduce(
58  blocked_range<size_t>(0, total_real_particles),
59  temp, [&](const blocked_range<size_t> &r, ReturnType temp0) -> ReturnType
60  {
61  for (size_t i = r.begin(); i != r.end(); ++i)
62  {
63  temp0 = reduce_operation(temp0, reduce_functor(i, dt));
64  }
65  return temp0;
66  },
67  [&](ReturnType x, ReturnType y) -> ReturnType
68  {
69  return reduce_operation(x, y);
70  });
71  }
72  //=================================================================================================//
73  template <class ParticleDynamicsInnerType, class ContactDataType>
74  ParticleDynamicsComplex<ParticleDynamicsInnerType, ContactDataType>::
75  ParticleDynamicsComplex(ComplexBodyRelation &complex_relation,
76  BaseBodyRelationContact &extra_contact_relation)
77  : ParticleDynamicsInnerType(complex_relation.inner_relation_),
78  ContactDataType(complex_relation.contact_relation_)
79  {
80  if (complex_relation.sph_body_ != extra_contact_relation.sph_body_)
81  {
82  std::cout << "\n Error: the two body_realtions do not have the same source body!" << std::endl;
83  std::cout << __FILE__ << ':' << __LINE__ << std::endl;
84  exit(1);
85  }
86 
87  for (auto &extra_body : extra_contact_relation.contact_bodies_)
88  {
89  // here we first obtain the pointer to the most derived class and then implicitly downcast it to
90  // the types defined in the base complex dynamics
91  this->contact_bodies_.push_back(extra_body->ThisObjectPtr());
92  this->contact_particles_.push_back(extra_body->base_particles_->ThisObjectPtr());
93  this->contact_material_.push_back(extra_body->base_material_->ThisObjectPtr());
94  }
95 
96  for (size_t i = 0; i != extra_contact_relation.contact_bodies_.size(); ++i)
97  {
98  this->contact_configuration_.push_back(&extra_contact_relation.contact_configuration_[i]);
99  }
100  }
101  //=================================================================================================//
102 }
103 //=================================================================================================//
104 #endif //BASE_PARTICLE_DYNAMICS_HPP
std::function< ReturnType(size_t, Real)> ReduceFunctor
Definition: base_particle_dynamics.h:52
This is the base classes of SPH bodies. The real body is for that with cell linked list and the ficti...
ReturnType ReduceIterator(size_t total_real_particles, ReturnType temp, ReduceFunctor< ReturnType > &reduce_functor, ReduceOperation &reduce_operation, Real dt=0.0)
Definition: base_particle_dynamics.hpp:43
This is for the base classes of particle dynamics, which describe the interaction between particles...
ReturnType ReduceIterator_parallel(size_t total_real_particles, ReturnType temp, ReduceFunctor< ReturnType > &reduce_functor, ReduceOperation &reduce_operation, Real dt=0.0)
Definition: base_particle_dynamics.hpp:54
Definition: solid_body_supplementary.cpp:9