Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update some peripheral utils for prediction #873

Merged
merged 14 commits into from
Apr 20, 2023
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: |
MINIFORGE_INSTALL_DIR=.miniforge3
. "$MINIFORGE_INSTALL_DIR/bin/activate" testing
python -m pip install types-psutil
python -m pip install types-psutil types-PyYAML
./run-mypy.sh

pylint:
Expand Down
28 changes: 27 additions & 1 deletion mirgecom/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.. autofunction:: make_status_message
.. autofunction:: make_rank_fname
.. autofunction:: make_par_fname
.. autofunction:: read_and_distribute_yaml_data
"""

__copyright__ = """
Expand Down Expand Up @@ -38,14 +39,16 @@
def make_init_message(*, dim, order, dt, t_final,
nstatus, nviz, cfl, constant_cfl,
initname, eosname, casename,
nelements=0, global_nelements=0):
nelements=0, global_nelements=0,
t_initial=0):
"""Create a summary of some general simulation parameters and inputs."""
return (
f"Initialization for Case({casename})\n"
f"===\n"
f"Num {dim}d order-{order} elements: {nelements}\n"
f"Num global elements: {global_nelements}\n"
f"Timestep: {dt}\n"
f"Initial time: {t_initial}\n"
f"Final time: {t_final}\n"
f"CFL: {cfl}\n"
f"Constant CFL: {constant_cfl}\n"
Expand Down Expand Up @@ -77,3 +80,26 @@ def make_rank_fname(basename, rank=0, step=0, t=0):
def make_par_fname(basename, step=0, t=0):
r"""Make parallel visualization filename."""
return f"{basename}-{step:09d}.pvtu"


def read_and_distribute_yaml_data(mpi_comm=None, file_path=None):
"""Read a YAML file on one rank, broadcast result to world."""
import yaml

input_data = None
if file_path is None:
return input_data

rank = 0

if mpi_comm is not None:
rank = mpi_comm.Get_rank()

if rank == 0:
with open(file_path) as f:
input_data = yaml.load(f, Loader=yaml.FullLoader)

if mpi_comm is not None:
input_data = mpi_comm.bcast(input_data, root=0)

return input_data
Loading