Skip to content

Commit 3643435

Browse files
committed
mhd time steppers refactor
1 parent 9c6e59a commit 3643435

File tree

4 files changed

+179
-295
lines changed

4 files changed

+179
-295
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
#ifndef PHARE_CORE_NUMERICS_BASE_MHD_TIMESTEPPER_HPP
2+
#define PHARE_CORE_NUMERICS_BASE_MHD_TIMESTEPPER_HPP
3+
4+
#include "initializer/data_provider.hpp"
5+
#include "core/numerics/godunov_fluxes/godunov_utils.hpp"
6+
7+
namespace PHARE::solver
8+
{
9+
template<typename MHDModel>
10+
class BaseMHDTimestepper
11+
{
12+
using FieldT = typename MHDModel::field_type;
13+
using VecFieldT = typename MHDModel::vecfield_type;
14+
using GridLayoutT = typename MHDModel::gridlayout_type;
15+
16+
public:
17+
BaseMHDTimestepper(PHARE::initializer::PHAREDict const& dict)
18+
: butcherFluxes_{{"timeRho_fx", core::MHDQuantity::Scalar::ScalarFlux_x},
19+
{"timeRhoV_fx", core::MHDQuantity::Vector::VecFlux_x},
20+
{"timeB_fx", core::MHDQuantity::Vector::VecFlux_x},
21+
{"timeEtot_fx", core::MHDQuantity::Scalar::ScalarFlux_x},
22+
23+
{"timeRho_fy", core::MHDQuantity::Scalar::ScalarFlux_y},
24+
{"timeRhoV_fy", core::MHDQuantity::Vector::VecFlux_y},
25+
{"timeB_fy", core::MHDQuantity::Vector::VecFlux_y},
26+
{"timeEtot_fy", core::MHDQuantity::Scalar::ScalarFlux_y},
27+
28+
{"timeRho_fz", core::MHDQuantity::Scalar::ScalarFlux_z},
29+
{"timeRhoV_fz", core::MHDQuantity::Vector::VecFlux_z},
30+
{"timeB_fz", core::MHDQuantity::Vector::VecFlux_z},
31+
{"timeEtot_fz", core::MHDQuantity::Scalar::ScalarFlux_z}}
32+
, butcherE_{"timeE", core::MHDQuantity::Vector::E}
33+
{
34+
}
35+
36+
void registerResources(MHDModel& model)
37+
{
38+
model.resourcesManager->registerResources(butcherFluxes_);
39+
model.resourcesManager->registerResources(butcherE_);
40+
}
41+
42+
void allocate(MHDModel& model, auto& patch, double const allocateTime) const
43+
{
44+
model.resourcesManager->allocate(butcherFluxes_, patch, allocateTime);
45+
model.resourcesManager->allocate(butcherE_, patch, allocateTime);
46+
}
47+
48+
void fillMessengerInfo(auto& info) const {}
49+
50+
NO_DISCARD auto getCompileTimeResourcesViewList()
51+
{
52+
return std::forward_as_tuple(butcherFluxes_, butcherE_);
53+
}
54+
55+
NO_DISCARD auto getCompileTimeResourcesViewList() const
56+
{
57+
return std::forward_as_tuple(butcherFluxes_, butcherE_);
58+
}
59+
60+
auto exposeFluxes() { return std::forward_as_tuple(butcherFluxes_, butcherE_); }
61+
62+
auto exposeFluxes() const { return std::forward_as_tuple(butcherFluxes_, butcherE_); }
63+
64+
protected:
65+
void resetButcherFluxes_(MHDModel& model, auto& level)
66+
{
67+
for (auto& patch : level)
68+
{
69+
auto const& layout = amr::layoutFromPatch<GridLayoutT>(*patch);
70+
auto _ = model.resourcesManager->setOnPatch(*patch, butcherFluxes_, butcherE_);
71+
72+
evalFluxesOnGhostBox(
73+
layout, [&](auto& left, auto const&... args) mutable { left(args...) = 0.0; },
74+
butcherFluxes_);
75+
76+
layout.evalOnGhostBox(butcherE_(core::Component::X), [&](auto const&... args) mutable {
77+
butcherE_(core::Component::X)(args...) = 0.0;
78+
});
79+
80+
layout.evalOnGhostBox(butcherE_(core::Component::Y), [&](auto const&... args) mutable {
81+
butcherE_(core::Component::Y)(args...) = 0.0;
82+
});
83+
84+
layout.evalOnGhostBox(butcherE_(core::Component::Z), [&](auto const&... args) mutable {
85+
butcherE_(core::Component::Z)(args...) = 0.0;
86+
});
87+
}
88+
}
89+
90+
void accumulateButcherFluxes_(MHDModel& model, auto& fluxes, auto& level)
91+
{
92+
for (auto& patch : level)
93+
{
94+
auto const& layout = amr::layoutFromPatch<GridLayoutT>(*patch);
95+
auto _ = model.resourcesManager->setOnPatch(*patch, butcherFluxes_, butcherE_, fluxes,
96+
model.state.E);
97+
98+
evalFluxesOnGhostBox(
99+
layout,
100+
[&](auto& left, auto const& right, auto const&... args) mutable {
101+
left(args...) += right(args...);
102+
},
103+
butcherFluxes_, fluxes);
104+
105+
106+
layout.evalOnGhostBox(butcherE_(core::Component::X), [&](auto const&... args) mutable {
107+
butcherE_(core::Component::X)(args...)
108+
+= model.state.E(core::Component::X)(args...);
109+
});
110+
111+
layout.evalOnGhostBox(butcherE_(core::Component::Y), [&](auto const&... args) mutable {
112+
butcherE_(core::Component::Y)(args...)
113+
+= model.state.E(core::Component::Y)(args...);
114+
});
115+
116+
layout.evalOnGhostBox(butcherE_(core::Component::Z), [&](auto const&... args) mutable {
117+
butcherE_(core::Component::Z)(args...)
118+
+= model.state.E(core::Component::Z)(args...);
119+
});
120+
}
121+
}
122+
123+
core::AllFluxes<FieldT, VecFieldT> butcherFluxes_;
124+
VecFieldT butcherE_;
125+
};
126+
} // namespace PHARE::solver
127+
128+
#endif

src/amr/solvers/time_integrator/euler_integrator.hpp

Lines changed: 12 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,21 @@
11
#ifndef PHARE_CORE_NUMERICS_EULER_INTEGRATOR_HPP
22
#define PHARE_CORE_NUMERICS_EULER_INTEGRATOR_HPP
33

4-
#include "core/numerics/constrained_transport/constrained_transport.hpp"
5-
#include "core/numerics/godunov_fluxes/godunov_utils.hpp"
64
#include "initializer/data_provider.hpp"
5+
#include "amr/solvers/time_integrator/base_mhd_timestepper.hpp"
76
#include "amr/solvers/time_integrator/euler.hpp"
87

98
namespace PHARE::solver
109
{
1110
template<template<typename> typename FVMethodStrategy, typename MHDModel>
12-
class EulerIntegrator
11+
class EulerIntegrator : public BaseMHDTimestepper<MHDModel>
1312
{
14-
using FieldT = typename MHDModel::field_type;
15-
using VecFieldT = typename MHDModel::vecfield_type;
16-
using GridLayoutT = typename MHDModel::gridlayout_type;
13+
using Super = BaseMHDTimestepper<MHDModel>;
1714

1815
public:
1916
EulerIntegrator(PHARE::initializer::PHAREDict const& dict)
20-
: euler_{dict}
21-
, butcherFluxes_{{"timeRho_fx", core::MHDQuantity::Scalar::ScalarFlux_x},
22-
{"timeRhoV_fx", core::MHDQuantity::Vector::VecFlux_x},
23-
{"timeB_fx", core::MHDQuantity::Vector::VecFlux_x},
24-
{"timeEtot_fx", core::MHDQuantity::Scalar::ScalarFlux_x},
25-
26-
{"timeRho_fy", core::MHDQuantity::Scalar::ScalarFlux_y},
27-
{"timeRhoV_fy", core::MHDQuantity::Vector::VecFlux_y},
28-
{"timeB_fy", core::MHDQuantity::Vector::VecFlux_y},
29-
{"timeEtot_fy", core::MHDQuantity::Scalar::ScalarFlux_y},
30-
31-
{"timeRho_fz", core::MHDQuantity::Scalar::ScalarFlux_z},
32-
{"timeRhoV_fz", core::MHDQuantity::Vector::VecFlux_z},
33-
{"timeB_fz", core::MHDQuantity::Vector::VecFlux_z},
34-
{"timeEtot_fz", core::MHDQuantity::Scalar::ScalarFlux_z}}
35-
, butcherE_{"timeE", core::MHDQuantity::Vector::E}
17+
: Super{dict}
18+
, euler_{dict}
3619
{
3720
}
3821

@@ -42,103 +25,21 @@ class EulerIntegrator
4225
void operator()(MHDModel& model, auto& state, auto& fluxes, auto& bc, auto& level,
4326
double const currentTime, double const newTime)
4427
{
45-
resetButcherFluxes_(model, level);
28+
this->resetButcherFluxes_(model, level);
4629

4730
euler_(model, state, state, fluxes, bc, level, currentTime, newTime);
4831

49-
accumulateButcherFluxes_(model, fluxes, level);
50-
}
51-
52-
void registerResources(MHDModel& model)
53-
{
54-
model.resourcesManager->registerResources(butcherFluxes_);
55-
model.resourcesManager->registerResources(butcherE_);
56-
}
57-
58-
void allocate(MHDModel& model, auto& patch, double const allocateTime) const
59-
{
60-
model.resourcesManager->allocate(butcherFluxes_, patch, allocateTime);
61-
model.resourcesManager->allocate(butcherE_, patch, allocateTime);
62-
}
63-
64-
void fillMessengerInfo(auto& info) const {}
65-
66-
NO_DISCARD auto getCompileTimeResourcesViewList()
67-
{
68-
return std::forward_as_tuple(butcherFluxes_, butcherE_);
69-
}
70-
71-
NO_DISCARD auto getCompileTimeResourcesViewList() const
72-
{
73-
return std::forward_as_tuple(butcherFluxes_, butcherE_);
32+
this->accumulateButcherFluxes_(model, fluxes, level);
7433
}
7534

76-
auto exposeFluxes() { return std::forward_as_tuple(butcherFluxes_, butcherE_); }
77-
78-
auto exposeFluxes() const { return std::forward_as_tuple(butcherFluxes_, butcherE_); }
35+
using Super::allocate;
36+
using Super::exposeFluxes;
37+
using Super::fillMessengerInfo;
38+
using Super::getCompileTimeResourcesViewList;
39+
using Super::registerResources;
7940

8041
private:
81-
void resetButcherFluxes_(MHDModel& model, auto& level)
82-
{
83-
for (auto& patch : level)
84-
{
85-
auto const& layout = amr::layoutFromPatch<GridLayoutT>(*patch);
86-
auto _ = model.resourcesManager->setOnPatch(*patch, butcherFluxes_, butcherE_);
87-
88-
evalFluxesOnGhostBox(
89-
layout, [&](auto& left, auto const&... args) mutable { left(args...) = 0.0; },
90-
butcherFluxes_);
91-
92-
layout.evalOnGhostBox(butcherE_(core::Component::X), [&](auto const&... args) mutable {
93-
butcherE_(core::Component::X)(args...) = 0.0;
94-
});
95-
96-
layout.evalOnGhostBox(butcherE_(core::Component::Y), [&](auto const&... args) mutable {
97-
butcherE_(core::Component::Y)(args...) = 0.0;
98-
});
99-
100-
layout.evalOnGhostBox(butcherE_(core::Component::Z), [&](auto const&... args) mutable {
101-
butcherE_(core::Component::Z)(args...) = 0.0;
102-
});
103-
}
104-
}
105-
106-
void accumulateButcherFluxes_(MHDModel& model, auto& fluxes, auto& level)
107-
{
108-
for (auto& patch : level)
109-
{
110-
auto const& layout = amr::layoutFromPatch<GridLayoutT>(*patch);
111-
auto _ = model.resourcesManager->setOnPatch(*patch, butcherFluxes_, butcherE_, fluxes,
112-
model.state.E);
113-
114-
evalFluxesOnGhostBox(
115-
layout,
116-
[&](auto& left, auto const& right, auto const&... args) mutable {
117-
left(args...) += right(args...);
118-
},
119-
butcherFluxes_, fluxes);
120-
121-
122-
layout.evalOnGhostBox(butcherE_(core::Component::X), [&](auto const&... args) mutable {
123-
butcherE_(core::Component::X)(args...)
124-
+= model.state.E(core::Component::X)(args...);
125-
});
126-
127-
layout.evalOnGhostBox(butcherE_(core::Component::Y), [&](auto const&... args) mutable {
128-
butcherE_(core::Component::Y)(args...)
129-
+= model.state.E(core::Component::Y)(args...);
130-
});
131-
132-
layout.evalOnGhostBox(butcherE_(core::Component::Z), [&](auto const&... args) mutable {
133-
butcherE_(core::Component::Z)(args...)
134-
+= model.state.E(core::Component::Z)(args...);
135-
});
136-
}
137-
}
138-
13942
Euler<FVMethodStrategy, MHDModel> euler_;
140-
core::AllFluxes<FieldT, VecFieldT> butcherFluxes_;
141-
VecFieldT butcherE_;
14243
};
14344
} // namespace PHARE::solver
14445

0 commit comments

Comments
 (0)