SPHinXsys  alpha version
cell_linked_list.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  * --------------------------------------------------------------------------*/
23 
33 #ifndef MESH_CELL_LINKED_LIST_H
34 #define MESH_CELL_LINKED_LIST_H
35 
36 #include "base_mesh.h"
37 #include "neighbor_relation.h"
38 
39 namespace SPH
40 {
41 
42  class SPHSystem;
43  class SPHBody;
44  class BaseParticles;
45  class Kernel;
46  class SPHAdaptation;
51  class CellList
52  {
53  public:
60 
61  CellList();
62  ~CellList(){};
63  };
64 
70  {
71  protected:
72  RealBody &real_body_;
73  Kernel &kernel_;
74  BaseParticles *base_particles_;
75 
77  virtual void clearSplitCellLists(SplitCellLists &split_cell_lists);
79  virtual void updateSplitCellLists(SplitCellLists &split_cell_lists) = 0;
80 
81  public:
83  BaseCellLinkedList(RealBody &real_body, SPHAdaptation &sph_adaptation);
84  virtual ~BaseCellLinkedList(){};
85 
88  virtual void assignBaseParticles(BaseParticles *base_particles) = 0;
89 
91  virtual void UpdateCellLists() = 0;
93  virtual void insertACellLinkedParticleIndex(size_t particle_index, const Vecd &particle_position) = 0;
95  virtual void InsertACellLinkedListDataEntry(size_t particle_index, const Vecd &particle_position) = 0;
97  virtual ListData findNearestListDataEntry(const Vecd &position) = 0;
99  virtual void computingSequence(StdLargeVec<size_t> &sequence) = 0;
101  virtual void tagBodyPartByCell(CellLists &cell_lists, std::function<bool(Vecd, Real)> &check_included) = 0;
103  virtual void tagBodyDomainBoundingCells(StdVec<CellLists> &cell_lists, BoundingBox &body_domain_bounds, int axis) = 0;
105  virtual void tagMirrorBoundingCells(CellLists &cell_lists, BoundingBox &body_domain_bounds, int axis, bool positive) = 0;
106  };
107 
113  class CellLinkedList : public BaseCellLinkedList, public Mesh
114  {
115  protected:
118  MeshDataMatrix<CellList> cell_linked_lists_;
119 
120  virtual void updateSplitCellLists(SplitCellLists &split_cell_lists) override;
121 
122  public:
123  CellLinkedList(BoundingBox tentative_bounds, Real grid_spacing,
124  RealBody &real_body, SPHAdaptation &sph_adaptation);
125  virtual ~CellLinkedList() { deleteMeshDataMatrix(); };
126 
127  void allocateMeshDataMatrix();
128  void deleteMeshDataMatrix();
130  virtual void assignBaseParticles(BaseParticles *base_particles) override;
131  void clearCellLists();
132  void UpdateCellListData();
133  virtual void UpdateCellLists() override;
134  void insertACellLinkedParticleIndex(size_t particle_index, const Vecd &particle_position) override;
135  void InsertACellLinkedListDataEntry(size_t particle_index, const Vecd &particle_position) override;
136  virtual ListData findNearestListDataEntry(const Vecd &position) override;
137  virtual void computingSequence(StdLargeVec<size_t> &sequence) override;
138  virtual void tagBodyPartByCell(CellLists &cell_lists, std::function<bool(Vecd, Real)> &check_included) override;
139  virtual void tagBodyDomainBoundingCells(StdVec<CellLists> &cell_lists, BoundingBox &body_domain_bounds, int axis) override;
140  virtual void tagMirrorBoundingCells(CellLists &cell_lists, BoundingBox &body_domain_bounds, int axis, bool positive) override;
141  virtual void writeMeshFieldToPlt(std::ofstream &output_file) override;
142 
144  template <typename GetParticleIndex, typename GetSearchDepth, typename GetNeighborRelation>
145  void searchNeighborsByParticles(size_t total_real_particles, BaseParticles &source_particles,
146  ParticleConfiguration &particle_configuration, GetParticleIndex &get_particle_index,
147  GetSearchDepth &get_search_depth, GetNeighborRelation &get_neighbor_relation);
148 
150  template <typename GetParticleIndex, typename GetSearchDepth, typename GetNeighborRelation, typename PartParticleCheck>
151  void searchNeighborPartsByParticles(size_t total_real_particles, BaseParticles &source_particles,
152  ParticleConfiguration &particle_configuration, GetParticleIndex &get_particle_index,
153  GetSearchDepth &get_search_depth, GetNeighborRelation &get_neighbor_relation,
154  PartParticleCheck &part_check);
155 
156  MeshDataMatrix<CellList> getCellLists() const { return cell_linked_lists_; }
157  };
158 
164  class MultilevelCellLinkedList : public MultilevelMesh<BaseCellLinkedList, CellLinkedList, RefinedMesh<CellLinkedList>>
165  {
166  protected:
167  StdLargeVec<Real> &h_ratio_;
168  virtual void updateSplitCellLists(SplitCellLists &split_cell_lists) override{};
170  inline size_t getMeshLevel(Real particle_cutoff_radius);
171 
172  public:
173  MultilevelCellLinkedList(BoundingBox tentative_bounds, Real reference_grid_spacing,
174  size_t total_levels, RealBody &real_body, SPHAdaptation &sph_adaptation);
175  virtual ~MultilevelCellLinkedList(){};
176 
177  virtual void assignBaseParticles(BaseParticles *base_particles) override;
178  virtual void UpdateCellLists() override;
179  void insertACellLinkedParticleIndex(size_t particle_index, const Vecd &particle_position) override;
180  void InsertACellLinkedListDataEntry(size_t particle_index, const Vecd &particle_position) override;
181  virtual ListData findNearestListDataEntry(const Vecd &position) override { return ListData(0, Vecd(0)); };
182  virtual void computingSequence(StdLargeVec<size_t> &sequence) override{};
183  virtual void tagBodyPartByCell(CellLists &cell_lists, std::function<bool(Vecd, Real)> &check_included) override;
184  virtual void tagBodyDomainBoundingCells(StdVec<CellLists> &cell_lists, BoundingBox &body_domain_bounds, int axis) override{};
185  virtual void tagMirrorBoundingCells(CellLists &cell_lists, BoundingBox &body_domain_bounds, int axis, bool positive) override{};
186  };
187 }
188 #endif // MESH_CELL_LINKED_LIST_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
This is the base classes of mesh, which is used to describe ordered and indexed data sets...
Particles with essential (geometric and kinematic) data. There are three types of particles, all par...
Definition: base_particles.h:81
virtual void clearSplitCellLists(SplitCellLists &split_cell_lists)
Definition: cell_linked_list.cpp:22
virtual void tagMirrorBoundingCells(CellLists &cell_lists, BoundingBox &body_domain_bounds, int axis, bool positive)=0
Defining a mesh cell linked list for a body. The meshes for all bodies share the same global coordina...
Definition: cell_linked_list.h:113
virtual void tagMirrorBoundingCells(CellLists &cell_lists, BoundingBox &body_domain_bounds, int axis, bool positive) override
Definition: cell_linked_list.h:185
StdVec< size_t > IndexVector
Definition: sph_data_containers.h:37
virtual void tagBodyDomainBoundingCells(StdVec< CellLists > &cell_lists, BoundingBox &body_domain_bounds, int axis) override
Definition: cell_linked_list_supplementary.cpp:154
virtual void tagBodyPartByCell(CellLists &cell_lists, std::function< bool(Vecd, Real)> &check_included) override
Definition: cell_linked_list_supplementary.cpp:134
ConcurrentIndexVector concurrent_particle_indexes_
Definition: cell_linked_list.h:55
virtual void UpdateCellLists() override
Definition: cell_linked_list.cpp:35
StdLargeVec< CellList * > CellLists
Definition: sph_data_containers.h:46
virtual void assignBaseParticles(BaseParticles *base_particles)=0
Abstract base class for cell-based mesh by introducing number of cells, buffer width and mesh-based d...
Definition: base_mesh.h:106
There are the classes for neighboring particles. It saves the information for carring out pair intera...
virtual void computingSequence(StdLargeVec< size_t > &sequence) override
Definition: cell_linked_list.cpp:64
The linked list for one cell.
Definition: cell_linked_list.h:51
virtual ListData findNearestListDataEntry(const Vecd &position) override
Definition: cell_linked_list.h:181
virtual void UpdateCellLists()=0
virtual void tagMirrorBoundingCells(CellLists &cell_lists, BoundingBox &body_domain_bounds, int axis, bool positive) override
Definition: cell_linked_list_supplementary.cpp:186
LargeVec< size_t > ConcurrentIndexVector
Definition: sph_data_containers.h:39
virtual void insertACellLinkedParticleIndex(size_t particle_index, const Vecd &particle_position)=0
virtual void updateSplitCellLists(SplitCellLists &split_cell_lists) override
Definition: cell_linked_list.h:168
MeshDataMatrix< CellList > cell_linked_lists_
Definition: cell_linked_list.h:118
StdLargeVec< ListData > ListDataVector
Definition: sph_data_containers.h:44
Abstract class for mesh cell linked list.
Definition: cell_linked_list.h:69
Abstract base class of a general SPH kernel function which is a smoothed Dirac delta function...
Definition: base_kernel.h:63
virtual void tagBodyDomainBoundingCells(StdVec< CellLists > &cell_lists, BoundingBox &body_domain_bounds, int axis)=0
Abstract base class for the field data saved on a mesh.
Definition: base_mesh.h:128
StdLargeVec< Neighborhood > ParticleConfiguration
Definition: neighbor_relation.h:66
std::pair< size_t, Vecd > ListData
Definition: sph_data_containers.h:42
BaseCellLinkedList(RealBody &real_body, SPHAdaptation &sph_adaptation)
Definition: cell_linked_list.cpp:17
Multi-level Meshes with successively double the resolution.
Definition: base_mesh.h:166
void insertACellLinkedParticleIndex(size_t particle_index, const Vecd &particle_position) override
Definition: cell_linked_list.cpp:100
virtual void assignBaseParticles(BaseParticles *base_particles) override
Definition: cell_linked_list.cpp:113
virtual void updateSplitCellLists(SplitCellLists &split_cell_lists)=0
ListDataVector cell_list_data_
Definition: cell_linked_list.h:57
virtual void updateSplitCellLists(SplitCellLists &split_cell_lists) override
Definition: cell_linked_list_supplementary.cpp:70
Defining a multilevel level set for a complex region.
Definition: cell_linked_list.h:164
size_t getMeshLevel(Real particle_cutoff_radius)
Definition: cell_linked_list.cpp:87
void InsertACellLinkedListDataEntry(size_t particle_index, const Vecd &particle_position) override
Definition: cell_linked_list_supplementary.cpp:99
void deleteMeshDataMatrix()
Definition: cell_linked_list_supplementary.cpp:26
IndexVector real_particle_indexes_
Definition: cell_linked_list.h:59
virtual void InsertACellLinkedListDataEntry(size_t particle_index, const Vecd &particle_position)=0
virtual void writeMeshFieldToPlt(std::ofstream &output_file) override
Definition: cell_linked_list_supplementary.cpp:222
virtual void assignBaseParticles(BaseParticles *base_particles) override
Definition: cell_linked_list.cpp:59
void searchNeighborPartsByParticles(size_t total_real_particles, BaseParticles &source_particles, ParticleConfiguration &particle_configuration, GetParticleIndex &get_particle_index, GetSearchDepth &get_search_depth, GetNeighborRelation &get_neighbor_relation, PartParticleCheck &part_check)
virtual ListData findNearestListDataEntry(const Vecd &position) override
Definition: cell_linked_list_supplementary.cpp:105
void InsertACellLinkedListDataEntry(size_t particle_index, const Vecd &particle_position) override
Definition: cell_linked_list.cpp:107
virtual void computingSequence(StdLargeVec< size_t > &sequence)=0
virtual ListData findNearestListDataEntry(const Vecd &position)=0
virtual void UpdateCellLists() override
Definition: cell_linked_list.cpp:122
void insertACellLinkedParticleIndex(size_t particle_index, const Vecd &particle_position) override
Definition: cell_linked_list_supplementary.cpp:93
Derived body with inner particle configuration or inner interactions. After construction, the particle and material must be specified.
Definition: base_body.h:182
virtual void tagBodyPartByCell(CellLists &cell_lists, std::function< bool(Vecd, Real)> &check_included) override
Definition: cell_linked_list.cpp:153
virtual void tagBodyPartByCell(CellLists &cell_lists, std::function< bool(Vecd, Real)> &check_included)=0
void allocateMeshDataMatrix()
Definition: cell_linked_list_supplementary.cpp:21
virtual void tagBodyDomainBoundingCells(StdVec< CellLists > &cell_lists, BoundingBox &body_domain_bounds, int axis) override
Definition: cell_linked_list.h:184
void searchNeighborsByParticles(size_t total_real_particles, BaseParticles &source_particles, ParticleConfiguration &particle_configuration, GetParticleIndex &get_particle_index, GetSearchDepth &get_search_depth, GetNeighborRelation &get_neighbor_relation)
Definition: cell_linked_list.hpp:16
Definition: solid_body_supplementary.cpp:9
virtual void computingSequence(StdLargeVec< size_t > &sequence) override
Definition: cell_linked_list.h:182