Skip to content

Commit c6cbe44

Browse files
committed
branch initial commit: cleaned history and simulator merging
1 parent f177c5c commit c6cbe44

19 files changed

+914
-617
lines changed

pyphare/pyphare/pharein/__init__.py

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
import os
2-
import sys
32
import subprocess
4-
import numpy as np
3+
import sys
54

5+
import numpy as np
66
from pyphare.core.phare_utilities import is_scalar
7-
from .uniform_model import UniformModel
8-
from .maxwellian_fluid_model import MaxwellianFluidModel
7+
8+
from .diagnostics import (ElectromagDiagnostics, FluidDiagnostics,
9+
InfoDiagnostics, MetaDiagnostics,
10+
ParticleDiagnostics)
911
from .electron_model import ElectronModel
10-
from .diagnostics import (
11-
FluidDiagnostics,
12-
ElectromagDiagnostics,
13-
ParticleDiagnostics,
14-
MetaDiagnostics,
15-
InfoDiagnostics,
16-
)
17-
from .simulation import (
18-
Simulation,
19-
serialize as serialize_sim,
20-
deserialize as deserialize_sim,
21-
)
2212
from .load_balancer import LoadBalancer
13+
from .maxwellian_fluid_model import MaxwellianFluidModel
14+
from .simulation import Simulation
15+
from .simulation import deserialize as deserialize_sim
16+
from .simulation import serialize as serialize_sim
17+
from .uniform_model import UniformModel
2318

2419
__all__ = [
2520
"UniformModel",
@@ -126,9 +121,10 @@ def clearDict():
126121

127122

128123
def populateDict():
129-
from .global_vars import sim as simulation
130124
import pybindlibs.dictator as pp
131125

126+
from .global_vars import sim as simulation
127+
132128
# pybind complains if receiving wrong type
133129
def add_int(path, val):
134130
pp.add_int(path, int(val))
@@ -412,3 +408,44 @@ def as_paths(rb):
412408
add_string("simulation/" + item[0], item[1])
413409
else:
414410
add_double("simulation/" + item[0], item[1])
411+
412+
413+
add_double("simualtion/algo/fv_method/resistivity", simulation.eta)
414+
add_double("simualtion/algo/fv_method/hyper_resistivity", simulation.nu)
415+
add_double("simualtion/algo/fv_method/heat_capacity_ratio", simulation.gamma)
416+
add_double("simualtion/algo/fv_euler/heat_capacity_ratio", simulation.gamma)
417+
add_double("simualtion/algo/to_primitive/heat_capacity_ratio", simulation.gamma)
418+
add_double("simualtion/algo/to_conservative/heat_capacity_ratio", simulation.gamma)
419+
420+
add_string("simulation/mhd_state/name", "mhd_state")
421+
422+
addInitFunction(
423+
"simulation/mhd_state/density/initializer", fn_wrapper(modelDict["density"])
424+
)
425+
addInitFunction(
426+
"simulation/mhd_state/velocity/initializer/x_component",
427+
fn_wrapper(modelDict["vx"]),
428+
)
429+
addInitFunction(
430+
"simulation/mhd_state/velocity/initializer/y_component",
431+
fn_wrapper(modelDict["vy"]),
432+
)
433+
addInitFunction(
434+
"simulation/mhd_state/velocity/initializer/z_component",
435+
fn_wrapper(modelDict["vz"]),
436+
)
437+
addInitFunction(
438+
"simulation/mhd_state/magnetic/initializer/x_component",
439+
fn_wrapper(modelDict["bx"]),
440+
)
441+
addInitFunction(
442+
"simulation/mhd_state/magnetic/initializer/y_component",
443+
fn_wrapper(modelDict["by"]),
444+
)
445+
addInitFunction(
446+
"simulation/mhd_state/magnetic/initializer/z_component",
447+
fn_wrapper(modelDict["bz"]),
448+
)
449+
addInitFunction(
450+
"simulation/mhd_state/pressure/initializer", fn_wrapper(modelDict["p"])
451+
)

src/amr/messengers/mhd_messenger_info.hpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#ifndef PHARE_MHD_MESSENGER_INFO_HPP
32
#define PHARE_MHD_MESSENGER_INFO_HPP
43

@@ -16,7 +15,30 @@ namespace amr
1615
using VecFieldNames = core::VecFieldNames;
1716

1817
public:
19-
// What is needed here ?
18+
std::string modelDensity;
19+
VecFieldNames modelVelocity;
20+
VecFieldNames modelMagnetic;
21+
std::string modelPressure;
22+
23+
VecFieldNames modelMomentum;
24+
VecFieldNames modelTotalEnergy;
25+
26+
VecFieldNames modelElectric;
27+
VecFieldNames modelCurrent;
28+
29+
std::vector<std::string> initDensity;
30+
std::vector<VecFieldNames> initVelocity;
31+
std::vector<VecFieldNames> initMagnetic;
32+
std::vector<std::string> initPressure;
33+
34+
std::vector<std::string> ghostDensity;
35+
std::vector<VecFieldNames> ghostVelocity;
36+
std::vector<std::string> ghostPressure;
37+
std::vector<VecFieldNames> ghostMagneticFluxesX;
38+
std::vector<VecFieldNames> ghostMagneticFluxesY;
39+
std::vector<VecFieldNames> ghostMagneticFluxesZ;
40+
std::vector<VecFieldNames> ghostElectric;
41+
2042
virtual ~MHDMessengerInfo() = default;
2143
};
2244

src/amr/physical_models/mhd_model.hpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ template<typename GridLayoutT, typename VecFieldT, typename AMR_Types, typename
2222
class MHDModel : public IPhysicalModel<AMR_Types>
2323
{
2424
public:
25+
static constexpr auto dimension = GridLayoutT::dimension;
26+
2527
using patch_t = typename AMR_Types::patch_t;
2628
using level_t = typename AMR_Types::level_t;
2729
using Interface = IPhysicalModel<AMR_Types>;
2830

29-
using field_type = typename VecFieldT::field_type;
30-
using gridlayout_type = GridLayoutT;
31+
using field_type = typename VecFieldT::field_type;
32+
using gridlayout_type = GridLayoutT;
33+
using resources_manager_type = amr::ResourcesManager<gridlayout_type, Grid_t>;
3134

3235
static inline std::string const model_name = "MHDModel";
33-
static constexpr auto dimension = gridlayout_type::dimension;
34-
using resources_manager_type = amr::ResourcesManager<gridlayout_type, Grid_t>;
3536

3637
core::MHDState<VecFieldT> state;
3738
std::shared_ptr<resources_manager_type> resourcesManager;
@@ -44,12 +45,7 @@ class MHDModel : public IPhysicalModel<AMR_Types>
4445
resourcesManager->allocate(state, patch, allocateTime);
4546
}
4647

47-
48-
49-
virtual void
50-
fillMessengerInfo(std::unique_ptr<amr::IMessengerInfo> const& /*info*/) const override
51-
{
52-
}
48+
virtual void fillMessengerInfo(std::unique_ptr<amr::IMessengerInfo> const& info) const override;
5349

5450
NO_DISCARD auto setOnPatch(patch_t& patch)
5551
{
@@ -97,6 +93,32 @@ void MHDModel<GridLayoutT, VecFieldT, AMR_Types, Grid_t>::initialize(level_t& le
9793
resourcesManager->registerForRestarts(*this);
9894
}
9995

96+
template<typename GridLayoutT, typename VecFieldT, typename AMR_Types, typename Grid_t>
97+
void MHDModel<GridLayoutT, VecFieldT, AMR_Types, Grid_t>::fillMessengerInfo(
98+
std::unique_ptr<amr::IMessengerInfo> const& info) const
99+
{
100+
auto& MHDInfo = dynamic_cast<amr::MHDMessengerInfo&>(*info);
101+
102+
MHDInfo.modelDensity = state.rho.name();
103+
MHDInfo.modelMagnetic = core::VecFieldNames{state.B};
104+
MHDInfo.modelVelocity = core::VecFieldNames{state.V};
105+
MHDInfo.modelPressure = state.P.name();
106+
MHDInfo.modelMomentum = core::VecFieldNames{state.rhoV};
107+
MHDInfo.modelTotalEnergy = core::VecFieldNames{state.Etot};
108+
MHDInfo.modelElectric = core::VecFieldNames{state.E};
109+
MHDInfo.modelCurrent = core::VecFieldNames{state.J};
110+
111+
MHDInfo.initDensity.push_back(state.rho.name());
112+
MHDInfo.initVelocity.push_back(core::VecFieldNames{state.V});
113+
MHDInfo.initMagnetic.push_back(core::VecFieldNames{state.B});
114+
MHDInfo.initPressure.push_back(state.P.name());
115+
116+
MHDInfo.ghostDensity.push_back(state.rho.name());
117+
MHDInfo.ghostVelocity.push_back(core::VecFieldNames{state.V});
118+
MHDInfo.ghostPressure.push_back(state.P.name());
119+
MHDInfo.ghostElectric.push_back(core::VecFieldNames{state.E});
120+
}
121+
100122
} // namespace PHARE::solver
101123

102124
#endif

src/amr/solvers/solver_mhd.hpp

Lines changed: 102 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class SolverMHD : public ISolver<AMR_Types>
5050
public:
5151
SolverMHD(PHARE::initializer::PHAREDict const& dict)
5252
: ISolver<AMR_Types>{"MHDSolver"}
53-
5453
, fluxes_{{"rho_fx", MHDQuantity::Scalar::ScalarFlux_x},
5554
{"rhoV_fx", MHDQuantity::Vector::VecFlux_x},
5655
{"B_fx", MHDQuantity::Vector::VecFlux_x},
@@ -73,26 +72,24 @@ class SolverMHD : public ISolver<AMR_Types>
7372

7473
std::string modelName() const override { return MHDModel::model_name; }
7574

76-
void fillMessengerInfo(std::unique_ptr<amr::IMessengerInfo> const& /*info*/) const override {}
75+
void fillMessengerInfo(std::unique_ptr<amr::IMessengerInfo> const& info) const override;
7776

78-
void registerResources(IPhysicalModel<AMR_Types>& /*model*/) override {}
77+
void registerResources(IPhysicalModel<AMR_Types>& model) override;
7978

8079
// TODO make this a resourcesUser
81-
void allocate(IPhysicalModel<AMR_Types>& /*model*/, patch_t& /*patch*/,
82-
double const /*allocateTime*/) const override
83-
{
84-
}
80+
void allocate(IPhysicalModel<AMR_Types>& model, patch_t& patch,
81+
double const allocateTime) const override;
8582

8683
void advanceLevel(hierarchy_t const& hierarchy, int const levelNumber, ISolverModelView& view,
8784
IMessenger& fromCoarserMessenger, double const currentTime,
8885
double const newTime) override;
8986

87+
void onRegrid() override {}
9088

9189
std::shared_ptr<ISolverModelView> make_view(level_t& level, IPhysicalModel_t& model) override
9290
{
9391
/*return std::make_shared<ModelViews_t>(level, dynamic_cast<MHDModel&>(model));*/
94-
throw std::runtime_error("no MHD model yet");
95-
return nullptr;
92+
throw std::runtime_error("SolverMHD::make_view not implemented");
9693
}
9794

9895
NO_DISCARD auto getCompileTimeResourcesViewList()
@@ -108,19 +105,107 @@ class SolverMHD : public ISolver<AMR_Types>
108105
private:
109106
struct TimeSetter
110107
{
111-
/*template <typename QuantityAccessor>*/
112-
/*void operator()(QuantityAccessor accessor) {*/
113-
/* for (auto& state : views)*/
114-
/* views.model().resourcesManager->setTime(accessor(state), *state.patch, newTime);*/
115-
/*}*/
116-
/**/
117-
/*ModelViews_t& views;*/
118-
/*double newTime;*/
108+
template<typename QuantityAccessor>
109+
void operator()(QuantityAccessor accessor)
110+
{
111+
for (auto& state : views)
112+
views.model().resourcesManager->setTime(accessor(state), *state.patch, newTime);
113+
}
114+
115+
ModelViews_t& views;
116+
double newTime;
119117
};
120118
};
121119

122120
// -----------------------------------------------------------------------------
123121

122+
template<typename MHDModel, typename AMR_Types, typename TimeIntegratorStrategy, typename Messenger,
123+
typename ModelViews_t>
124+
void SolverMHD<MHDModel, AMR_Types, TimeIntegratorStrategy, Messenger,
125+
ModelViews_t>::registerResources(IPhysicalModel_t& model)
126+
{
127+
auto& mhdmodel = dynamic_cast<MHDModel&>(model);
128+
129+
mhdmodel.resourcesManager->registerResources(fluxes_.rho_fx);
130+
mhdmodel.resourcesManager->registerResources(fluxes_.rhoV_fx);
131+
mhdmodel.resourcesManager->registerResources(fluxes_.B_fx);
132+
mhdmodel.resourcesManager->registerResources(fluxes_.Etot_fx);
133+
134+
if constexpr (dimension >= 2)
135+
{
136+
mhdmodel.resourcesManager->registerResources(fluxes_.rho_fy);
137+
mhdmodel.resourcesManager->registerResources(fluxes_.rhoV_fy);
138+
mhdmodel.resourcesManager->registerResources(fluxes_.B_fy);
139+
mhdmodel.resourcesManager->registerResources(fluxes_.Etot_fy);
140+
141+
if constexpr (dimension == 3)
142+
{
143+
mhdmodel.resourcesManager->registerResources(fluxes_.rho_fz);
144+
mhdmodel.resourcesManager->registerResources(fluxes_.rhoV_fz);
145+
mhdmodel.resourcesManager->registerResources(fluxes_.B_fz);
146+
mhdmodel.resourcesManager->registerResources(fluxes_.Etot_fz);
147+
}
148+
}
149+
150+
evolve_.registerResources(mhdmodel);
151+
}
152+
153+
template<typename MHDModel, typename AMR_Types, typename TimeIntegratorStrategy, typename Messenger,
154+
typename ModelViews_t>
155+
void SolverMHD<MHDModel, AMR_Types, TimeIntegratorStrategy, Messenger, ModelViews_t>::allocate(
156+
IPhysicalModel_t& model, patch_t& patch, double const allocateTime) const
157+
158+
{
159+
auto& mhdmodel = dynamic_cast<MHDModel&>(model);
160+
161+
mhdmodel.resourcesManager->allocate(fluxes_.rho_fx, patch, allocateTime);
162+
mhdmodel.resourcesManager->allocate(fluxes_.rhoV_fx, patch, allocateTime);
163+
mhdmodel.resourcesManager->allocate(fluxes_.B_fx, patch, allocateTime);
164+
mhdmodel.resourcesManager->allocate(fluxes_.Etot_fx, patch, allocateTime);
165+
166+
if constexpr (dimension >= 2)
167+
{
168+
mhdmodel.resourcesManager->allocate(fluxes_.rho_fy, patch, allocateTime);
169+
mhdmodel.resourcesManager->allocate(fluxes_.rhoV_fy, patch, allocateTime);
170+
mhdmodel.resourcesManager->allocate(fluxes_.B_fy, patch, allocateTime);
171+
mhdmodel.resourcesManager->allocate(fluxes_.Etot_fy, patch, allocateTime);
172+
173+
if constexpr (dimension == 3)
174+
{
175+
mhdmodel.resourcesManager->allocate(fluxes_.rho_fz, patch, allocateTime);
176+
mhdmodel.resourcesManager->allocate(fluxes_.rhoV_fz, patch, allocateTime);
177+
mhdmodel.resourcesManager->allocate(fluxes_.B_fz, patch, allocateTime);
178+
mhdmodel.resourcesManager->allocate(fluxes_.Etot_fz, patch, allocateTime);
179+
}
180+
}
181+
182+
evolve_.allocate(mhdmodel, patch, allocateTime);
183+
}
184+
185+
template<typename MHDModel, typename AMR_Types, typename TimeIntegratorStrategy, typename Messenger,
186+
typename ModelViews_t>
187+
void SolverMHD<MHDModel, AMR_Types, TimeIntegratorStrategy, Messenger,
188+
ModelViews_t>::fillMessengerInfo(std::unique_ptr<amr::IMessengerInfo> const& info)
189+
const
190+
191+
{
192+
auto& mhdInfo = dynamic_cast<amr::MHDMessengerInfo&>(*info);
193+
194+
mhdInfo.ghostMagneticFluxesX.emplace_back(core::VecFieldNames(fluxes_.B_fx));
195+
196+
if constexpr (dimension >= 2)
197+
{
198+
mhdInfo.ghostMagneticFluxesY.emplace_back(core::VecFieldNames(fluxes_.B_fy));
199+
200+
if constexpr (dimension == 3)
201+
{
202+
mhdInfo.ghostMagneticFluxesZ.emplace_back(core::VecFieldNames(fluxes_.B_fz));
203+
}
204+
}
205+
206+
evolve_.fillMessengerInfo(mhdInfo);
207+
}
208+
124209
template<typename MHDModel, typename AMR_Types, typename TimeIntegratorStrategy, typename Messenger,
125210
typename ModelViews_t>
126211
void SolverMHD<MHDModel, AMR_Types, TimeIntegratorStrategy, Messenger, ModelViews_t>::advanceLevel(

src/amr/solvers/time_integrator/euler_integrator.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class EulerIntegrator
2121
euler_(layouts, state, state, fluxes, bc, level, currentTime, newTime);
2222
}
2323

24+
void registerResources(MHDModel& model) {}
25+
26+
void allocate(MHDModel& model, auto& patch, double const allocateTime) const {}
27+
28+
void fillMessengerInfo(auto& info) const {}
29+
2430
private:
2531
Euler<FVMethodStrategy, MHDModel> euler_;
2632
};

src/amr/solvers/time_integrator/tvdrk2_integrator.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef PHARE_CORE_NUMERICS_TVDRK2_INTEGRATOR_HPP
22
#define PHARE_CORE_NUMERICS_TVDRK2_INTEGRATOR_HPP
33

4+
#include "core/data/vecfield/vecfield.hpp"
45
#include "initializer/data_provider.hpp"
56
#include "amr/solvers/solver_mhd_model_view.hpp"
67
#include "amr/solvers/time_integrator/euler.hpp"
@@ -41,6 +42,21 @@ class TVDRK2Integrator
4142
tvdrk2_step_(layouts, state, RKPair_t{w0_, state}, RKPair_t{w1_, state1_});
4243
}
4344

45+
void registerResources(MHDModel& model) { model.resourcesManager->registerResources(state1_); }
46+
47+
void allocate(MHDModel& model, auto& patch, double const allocateTime) const
48+
{
49+
model.resourcesManager->allocate(state1_, patch, allocateTime);
50+
}
51+
52+
void fillMessengerInfo(auto& info) const
53+
{
54+
info.ghostDensity.push_back(state1_.rho.name());
55+
info.ghostVelocity.push_back(core::VecFieldNames{state1_.V});
56+
info.ghostPressure.push_back(state1_.P.name());
57+
info.ghostElectric.push_back(core::VecFieldNames{state1_.E});
58+
}
59+
4460
NO_DISCARD auto getCompileTimeResourcesViewList() { return std::forward_as_tuple(state1_); }
4561

4662
NO_DISCARD auto getCompileTimeResourcesViewList() const

0 commit comments

Comments
 (0)