SPHinXsys  alpha version
base_body.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  * HU1527/12-1 and HU1527/12-4. *
14  * *
15  * Portions copyright (c) 2017-2022 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  * -----------------------------------------------------------------------------*/
36 #ifndef BASE_BODY_H
37 #define BASE_BODY_H
38 
39 #include "base_data_package.h"
40 #include "sph_data_containers.h"
41 #include "adaptation.h"
42 #include "cell_linked_list.h"
43 #include "particle_sorting.h"
44 #include "all_geometries.h"
45 
46 #include <string>
47 
48 namespace SPH
49 {
50  class SPHSystem;
51  class SPHBodyRelation;
52  class BodySurface;
53 
61  class SPHBody
62  {
63  private:
64  SharedPtrKeeper<Shape> shape_ptr_keeper_;
65 
66  public:
69  protected:
70  UniquePtrKeeper<SPHAdaptation> sph_adaptation_ptr_keeper_;
71 
72  private:
73  UniquePtrKeeper<BaseMaterial> base_material_ptr_keeper_;
74  UniquePtrKeeper<BaseParticles> base_particles_ptr_keeper_;
75 
76  protected:
77  SPHSystem &sph_system_;
78  std::string body_name_;
83  bool is_domain_bounds_determined_;
84 
85  public:
89  StdVec<SPHBodyRelation *> body_relations_;
91  explicit SPHBody(SPHSystem &sph_system, SharedPtr<Shape> shape_ptr);
92  virtual ~SPHBody(){};
93 
94  std::string getBodyName();
95  SPHSystem &getSPHSystem();
96  Real getSPHBodyResolutionRef() { return sph_adaptation_->ReferenceSpacing(); };
97  void setNewlyUpdated() { newly_updated_ = true; };
98  void setNotNewlyUpdated() { newly_updated_ = false; };
99  bool checkNewlyUpdated() { return newly_updated_; };
100  void setBodyDomainBounds(const BoundingBox &body_domain_bounds);
101  BoundingBox getBodyDomainBounds();
102  BoundingBox getSPHSystemBounds();
103  //----------------------------------------------------------------------
104  // Object factory template functions
105  //----------------------------------------------------------------------
106  template <typename... ConstructorArgs>
107  LevelSetShape *defineComponentLevelSetShape(const std::string &shape_name, ConstructorArgs &&...args)
108  {
109  ComplexShape *complex_shape = DynamicCast<ComplexShape>(this, body_shape_);
110  return complex_shape->defineLevelSetShape(this, shape_name, std::forward<ConstructorArgs>(args)...);
111  };
112 
113  template <typename... ConstructorArgs>
114  LevelSetShape *defineBodyLevelSetShape(ConstructorArgs &&...args)
115  {
116  LevelSetShape *levelset_shape =
117  shape_ptr_keeper_.resetPtr<LevelSetShape>(this, *body_shape_, std::forward<ConstructorArgs>(args)...);
118  body_shape_ = levelset_shape;
119  return levelset_shape;
120  };
121 
123  template <class ParticleType = BaseParticles, class MaterialType = BaseMaterial>
124  void defineParticlesWithMaterial(MaterialType *material)
125  {
126  base_material_ = material;
127  base_particles_ = base_particles_ptr_keeper_.createPtr<ParticleType>(*this, material);
128  };
129 
131  template <class ParticleType = BaseParticles, class MaterialType = BaseMaterial, typename... ConstructorArgs>
132  void defineParticlesAndMaterial(ConstructorArgs &&...args)
133  {
134  MaterialType *material = base_material_ptr_keeper_.createPtr<MaterialType>(std::forward<ConstructorArgs>(args)...);
135  defineParticlesWithMaterial<ParticleType>(material);
136  };
137 
140  template <class ParticleGeneratorType, typename... ConstructorArgs>
141  void generateParticles(ConstructorArgs &&...args)
142  {
143  ParticleGeneratorType particle_generator(*this, std::forward<ConstructorArgs>(args)...);
144  particle_generator.initializeGeometricVariables();
147  };
148 
151  virtual void assignBaseParticles(BaseParticles *base_particles);
152  void allocateConfigurationMemoriesForBufferParticles();
153 
154  template <typename VariableType>
155  void addBodyStateForRecording(const std::string &variable_name)
156  {
157  base_particles_->template addVariableToWrite<VariableType>(variable_name);
158  };
159 
160  template <class DerivedVariableMethod>
161  void addDerivedBodyStateForRecording()
162  {
163  base_particles_->template addDerivedVariableToWrite<DerivedVariableMethod>();
164  };
165 
166  virtual void writeParticlesToVtuFile(std::ostream &output_file);
167  virtual void writeParticlesToVtpFile(std::ofstream &output_file);
168  virtual void writeParticlesToPltFile(std::ofstream &output_file);
169  virtual void writeSurfaceParticlesToVtuFile(std::ofstream &output_file, BodySurface &surface_particles);
170  virtual void writeParticlesToXmlForRestart(std::string &filefullpath);
171  virtual void readParticlesFromXmlForRestart(std::string &filefullpath);
172  virtual void writeToXmlForReloadParticle(std::string &filefullpath);
173  virtual void readFromXmlForReloadParticle(std::string &filefullpath);
174  virtual SPHBody *ThisObjectPtr() { return this; };
175  };
176 
182  class RealBody : public SPHBody
183  {
184  private:
185  UniquePtrKeeper<BaseCellLinkedList> cell_linked_list_keeper_;
186  BoundingBox system_domain_bounds_;
193  SplitCellLists split_cell_lists_;
194  bool use_split_cell_lists_;
195 
196  public:
197  ParticleSorting particle_sorting_;
200  explicit RealBody(SPHSystem &sph_system, SharedPtr<Shape> shape_ptr);
201  virtual ~RealBody(){};
202 
203  void setUseSplitCellLists() { use_split_cell_lists_ = true; };
204  bool getUseSplitCellLists() { return use_split_cell_lists_; };
205  SplitCellLists &getSplitCellLists() { return split_cell_lists_; };
208  virtual void assignBaseParticles(BaseParticles *base_particles) override;
209  virtual void sortParticleWithCellLinkedList();
210  virtual void updateCellLinkedList();
211  //----------------------------------------------------------------------
212  // Object factory template functions
213  //----------------------------------------------------------------------
214  template <class AdaptationType, typename... ConstructorArgs>
215  void defineAdaptation(ConstructorArgs &&...args)
216  {
217  sph_adaptation_ = sph_adaptation_ptr_keeper_
218  .createPtr<AdaptationType>(this, std::forward<ConstructorArgs>(args)...);
219  cell_linked_list_ = cell_linked_list_keeper_.movePtr(
220  sph_adaptation_->createCellLinkedList(system_domain_bounds_, *this));
221  };
222  };
223 }
224 #endif //BASE_BODY_H
StdVec< ConcurrentCellLists > SplitCellLists
Definition: sph_data_containers.h:54
Base class for all adaptations. The base class defines essential global parameters. It is also used for single-resolution method. In the constructor parameter, system_refinement_ratio defines the relation between present resolution to the system reference resolution. The derived classes are defined for more complex adaptations.
Definition: adaptation.h:55
DerivedType * resetPtr(ConstructorArgs &&...args)
Definition: ownership.h:175
StdVec< SPHBodyRelation * > body_relations_
Definition: base_body.h:89
Particles with essential (geometric and kinematic) data. There are three types of particles, all par...
Definition: base_particles.h:81
Base class for all volumetric geometries Note that checkContain and findClosest point are basic funct...
Definition: base_geometry.h:64
BaseCellLinkedList * cell_linked_list_
Definition: base_body.h:198
virtual void initializeOtherVariables()
Definition: base_particles.cpp:39
BaseMaterial * base_material_
Definition: base_body.h:87
Base of all materials.
Definition: base_material.h:52
bool newly_updated_
Definition: base_body.h:79
Here gives the classes for managing cell linked lists. This is the basic class for building the parti...
void defineParticlesAndMaterial(ConstructorArgs &&...args)
Definition: base_body.h:132
void defineParticlesWithMaterial(MaterialType *material)
Definition: base_body.h:124
Adaptation defines the parameters for single or multi-resolution computations.
A wrapper to provide an ownership for a new derived object which previous often generated by new a ra...
Definition: ownership.h:90
Abstract class for mesh cell linked list.
Definition: cell_linked_list.h:69
The class for sorting particle according a given sequence.
Definition: particle_sorting.h:265
BoundingBox body_domain_bounds_
Definition: base_body.h:82
Here gives the classes for particle sorting.
void generateParticles(ConstructorArgs &&...args)
Definition: base_body.h:141
DerivedType * createPtr(ConstructorArgs &&...args)
Definition: ownership.h:95
virtual void assignBaseParticles(BaseParticles *base_particles) override
Definition: base_body.cpp:126
BaseType * movePtr(UniquePtr< BaseType > moved_unique_ptr)
Definition: ownership.h:110
A wrapper to provide an shared ownership for a new derived object which previous often generated by n...
Definition: ownership.h:170
Shape * body_shape_
Definition: base_body.h:67
virtual void assignBaseParticles(BaseParticles *base_particles)
Definition: base_material.cpp:13
Set up of basic data structure.
BaseParticles * base_particles_
Definition: base_body.h:88
SPHBody is a base body with basic data and functions. Its derived class can be a real fluid body...
Definition: base_body.h:61
virtual void assignBaseParticles(BaseParticles *base_particles)
Definition: base_body.cpp:40
The SPH system managing objects in the system level.
Definition: sph_system.h:46
SPHAdaptation * sph_adaptation_
Definition: base_body.h:86
Derived body with inner particle configuration or inner interactions. After construction, the particle and material must be specified.
Definition: base_body.h:182
Definition: solid_body_supplementary.cpp:9