-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Put Zhu ASCII parsing into mean_opacity_photons (BRR suggestion).
+ Remove Zhu grey table class and unit test. + Replace Zhu data table with toy power-law data table. + Generalize file-based ctor to take ASCII or HDF5 file. + Add sub-test for parsing toy power-law data into MeanOpacity.
- Loading branch information
1 parent
cd895ca
commit e8acf30
Showing
9 changed files
with
249 additions
and
10,210 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
singularity-opac/photons/example_ascii/create_mean_opac_ascii.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#--------------------------------------------------------------------------------------------------# | ||
# This script defaults to using the temperature and density bounds for opacity data found | ||
# in Zhaohuan Zhu et al (2021), "Global 3D Radiation Hydrodynamic Simulations of Proto-Jupiter’s | ||
# Convective EnvelopeConvective Envelope". Otherwise, it merely generates a power law for Rosseland | ||
# and Planck-averaged opacities, and produces a table in an ASCII format equivalent to that of Zhu. | ||
#--------------------------------------------------------------------------------------------------# | ||
import numpy as np | ||
import argparse | ||
|
||
#-- parse command line arguments | ||
parser = argparse.ArgumentParser(description="Create power-law grey opacity ASCII table (for testing).") | ||
parser.add_argument("fname", type=str, help="base opacity file name to create (.txt is appended).") | ||
parser.add_argument("--Nrho", type=int, default=4, help="Number of density points (assumes log space)") | ||
parser.add_argument("--rho", type=float, nargs=2, default=[1e-14, 0.7943282347241912], | ||
help="min, max densities [g/cc]") | ||
parser.add_argument("--NT", type=int, default=4, help="Number of temperature points (assumes log space)") | ||
parser.add_argument("--T", type=float, nargs=2, default=[1.0, 7943282.347242886], | ||
help="min, max temperatures [K]") | ||
parser.add_argument("--rho_ref", type=float, default=1e-6, help="Reference density [g/cc]") | ||
parser.add_argument("--rho_exp", type=float, default=0.0, help="Exponent of density / ref. density") | ||
parser.add_argument("--T_ref", type=float, default=11604, help="Reference density [K]") | ||
parser.add_argument("--T_exp", type=float, default=0.0, help="Exponent of temperature / ref. temperature") | ||
parser.add_argument("--Pkap_coef", type=float, default=0.01, help="Planck opacity coefficient [cm^2/g]") | ||
parser.add_argument("--Rkap_coef", type=float, default=0.01, help="Rosseland opacity coefficient [cm^2/g]") | ||
args = parser.parse_args() | ||
|
||
#-- implement simple power law | ||
def power_law_kappa(r, t): | ||
'''power_law_kappa (cgs): r=density (1st arg), t=temperature (2nd arg)''' | ||
kap_coef = [args.Rkap_coef, args.Pkap_coef] | ||
kap_pwrs = (r / args.rho_ref)**(args.rho_exp) * (t / args.T_ref)**(args.T_exp) | ||
return [kapc * kap_pwrs for kapc in kap_coef] | ||
|
||
#-- set rho and T arrays | ||
rho = np.logspace(np.log10(args.rho[0]), np.log10(args.rho[1]), args.Nrho) | ||
T = np.logspace(np.log10(args.T[0]), np.log10(args.T[1]), args.NT) | ||
|
||
#-- initialize the opacity array - columns: density, temperature, Rosseland, Planck | ||
Nrow = args.Nrho * args.NT | ||
opac = np.zeros((Nrow, 4)) | ||
|
||
#-- populate opacity array | ||
for i in range(args.Nrho): | ||
for j in range(args.NT): | ||
k = j + args.NT * i | ||
opac[k,0] = rho[i] | ||
opac[k,1] = T[j] | ||
opac[k,2:] = power_law_kappa(rho[i], T[j]) | ||
|
||
#-- save opacity array | ||
np.savetxt(args.fname+'.txt', opac, delimiter=" ", | ||
header="rho "+str(args.Nrho)+" T "+str(args.NT), comments=" ", fmt="%.8e") | ||
|
||
#--------------------------------------------------------------------------------------------------# | ||
# End of create_mean_opac_ascii.py | ||
#--------------------------------------------------------------------------------------------------# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
rho 4 T 4 | ||
1.00000000e-14 1.00000000e+00 1.00000000e-03 1.00000000e-01 | ||
1.00000000e-14 1.99526231e+02 1.00000000e-03 1.00000000e-01 | ||
1.00000000e-14 3.98107171e+04 1.00000000e-03 1.00000000e-01 | ||
1.00000000e-14 7.94328235e+06 1.00000000e-03 1.00000000e-01 | ||
4.29866235e-10 1.00000000e+00 1.00000000e-03 1.00000000e-01 | ||
4.29866235e-10 1.99526231e+02 1.00000000e-03 1.00000000e-01 | ||
4.29866235e-10 3.98107171e+04 1.00000000e-03 1.00000000e-01 | ||
4.29866235e-10 7.94328235e+06 1.00000000e-03 1.00000000e-01 | ||
1.84784980e-05 1.00000000e+00 1.00000000e-03 1.00000000e-01 | ||
1.84784980e-05 1.99526231e+02 1.00000000e-03 1.00000000e-01 | ||
1.84784980e-05 3.98107171e+04 1.00000000e-03 1.00000000e-01 | ||
1.84784980e-05 7.94328235e+06 1.00000000e-03 1.00000000e-01 | ||
7.94328235e-01 1.00000000e+00 1.00000000e-03 1.00000000e-01 | ||
7.94328235e-01 1.99526231e+02 1.00000000e-03 1.00000000e-01 | ||
7.94328235e-01 3.98107171e+04 1.00000000e-03 1.00000000e-01 | ||
7.94328235e-01 7.94328235e+06 1.00000000e-03 1.00000000e-01 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-158 KB
singularity-opac/photons/zhu_data/opacitysolar09dustq3p5amax0p1new.hdf5
Binary file not shown.
Oops, something went wrong.