Skip to content

Commit 846dd40

Browse files
committed
Don't use double as map key
1 parent 1da6a22 commit 846dd40

File tree

1 file changed

+37
-46
lines changed

1 file changed

+37
-46
lines changed

dccrg.hpp

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ template <
819819
return neighbors;
820820
}
821821

822-
void set_partitioning_neighborhood_id (int id) {
822+
void set_partitioning_neighborhood (int id) {
823823
partitioning_neighborhood_id = id;
824824
}
825825

@@ -2827,23 +2827,23 @@ template <
28272827
{
28282828
std::array<double, 3> ret;
28292829
for (int i = 0; i < 3; ++i) {
2830-
ret[i] = static_cast<double>(in[i]) / (in[3] > 0 ? in[3] : 1.0);
2830+
ret[i] = static_cast<double>(in[i]) / static_cast<double>(in[3] > 0 ? in[3] : 1);
28312831
}
28322832
return ret;
28332833
}
28342834

2835-
std::map<double, std::vector<uint64_t>> get_vlasov_neighbors(
2835+
std::map<int, std::vector<uint64_t>> get_vlasov_neighbors(
28362836
const uint64_t cell,
28372837
const int neighborhood_id,
28382838
const int dimension,
28392839
const int stencil_width
28402840
) const {
2841-
std::map<double, std::vector<uint64_t>> ret;
2841+
std::map<int, std::vector<uint64_t>> ret;
28422842
int my_ref {mapping.get_refinement_level(cell)};
2843-
28442843
std::vector<std::pair<uint64_t, std::array<int, 4>>> neighs;
28452844
const auto* p = get_neighbors_of(cell, neighborhood_id);
28462845
if (!p) {
2846+
std::cerr << "Cell " << cell << ", neighborhood " << neighborhood_id << ", dimension " << dimension << " not found" << std::endl;
28472847
return ret;
28482848
}
28492849

@@ -2855,49 +2855,54 @@ template <
28552855
}
28562856
);
28572857

2858-
auto it = neighs.begin();
2859-
while (it < neighs.end() && it->second[dimension] < 0) {
2858+
auto it = neighs.cbegin();
2859+
while (it < neighs.cend() && it->second[dimension] < 0) {
28602860
++it;
28612861
}
28622862

28632863
int found {0};
2864-
for (auto neg = it - 1; neg >= neighs.begin(); --neg) {
2864+
std::uint64_t previous_cell {error_cell};
2865+
double previous_offset {0.0};
2866+
for (auto neg = std::make_reverse_iterator(it); neg != neighs.crend(); ++neg) {
28652867
double offset = distance_to_double(neg->second)[dimension];
2866-
if (ret.count(offset)) {
2867-
ret[offset].push_back(neg->first);
2868-
} else if (found < stencil_width) {
2869-
++found;
2870-
ret[offset] = std::vector<uint64_t> {neg->first};
2871-
} else {
2872-
break;
2868+
if (neg->first == previous_cell || neg->first == error_cell) {
2869+
continue;
2870+
} else if (offset < previous_offset) {
2871+
if (++found > stencil_width)
2872+
break;
28732873
}
2874+
2875+
ret[-found].push_back(neg->first);
2876+
previous_cell = neg->first;
28742877
}
28752878

2876-
while (it < neighs.end() && it->second[dimension] <= 0) {
2879+
while (it < neighs.cend() && it->second[dimension] <= 0) {
28772880
++it;
28782881
}
28792882

28802883
found = 0;
2881-
for (auto pos = it; pos < neighs.end(); ++pos) {
2884+
previous_cell = error_cell;
2885+
previous_offset = 0.0;
2886+
for (auto pos = it; pos != neighs.cend(); ++pos) {
28822887
double offset = distance_to_double(pos->second)[dimension];
2883-
if (ret.count(offset)) {
2884-
ret[offset].push_back(pos->first);
2885-
} else if (found < stencil_width) {
2886-
++found;
2887-
ret[offset] = std::vector<uint64_t> {pos->first};
2888-
} else {
2889-
break;
2888+
if (pos->first == previous_cell || pos->first == error_cell) {
2889+
continue;
2890+
} else if (offset > previous_offset) {
2891+
if (++found > stencil_width)
2892+
break;
28902893
}
2891-
}
2894+
2895+
ret[found].push_back(pos->first);
2896+
previous_cell = pos->first;
2897+
}
28922898

28932899
return ret;
28942900
}
28952901

28962902
// Get actual Vlasov stencil neighbors
28972903
// Assumes linear 3 linear stencils from neighborhood_id to neighborhood_id + 2
28982904
std::set<uint64_t> get_vlasov_neighbors(
2899-
const uint64_t cell,
2900-
const int neighborhood_id
2905+
const uint64_t cell
29012906
) const {
29022907
int stencil_width {0};
29032908
switch (neighborhood_length) {
@@ -2917,7 +2922,7 @@ template <
29172922

29182923
std::set<uint64_t> ret;
29192924
for (int dim = 0; dim < 3; ++dim) {
2920-
for (auto& [dist, cells] : get_vlasov_neighbors(cell, neighborhood_id + dim, dim, stencil_width)) {
2925+
for (auto& [dist, cells] : get_vlasov_neighbors(cell, partitioning_neighborhood_id + dim, dim, stencil_width)) {
29212926
ret.insert(cells.begin(), cells.end());
29222927
}
29232928
}
@@ -11403,13 +11408,7 @@ template <
1140311408
return;
1140411409
}
1140511410

11406-
number_of_neighbors[i] = 0;
11407-
for (const auto& neighbor : dccrg_instance->get_vlasov_neighbors(cell, dccrg_instance->partitioning_neighborhood_id)) {
11408-
// Zoltan 3.501 crashes in hierarchial if a cell is a neighbor to itself
11409-
if (neighbor != 0 && neighbor != cell) {
11410-
number_of_neighbors[i]++;
11411-
}
11412-
}
11411+
number_of_neighbors[i] = dccrg_instance->get_vlasov_neighbors(cell).size();
1141311412
}
1141411413
}
1141511414

@@ -11458,7 +11457,7 @@ template <
1145811457

1145911458
number_of_neighbors[i] = 0;
1146011459

11461-
for (const auto& neighbor: dccrg_instance->get_vlasov_neighbors(cell, dccrg_instance->partitioning_neighborhood_id)) {
11460+
for (const auto& neighbor: dccrg_instance->get_vlasov_neighbors(cell)) {
1146211461
// Zoltan 3.501 crashes in hierarchial if a cell is a neighbor to itself
1146311462
if (neighbor == 0 || neighbor == cell) {
1146411463
continue;
@@ -11553,15 +11552,7 @@ template <
1155311552

1155411553
*number_of_connections = 0;
1155511554
for (const auto& item: dccrg_instance->cell_data) {
11556-
11557-
(*number_of_connections)++;
11558-
11559-
for (const auto& neighbor: dccrg_instance->get_vlasov_neighbors(item.first, dccrg_instance->partitioning_neighborhood_id)) {
11560-
// Zoltan 3.501 crashes in hierarchial if a cell is a neighbor to itself
11561-
if (neighbor != 0 && neighbor != item.first) {
11562-
(*number_of_connections)++;
11563-
}
11564-
}
11555+
(*number_of_connections) += 1 + dccrg_instance->get_vlasov_neighbors(item.first).size();
1156511556
}
1156611557
}
1156711558

@@ -11620,7 +11611,7 @@ template <
1162011611
// add a connection to the cell itself from its hyperedge
1162111612
connections[connection_number++] = item.first;
1162211613

11623-
for (const auto& neighbor: dccrg_instance->get_vlasov_neighbors(item.first, dccrg_instance->partitioning_neighborhood_id)) {
11614+
for (const auto& neighbor: dccrg_instance->get_vlasov_neighbors(item.first)) {
1162411615
// Zoltan 3.501 crashes in hierarchial if a cell is a neighbor to itself
1162511616
if (neighbor == 0 || neighbor == item.first) {
1162611617
continue;

0 commit comments

Comments
 (0)