1- #ifndef PHARE_MAGNETIC_FIELD_COARSENER
2- #define PHARE_MAGNETIC_FIELD_COARSENER
3-
4-
5- #include " core/def/phare_mpi.hpp"
1+ #ifndef PHARE_ELECTRIC_FIELD_COARSENER
2+ #define PHARE_ELECTRIC_FIELD_COARSENER
63
4+ #include " amr/amr_constants.hpp"
75#include " core/data/grid/gridlayoutdefs.hpp"
8- #include " core/hybrid/hybrid_quantities.hpp"
96#include " core/utilities/constants.hpp"
7+ #include " amr/resources_manager/amr_utils.hpp"
108
119
1210#include < SAMRAI/hier/Box.h>
11+ #include < cstddef>
1312#include < stdexcept>
1413
1514namespace PHARE ::amr
@@ -32,13 +31,13 @@ using core::dirZ;
3231 *
3332 */
3433template <std::size_t dimension>
35- class MagneticFieldCoarsener
34+ class ElectricFieldCoarsener
3635{
3736public:
38- MagneticFieldCoarsener (std::array<core::QtyCentering, dimension> const centering,
37+ ElectricFieldCoarsener (std::array<core::QtyCentering, dimension> const centering,
3938 SAMRAI::hier::Box const & sourceBox,
4039 SAMRAI::hier::Box const & destinationBox,
41- SAMRAI::hier::IntVector const & ratio)
40+ SAMRAI::hier::IntVector const & /* ratio*/ )
4241 : centering_{centering}
4342 , sourceBox_{sourceBox}
4443 , destinationBox_{destinationBox}
@@ -55,86 +54,101 @@ class MagneticFieldCoarsener
5554
5655 core::Point<int , dimension> fineStartIndex;
5756
58- fineStartIndex[dirX] = coarseIndex[dirX] * this ->ratio_ ;
59-
60- if constexpr (dimension > 1 )
57+ for (auto i = std::size_t {0 }; i < dimension; ++i)
6158 {
62- fineStartIndex[dirY] = coarseIndex[dirY] * this ->ratio_ ;
63- if constexpr (dimension > 2 )
64- {
65- fineStartIndex[dirZ] = coarseIndex[dirZ] * this ->ratio_ ;
66- }
59+ fineStartIndex[i] = coarseIndex[i] * refinementRatio;
6760 }
6861
6962 fineStartIndex = AMRToLocal (fineStartIndex, sourceBox_);
7063 coarseIndex = AMRToLocal (coarseIndex, destinationBox_);
7164
72- // the following kinda assumes where B is, i.e. Yee layout centering
73- // as it only does faces pirmal-dual, dual-primal and dual-dual
74-
7565 if constexpr (dimension == 1 )
7666 {
77- // in 1D div(B) is automatically satisfied so using this coarsening
78- // opertor is probably not better than the default one, but we do that
79- // for a kind of consistency...
80- // coarse flux is equal to fine flux and we're 1D so there is flux partitioned
81- // only for By and Bz, Bx is equal to the fine value
82-
83- if (centering_[dirX] == core::QtyCentering::primal) // bx
84- {
85- coarseField (coarseIndex[dirX]) = fineField (fineStartIndex[dirX]);
86- }
87- else if (centering_[dirX] == core::QtyCentering::dual) // by and bz
67+ if (centering_[dirX] == core::QtyCentering::dual) // ex
8868 {
8969 coarseField (coarseIndex[dirX])
9070 = 0.5 * (fineField (fineStartIndex[dirX] + 1 ) + fineField (fineStartIndex[dirX]));
9171 }
72+ else if (centering_[dirX] == core::QtyCentering::primal) // ey, ez
73+ {
74+ coarseField (coarseIndex[dirX]) = fineField (fineStartIndex[dirX]);
75+ }
9276 }
9377
9478 if constexpr (dimension == 2 )
9579 {
96- if (centering_[dirX] == core::QtyCentering::primal
97- and centering_[dirY] == core::QtyCentering::dual)
80+ if (centering_[dirX] == core::QtyCentering::dual
81+ and centering_[dirY] == core::QtyCentering::primal) // ex
9882 {
9983 coarseField (coarseIndex[dirX], coarseIndex[dirY])
10084 = 0.5
10185 * (fineField (fineStartIndex[dirX], fineStartIndex[dirY])
102- + fineField (fineStartIndex[dirX], fineStartIndex[dirY] + 1 ));
86+ + fineField (fineStartIndex[dirX] + 1 , fineStartIndex[dirY]));
10387 }
104- else if (centering_[dirX] == core::QtyCentering::dual
105- and centering_[dirY] == core::QtyCentering::primal)
88+ else if (centering_[dirX] == core::QtyCentering::primal
89+ and centering_[dirY] == core::QtyCentering::dual) // ey
10690 {
10791 coarseField (coarseIndex[dirX], coarseIndex[dirY])
10892 = 0.5
10993 * (fineField (fineStartIndex[dirX], fineStartIndex[dirY])
110- + fineField (fineStartIndex[dirX] + 1 , fineStartIndex[dirY]));
94+ + fineField (fineStartIndex[dirX], fineStartIndex[dirY] + 1 ));
11195 }
112- else if (centering_[dirX] == core::QtyCentering::dual
113- and centering_[dirY] == core::QtyCentering::dual)
96+ else if (centering_[dirX] == core::QtyCentering::primal
97+ and centering_[dirY] == core::QtyCentering::primal) // ez
11498 {
11599 coarseField (coarseIndex[dirX], coarseIndex[dirY])
116- = 0.25
117- * (fineField (fineStartIndex[dirX], fineStartIndex[dirY])
118- + fineField (fineStartIndex[dirX] + 1 , fineStartIndex[dirY])
119- + fineField (fineStartIndex[dirX], fineStartIndex[dirY] + 1 )
120- + fineField (fineStartIndex[dirX] + 1 , fineStartIndex[dirY] + 1 ));
100+ = fineField (fineStartIndex[dirX], fineStartIndex[dirY]);
121101 }
122102 else
123103 {
124- throw std::runtime_error (" no magnetic field should end up here" );
104+ throw std::runtime_error (" no electric field should end up here" );
125105 }
126106 }
127107 else if constexpr (dimension == 3 )
128108 {
129- throw std::runtime_error (" Not Implemented yet" );
109+ if (centering_[dirX] == core::QtyCentering::dual
110+ and centering_[dirY] == core::QtyCentering::primal
111+ and centering_[dirZ] == core::QtyCentering::primal) // ex
112+ {
113+ coarseField (coarseIndex[dirX], coarseIndex[dirY], coarseIndex[dirZ])
114+ = 0.5
115+ * (fineField (fineStartIndex[dirX], fineStartIndex[dirY], fineStartIndex[dirZ])
116+ + fineField (fineStartIndex[dirX] + 1 , fineStartIndex[dirY],
117+ fineStartIndex[dirZ]));
118+ }
119+ else if (centering_[dirX] == core::QtyCentering::primal
120+ and centering_[dirY] == core::QtyCentering::dual
121+ and centering_[dirZ] == core::QtyCentering::primal) // ey
122+ {
123+ coarseField (coarseIndex[dirX], coarseIndex[dirY], coarseIndex[dirZ])
124+ = 0.5
125+ * (fineField (fineStartIndex[dirX], fineStartIndex[dirY], fineStartIndex[dirZ])
126+ + fineField (fineStartIndex[dirX], fineStartIndex[dirY] + 1 ,
127+ fineStartIndex[dirZ]));
128+ }
129+ else if (centering_[dirX] == core::QtyCentering::primal
130+ and centering_[dirY] == core::QtyCentering::primal
131+ and centering_[dirZ] == core::QtyCentering::dual) // ez
132+ {
133+ coarseField (coarseIndex[dirX], coarseIndex[dirY], coarseIndex[dirZ])
134+ = 0.5
135+ * (fineField (fineStartIndex[dirX], fineStartIndex[dirY], fineStartIndex[dirZ])
136+ + fineField (fineStartIndex[dirX], fineStartIndex[dirY],
137+ fineStartIndex[dirZ] + 1 ));
138+ }
139+ else
140+ {
141+ throw std::runtime_error (" no electric field should end up here" );
142+ }
130143 }
131144 }
132145
133146private:
134147 std::array<core::QtyCentering, dimension> const centering_;
135148 SAMRAI::hier::Box const sourceBox_;
136149 SAMRAI::hier::Box const destinationBox_;
137- static int constexpr ratio_ = 2 ;
138150};
151+
139152} // namespace PHARE::amr
153+
140154#endif
0 commit comments