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

Fix modernize-loop-convert #253

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions Source/PeleLMDerive.H
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -121,7 +121,7 @@ protected:
* \param interp
*/
PeleLMDeriveRec(
const std::string& name,
std::string name,
amrex::IndexType result_type,
int nvar_derive,
amrex::Vector<std::string>& var_names,
Expand All @@ -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,
Expand All @@ -158,7 +158,7 @@ protected:
* \param interp
*/
PeleLMDeriveRec(
const std::string& name,
std::string name,
amrex::IndexType result_type,
int nvar_derive,
amrex::Vector<std::string>& var_names,
Expand Down
51 changes: 24 additions & 27 deletions Source/PeleLMDerive.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include <PeleLMDerive.H>
#include <utility>

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),
Expand All @@ -20,14 +21,14 @@ PeleLMDeriveRec::PeleLMDeriveRec(
}

PeleLMDeriveRec::PeleLMDeriveRec(
const std::string& a_name,
std::string a_name,
IndexType result_type,
int nvar_derive,
Vector<std::string>& 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),
Expand All @@ -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<std::string>& 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)
{
Expand All @@ -73,8 +74,8 @@ PeleLMDeriveRec::PeleLMDeriveRec(
PeleLMDeriveRec::~PeleLMDeriveRec()
{
func = nullptr;
mapper = 0;
bx_map = 0;
mapper = nullptr;
bx_map = nullptr;
}

const std::string&
Expand Down Expand Up @@ -200,17 +201,15 @@ PeleLMDeriveList::dlist()
bool
PeleLMDeriveList::canDerive(const std::string& name) const
{
for (std::list<PeleLMDeriveRec>::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;
}
}
Expand All @@ -220,19 +219,17 @@ PeleLMDeriveList::canDerive(const std::string& name) const
const PeleLMDeriveRec*
PeleLMDeriveList::get(const std::string& name) const
{
for (std::list<PeleLMDeriveRec>::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;
}
19 changes: 8 additions & 11 deletions Source/PeleLMDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -87,15 +87,12 @@ PeleLM::doDiagnostics()
}

Vector<std::string> stateNames;
for (std::list<std::tuple<int, std::string>>::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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/PeleLMEvolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions Source/PeleLMPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
}
Expand Down Expand Up @@ -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);
}

Expand Down
13 changes: 6 additions & 7 deletions Source/PeleLMSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions Source/PeleLMTagging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<MultiFab> 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
Expand Down
40 changes: 14 additions & 26 deletions Source/PeleLMUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,11 +1096,8 @@ bool
PeleLM::isStateVariable(std::string_view a_name)
{
// Check state
for (std::list<std::tuple<int, std::string>>::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;
}
}
Expand All @@ -1111,11 +1108,8 @@ bool
PeleLM::isReactVariable(std::string_view a_name)
{
// Check reaction state
for (std::list<std::tuple<int, std::string>>::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;
}
}
Expand All @@ -1131,12 +1125,9 @@ PeleLM::stateVariableIndex(std::string_view a_name)
"PeleLM::stateVariableIndex(): unknown State variable: " +
static_cast<std::string>(a_name));
}
for (std::list<std::tuple<int, std::string>>::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;
Expand All @@ -1151,12 +1142,9 @@ PeleLM::reactVariableIndex(std::string_view a_name)
"PeleLM::reactVariableIndex(): unknown Reaction variable: " +
static_cast<std::string>(a_name));
}
for (std::list<std::tuple<int, std::string>>::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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Source/PeleLM_K.H
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down