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

Support for cosmic ray fields in GAMER #4739

Merged
merged 6 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions yt/frontends/gamer/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ def _parse_parameter_file(self):
# make aliases to some frequently used variables
if parameters["Model"] == "Hydro":
self.gamma = parameters["Gamma"]
self.gamma_cr = self.parameters.get("CR_Gamma", None)
self.eos = parameters.get("EoS", 1) # Assume gamma-law by default
# default to 0.6 for old data format
self.mu = parameters.get(
Expand Down
18 changes: 18 additions & 0 deletions yt/frontends/gamer/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class GAMERFieldInfo(FieldInfoContainer):
("MomY", (mom_units, ["momentum_density_y"], None)),
("MomZ", (mom_units, ["momentum_density_z"], None)),
("Engy", (erg_units, ["total_energy_density"], None)),
("CRay", (erg_units, ["cosmic_ray_energy_density"], None)),
("Pote", (pot_units, ["gravitational_potential"], None)),
# MHD fields on disk (CC=cell-centered)
("CCMagX", (b_units, [], "B_x")),
Expand Down Expand Up @@ -289,6 +290,9 @@ def et(data):
if self.ds.mhd:
# magnetic_energy is a yt internal field
Et -= data["gas", "magnetic_energy_density"]
if self.ds.gamma_cr is not None:
# cosmic rays are included in this dataset
Et -= data["gas", "cosmic_ray_energy_density"]
return Et

# thermal energy per mass (i.e., specific)
Expand Down Expand Up @@ -334,6 +338,20 @@ def _thermal_energy_density(field, data):
units=unit_system["pressure"],
)

if self.ds.gamma_cr is not None:

def _cr_pressure(field, data):
return (data.ds.gamma_cr - 1.0) * data[
"gas", "cosmic_ray_energy_density"
]

self.add_field(
("gas", "cosmic_ray_pressure"),
_cr_pressure,
sampling_type="cell",
units=self.ds.unit_system["pressure"],
)

# mean molecular weight
if hasattr(self.ds, "mu"):

Expand Down