Skip to content

Commit a4b2fae

Browse files
committed
fix: Fix constants
1 parent cbe768f commit a4b2fae

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

src/radiosim/ppdisks/simulation.py

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ def get_default_sampling_config():
2929
return {
3030
"disk_parameters": {
3131
"aspect_ratio": [0.01, 0.1], # Disk aspect ratio @ r=R0 (default R0 = 1AU)
32-
"disk_mass_ref_radius": 1000, # Reference radius R_ref in AU
33-
"disk_mass": [0.001, 0.01], # Cumulative disk mask @ r=R_ref
34-
"sigma_slope": [0.05, 0.3], # Exponent of the density profile
32+
"disk_mass_ref_radius": 150, # Reference radius R_ref in AU
33+
"disk_mass": [0.01, 0.03], # Cumulative disk mask in M_sun @ r=R_ref
34+
"sigma_slope": [0.1, 0.3], # Exponent of the density profile
3535
"flaring_index": [0.0, 0.0],
3636
"alpha": [0.001, 0.01], # Shakura-Sunyaev viscosity parameter
3737
},
@@ -113,6 +113,7 @@ def __init__(
113113
float_type: type,
114114
polar_img_size: tuple[int],
115115
unit_system: UnitSystem,
116+
use_default_constants: bool,
116117
):
117118
self.name: str = name
118119
self._root_directory: Path = Path(root_directory)
@@ -135,7 +136,16 @@ def __init__(
135136
self._polar_img_size: tuple[int] = polar_img_size
136137

137138
self._unit_system: UnitSystem = unit_system
138-
self._constants: Constants = Constants(unit_system=unit_system, autosave=True)
139+
self._use_default_constants: bool = use_default_constants
140+
141+
if use_default_constants:
142+
self._constants: Constants = Constants.default(unit_system=unit_system)
143+
self._constants._autosave = True
144+
self._constants.save()
145+
else:
146+
self._constants: Constants = Constants(
147+
unit_system=unit_system, autosave=True
148+
)
139149

140150
self._planet_config: PlanetConfig = PlanetConfig(
141151
name=f"radiosim_{self.name}", autosave=True, unit_system=self._unit_system
@@ -152,6 +162,7 @@ def save_config(self) -> None:
152162
else "FLOAT32",
153163
"polar_img_size": list(self._polar_img_size),
154164
"unit_system": self._unit_system.name,
165+
"use_default_constants": self._use_default_constants,
155166
}
156167
}
157168
self._config.dump_dict(content)
@@ -304,9 +315,13 @@ def simulate(
304315
]
305316

306317
param_config["disk_parameters.sigma0"] = sigma0(
307-
ref_radius=disk_parameters["disk_mass_ref_radius"],
308-
R0=self._constants["R0"],
309-
mass=disk_parameters["disk_mass"],
318+
ref_radius=(disk_parameters["disk_mass_ref_radius"] * un.AU)
319+
.to(self._unit_system.length)
320+
.value,
321+
R0=self._constants["R0"].value,
322+
mass=(disk_parameters["disk_mass"] * const.M_sun)
323+
.to(self._unit_system.mass)
324+
.value,
310325
sigma_slope=disk_parameters["sigma_slope"],
311326
)
312327

@@ -480,6 +495,7 @@ def new(
480495
float_type: type = np.float64,
481496
polar_img_size: tuple[int] = (300, 800),
482497
unit_system: UnitSystem | str = UnitSystem.MKS,
498+
use_default_constants: bool = True,
483499
) -> "Simulation":
484500
if parent_directory is None:
485501
parent_directory = Path.cwd()
@@ -524,7 +540,8 @@ def new(
524540
setup=setup,
525541
float_type=float_type,
526542
polar_img_size=polar_img_size,
527-
unit_system=unit_system.default(),
543+
unit_system=unit_system,
544+
use_default_constants=use_default_constants,
528545
)
529546

530547
instance.save_config()
@@ -548,6 +565,7 @@ def load(cls, root_directory: PathLike) -> "Simulation":
548565
else np.float32,
549566
polar_img_size=tuple(config["general.polar_img_size"]),
550567
unit_system=UnitSystem.__members__[config["general.unit_system"]],
568+
use_default_constants=config["general.use_default_constants"],
551569
)
552570

553571
return instance
@@ -856,6 +874,8 @@ def plot_density_profile(
856874
show_formula: bool = False,
857875
r_min: float | None = None,
858876
r_max: float | None = None,
877+
x_norm: str | None = None,
878+
y_norm: str | None = None,
859879
plot_args: dict | None = None,
860880
fig: matplotlib.figure.Figure | None = None,
861881
fig_args: dict | None = None,
@@ -881,10 +901,23 @@ def plot_density_profile(
881901
sample_config = self.get_sample_config()
882902
unit_system = self._run._sim._unit_system
883903

904+
s0 = sigma0(
905+
ref_radius=(sample_config["disk_parameters.disk_mass_ref_radius"] * un.AU)
906+
.to(unit_system.length)
907+
.value,
908+
R0=self._run._sim._constants["R0"].value,
909+
mass=(sample_config["disk_parameters.disk_mass"] * const.M_sun)
910+
.to(unit_system.mass)
911+
.value,
912+
sigma_slope=sample_config["disk_parameters.sigma_slope"],
913+
)
914+
915+
print(s0)
916+
884917
density = surface_density(
885918
radii,
886919
R0=self._run._sim._constants["R0"].value,
887-
sigma0=sample_config["disk_parameters.sigma0"],
920+
sigma0=s0,
888921
sigma_slope=sample_config["disk_parameters.sigma_slope"],
889922
) * (unit_system.mass / unit_system.length**2).to(density_unit)
890923

@@ -893,7 +926,7 @@ def plot_density_profile(
893926
ax.plot(
894927
radii,
895928
density,
896-
label="$\\Sigma(R)=\\Sigma_0 \cdot (\\frac{R}{R_0})^{-p}$"
929+
label="$\\Sigma(R)=\\Sigma_0 \\cdot (\\frac{R}{R_0})^{-p}$"
897930
if show_formula
898931
else None,
899932
**plot_args,
@@ -916,6 +949,13 @@ def plot_density_profile(
916949
ax.set_ylabel(
917950
f"Density Profile $\\Sigma$ in {density_unit.to_string(format='latex')}"
918951
)
952+
953+
if x_norm is not None:
954+
ax.set_xscale(x_norm)
955+
956+
if y_norm is not None:
957+
ax.set_yscale(y_norm)
958+
919959
ax.legend()
920960

921961
if save_to is not None:

0 commit comments

Comments
 (0)