Skip to content

Commit

Permalink
Fix units of potential
Browse files Browse the repository at this point in the history
  • Loading branch information
cphyc committed Apr 1, 2021
1 parent 5aa1c29 commit fe208ab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion yt/frontends/ramses/field_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def detect_fields(cls, ds):
ndim = ds.dimensionality

if nvar == ndim + 1:
fields = ["potential"] + [f"{k}-acceleration" for k in "xyz"[:ndim]]
fields = ["Potential"] + [f"{k}-acceleration" for k in "xyz"[:ndim]]
else:
fields = [f"{k}-acceleration" for k in "xyz"[:ndim]]
ndetected = len(fields)
Expand Down
3 changes: 2 additions & 1 deletion yt/frontends/ramses/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
vel_units = "code_velocity"
pressure_units = "code_pressure"
ener_units = "code_mass * code_velocity**2"
specific_ener_units = "code_velocity**2"
ang_mom_units = "code_mass * code_velocity * code_length"
cooling_function_units = " erg * cm**3 /s"
cooling_function_prime_units = " erg * cm**3 /s/K"
Expand Down Expand Up @@ -90,7 +91,7 @@ class RAMSESFieldInfo(FieldInfoContainer):
("x-acceleration", (ra_units, ["acceleration_x"], None)),
("y-acceleration", (ra_units, ["acceleration_y"], None)),
("z-acceleration", (ra_units, ["acceleration_z"], None)),
("Potential", (ener_units, ["potential"], None)),
("Potential", (specific_ener_units, ["potential"], None)),
("B_x_left", (b_units, ["magnetic_field_x_left"], None)),
("B_x_right", (b_units, ["magnetic_field_x_right"], None)),
("B_y_left", (b_units, ["magnetic_field_y_left"], None)),
Expand Down
28 changes: 18 additions & 10 deletions yt/frontends/ramses/tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,25 @@ def check_unit(array, unit):


@requires_file(output_00080)
@requires_file(ramses_sink)
def test_grav_detection():
ds = yt.load(output_00080)

# Test detection
for k in "xyz":
assert ("gravity", f"{k}-acceleration") in ds.field_list
assert ("gas", f"acceleration_{k}") in ds.derived_field_list

# Test access
for k in "xyz":
ds.r["gas", f"acceleration_{k}"]
for path, has_potential in ((output_00080, False), (ramses_sink, True)):
ds = yt.load(path)

# Test detection
for k in "xyz":
assert ("gravity", f"{k}-acceleration") in ds.field_list
assert ("gas", f"acceleration_{k}") in ds.derived_field_list

if has_potential:
assert ("gravity", "Potential") in ds.field_list
assert ("gas", "potential") in ds.derived_field_list

# Test access
for k in "xyz":
ds.r["gas", f"acceleration_{k}"].to("m/s**2")
if has_potential:
ds.r["gas", "potential"].to("m**2/s**2")


@requires_file(ramses_sink)
Expand Down

0 comments on commit fe208ab

Please sign in to comment.