26 #ifndef EWOMS_FV_BASE_NEWTON_METHOD_HH
27 #define EWOMS_FV_BASE_NEWTON_METHOD_HH
36 template <
class TypeTag>
39 template <
class TypeTag>
44 namespace Properties {
99 template <
class TypeTag>
100 class FvBaseNewtonMethod :
public NewtonMethod<TypeTag>
103 typedef typename GET_PROP_TYPE(TypeTag,
NewtonMethod) Implementation;
105 typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
106 typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
107 typedef typename GET_PROP_TYPE(TypeTag, Model) Model;
108 typedef typename GET_PROP_TYPE(TypeTag, Linearizer) Linearizer;
110 typedef typename GET_PROP_TYPE(TypeTag, GlobalEqVector) GlobalEqVector;
111 typedef typename GET_PROP_TYPE(TypeTag, SolutionVector) SolutionVector;
112 typedef typename GET_PROP_TYPE(TypeTag, PrimaryVariables) PrimaryVariables;
113 typedef typename GET_PROP_TYPE(TypeTag, EqVector) EqVector;
118 : ParentType(simulator)
142 const SolutionVector ¤tSolution,
143 const GlobalEqVector &solutionUpdate,
144 const GlobalEqVector ¤tResidual)
147 auto& linearizer =
model.linearizer();
154 if (!std::isfinite(solutionUpdate.two_norm2()))
155 OPM_THROW(Opm::NumericalProblem,
"Non-finite update!");
157 Scalar relinearizationTol = 0.0;
160 if (enablePartialRelinearization_()) {
161 linearizer.updateRelinearizationErrors(solutionUpdate, currentResidual);
165 relinearizationTol = 1e-1*linearizer.maxDofError();
169 for (
unsigned i = 0; i < 6; ++i) {
170 unsigned numRelinearized = 0;
171 for (
unsigned dofIdx = 0; dofIdx <
model.numGridDof(); ++dofIdx) {
172 if (linearizer.dofError(dofIdx) > relinearizationTol)
176 if (numRelinearized*100 >=
model.numGridDof()*15)
179 relinearizationTol /= 10;
183 linearizer.setRelinearizationTolerance(relinearizationTol);
187 for (
unsigned dofIdx = 0; dofIdx <
model.numGridDof(); ++dofIdx) {
188 asImp_().updatePrimaryVariables_(dofIdx,
189 nextSolution[dofIdx],
190 currentSolution[dofIdx],
191 solutionUpdate[dofIdx],
192 currentResidual[dofIdx]);
193 model.setIntensiveQuantitiesCacheEntryValidity(dofIdx, 0,
false);
197 int nTotalDof =
model.numTotalDof();
198 for (
int dofIdx =
model.numGridDof(); dofIdx < nTotalDof; ++dofIdx) {
199 nextSolution[dofIdx] = currentSolution[dofIdx];
200 nextSolution[dofIdx] -= solutionUpdate[dofIdx];
221 model_().linearizer().relinearizeAll();
231 if (enableLinearizationRecycling_())
232 model_().linearizer().setLinearizationReusable(
true);
234 model_().linearizer().relinearizeAll();
250 Implementation &asImp_()
251 {
return *
static_cast<Implementation*
>(
this); }
253 const Implementation &asImp_()
const
254 {
return *
static_cast<const Implementation*
>(
this); }
260 bool enablePartialRelinearization_()
const
261 {
return EWOMS_GET_PARAM(TypeTag,
bool, EnablePartialRelinearization); }
267 bool enableLinearizationRecycling_()
const
268 {
return EWOMS_GET_PARAM(TypeTag,
bool, EnableLinearizationRecycling); }
void writeConvergence_(const SolutionVector ¤tSolution, const GlobalEqVector &solutionUpdate)
Write the convergence behaviour of the newton method to disk.
Definition: newtonmethod.hh:667
Model & model_()
Returns a reference to the model.
Definition: fvbasenewtonmethod.hh:240
void failed_()
Called if the Newton method broke down.
Definition: fvbasenewtonmethod.hh:217
void beginIteration_()
Indicates the beginning of a Newton iteration.
Definition: newtonmethod.hh:541
void beginIteration_()
Indicates the beginning of a Newton iteration.
Definition: fvbasenewtonmethod.hh:207
The multi-dimensional Newton method.
Definition: newtonmethod.hh:54
#define GET_PROP_TYPE(TypeTag, PropTagName)
Access the type attribute of a property for a type tag.
Definition: propertysystem.hh:485
void update_(SolutionVector &nextSolution, const SolutionVector ¤tSolution, const GlobalEqVector &solutionUpdate, const GlobalEqVector ¤tResidual)
Update the current solution with a delta vector.
Definition: fvbasenewtonmethod.hh:141
Model & model()
Returns a reference to the numeric model.
Definition: newtonmethod.hh:245
The multi-dimensional Newton method.
NEW_PROP_TAG(Grid)
The type of the DUNE grid.
SET_TYPE_PROP(NumericModel, Scalar, double)
Set the default type of scalar values to double.
Definition: baseauxiliarymodule.hh:35
void succeeded_()
Called if the Newton method was successful.
Definition: newtonmethod.hh:744
NewtonMethod(Simulator &simulator)
Definition: newtonmethod.hh:183
Writes the intermediate solutions during the Newton scheme for models using a finite volume discretiz...
Definition: fvbasenewtonconvergencewriter.hh:53
void failed_()
Called if the Newton method broke down.
Definition: newtonmethod.hh:736
Provides the magic behind the eWoms property system.
Writes the intermediate solutions during the Newton scheme for models using a finite volume discretiz...
const Model & model_() const
Returns a reference to the model.
Definition: fvbasenewtonmethod.hh:246
A Newton method for models using a finite volume discretization.
Definition: fvbasenewtonmethod.hh:37
#define INHERITS_FROM(...)
Syntactic sugar for NEW_TYPE_TAG.
Definition: propertysystem.hh:229
void succeeded_()
Called when the Newton method was successful.
Definition: fvbasenewtonmethod.hh:227
#define EWOMS_GET_PARAM(TypeTag, ParamType, ParamName)
Retrieve a runtime parameter.
Definition: parametersystem.hh:95