@@ -2822,10 +2822,27 @@ template <
28222822 return ret_val;
28232823 }
28242824
2825- // Recursively find Vlasov solver neighbors
2826- // Janky, and most likely incredibly inefficient
2827- std::set<uint64_t > get_vlasov_neighbors (
2828- const uint64_t cell
2825+ // Get maximum displacement between cells a and b
2826+ double get_maximum_displacement (
2827+ const uint64_t a,
2828+ const uint64_t b
2829+ ) const {
2830+ auto x_a = get_center (a);
2831+ auto x_b = get_center (b);
2832+ double ret {0 };
2833+ for (int i = 0 ; i < 3 ; ++i) {
2834+ double r = std::abs (x_a[i] - x_b[i]);
2835+ ret = r > ret ? r : ret;
2836+ }
2837+ return ret;
2838+ }
2839+
2840+ // Get Vlasov stencil neighbors by calculating distance
2841+ // Assumes neighborhood given is a + -shaped stencil
2842+ // Probably inefficient
2843+ std::vector<uint64_t > get_vlasov_neighbors (
2844+ const uint64_t cell,
2845+ const int neighborhood_id = default_neighborhood_id
28292846 ) const {
28302847 int stencil_width {0 };
28312848 switch (neighborhood_length) {
@@ -2842,25 +2859,18 @@ template <
28422859 std::cerr << " Weird stencil width" << std::endl;
28432860 break ;
28442861 }
2862+
2863+ std::vector<uint64_t > ret;
2864+ int my_ref {mapping.get_refinement_level (cell)};
28452865
2846- std::set<uint64_t > ret;
2847- auto last_neighbors {get_face_neighbors_of (cell)};
2848- for (const auto & [id, dir] : last_neighbors) {
2849- ret.insert (id);
2850- }
2866+ for (auto & [neigh, dir] : *get_neighbors_of (cell, neighborhood_id)) {
2867+ double r {get_maximum_displacement (cell, neigh)};
2868+ int other_ref {mapping.get_refinement_level (neigh)};
28512869
2852- for (int i = 1 ; i < stencil_width; ++i) {
2853- std::vector<std::pair<uint64_t , int >> new_neighbors;
2854- for (const auto & p : last_neighbors) {
2855- for (const auto pp : get_face_neighbors_of (p.first )) {
2856- if (p.second == pp.second ) {
2857- new_neighbors.push_back (pp);
2858- ret.insert (pp.first );
2859- }
2860- }
2870+ // 0.1 purely for floating point errors, assume cubical cells
2871+ if (r < (stencil_width + 0.1 ) * geometry.get_length ((my_ref < other_ref) ? neigh : cell)[0 ]) {
2872+ ret.push_back (neigh);
28612873 }
2862-
2863- last_neighbors = new_neighbors;
28642874 }
28652875
28662876 return ret;
@@ -11345,11 +11355,9 @@ template <
1134511355 }
1134611356
1134711357 number_of_neighbors[i] = 0 ;
11348- for (const auto & neighbor: dccrg_instance->get_vlasov_neighbors (cell)) {
11349- if (neighbor != 0
11350- /* Zoltan 3.501 crashes in hierarchial
11351- if a cell is a neighbor to itself */
11352- && neighbor != cell) {
11358+ for (const auto & neighbor : dccrg_instance->get_vlasov_neighbors (cell, dccrg_instance->partitioning_neighborhood_id )) {
11359+ // Zoltan 3.501 crashes in hierarchial if a cell is a neighbor to itself
11360+ if (neighbor != 0 && neighbor != cell) {
1135311361 number_of_neighbors[i]++;
1135411362 }
1135511363 }
@@ -11401,12 +11409,9 @@ template <
1140111409
1140211410 number_of_neighbors[i] = 0 ;
1140311411
11404- for (const auto & neighbor: dccrg_instance->get_vlasov_neighbors (cell)) {
11405-
11406- if (neighbor == 0
11407- /* Zoltan 3.501 crashes in hierarchial
11408- if a cell is a neighbor to itself */
11409- || neighbor == cell) {
11412+ for (const auto & neighbor: dccrg_instance->get_vlasov_neighbors (cell, dccrg_instance->partitioning_neighborhood_id )) {
11413+ // Zoltan 3.501 crashes in hierarchial if a cell is a neighbor to itself
11414+ if (neighbor == 0 || neighbor == cell) {
1141011415 continue ;
1141111416 }
1141211417
@@ -11502,9 +11507,8 @@ template <
1150211507
1150311508 (*number_of_connections)++;
1150411509
11505- for (const auto & neighbor: dccrg_instance->get_vlasov_neighbors (item.first )) {
11506- /* Zoltan 3.501 crashes in hierarchial
11507- if a cell is a neighbor to itself */
11510+ for (const auto & neighbor: dccrg_instance->get_vlasov_neighbors (item.first , dccrg_instance->partitioning_neighborhood_id )) {
11511+ // Zoltan 3.501 crashes in hierarchial if a cell is a neighbor to itself
1150811512 if (neighbor != 0 && neighbor != item.first ) {
1150911513 (*number_of_connections)++;
1151011514 }
@@ -11567,9 +11571,8 @@ template <
1156711571 // add a connection to the cell itself from its hyperedge
1156811572 connections[connection_number++] = item.first ;
1156911573
11570- for (const auto & neighbor: dccrg_instance->get_vlasov_neighbors (item.first )) {
11571- /* Zoltan 3.501 crashes in hierarchial
11572- if a cell is a neighbor to itself */
11574+ for (const auto & neighbor: dccrg_instance->get_vlasov_neighbors (item.first , dccrg_instance->partitioning_neighborhood_id )) {
11575+ // Zoltan 3.501 crashes in hierarchial if a cell is a neighbor to itself
1157311576 if (neighbor == 0 || neighbor == item.first ) {
1157411577 continue ;
1157511578 }
0 commit comments