NonlinearSystem.hpp
Go to the documentation of this file.
1#ifndef OPM_FLOW_NONLINEAR_SYSTEM_HEADER_INCLUDED
2#define OPM_FLOW_NONLINEAR_SYSTEM_HEADER_INCLUDED
3/*
4 Copyright 2026, SINTEF Digital
5
6 This file is part of the Open Porous Media project (OPM).
7
8 OPM is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 OPM is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with OPM. If not, see <http://www.gnu.org/licenses/>.
20*/
21#include <cstddef>
22
23#include <opm/input/eclipse/Schedule/Tuning.hpp>
24
26
35#include <span>
36#include <string_view>
37#include <tuple>
38#include <vector>
39
40namespace Opm {
41
42template <class TypeTag>
44{
45public:
46 // --------- Types ---------
56
57 // --------- Public methods ---------
58 virtual ~NonlinearSystem() = default;
59
60 bool isParallel() const
61 { return grid_.comm().size() > 1; }
62
63 const Simulator& simulator() const
64 { return simulator_; }
65
67 { return simulator_; }
68
70 { return terminal_output_; }
71
72 int numPhases() const
73 { return Indices::numPhases; }
74
76 { return failureReport_; }
77
78 const std::vector<StepReport>& stepReports() const
79 { return convergence_reports_; }
80
81 const ComponentName& compNames() const
82 { return compNames_; }
83
84 const ModelParameters& param() const
85 { return param_; }
86
88 { return well_model_; }
89
90 const WellModel& wellModel() const
91 { return well_model_; }
92
94 { simulator_.problem().beginEpisode(); }
95
97 { simulator_.problem().endEpisode(); }
98
100
101 void updateTUNING(const Tuning& tuning);
102
103 void updateTUNINGDP(const TuningDp& tuning_dp);
104
105 void updateSolution(const GlobalEqVector& dx);
106
107 template <class LogFailure>
109 const int componentIdx,
110 const std::string_view componentName,
111 const std::span<const Scalar> residuals,
112 const std::span<const ConvergenceReport::ReservoirFailure::Type> types,
113 const std::span<const Scalar> tolerances,
114 const Scalar maxResidualAllowed,
115 LogFailure&& logFailure) const;
116
117protected:
119 const ModelParameters& param,
121 const bool terminal_output);
122
123 virtual void initialLinearization(SimulatorReportSingle& report,
124 int minIter,
125 int maxIter,
126 const SimulatorTimerInterface& timer);
127
128 virtual bool shouldStoreSolutionUpdate() const
129 { return false; }
130
132 {}
133
135 {}
136
138
139 template <class WellModelType>
141
142 template <class ModelParametersType>
143 void applyTUNING(ModelParametersType& param,
144 const Tuning& tuning);
145
146 template <class ModelParametersType>
147 void applyTUNINGDP(ModelParametersType& param,
148 const TuningDp& tuning_dp);
149
150 template <class ValueType>
151 std::tuple<ValueType, ValueType>
153 const ValueType primaryVolumeLocal,
154 const ValueType secondaryVolumeLocal,
155 std::vector<ValueType>& sumValues,
156 std::vector<ValueType>& maxValues,
157 std::vector<ValueType>& averagedValues);
158
160 { convergence_reports_.back().report.pop_back(); }
161
162 // --------- Data members ---------
164 const Grid& grid_;
169 std::vector<StepReport> convergence_reports_;
171 std::vector<std::vector<Scalar>> residual_norms_history_;
174};
175
176} // namespace Opm
177
179
180#endif // OPM_FLOW_NONLINEAR_SYSTEM_HEADER_INCLUDED
Definition: ComponentName.hpp:34
Definition: ConvergenceReport.hpp:38
Definition: NonlinearSystem.hpp:44
bool terminal_output_
Definition: NonlinearSystem.hpp:165
void updateTUNINGDP(const TuningDp &tuning_dp)
Definition: NonlinearSystem_impl.hpp:57
void applyTUNINGDP(ModelParametersType &param, const TuningDp &tuning_dp)
Definition: NonlinearSystem_impl.hpp:244
virtual ~NonlinearSystem()=default
const SimulatorReportSingle & failureReport() const
Definition: NonlinearSystem.hpp:75
const ComponentName & compNames() const
Definition: NonlinearSystem.hpp:81
const Simulator & simulator() const
Definition: NonlinearSystem.hpp:63
std::tuple< ValueType, ValueType > convergenceReduction(Parallel::Communication comm, const ValueType primaryVolumeLocal, const ValueType secondaryVolumeLocal, std::vector< ValueType > &sumValues, std::vector< ValueType > &maxValues, std::vector< ValueType > &averagedValues)
Definition: NonlinearSystem_impl.hpp:257
WellModel & well_model_
Definition: NonlinearSystem.hpp:167
void updateSolution(const GlobalEqVector &dx)
Definition: NonlinearSystem_impl.hpp:65
ComponentName compNames_
Definition: NonlinearSystem.hpp:170
WellModel & wellModel()
Definition: NonlinearSystem.hpp:87
const std::vector< StepReport > & stepReports() const
Definition: NonlinearSystem.hpp:78
Simulator & simulator()
Definition: NonlinearSystem.hpp:66
virtual void prepareSolutionUpdate()
Definition: NonlinearSystem.hpp:131
BlackoilModelParameters< Scalar > ModelParameters
Definition: NonlinearSystem.hpp:53
const Grid & grid_
Definition: NonlinearSystem.hpp:164
void popLastStepReport()
Definition: NonlinearSystem.hpp:159
std::vector< StepReport > convergence_reports_
Definition: NonlinearSystem.hpp:169
const ModelParameters & param() const
Definition: NonlinearSystem.hpp:84
int numPhases() const
Definition: NonlinearSystem.hpp:72
void addReservoirConvergenceMetrics(ConvergenceReport &report, const int componentIdx, const std::string_view componentName, const std::span< const Scalar > residuals, const std::span< const ConvergenceReport::ReservoirFailure::Type > types, const std::span< const Scalar > tolerances, const Scalar maxResidualAllowed, LogFailure &&logFailure) const
Definition: NonlinearSystem_impl.hpp:96
const WellModel & wellModel() const
Definition: NonlinearSystem.hpp:90
GetPropType< TypeTag, Properties::FluidSystem > FluidSystem
Definition: NonlinearSystem.hpp:49
GetPropType< TypeTag, Properties::Scalar > Scalar
Definition: NonlinearSystem.hpp:51
SimulatorReportSingle failureReport_
Definition: NonlinearSystem.hpp:168
virtual bool shouldStoreSolutionUpdate() const
Definition: NonlinearSystem.hpp:128
void endReportStep()
Definition: NonlinearSystem.hpp:96
virtual void initialLinearization(SimulatorReportSingle &report, int minIter, int maxIter, const SimulatorTimerInterface &timer)
Definition: NonlinearSystem_impl.hpp:153
bool isParallel() const
Definition: NonlinearSystem.hpp:60
GetPropType< TypeTag, Properties::Grid > Grid
Definition: NonlinearSystem.hpp:48
void beginReportStep()
Definition: NonlinearSystem.hpp:93
ModelParameters param_
Definition: NonlinearSystem.hpp:166
void updateTUNING(const Tuning &tuning)
Definition: NonlinearSystem_impl.hpp:49
Simulator & simulator_
Definition: NonlinearSystem.hpp:163
GetPropType< TypeTag, Properties::Simulator > Simulator
Definition: NonlinearSystem.hpp:47
void applyTUNING(ModelParametersType &param, const Tuning &tuning)
Definition: NonlinearSystem_impl.hpp:229
GetPropType< TypeTag, Properties::GlobalEqVector > GlobalEqVector
Definition: NonlinearSystem.hpp:52
bool terminalOutputEnabled() const
Definition: NonlinearSystem.hpp:69
SimulatorReportSingle prepareStep(const SimulatorTimerInterface &timer)
Definition: NonlinearSystem_impl.hpp:182
GetPropType< TypeTag, Properties::Indices > Indices
Definition: NonlinearSystem.hpp:50
std::vector< std::vector< Scalar > > residual_norms_history_
Definition: NonlinearSystem.hpp:171
Scalar current_relaxation_
Definition: NonlinearSystem.hpp:172
GetPropType< TypeTag, Properties::WellModel > WellModel
Definition: NonlinearSystem.hpp:54
NonlinearSystem(Simulator &simulator, const ModelParameters &param, WellModel &wellModel, const bool terminal_output)
Definition: NonlinearSystem_impl.hpp:137
virtual void storeSolutionUpdate(const GlobalEqVector &)
Definition: NonlinearSystem.hpp:134
GlobalEqVector dx_old_
Definition: NonlinearSystem.hpp:173
SimulatorReportSingle assembleReservoir(const SimulatorTimerInterface &timer)
Definition: NonlinearSystem_impl.hpp:41
Manages the initializing and running of time dependent problems.
Definition: simulator.hh:84
Interface class for SimulatorTimer objects, to be improved.
Definition: SimulatorTimerInterface.hpp:34
Declares the properties required by the black oil model.
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilbioeffectsmodules.hh:45
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
The Opm property system, traits with inheritance.
Solver parameters for the NonlinearSystemBlackOilReservoir.
Definition: BlackoilModelParameters.hpp:201
A struct for returning timing data from a simulator to its caller.
Definition: SimulatorReport.hpp:34