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

@ -191,9 +191,9 @@ EclGenericOutputBlackoilModule(const EclipseState& eclState,
anyFlows_ = false; anyFlows_ = false;
enableFlores_ = false; // Used for the output of i+, j+, k+ enableFlores_ = false; // Used for the output of i+, j+, k+
enableFloresn_ = false; // Used for the special case of nnc enableFloresn_ = false; // Used for the special case of nnc
enableFlows_ = false; enableFlows_ = false;
enableFlowsn_ = false; enableFlowsn_ = false;
for (const auto& block : this->schedule_) { // Uses Schedule::begin() and Schedule::end() for (const auto& block : this->schedule_) { // Uses Schedule::begin() and Schedule::end()
const auto& rstkw = block.rst_config().keywords; const auto& rstkw = block.rst_config().keywords;
@ -419,7 +419,7 @@ outputProdLog(size_t reportStepNum,
tmp_values[6] = get("GWCT"); //WellProdDataType::WaterCut tmp_values[6] = get("GWCT"); //WellProdDataType::WaterCut
tmp_values[7] = get("GGOR"); //WellProdDataType::GasOilRatio tmp_values[7] = get("GGOR"); //WellProdDataType::GasOilRatio
} }
tmp_values[8] = tmp_values[3]/tmp_values[4]; //WellProdDataType::WaterGasRatio tmp_values[8] = tmp_values[3]/tmp_values[4]; //WellProdDataType::WaterGasRatio
if (isnan(tmp_values[8])){ if (isnan(tmp_values[8])){
tmp_values[8] = 0.0; tmp_values[8] = 0.0;
@ -944,50 +944,43 @@ setRestart(const data::Solution& sol,
assert(!saturation_[oilPhaseIdx].empty()); assert(!saturation_[oilPhaseIdx].empty());
saturation_[oilPhaseIdx][elemIdx] = so; saturation_[oilPhaseIdx][elemIdx] = so;
if (!fluidPressure_.empty() && sol.has("PRESSURE")) auto assign = [elemIdx, globalDofIndex, &sol](const std::string& name,
fluidPressure_[elemIdx] = sol.data("PRESSURE")[globalDofIndex]; ScalarBuffer& data)
if (!temperature_.empty() && sol.has("TEMP"))
temperature_[elemIdx] = sol.data("TEMP")[globalDofIndex]; {
if (!rs_.empty() && sol.has("RS")) if (!data.empty() && sol.has(name)) {
rs_[elemIdx] = sol.data("RS")[globalDofIndex]; data[elemIdx] = sol.data(name)[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]; const auto fields = std::array{
if (!rvw_.empty() && sol.has("RVW")) std::pair{"BIOFILM", &cBiofilm_},
rvw_[elemIdx] = sol.data("RVW")[globalDofIndex]; std::pair{"CALCITE",&cCalcite_},
if (!cPolymer_.empty() && sol.has("POLYMER")) std::pair{"FOAM", &cFoam_},
cPolymer_[elemIdx] = sol.data("POLYMER")[globalDofIndex]; std::pair{"KRNSW_GO", &krnSwMdcGo_},
if (!cFoam_.empty() && sol.has("FOAM")) std::pair{"KRNSW_OW", &krnSwMdcOw_},
cFoam_[elemIdx] = sol.data("FOAM")[globalDofIndex]; std::pair{"MICROBES", &cMicrobes_},
if (!cSalt_.empty() && sol.has("SALT")) std::pair{"OXYGEN", &cOxygen_},
cSalt_[elemIdx] = sol.data("SALT")[globalDofIndex]; std::pair{"PCSWM_GO", &pcSwMdcGo_},
if (!pSalt_.empty() && sol.has("SALTP")) std::pair{"PCSWM_OW", &pcSwMdcOw_},
pSalt_[elemIdx] = sol.data("SALTP")[globalDofIndex]; std::pair{"PERMFACT", &permFact_},
if (!permFact_.empty() && sol.has("PERMFACT")) std::pair{"POLYMER", &cPolymer_},
permFact_[elemIdx] = sol.data("PERMFACT")[globalDofIndex]; std::pair{"PPCW", &ppcw_},
if (!soMax_.empty() && sol.has("SOMAX")) std::pair{"PRESSURE", &fluidPressure_},
soMax_[elemIdx] = sol.data("SOMAX")[globalDofIndex]; std::pair{"RS", &rs_},
if (!pcSwMdcOw_.empty() && sol.has("PCSWM_OW")) std::pair{"RSW", &rsw_},
pcSwMdcOw_[elemIdx] = sol.data("PCSWM_OW")[globalDofIndex]; std::pair{"RV", &rv_},
if (!krnSwMdcOw_.empty() && sol.has("KRNSW_OW")) std::pair{"RVW", &rvw_},
krnSwMdcOw_[elemIdx] = sol.data("KRNSW_OW")[globalDofIndex]; std::pair{"SALT", &cSalt_},
if (!pcSwMdcGo_.empty() && sol.has("PCSWM_GO")) std::pair{"SALTP", &pSalt_},
pcSwMdcGo_[elemIdx] = sol.data("PCSWM_GO")[globalDofIndex]; std::pair{"SOMAX", &soMax_},
if (!krnSwMdcGo_.empty() && sol.has("KRNSW_GO")) std::pair{"TEMP", &temperature_},
krnSwMdcGo_[elemIdx] = sol.data("KRNSW_GO")[globalDofIndex]; std::pair{"UREA", &cUrea_},
if (!ppcw_.empty() && sol.has("PPCW")) };
ppcw_[elemIdx] = sol.data("PPCW")[globalDofIndex];
if (!cMicrobes_.empty() && sol.has("MICROBES")) std::for_each(fields.begin(), fields.end(),
cMicrobes_[elemIdx] = sol.data("MICROBES")[globalDofIndex]; [&assign](const auto& p)
if (!cOxygen_.empty() && sol.has("OXYGEN")) { assign(p.first, *p.second); });
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];
} }
template<class FluidSystem,class Scalar> template<class FluidSystem,class Scalar>
@ -1593,14 +1586,14 @@ outputProductionReport_(const ScalarBuffer& wellProd,
ss << ": : : : SCC/HR : SCC/HR : SCC/HR : RCC : SCC/SCC : SCC/SCC : SCC/SCC : ATMA : ATMA :\n";// :\n"; ss << ": : : : SCC/HR : SCC/HR : SCC/HR : RCC : SCC/SCC : SCC/SCC : SCC/SCC : ATMA : ATMA :\n";// :\n";
} }
ss << "=================================================================================================================================\n";//=================== \n"; ss << "=================================================================================================================================\n";//=================== \n";
} }
else { else {
if (wellProd[WellProdDataType::WellLocationi] < 1) { if (wellProd[WellProdDataType::WellLocationi] < 1) {
ss << std::right << std::fixed << ":" << std::setw (8) << wellProdNames[WellProdDataType::WellName] << ":" << std::setprecision(0) << std::setw(11) << "" << ":" << std::setw(4) << wellProdNames[WellProdDataType::CTRLMode] << ":" << std::setprecision(1) << std::setw(11) << wellProd[WellProdDataType::OilRate] << ":" << std::setw(11) << wellProd[WellProdDataType::WaterRate] << ":" << std::setw(11)<< wellProd[WellProdDataType::GasRate] << ":" << std::setw(11) << wellProd[WellProdDataType::FluidResVol] << std::setprecision(3) << ":" << std::setw(11) << wellProd[WellProdDataType::WaterCut] << std::setprecision(2) << ":" << std::setw(10) << wellProd[WellProdDataType::GasOilRatio] << std::setprecision(4) << ":" << std::setw(12) << wellProd[WellProdDataType::WatGasRatio] << std::setprecision(1) << ":" << std::setw(8) << "" << ":" << std::setw(8) << "" << ": \n"; ss << std::right << std::fixed << ":" << std::setw (8) << wellProdNames[WellProdDataType::WellName] << ":" << std::setprecision(0) << std::setw(11) << "" << ":" << std::setw(4) << wellProdNames[WellProdDataType::CTRLMode] << ":" << std::setprecision(1) << std::setw(11) << wellProd[WellProdDataType::OilRate] << ":" << std::setw(11) << wellProd[WellProdDataType::WaterRate] << ":" << std::setw(11)<< wellProd[WellProdDataType::GasRate] << ":" << std::setw(11) << wellProd[WellProdDataType::FluidResVol] << std::setprecision(3) << ":" << std::setw(11) << wellProd[WellProdDataType::WaterCut] << std::setprecision(2) << ":" << std::setw(10) << wellProd[WellProdDataType::GasOilRatio] << std::setprecision(4) << ":" << std::setw(12) << wellProd[WellProdDataType::WatGasRatio] << std::setprecision(1) << ":" << std::setw(8) << "" << ":" << std::setw(8) << "" << ": \n";
} }
else { else {
ss << std::right << std::fixed << ":" << std::setw (8) << wellProdNames[WellProdDataType::WellName] << ":" << std::setprecision(0) << std::setw(5) << wellProd[WellProdDataType::WellLocationi] << "," << std::setw(5) << wellProd[WellProdDataType::WellLocationj] << ":" << std::setw(4) << wellProdNames[WellProdDataType::CTRLMode] << ":" << std::setprecision(1) << std::setw(11) << wellProd[WellProdDataType::OilRate] << ":" << std::setw(11) << wellProd[WellProdDataType::WaterRate] << ":" << std::setw(11)<< wellProd[WellProdDataType::GasRate] << ":" << std::setw(11) << wellProd[WellProdDataType::FluidResVol] << std::setprecision(3) << ":" << std::setw(11) << wellProd[WellProdDataType::WaterCut] << std::setprecision(2) << ":" << std::setw(10) << wellProd[WellProdDataType::GasOilRatio] << std::setprecision(4) << ":" << std::setw(12) << wellProd[WellProdDataType::WatGasRatio] << std::setprecision(1) << ":" << std::setw(8) << wellProd[WellProdDataType::BHP] << ":" << std::setw(8) << wellProd[WellProdDataType::THP] << ": \n"; ss << std::right << std::fixed << ":" << std::setw (8) << wellProdNames[WellProdDataType::WellName] << ":" << std::setprecision(0) << std::setw(5) << wellProd[WellProdDataType::WellLocationi] << "," << std::setw(5) << wellProd[WellProdDataType::WellLocationj] << ":" << std::setw(4) << wellProdNames[WellProdDataType::CTRLMode] << ":" << std::setprecision(1) << std::setw(11) << wellProd[WellProdDataType::OilRate] << ":" << std::setw(11) << wellProd[WellProdDataType::WaterRate] << ":" << std::setw(11)<< wellProd[WellProdDataType::GasRate] << ":" << std::setw(11) << wellProd[WellProdDataType::FluidResVol] << std::setprecision(3) << ":" << std::setw(11) << wellProd[WellProdDataType::WaterCut] << std::setprecision(2) << ":" << std::setw(10) << wellProd[WellProdDataType::GasOilRatio] << std::setprecision(4) << ":" << std::setw(12) << wellProd[WellProdDataType::WatGasRatio] << std::setprecision(1) << ":" << std::setw(8) << wellProd[WellProdDataType::BHP] << ":" << std::setw(8) << wellProd[WellProdDataType::THP] << ": \n";
} }
ss << ":"<< std::setfill ('-') << std::setw (9) << ":" << std::setfill ('-') << std::setw (12) << ":" << std::setfill ('-') << std::setw (5) << ":" << std::setfill ('-') << std::setw (12) << ":" << std::setfill ('-') << std::setw (12) << ":" << std::setfill ('-') << std::setw (12) << ":" << std::setfill ('-') << std::setw (12) << ":" << std::setfill ('-') << std::setw (12) << ":" << std::setfill ('-') << std::setw (11) << ":" << std::setfill ('-') << std::setw (13) << ":" << std::setfill ('-') << std::setw (9) << ":" << std::setfill ('-') << std::setw (9) << ":" << "\n"; ss << ":"<< std::setfill ('-') << std::setw (9) << ":" << std::setfill ('-') << std::setw (12) << ":" << std::setfill ('-') << std::setw (5) << ":" << std::setfill ('-') << std::setw (12) << ":" << std::setfill ('-') << std::setw (12) << ":" << std::setfill ('-') << std::setw (12) << ":" << std::setfill ('-') << std::setw (12) << ":" << std::setfill ('-') << std::setw (12) << ":" << std::setfill ('-') << std::setw (11) << ":" << std::setfill ('-') << std::setw (13) << ":" << std::setfill ('-') << std::setw (9) << ":" << std::setfill ('-') << std::setw (9) << ":" << "\n";
} }
OpmLog::note(ss.str()); OpmLog::note(ss.str());