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

Print temporals in CSV format #410

Merged
merged 7 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Source/Efield/PeleLMeX_EFUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,9 @@ PeleLM::ionsBalance()
}
}

tmpIonsFile << m_nstep << " " << m_cur_time; // Time info
tmpIonsFile << m_nstep << "," << m_cur_time; // Time info
for (int i = 0; i < 2 * AMREX_SPACEDIM; i++) {
tmpIonsFile << " " << ionsCurrent[i]; // ions current as xlo, xhi, ylo, ...
tmpIonsFile << "," << ionsCurrent[i]; // ions current as xlo, xhi, ylo, ...
}
tmpIonsFile << "\n";
tmpIonsFile.flush();
Expand Down
1 change: 1 addition & 0 deletions Source/PeleLMeX.H
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,7 @@ public:
bool isReactVariable(std::string_view a_name);
int stateVariableIndex(std::string_view a_name);
int reactVariableIndex(std::string_view a_name);
std::string stateVariableName(int a_index);

// Typical values
void setTypicalValues(const PeleLM::TimeStamp& a_time, int is_init = 0);
Expand Down
81 changes: 52 additions & 29 deletions Source/PeleLMeX_Temporals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ PeleLM::massBalance()
+m_domainMassFlux[2] + m_domainMassFlux[3],
+m_domainMassFlux[4] + m_domainMassFlux[5]);

tmpMassFile << m_nstep << " " << m_cur_time // Time info
<< " " << m_massNew // mass
<< " " << dmdt // mass temporal derivative
<< " " << massFluxBalance // domain boundaries mass fluxes
<< " " << std::abs(dmdt - massFluxBalance) << " \n"; // balance
tmpMassFile << m_nstep << "," << m_cur_time // Time info
<< "," << m_massNew // mass
<< "," << dmdt // mass temporal derivative
<< "," << massFluxBalance // domain boundaries mass fluxes
<< "," << std::abs(dmdt - massFluxBalance) << "\n"; // balance
tmpMassFile.flush();
}

void
PeleLM::speciesBalancePatch()
{
tmppatchmfrFile << m_nstep << " " << m_cur_time; // Time info
tmppatchmfrFile << m_nstep << "," << m_cur_time; // Time info
for (int n = 0; n < m_bPatches.size(); n++) {
BPatch::BpatchDataContainer* bphost = m_bPatches[n]->getHostDataPtr();
for (int i = 0; i < bphost->num_species; i++) {
tmppatchmfrFile << " " << bphost->speciesFlux[i];
tmppatchmfrFile << "," << bphost->speciesFlux[i];
}
}
tmppatchmfrFile << "\n";
Expand All @@ -90,13 +90,13 @@ PeleLM::speciesBalance()
m_domainRhoYFlux[2 * n * AMREX_SPACEDIM + 5]);
}

tmpSpecFile << m_nstep << " " << m_cur_time; // Time info
tmpSpecFile << m_nstep << "," << m_cur_time; // Time info
for (int n = 0; n < NUM_SPECIES; n++) {
tmpSpecFile << " " << m_RhoYNew[n] // mass of Y
<< " " << dmYdt[n] // mass temporal derivative
<< " " << massYFluxBalance[n] // domain boundaries mass fluxes
<< " " << rhoYdots[n] // integrated consumption rate
<< " "
tmpSpecFile << "," << m_RhoYNew[n] // mass of Y
<< "," << dmYdt[n] // mass temporal derivative
<< "," << massYFluxBalance[n] // domain boundaries mass fluxes
<< "," << rhoYdots[n] // integrated consumption rate
<< ","
<< std::abs(
dmYdt[n] - massYFluxBalance[n] - rhoYdots[n]); // balance
}
Expand Down Expand Up @@ -310,11 +310,11 @@ PeleLM::rhoHBalance()
+m_domainRhoHFlux[2] + m_domainRhoHFlux[3],
+m_domainRhoHFlux[4] + m_domainRhoHFlux[5]);

tmpMassFile << m_nstep << " " << m_cur_time // Time info
<< " " << m_RhoHNew // RhoH
<< " " << dRhoHdt // RhoH temporal derivative
<< " " << rhoHFluxBalance // domain boundaries RhoH fluxes
<< " " << std::abs(dRhoHdt - rhoHFluxBalance) << " \n"; // balance
tmpMassFile << m_nstep << "," << m_cur_time // Time info
<< "," << m_RhoHNew // RhoH
<< "," << dRhoHdt // RhoH temporal derivative
<< "," << rhoHFluxBalance // domain boundaries RhoH fluxes
<< "," << std::abs(dRhoHdt - rhoHFluxBalance) << "\n"; // balance
tmpMassFile.flush();
}

Expand Down Expand Up @@ -670,13 +670,13 @@ PeleLM::writeTemporals()
heatReleaseRateInt = MFSum(GetVecOfConstPtrs(kinEnergy), 0);
}

tmpStateFile << m_nstep << " " << m_cur_time << " " << m_dt // Time
<< " " << kinenergy_int // Kinetic energy
<< " " << enstrophy_int // Enstrophy
<< " " << m_pNew // Thermo. pressure
<< " " << fuelConsumptionInt // Integ fuel burning rate
<< " " << heatReleaseRateInt // Integ heat release rate
<< " \n";
tmpStateFile << m_nstep << "," << m_cur_time << "," << m_dt // Time
<< "," << kinenergy_int // Kinetic energy
<< "," << enstrophy_int // Enstrophy
<< "," << m_pNew // Thermo. pressure
<< "," << fuelConsumptionInt // Integ fuel burning rate
<< "," << heatReleaseRateInt // Integ heat release rate
<< "\n";
tmpStateFile.flush();

// Get min/max for state components
Expand All @@ -689,12 +689,12 @@ PeleLM::writeTemporals()
? MLmin(GetVecOfConstPtrs(getStateVect(AmrNewTime)), 0, AMREX_SPACEDIM)
: MLmin(GetVecOfConstPtrs(getStateVect(AmrNewTime)), 0, NVAR);

tmpExtremasFile << m_nstep << " " << m_cur_time; // Time
tmpExtremasFile << m_nstep << "," << m_cur_time; // Time
for (int n = 0; n < stateMax.size();
++n) { // Min & max of each state variable
tmpExtremasFile << " " << stateMin[n] << " " << stateMax[n];
tmpExtremasFile << "," << stateMin[n] << "," << stateMax[n];
}
tmpExtremasFile << " \n";
tmpExtremasFile << "\n";
tmpExtremasFile.flush();

#ifdef PELE_USE_EFIELD
Expand All @@ -720,34 +720,52 @@ PeleLM::openTempFile()
tempFileName.c_str(),
std::ios::out | std::ios::app | std::ios_base::binary);
tmpStateFile.precision(12);
tmpStateFile << "iter,time,dt,kinEnergy,enstrophy,pressure,fuelConsumption,"
"heatRelease\n";
if (m_do_massBalance != 0) {
tempFileName = "temporals/tempMass";
tmpMassFile.open(
tempFileName.c_str(),
std::ios::out | std::ios::app | std::ios_base::binary);
tmpMassFile.precision(12);
tmpMassFile << "iter,time,massNew,dmdt,netMassFlux,balance\n";
}
if (m_do_speciesBalance != 0) {
tempFileName = "temporals/tempSpecies";
tmpSpecFile.open(
tempFileName.c_str(),
std::ios::out | std::ios::app | std::ios_base::binary);
tmpSpecFile.precision(12);
tmpSpecFile << "iter,time";
for (int n = 0; n < NUM_SPECIES; n++) {
tmpSpecFile << ",rhoYnew_" << PeleLM::stateVariableName(FIRSTSPEC + n);
tmpSpecFile << ",drhoYdt_" << PeleLM::stateVariableName(FIRSTSPEC + n);
tmpSpecFile << ",netFlux_" << PeleLM::stateVariableName(FIRSTSPEC + n);
tmpSpecFile << ",rxnCons_" << PeleLM::stateVariableName(FIRSTSPEC + n);
tmpSpecFile << ",balance_" << PeleLM::stateVariableName(FIRSTSPEC + n);
}
tmpSpecFile << "\n";
}
if (m_do_extremas != 0) {
tempFileName = "temporals/tempExtremas";
tmpExtremasFile.open(
tempFileName.c_str(),
std::ios::out | std::ios::app | std::ios_base::binary);
tmpExtremasFile.precision(12);
tmpExtremasFile << "iter,time";
for (int n = 0; n < NVAR; ++n) {
tmpExtremasFile << ",min_" << PeleLM::stateVariableName(n) << ",max_"
<< PeleLM::stateVariableName(n);
}
tmpExtremasFile << "\n";
}
if (m_do_patch_mfr != 0) {
tempFileName = "temporals/temppatchmfr";
tmppatchmfrFile.open(
tempFileName.c_str(),
std::ios::out | std::ios::app | std::ios_base::binary);
tmppatchmfrFile.precision(12);
tmppatchmfrFile << "#Variables=iter,time";
tmppatchmfrFile << "iter,time";
for (int n = 0; n < m_bPatches.size(); n++) {
BPatch* patch = m_bPatches[n].get();
BPatch::BpatchDataContainer bphost = patch->getHostData();
Expand All @@ -765,6 +783,11 @@ PeleLM::openTempFile()
tempFileName.c_str(),
std::ios::out | std::ios::app | std::ios_base::binary);
tmpIonsFile.precision(12);
tmpIonsFile << "iter,time";
for (int i = 0; i < AMREX_SPACEDIM; i++) {
tmpIonsFile << ",curr_" << i << "_low,curr_" << i << "_hi";
}
tmpIonsFile << "\n";
}
#endif
}
Expand Down
18 changes: 18 additions & 0 deletions Source/PeleLMeX_Utils.cpp
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line No: 1213, in the print statement, it should be "invalid" and not "invalod".

Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,24 @@ PeleLM::stateVariableIndex(std::string_view a_name)
return idx;
}

std::string
PeleLM::stateVariableName(int a_index)
{
if (a_index < 0 || a_index >= NVAR) {
amrex::Error(
"PeleLM::stateVariableName(): invalod state index: " +
std::to_string(a_index));
}

std::string var_name;
for (const auto& stateComponent : stateComponents) {
if (std::get<0>(stateComponent) == a_index) {
var_name = std::get<1>(stateComponent);
}
}
return var_name;
}

int
PeleLM::reactVariableIndex(std::string_view a_name)
{
Expand Down
Loading