mirror of
https://github.com/OPM/opm-simulators.git
synced 2026-08-09 14:28:04 -05:00
BlackoilNewtonMethod: add struct holding parameters and put in blackoilnewthonmethodparameters.cpp
This commit is contained in:
@@ -59,6 +59,7 @@ list (APPEND MAIN_SOURCE_FILES
|
||||
opm/models/blackoil/blackoilextboparams.cpp
|
||||
opm/models/blackoil/blackoilfoamparams.cpp
|
||||
opm/models/blackoil/blackoilmicpparams.cpp
|
||||
opm/models/blackoil/blackoilnewtonmethodparameters.cpp
|
||||
opm/models/blackoil/blackoilpolymerparams.cpp
|
||||
opm/models/blackoil/blackoilsolventparams.cpp
|
||||
opm/models/io/restart.cpp
|
||||
|
||||
@@ -73,17 +73,7 @@ class BlackOilNewtonMethod : public GetPropType<TypeTag, Properties::DiscNewtonM
|
||||
public:
|
||||
BlackOilNewtonMethod(Simulator& simulator) : ParentType(simulator)
|
||||
{
|
||||
priVarOscilationThreshold_ = Parameters::Get<Parameters::PriVarOscilationThreshold<Scalar>>();
|
||||
dpMaxRel_ = Parameters::Get<Parameters::DpMaxRel<Scalar>>();
|
||||
dsMax_ = Parameters::Get<Parameters::DsMax<Scalar>>();
|
||||
projectSaturations_ = Parameters::Get<Parameters::ProjectSaturations>();
|
||||
maxTempChange_ = Parameters::Get<Parameters::MaxTemperatureChange<Scalar>>();
|
||||
tempMax_ = Parameters::Get<Parameters::TemperatureMax<Scalar>>();
|
||||
tempMin_ = Parameters::Get<Parameters::TemperatureMin<Scalar>>();
|
||||
pressMax_ = Parameters::Get<Parameters::PressureMax<Scalar>>();
|
||||
pressMin_ = Parameters::Get<Parameters::PressureMin<Scalar>>();
|
||||
waterSaturationMax_ = Parameters::Get<Parameters::MaximumWaterSaturation<Scalar>>();
|
||||
waterOnlyThreshold_ = Parameters::Get<Parameters::WaterOnlyThreshold<Scalar>>();
|
||||
bparams_.read();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -102,30 +92,7 @@ public:
|
||||
static void registerParameters()
|
||||
{
|
||||
ParentType::registerParameters();
|
||||
|
||||
Parameters::Register<Parameters::DpMaxRel<Scalar>>
|
||||
("Maximum relative change of pressure in a single iteration");
|
||||
Parameters::Register<Parameters::DsMax<Scalar>>
|
||||
("Maximum absolute change of any saturation in a single iteration");
|
||||
Parameters::Register<Parameters::PriVarOscilationThreshold<Scalar>>
|
||||
("The threshold value for the primary variable switching conditions "
|
||||
"after its meaning has switched to hinder oscilations");
|
||||
Parameters::Register<Parameters::ProjectSaturations>
|
||||
("Option for doing saturation projection");
|
||||
Parameters::Register<Parameters::MaxTemperatureChange<Scalar>>
|
||||
("Maximum absolute change of temperature in a single iteration");
|
||||
Parameters::Register<Parameters::TemperatureMax<Scalar>>
|
||||
("Maximum absolute temperature");
|
||||
Parameters::Register<Parameters::TemperatureMin<Scalar>>
|
||||
("Minimum absolute temperature");
|
||||
Parameters::Register<Parameters::PressureMax<Scalar>>
|
||||
("Maximum absolute pressure");
|
||||
Parameters::Register<Parameters::PressureMin<Scalar>>
|
||||
("Minimum absolute pressure");
|
||||
Parameters::Register<Parameters::MaximumWaterSaturation<Scalar>>
|
||||
("Maximum water saturation");
|
||||
Parameters::Register<Parameters::WaterOnlyThreshold<Scalar>>
|
||||
("Cells with water saturation above or equal is considered one-phase water only");
|
||||
BlackoilNewtonParams<Scalar>::registerParameters();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -272,8 +239,9 @@ protected:
|
||||
// scaling factor for saturation deltas to make sure that none of them exceeds
|
||||
// the specified threshold value.
|
||||
Scalar satAlpha = 1.0;
|
||||
if (maxSatDelta > dsMax_)
|
||||
satAlpha = dsMax_/maxSatDelta;
|
||||
if (maxSatDelta > bparams_.dsMax_) {
|
||||
satAlpha = bparams_.dsMax_ / maxSatDelta;
|
||||
}
|
||||
|
||||
for (int pvIdx = 0; pvIdx < int(numEq); ++pvIdx) {
|
||||
// calculate the update of the current primary variable. For the black-oil
|
||||
@@ -286,8 +254,8 @@ protected:
|
||||
|
||||
// limit pressure delta
|
||||
if (pvIdx == Indices::pressureSwitchIdx) {
|
||||
if (std::abs(delta) > params_.dpMaxRel_ * currentValue[pvIdx]) {
|
||||
delta = signum(delta) * params_.dpMaxRel_ * currentValue[pvIdx];
|
||||
if (std::abs(delta) > bparams_.dpMaxRel_ * currentValue[pvIdx]) {
|
||||
delta = signum(delta) * bparams_.dpMaxRel_ * currentValue[pvIdx];
|
||||
}
|
||||
}
|
||||
// water saturation delta
|
||||
@@ -341,7 +309,7 @@ protected:
|
||||
}
|
||||
else if (enableEnergy && pvIdx == Indices::temperatureIdx) {
|
||||
const double sign = delta >= 0. ? 1. : -1.;
|
||||
delta = sign * std::min(std::abs(delta), maxTempChange_);
|
||||
delta = sign * std::min(std::abs(delta), bparams_.maxTempChange_);
|
||||
}
|
||||
else if (enableBrine && pvIdx == Indices::saltConcentrationIdx &&
|
||||
enableSaltPrecipitation &&
|
||||
@@ -396,11 +364,12 @@ protected:
|
||||
}
|
||||
|
||||
// keep the temperature within given values
|
||||
if (enableEnergy && pvIdx == Indices::temperatureIdx)
|
||||
nextValue[pvIdx] = std::clamp(nextValue[pvIdx], tempMin_, tempMax_);
|
||||
if (enableEnergy && pvIdx == Indices::temperatureIdx) {
|
||||
nextValue[pvIdx] = std::clamp(nextValue[pvIdx], bparams_.tempMin_, bparams_.tempMax_);
|
||||
}
|
||||
|
||||
if (pvIdx == Indices::pressureSwitchIdx) {
|
||||
nextValue[pvIdx] = std::clamp(nextValue[pvIdx], pressMin_, pressMax_);
|
||||
nextValue[pvIdx] = std::clamp(nextValue[pvIdx], bparams_.pressMin_, bparams_.pressMax_);
|
||||
}
|
||||
|
||||
|
||||
@@ -429,14 +398,24 @@ protected:
|
||||
// switch the new primary variables to something which is physically meaningful.
|
||||
// use a threshold value after a switch to make it harder to switch back
|
||||
// immediately.
|
||||
if (wasSwitched_[globalDofIdx])
|
||||
wasSwitched_[globalDofIdx] = nextValue.adaptPrimaryVariables(this->problem(), globalDofIdx, waterSaturationMax_, waterOnlyThreshold_, priVarOscilationThreshold_);
|
||||
else
|
||||
wasSwitched_[globalDofIdx] = nextValue.adaptPrimaryVariables(this->problem(), globalDofIdx, waterSaturationMax_, waterOnlyThreshold_);
|
||||
if (wasSwitched_[globalDofIdx]) {
|
||||
wasSwitched_[globalDofIdx] = nextValue.adaptPrimaryVariables(this->problem(),
|
||||
globalDofIdx,
|
||||
bparams_.waterSaturationMax_,
|
||||
bparams_.waterOnlyThreshold_,
|
||||
bparams_.priVarOscilationThreshold_);
|
||||
}
|
||||
else {
|
||||
wasSwitched_[globalDofIdx] = nextValue.adaptPrimaryVariables(this->problem(),
|
||||
globalDofIdx,
|
||||
bparams_.waterSaturationMax_,
|
||||
bparams_.waterOnlyThreshold_);
|
||||
}
|
||||
|
||||
if (wasSwitched_[globalDofIdx])
|
||||
++ numPriVarsSwitched_;
|
||||
if(projectSaturations_){
|
||||
if (wasSwitched_[globalDofIdx]) {
|
||||
++numPriVarsSwitched_;
|
||||
}
|
||||
if (bparams_.projectSaturations_) {
|
||||
nextValue.chopAndNormalizeSaturations();
|
||||
}
|
||||
|
||||
@@ -444,24 +423,13 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
int numPriVarsSwitched_;
|
||||
int numPriVarsSwitched_{};
|
||||
|
||||
Scalar priVarOscilationThreshold_;
|
||||
Scalar waterSaturationMax_;
|
||||
Scalar waterOnlyThreshold_;
|
||||
|
||||
Scalar dpMaxRel_;
|
||||
Scalar dsMax_;
|
||||
bool projectSaturations_;
|
||||
Scalar maxTempChange_;
|
||||
Scalar tempMax_;
|
||||
Scalar tempMin_;
|
||||
Scalar pressMax_;
|
||||
Scalar pressMin_;
|
||||
BlackoilNewtonParams<Scalar> bparams_{};
|
||||
|
||||
// keep track of cells where the primary variable meaning has changed
|
||||
// to detect and hinder oscillations
|
||||
std::vector<bool> wasSwitched_;
|
||||
std::vector<bool> wasSwitched_{};
|
||||
};
|
||||
|
||||
} // namespace Opm
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
// vi: set et ts=4 sw=4 sts=4:
|
||||
/*
|
||||
This file is part of the Open Porous Media project (OPM).
|
||||
|
||||
OPM is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OPM is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Consult the COPYING file in the top-level source directory of this
|
||||
module for the precise wording of the license and the list of
|
||||
copyright holders.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <opm/models/blackoil/blackoilnewtonmethodparameters.hpp>
|
||||
|
||||
#include <opm/models/utils/parametersystem.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
template<class Scalar>
|
||||
void BlackoilNewtonParams<Scalar>::registerParameters()
|
||||
{
|
||||
Parameters::Register<Parameters::DpMaxRel<Scalar>>
|
||||
("Maximum relative change of pressure in a single iteration");
|
||||
Parameters::Register<Parameters::DsMax<Scalar>>
|
||||
("Maximum absolute change of any saturation in a single iteration");
|
||||
Parameters::Register<Parameters::PriVarOscilationThreshold<Scalar>>
|
||||
("The threshold value for the primary variable switching conditions "
|
||||
"after its meaning has switched to hinder oscillations");
|
||||
Parameters::Register<Parameters::ProjectSaturations>
|
||||
("Option for doing saturation projection");
|
||||
Parameters::Register<Parameters::MaxTemperatureChange<Scalar>>
|
||||
("Maximum absolute change of temperature in a single iteration");
|
||||
Parameters::Register<Parameters::TemperatureMax<Scalar>>
|
||||
("Maximum absolute temperature");
|
||||
Parameters::Register<Parameters::TemperatureMin<Scalar>>
|
||||
("Minimum absolute temperature");
|
||||
Parameters::Register<Parameters::PressureMax<Scalar>>
|
||||
("Maximum absolute pressure");
|
||||
Parameters::Register<Parameters::PressureMin<Scalar>>
|
||||
("Minimum absolute pressure");
|
||||
Parameters::Register<Parameters::MaximumWaterSaturation<Scalar>>
|
||||
("Maximum water saturation");
|
||||
Parameters::Register<Parameters::WaterOnlyThreshold<Scalar>>
|
||||
("Cells with water saturation above or equal is considered one-phase water only");
|
||||
}
|
||||
|
||||
template<class Scalar>
|
||||
void BlackoilNewtonParams<Scalar>::read()
|
||||
{
|
||||
priVarOscilationThreshold_ = Parameters::Get<Parameters::PriVarOscilationThreshold<Scalar>>();
|
||||
dpMaxRel_ = Parameters::Get<Parameters::DpMaxRel<Scalar>>();
|
||||
dsMax_ = Parameters::Get<Parameters::DsMax<Scalar>>();
|
||||
projectSaturations_ = Parameters::Get<Parameters::ProjectSaturations>();
|
||||
maxTempChange_ = Parameters::Get<Parameters::MaxTemperatureChange<Scalar>>();
|
||||
tempMax_ = Parameters::Get<Parameters::TemperatureMax<Scalar>>();
|
||||
tempMin_ = Parameters::Get<Parameters::TemperatureMin<Scalar>>();
|
||||
pressMax_ = Parameters::Get<Parameters::PressureMax<Scalar>>();
|
||||
pressMin_ = Parameters::Get<Parameters::PressureMin<Scalar>>();
|
||||
waterSaturationMax_ = Parameters::Get<Parameters::MaximumWaterSaturation<Scalar>>();
|
||||
waterOnlyThreshold_ = Parameters::Get<Parameters::WaterOnlyThreshold<Scalar>>();
|
||||
}
|
||||
|
||||
template struct BlackoilNewtonParams<double>;
|
||||
|
||||
#if FLOW_INSTANTIATE_FLOAT
|
||||
template struct BlackoilNewtonParams<float>;
|
||||
#endif
|
||||
|
||||
} // namespace Opm
|
||||
@@ -64,4 +64,34 @@ struct WaterOnlyThreshold { static constexpr Scalar value = 1.0; };
|
||||
|
||||
} // namespace Opm::Parameters
|
||||
|
||||
namespace Opm {
|
||||
|
||||
/*!
|
||||
* \brief Struct holding the parameters for BlackoilNewtonMethod.
|
||||
*/
|
||||
template<class Scalar>
|
||||
struct BlackoilNewtonParams
|
||||
{
|
||||
//! \brief Registers the parameters in parameter system.
|
||||
static void registerParameters();
|
||||
|
||||
//! \brief Reads the parameter values from the parameter system.
|
||||
void read();
|
||||
|
||||
Scalar priVarOscilationThreshold_;
|
||||
Scalar waterSaturationMax_;
|
||||
Scalar waterOnlyThreshold_;
|
||||
|
||||
Scalar dpMaxRel_;
|
||||
Scalar dsMax_;
|
||||
bool projectSaturations_;
|
||||
Scalar maxTempChange_;
|
||||
Scalar tempMax_;
|
||||
Scalar tempMin_;
|
||||
Scalar pressMax_;
|
||||
Scalar pressMin_;
|
||||
};
|
||||
|
||||
} // namespace Opm
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user