Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Binary/*run1*

DiskHaloA/*run0*
DiskHaloA/processor.rates
__pycache__/
8 changes: 7 additions & 1 deletion EXP-units/expunits.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ def compute_scales(G_old, G_new, s_L, s_V, s_M):
s_L, s_V, s_M are either floats or None.
Returns (s_L, s_V, s_M). Raises ValueError if insufficient or inconsistent.
"""
# Validate G_new is physically meaningful
if G_new <= 0:
raise ValueError(f"G_new must be positive (got {G_new}). Zero or negative gravitational constants are not physically meaningful.")
if G_old <= 0:
raise ValueError(f"G_old must be positive (got {G_old}). Zero or negative gravitational constants are not physically meaningful.")

known = [(s_L is not None), (s_V is not None), (s_M is not None)]
n_known = sum(known)

Expand All @@ -114,7 +120,7 @@ def compute_scales(G_old, G_new, s_L, s_V, s_M):
G_check = (s_L * s_V**2) / (G_old * s_M)
if not math.isfinite(G_check):
raise ValueError("Computed G_check is not finite.")
if abs((G_check - G_new) / (abs(G_new) if G_new != 0 else 1.0)) > 1e-9:
if abs((G_check - G_new) / G_new) > 1e-9:
raise ValueError(f"Inconsistent scales: G_new requested {G_new} but scales give {G_check}.")
return s_L, s_V, s_M

Expand Down