diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index d36d4a929..bf369a71c 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -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 diff --git a/opm/models/blackoil/blackoilnewtonmethod.hpp b/opm/models/blackoil/blackoilnewtonmethod.hpp index a418064c8..124540f29 100644 --- a/opm/models/blackoil/blackoilnewtonmethod.hpp +++ b/opm/models/blackoil/blackoilnewtonmethod.hpp @@ -73,17 +73,7 @@ class BlackOilNewtonMethod : public GetPropType>(); - dpMaxRel_ = Parameters::Get>(); - dsMax_ = Parameters::Get>(); - projectSaturations_ = Parameters::Get(); - maxTempChange_ = Parameters::Get>(); - tempMax_ = Parameters::Get>(); - tempMin_ = Parameters::Get>(); - pressMax_ = Parameters::Get>(); - pressMin_ = Parameters::Get>(); - waterSaturationMax_ = Parameters::Get>(); - waterOnlyThreshold_ = Parameters::Get>(); + bparams_.read(); } /*! @@ -102,30 +92,7 @@ public: static void registerParameters() { ParentType::registerParameters(); - - Parameters::Register> - ("Maximum relative change of pressure in a single iteration"); - Parameters::Register> - ("Maximum absolute change of any saturation in a single iteration"); - Parameters::Register> - ("The threshold value for the primary variable switching conditions " - "after its meaning has switched to hinder oscilations"); - Parameters::Register - ("Option for doing saturation projection"); - Parameters::Register> - ("Maximum absolute change of temperature in a single iteration"); - Parameters::Register> - ("Maximum absolute temperature"); - Parameters::Register> - ("Minimum absolute temperature"); - Parameters::Register> - ("Maximum absolute pressure"); - Parameters::Register> - ("Minimum absolute pressure"); - Parameters::Register> - ("Maximum water saturation"); - Parameters::Register> - ("Cells with water saturation above or equal is considered one-phase water only"); + BlackoilNewtonParams::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 bparams_{}; // keep track of cells where the primary variable meaning has changed // to detect and hinder oscillations - std::vector wasSwitched_; + std::vector wasSwitched_{}; }; } // namespace Opm diff --git a/opm/models/blackoil/blackoilnewtonmethodparameters.cpp b/opm/models/blackoil/blackoilnewtonmethodparameters.cpp new file mode 100644 index 000000000..444ec900f --- /dev/null +++ b/opm/models/blackoil/blackoilnewtonmethodparameters.cpp @@ -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 . + + 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 +#include + +#include + +namespace Opm { + +template +void BlackoilNewtonParams::registerParameters() +{ + Parameters::Register> + ("Maximum relative change of pressure in a single iteration"); + Parameters::Register> + ("Maximum absolute change of any saturation in a single iteration"); + Parameters::Register> + ("The threshold value for the primary variable switching conditions " + "after its meaning has switched to hinder oscillations"); + Parameters::Register + ("Option for doing saturation projection"); + Parameters::Register> + ("Maximum absolute change of temperature in a single iteration"); + Parameters::Register> + ("Maximum absolute temperature"); + Parameters::Register> + ("Minimum absolute temperature"); + Parameters::Register> + ("Maximum absolute pressure"); + Parameters::Register> + ("Minimum absolute pressure"); + Parameters::Register> + ("Maximum water saturation"); + Parameters::Register> + ("Cells with water saturation above or equal is considered one-phase water only"); +} + +template +void BlackoilNewtonParams::read() +{ + priVarOscilationThreshold_ = Parameters::Get>(); + dpMaxRel_ = Parameters::Get>(); + dsMax_ = Parameters::Get>(); + projectSaturations_ = Parameters::Get(); + maxTempChange_ = Parameters::Get>(); + tempMax_ = Parameters::Get>(); + tempMin_ = Parameters::Get>(); + pressMax_ = Parameters::Get>(); + pressMin_ = Parameters::Get>(); + waterSaturationMax_ = Parameters::Get>(); + waterOnlyThreshold_ = Parameters::Get>(); +} + +template struct BlackoilNewtonParams; + +#if FLOW_INSTANTIATE_FLOAT +template struct BlackoilNewtonParams; +#endif + +} // namespace Opm diff --git a/opm/models/blackoil/blackoilnewtonmethodparameters.hpp b/opm/models/blackoil/blackoilnewtonmethodparameters.hpp index 689708334..7289e98a4 100644 --- a/opm/models/blackoil/blackoilnewtonmethodparameters.hpp +++ b/opm/models/blackoil/blackoilnewtonmethodparameters.hpp @@ -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 +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