-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CCSN Initilization #135
base: main
Are you sure you want to change the base?
CCSN Initilization #135
Conversation
I didn't make it to this yet. Sorry @carlnotsagan I was sick last week and on travel before that. This is on my priority list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This actually all looks reasonable. I don't see the units issue off the top of my head though I do have some nitpicks. Might need to debug with the code + the input progenitor.
std::pair<int, int> p = Get1DProfileNumZones(model_filename); | ||
const int num_zones = p.first - 1; | ||
const int num_comments = p.second; | ||
const int num_vars = 11; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is always the same, I suggest moving it to the ccsn.hpp
header file and defining it as a global constant
constexpr int NUM_VARS = 11;
inside the CCSN
namespace. Unless you think this might change later? In which case, putting it here and making it a param
is the right thing.
if (num_zones > 0 && npoints != num_zones) { | ||
std::stringstream msg; | ||
msg << "When using a stellar input profile Monopole GR npoints must equal the number " | ||
"of zones in input file:" | ||
<< num_zones << std::endl; | ||
PARTHENON_THROW(msg); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're doing interpolation so is this actually true? I think this restriction can be relaxed.
auto matter_h = monopolepkg->Param<MonopoleGR::Matter_host_t>("matter_h"); | ||
auto state_h = params.Get<CCSN::State_host_t>("ccsn_state_interp_h"); | ||
|
||
// printf("Current working dir: %s\n", get_current_dir_name()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// printf("Current working dir: %s\n", get_current_dir_name()); |
Real yint = MonopoleGR::Interpolate(xa, state_raw, radius, | ||
j); // call to some interp routine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird spacing here. Also this is a linear interpolation routine.
printf("MESA model interpolated to monopoleGR rgrid. Central density = %.14e (g/cc)\n", | ||
ccsn_state_interp_d(CCSN::RHO, 0)); | ||
printf( | ||
"MESA model interpolated to monopoleGR rgrid. Central electron fraction = %.14e\n", | ||
ccsn_state_interp_d(CCSN::YE, 0)); | ||
printf("MESA model interpolated to monopoleGR rgrid. Central pressure = %.14e " | ||
"(dyn/cm**2)\n", | ||
ccsn_state_interp_d(CCSN::PRES, 0)); | ||
printf( | ||
"MESA model interpolated to monopoleGR rgrid. Central temperature = %.14e (GK)\n", | ||
ccsn_state_interp_d(CCSN::TEMP, 0)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be behind a check for whether or not you're on the root MPI rank. You need
#include <globals.hpp>
which includes the relevant header file from Parthenon and then
if (parthenon::Globals::my_rank == 0) {
// The print statements
}
this will ensure that when you run the code in parallel, the messages are only printed once.
// convert from specific eint then to code units | ||
Real mass = ccsn_state_interp_h(CCSN::RHO, i) * (4. / 3.) * | ||
(pi)*std::pow(ccsn_state_interp_h(CCSN::R, i), 3.); | ||
|
||
ccsn_state_conv_interp_h(CCSN::EPS, i) = | ||
ccsn_state_interp_h(CCSN::EPS, i) * mass * unit_conv.GetEnergyCGSToCode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will never want total energy in a cell (and what you've computed here is total energy enclosed by a given radius, which is definitely not what we want). We either want specific internal energy or we want internal energy by volume:
also the monopole solver actually wants specific energy unit_conv.GetEnergyCGSToCode()/unit_conv.GetMassCGSToCode()
and only convert to energy density
Real pres = ccsn_state_conv_interp_h(CCSN::PRES, i); // pressure | ||
Real rho = ccsn_state_conv_interp_h(CCSN::RHO, i); // mass density | ||
Real eps = ccsn_state_conv_interp_h( | ||
CCSN::EPS, i); // specific internal energy - need to multiply by mass? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't used here so no reason to pull them out.
// floor based on pressure | ||
if (pres <= 1.1 * Pmin) { | ||
pres = rho = eps = 0; | ||
} else { | ||
// PolytropeThermoFromP(press, K, Gamma, rho, eps); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you're passing in the monopoleGR quantities directly into the monopole solver, you probably don't need this.
// Pressure floor | ||
Real pmin = pin->GetOrAddReal("ccsn", "Pmin", 1e-9); | ||
params.Add("pmin", pmin); | ||
|
||
// Mass density floor | ||
Real rhomin = pin->GetOrAddReal("ccsn", "rhomin", 1e-12); | ||
params.Add("rhomin", rhomin); | ||
|
||
// Internal energy floor | ||
Real epsmin = pin->GetOrAddReal("ccsn", "epsmin", 1e-12); | ||
params.Add("epsmin", epsmin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... which probably means you don't need these floors.
KOKKOS_INLINE_FUNCTION | ||
std::pair<int, int> Get1DProfileNumZones(const std::string model_filename) { | ||
|
||
// open file | ||
std::ifstream inputfile(model_filename); | ||
const std::string whitespace(" \t\n\r"); | ||
|
||
// error check | ||
if (!inputfile.is_open()) { | ||
std::cout << model_filename << " not found :( \n."; | ||
exit(-1); | ||
} | ||
|
||
int nz = 0; | ||
int nc = 0; | ||
std::string line; | ||
std::string comment1("#"); | ||
std::string comment2("//"); | ||
|
||
// get number of zones from 1d file | ||
while (!inputfile.eof()) { | ||
|
||
getline(inputfile, line); | ||
|
||
std::size_t first_nonws = line.find_first_not_of(whitespace); | ||
|
||
// skip empty lines | ||
if (first_nonws == std::string::npos) { | ||
continue; | ||
} | ||
|
||
// skip comments | ||
if (line.find(comment1) == first_nonws || line.find(comment2) == first_nonws) { | ||
nc++; | ||
continue; | ||
} | ||
|
||
nz++; | ||
} | ||
|
||
inputfile.close(); | ||
|
||
return std::make_pair(nz + 1, nc); | ||
} | ||
|
||
template <typename ParArray2D> | ||
KOKKOS_INLINE_FUNCTION void Get1DProfileData(const std::string model_filename, | ||
const int num_zones, const int num_comments, | ||
const int num_vars, | ||
ParArray2D &ccsn_state_raw_h) { | ||
|
||
std::ifstream inputfile(model_filename); | ||
|
||
Real val = 0; | ||
std::string line; | ||
int line_num = 0; | ||
|
||
// skip comment lines | ||
while (line_num < num_comments) { | ||
getline(inputfile, line); | ||
line_num++; | ||
} | ||
|
||
// read file into model_1d | ||
for (int i = 0; i < num_zones; i++) // number of zones | ||
{ | ||
for (int j = 0; j < num_vars; j++) // number of vars | ||
{ | ||
inputfile >> val; | ||
ccsn_state_raw_h(j, i) = val; | ||
} | ||
} | ||
|
||
std::cout << "Read 1D profile into state array.\n"; | ||
|
||
inputfile.close(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's probably a way to read the data without looping through the file twice. But that's a problem for future us. This is fine for now.
Thanks for these comments. I have been working on chicoma so may need to wait until that is back up. Sounds like there is still a units issue and these are mostly design based. i'll go through them when i can and update once done! |
I thought I might try to download and poke at it myself to see if I could find the issue. Might ping you for the progenitor file. |
Reads in 1D stellar profile.
Maps to phoebus grid and fills matter variables
Assumes dr is the same for Monopole solver and input file
![compare_KEPLER_and_phoebus_ic](https://user-images.githubusercontent.com/19437981/202521097-9d0fe567-8401-4542-9187-8cdf7098a5bc.png)
Has check for
npoints
not equal to input fileConverts units to scale free assumed by monopole solver.