Loading...
Searching...
No Matches
pvsnewtonmethod.hh
Go to the documentation of this file.
// -*- 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.
*/
#ifndef EWOMS_PVS_NEWTON_METHOD_HH
#define EWOMS_PVS_NEWTON_METHOD_HH
#include <opm/models/common/multiphasebaseproperties.hh>
#include <opm/models/nonlinear/newtonmethod.hh>
#include <algorithm>
#include <cmath>
namespace Opm::Properties {
template <class TypeTag, class MyTypeTag>
struct DiscNewtonMethod;
} // namespace Opm::Properties
namespace Opm {
template <class TypeTag>
class PvsNewtonMethod : public GetPropType<TypeTag, Properties::DiscNewtonMethod>
{
using ParentType = GetPropType<TypeTag, Properties::DiscNewtonMethod>;
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
using SolutionVector = GetPropType<TypeTag, Properties::SolutionVector>;
using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
using EqVector = GetPropType<TypeTag, Properties::EqVector>;
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
using Indices = GetPropType<TypeTag, Properties::Indices>;
using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
enum { numPhases = FluidSystem::numPhases };
// primary variable indices
enum { pressure0Idx = Indices::pressure0Idx };
enum { switch0Idx = Indices::switch0Idx };
public:
explicit PvsNewtonMethod(Simulator& simulator) : ParentType(simulator)
{}
protected:
friend NewtonMethod<TypeTag>;
friend ParentType;
void updatePrimaryVariables_(unsigned,
PrimaryVariables& nextValue,
const PrimaryVariables& currentValue,
const EqVector& update,
const EqVector&)
{
// normal Newton-Raphson update
nextValue = currentValue;
nextValue -= update;
// put crash barriers along the update path
// saturations: limit the change of any saturation to at most 20%
Scalar sumSatDelta = 0.0;
Scalar maxSatDelta = 0.0;
for (unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx) {
if (!currentValue.phaseIsPresent(phaseIdx)) {
continue;
}
maxSatDelta = std::max(std::abs(update[switch0Idx + phaseIdx]),
maxSatDelta);
sumSatDelta += update[switch0Idx + phaseIdx];
}
maxSatDelta = std::max(std::abs(-sumSatDelta), maxSatDelta);
if (maxSatDelta > 0.2) {
const Scalar alpha = 0.2 / maxSatDelta;
for (unsigned phaseIdx = 0; phaseIdx < numPhases - 1; ++phaseIdx) {
if (!currentValue.phaseIsPresent(phaseIdx)) {
continue;
}
nextValue[switch0Idx + phaseIdx] =
currentValue[switch0Idx + phaseIdx] -
alpha * update[switch0Idx + phaseIdx];
}
}
// limit pressure reference change to 20% of the total value per iteration
nextValue[pressure0Idx] = std::clamp(nextValue[pressure0Idx],
currentValue[pressure0Idx] * 0.8,
currentValue[pressure0Idx] * 1.2);
}
void endIteration_(SolutionVector& uCurrentIter,
const SolutionVector& uLastIter)
{
ParentType::endIteration_(uCurrentIter, uLastIter);
this->problem().model().switchPrimaryVars_();
}
};
} // namespace Opm
#endif
Opm::NewtonMethod
The multi-dimensional Newton method.
Definition newtonmethod.hh:100
Opm::PvsNewtonMethod::updatePrimaryVariables_
void updatePrimaryVariables_(unsigned, PrimaryVariables &nextValue, const PrimaryVariables &currentValue, const EqVector &update, const EqVector &)
Update a single primary variables object.
Definition pvsnewtonmethod.hh:81
Opm::PvsNewtonMethod::endIteration_
void endIteration_(SolutionVector &uCurrentIter, const SolutionVector &uLastIter)
Indicates that one Newton iteration was finished.
Definition pvsnewtonmethod.hh:133
multiphasebaseproperties.hh
Defines the common properties required by the porous medium multi-phase models.
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::GetPropType
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition propertysystem.hh:233
newtonmethod.hh
The multi-dimensional Newton method.
Opm::Properties::DiscNewtonMethod
The discretization specific part of he implementing the Newton algorithm.
Definition fvbasenewtonmethod.hh:55