Skip to content

Commit 5aeec1d

Browse files
committed
different models in python for hybrid and mhd
1 parent 9b2b049 commit 5aeec1d

File tree

5 files changed

+61
-23
lines changed

5 files changed

+61
-23
lines changed

.github/workflows/cmake_ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
8989
- name: Build
9090
working-directory: ${{runner.workspace}}/build
91-
run: cmake --build . -j 2
91+
run: cmake --build . -j 1
9292

9393
- name: Test
9494
working-directory: ${{runner.workspace}}/build

pyphare/pyphare/simulator/simulator.py

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
#
33
#
44

5-
import os
6-
import datetime
75
import atexit
6+
import datetime
7+
import os
88
import time as timem
9+
from pathlib import Path
10+
911
import numpy as np
1012
import pyphare.pharein as ph
11-
from pathlib import Path
12-
from . import monitoring as mon
1313

14+
from . import monitoring as mon
1415

1516
life_cycles = {}
1617
SIM_MONITOR = os.getenv("PHARE_SIM_MON", "False").lower() in ("true", "1", "t")
@@ -26,13 +27,35 @@ def simulator_shutdown():
2627
life_cycles.clear()
2728

2829

29-
def make_cpp_simulator(dim, interp, nbrRefinedPart, hier):
30+
def make_cpp_simulator(
31+
hier,
32+
dim,
33+
interp,
34+
nbrRefinedPart,
35+
mhd_timestepper,
36+
reconstruction,
37+
limiter,
38+
riemann,
39+
hall,
40+
res,
41+
hyper_res,
42+
):
3043
from pyphare.cpp import cpp_lib
3144

3245
if SCOPE_TIMING:
3346
mon.timing_setup(cpp_lib())
3447

35-
make_sim = f"make_simulator_{dim}_{interp}_{nbrRefinedPart}"
48+
nbrRefinedPart_suffix = f"_{nbrRefinedPart}" if nbrRefinedPart else ""
49+
mhd_timestepper_suffix = f"_{mhd_timestepper}" if mhd_timestepper else ""
50+
reconstruction_suffix = f"_{reconstruction}" if reconstruction else ""
51+
limiter_suffix = f"_{limiter}" if limiter else ""
52+
riemann_suffix = f"_{riemann}" if riemann else ""
53+
hall_suffix = "_hall" if hall else ""
54+
res_suffix = "_res" if res else ""
55+
hyper_res_suffix = "_hyper_res" if hyper_res else ""
56+
57+
make_sim = f"make_simulator_{dim}_{interp}{nbrRefinedPart_suffix}{mhd_timestepper_suffix}{reconstruction_suffix}{limiter_suffix}{riemann_suffix}{hall_suffix}{res_suffix}{hyper_res_suffix}"
58+
3659
return getattr(cpp_lib(), make_sim)(hier)
3760

3861

@@ -109,8 +132,8 @@ def __del__(self):
109132
def setup(self):
110133
# mostly to detach C++ class construction/dict parsing from C++ Simulator::init
111134
try:
112-
from pyphare.cpp import cpp_lib
113135
import pyphare.cpp.validate as validate_cpp
136+
from pyphare.cpp import cpp_lib
114137

115138
startMPI()
116139

@@ -124,11 +147,29 @@ def setup(self):
124147
ph.populateDict()
125148
self.cpp_hier = cpp_lib().make_hierarchy()
126149

150+
refined_particle_nbr = getattr(
151+
self.simulation, "refined_particle_nbr", False
152+
)
153+
mhd_timestepper = getattr(self.simulation, "mhd_timestepper", False)
154+
reconstruction = getattr(self.simulation, "reconstruction", False)
155+
limiter = getattr(self.simulation, "limiter", False)
156+
riemann = getattr(self.simulation, "riemann", False)
157+
hall = getattr(self.simulation, "hall", False)
158+
res = getattr(self.simulation, "res", False)
159+
hyper_res = getattr(self.simulation, "hyper_res", False)
160+
127161
self.cpp_sim = make_cpp_simulator(
162+
self.cpp_hier,
128163
self.simulation.ndim,
129164
self.simulation.interp_order,
130-
self.simulation.refined_particle_nbr,
131-
self.cpp_hier,
165+
refined_particle_nbr,
166+
mhd_timestepper,
167+
reconstruction,
168+
limiter,
169+
riemann,
170+
hall,
171+
res,
172+
hyper_res,
132173
)
133174
return self
134175
except Exception:

src/python3/cpp_mhd_parameters.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ class RegistererSelector
195195

196196
bool constexpr compile_one
197197
= (TI == TimeIntegratorType::TVDRK3 && RC == ReconstructionType::WENOZ
198-
&& SL == SlopeLimiterType::count && RS == RiemannSolverType::Rusanov
199-
&& (Hall || !Hall) && !Resistivity && !HyperResistivity);
198+
&& SL == SlopeLimiterType::count && RS == RiemannSolverType::Rusanov && !Resistivity
199+
&& !HyperResistivity);
200200

201201
return !compile_one;
202202
}

src/simulator/simulator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ void Simulator<_dimension, _interp_order, _nbRefinedPart, MHDTimeStepper>::initi
474474
try
475475
{
476476
if (isInitialized)
477-
std::runtime_error("cannot initialize - simulator already isInitialized");
477+
throw std::runtime_error("cannot initialize - simulator already isInitialized");
478478

479479
if (integrator_ != nullptr)
480480
integrator_->initialize();

tests/simulator/test_initialization.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99
from pyphare.core.box import nDBox
1010
from pyphare.core.phare_utilities import assert_fp_any_all_close
1111
from pyphare.pharein import ElectronModel, MaxwellianFluidModel
12-
from pyphare.pharein.diagnostics import (
13-
ElectromagDiagnostics,
14-
FluidDiagnostics,
15-
ParticleDiagnostics,
16-
)
12+
from pyphare.pharein.diagnostics import (ElectromagDiagnostics,
13+
FluidDiagnostics, ParticleDiagnostics)
1714
from pyphare.pharein.simulation import Simulation
1815
from pyphare.pharesee.geometry import level_ghost_boxes
19-
from pyphare.pharesee.hierarchy.hierarchy_utils import merge_particles
2016
from pyphare.pharesee.hierarchy import hierarchy_from
17+
from pyphare.pharesee.hierarchy.hierarchy_utils import merge_particles
2118
from pyphare.pharesee.particles import aggregate as aggregate_particles
2219
from pyphare.simulator.simulator import Simulator
2320

@@ -268,7 +265,7 @@ def _test_B_is_as_provided_by_user(self, dim, interp_order, **kwargs):
268265

269266
from pyphare.pharein import global_vars
270267

271-
model = global_vars.sim.model
268+
model = global_vars.sim.maxwellian_fluid_model
272269

273270
bx_fn = model.model_dict["bx"]
274271
by_fn = model.model_dict["by"]
@@ -334,7 +331,7 @@ def _test_bulkvel_is_as_provided_by_user(self, dim, interp_order):
334331

335332
from pyphare.pharein import global_vars
336333

337-
model = global_vars.sim.model
334+
model = global_vars.sim.maxwellian_fluid_model
338335
# protons and beam have same bulk vel here so take only proton func.
339336
vx_fn = model.model_dict["protons"]["vx"]
340337
vy_fn = model.model_dict["protons"]["vy"]
@@ -462,7 +459,7 @@ def _test_density_is_as_provided_by_user(self, dim, interp_order):
462459

463460
from pyphare.pharein import global_vars
464461

465-
model = global_vars.sim.model
462+
model = global_vars.sim.maxwellian_fluid_model
466463
proton_density_fn = model.model_dict["protons"]["density"]
467464
beam_density_fn = model.model_dict["beam"]["density"]
468465

@@ -551,7 +548,7 @@ def _test_density_decreases_as_1overSqrtN(
551548

552549
from pyphare.pharein import global_vars
553550

554-
model = global_vars.sim.model
551+
model = global_vars.sim.maxwellian_fluid_model
555552
density_fn = model.model_dict["protons"]["density"]
556553

557554
patch = hier.level(0).patches[0]

0 commit comments

Comments
 (0)