Skip to content

Commit 9b2b049

Browse files
committed
BROKEN: different models in python for hybrid and mhd
1 parent 27e8032 commit 9b2b049

File tree

19 files changed

+181
-54
lines changed

19 files changed

+181
-54
lines changed

pyphare/pyphare/pharein/__init__.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
sys.path = sys.path + pythonpath
5555

5656

57+
def add_vector_string(path, val):
58+
import pybindlibs.dictator as pp
59+
60+
pp.add_vector_string(path, list(val))
61+
62+
5763
def NO_GUI():
5864
"""prevents issues when command line only and no desktop etc"""
5965
import matplotlib as mpl
@@ -76,13 +82,15 @@ def populateDict():
7682

7783
initialize.general.populateDict(sim)
7884

79-
if not sim.init_options:
80-
sim.init_options = ["hybrid"]
85+
if not sim.model_options:
86+
sim.model_options = ["HybridModel"]
8187

82-
if "hybrid" in sim.init_options:
88+
if "HybridModel" in sim.model_options:
8389
initialize.hybrid.populateDict(sim)
84-
if "mhd" in sim.init_options:
90+
if "MHDModel" in sim.model_options:
8591
initialize.mhd.populateDict(sim)
8692

87-
if not ("hybrid" in sim.init_options or "mhd" in sim.init_options):
93+
if not ("HybridModel" in sim.model_options or "MHDModel" in sim.model_options):
8894
raise ValueError("Unknown simulation type")
95+
96+
add_vector_string("simulation/models", sim.model_options)

pyphare/pyphare/pharein/diagnostics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def to_dict(self):
216216

217217

218218
def population_in_model(population):
219-
return population in [p for p in global_vars.sim.model.populations]
219+
return population in [p for p in global_vars.sim.maxwellian_fluid_model.populations]
220220

221221

222222
class FluidDiagnostics_(Diagnostics):

pyphare/pyphare/pharein/initialize/general.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import os
22

33
import numpy as np
4+
import pybindlibs.dictator as pp
45
from pyphare.core.phare_utilities import is_scalar
56
from pyphare.pharein.load_balancer import LoadBalancer
67
from pyphare.pharein.simulation import deserialize as deserialize_sim
78
from pyphare.pharein.simulation import serialize as serialize_sim
89

9-
import pybindlibs.dictator as pp
10-
1110

1211
def _patch_data_ids(restart_file_dir):
1312
"""

pyphare/pyphare/pharein/initialize/hybrid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def populateDict(sim):
1616
add_double("simulation/algo/ohm/hyper_resistivity", sim.hyper_resistivity)
1717
add_string("simulation/algo/ohm/hyper_mode", sim.hyper_mode)
1818

19-
init_model = sim.model
19+
init_model = sim.maxwellian_fluid_model
2020
modelDict = init_model.model_dict
2121

2222
if init_model.nbr_populations() < 0:

pyphare/pyphare/pharein/initialize/mhd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def populateDict(sim):
2121

2222
add_string("simulation/mhd_state/name", "mhd_state")
2323

24-
init_model = sim.model
24+
init_model = sim.mhd_model
2525
modelDict = init_model.model_dict
2626

2727
addInitFunction(

pyphare/pyphare/pharein/maxwellian_fluid_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __init__(self, bx=None, by=None, bz=None, **kwargs):
9191
if should_validate:
9292
self.validate(global_vars.sim)
9393

94-
global_vars.sim.set_model(self)
94+
global_vars.sim.set_maxwellian_fluid_model(self)
9595

9696
# ------------------------------------------------------------------------------
9797

pyphare/pyphare/pharein/mhd_model.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from . import global_vars
2+
3+
4+
class MHDModel(object):
5+
def defaulter(self, input, value):
6+
if input is not None:
7+
import inspect
8+
9+
params = list(inspect.signature(input).parameters.values())
10+
assert len(params)
11+
param_per_dim = len(params) == self.dim
12+
has_vargs = params[0].kind == inspect.Parameter.VAR_POSITIONAL
13+
assert param_per_dim or has_vargs
14+
return input
15+
if self.dim == 1:
16+
return lambda x: value + x * 0
17+
if self.dim == 2:
18+
return lambda x, y: value
19+
if self.dim == 3:
20+
return lambda x, y, z: value
21+
22+
def __init__(
23+
self, density=None, vx=None, vy=None, vz=None, bx=None, by=None, bz=None, p=None
24+
):
25+
if global_vars.sim is None:
26+
raise RuntimeError("A simulation must be declared before a model")
27+
28+
if global_vars.sim.model is not None:
29+
raise RuntimeError("A model is already created")
30+
31+
self.dim = global_vars.sim.ndim
32+
33+
density = self.defaulter(density, 1.0)
34+
vx = self.defaulter(vx, 1.0)
35+
vy = self.defaulter(vy, 0.0)
36+
vz = self.defaulter(vz, 0.0)
37+
bx = self.defaulter(bx, 1.0)
38+
by = self.defaulter(by, 0.0)
39+
bz = self.defaulter(bz, 0.0)
40+
p = self.defaulter(p, 1.0)
41+
42+
self.model_dict = {}
43+
44+
self.model_dict.update(
45+
{
46+
"density": density,
47+
"vx": vx,
48+
"vy": vy,
49+
"vz": vz,
50+
"bx": bx,
51+
"by": by,
52+
"bz": bz,
53+
"p": p,
54+
}
55+
)
56+
57+
global_vars.sim.set_mhd_model(self)

pyphare/pyphare/pharein/simulation.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os
2+
from copy import deepcopy
3+
24
import numpy as np
35

4-
from ..core import phare_utilities
5-
from . import global_vars
66
from ..core import box as boxm
7+
from ..core import phare_utilities
78
from ..core.box import Box
8-
from copy import deepcopy
9+
from . import global_vars
910

1011
# ------------------------------------------------------------------------------
1112

@@ -957,7 +958,9 @@ def __init__(self, **kwargs):
957958
self.ndim = compute_dimension(self.cells)
958959

959960
self.diagnostics = {}
960-
self.model = None
961+
self.uniform_model = None
962+
self.maxwellian_fluid_model = None
963+
self.mhd_model = None
961964
self.electrons = None
962965
self.load_balancer = None
963966

@@ -1065,12 +1068,26 @@ def count_diagnostics(self, type_name):
10651068

10661069
# ------------------------------------------------------------------------------
10671070

1068-
def set_model(self, model):
1071+
def set_uniform_model(self, mhd_model):
1072+
"""
1073+
1074+
:meta private:
1075+
"""
1076+
self.uniform_model = mhd_model
1077+
1078+
def set_maxwellian_fluid_model(self, maxwellian_fluid_model):
10691079
"""
10701080
10711081
:meta private:
10721082
"""
1073-
self.model = model
1083+
self.maxwellian_fluid_model = maxwellian_fluid_model
1084+
1085+
def set_mhd_model(self, mhd_model):
1086+
"""
1087+
1088+
:meta private:
1089+
"""
1090+
self.mhd_model = mhd_model
10741091

10751092
def set_electrons(self, electrons):
10761093
"""
@@ -1089,14 +1106,17 @@ def serialize(sim):
10891106
:meta private:
10901107
"""
10911108
# pickle cannot handle simulation objects
1092-
import dill
10931109
import codecs
10941110

1111+
import dill
1112+
10951113
return codecs.encode(dill.dumps(de_numpify_simulation(deepcopy(sim))), "hex")
10961114

10971115

10981116
def deserialize(hex):
10991117
""":meta private:"""
1100-
import dill, codecs
1118+
import codecs
1119+
1120+
import dill
11011121

11021122
return re_numpify_simulation(dill.loads(codecs.decode(hex, "hex")))

pyphare/pyphare/pharein/uniform_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, b=(1.0, 0.0, 0.0), e=(0.0, 0.0, 0.0), **kwargs):
1111
if global_vars.sim.model is not None:
1212
raise RuntimeError("A model is already created")
1313

14-
global_vars.sim.set_model(self)
14+
global_vars.sim.set_uniform_model(self)
1515

1616
if len(b) != 3 or (not isinstance(b, tuple) and not isinstance(b, list)):
1717
raise ValueError("invalid B")

src/amr/messengers/mhd_messenger_info.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace amr
2121
std::string modelPressure;
2222

2323
VecFieldNames modelMomentum;
24-
VecFieldNames modelTotalEnergy;
24+
std::string modelTotalEnergy;
2525

2626
VecFieldNames modelElectric;
2727
VecFieldNames modelCurrent;

0 commit comments

Comments
 (0)