Skip to content

Commit 3015cb7

Browse files
authored
Merge pull request #1083 from UCaromel/debug-fix-master
fix broken coarse/fine boundary flux conservation, add tensorfield data, rework schedules etc.
1 parent 238185f commit 3015cb7

File tree

92 files changed

+3663
-1881
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+3663
-1881
lines changed

src/amr/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ set( SOURCES_INC
1111
data/field/coarsening/field_coarsen_index_weight.hpp
1212
data/field/coarsening/coarsen_weighter.hpp
1313
data/field/coarsening/default_field_coarsener.hpp
14-
data/field/coarsening/magnetic_field_coarsener.hpp
14+
data/field/coarsening/electric_field_coarsener.hpp
1515
data/field/field_data.hpp
1616
data/field/field_data_factory.hpp
1717
data/field/field_geometry.hpp
1818
data/field/field_overlap.hpp
1919
data/field/field_variable.hpp
2020
data/field/refine/field_linear_refine.hpp
2121
data/field/refine/field_refiner.hpp
22+
data/field/refine/magnetic_field_init_refiner.hpp
2223
data/field/refine/magnetic_field_refiner.hpp
2324
data/field/refine/electric_field_refiner.hpp
2425
data/field/refine/linear_weighter.hpp

src/amr/data/field/coarsening/default_field_coarsener.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
#define PHARE_DEFAULT_FIELD_COARSENER_HPP
33

44

5-
#include "core/def/phare_mpi.hpp"
5+
#include "core/def/phare_mpi.hpp" // IWYU pragma: keep
66

77
#include "core/def.hpp"
8-
#include "core/data/grid/gridlayoutdefs.hpp"
98
#include "core/utilities/constants.hpp"
109
#include "core/utilities/point/point.hpp"
10+
#include "core/data/grid/gridlayoutdefs.hpp"
1111

12-
#include "amr/data/field/coarsening/field_coarsen_index_weight.hpp"
1312
#include "amr/resources_manager/amr_utils.hpp"
13+
#include "amr/data/field/coarsening/field_coarsen_index_weight.hpp"
1414

1515
#include <SAMRAI/hier/Box.h>
1616

17-
#include <cstddef>
1817
#include <array>
18+
#include <cstddef>
19+
1920

2021

2122

@@ -157,4 +158,6 @@ namespace amr
157158
} // namespace PHARE
158159

159160

161+
162+
160163
#endif
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
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

1514
namespace PHARE::amr
@@ -32,13 +31,13 @@ using core::dirZ;
3231
*
3332
*/
3433
template<std::size_t dimension>
35-
class MagneticFieldCoarsener
34+
class ElectricFieldCoarsener
3635
{
3736
public:
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

133146
private:
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

src/amr/data/field/coarsening/field_coarsen_index_weight.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@
55
#include "core/def/phare_mpi.hpp"
66

77
#include "core/def.hpp"
8-
#include "coarsen_weighter.hpp"
98
#include "core/data/grid/gridlayoutdefs.hpp"
10-
#include "core/hybrid/hybrid_quantities.hpp"
11-
#include "core/data/field/field.hpp"
12-
#include "core/utilities/constants.hpp"
139

1410
#include "amr/resources_manager/amr_utils.hpp"
1511

12+
#include "coarsen_weighter.hpp"
1613

1714
#include <SAMRAI/hier/Box.h>
1815

0 commit comments

Comments
 (0)