11#include " cell_linked_list.h"
22
33#include " base_particles.hpp"
4- #include " mesh_iterators.hpp"
54
65namespace SPH
76{
87// =================================================================================================//
9- void CellLinkedList ::allocateMeshDataMatrix ()
10- {
11- Allocate2dArray (cell_index_lists_, all_cells_);
12- Allocate2dArray (cell_data_lists_, all_cells_);
13-
14- mesh_parallel_for (MeshRange (Array2i::Zero (), all_cells_),
15- [&](int i, int j)
16- {
17- cell_index_lists_[i][j].reserve (12 );
18- cell_data_lists_[i][j].reserve (12 );
19- });
20- }
21- // =================================================================================================//
22- void CellLinkedList ::deleteMeshDataMatrix ()
23- {
24- Delete2dArray (cell_index_lists_, all_cells_);
25- Delete2dArray (cell_data_lists_, all_cells_);
26- }
27- // =================================================================================================//
28- void CellLinkedList::clearCellLists ()
29- {
30- mesh_parallel_for (MeshRange (Array2i::Zero (), all_cells_),
31- [&](int i, int j)
32- {
33- cell_index_lists_[i][j].clear ();
34- });
35- }
36- // =================================================================================================//
37- void CellLinkedList::UpdateCellListData (BaseParticles &base_particles)
38- {
39- StdLargeVec<Vecd> &pos = base_particles.ParticlePositions ();
40- mesh_parallel_for (
41- MeshRange (Array2i::Zero (), all_cells_),
42- [&](int i, int j)
43- {
44- cell_data_lists_[i][j].clear ();
45- ConcurrentIndexVector &cell_list = cell_index_lists_[i][j];
46- for (size_t s = 0 ; s != cell_list.size (); ++s)
47- {
48- size_t index = cell_list[s];
49- cell_data_lists_[i][j].emplace_back (std::make_pair (index, pos[index]));
50- }
51- });
52- }
53- // =================================================================================================//
54- void CellLinkedList::updateSplitCellLists (SplitCellLists &split_cell_lists)
55- {
56- // clear the data
57- clearSplitCellLists (split_cell_lists);
58- mesh_parallel_for (
59- MeshRange (Array2i::Zero (), all_cells_),
60- [&](int i, int j)
61- {
62- size_t real_particles_in_cell = cell_index_lists_[i][j].size ();
63- if (real_particles_in_cell != 0 )
64- {
65- split_cell_lists[transferMeshIndexTo1D (Array2i (3 , 3 ), Array2i (i % 3 , j % 3 ))]
66- .push_back (&cell_index_lists_[i][j]);
67- }
68- });
69- }
70- // =================================================================================================//
71- void CellLinkedList ::insertParticleIndex (size_t particle_index, const Vecd &particle_position)
72- {
73- Array2i cellpos = CellIndexFromPosition (particle_position);
74- cell_index_lists_[cellpos[0 ]][cellpos[1 ]].emplace_back (particle_index);
75- }
76- // =================================================================================================//
77- void CellLinkedList ::InsertListDataEntry (size_t particle_index, const Vecd &particle_position)
78- {
79- Array2i cellpos = CellIndexFromPosition (particle_position);
80- cell_data_lists_[cellpos[0 ]][cellpos[1 ]]
81- .emplace_back (std::make_pair (particle_index, particle_position));
82- }
83- // =================================================================================================//
84- ListData CellLinkedList::findNearestListDataEntry (const Vecd &position)
85- {
86- Real min_distance_sqr = MaxReal;
87- ListData nearest_entry (MaxSize_t, MaxReal * Vecd::Ones ());
88-
89- Array2i cell = CellIndexFromPosition (position);
90- mesh_for_each (
91- Array2i::Zero ().max (cell - Array2i::Ones ()),
92- all_cells_.min (cell + 2 * Array2i::Ones ()),
93- [&](int l, int m)
94- {
95- ListDataVector &target_particles = cell_data_lists_[l][m];
96- for (const ListData &list_data : target_particles)
97- {
98- Real distance_sqr = (position - std::get<1 >(list_data)).squaredNorm ();
99- if (distance_sqr < min_distance_sqr)
100- {
101- min_distance_sqr = distance_sqr;
102- nearest_entry = list_data;
103- }
104- }
105- });
106- return nearest_entry;
107- }
108- // =================================================================================================//
109- void CellLinkedList::
110- tagBodyPartByCell (ConcurrentCellLists &cell_lists, std::function<bool (Vecd, Real)> &check_included)
111- {
112- mesh_parallel_for (
113- MeshRange (Array2i::Zero (), all_cells_),
114- [&](int i, int j)
115- {
116- bool is_included = false ;
117- mesh_for_each (
118- Array2i::Zero ().max (Array2i (i, j) - Array2i::Ones ()),
119- all_cells_.min (Array2i (i, j) + 2 * Array2i::Ones ()),
120- [&](int l, int m)
121- {
122- if (check_included (CellPositionFromIndex (Array2i (l, m)), grid_spacing_))
123- {
124- is_included = true ;
125- }
126- });
127- if (is_included == true )
128- cell_lists.push_back (&cell_index_lists_[i][j]);
129- });
130- }
131- // =================================================================================================//
1328void CellLinkedList::
1339 tagBoundingCells (StdVec<CellLists> &cell_data_lists, const BoundingBox &bounding_bounds, int axis)
13410{
@@ -145,8 +21,8 @@ void CellLinkedList::
14521 Array2i cell = Array2i::Zero ();
14622 cell[axis] = i;
14723 cell[second_axis] = j;
148- cell_data_lists[0 ].first .push_back (&cell_index_lists_[ cell[ 0 ]][cell[ 1 ]] );
149- cell_data_lists[0 ].second .push_back (&cell_data_lists_[ cell[ 0 ]][cell[ 1 ]] );
24+ cell_data_lists[0 ].first .push_back (&getCellDataList ( cell_index_lists_, cell) );
25+ cell_data_lists[0 ].second .push_back (&getCellDataList ( cell_data_lists_, cell) );
15026 }
15127
15228 // upper bound cells
@@ -158,8 +34,8 @@ void CellLinkedList::
15834 Array2i cell = Array2i::Zero ();
15935 cell[axis] = i;
16036 cell[second_axis] = j;
161- cell_data_lists[1 ].first .push_back (&cell_index_lists_[ cell[ 0 ]][cell[ 1 ]] );
162- cell_data_lists[1 ].second .push_back (&cell_data_lists_[ cell[ 0 ]][cell[ 1 ]] );
37+ cell_data_lists[1 ].first .push_back (&getCellDataList ( cell_index_lists_, cell) );
38+ cell_data_lists[1 ].second .push_back (&getCellDataList ( cell_data_lists_, cell) );
16339 }
16440}
16541// =============================================================================================//
@@ -202,7 +78,7 @@ void CellLinkedList::writeMeshFieldToPlt(std::ofstream &output_file)
20278 {
20379 for (int i = 0 ; i != number_of_operation[0 ]; ++i)
20480 {
205- output_file << cell_index_lists_[i][j] .size () << " " ;
81+ output_file << getCellDataList ( cell_index_lists_, Array2i (i, j)) .size () << " " ;
20682 }
20783 output_file << " \n " ;
20884 }
0 commit comments