Skip to content

Commit e4e7a51

Browse files
committed
usable solver still unmaintained, working diagnostics
1 parent f2446ef commit e4e7a51

File tree

12 files changed

+86
-75
lines changed

12 files changed

+86
-75
lines changed

pyphare/pyphare/pharein/diagnostics.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,9 @@ def _setSubTypeAttributes(self, **kwargs):
197197
)
198198
raise ValueError(error_msg.format(kwargs["quantity"]))
199199
else:
200-
self.quantity = "/" + kwargs["quantity"]
200+
self.quantity = "/mhd/" + kwargs["quantity"]
201+
202+
self.attributes["heat_capacity_ratio"] = global_vars.sim.gamma
201203

202204
def to_dict(self):
203205
return {

pyphare/pyphare/pharein/initialize/general.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,16 @@ def as_paths(rb):
205205
add_size_t(name_path + "/" + "n_attributes", len(diag.attributes))
206206
for attr_idx, attr_key in enumerate(diag.attributes):
207207
add_string(name_path + "/" + f"attribute_{attr_idx}_key", attr_key)
208-
add_string(
209-
name_path + "/" + f"attribute_{attr_idx}_value",
210-
diag.attributes[attr_key],
211-
)
208+
if attr_key == "heat_capacity_ratio":
209+
add_double(
210+
name_path + "/" + f"attribute_{attr_idx}_value",
211+
diag.attributes[attr_key],
212+
)
213+
else:
214+
add_string(
215+
name_path + "/" + f"attribute_{attr_idx}_value",
216+
diag.attributes[attr_key],
217+
)
212218

213219
if len(sim.diagnostics) > 0:
214220
if sim.diag_options is not None and "options" in sim.diag_options:

src/core/numerics/primite_conservative_converter/to_primitive_converter.hpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,7 @@ class ToPrimitiveConverter : public LayoutHolder<GridLayout>
4545
void operator()(Field const& rho, VecField const& rhoV, VecField const& B, Field const& Etot,
4646
VecField& V, Field& P) const
4747
{
48-
ToPrimitiveConverter_ref<GridLayout>{*this->layout_, gamma_}(rho, rhoV, B, Etot, V, P);
49-
}
50-
51-
// used for diagnostics
52-
template<typename Field, typename VecField>
53-
void rhoVToV(Field const& rho, VecField const& rhoV, VecField& V) const
54-
{
55-
layout_.evalOnBox(rho, [&](auto&... args) mutable {
56-
ToPrimitiveConverter_ref<GridLayout>::rhoVToV_(rho, rhoV, V, {args...});
57-
});
58-
}
59-
60-
template<typename Field, typename VecField>
61-
void eosEtotToP(Field const& rho, VecField const& rhoV, VecField const& B, Field const& Etot,
62-
Field& P) const
63-
{
64-
layout_.evalOnBox(rho, [&](auto&... args) mutable {
65-
ToPrimitiveConverter_ref<GridLayout>::eosEtotToP_(gamma_, rho, rhoV, B, Etot, P,
66-
{args...});
67-
});
48+
ToPrimitiveConverter_ref<GridLayout>{*this->layout_}(gamma_, rho, rhoV, B, Etot, V, P);
6849
}
6950

7051
private:
@@ -77,23 +58,37 @@ class ToPrimitiveConverter_ref
7758
constexpr static auto dimension = GridLayout::dimension;
7859

7960
public:
80-
ToPrimitiveConverter_ref(GridLayout const& layout, double const gamma)
61+
ToPrimitiveConverter_ref(GridLayout const& layout)
8162
: layout_{layout}
82-
, gamma_{gamma}
8363
{
8464
}
8565

8666
template<typename Field, typename VecField>
87-
void operator()(Field const& rho, VecField const& rhoV, VecField const& B, Field const& Etot,
88-
VecField& V, Field& P) const
67+
void operator()(double const gamma, Field const& rho, VecField const& rhoV, VecField const& B,
68+
Field const& Etot, VecField& V, Field& P) const
69+
{
70+
rhoVToVOnBox(rho, rhoV, V);
71+
72+
eosEtotToPOnBox(gamma, rho, rhoV, B, Etot, P);
73+
}
74+
75+
// used for diagnostics
76+
template<typename Field, typename VecField>
77+
void rhoVToVOnBox(Field const& rho, VecField const& rhoV, VecField& V) const
8978
{
9079
layout_.evalOnBox(rho, [&](auto&... args) mutable { rhoVToV_(rho, rhoV, V, {args...}); });
80+
}
9181

82+
template<typename Field, typename VecField>
83+
void eosEtotToPOnBox(double const gamma, Field const& rho, VecField const& rhoV,
84+
VecField const& B, Field const& Etot, Field& P) const
85+
{
9286
layout_.evalOnBox(rho, [&](auto&... args) mutable {
93-
eosEtotToP_(gamma_, rho, rhoV, B, Etot, P, {args...});
87+
eosEtotToP_(gamma, rho, rhoV, B, Etot, P, {args...});
9488
});
9589
}
9690

91+
private:
9792
template<typename Field, typename VecField>
9893
static void rhoVToV_(Field const& rho, VecField const& rhoV, VecField& V,
9994
MeshIndex<Field::dimension> index)
@@ -137,8 +132,6 @@ class ToPrimitiveConverter_ref
137132

138133
private:
139134
GridLayout layout_;
140-
141-
double const gamma_;
142135
};
143136

144137
} // namespace PHARE::core

src/diagnostic/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ if (HighFive)
1717
${PROJECT_SOURCE_DIR}/detail/types/electromag.hpp
1818
${PROJECT_SOURCE_DIR}/detail/types/fluid.hpp
1919
${PROJECT_SOURCE_DIR}/detail/types/meta.hpp
20+
${PROJECT_SOURCE_DIR}/detail/types/mhd.hpp
2021
)
2122
endif()
2223

src/diagnostic/detail/h5writer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ class H5Writer
219219
// block public access to internal state
220220
friend class FluidDiagnosticWriter<This>;
221221
friend class ElectromagDiagnosticWriter<This>;
222+
friend class MHDDiagnosticWriter<This>;
222223
friend class ParticlesDiagnosticWriter<This>;
223224
friend class MetaDiagnosticWriter<This>;
224225
friend class InfoDiagnosticWriter<This>;

src/diagnostic/detail/types/mhd.hpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,12 @@ template<typename H5Writer>
6767
void MHDDiagnosticWriter<H5Writer>::createFiles(DiagnosticProperties& diagnostic)
6868
{
6969
std::string tree{"/mhd/"};
70-
checkCreateFileFor_(diagnostic, fileData_, tree, "density", "velocity", "B", "pressure", "rhoV",
71-
"Etot");
70+
checkCreateFileFor_(diagnostic, fileData_, tree, "rho", "V", "B", "P", "rhoV", "Etot");
7271
}
7372

7473
template<typename H5Writer>
7574
void MHDDiagnosticWriter<H5Writer>::compute(DiagnosticProperties& diagnostic)
7675
{
77-
core::ToPrimitiveConverter<GridLayout> toPrim;
78-
7976
auto& h5Writer = this->h5Writer_;
8077
auto& modelView = h5Writer.modelView();
8178
auto minLvl = h5Writer.minLevel;
@@ -89,19 +86,22 @@ void MHDDiagnosticWriter<H5Writer>::compute(DiagnosticProperties& diagnostic)
8986
auto& Etot = modelView.getEtot();
9087

9188
std::string tree{"/mhd/"};
92-
if (isActiveDiag(diagnostic, tree, "velocity"))
89+
if (isActiveDiag(diagnostic, tree, "V"))
9390
{
94-
auto computeVelocity = [&](GridLayout& layout, std::string& patchID, std::size_t iLevel) {
95-
auto _sl = core::SetLayout(&layout, toPrim);
96-
toPrim.rhoVToV(rho, rhoV, V);
91+
auto computeVelocity = [&](GridLayout& layout, std::string patchID, std::size_t iLevel) {
92+
core::ToPrimitiveConverter_ref<GridLayout> toPrim{layout};
93+
toPrim.rhoVToVOnBox(rho, rhoV, V);
9794
};
9895
modelView.visitHierarchy(computeVelocity, minLvl, maxLvl);
9996
}
100-
if (isActiveDiag(diagnostic, tree, "pressure"))
97+
if (isActiveDiag(diagnostic, tree, "P"))
10198
{
102-
auto computePressure = [&](GridLayout& layout, std::string& patchID, std::size_t iLevel) {
103-
auto _sl = core::SetLayout(&layout, toPrim);
104-
toPrim.eosEtotToP(rho, rhoV, B, Etot, P);
99+
auto computePressure = [&](GridLayout& layout, std::string patchID, std::size_t iLevel) {
100+
auto const gamma = diagnostic.fileAttributes["heat_capacity_ratio"]
101+
.template to<double>(); // or FloatType if we want to expose that
102+
// to DiagnosticProperties
103+
core::ToPrimitiveConverter_ref<GridLayout> toPrim{layout};
104+
toPrim.eosEtotToPOnBox(gamma, rho, rhoV, B, Etot, P);
105105
};
106106
modelView.visitHierarchy(computePressure, minLvl, maxLvl);
107107
}
@@ -143,18 +143,18 @@ void MHDDiagnosticWriter<H5Writer>::getDataSetInfo(DiagnosticProperties& diagnos
143143
};
144144

145145
std::string tree{"/mhd/"};
146-
if (isActiveDiag(diagnostic, tree, "density"))
147-
infoDS(rho, "density", patchAttributes[lvlPatchID]);
148-
if (isActiveDiag(diagnostic, tree, "velocity"))
149-
infoVF(V, "velocity", patchAttributes[lvlPatchID]);
146+
if (isActiveDiag(diagnostic, tree, "rho"))
147+
infoDS(rho, "rho", patchAttributes[lvlPatchID]["mhd"]);
148+
if (isActiveDiag(diagnostic, tree, "V"))
149+
infoVF(V, "V", patchAttributes[lvlPatchID]["mhd"]);
150150
if (isActiveDiag(diagnostic, tree, "B"))
151-
infoVF(B, "B", patchAttributes[lvlPatchID]);
152-
if (isActiveDiag(diagnostic, tree, "pressure"))
153-
infoDS(P, "pressure", patchAttributes[lvlPatchID]);
151+
infoVF(B, "B", patchAttributes[lvlPatchID]["mhd"]);
152+
if (isActiveDiag(diagnostic, tree, "P"))
153+
infoDS(P, "P", patchAttributes[lvlPatchID]["mhd"]);
154154
if (isActiveDiag(diagnostic, tree, "rhoV"))
155-
infoVF(rhoV, "rhoV", patchAttributes[lvlPatchID]);
155+
infoVF(rhoV, "rhoV", patchAttributes[lvlPatchID]["mhd"]);
156156
if (isActiveDiag(diagnostic, tree, "Etot"))
157-
infoDS(Etot, "Etot", patchAttributes[lvlPatchID]);
157+
infoDS(Etot, "Etot", patchAttributes[lvlPatchID]["mhd"]);
158158
}
159159

160160
template<typename H5Writer>
@@ -196,14 +196,14 @@ void MHDDiagnosticWriter<H5Writer>::initDataSets(
196196
std::string path = h5Writer.getPatchPathAddTimestamp(lvl, patchID) + "/";
197197

198198
std::string tree{"/mhd/"};
199-
if (isActiveDiag(diagnostic, tree, "density"))
200-
initDS(path, attr["mhd"], "density", null);
201-
if (isActiveDiag(diagnostic, tree, "velocity"))
202-
initVF(path, attr["mhd"], "velocity", null);
199+
if (isActiveDiag(diagnostic, tree, "rho"))
200+
initDS(path, attr["mhd"], "rho", null);
201+
if (isActiveDiag(diagnostic, tree, "V"))
202+
initVF(path, attr["mhd"], "V", null);
203203
if (isActiveDiag(diagnostic, tree, "B"))
204204
initVF(path, attr["mhd"], "B", null);
205-
if (isActiveDiag(diagnostic, tree, "pressure"))
206-
initDS(path, attr["mhd"], "pressure", null);
205+
if (isActiveDiag(diagnostic, tree, "P"))
206+
initDS(path, attr["mhd"], "P", null);
207207
if (isActiveDiag(diagnostic, tree, "rhoV"))
208208
initVF(path, attr["mhd"], "rhoV", null);
209209
if (isActiveDiag(diagnostic, tree, "Etot"))
@@ -233,14 +233,14 @@ void MHDDiagnosticWriter<H5Writer>::write(DiagnosticProperties& diagnostic)
233233

234234
std::string path = h5Writer.patchPath() + "/";
235235
std::string tree{"/mhd/"};
236-
if (isActiveDiag(diagnostic, tree, "density"))
237-
writeDS(path + "density", rho);
238-
if (isActiveDiag(diagnostic, tree, "velocity"))
239-
writeTF(path + "velocity", V);
236+
if (isActiveDiag(diagnostic, tree, "rho"))
237+
writeDS(path + "rho", rho);
238+
if (isActiveDiag(diagnostic, tree, "V"))
239+
writeTF(path + "V", V);
240240
if (isActiveDiag(diagnostic, tree, "B"))
241241
writeTF(path + "B", B);
242-
if (isActiveDiag(diagnostic, tree, "pressure"))
243-
writeDS(path + "pressure", P);
242+
if (isActiveDiag(diagnostic, tree, "P"))
243+
writeDS(path + "P", P);
244244
if (isActiveDiag(diagnostic, tree, "rhoV"))
245245
writeTF(path + "rhoV", rhoV);
246246
if (isActiveDiag(diagnostic, tree, "Etot"))

src/diagnostic/diagnostic_manager.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,16 @@ DiagnosticsManager<Writer>::addDiagDict(initializer::PHAREDict const& diagParams
161161
{
162162
std::string idx = std::to_string(i);
163163
std::string key = diagParams["attribute_" + idx + "_key"].template to<std::string>();
164-
std::string val = diagParams["attribute_" + idx + "_value"].template to<std::string>();
165-
diagProps.fileAttributes[key] = val;
164+
if (key == "heat_capacity_ratio")
165+
{
166+
double val = diagParams["attribute_" + idx + "_value"].template to<double>();
167+
diagProps.fileAttributes[key] = val;
168+
}
169+
else
170+
{
171+
std::string val = diagParams["attribute_" + idx + "_value"].template to<std::string>();
172+
diagProps.fileAttributes[key] = val;
173+
}
166174
}
167175

168176
return *this;

src/diagnostic/diagnostic_model_view.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class ModelView<Hierarchy, Model, MHDIdentifier> : public BaseModelView<Hierarch
197197

198198
NO_DISCARD VecField& getRhoV() const { return this->model_.state.rhoV; }
199199

200-
NO_DISCARD VecField& getEtot() const { return this->model_.state.Etot; }
200+
NO_DISCARD Field& getEtot() const { return this->model_.state.Etot; }
201201

202202
// What about E, J, etc. ? Those 2 in particular are physically relevant temporaries.
203203
};

src/diagnostic/diagnostic_props.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct DiagnosticProperties
1414
{
1515
// Types limited to actual need, no harm to modify
1616
using Params = cppdict::Dict<std::size_t>;
17-
using FileAttributes = cppdict::Dict<std::string>;
17+
using FileAttributes = cppdict::Dict<std::string, double>;
1818

1919
std::vector<double> writeTimestamps, computeTimestamps;
2020
std::string type, quantity;

src/diagnostic/diagnostics.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "diagnostic/detail/types/fluid.hpp"
3131
#include "diagnostic/detail/types/meta.hpp"
3232
#include "diagnostic/detail/types/info.hpp"
33+
#include "diagnostic/detail/types/mhd.hpp"
3334

3435
#endif
3536

src/simulator/simulator.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ void Simulator<dim, _interp, nbRefinedPart, MHDTimeStepper>::mhd_init(
392392
auto lbm_id = lbm_->getId(); // moved on next line
393393
multiphysInteg_->setLoadBalancerManager(std::move(lbm_));
394394

395-
if (dict["simulation"].contains("restarts"))
396-
startTime_ = restarts_init(dict["simulation"]["restarts"]);
395+
/*if (dict["simulation"].contains("restarts"))*/
396+
/* startTime_ = restarts_init(dict["simulation"]["restarts"]);*/
397397

398398
integrator_
399399
= std::make_unique<Integrator>(dict, hierarchy_, multiphysInteg_, multiphysInteg_,

tests/functional/mhd_orszagtang/orszag_tang_merged.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@
1616
time_step_nbr = 357
1717
time_step = 0.0014
1818
dt = 10 * time_step
19-
nt = time_step * time_step_nbr / (dt + 1)
20-
timestamps = dt * np.arange(nt)
19+
timestamps = dt * np.arange(int(time_step_nbr / 10) + 1)
2120

2221

2322
def config():
2423
cells = (128, 128)
2524
dl = (1.0 / cells[0], 1.0 / cells[1])
2625

2726
sim = ph.Simulation(
28-
smallest_patch_size=128,
29-
largest_patch_size=128,
27+
smallest_patch_size=15,
28+
largest_patch_size=25,
3029
time_step_nbr=time_step_nbr,
3130
time_step=time_step,
3231
cells=cells,

0 commit comments

Comments
 (0)