Skip to content

Commit 52c826f

Browse files
Merge pull request #4323 from forrestglines/parthenon-frontend
Add `Parthenon` frontend
2 parents 54aa1be + dd42468 commit 52c826f

16 files changed

+911
-3
lines changed

doc/source/analyzing/fields.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,9 @@ which results in:
439439
p_B = \frac{B^2}{2} \\
440440
v_A = \frac{B}{\sqrt{\rho}}
441441
442-
Using this convention is currently only available for :ref:`Athena<loading-athena-data>`
443-
and :ref:`Athena++<loading-athena-pp-data>` datasets, though it will likely be available
444-
for more datasets in the future.
442+
Using this convention is currently only available for :ref:`Athena<loading-athena-data>`,
443+
:ref:`Athena++<loading-athena-pp-data>`, and :ref:`AthenaPK<loading-parthenon-data>` datasets,
444+
though it will likely be available for more datasets in the future.
445445

446446
yt automatically detects on a per-frontend basis what units the magnetic should be in, and allows conversion between
447447
different magnetic field units in the different unit systems as well. To determine how to set up special magnetic field handling when designing a new frontend, check out

doc/source/examining/loading_data.rst

+117
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,123 @@ using a ``parameters`` dict, accepting the following keys:
553553
release.
554554
* Domains may be visualized assuming periodicity.
555555

556+
.. _loading-parthenon-data:
557+
558+
Parthenon Data
559+
--------------
560+
561+
Parthenon HDF5 data is supported and cared for by Forrest Glines and Philipp Grete.
562+
The Parthenon framework is the basis for various downstream codes, e.g.,
563+
`AthenaPK <https://github.com/parthenon-hpc-lab/athenapk>`_,
564+
`Phoebus <https://github.com/lanl/phoebus>`_,
565+
`KHARMA <https://github.com/AFD-Illinois/kharma>`_,
566+
RIOT, and the
567+
`parthenon-hydro <https://github.com/parthenon-hpc-lab/parthenon-hydro>`_ miniapp.
568+
Support for these codes is handled through the common Parthenon frontend with
569+
specifics described in the following.
570+
Note that only AthenaPK data is currently automatically converted to the
571+
standard fields known by yt.
572+
For other codes, the raw data of the fields stored in the output file is accessible
573+
and a conversion between those fields and yt standard fields needs to be done manually.
574+
575+
.. rubric:: Caveats
576+
577+
* Reading particle data from Parthenon output is currently not supported.
578+
* Spherical and cylindrical coordinates only work for AthenaPK data.
579+
* Only periodic boundary conditions are properly handled. Calculating quantities requiring
580+
larger stencils (like derivatives) will be incorrect at mesh boundaries that are not periodic.
581+
582+
AthenaPK
583+
^^^^^^^^
584+
585+
Fluid data on uniform-grid, SMR, and AMR datasets in Cartesian coordinates are fully supported.
586+
587+
AthenaPK data may contain information on units in the output (when specified
588+
via the ``<units>`` block in the input file when the simulation was originally run).
589+
If that information is present, it will be used by yt.
590+
Otherwise the default unit system will be the code unit
591+
system with conversion of 1 ``code_length`` equalling 1 cm, and so on (given yt's default
592+
cgs/"Gaussian" unit system). If you would like to provided different
593+
conversions, you may supply conversions for length, time, and mass to ``load``
594+
using the ``units_override`` functionality:
595+
596+
.. code-block:: python
597+
598+
import yt
599+
600+
units_override = {
601+
"length_unit": (1.0, "Mpc"),
602+
"time_unit": (1.0, "Myr"),
603+
"mass_unit": (1.0e14, "Msun"),
604+
}
605+
606+
ds = yt.load("parthenon.restart.final.rhdf", units_override=units_override)
607+
608+
This means that the yt fields, e.g. ``("gas","density")``,
609+
``("gas","velocity_x")``, ``("gas","magnetic_field_x")``, will be in cgs units
610+
(or whatever unit system was specified), but the AthenaPK fields, e.g.,
611+
``("parthenon","prim_density")``, ``("parthenon","prim_velocity_1")``,
612+
``("parthenon","prim_magnetic_field_1")``, will be in code units.
613+
614+
The default normalization for various magnetic-related quantities such as
615+
magnetic pressure, Alfven speed, etc., as well as the conversion between
616+
magnetic code units and other units, is Gaussian/CGS, meaning that factors
617+
of :math:`4\pi` or :math:`\sqrt{4\pi}` will appear in these quantities, e.g.
618+
:math:`p_B = B^2/8\pi`. To use the Lorentz-Heaviside normalization instead,
619+
in which the factors of :math:`4\pi` are dropped (:math:`p_B = B^2/2), for
620+
example), set ``magnetic_normalization="lorentz_heaviside"`` in the call to
621+
``yt.load``:
622+
623+
.. code-block:: python
624+
625+
ds = yt.load(
626+
"parthenon.restart.final.rhdf",
627+
units_override=units_override,
628+
magnetic_normalization="lorentz_heaviside",
629+
)
630+
631+
Alternative values (i.e., overriding the default ones stored in the simulation
632+
output) for the following simulation parameters may be specified
633+
using a ``parameters`` dict, accepting the following keys:
634+
635+
* ``gamma``: ratio of specific heats, Type: Float. If not specified,
636+
:math:`\gamma = 5/3` is assumed.
637+
* ``mu``: mean molecular weight, Type: Float. If not specified, :math:`\mu = 0.6`
638+
(for a fully ionized primordial plasma) is assumed.
639+
640+
Other Parthenon based codes
641+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
642+
643+
As mentioned above, a default conversion from code fields to yt fields (e.g.,
644+
from a density field to ``("gas","density")``) is currently not available --
645+
though more specialized frontends may be added in the future.
646+
647+
All raw data of a Parthenon-based simulation output is available through
648+
the ``("parthenon","NAME")`` fields where ``NAME`` varies between codes
649+
and the respective code documentation should be consulted.
650+
651+
One option to manually convert those raw fields to the standard yt fields
652+
is by adding derived fields, e.g., for the field named "``mass.density``"
653+
that is stored in cgs units on disk:
654+
655+
.. code-block:: python
656+
657+
from yt import derived_field
658+
659+
660+
@derived_field(name="density", units="g*cm**-3", sampling_type="cell")
661+
def _density(field, data):
662+
return data[("parthenon", "mass.density")] * yt.units.g / yt.units.cm**3
663+
664+
Moreover, an ideal equation of state is assumed with the following parameters,
665+
which may be specified using a ``parameters`` dict, accepting the following keys:
666+
667+
* ``gamma``: ratio of specific heats, Type: Float. If not specified,
668+
:math:`\gamma = 5/3` is assumed.
669+
* ``mu``: mean molecular weight, Type: Float. If not specified, :math:`\mu = 0.6`
670+
(for a fully ionized primordial plasma) is assumed.
671+
672+
556673
.. _loading-orion-data:
557674

558675
AMReX / BoxLib Data

doc/source/reference/code_support.rst

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ each supported output format using yt.
7070
+-----------------------+------------+-----------+------------+-------+----------+----------+------------+-------------+
7171
| OWLS/EAGLE | Y | Y | Y | Y | Y | Y | Y | Full |
7272
+-----------------------+------------+-----------+------------+-------+----------+----------+------------+-------------+
73+
| Parthenon | Y | N | Y | Y | Y | Y | Y | Partial |
74+
+-----------------------+------------+-----------+------------+-------+----------+----------+------------+-------------+
7375
| Piernik | Y | N/A | Y | Y | Y | Y | Y | Full |
7476
+-----------------------+------------+-----------+------------+-------+----------+----------+------------+-------------+
7577
| Pluto | Y | N | Y | Y | Y | Y | Y | Partial |

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ nc4-cm1 = ["yt[netCDF4]"]
124124
open-pmd = ["yt[HDF5]"]
125125
owls = ["yt[HDF5]"]
126126
owls-subfind = ["yt[HDF5]"]
127+
parthenon = ["yt[HDF5]"]
127128
ramses = ["yt[Fortran]"]
128129
rockstar = []
129130
sdf = ["requests>=2.20.0"]
@@ -183,6 +184,7 @@ full = [
183184
"yt[open_pmd]",
184185
"yt[owls]",
185186
"yt[owls_subfind]",
187+
"yt[parthenon]",
186188
"yt[ramses]",
187189
"yt[rockstar]",
188190
"yt[sdf]",
@@ -353,6 +355,7 @@ addopts = '''
353355
--ignore-glob='/*/yt/frontends/open_pmd/tests/test_outputs.py'
354356
--ignore-glob='/*/yt/frontends/owls/tests/test_outputs.py'
355357
--ignore-glob='/*/yt/frontends/owls_subfind/tests/test_outputs.py'
358+
--ignore-glob='/*/yt/frontends/parthenon/tests/test_outputs.py'
356359
--ignore-glob='/*/yt/frontends/ramses/tests/test_outputs.py'
357360
--ignore-glob='/*/yt/frontends/rockstar/tests/test_outputs.py'
358361
--ignore-glob='/*/yt/frontends/tipsy/tests/test_outputs.py'

tests/tests.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ answer_tests:
171171
local_nc4_cm1_002: # PR 2176, 2998
172172
- yt/frontends/nc4_cm1/tests/test_outputs.py:test_cm1_mesh_fields
173173

174+
local_parthenon_001: # PR 4323
175+
- yt/frontends/parthenon/tests/test_outputs.py:test_loading_data
176+
- yt/frontends/parthenon/tests/test_outputs.py:test_cluster
177+
- yt/frontends/parthenon/tests/test_outputs.py:test_derived_fields
178+
174179
other_tests:
175180
unittests:
176181
# keep in sync with nose_ignores.txt

yt/frontends/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"open_pmd",
3636
"owls",
3737
"owls_subfind",
38+
"parthenon",
3839
"ramses",
3940
"rockstar",
4041
"sdf",

yt/frontends/parthenon/__init__.py

Whitespace-only changes.

yt/frontends/parthenon/api.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from . import tests
2+
from .data_structures import ParthenonDataset, ParthenonGrid, ParthenonHierarchy
3+
from .fields import ParthenonFieldInfo
4+
from .io import IOHandlerParthenon

0 commit comments

Comments
 (0)