Skip to content

Commit c33682b

Browse files
authored
Merge pull request #557 from Xiangyu-Hu/refactory/revise_list_data
reverse the list data by using pair as before.
2 parents 503afe9 + db943b5 commit c33682b

File tree

11 files changed

+67
-80
lines changed

11 files changed

+67
-80
lines changed

src/for_2D_build/meshes/cell_linked_list_supplementary.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ void CellLinkedList::clearCellLists()
3737
void CellLinkedList::UpdateCellListData(BaseParticles &base_particles)
3838
{
3939
StdLargeVec<Vecd> &pos = base_particles.pos_;
40-
StdLargeVec<Real> &Vol = base_particles.Vol_;
4140
mesh_parallel_for(
4241
MeshRange(Array2i::Zero(), all_cells_),
4342
[&](int i, int j)
@@ -47,7 +46,7 @@ void CellLinkedList::UpdateCellListData(BaseParticles &base_particles)
4746
for (size_t s = 0; s != cell_list.size(); ++s)
4847
{
4948
size_t index = cell_list[s];
50-
cell_data_lists_[i][j].emplace_back(std::make_tuple(index, pos[index], Vol[index]));
49+
cell_data_lists_[i][j].emplace_back(std::make_pair(index, pos[index]));
5150
}
5251
});
5352
}
@@ -75,18 +74,17 @@ void CellLinkedList ::insertParticleIndex(size_t particle_index, const Vecd &par
7574
cell_index_lists_[cellpos[0]][cellpos[1]].emplace_back(particle_index);
7675
}
7776
//=================================================================================================//
78-
void CellLinkedList ::InsertListDataEntry(
79-
size_t particle_index, const Vecd &particle_position, Real volumetric)
77+
void CellLinkedList ::InsertListDataEntry(size_t particle_index, const Vecd &particle_position)
8078
{
8179
Array2i cellpos = CellIndexFromPosition(particle_position);
82-
cell_data_lists_[cellpos[0]][cellpos[1]].emplace_back(
83-
std::make_tuple(particle_index, particle_position, volumetric));
80+
cell_data_lists_[cellpos[0]][cellpos[1]]
81+
.emplace_back(std::make_pair(particle_index, particle_position));
8482
}
8583
//=================================================================================================//
8684
ListData CellLinkedList::findNearestListDataEntry(const Vecd &position)
8785
{
8886
Real min_distance_sqr = MaxReal;
89-
ListData nearest_entry(MaxSize_t, MaxReal * Vecd::Ones(), MaxReal);
87+
ListData nearest_entry(MaxSize_t, MaxReal * Vecd::Ones());
9088

9189
Array2i cell = CellIndexFromPosition(position);
9290
mesh_for_each(

src/for_3D_build/meshes/cell_linked_list_supplementary.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ void CellLinkedList::clearCellLists()
3535
void CellLinkedList::UpdateCellListData(BaseParticles &base_particles)
3636
{
3737
StdLargeVec<Vecd> &pos = base_particles.pos_;
38-
StdLargeVec<Real> &Vol = base_particles.Vol_;
3938
mesh_parallel_for(
4039
MeshRange(Array3i::Zero(), all_cells_),
4140
[&](int i, int j, int k)
@@ -45,7 +44,7 @@ void CellLinkedList::UpdateCellListData(BaseParticles &base_particles)
4544
for (size_t s = 0; s != cell_list.size(); ++s)
4645
{
4746
size_t index = cell_list[s];
48-
cell_data_lists_[i][j][k].emplace_back(std::make_tuple(index, pos[index], Vol[index]));
47+
cell_data_lists_[i][j][k].emplace_back(std::make_pair(index, pos[index]));
4948
}
5049
});
5150
}
@@ -72,18 +71,17 @@ void CellLinkedList ::insertParticleIndex(size_t particle_index, const Vecd &par
7271
cell_index_lists_[cell_pos[0]][cell_pos[1]][cell_pos[2]].emplace_back(particle_index);
7372
}
7473
//=================================================================================================//
75-
void CellLinkedList ::InsertListDataEntry(size_t particle_index,
76-
const Vecd &particle_position, Real volumetric)
74+
void CellLinkedList ::InsertListDataEntry(size_t particle_index, const Vecd &particle_position)
7775
{
7876
Array3i cell_pos = CellIndexFromPosition(particle_position);
7977
cell_data_lists_[cell_pos[0]][cell_pos[1]][cell_pos[2]].emplace_back(
80-
std::make_tuple(particle_index, particle_position, volumetric));
78+
std::make_pair(particle_index, particle_position));
8179
}
8280
//=================================================================================================//
8381
ListData CellLinkedList::findNearestListDataEntry(const Vecd &position)
8482
{
8583
Real min_distance_sqr = MaxReal;
86-
ListData nearest_entry = std::make_tuple(MaxSize_t, MaxReal * Vecd::Ones(), MaxReal);
84+
ListData nearest_entry = std::make_pair(MaxSize_t, MaxReal * Vecd::Ones());
8785

8886
Array3i cell = CellIndexFromPosition(position);
8987
mesh_for_each(

src/for_3D_build/particle_generator/particle_generator_network.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ParticleGenerator<Network>::
2323
Vecd end_direction = displacement / (displacement.norm() + TinyReal);
2424
/** Add initial particle to the first branch of the tree. */
2525
growAParticleOnBranch(tree_->root_, starting_pnt_, end_direction);
26-
cell_linked_list_.InsertListDataEntry(0, pos_[0], segment_length_);
26+
cell_linked_list_.InsertListDataEntry(0, pos_[0]);
2727
}
2828
//=================================================================================================//
2929
void ParticleGenerator<Network>::
@@ -157,7 +157,7 @@ bool ParticleGenerator<Network>::
157157

158158
for (const size_t &particle_idx : new_branch->inner_particles_)
159159
{
160-
cell_linked_list_.InsertListDataEntry(particle_idx, pos_[particle_idx], segment_length_);
160+
cell_linked_list_.InsertListDataEntry(particle_idx, pos_[particle_idx]);
161161
}
162162
}
163163

src/shared/bodies/complex_bodies/tree_body.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ void TreeBody::buildParticleConfiguration(ParticleConfiguration &particle_config
2121
neighboring_ids.push_back(branches_[1]->inner_particles_[1]);
2222
/** Build configuration. */
2323
const StdLargeVec<Vecd> &pos = base_particles_->pos_;
24-
const StdLargeVec<Real> &Vol = base_particles_->Vol_;
2524
NeighborBuilderInner neighbor_relation_inner(*this);
2625
for (size_t n = 0; n != neighboring_ids.size(); ++n)
2726
{
2827
size_t index_j = neighboring_ids[n];
29-
ListData list_data_j = std::make_tuple(index_j, pos[index_j], Vol[index_j]);
28+
ListData list_data_j = std::make_pair(index_j, pos[index_j]);
3029
Neighborhood &neighborhood = particle_configuration[particle_id];
3130
neighbor_relation_inner(neighborhood, pos[particle_id], particle_id, list_data_j);
3231
}
@@ -93,7 +92,7 @@ void TreeBody::buildParticleConfiguration(ParticleConfiguration &particle_config
9392
for (size_t n = 0; n != neighboring_ids.size(); ++n)
9493
{
9594
size_t index_j = neighboring_ids[n];
96-
ListData list_data_j = std::make_tuple(index_j, pos[index_j], Vol[index_j]);
95+
ListData list_data_j = std::make_pair(index_j, pos[index_j]);
9796
Neighborhood &neighborhood = particle_configuration[particle_id];
9897
neighbor_relation_inner(neighborhood, pos[particle_id], particle_id, list_data_j);
9998
}
@@ -165,7 +164,7 @@ void TreeBody::buildParticleConfiguration(ParticleConfiguration &particle_config
165164
for (size_t n = 0; n != neighboring_ids.size(); ++n)
166165
{
167166
size_t index_j = neighboring_ids[n];
168-
ListData list_data_j = std::make_tuple(index_j, pos[index_j], Vol[index_j]);
167+
ListData list_data_j = std::make_pair(index_j, pos[index_j]);
169168
Neighborhood &neighborhood = particle_configuration[particle_id];
170169
neighbor_relation_inner(neighborhood, pos[particle_id], particle_id, list_data_j);
171170
}
@@ -203,7 +202,7 @@ void TreeBody::buildParticleConfiguration(ParticleConfiguration &particle_config
203202
for (size_t n = 0; n != neighboring_ids.size(); ++n)
204203
{
205204
size_t index_j = neighboring_ids[n];
206-
ListData list_data_j = std::make_tuple(index_j, pos[index_j], Vol[index_j]);
205+
ListData list_data_j = std::make_pair(index_j, pos[index_j]);
207206
Neighborhood &neighborhood = particle_configuration[particle_id];
208207
neighbor_relation_inner(neighborhood, pos[particle_id], particle_id, list_data_j);
209208
}

src/shared/common/sph_data_containers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ using ConcurrentIndexVector = ConcurrentVec<size_t>;
5858
using ParticlesBound = std::pair<size_t, size_t>;
5959

6060
/** List data pair: first for indexes, second for particle position. */
61-
using ListData = std::tuple<size_t, Vecd, Real>;
61+
using ListData = std::pair<size_t, Vecd>;
6262
using ListDataVector = StdLargeVec<ListData>;
6363
using DataListsInCells = StdLargeVec<ListDataVector *>;
6464
using ConcurrentCellLists = ConcurrentVec<ConcurrentIndexVector *>;

src/shared/meshes/cell_linked_list.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,16 @@ size_t MultilevelCellLinkedList::getMeshLevel(Real particle_cutoff_radius)
100100
return 999; // means an error in level searching
101101
};
102102
//=================================================================================================//
103-
void MultilevelCellLinkedList::
104-
insertParticleIndex(size_t particle_index, const Vecd &particle_position)
103+
void MultilevelCellLinkedList::insertParticleIndex(size_t particle_index, const Vecd &particle_position)
105104
{
106105
size_t level = getMeshLevel(kernel_.CutOffRadius(h_ratio_[particle_index]));
107106
mesh_levels_[level]->insertParticleIndex(particle_index, particle_position);
108107
}
109108
//=================================================================================================//
110-
void MultilevelCellLinkedList::
111-
InsertListDataEntry(size_t particle_index, const Vecd &particle_position, Real volumetric)
109+
void MultilevelCellLinkedList::InsertListDataEntry(size_t particle_index, const Vecd &particle_position)
112110
{
113111
size_t level = getMeshLevel(kernel_.CutOffRadius(h_ratio_[particle_index]));
114-
mesh_levels_[level]->InsertListDataEntry(particle_index, particle_position, volumetric);
112+
mesh_levels_[level]->InsertListDataEntry(particle_index, particle_position);
115113
}
116114
//=================================================================================================//
117115
void MultilevelCellLinkedList::UpdateCellLists(BaseParticles &base_particles)

src/shared/meshes/cell_linked_list.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class BaseCellLinkedList : public BaseMeshField
6969
/** Insert a cell-linked_list entry to the concurrent index list. */
7070
virtual void insertParticleIndex(size_t particle_index, const Vecd &particle_position) = 0;
7171
/** Insert a cell-linked_list entry of the index and particle position pair. */
72-
virtual void InsertListDataEntry(size_t particle_index, const Vecd &particle_position, Real volumetric) = 0;
72+
virtual void InsertListDataEntry(size_t particle_index, const Vecd &particle_position) = 0;
7373
/** find the nearest list data entry */
7474
virtual ListData findNearestListDataEntry(const Vecd &position) = 0;
7575
/** computing the sequence which indicate the order of sorted particle data */
@@ -117,7 +117,7 @@ class CellLinkedList : public BaseCellLinkedList, public Mesh
117117
void UpdateCellListData(BaseParticles &base_particles);
118118
virtual void UpdateCellLists(BaseParticles &base_particles) override;
119119
void insertParticleIndex(size_t particle_index, const Vecd &particle_position) override;
120-
void InsertListDataEntry(size_t particle_index, const Vecd &particle_position, Real volumetric) override;
120+
void InsertListDataEntry(size_t particle_index, const Vecd &particle_position) override;
121121
virtual ListData findNearestListDataEntry(const Vecd &position) override;
122122
virtual StdLargeVec<size_t> &computingSequence(BaseParticles &base_particles) override;
123123
virtual void tagBodyPartByCell(ConcurrentCellLists &cell_lists, std::function<bool(Vecd, Real)> &check_included) override;
@@ -152,8 +152,8 @@ class MultilevelCellLinkedList : public MultilevelMesh<BaseCellLinkedList, CellL
152152

153153
virtual void UpdateCellLists(BaseParticles &base_particles) override;
154154
void insertParticleIndex(size_t particle_index, const Vecd &particle_position) override;
155-
void InsertListDataEntry(size_t particle_index, const Vecd &particle_position, Real volumetric) override;
156-
virtual ListData findNearestListDataEntry(const Vecd &position) override { return ListData(0, Vecd::Zero(), 0); };
155+
void InsertListDataEntry(size_t particle_index, const Vecd &particle_position) override;
156+
virtual ListData findNearestListDataEntry(const Vecd &position) override { return ListData(0, Vecd::Zero()); }; // mocking, not implemented
157157
virtual StdLargeVec<size_t> &computingSequence(BaseParticles &base_particles) override;
158158
virtual void tagBodyPartByCell(ConcurrentCellLists &cell_lists, std::function<bool(Vecd, Real)> &check_included) override;
159159
virtual void tagBoundingCells(StdVec<CellLists> &cell_data_lists, const BoundingBox &bounding_bounds, int axis) override{};

src/shared/particle_dynamics/general_dynamics/domian_bouding/domain_bounding.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ void PeriodicConditionUsingCellLinkedList::
2727
Vecd translated_position = particle_position - periodic_translation_;
2828
/** insert ghost particle to cell linked list */
2929
mutex_cell_list_entry_.lock();
30-
cell_linked_list_.InsertListDataEntry(std::get<0>(cell_list_data[num]),
31-
translated_position, std::get<2>(cell_list_data[num]));
30+
cell_linked_list_.InsertListDataEntry(cell_list_data[num].first, translated_position);
3231
mutex_cell_list_entry_.unlock();
3332
}
3433
}
@@ -46,8 +45,7 @@ void PeriodicConditionUsingCellLinkedList::
4645
Vecd translated_position = particle_position + periodic_translation_;
4746
/** insert ghost particle to cell linked list */
4847
mutex_cell_list_entry_.lock();
49-
cell_linked_list_.InsertListDataEntry(std::get<0>(cell_list_data[num]),
50-
translated_position, std::get<2>(cell_list_data[num]));
48+
cell_linked_list_.InsertListDataEntry(cell_list_data[num].first, translated_position);
5149
mutex_cell_list_entry_.unlock();
5250
}
5351
}

src/shared/particle_dynamics/general_dynamics/domian_bouding/ghost_bounding.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ void PeriodicConditionUsingGhostParticles::CreatPeriodicGhostParticles::checkLow
7474
base_particles_.updateGhostParticle(lower_ghost_bound_.second, index_i);
7575
pos_[lower_ghost_bound_.second] = particle_position + periodic_translation_;
7676
/** insert ghost particle to cell linked list */
77-
cell_linked_list_.InsertListDataEntry(lower_ghost_bound_.second,
78-
pos_[lower_ghost_bound_.second], Vol_[index_i]);
77+
cell_linked_list_.InsertListDataEntry(lower_ghost_bound_.second, pos_[lower_ghost_bound_.second]);
7978
lower_ghost_bound_.second++;
8079
ghost_boundary_.checkWithinGhostSize(lower_ghost_bound_);
8180
mutex_create_ghost_particle_.unlock();
@@ -92,8 +91,7 @@ void PeriodicConditionUsingGhostParticles::CreatPeriodicGhostParticles::checkUpp
9291
base_particles_.updateGhostParticle(upper_ghost_bound_.second, index_i);
9392
pos_[upper_ghost_bound_.second] = particle_position - periodic_translation_;
9493
/** insert ghost particle to cell linked list */
95-
cell_linked_list_.InsertListDataEntry(upper_ghost_bound_.second,
96-
pos_[upper_ghost_bound_.second], Vol_[index_i]);
94+
cell_linked_list_.InsertListDataEntry(upper_ghost_bound_.second, pos_[upper_ghost_bound_.second]);
9795
upper_ghost_bound_.second++;
9896
ghost_boundary_.checkWithinGhostSize(upper_ghost_bound_);
9997
mutex_create_ghost_particle_.unlock();

0 commit comments

Comments
 (0)