Merge pull request #4311 from bska/publish-component-names

Capture Component Names in Independent Datastructure
This commit is contained in:
Bård Skaflestad 2022-12-09 10:13:42 +01:00 committed by GitHub
commit 1221936791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,13 +59,14 @@
#include <dune/common/timer.hh>
#include <dune/common/unused.hh>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <utility>
#include <vector>
#include <algorithm>
namespace Opm::Properties {
@ -202,6 +203,70 @@ namespace Opm {
typedef Dune::BlockVector<VectorBlockType> BVector;
typedef ISTLSolverEbos<TypeTag> ISTLSolverType;
class ComponentName
{
public:
ComponentName()
: names_(numEq)
{
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
if (!FluidSystem::phaseIsActive(phaseIdx)) {
continue;
}
const unsigned canonicalCompIdx = FluidSystem::solventComponentIndex(phaseIdx);
names_[Indices::canonicalToActiveComponentIndex(canonicalCompIdx)]
= FluidSystem::componentName(canonicalCompIdx);
}
if constexpr (has_solvent_) {
names_[solventSaturationIdx] = "Solvent";
}
if constexpr (has_extbo_) {
names_[zFractionIdx] = "ZFraction";
}
if constexpr (has_polymer_) {
names_[polymerConcentrationIdx] = "Polymer";
}
if constexpr (has_polymermw_) {
assert(has_polymer_);
names_[polymerMoleWeightIdx] = "MolecularWeightP";
}
if constexpr (has_energy_) {
names_[temperatureIdx] = "Energy";
}
if constexpr (has_foam_) {
names_[foamConcentrationIdx] = "Foam";
}
if constexpr (has_brine_) {
names_[saltConcentrationIdx] = "Brine";
}
if constexpr (has_micp_) {
names_[microbialConcentrationIdx] = "Microbes";
names_[oxygenConcentrationIdx] = "Oxygen";
names_[ureaConcentrationIdx] = "Urea";
names_[biofilmConcentrationIdx] = "Biofilm";
names_[calciteConcentrationIdx] = "Calcite";
}
}
const std::string& name(const int compIdx) const
{
return this->names_[compIdx];
}
private:
std::vector<std::string> names_{};
};
//typedef typename SolutionVector :: value_type PrimaryVariables ;
// --------- Public methods ---------
@ -861,49 +926,6 @@ namespace Opm {
residual_norms.push_back(CNV[compIdx]);
}
// Setup component names, only the first time the function is run.
static std::vector<std::string> compNames;
if (compNames.empty()) {
compNames.resize(numComp);
for (unsigned phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx) {
if (!FluidSystem::phaseIsActive(phaseIdx)) {
continue;
}
const unsigned canonicalCompIdx = FluidSystem::solventComponentIndex(phaseIdx);
const unsigned compIdx = Indices::canonicalToActiveComponentIndex(canonicalCompIdx);
compNames[compIdx] = FluidSystem::componentName(canonicalCompIdx);
}
if constexpr (has_solvent_) {
compNames[solventSaturationIdx] = "Solvent";
}
if constexpr (has_extbo_) {
compNames[zFractionIdx] = "ZFraction";
}
if constexpr (has_polymer_) {
compNames[polymerConcentrationIdx] = "Polymer";
}
if constexpr (has_polymermw_) {
assert(has_polymer_);
compNames[polymerMoleWeightIdx] = "MolecularWeightP";
}
if constexpr (has_energy_) {
compNames[temperatureIdx] = "Energy";
}
if constexpr (has_foam_) {
compNames[foamConcentrationIdx] = "Foam";
}
if constexpr (has_brine_) {
compNames[saltConcentrationIdx] = "Brine";
}
if constexpr (has_micp_) {
compNames[microbialConcentrationIdx] = "Microbes";
compNames[oxygenConcentrationIdx] = "Oxygen";
compNames[ureaConcentrationIdx] = "Urea";
compNames[biofilmConcentrationIdx] = "Biofilm";
compNames[calciteConcentrationIdx] = "Calcite";
}
}
// Create convergence report.
ConvergenceReport report;
using CR = ConvergenceReport;
@ -916,17 +938,17 @@ namespace Opm {
if (std::isnan(res[ii])) {
report.setReservoirFailed({types[ii], CR::Severity::NotANumber, compIdx});
if ( terminal_output_ ) {
OpmLog::debug("NaN residual for " + compNames[compIdx] + " equation.");
OpmLog::debug("NaN residual for " + this->compNames_.name(compIdx) + " equation.");
}
} else if (res[ii] > maxResidualAllowed()) {
report.setReservoirFailed({types[ii], CR::Severity::TooLarge, compIdx});
if ( terminal_output_ ) {
OpmLog::debug("Too large residual for " + compNames[compIdx] + " equation.");
OpmLog::debug("Too large residual for " + this->compNames_.name(compIdx) + " equation.");
}
} else if (res[ii] < 0.0) {
report.setReservoirFailed({types[ii], CR::Severity::Normal, compIdx});
if ( terminal_output_ ) {
OpmLog::debug("Negative residual for " + compNames[compIdx] + " equation.");
OpmLog::debug("Negative residual for " + this->compNames_.name(compIdx) + " equation.");
}
} else if (res[ii] > tol[ii]) {
report.setReservoirFailed({types[ii], CR::Severity::Normal, compIdx});
@ -942,12 +964,12 @@ namespace Opm {
std::string msg = "Iter";
for (int compIdx = 0; compIdx < numComp; ++compIdx) {
msg += " MB(";
msg += compNames[compIdx][0];
msg += this->compNames_.name(compIdx)[0];
msg += ") ";
}
for (int compIdx = 0; compIdx < numComp; ++compIdx) {
msg += " CNV(";
msg += compNames[compIdx][0];
msg += this->compNames_.name(compIdx)[0];
msg += ") ";
}
OpmLog::debug(msg);
@ -1065,6 +1087,8 @@ namespace Opm {
BVector dx_old_;
std::vector<StepReport> convergence_reports_;
ComponentName compNames_{};
public:
/// return the StandardWells object
BlackoilWellModel<TypeTag>&