20#ifndef OPM_NEWTON_ITERATION_CONTEXT_HPP
21#define OPM_NEWTON_ITERATION_CONTEXT_HPP
43struct NewtonIterationContext {
45 NewtonIterationContext() =
default;
54 return inLocalSolve_ ? localIteration_ : globalIteration_;
69 return !timestepInitialized_ && !inLocalSolve_;
76 return globalIteration_ == 0 && !inLocalSolve_;
83 return globalIteration_ < nupcol;
97 if (inLocalSolve_)
return false;
98 return globalIteration_ < maxIter;
106 timestepInitialized_ =
true;
124 globalIteration_ = 0;
126 timestepInitialized_ =
false;
127 inLocalSolve_ =
false;
134 return {globalIteration_, 0,
true,
true};
139 : globalIteration_(globalIter), localIteration_(localIter)
140 , inLocalSolve_(localSolve), timestepInitialized_(tsInit)
142 int globalIteration_ = 0;
143 int localIteration_ = 0;
144 bool inLocalSolve_ =
false;
145 bool timestepInitialized_ =
false;
151template<
class Problem>
152class LocalContextGuard {
154 LocalContextGuard(Problem& problem)
156 , saved_(problem.iterationContext())
158 problem_.mutableIterationContext() = saved_.forLocalSolve();
163 problem_.mutableIterationContext() = saved_;
166 LocalContextGuard(
const LocalContextGuard&) =
delete;
167 LocalContextGuard& operator=(
const LocalContextGuard&) =
delete;
168 LocalContextGuard(LocalContextGuard&&) =
delete;
169 LocalContextGuard& operator=(LocalContextGuard&&) =
delete;
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:45
Context for iteration-dependent decisions in the Newton solver.
Definition NewtonIterationContext.hpp:43
bool isFirstGlobalIteration() const
Is this the first iteration of the global solve (not a local solve)?
Definition NewtonIterationContext.hpp:74
void markTimestepInitialized()
State Mutations.
Definition NewtonIterationContext.hpp:104
bool inLocalSolve() const
Whether we are inside a domain-local solve (NLDD).
Definition NewtonIterationContext.hpp:58
void advanceIteration()
Advance the current iteration counter.
Definition NewtonIterationContext.hpp:112
NewtonIterationContext forLocalSolve() const
Create a context for a domain-local solve.
Definition NewtonIterationContext.hpp:132
bool withinNupcol(int nupcol) const
Are we within the NUPCOL iteration window?
Definition NewtonIterationContext.hpp:81
bool needsTimestepInit() const
Semantic Queries.
Definition NewtonIterationContext.hpp:67
bool timestepInitialized() const
Whether timestep initialization has been performed.
Definition NewtonIterationContext.hpp:61
int iteration() const
Getters.
Definition NewtonIterationContext.hpp:52
void resetForNewTimestep()
Reset all state for a new timestep.
Definition NewtonIterationContext.hpp:122
bool shouldRunInnerWellIterations(int maxIter) const
Whether inner well iterations should run.
Definition NewtonIterationContext.hpp:95
bool shouldRelax(int strictIterations) const
Should tolerances be relaxed based on iteration count?
Definition NewtonIterationContext.hpp:88