Skip to content

Commit

Permalink
Modify ASCII parser to use min/max header data.
Browse files Browse the repository at this point in the history
+ Make changes to parser name and comments to remove references.
+ Remove power-law opacity generation script.

Note: the new metadata is redundant with the rho-T column data,
so either might be removed.
  • Loading branch information
RyanWollaeger committed Nov 20, 2024
1 parent bc206ec commit 468e04c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 74 deletions.
56 changes: 0 additions & 56 deletions singularity-opac/photons/example_ascii/create_mean_opac_ascii.py

This file was deleted.

12 changes: 7 additions & 5 deletions singularity-opac/photons/example_ascii/kap_plaw.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
rho 4 T 4
NRho 4 NT 4
rho_min 1.00000000e-14 rho_max 7.94328235e-01
T_min 1.00000000e+00 T_max 7.94328235e+06
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 1.99526232e+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 1.99526232e+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 1.99526232e+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 1.99526232e+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
47 changes: 34 additions & 13 deletions singularity-opac/photons/mean_opacity_photons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MeanOpacity {
NT, lNuMin, lNuMax, NNu, lambda);
}

// construct Planck/Rosseland DataBox from Zhu-formatted ascii file
// construct Planck/Rosseland DataBox from ascii file
MeanOpacity(const std::string &filename) : filename_(filename.c_str()) {

// get number of density and temperature points
Expand All @@ -72,8 +72,7 @@ class MeanOpacity {
std::string extension = filePath.extension().string();

if (extension == ".txt") {
// assume this is one of the original Zhu et al (2021) ASCII files
loadZhuASCII(ff);
loadASCII(ff);
#ifdef SPINER_USE_HDF
} else if (extension == ".hdf5" || extension == ".h5" || extension == ".sp5") {
herr_t status = H5_SUCCESS;
Expand Down Expand Up @@ -202,16 +201,16 @@ class MeanOpacity {
}
}

// if .txt file, assume it is the original Zhu dust opacity file
void loadZhuASCII(std::ifstream &ff) {
// ASCII opacity file reader
void loadASCII(std::ifstream &ff) {

int NRho = -1;
int NT = -1;

// line read from file
std::string fline;

// read 1-line header to get sizes
// read 1st line of header to get sizes
std::getline(ff, fline);

// tokenize fline
Expand All @@ -222,19 +221,41 @@ class MeanOpacity {
fl_tok = std::strtok(nullptr, " ");
NRho = std::stoi(fl_tok);

// move to next token to get number of density points
// move to next token to get number of temperature points
fl_tok = std::strtok(nullptr, " ");
fl_tok = std::strtok(nullptr, " ");
NT = std::stoi(fl_tok);

// reseize the Planck and Rosseland databoxes (number of types of opac=2)
// read 2nd line of header to get min/max density
std::getline(ff, fline);
// tokenize fline
cfline = const_cast<char*>(fline.c_str());
fl_tok = std::strtok(cfline, " ");
fl_tok = std::strtok(nullptr, " ");
const Real RhoMin = std::stod(fl_tok);
fl_tok = std::strtok(nullptr, " ");
fl_tok = std::strtok(nullptr, " ");
const Real RhoMax = std::stod(fl_tok);

// read 3nd line of header to get min/max temperature
std::getline(ff, fline);
// tokenize fline
cfline = const_cast<char*>(fline.c_str());
fl_tok = std::strtok(cfline, " ");
fl_tok = std::strtok(nullptr, " ");
const Real TMin = std::stod(fl_tok);
fl_tok = std::strtok(nullptr, " ");
fl_tok = std::strtok(nullptr, " ");
const Real TMax = std::stod(fl_tok);

// reseize the Planck and Rosseland databox
lkappa_.resize(NRho, NT, 2);

// set rho-T rankges (Zhu tables are uniform in log-log rho-T space)
const Real lTMin = toLog_(1.0);
const Real lTMax = toLog_(7943282.347242886);
const Real lRhoMin = toLog_(1.0e-14);
const Real lRhoMax = toLog_(0.7943282347241912);
// set rho-T ranges
const Real lTMin = toLog_(TMin);
const Real lTMax = toLog_(TMax);
const Real lRhoMin = toLog_(RhoMin);
const Real lRhoMax = toLog_(RhoMax);
lkappa_.setRange(1, lTMin, lTMax, NT);
lkappa_.setRange(2, lRhoMin, lRhoMax, NRho);

Expand Down

0 comments on commit 468e04c

Please sign in to comment.