diff --git a/Source/PeleLMDerive.H b/Source/PeleLMDerive.H index 4d0a5581..fa1e2793 100644 --- a/Source/PeleLMDerive.H +++ b/Source/PeleLMDerive.H @@ -102,7 +102,7 @@ protected: * \param interp */ PeleLMDeriveRec( - const std::string& name, + std::string name, amrex::IndexType result_type, int nvar_derive, PeleLMDeriveFunc der_func, @@ -121,7 +121,7 @@ protected: * \param interp */ PeleLMDeriveRec( - const std::string& name, + std::string name, amrex::IndexType result_type, int nvar_derive, amrex::Vector& var_names, @@ -140,7 +140,7 @@ protected: * \param interp */ PeleLMDeriveRec( - const std::string& name, + std::string name, amrex::IndexType result_type, int nvar_derive, DeriveBoxMap box_map, @@ -158,7 +158,7 @@ protected: * \param interp */ PeleLMDeriveRec( - const std::string& name, + std::string name, amrex::IndexType result_type, int nvar_derive, amrex::Vector& var_names, diff --git a/Source/PeleLMDerive.cpp b/Source/PeleLMDerive.cpp index fca7e606..696ebe05 100644 --- a/Source/PeleLMDerive.cpp +++ b/Source/PeleLMDerive.cpp @@ -1,15 +1,16 @@ #include +#include using namespace amrex; PeleLMDeriveRec::PeleLMDeriveRec( - const std::string& a_name, + std::string a_name, IndexType result_type, int nvar_derive, PeleLMDeriveFunc der_func, DeriveBoxMap box_map, Interpolater* a_interp) - : derive_name(a_name), + : derive_name(std::move(a_name)), variable_names(), der_type(result_type), n_derive(nvar_derive), @@ -20,14 +21,14 @@ PeleLMDeriveRec::PeleLMDeriveRec( } PeleLMDeriveRec::PeleLMDeriveRec( - const std::string& a_name, + std::string a_name, IndexType result_type, int nvar_derive, Vector& var_names, PeleLMDeriveFunc der_func, DeriveBoxMap box_map, Interpolater* a_interp) - : derive_name(a_name), + : derive_name(std::move(a_name)), variable_names(var_names), der_type(result_type), n_derive(nvar_derive), @@ -38,33 +39,33 @@ PeleLMDeriveRec::PeleLMDeriveRec( } PeleLMDeriveRec::PeleLMDeriveRec( - const std::string& a_name, + std::string a_name, IndexType result_type, int nvar_derive, DeriveBoxMap box_map, Interpolater* a_interp) - : derive_name(a_name), + : derive_name(std::move(a_name)), variable_names(), der_type(result_type), n_derive(nvar_derive), - func(nullptr), + mapper(a_interp), bx_map(box_map) { } PeleLMDeriveRec::PeleLMDeriveRec( - const std::string& a_name, + std::string a_name, IndexType result_type, int nvar_derive, Vector& var_names, DeriveBoxMap box_map, Interpolater* a_interp) - : derive_name(a_name), + : derive_name(std::move(a_name)), variable_names(var_names), der_type(result_type), n_derive(nvar_derive), - func(nullptr), + mapper(a_interp), bx_map(box_map) { @@ -73,8 +74,8 @@ PeleLMDeriveRec::PeleLMDeriveRec( PeleLMDeriveRec::~PeleLMDeriveRec() { func = nullptr; - mapper = 0; - bx_map = 0; + mapper = nullptr; + bx_map = nullptr; } const std::string& @@ -200,17 +201,15 @@ PeleLMDeriveList::dlist() bool PeleLMDeriveList::canDerive(const std::string& name) const { - for (std::list::const_iterator li = lst.begin(), - End = lst.end(); - li != End; ++li) { + for (const auto& li : lst) { // Can be either a component name ... - for (int i = 0; i < li->numDerive(); i++) { - if (li->variableName(i) == name) { + for (int i = 0; i < li.numDerive(); i++) { + if (li.variableName(i) == name) { return true; } } // ... or a derive name - if (li->derive_name == name) { + if (li.derive_name == name) { return true; } } @@ -220,19 +219,17 @@ PeleLMDeriveList::canDerive(const std::string& name) const const PeleLMDeriveRec* PeleLMDeriveList::get(const std::string& name) const { - for (std::list::const_iterator li = lst.begin(), - End = lst.end(); - li != End; ++li) { + for (const auto& li : lst) { // Can be either a component name ... - for (int i = 0; i < li->numDerive(); i++) { - if (li->variableName(i) == name) { - return &(*li); + for (int i = 0; i < li.numDerive(); i++) { + if (li.variableName(i) == name) { + return &li; } } // ... or a derive name - if (li->derive_name == name) { - return &(*li); + if (li.derive_name == name) { + return &li; } } - return 0; + return nullptr; } diff --git a/Source/PeleLMDiagnostics.cpp b/Source/PeleLMDiagnostics.cpp index c3cf424a..ea6eb035 100644 --- a/Source/PeleLMDiagnostics.cpp +++ b/Source/PeleLMDiagnostics.cpp @@ -52,9 +52,9 @@ void PeleLM::updateDiagnostics() { // Might need to update some internal data as the grid changes - for (int n = 0; n < m_diagnostics.size(); ++n) { - if (m_diagnostics[n]->needUpdate()) { - m_diagnostics[n]->prepare( + for (const auto& m_diagnostic : m_diagnostics) { + if (m_diagnostic->needUpdate()) { + m_diagnostic->prepare( finestLevel() + 1, Geom(0, finestLevel()), boxArray(0, finestLevel()), dmap, m_diagVars); } @@ -87,15 +87,12 @@ PeleLM::doDiagnostics() } Vector stateNames; - for (std::list>::const_iterator - li = stateComponents.begin(), - End = stateComponents.end(); - li != End; ++li) { - stateNames.push_back(get<1>(*li)); + for (const auto& stateComponent : stateComponents) { + stateNames.push_back(get<1>(stateComponent)); } - for (int n = 0; n < m_diagnostics.size(); ++n) { - if (m_diagnostics[n]->doDiag(m_cur_time, m_nstep)) { - m_diagnostics[n]->processDiag( + for (const auto& m_diagnostic : m_diagnostics) { + if (m_diagnostic->doDiag(m_cur_time, m_nstep)) { + m_diagnostic->processDiag( m_nstep, m_cur_time, GetVecOfConstPtrs(diagMFVec), m_diagVars); } } diff --git a/Source/PeleLMEvolve.cpp b/Source/PeleLMEvolve.cpp index 58ce411d..f46e8cb7 100644 --- a/Source/PeleLMEvolve.cpp +++ b/Source/PeleLMEvolve.cpp @@ -240,7 +240,7 @@ PeleLM::checkMessage(const std::string& a_action) int action_flag = 0; if (ParallelDescriptor::IOProcessor()) { FILE* fp; - if ((fp = fopen(action_file.c_str(), "r")) != 0) { + if ((fp = fopen(action_file.c_str(), "r")) != nullptr) { remove(action_file.c_str()); action_flag = 1; fclose(fp); diff --git a/Source/PeleLMPlot.cpp b/Source/PeleLMPlot.cpp index c8910e70..6d8ed8db 100644 --- a/Source/PeleLMPlot.cpp +++ b/Source/PeleLMPlot.cpp @@ -477,8 +477,8 @@ PeleLM::WriteHeader(const std::string& name, bool is_checkpoint) const // Ambient pressure and typvals HeaderFile << m_pNew << "\n"; - for (int n = 0; n < typical_values.size(); n++) { - HeaderFile << typical_values[n] << "\n"; + for (double typical_value : typical_values) { + HeaderFile << typical_value << "\n"; } } } @@ -663,8 +663,8 @@ PeleLM::ReadCheckPointFile() is >> m_pNew; GotoNextLine(is); m_pOld = m_pNew; - for (int n = 0; n < typical_values.size(); n++) { - is >> typical_values[n]; + for (double& typical_value : typical_values) { + is >> typical_value; GotoNextLine(is); } diff --git a/Source/PeleLMSetup.cpp b/Source/PeleLMSetup.cpp index 114e45c9..91bc8849 100644 --- a/Source/PeleLMSetup.cpp +++ b/Source/PeleLMSetup.cpp @@ -1137,8 +1137,8 @@ PeleLM::taggingSetup() ppamr.queryarr( "refinement_indicators", refinement_indicators, 0, ppamr.countval("refinement_indicators")); - for (int n = 0; n < refinement_indicators.size(); ++n) { - std::string ref_prefix = amr_prefix + "." + refinement_indicators[n]; + for (const auto& refinement_indicator : refinement_indicators) { + std::string ref_prefix = amr_prefix + "." + refinement_indicator; ParmParse ppr(ref_prefix); // Tag a given box @@ -1211,16 +1211,15 @@ PeleLM::taggingSetup() errTags.push_back(AMRErrorTag(info)); itexists = true; } else { - Abort( - std::string( - "Unrecognized refinement indicator for " + refinement_indicators[n]) - .c_str()); + Abort(std::string( + "Unrecognized refinement indicator for " + refinement_indicator) + .c_str()); } if (!itexists) { amrex::Error( "PeleLM::taggingSetup(): unknown variable field for criteria " + - refinement_indicators[n]); + refinement_indicator); } } } diff --git a/Source/PeleLMTagging.cpp b/Source/PeleLMTagging.cpp index d0bc9052..236aba54 100644 --- a/Source/PeleLMTagging.cpp +++ b/Source/PeleLMTagging.cpp @@ -22,13 +22,12 @@ PeleLM::ErrorEst(int lev, TagBoxArray& tags, Real time, int /*ng*/) } #endif - for (int n = 0; n < errTags.size(); ++n) { + for (const auto& errTag : errTags) { std::unique_ptr mf; - if (errTags[n].Field() != std::string()) { - mf = deriveComp(errTags[n].Field(), time, lev, errTags[n].NGrow()); + if (errTag.Field() != std::string()) { + mf = deriveComp(errTag.Field(), time, lev, errTag.NGrow()); } - errTags[n]( - tags, mf.get(), TagBox::CLEAR, TagBox::SET, time, lev, geom[lev]); + errTag(tags, mf.get(), TagBox::CLEAR, TagBox::SET, time, lev, geom[lev]); } #ifdef AMREX_USE_EB diff --git a/Source/PeleLMUtils.cpp b/Source/PeleLMUtils.cpp index 763a6891..1a672a52 100644 --- a/Source/PeleLMUtils.cpp +++ b/Source/PeleLMUtils.cpp @@ -1096,11 +1096,8 @@ bool PeleLM::isStateVariable(std::string_view a_name) { // Check state - for (std::list>::const_iterator - li = stateComponents.begin(), - End = stateComponents.end(); - li != End; ++li) { - if (std::get<1>(*li) == a_name) { + for (const auto& stateComponent : stateComponents) { + if (std::get<1>(stateComponent) == a_name) { return true; } } @@ -1111,11 +1108,8 @@ bool PeleLM::isReactVariable(std::string_view a_name) { // Check reaction state - for (std::list>::const_iterator - li = reactComponents.begin(), - End = reactComponents.end(); - li != End; ++li) { - if (std::get<1>(*li) == a_name) { + for (const auto& reactComponent : reactComponents) { + if (std::get<1>(reactComponent) == a_name) { return true; } } @@ -1131,12 +1125,9 @@ PeleLM::stateVariableIndex(std::string_view a_name) "PeleLM::stateVariableIndex(): unknown State variable: " + static_cast(a_name)); } - for (std::list>::const_iterator - li = stateComponents.begin(), - End = stateComponents.end(); - li != End; ++li) { - if (std::get<1>(*li) == a_name) { - idx = std::get<0>(*li); + for (const auto& stateComponent : stateComponents) { + if (std::get<1>(stateComponent) == a_name) { + idx = std::get<0>(stateComponent); } } return idx; @@ -1151,12 +1142,9 @@ PeleLM::reactVariableIndex(std::string_view a_name) "PeleLM::reactVariableIndex(): unknown Reaction variable: " + static_cast(a_name)); } - for (std::list>::const_iterator - li = reactComponents.begin(), - End = reactComponents.end(); - li != End; ++li) { - if (std::get<1>(*li) == a_name) { - idx = std::get<0>(*li); + for (const auto& reactComponent : reactComponents) { + if (std::get<1>(reactComponent) == a_name) { + idx = std::get<0>(reactComponent); } } return idx; @@ -1790,11 +1778,11 @@ PeleLM::parseComposition( // Ensure that it sums to 1.0: Real sum = 0.0; - for (int k = 0; k < NUM_SPECIES; k++) { - sum += compoIn[k]; + for (double k : compoIn) { + sum += k; } - for (int k = 0; k < NUM_SPECIES; k++) { - compoIn[k] /= sum; + for (double& k : compoIn) { + k /= sum; } // Fill the massFrac array, convert from mole fraction if necessary diff --git a/Source/PeleLM_K.H b/Source/PeleLM_K.H index 571cb879..0dab5d95 100644 --- a/Source/PeleLM_K.H +++ b/Source/PeleLM_K.H @@ -308,8 +308,8 @@ compute_divu( amrex::Real hi[NUM_SPECIES] = {0.0}; eos.T2Hi(T(i, j, k), hi); cpmix *= 1.0e-4_rt; // CGS -> MKS conversion - for (int n = 0; n < NUM_SPECIES; n++) { - hi[n] *= 1.0e-4_rt; // CGS -> MKS conversion + for (double& n : hi) { + n *= 1.0e-4_rt; // CGS -> MKS conversion } amrex::Real denominv = 1.0_rt / (rho * cpmix * T(i, j, k));