replace repeated if statements with table and lambdas

This commit is contained in:
Arne Morten Kvarving 2023-08-04 15:11:11 +02:00
parent 61a3908f38
commit c3cba635a2

View File

@ -944,50 +944,43 @@ setRestart(const data::Solution& sol,
assert(!saturation_[oilPhaseIdx].empty());
saturation_[oilPhaseIdx][elemIdx] = so;
if (!fluidPressure_.empty() && sol.has("PRESSURE"))
fluidPressure_[elemIdx] = sol.data("PRESSURE")[globalDofIndex];
if (!temperature_.empty() && sol.has("TEMP"))
temperature_[elemIdx] = sol.data("TEMP")[globalDofIndex];
if (!rs_.empty() && sol.has("RS"))
rs_[elemIdx] = sol.data("RS")[globalDofIndex];
if (!rsw_.empty() && sol.has("RSW"))
rsw_[elemIdx] = sol.data("RSW")[globalDofIndex];
if (!rv_.empty() && sol.has("RV"))
rv_[elemIdx] = sol.data("RV")[globalDofIndex];
if (!rvw_.empty() && sol.has("RVW"))
rvw_[elemIdx] = sol.data("RVW")[globalDofIndex];
if (!cPolymer_.empty() && sol.has("POLYMER"))
cPolymer_[elemIdx] = sol.data("POLYMER")[globalDofIndex];
if (!cFoam_.empty() && sol.has("FOAM"))
cFoam_[elemIdx] = sol.data("FOAM")[globalDofIndex];
if (!cSalt_.empty() && sol.has("SALT"))
cSalt_[elemIdx] = sol.data("SALT")[globalDofIndex];
if (!pSalt_.empty() && sol.has("SALTP"))
pSalt_[elemIdx] = sol.data("SALTP")[globalDofIndex];
if (!permFact_.empty() && sol.has("PERMFACT"))
permFact_[elemIdx] = sol.data("PERMFACT")[globalDofIndex];
if (!soMax_.empty() && sol.has("SOMAX"))
soMax_[elemIdx] = sol.data("SOMAX")[globalDofIndex];
if (!pcSwMdcOw_.empty() && sol.has("PCSWM_OW"))
pcSwMdcOw_[elemIdx] = sol.data("PCSWM_OW")[globalDofIndex];
if (!krnSwMdcOw_.empty() && sol.has("KRNSW_OW"))
krnSwMdcOw_[elemIdx] = sol.data("KRNSW_OW")[globalDofIndex];
if (!pcSwMdcGo_.empty() && sol.has("PCSWM_GO"))
pcSwMdcGo_[elemIdx] = sol.data("PCSWM_GO")[globalDofIndex];
if (!krnSwMdcGo_.empty() && sol.has("KRNSW_GO"))
krnSwMdcGo_[elemIdx] = sol.data("KRNSW_GO")[globalDofIndex];
if (!ppcw_.empty() && sol.has("PPCW"))
ppcw_[elemIdx] = sol.data("PPCW")[globalDofIndex];
if (!cMicrobes_.empty() && sol.has("MICROBES"))
cMicrobes_[elemIdx] = sol.data("MICROBES")[globalDofIndex];
if (!cOxygen_.empty() && sol.has("OXYGEN"))
cOxygen_[elemIdx] = sol.data("OXYGEN")[globalDofIndex];
if (!cUrea_.empty() && sol.has("UREA"))
cUrea_[elemIdx] = sol.data("UREA")[globalDofIndex];
if (!cBiofilm_.empty() && sol.has("BIOFILM"))
cBiofilm_[elemIdx] = sol.data("BIOFILM")[globalDofIndex];
if (!cCalcite_.empty() && sol.has("CALCITE"))
cCalcite_[elemIdx] = sol.data("CALCITE")[globalDofIndex];
auto assign = [elemIdx, globalDofIndex, &sol](const std::string& name,
ScalarBuffer& data)
{
if (!data.empty() && sol.has(name)) {
data[elemIdx] = sol.data(name)[globalDofIndex];
}
};
const auto fields = std::array{
std::pair{"BIOFILM", &cBiofilm_},
std::pair{"CALCITE",&cCalcite_},
std::pair{"FOAM", &cFoam_},
std::pair{"KRNSW_GO", &krnSwMdcGo_},
std::pair{"KRNSW_OW", &krnSwMdcOw_},
std::pair{"MICROBES", &cMicrobes_},
std::pair{"OXYGEN", &cOxygen_},
std::pair{"PCSWM_GO", &pcSwMdcGo_},
std::pair{"PCSWM_OW", &pcSwMdcOw_},
std::pair{"PERMFACT", &permFact_},
std::pair{"POLYMER", &cPolymer_},
std::pair{"PPCW", &ppcw_},
std::pair{"PRESSURE", &fluidPressure_},
std::pair{"RS", &rs_},
std::pair{"RSW", &rsw_},
std::pair{"RV", &rv_},
std::pair{"RVW", &rvw_},
std::pair{"SALT", &cSalt_},
std::pair{"SALTP", &pSalt_},
std::pair{"SOMAX", &soMax_},
std::pair{"TEMP", &temperature_},
std::pair{"UREA", &cUrea_},
};
std::for_each(fields.begin(), fields.end(),
[&assign](const auto& p)
{ assign(p.first, *p.second); });
}
template<class FluidSystem,class Scalar>