@@ -2822,27 +2822,82 @@ template <
28222822 return ret_val;
28232823 }
28242824
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 };
2825+ // Consider giving index as argument to reduce calculations
2826+ static std::array<double , 3 > distance_to_double (const std::array<int , 4 >& in)
2827+ {
2828+ std::array<double , 3 > ret;
28332829 for (int i = 0 ; i < 3 ; ++i) {
2834- double r = std::abs (x_a[i] - x_b[i]);
2835- ret = r > ret ? r : ret;
2830+ ret[i] = static_cast <double >(in[i]) / (in[3 ] > 0 ? in[3 ] : 1.0 );
28362831 }
28372832 return ret;
28382833 }
28392834
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 (
2835+ std::map<double , std::vector<uint64_t >> get_vlasov_neighbors (
28442836 const uint64_t cell,
2845- const int neighborhood_id = default_neighborhood_id
2837+ const int neighborhood_id,
2838+ const int dimension,
2839+ const int stencil_width
2840+ ) const {
2841+ std::map<double , std::vector<uint64_t >> ret;
2842+ int my_ref {mapping.get_refinement_level (cell)};
2843+
2844+ std::vector<std::pair<uint64_t , std::array<int , 4 >>> neighs;
2845+ const auto * p = get_neighbors_of (cell, neighborhood_id);
2846+ if (!p) {
2847+ return ret;
2848+ }
2849+
2850+ neighs = *p;
2851+ // We still need to sort since more refined cells are in xyz order
2852+ std::stable_sort (neighs.begin (), neighs.end (),
2853+ [this , dimension] (const std::pair<uint64_t , std::array<int , 4 >>& a, const std::pair<uint64_t , std::array<int , 4 >>& b) {
2854+ return distance_to_double (a.second )[dimension] < distance_to_double (b.second )[dimension];
2855+ }
2856+ );
2857+
2858+ auto it = neighs.begin ();
2859+ while (it < neighs.end () && it->second [dimension] < 0 ) {
2860+ ++it;
2861+ }
2862+
2863+ int found {0 };
2864+ for (auto neg = it - 1 ; neg >= neighs.begin (); --neg) {
2865+ 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 ;
2873+ }
2874+ }
2875+
2876+ while (it < neighs.end () && it->second [dimension] <= 0 ) {
2877+ ++it;
2878+ }
2879+
2880+ found = 0 ;
2881+ for (auto pos = it; pos < neighs.end (); ++pos) {
2882+ 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 ;
2890+ }
2891+ }
2892+
2893+ return ret;
2894+ }
2895+
2896+ // Get actual Vlasov stencil neighbors
2897+ // Assumes linear 3 linear stencils from neighborhood_id to neighborhood_id + 2
2898+ std::set<uint64_t > get_vlasov_neighbors (
2899+ const uint64_t cell,
2900+ const int neighborhood_id
28462901 ) const {
28472902 int stencil_width {0 };
28482903 switch (neighborhood_length) {
@@ -2859,20 +2914,13 @@ template <
28592914 std::cerr << " Weird stencil width" << std::endl;
28602915 break ;
28612916 }
2862-
2863- std::vector<uint64_t > ret;
2864- int my_ref {mapping.get_refinement_level (cell)};
28652917
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)};
2869-
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);
2918+ std::set<uint64_t > ret;
2919+ for (int dim = 0 ; dim < 3 ; ++dim) {
2920+ for (auto & [dist, cells] : get_vlasov_neighbors (cell, neighborhood_id + dim, dim, stencil_width)) {
2921+ ret.insert (cells.begin (), cells.end ());
28732922 }
28742923 }
2875-
28762924 return ret;
28772925 }
28782926
@@ -7908,6 +7956,7 @@ template <
79087956
79097957 add_partitioning_level (1 ); // Level 1 - Processes
79107958 add_partitioning_option (1 , " LB_METHOD" , " RCB" );
7959+ // add_partitioning_option(1, "LB_METHOD", "RIB");
79117960 }
79127961
79137962 // reserved options that the user cannot change
0 commit comments