-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fb6a68
commit b7147a9
Showing
4 changed files
with
167 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#ifndef _PHARE_CORE_DATA_ELECTROMAG_ELECTROMAG_INITIALIZER_HPP_ | ||
#define _PHARE_CORE_DATA_ELECTROMAG_ELECTROMAG_INITIALIZER_HPP_ | ||
|
||
#include "initializer/data_provider.hpp" | ||
|
||
#include <array> | ||
|
||
|
||
namespace PHARE::core | ||
{ | ||
|
||
template<typename Electromag_t, typename GridLayout> | ||
class ElectromagInitializer | ||
{ | ||
public: | ||
virtual void init(Electromag_t& /*em*/, GridLayout const& /*layout*/) const { /*noop*/ } | ||
virtual ~ElectromagInitializer() {} | ||
}; | ||
|
||
template<typename Electromag_t, typename GridLayout> | ||
class ElectromagUserFuncInitializer : public ElectromagInitializer<Electromag_t, GridLayout> | ||
{ | ||
public: | ||
ElectromagUserFuncInitializer(initializer::PHAREDict const& dict) | ||
: Binit_{dict["magnetic"]["initializer"]} | ||
{ | ||
} | ||
virtual ~ElectromagUserFuncInitializer() {} | ||
|
||
void init(Electromag_t& em, GridLayout const& layout) const override | ||
{ | ||
Binit_.initialize(em.B, layout); | ||
} | ||
|
||
VecFieldInitializer<Electromag_t::dimension> Binit_; | ||
}; | ||
|
||
|
||
template<typename Electromag_t, typename GridLayout> | ||
class ElectromagInitializerFactory | ||
{ | ||
public: | ||
NO_DISCARD static std::unique_ptr<ElectromagInitializer<Electromag_t, GridLayout>> | ||
create(initializer::PHAREDict const& dict) | ||
{ | ||
return std::make_unique<ElectromagUserFuncInitializer<Electromag_t, GridLayout>>(dict); | ||
// else | ||
// return std::make_unique<ElectromagInitializer<Electromag_t>>(); | ||
} | ||
}; | ||
|
||
} // namespace PHARE::core | ||
|
||
#endif // _PHARE_CORE_DATA_ELECTROMAG_ELECTROMAG_INITIALIZER_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import copy | ||
|
||
import time | ||
import h5py | ||
import datetime | ||
import unittest | ||
import numpy as np | ||
from pathlib import Path | ||
from datetime import timedelta | ||
|
||
from ddt import ddt, data, unpack | ||
|
||
from pyphare.cpp import cpp_lib | ||
|
||
cpp = cpp_lib() | ||
|
||
import pyphare.pharein as ph | ||
from pyphare.pharesee.run import Run | ||
from pyphare.simulator.simulator import Simulator | ||
|
||
from tests.simulator import SimulatorTest | ||
from tests.diagnostic import dump_all_diags | ||
from pyphare.pharesee.hierarchy.patchdata import ParticleData | ||
from pyphare.pharesee.hierarchy.fromh5 import get_all_available_quantities_from_h5 | ||
|
||
# ./build/tests/simulator/phare_outputs/restarts/test/test_restarts_1/1/1/1/00000.00400/restore.000000/nodes.0000001/proc.0000000 | ||
|
||
|
||
def setup_model(ppc=100): | ||
model = ph.MaxwellianFluidModel(protons={"nbr_part_per_cell": ppc}) | ||
ph.ElectronModel(closure="isothermal", Te=0.12) | ||
return model | ||
|
||
|
||
timestep = 0.001 | ||
out = "phare_outputs/parse_restarts" | ||
simArgs = dict( | ||
time_step_nbr=2, | ||
time_step=timestep, | ||
cells=200, | ||
dl=0.3, | ||
restart_options=dict(dir=out, mode="overwrite"), | ||
) | ||
|
||
|
||
def traverse_h5_for_groups_recursive(h5content: "H5Content", group, path=""): | ||
if "level_0000" in path: | ||
for key in group.attrs: | ||
h5content.attr[f"{path}/{key}"] = group.attrs[key] | ||
if isinstance(group, h5py._hl.group.Group): | ||
for key in group: | ||
kpath = f"{path}/{key}" | ||
traverse_h5_for_groups_recursive(h5content, group[key], path=kpath) | ||
else: | ||
if "level_0000" not in path: | ||
return | ||
h5content.data[path] = group | ||
|
||
|
||
class H5Content: | ||
def __init__(self, path): | ||
self.file = h5py.File(path, "r") | ||
self.data = {} | ||
self.attr = {} | ||
traverse_h5_for_groups_recursive(self, self.file) | ||
|
||
|
||
@ddt | ||
class RestartsParserTest(SimulatorTest): | ||
def __init__(self, *args, **kwargs): | ||
super(RestartsParserTest, self).__init__(*args, **kwargs) | ||
self.simulator = None | ||
|
||
def tearDown(self): | ||
super(RestartsParserTest, self).tearDown() | ||
if self.simulator is not None: | ||
self.simulator.reset() | ||
self.simulator = None | ||
ph.global_vars.sim = None | ||
|
||
def test_restart_parser(self): | ||
h5_filepath = "phare_outputs/restarts/test/test_restarts_1/1/1/1/00000.00400/restore.000000/nodes.0000001/proc.0000000" | ||
|
||
h5 = H5Content(h5_filepath) | ||
print( | ||
h5.file[ | ||
"/PHARE_hierarchy/level_0000/level_0000-patch_0000000-block_0000000/EMAvg_B_x##default/d_ghost_box" | ||
][:] | ||
) | ||
for k in h5.data: | ||
print(k) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |