Skip to content

Commit ba84522

Browse files
committed
em diags compatibility
1 parent d084eac commit ba84522

File tree

9 files changed

+158
-40
lines changed

9 files changed

+158
-40
lines changed

pyphare/pyphare/core/gridlayout.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@
4343
"Pyy": "primal",
4444
"Pyz": "primal",
4545
"Pzz": "primal",
46+
47+
# finite volume mhd quantities are 3ple dual
48+
"mhdRho": "dual",
49+
"mhdVx": "dual",
50+
"mhdVy": "dual",
51+
"mhdVz": "dual",
52+
"mhdP": "dual",
53+
"mhdRhoVx": "dual",
54+
"mhdRhoVy": "dual",
55+
"mhdRhoVz": "dual",
56+
"mhdEtot": "dual",
57+
4658
"tags": "dual",
4759
},
4860
"y": {
@@ -78,6 +90,17 @@
7890
"Pyy": "primal",
7991
"Pyz": "primal",
8092
"Pzz": "primal",
93+
94+
"mhdRho": "dual",
95+
"mhdVx": "dual",
96+
"mhdVy": "dual",
97+
"mhdVz": "dual",
98+
"mhdP": "dual",
99+
"mhdRhoVx": "dual",
100+
"mhdRhoVy": "dual",
101+
"mhdRhoVz": "dual",
102+
"mhdEtot": "dual",
103+
81104
"tags": "dual",
82105
},
83106
"z": {
@@ -113,6 +136,17 @@
113136
"Pyy": "primal",
114137
"Pyz": "primal",
115138
"Pzz": "primal",
139+
140+
"mhdRho": "dual",
141+
"mhdVx": "dual",
142+
"mhdVy": "dual",
143+
"mhdVz": "dual",
144+
"mhdP": "dual",
145+
"mhdRhoVx": "dual",
146+
"mhdRhoVy": "dual",
147+
"mhdRhoVz": "dual",
148+
"mhdEtot": "dual",
149+
116150
"tags": "dual",
117151
},
118152
}

pyphare/pyphare/pharein/diagnostics.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def _setSubTypeAttributes(self, **kwargs): # stop pyline complaining
180180

181181
# ------------------------------------------------------------------------------
182182
class MHDDiagnostics(Diagnostics):
183-
mhd_quantities = ["rho", "V", "B", "P", "rhoV", "Etot"]
183+
mhd_quantities = ["rho", "V", "P", "rhoV", "Etot"]
184184
type = "mhd"
185185

186186
def __init__(self, **kwargs):
@@ -196,8 +196,6 @@ def _setSubTypeAttributes(self, **kwargs):
196196
MHDDiagnostics.mhd_quantities
197197
)
198198
raise ValueError(error_msg.format(kwargs["quantity"]))
199-
elif kwargs["quantity"] == "B":
200-
self.quantity = "/EM_B"
201199
else:
202200
self.quantity = "/mhd/" + kwargs["quantity"]
203201

pyphare/pyphare/pharesee/hierarchy/hierarchy_utils.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
from dataclasses import dataclass, field
21
from copy import deepcopy
3-
import numpy as np
4-
2+
from dataclasses import dataclass, field
53
from typing import Any, List, Tuple
64

5+
import numpy as np
6+
from pyphare.core import phare_utilities as phut
7+
8+
from ...core.box import Box
9+
from ...core.gridlayout import GridLayout
10+
from ...core.phare_utilities import listify, refinement_ratio
711
from .hierarchy import PatchHierarchy, format_timestamp
12+
from .patch import Patch
813
from .patchdata import FieldData, ParticleData
914
from .patchlevel import PatchLevel
10-
from .patch import Patch
11-
from ...core.box import Box
12-
from ...core.gridlayout import GridLayout
13-
from ...core.phare_utilities import listify
14-
from ...core.phare_utilities import refinement_ratio
15-
from pyphare.core import phare_utilities as phut
16-
1715

1816
field_qties = {
1917
"EM_B_x": "Bx",
@@ -36,6 +34,18 @@
3634
"momentum_tensor_zz": "Mzz",
3735
"density": "rho",
3836
"mass_density": "rho",
37+
38+
# for now mhd specific quantities
39+
"rho": "mhdRho",
40+
"V_x": "mhdVx",
41+
"V_y": "mhdVy",
42+
"V_z": "mhdVz",
43+
"P": "mhdP",
44+
"rhoV_x": "mhdRhoVx",
45+
"rhoV_y": "mhdRhoVy",
46+
"rhoV_z": "mhdRhoVz",
47+
"Etot": "mhdEtot",
48+
3949
"tags": "tags",
4050
}
4151

pyphare/pyphare/pharesee/run/run.py

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1-
import os
21
import glob
3-
import numpy as np
4-
5-
from pyphare.pharesee.hierarchy import hierarchy_from
6-
from pyphare.pharesee.hierarchy import ScalarField, VectorField
2+
import os
73

8-
from pyphare.pharesee.hierarchy.hierarchy_utils import compute_hier_from
9-
from pyphare.pharesee.hierarchy.hierarchy_utils import flat_finest_field
4+
import numpy as np
105
from pyphare.core.phare_utilities import listify
11-
126
from pyphare.logger import getLogger
13-
from .utils import (
14-
_compute_to_primal,
15-
_compute_pop_pressure,
16-
_compute_pressure,
17-
_compute_current,
18-
_compute_divB,
19-
_get_rank,
20-
make_interpolator,
21-
)
7+
from pyphare.pharesee.hierarchy import ScalarField, VectorField, hierarchy_from
8+
from pyphare.pharesee.hierarchy.hierarchy_utils import (compute_hier_from,
9+
flat_finest_field)
2210

11+
from .utils import (_compute_current, _compute_divB, _compute_pop_pressure,
12+
_compute_pressure, _compute_to_primal, _get_rank,
13+
make_interpolator)
2314

2415
logger = getLogger(__name__)
2516

@@ -176,6 +167,64 @@ def GetDivB(self, time, merged=False, interp="nearest", **kwargs):
176167
db = compute_hier_from(_compute_divB, B)
177168
return ScalarField(self._get(db, time, merged, interp))
178169

170+
def GetMHDrho(
171+
self, time, merged=False, interp="nearest", all_primal=True, **kwargs
172+
):
173+
if merged:
174+
all_primal = False
175+
hier = self._get_hierarchy(time, "mhd_rho.h5", **kwargs)
176+
if not all_primal:
177+
return self._get(hier, time, merged, interp)
178+
179+
h = compute_hier_from(_compute_to_primal, hier, value="mhdRho")
180+
return VectorField(h)
181+
182+
def GetMHDV(self, time, merged=False, interp="nearest", all_primal=True, **kwargs):
183+
if merged:
184+
all_primal = False
185+
hier = self._get_hierarchy(time, "mhd_V.h5", **kwargs)
186+
if not all_primal:
187+
return self._get(hier, time, merged, interp)
188+
189+
h = compute_hier_from(_compute_to_primal, hier, x="mhdVx", y="mhdVy", z="mhdVz")
190+
return VectorField(h)
191+
192+
def GetMHDP(
193+
self, time, merged=False, interp="nearest", all_primal=True, **kwargs
194+
):
195+
if merged:
196+
all_primal = False
197+
hier = self._get_hierarchy(time, "mhd_P.h5", **kwargs)
198+
if not all_primal:
199+
return self._get(hier, time, merged, interp)
200+
201+
h = compute_hier_from(_compute_to_primal, hier, value="mhdP")
202+
return VectorField(h)
203+
204+
def GetMHDrhoV(
205+
self, time, merged=False, interp="nearest", all_primal=True, **kwargs
206+
):
207+
if merged:
208+
all_primal = False
209+
hier = self._get_hierarchy(time, "mhd_rhoV.h5", **kwargs)
210+
if not all_primal:
211+
return self._get(hier, time, merged, interp)
212+
213+
h = compute_hier_from(
214+
_compute_to_primal, hier, x="mhdRhoVx", y="mhdRhoVy", z="mhdRhoVz"
215+
)
216+
return VectorField(h)
217+
218+
def GetMHDEtot(self, time, merged=False, interp="nearest", all_primal=True, **kwargs):
219+
if merged:
220+
all_primal = False
221+
hier = self._get_hierarchy(time, "mhd_Etot.h5", **kwargs)
222+
if not all_primal:
223+
return self._get(hier, time, merged, interp)
224+
225+
h = compute_hier_from(_compute_to_primal, hier, value="mhdEtot")
226+
return VectorField(h)
227+
179228
def GetRanks(self, time, merged=False, interp="nearest", **kwargs):
180229
"""
181230
returns a hierarchy of MPI ranks

pyphare/pyphare/pharesee/run/utils.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from pyphare.core.gridlayout import yee_centering
21
import numpy as np
2+
from pyphare.core.gridlayout import yee_centering
33

44

55
def _current1d(by, bz, xby, xbz):
@@ -184,7 +184,7 @@ def _dpd_to_ppp_domain_slicing(**kwargs):
184184

185185
def _ddp_to_ppp_domain_slicing(**kwargs):
186186
"""
187-
return the slicing for (dual,primal,primal) to (primal,primal,primal)
187+
return the slicing for (dual,dual,primal) to (primal,primal,primal)
188188
centering that is the centering of Bz on a Yee grid
189189
"""
190190

@@ -270,6 +270,31 @@ def _ppd_to_ppp_domain_slicing(**kwargs):
270270
else:
271271
raise RuntimeError("dimension not yet implemented")
272272

273+
def _ddd_to_ppp_domain_slicing(**kwargs):
274+
"""
275+
return the slicing for (dual,dual,dual) to (primal,primal,primal)
276+
centering that is the centering of Bz on a Yee grid
277+
"""
278+
279+
nb_ghosts = kwargs["nb_ghosts"]
280+
ndim = kwargs["ndim"]
281+
282+
inner, inner_shift_left, inner_shift_right = _inner_slices(nb_ghosts)
283+
284+
if ndim == 1:
285+
inner_all = tuple([inner] * ndim)
286+
return inner_all, (inner_shift_left, inner_shift_right)
287+
elif ndim == 2:
288+
inner_all = tuple([inner] * ndim)
289+
return inner_all, (
290+
(inner_shift_left, inner_shift_left),
291+
(inner_shift_left, inner_shift_right),
292+
(inner_shift_right, inner_shift_left),
293+
(inner_shift_right, inner_shift_right),
294+
)
295+
else:
296+
raise RuntimeError("dimension not yet implemented")
297+
273298

274299
slices_to_primal_ = {
275300
"primal_primal_primal": _ppp_to_ppp_domain_slicing,
@@ -279,6 +304,7 @@ def _ppd_to_ppp_domain_slicing(**kwargs):
279304
"dual_primal_primal": _dpp_to_ppp_domain_slicing,
280305
"primal_dual_primal": _pdp_to_ppp_domain_slicing,
281306
"primal_primal_dual": _ppd_to_ppp_domain_slicing,
307+
"dual_dual_dual": _ddd_to_ppp_domain_slicing,
282308
}
283309

284310

@@ -468,7 +494,8 @@ def make_interpolator(data, coords, interp, domain, dl, qty, nbrGhosts):
468494
finest_coords = (x,)
469495

470496
elif dim == 2:
471-
from scipy.interpolate import LinearNDInterpolator, NearestNDInterpolator
497+
from scipy.interpolate import (LinearNDInterpolator,
498+
NearestNDInterpolator)
472499

473500
if interp == "nearest":
474501
interpolator = NearestNDInterpolator(coords, data)

src/core/numerics/godunov_fluxes/godunov_fluxes.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class Godunov : public LayoutHolder<GridLayout>
6969
}
7070

7171
private:
72-
GridLayout layout_;
7372
double const gamma_;
7473
double const eta_;
7574
double const nu_;

src/diagnostic/detail/types/mhd.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void MHDDiagnosticWriter<H5Writer>::compute(DiagnosticProperties& diagnostic)
7979

8080
auto& rho = modelView.getRho();
8181
auto& V = modelView.getV();
82-
auto& B = *modelView.getElectromagFields()[0];
82+
auto& B = modelView.getB();
8383
auto& P = modelView.getP();
8484
auto& rhoV = modelView.getRhoV();
8585
auto& Etot = modelView.getEtot();

src/diagnostic/diagnostic_model_view.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,11 @@ class ModelView<Hierarchy, Model, MHDIdentifier> : public BaseModelView<Hierarch
190190

191191
NO_DISCARD VecField& getV() const { return this->model_.state.V; }
192192

193-
// compatibility with the electromag diagnostic writer
194-
NO_DISCARD std::vector<VecField*> getElectromagFields() const
193+
NO_DISCARD VecField& getB() const { return this->model_.state.B; }
194+
195+
NO_DISCARD VecField& getE() const
195196
{
196-
return {&this->model_.state.B};
197+
throw std::runtime_error("E not currently available in MHD diagnostics");
197198
}
198199

199200
NO_DISCARD Field& getP() const { return this->model_.state.P; }

tests/functional/mhd_orszagtang/orszag_tang_merged.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def p(x, y):
8080

8181
ph.ElectromagDiagnostics(quantity="B", write_timestamps=timestamps)
8282

83-
# for quantity in ["rho", "V", "B", "P"]:
84-
# ph.MHDDiagnostics(quantity=quantity, write_timestamps=timestamps)
83+
for quantity in ["rho", "V", "P"]:
84+
ph.MHDDiagnostics(quantity=quantity, write_timestamps=timestamps)
8585

8686
return sim
8787

0 commit comments

Comments
 (0)