Organize in submodules
This commit is contained in:
@@ -0,0 +1,464 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import h5py
|
||||
import numpy as np
|
||||
import matplotlib as mpl
|
||||
from astrophysix import units as U
|
||||
from astrophysix.simdm import Project, ProjectCategory, SimulationStudy
|
||||
from astrophysix.simdm.datafiles import PlotInfo, PlotType
|
||||
from astrophysix.utils.file import FileType
|
||||
|
||||
from plotter import Plotter
|
||||
from params import default_params
|
||||
from ramses_astrophysix import ramses
|
||||
|
||||
|
||||
# ---------------------------------------------- Global parameters ------------------------------------------ #
|
||||
|
||||
# groups = ["jr13_tic"]
|
||||
groups = ["jr11", "jr12", "jr12_tic", "jr13_tic"]
|
||||
keep_plot_info = False
|
||||
include_hdf5 = True
|
||||
replot = True
|
||||
nml_key = "cloud_params/beta_cool"
|
||||
select = {
|
||||
"time": 4.5,
|
||||
# "filter_nml" : (nml_key, "=", 8),
|
||||
}
|
||||
|
||||
|
||||
params = default_params()
|
||||
params.input.nml_filename = "disk.nml"
|
||||
params.pymses.map_size = 2048
|
||||
params.pymses.zoom = 4
|
||||
params.pymses.filter = False
|
||||
params.pymses.variables = ["rho", "vel", "P", "g"]
|
||||
params.pymses.multiprocessing = True
|
||||
params.process.verbose = True
|
||||
params.disk.enable = True
|
||||
params.disk.nb_bin = 100
|
||||
params.pdf.nb_bin = 100
|
||||
params.process.num_process = 10
|
||||
in_dir = "/drf/projets/alfven-data/nbrucy/simus/fragdisk"
|
||||
out_dir = "/dsm/anais/storageA/nbrucy/visus/fragdisk/mnras"
|
||||
in_dir_conv = "/drf/projets/alfven-data/nbrucy/simus/conv_disk"
|
||||
out_dir_conv = "/dsm/anais/storageA/nbrucy/visus/conv_disk"
|
||||
|
||||
|
||||
# ---------------------------------------------- Project creation ------------------------------------------ #
|
||||
# Available project categories are :
|
||||
# - ProjectCategory.SolarMHD
|
||||
# - ProjectCategory.PlanetaryAtmospheres
|
||||
# - ProjectCategory.StarPlanetInteractions
|
||||
# - ProjectCategory.StarFormation
|
||||
# - ProjectCategory.Supernovae
|
||||
# - ProjectCategory.GalaxyFormation
|
||||
# - ProjectCategory.GalaxyMergers
|
||||
# - ProjectCategory.Cosmology
|
||||
proj = Project(
|
||||
category=ProjectCategory.StarPlanetInteractions,
|
||||
project_title="Fragdisk",
|
||||
alias="FRAGDISK",
|
||||
short_description="Fragmentation of self-gravitating disks",
|
||||
general_description="""
|
||||
|
||||
<h4> Study of the fragmentation of self-gravitating disks</h4>
|
||||
<p>
|
||||
See Brucy & Hennebelle 2021 (submitted) for more details.
|
||||
This database is currently being completed.
|
||||
</p>
|
||||
|
||||
<h4>Abstract:</h4>
|
||||
|
||||
<p>
|
||||
Self-gravitating disks are believed to play an important role in astrophysics in particular regarding the
|
||||
star and planet formation process.
|
||||
In this context, disks subject to an idealized cooling process, characterized by a cooling timescale
|
||||
$\\beta$ expressed in unit of orbital timescale, have been extensively studied.
|
||||
We take advantage of the Riemann solver and the 3D Godunov scheme implemented in the code Ramses to
|
||||
perform high resolution simulations, complementing previous studies that have used Smoothed Particle
|
||||
Hydrodynamics (SPH) or 2D grid codes.
|
||||
</p>
|
||||
|
||||
<h4> Description of the simulations: </h4>
|
||||
|
||||
<p>
|
||||
We simulate a disk of gas undergoing purely hydrodynamics forces,
|
||||
its own gravity and the $\\beta$-cooling.
|
||||
The simulation is ran with the 3D-grid code Ramses (Teyssier 2002) which uses a Godunov scheme.
|
||||
The flux between each cell is computed with the HLLC Riemann solver.
|
||||
The gravity potential is updated at each timestep with a Poisson solver,
|
||||
and a source term is added to the energy equation to implement the $\\beta$-cooling.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The $\\beta$-cooling consists in removing internal energy from the gas with a cooling time:
|
||||
$t_\\text{cool} = \\beta \\Omega^{-1}$ with $\\Omega$ the rotation frequency.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
We use the same initial conditions as in Meru & Bate (2012) to allow comparison.
|
||||
The specific disk setup for Ramses was inspired by Hennebelle et al. (2017).
|
||||
The disk is initially close to equilibrium with an initial column density profile
|
||||
$\\Sigma \\propto r^{-1}$ and a temperature profile $T \\propto r^{-1/2}$
|
||||
where $r$ is the cylindrical radius.
|
||||
The disk has a radius $r_d = 0.25$ (code units), after which the density is divided by 100.
|
||||
The density and temperature at the disk radius $r_d$ are chosen so that the mass
|
||||
of the disk $M_d = 0.1 M_\\star$, where $M_\\star$ is the mass of the central object,
|
||||
and the initial value of the Toomre parameter at the disk radius is $Q_{0,d} = 2$.
|
||||
The adiabatic index of the gas is $\\gamma = 5/3$.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The simulation is run within a cube of size $L=2$. Although the problem has a cylindrical symmetry,
|
||||
we use Cartesian coordinates.
|
||||
This prevents having a singularity at the centre of the box.
|
||||
One caveat is the poor resolution on the centre of the cube but this is mitigated
|
||||
by the use of the adaptive mesh refinement (AMR).
|
||||
Another caveat is that having a cubic box may introduce spurious
|
||||
reflection at the border of the simulation.
|
||||
To avoid this, we maintain a dead zone over a radius of $0.875$ (in code units)
|
||||
where all variables are replaced by their initial value at each timestep.
|
||||
This method has been used in Hennebelle et al. (2017) and has proven to be efficient.
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
The simulations presented here were run for several values of $\beta$ and several resolutions.
|
||||
To reduce the computation time, we use the Ramses's Adaptative Mesh Refinement (AMR).
|
||||
Only the parts of the simulation which are prone to form fragments are simulated with full resolution.
|
||||
Each cell is refined until the Jeans's length is covered by at least 20 cells or it reaches the maximum
|
||||
level of refinement $l_{\\max}$.
|
||||
The level of refinement of a cell is the number of times the simulation box must be divided in eight
|
||||
equal part to get the cell.
|
||||
Thus, the resolution of a simulation is given by the value of $l_{\\max}$.
|
||||
|
||||
A first set of simulations with $l_{\\max} = 11$ to $l_{\\max} = 12$ are run until
|
||||
about 5 Outer Rotation Periods (ORP),
|
||||
that is that the gas at the border of the disk had 5 orbits around the star.
|
||||
A second set of simulations, labelled tic, for Turbulent Initial Condition,
|
||||
were run from relaxed initial conditions for $l_{\\max} = 12$ and $l_{\\max} = 13$.
|
||||
More precisely, they were restarted from a simulation at $\beta = 20$ and $l_{\\max} = 12$
|
||||
for which the whole disk reached a gravito-turbulent state (after 2 ORPs).
|
||||
According to Paardekooper et al. (2011) and Clarke et al.(2007), departing
|
||||
from such turbulent condition should reduce spurious fragmentation.
|
||||
|
||||
</p>
|
||||
""",
|
||||
data_description="""
|
||||
<p>The data available for this project is the underlying data of the article Brucy & Hennebelle 2021.</p>
|
||||
<p>The data is not already fully uploaded. 3D datacube extraction on demand is planned</p>
|
||||
""",
|
||||
directory_path="~nbrucy/simus/fragdisk",
|
||||
)
|
||||
print(proj)
|
||||
# ------------------------------------------------------------------------------------------------------ #
|
||||
|
||||
|
||||
# ---- Units ----
|
||||
pl_units = Plotter(
|
||||
in_dir,
|
||||
filter_name="104_beta4_jr13",
|
||||
in_nums="last",
|
||||
path_out=out_dir,
|
||||
params=params,
|
||||
)
|
||||
info = pl_units.comp.info
|
||||
rd = U.Unit.create_unit(
|
||||
"r_d",
|
||||
latex="r_\\mathrm{d}",
|
||||
base_unit=0.25 * info["unit_length"] / info["boxlen"],
|
||||
)
|
||||
rhod = U.Unit.create_unit(
|
||||
"rho_d",
|
||||
latex="\\rho_\\mathrm{d}",
|
||||
base_unit=6.36 * info["unit_density"],
|
||||
)
|
||||
rho_u = U.Unit.create_unit(
|
||||
"rho_u",
|
||||
latex="\mathrm{M}_\\star.r_\\mathrm{d}^{-3}",
|
||||
base_unit=info["unit_mass"] * rd ** (-3),
|
||||
)
|
||||
orp = U.Unit.create_unit(
|
||||
"ORP",
|
||||
base_unit=2 * np.pi * np.sqrt(0.25 ** 3) * info["unit_time"],
|
||||
)
|
||||
vkd = U.Unit.create_unit(
|
||||
"vkd",
|
||||
latex="v_\\mathrm{k,d}",
|
||||
base_unit=2 * np.pi * rd / orp,
|
||||
)
|
||||
Pd = U.Unit.create_unit(
|
||||
"P_d",
|
||||
base_unit=(0.2 * info["unit_velocity"]) ** 2 * rhod,
|
||||
)
|
||||
P_u = U.Unit.create_unit(
|
||||
"P_u",
|
||||
latex="v_\\mathrm{k,d}^2.\\mathrm{M}_\\star.r_\\mathrm{d}^{-3}",
|
||||
base_unit=vkd ** 2 * rho_u,
|
||||
)
|
||||
|
||||
Sigmad = U.Unit.create_unit(
|
||||
"Sigma_d",
|
||||
latex="\\Sigma_d",
|
||||
base_unit=0.25 * info["unit_density"] * info["unit_length"] / info["boxlen"],
|
||||
)
|
||||
Sigma_u = U.Unit.create_unit(
|
||||
"Sigma_u",
|
||||
latex="M_\\star.r_d^{-2}",
|
||||
base_unit=rd ** (-2) * info["unit_mass"],
|
||||
)
|
||||
|
||||
|
||||
# ---- Runs -----
|
||||
|
||||
pls = []
|
||||
|
||||
for group in groups:
|
||||
if group == "jr13_tic":
|
||||
# JR13_TIC
|
||||
|
||||
params.astrophysix.simu_fmt = "beta{nml[cloud_params/beta_cool]:g}_{tag:.8}"
|
||||
params.astrophysix.descr_fmt = """
|
||||
<p>Group {tag:.8}, $\\beta$ = {nml[cloud_params/beta_cool]}.</p>
|
||||
"""
|
||||
|
||||
runs = "*_jr13"
|
||||
pl = Plotter(
|
||||
in_dir,
|
||||
filter_name=runs,
|
||||
in_nums="all",
|
||||
sort_run_by=nml_key,
|
||||
path_out=out_dir,
|
||||
tag="jr13_tic_mnras",
|
||||
params=params,
|
||||
unit_time=orp,
|
||||
)
|
||||
|
||||
if group == "jr12_tic":
|
||||
# JR12_TIC
|
||||
params.astrophysix.simu_fmt = "beta{nml[cloud_params/beta_cool]:g}_{tag:.8}"
|
||||
params.astrophysix.descr_fmt = """
|
||||
<p>Group {tag:.8}, $\\beta$ = {nml[cloud_params/beta_cool]}.</p>
|
||||
"""
|
||||
runs_12 = "0[0-9][0-9]_beta*_jr12"
|
||||
pl = Plotter(
|
||||
in_dir,
|
||||
filter_name=runs_12,
|
||||
in_nums="all",
|
||||
sort_run_by=nml_key,
|
||||
filter_nml=("cloud_params", "!=", 7),
|
||||
path_out=out_dir,
|
||||
tag="jr12_tic_mnras",
|
||||
params=params,
|
||||
unit_time=orp,
|
||||
)
|
||||
|
||||
if group == "jr12":
|
||||
|
||||
params.astrophysix.simu_fmt = "beta{nml[cloud_params/beta_cool]:g}_{tag:.4}"
|
||||
params.astrophysix.descr_fmt = """
|
||||
<p>Group {tag:.4}, $\\beta$ = {nml[cloud_params/beta_cool]}</p>
|
||||
"""
|
||||
|
||||
# JR12
|
||||
runs = "[7-8][0-9]_beta*_j*"
|
||||
pl = Plotter(
|
||||
in_dir_conv,
|
||||
filter_name=runs,
|
||||
in_nums="all",
|
||||
sort_run_by=nml_key,
|
||||
path_out=out_dir,
|
||||
tag="jr12_mnras",
|
||||
params=params,
|
||||
unit_time=orp,
|
||||
)
|
||||
|
||||
if group == "jr11":
|
||||
|
||||
params.astrophysix.simu_fmt = "beta{nml[cloud_params/beta_cool]:g}_{tag:.4}"
|
||||
params.astrophysix.descr_fmt = """
|
||||
<p>Group {tag:.4}, $\\beta$ = {nml[cloud_params/beta_cool]}</p>
|
||||
"""
|
||||
|
||||
# JR11
|
||||
runs = "*beta*_jr11"
|
||||
pl = Plotter(
|
||||
in_dir_conv,
|
||||
filter_name=runs,
|
||||
sort_run_by=nml_key,
|
||||
filter_nml=("cloud_params/beta_cool", ">", 3),
|
||||
path_out=out_dir_conv,
|
||||
tag="jr11_mnras",
|
||||
params=params,
|
||||
unit_time=orp,
|
||||
)
|
||||
|
||||
pls.append(pl)
|
||||
print("{} defined".format(group.upper()))
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
for pl in pls:
|
||||
pl.params.process.verbose = True
|
||||
pl.comp.params.process.verbose = True
|
||||
for run in pl.runs:
|
||||
simu = pl.simulations[run]
|
||||
proj.simulations.add(simu)
|
||||
|
||||
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
for pl in pls:
|
||||
# Edit descriptions
|
||||
pl.rules["slice_rho"].description = "Density slice"
|
||||
pl.rules["slice_P"].description = "Pressure slice"
|
||||
pl.rules["slice_velr"].description = "Radial velocity slice"
|
||||
pl.rules["slice_velphi"].description = "Orthoradial velocity slice"
|
||||
pl.rules[
|
||||
"pdf_coldens"
|
||||
].description = """
|
||||
Probability function of the logarithm of the column density fluctuations
|
||||
$\\sigma = \\Sigma/\\overline{\\Sigma}$ with respect to its azimuthal average
|
||||
"""
|
||||
|
||||
# define plot parameters
|
||||
map_kwargs = {
|
||||
"overwrite": replot,
|
||||
"overwrite_dep": False,
|
||||
"unit_space": rd,
|
||||
"center_space": True,
|
||||
"unit_time": orp,
|
||||
"nml_key": "cloud_params/beta_cool",
|
||||
"select": select,
|
||||
}
|
||||
|
||||
coldens_kwargs = {
|
||||
**map_kwargs,
|
||||
**{
|
||||
"unit": Sigma_u,
|
||||
"label": r"$\Sigma$",
|
||||
},
|
||||
}
|
||||
|
||||
rho_kwargs = {
|
||||
**map_kwargs,
|
||||
**{
|
||||
"unit": rho_u,
|
||||
"label": r"$\rho$",
|
||||
},
|
||||
}
|
||||
|
||||
P_kwargs = {
|
||||
**map_kwargs,
|
||||
**{
|
||||
"unit": P_u,
|
||||
"label": r"$P$",
|
||||
},
|
||||
}
|
||||
|
||||
vel_kwargs = {
|
||||
**map_kwargs,
|
||||
**{
|
||||
"unit": vkd,
|
||||
},
|
||||
}
|
||||
|
||||
# do plots
|
||||
pl.coldens("z", **coldens_kwargs)
|
||||
pl.coldens("y", **coldens_kwargs)
|
||||
|
||||
pl.slice_rho("z", **rho_kwargs)
|
||||
pl.slice_rho("y", **rho_kwargs)
|
||||
|
||||
pl.slice_velr(
|
||||
"z",
|
||||
label=r"$v_r$",
|
||||
norm=mpl.colors.SymLogNorm(0.1, vmin=-2, vmax=2, base=10),
|
||||
autoscale=False,
|
||||
**vel_kwargs,
|
||||
)
|
||||
pl.slice_velphi("z", label=r"$v_\varphi$", **vel_kwargs)
|
||||
pl.slice_velx("z", label=r"$v_x$", **vel_kwargs)
|
||||
|
||||
pl.slice_P("z", **P_kwargs)
|
||||
|
||||
pl.pdf_coldens(
|
||||
"z",
|
||||
overwrite=replot,
|
||||
overwrite_dep=False,
|
||||
unit_time=orp,
|
||||
nml_key="cloud_params/beta_cool",
|
||||
label=r"$\log(\Sigma / \overline{\Sigma})$",
|
||||
kind="step",
|
||||
color="k",
|
||||
select=select,
|
||||
)
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
# Light fake PlotInfo to replace real one to reduce size of the hdf5 file
|
||||
pi = PlotInfo(
|
||||
plot_type=PlotType.LINE_PLOT,
|
||||
xaxis_values=np.array([10.0, 20.0, 30.0, 40.0, 50.0]),
|
||||
yaxis_values=np.array([1.256, 2.456, 3.921, 4.327, 5.159]),
|
||||
xaxis_log_scale=False,
|
||||
yaxis_log_scale=False,
|
||||
xaxis_label="Mass",
|
||||
yaxis_label="Probability",
|
||||
xaxis_unit=U.Msun,
|
||||
plot_title="Initial mass function",
|
||||
yaxis_unit=U.Mpc,
|
||||
)
|
||||
|
||||
for simu in proj.simulations:
|
||||
for snap in simu.snapshots:
|
||||
|
||||
# Change unit to things Galactica understands
|
||||
snap.time = (snap.time[0], U.none)
|
||||
snap.description = """
|
||||
<p>Snapshot at {time:.3g} ORPs.</p>
|
||||
|
||||
<h5 class="sn_panel">Notations:</h5>
|
||||
|
||||
<p>
|
||||
$r_d$ : radius of the disk <br />
|
||||
ORP : outer rotation period, that is period of the gas at $r_d$ <br />
|
||||
$M_\\star$ : Mass of the central object <br />
|
||||
$v_{kepl}$ : Keplerian speed at $r_d$
|
||||
</p>
|
||||
<p>All slices are taken at $z=0$ or $y=0$.
|
||||
""".format(
|
||||
time=snap.time[0], kepl="{k,d}"
|
||||
)
|
||||
|
||||
# Convert plotinfo into HDF5 file
|
||||
for df in snap.datafiles:
|
||||
name = df[FileType.JPEG_FILE].filename
|
||||
name = os.path.splitext(name)[0] + ".h5"
|
||||
if include_hdf5 and df.name not in ["slice_velphi_z", "slice_velr_z"]:
|
||||
h5 = h5py.File(out_dir + "/" + name, "w")
|
||||
p = h5.create_group("plot")
|
||||
df.plot_info.hsp_save_to_h5(p)
|
||||
h5.close()
|
||||
df[FileType.HDF5_FILE] = out_dir + "/" + name
|
||||
if not keep_plot_info:
|
||||
df.plot_info = pi
|
||||
|
||||
# Trim parameters name
|
||||
for param in ramses.input_parameters:
|
||||
param.key = os.path.basename(param.key)
|
||||
|
||||
# Validity check
|
||||
proj.galactica_validity_check()
|
||||
|
||||
# Save
|
||||
study = SimulationStudy(project=proj)
|
||||
study.save_HDF5(out_dir + "/fragdisk_study.h5")
|
||||
@@ -0,0 +1,326 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# This file is part of the 'astrophysix' Python package.
|
||||
#
|
||||
# Copyright © Commissariat a l'Energie Atomique et aux Energies Alternatives (CEA)
|
||||
#
|
||||
# FREE SOFTWARE LICENCING
|
||||
# -----------------------
|
||||
# This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free
|
||||
# software. You can use, modify and/or redistribute the software under the terms of the CeCILL license as circulated by
|
||||
# CEA, CNRS and INRIA at the following URL: "http://www.cecill.info". As a counterpart to the access to the source code
|
||||
# and rights to copy, modify and redistribute granted by the license, users are provided only with a limited warranty
|
||||
# and the software's author, the holder of the economic rights, and the successive licensors have only limited
|
||||
# liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying
|
||||
# and/or developing or reproducing the software by the user in light of its specific status of free software, that may
|
||||
# mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and
|
||||
# experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the
|
||||
# software's suitability as regards their requirements in conditions enabling the security of their systems and/or data
|
||||
# to be ensured and, more generally, to use and operate it in the same conditions as regards security. The fact that
|
||||
# you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its terms.
|
||||
#
|
||||
#
|
||||
# COMMERCIAL SOFTWARE LICENCING
|
||||
# -----------------------------
|
||||
# You can obtain this software from CEA under other licencing terms for commercial purposes. For this you will need to
|
||||
# negotiate a specific contract with a legal representative of CEA.
|
||||
#
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
import numpy as N
|
||||
from astrophysix import units as U
|
||||
from astrophysix.simdm import Project, ProjectCategory, SimulationStudy
|
||||
from astrophysix.simdm.datafiles import Datafile, PlotInfo, PlotType
|
||||
from astrophysix.simdm.experiment import (
|
||||
AppliedAlgorithm,
|
||||
ParameterSetting,
|
||||
ParameterVisibility,
|
||||
ResolvedPhysicalProcess,
|
||||
Simulation,
|
||||
)
|
||||
from astrophysix.simdm.protocol import (
|
||||
Algorithm,
|
||||
AlgoType,
|
||||
InputParameter,
|
||||
PhysicalProcess,
|
||||
Physics,
|
||||
SimulationCode,
|
||||
)
|
||||
from astrophysix.simdm.results import GenericResult, Snapshot
|
||||
from astrophysix.utils.file import FileType
|
||||
|
||||
# ----------------------------------------------- Project creation --------------------------------------------------- #
|
||||
# Available project categories are :
|
||||
# - ProjectCategory.SolarMHD
|
||||
# - ProjectCategory.PlanetaryAtmospheres
|
||||
# - ProjectCategory.StarPlanetInteractions
|
||||
# - ProjectCategory.StarFormation
|
||||
# - ProjectCategory.Supernovae
|
||||
# - ProjectCategory.GalaxyFormation
|
||||
# - ProjectCategory.GalaxyMergers
|
||||
# - ProjectCategory.Cosmology
|
||||
proj = Project(
|
||||
category=ProjectCategory.StarFormation,
|
||||
project_title="Ismfeed",
|
||||
alias="ismfeed",
|
||||
short_description="Impact of feedback and turbulence on star formation",
|
||||
general_description="""Impact of feedback and turbulence on star formation. The simulation presented here are described in Brucy et al. 2020, ApJL, L38""",
|
||||
data_description="The data available in this project...",
|
||||
directory_path="~nbrucy/simus/ismfeed",
|
||||
)
|
||||
print(proj)
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
# --------------------------------------- Simulation code definition ------------------------------------------------- #
|
||||
ramses = SimulationCode(
|
||||
name="Ramses 3 (MHD)",
|
||||
code_name="Ramses",
|
||||
code_version="3.10.1",
|
||||
alias="RAMSES_3",
|
||||
url="https://www.ics.uzh.ch/~teyssier/ramses/RAMSES.html",
|
||||
description="Ramses MHD code",
|
||||
)
|
||||
# => Add algorithms : available algorithm types are :
|
||||
# - AlgoType.AdaptiveMeshRefinement
|
||||
# - AlgoType.VoronoiMovingMesh
|
||||
# - AlgoType.SmoothParticleHydrodynamics
|
||||
# - AlgoType.Godunov
|
||||
# - AlgoType.PoissonMultigrid
|
||||
# - AlgoType.PoissonConjugateGradient
|
||||
# - AlgoType.ParticleMesh
|
||||
# - AlgoType.FriendOfFriend
|
||||
# - AlgoType.HLLCRiemann
|
||||
# - AlgoType.RayTracer
|
||||
# amr = ramses.algorithms.add(Algorithm(algo_type=AlgoType.AdaptiveMeshRefinement, description="AMR"))
|
||||
ramses.algorithms.add(
|
||||
Algorithm(algo_type=AlgoType.Godunov, description="Godunov scheme")
|
||||
)
|
||||
ramses.algorithms.add(
|
||||
Algorithm(algo_type=AlgoType.HLLCRiemann, description="HLLC Riemann solver")
|
||||
)
|
||||
ramses.algorithms.add(
|
||||
Algorithm(
|
||||
algo_type=AlgoType.PoissonMultigrid, description="Multigrid Poisson solver"
|
||||
)
|
||||
)
|
||||
ramses.algorithms.add(
|
||||
Algorithm(algo_type=AlgoType.ParticleMesh, description="PM solver")
|
||||
)
|
||||
|
||||
# => Add input parameters
|
||||
ramses.input_parameters.add(
|
||||
InputParameter(
|
||||
key="amr_params/levelmin",
|
||||
name="Lmin",
|
||||
description="min. level of AMR refinement",
|
||||
)
|
||||
)
|
||||
ramses.input_parameters.add(
|
||||
InputParameter(
|
||||
key="amr_params/levelmax",
|
||||
name="Lmax",
|
||||
description="max. level of AMR refinement",
|
||||
)
|
||||
)
|
||||
|
||||
ramses.input_parameters.add(
|
||||
InputParameter(
|
||||
key="turb_params/turb_rms", name="f_rms", description="Amplitude of the driving"
|
||||
)
|
||||
)
|
||||
ramses.input_parameters.add(
|
||||
InputParameter(
|
||||
key="cloud_params/dens0", name="n_0", description="Midplane density in cm**-3"
|
||||
)
|
||||
)
|
||||
ramses.input_parameters.add(
|
||||
InputParameter(
|
||||
key="cloud_params/bx_bound",
|
||||
name="bx_bound",
|
||||
description="imposed magnetic field at the x boundary (1 implies that the magnetic pressure is equal to thermal pressure in WNM, which corresponds to about 5muG)",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# => Add physical processes : available physics are :
|
||||
# - Physics.SelfGravity
|
||||
# - Physics.Hydrodynamics
|
||||
# - Physics.MHD
|
||||
# - Physics.StarFormation
|
||||
# - Physics.SupernovaeFeedback
|
||||
# - Physics.AGNFeedback
|
||||
# - Physics.MolecularCooling
|
||||
ramses.physical_processes.add(
|
||||
PhysicalProcess(
|
||||
physics=Physics.StarFormation,
|
||||
description="Star Formation is triggered when density overpass",
|
||||
)
|
||||
)
|
||||
ramses.physical_processes.add(
|
||||
PhysicalProcess(
|
||||
physics=Physics.MHD, description="Magneto-hydrodynamical equations are solved"
|
||||
)
|
||||
)
|
||||
ramses.physical_processes.add(
|
||||
PhysicalProcess(physics=Physics.SelfGravity, description="Self-Gravity is applied.")
|
||||
)
|
||||
ramses.physical_processes.add(
|
||||
PhysicalProcess(physics=Physics.SupernovaeFeedback, description="SN feedback")
|
||||
)
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
# -------------------------------------------- Simulation setup ------------------------------------------------------ #
|
||||
simu = Simulation(
|
||||
simu_code=ramses,
|
||||
name="Noturb_1",
|
||||
alias="noturb_1",
|
||||
description="Simulation without turbulence",
|
||||
directory_path="~nbrucy/simus/turb/",
|
||||
)
|
||||
proj.simulations.add(simu)
|
||||
|
||||
# Add applied algorithms implementation details. Warning : corresponding algorithms must have been added in the 'ramses'
|
||||
# simulation code.
|
||||
# simu.applied_algorithms.add(AppliedAlgorithm(algorithm=amr, details="My AMR implementation [Teyssier 2002]"))
|
||||
# simu.applied_algorithms.add(AppliedAlgorithm(algorithm=ramses.algorithms[AlgoType.HLLCRiemann.name],
|
||||
# details="My Riemann solver implementation [Teyssier 2002]"))
|
||||
|
||||
# Add parameter setting. Warning : corresponding input parameter must have been added in the 'ramses' simulation code.
|
||||
# Available parameter visibility options are :
|
||||
# - ParameterVisibility.NOT_DISPLAYED
|
||||
# - ParameterVisibility.ADVANCED_DISPLAY
|
||||
# - ParameterVisibility.BASIC_DISPLAY
|
||||
simu.parameter_settings.add(
|
||||
ParameterSetting(
|
||||
input_param=ramses.input_parameters["levelmin"],
|
||||
value=8,
|
||||
visibility=ParameterVisibility.BASIC_DISPLAY,
|
||||
)
|
||||
)
|
||||
simu.parameter_settings.add(
|
||||
ParameterSetting(
|
||||
input_param=lmax, value=12, visibility=ParameterVisibility.BASIC_DISPLAY
|
||||
)
|
||||
)
|
||||
|
||||
# Add resolved physical process implementation details. Warning : corresponding physical process must have been added to
|
||||
# the 'ramses' simulation code
|
||||
simu.resolved_physics.add(
|
||||
ResolvedPhysicalProcess(
|
||||
physics=ramses.physical_processes[Physics.StarFormation.name],
|
||||
details="Star formation specific implementation",
|
||||
)
|
||||
)
|
||||
simu.resolved_physics.add(
|
||||
ResolvedPhysicalProcess(
|
||||
physics=grav, details="self-gravity specific implementation"
|
||||
)
|
||||
)
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
# -------------------------------------- Simulation generic result and snapshots ------------------------------------- #
|
||||
# Generic result
|
||||
gres = GenericResult(
|
||||
name="Key result 1 !",
|
||||
description="My description",
|
||||
directory_path="/my/path/to/result",
|
||||
)
|
||||
simu.generic_results.add(gres)
|
||||
|
||||
# Simulation snapshot
|
||||
# In one-line
|
||||
sn = simu.snapshots.add(
|
||||
Snapshot(
|
||||
name="My best snapshot !",
|
||||
description="My first snapshot description",
|
||||
time=(125, U.kyr),
|
||||
physical_size=(250.0, U.kpc),
|
||||
directory_path="/path/to/snapshot1",
|
||||
data_reference="OUTPUT_00056",
|
||||
)
|
||||
)
|
||||
# Or create snapshot, then add it to the simulation
|
||||
sn2 = Snapshot(
|
||||
name="My second best snapshot !",
|
||||
description="My second snapshot description",
|
||||
time=(0.26, U.Myr),
|
||||
physical_size=(0.25, U.Mpc),
|
||||
directory_path="/path/to/snapshot2",
|
||||
data_reference="OUTPUT_00158",
|
||||
)
|
||||
simu.snapshots.add(sn2)
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
# ---------------------------------------------------- Result datafiles ---------------------------------------------- #
|
||||
# Datafile creation
|
||||
imf_df = sn.datafiles.add(
|
||||
Datafile(
|
||||
name="Initial mass function plot",
|
||||
description="This is my plot detailed description",
|
||||
)
|
||||
)
|
||||
|
||||
# Add attached files to a datafile (1 per file type). Available file types are :
|
||||
# - FileType.HDF5_FILE
|
||||
# - FileType.PNG_FILE
|
||||
# - FileType.JPEG_FILE
|
||||
# - FileType.FITS_FILE
|
||||
# - FileType.TARGZ_FILE
|
||||
# - FileType.PICKLE_FILE
|
||||
# - FileType.JSON_FILE
|
||||
# - FileType.CSV_FILE
|
||||
# - FileType.ASCII_FILE
|
||||
imf_df[FileType.PNG_FILE] = os.path.join(
|
||||
"/data", "io", "datafiles", "plot_image_IMF.png"
|
||||
)
|
||||
imf_df[FileType.JPEG_FILE] = os.path.join(
|
||||
"/data", "io", "datafiles", "plot_with_legend.jpg"
|
||||
)
|
||||
imf_df[FileType.FITS_FILE] = os.path.join(
|
||||
"/data", "io", "datafiles", "cassiopea_A_0.5-1.5keV.fits"
|
||||
)
|
||||
imf_df[FileType.TARGZ_FILE] = os.path.join("/data", "io", "datafiles", "archive.tar.gz")
|
||||
imf_df[FileType.JSON_FILE] = os.path.join(
|
||||
"/data", "io", "datafiles", "test_header_249.json"
|
||||
)
|
||||
imf_df[FileType.ASCII_FILE] = os.path.join("/data", "io", "datafiles", "abstract.txt")
|
||||
imf_df[FileType.HDF5_FILE] = os.path.join("/data", "io", "HDF5", "study.h5")
|
||||
imf_df[FileType.PICKLE_FILE] = os.path.join(
|
||||
"/data", "io", "datafiles", "dict_saved.pkl"
|
||||
)
|
||||
|
||||
# Datafile plot information (for plot future updates and online interactive visualisation on Galactica web pages).
|
||||
# Available plot types are :
|
||||
# - LINE_PLOT
|
||||
# - SCATTER_PLOT
|
||||
# - HISTOGRAM
|
||||
# - HISTOGRAM_2D
|
||||
# - IMAGE
|
||||
# - MAP_2D
|
||||
imf_df.plot_info = PlotInfo(
|
||||
plot_type=PlotType.LINE_PLOT,
|
||||
xaxis_values=N.array([10.0, 20.0, 30.0, 40.0, 50.0]),
|
||||
yaxis_values=N.array([1.256, 2.456, 3.921, 4.327, 5.159]),
|
||||
xaxis_log_scale=False,
|
||||
yaxis_log_scale=False,
|
||||
xaxis_label="Mass",
|
||||
yaxis_label="Probability",
|
||||
xaxis_unit=U.Msun,
|
||||
plot_title="Initial mass function",
|
||||
yaxis_unit=U.Mpc,
|
||||
)
|
||||
# -------------------------------------------------------------------------------------------------------------------- #
|
||||
|
||||
|
||||
# Save study in HDF5 file
|
||||
study = SimulationStudy(project=proj)
|
||||
study.save_HDF5("./frig_study.h5")
|
||||
|
||||
# Eventually reload it from HDF5 file to edit its content
|
||||
# study = SimulationStudy.load_HDF5("./frig_study.h5")
|
||||
@@ -0,0 +1,91 @@
|
||||
# coding: utf-8
|
||||
|
||||
|
||||
from astrophysix.simdm.protocol import (
|
||||
Algorithm,
|
||||
AlgoType,
|
||||
InputParameter,
|
||||
PhysicalProcess,
|
||||
Physics,
|
||||
SimulationCode,
|
||||
)
|
||||
|
||||
# Simulation code definition #
|
||||
ramses = SimulationCode(
|
||||
name="Ramses 3 (MHD)",
|
||||
code_name="Ramses",
|
||||
code_version="3.10.1",
|
||||
alias="RAMSES_3",
|
||||
url="https://www.ics.uzh.ch/~teyssier/ramses/RAMSES.html",
|
||||
description="Ramses MHD code",
|
||||
)
|
||||
# => Add algorithms : available algorithm types are :
|
||||
# - AlgoType.AdaptiveMeshRefinement
|
||||
# - AlgoType.VoronoiMovingMesh
|
||||
# - AlgoType.SmoothParticleHydrodynamics
|
||||
# - AlgoType.Godunov
|
||||
# - AlgoType.PoissonMultigrid
|
||||
# - AlgoType.PoissonConjugateGradient
|
||||
# - AlgoType.ParticleMesh
|
||||
# - AlgoType.FriendOfFriend
|
||||
# - AlgoType.HLLCRiemann
|
||||
# - AlgoType.RayTracer
|
||||
ramses.algorithms.add(
|
||||
Algorithm(algo_type=AlgoType.AdaptiveMeshRefinement, description="AMR")
|
||||
)
|
||||
ramses.algorithms.add(
|
||||
Algorithm(algo_type=AlgoType.Godunov, description="Godunov scheme")
|
||||
)
|
||||
ramses.algorithms.add(
|
||||
Algorithm(algo_type=AlgoType.HLLCRiemann, description="HLLC Riemann solver")
|
||||
)
|
||||
ramses.algorithms.add(
|
||||
Algorithm(
|
||||
algo_type=AlgoType.PoissonMultigrid, description="Multigrid Poisson solver"
|
||||
)
|
||||
)
|
||||
# => Add input parameters
|
||||
ramses.input_parameters.add(
|
||||
InputParameter(
|
||||
key="amr_params/levelmin",
|
||||
name="lmin",
|
||||
description="min. level of AMR refinement",
|
||||
)
|
||||
)
|
||||
ramses.input_parameters.add(
|
||||
InputParameter(
|
||||
key="amr_params/levelmax",
|
||||
name="lmax",
|
||||
description="max. level of AMR refinement",
|
||||
)
|
||||
)
|
||||
ramses.input_parameters.add(
|
||||
InputParameter(
|
||||
key="amr_params/jeans_refine",
|
||||
name="jeans_refine",
|
||||
description="Array, number of cells needed to resolve the Jeans lenght at each level from lmin",
|
||||
)
|
||||
)
|
||||
ramses.input_parameters.add(
|
||||
InputParameter(
|
||||
key="cloud_params/beta_cool", name="beta", description="Cooling parameter"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# => Add physical processes : available physics are :
|
||||
# - Physics.SelfGravity
|
||||
# - Physics.Hydrodynamics
|
||||
# - Physics.MHD
|
||||
# - Physics.StarFormation
|
||||
# - Physics.SupernovaeFeedback
|
||||
# - Physics.AGNFeedback
|
||||
# - Physics.MolecularCooling
|
||||
ramses.physical_processes.add(
|
||||
PhysicalProcess(
|
||||
physics=Physics.Hydrodynamics, description="Hydrodynamical equations are solved"
|
||||
)
|
||||
)
|
||||
ramses.physical_processes.add(
|
||||
PhysicalProcess(physics=Physics.SelfGravity, description="Self-Gravity is applied.")
|
||||
)
|
||||
Reference in New Issue
Block a user