Skip to content
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

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

CCSN Initilization #135

wants to merge 27 commits into from

Conversation

carlnotsagan
Copy link
Collaborator

@carlnotsagan carlnotsagan commented Oct 27, 2022

  • 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

  • Has check for npoints not equal to input file

  • Converts units to scale free assumed by monopole solver.

@carlnotsagan carlnotsagan added the enhancement New feature or request label Oct 27, 2022
@carlnotsagan carlnotsagan self-assigned this Oct 27, 2022
@carlnotsagan carlnotsagan changed the title WIP: CCSN Initilization CCSN Initilization Nov 21, 2022
@Yurlungur
Copy link
Collaborator

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.

Copy link
Collaborator

@Yurlungur Yurlungur left a 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;
Copy link
Collaborator

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.

Comment on lines +135 to +141
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);
}
Copy link
Collaborator

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());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// printf("Current working dir: %s\n", get_current_dir_name());

Comment on lines +201 to +202
Real yint = MonopoleGR::Interpolate(xa, state_raw, radius,
j); // call to some interp routine
Copy link
Collaborator

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.

Comment on lines +209 to +219
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));
Copy link
Collaborator

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.

Comment on lines +250 to +255
// 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();
Copy link
Collaborator

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:
$u = \varepsilon \rho$
also the monopole solver actually wants specific energy $\varepsilon$, not energy density $u$. So I would leave this as $\varepsilon$ with appropriate units of unit_conv.GetEnergyCGSToCode()/unit_conv.GetMassCGSToCode() and only convert to energy density $u$ in the problem generator when you set the 3D grid variables.

Comment on lines +287 to +290
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?
Copy link
Collaborator

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.

Comment on lines +298 to +303
// floor based on pressure
if (pres <= 1.1 * Pmin) {
pres = rho = eps = 0;
} else {
// PolytropeThermoFromP(press, K, Gamma, rho, eps);
}
Copy link
Collaborator

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.

Comment on lines +80 to +90
// 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);
Copy link
Collaborator

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.

Comment on lines +48 to +124
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();
}
Copy link
Collaborator

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.

@carlnotsagan
Copy link
Collaborator Author

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!

@Yurlungur
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants