My Project
Loading...
Searching...
No Matches
BlackoilModel.hpp
1/*
2 Copyright 2013, 2015 SINTEF ICT, Applied Mathematics.
3 Copyright 2014, 2015 Dr. Blatt - HPC-Simulation-Software & Services
4 Copyright 2014, 2015 Statoil ASA.
5 Copyright 2015 NTNU
6 Copyright 2015, 2016, 2017 IRIS AS
7
8 This file is part of the Open Porous Media project (OPM).
9
10 OPM is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 OPM is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with OPM. If not, see <http://www.gnu.org/licenses/>.
22*/
23
24#ifndef OPM_BLACKOILMODEL_HEADER_INCLUDED
25#define OPM_BLACKOILMODEL_HEADER_INCLUDED
26
27#include <opm/simulators/aquifers/BlackoilAquiferModel.hpp>
28
29#include <opm/simulators/flow/BlackoilModelConvergenceMonitor.hpp>
30#include <opm/simulators/flow/BlackoilModelNldd.hpp>
31#include <opm/simulators/flow/BlackoilModelProperties.hpp>
33#include <opm/simulators/flow/RSTConv.hpp>
34
35#include <opm/simulators/linalg/ISTLSolver.hpp>
36
37#include <opm/simulators/timestepping/ConvergenceReport.hpp>
38#include <opm/simulators/timestepping/SimulatorReport.hpp>
39#include <opm/simulators/timestepping/SimulatorTimer.hpp>
40
41#include <opm/simulators/utils/BlackoilPhases.hpp>
42#include <opm/simulators/utils/ComponentName.hpp>
43
44#include <opm/simulators/wells/BlackoilWellModel.hpp>
45
46#include <memory>
47#include <tuple>
48#include <vector>
49
50#include <fmt/format.h>
51
52namespace Opm {
53
60template <class TypeTag>
62{
63public:
64 // --------- Types and enums ---------
78
79 static constexpr int numEq = Indices::numEq;
80 static constexpr int contiSolventEqIdx = Indices::contiSolventEqIdx;
81 static constexpr int contiZfracEqIdx = Indices::contiZfracEqIdx;
82 static constexpr int contiPolymerEqIdx = Indices::contiPolymerEqIdx;
83 static constexpr int contiEnergyEqIdx = Indices::contiEnergyEqIdx;
84 static constexpr int contiPolymerMWEqIdx = Indices::contiPolymerMWEqIdx;
85 static constexpr int contiFoamEqIdx = Indices::contiFoamEqIdx;
86 static constexpr int contiBrineEqIdx = Indices::contiBrineEqIdx;
87 static constexpr int contiMicrobialEqIdx = Indices::contiMicrobialEqIdx;
88 static constexpr int contiOxygenEqIdx = Indices::contiOxygenEqIdx;
89 static constexpr int contiUreaEqIdx = Indices::contiUreaEqIdx;
90 static constexpr int contiBiofilmEqIdx = Indices::contiBiofilmEqIdx;
91 static constexpr int contiCalciteEqIdx = Indices::contiCalciteEqIdx;
92 static constexpr int solventSaturationIdx = Indices::solventSaturationIdx;
93 static constexpr int zFractionIdx = Indices::zFractionIdx;
94 static constexpr int polymerConcentrationIdx = Indices::polymerConcentrationIdx;
95 static constexpr int polymerMoleWeightIdx = Indices::polymerMoleWeightIdx;
96 static constexpr int temperatureIdx = Indices::temperatureIdx;
97 static constexpr int foamConcentrationIdx = Indices::foamConcentrationIdx;
98 static constexpr int saltConcentrationIdx = Indices::saltConcentrationIdx;
99 static constexpr int microbialConcentrationIdx = Indices::microbialConcentrationIdx;
100 static constexpr int oxygenConcentrationIdx = Indices::oxygenConcentrationIdx;
101 static constexpr int ureaConcentrationIdx = Indices::ureaConcentrationIdx;
102 static constexpr int biofilmConcentrationIdx = Indices::biofilmConcentrationIdx;
103 static constexpr int calciteConcentrationIdx = Indices::calciteConcentrationIdx;
104
105 using VectorBlockType = Dune::FieldVector<Scalar, numEq>;
106 using MatrixBlockType = typename SparseMatrixAdapter::MatrixBlock;
107 using Mat = typename SparseMatrixAdapter::IstlMatrix;
108 using BVector = Dune::BlockVector<VectorBlockType>;
109
111
112 // --------- Public methods ---------
113
124 BlackoilModel(Simulator& simulator,
125 const ModelParameters& param,
127 const bool terminal_output);
128
129 bool isParallel() const
130 { return grid_.comm().size() > 1; }
131
132 const EclipseState& eclState() const
133 { return simulator_.vanguard().eclState(); }
134
138
139 void initialLinearization(SimulatorReportSingle& report,
140 const int iteration,
141 const int minIter,
142 const int maxIter,
143 const SimulatorTimerInterface& timer);
144
152 template <class NonlinearSolverType>
154 const SimulatorTimerInterface& timer,
156
157 template <class NonlinearSolverType>
158 SimulatorReportSingle nonlinearIterationNewton(const int iteration,
159 const SimulatorTimerInterface& timer,
161
166
169 const int iterationIdx);
170
171 // compute the "relative" change of the solution between time steps
172 Scalar relativeChange() const;
173
176 { return simulator_.model().newtonMethod().linearSolver().iterations (); }
177
178 // Obtain reference to linear solver setup time
179 double& linearSolveSetupTime()
180 { return linear_solve_setup_time_; }
181
184 void solveJacobianSystem(BVector& x);
185
187 void updateSolution(const BVector& dx);
188
191 { return terminal_output_; }
192
193 std::tuple<Scalar,Scalar>
194 convergenceReduction(Parallel::Communication comm,
195 const Scalar pvSumLocal,
196 const Scalar numAquiferPvSumLocal,
197 std::vector<Scalar>& R_sum,
198 std::vector<Scalar>& maxCoeff,
199 std::vector<Scalar>& B_avg);
200
204 std::pair<Scalar,Scalar>
205 localConvergenceData(std::vector<Scalar>& R_sum,
206 std::vector<Scalar>& maxCoeff,
207 std::vector<Scalar>& B_avg,
208 std::vector<int>& maxCoeffCell);
209
213 std::pair<std::vector<double>, std::vector<int>>
214 characteriseCnvPvSplit(const std::vector<Scalar>& B_avg, const double dt);
215
216 void updateTUNING(const Tuning& tuning);
217
219 getReservoirConvergence(const double reportTime,
220 const double dt,
221 const int iteration,
222 const int maxIter,
223 std::vector<Scalar>& B_avg,
224 std::vector<Scalar>& residual_norms);
225
234 const int iteration,
235 const int maxIter,
236 std::vector<Scalar>& residual_norms);
237
239 int numPhases() const
240 { return phaseUsage_.num_phases; }
241
243 template<class T>
244 std::vector<std::vector<Scalar> >
245 computeFluidInPlace(const T&, const std::vector<int>& fipnum) const
246 { return this->computeFluidInPlace(fipnum); }
247
249 std::vector<std::vector<Scalar> >
250 computeFluidInPlace(const std::vector<int>& /*fipnum*/) const;
251
252 const Simulator& simulator() const
253 { return simulator_; }
254
255 Simulator& simulator()
256 { return simulator_; }
257
260 { return failureReport_; }
261
264
266 const std::vector<SimulatorReport>& domainAccumulatedReports() const;
267
269 void writeNonlinearIterationsPerCell(const std::filesystem::path& odir) const;
270
271 const std::vector<StepReport>& stepReports() const
272 { return convergence_reports_; }
273
274 void writePartitions(const std::filesystem::path& odir) const;
275
279 { return well_model_; }
280
282 wellModel() const
283 { return well_model_; }
284
285 void beginReportStep()
286 { simulator_.problem().beginEpisode(); }
287
288 void endReportStep()
289 { simulator_.problem().endEpisode(); }
290
291 template<class FluidState, class Residual>
292 void getMaxCoeff(const unsigned cell_idx,
293 const IntensiveQuantities& intQuants,
294 const FluidState& fs,
295 const Residual& modelResid,
296 const Scalar pvValue,
297 std::vector<Scalar>& B_avg,
298 std::vector<Scalar>& R_sum,
299 std::vector<Scalar>& maxCoeff,
300 std::vector<int>& maxCoeffCell);
301
303 const ModelParameters& param() const
304 { return param_; }
305
308 { return compNames_; }
309
311 bool hasNlddSolver() const
312 { return nlddSolver_ != nullptr; }
313
314protected:
315 // --------- Data members ---------
316 Simulator& simulator_;
317 const Grid& grid_;
318 const PhaseUsage phaseUsage_;
319 static constexpr bool has_solvent_ = getPropValue<TypeTag, Properties::EnableSolvent>();
320 static constexpr bool has_extbo_ = getPropValue<TypeTag, Properties::EnableExtbo>();
321 static constexpr bool has_polymer_ = getPropValue<TypeTag, Properties::EnablePolymer>();
322 static constexpr bool has_polymermw_ = getPropValue<TypeTag, Properties::EnablePolymerMW>();
323 static constexpr bool has_energy_ = getPropValue<TypeTag, Properties::EnableEnergy>();
324 static constexpr bool has_foam_ = getPropValue<TypeTag, Properties::EnableFoam>();
325 static constexpr bool has_brine_ = getPropValue<TypeTag, Properties::EnableBrine>();
326 static constexpr bool has_micp_ = getPropValue<TypeTag, Properties::EnableMICP>();
327
328 ModelParameters param_;
329 SimulatorReportSingle failureReport_;
330
331 // Well Model
332 BlackoilWellModel<TypeTag>& well_model_;
333
337 long int global_nc_;
338
339 std::vector<std::vector<Scalar>> residual_norms_history_;
340 Scalar current_relaxation_;
341 BVector dx_old_;
342
343 std::vector<StepReport> convergence_reports_;
344 ComponentName compNames_{};
345
346 std::unique_ptr<BlackoilModelNldd<TypeTag>> nlddSolver_;
348
349private:
350 Scalar dpMaxRel() const { return param_.dp_max_rel_; }
351 Scalar dsMax() const { return param_.ds_max_; }
352 Scalar drMaxRel() const { return param_.dr_max_rel_; }
353 Scalar maxResidualAllowed() const { return param_.max_residual_allowed_; }
354 double linear_solve_setup_time_;
355 std::vector<bool> wasSwitched_;
356};
357
358} // namespace Opm
359
360#include <opm/simulators/flow/BlackoilModel_impl.hpp>
361
362#endif // OPM_BLACKOILMODEL_HEADER_INCLUDED
Implementation of penalty cards for three-phase black oil.
Definition BlackoilModelConvergenceMonitor.hpp:35
A model implementation for three-phase black oil.
Definition BlackoilModel.hpp:62
std::vector< std::vector< Scalar > > computeFluidInPlace(const T &, const std::vector< int > &fipnum) const
Wrapper required due to not following generic API.
Definition BlackoilModel.hpp:245
int linearIterationsLastSolve() const
Number of linear iterations used in last call to solveJacobianSystem().
Definition BlackoilModel.hpp:175
SimulatorReportSingle nonlinearIteration(const int iteration, const SimulatorTimerInterface &timer, NonlinearSolverType &nonlinear_solver)
Called once per nonlinear iteration.
Definition BlackoilModel_impl.hpp:219
void writeNonlinearIterationsPerCell(const std::filesystem::path &odir) const
Write the number of nonlinear iterations per cell to a file in ResInsight compatible format.
Definition BlackoilModel_impl.hpp:1003
SimulatorReportSingle assembleReservoir(const SimulatorTimerInterface &, const int iterationIdx)
Assemble the residual and Jacobian of the nonlinear system.
Definition BlackoilModel_impl.hpp:363
ConvergenceReport getConvergence(const SimulatorTimerInterface &timer, const int iteration, const int maxIter, std::vector< Scalar > &residual_norms)
Compute convergence based on total mass balance (tol_mb) and maximum residual mass balance (tol_cnv).
Definition BlackoilModel_impl.hpp:945
const std::vector< SimulatorReport > & domainAccumulatedReports() const
return the statistics of local solves accumulated for each domain on this rank
Definition BlackoilModel_impl.hpp:993
std::pair< Scalar, Scalar > localConvergenceData(std::vector< Scalar > &R_sum, std::vector< Scalar > &maxCoeff, std::vector< Scalar > &B_avg, std::vector< int > &maxCoeffCell)
Get reservoir quantities on this process needed for convergence calculations.
Definition BlackoilModel_impl.hpp:610
bool terminalOutputEnabled() const
Return true if output to cout is wanted.
Definition BlackoilModel.hpp:190
int numPhases() const
The number of active fluid phases in the model.
Definition BlackoilModel.hpp:239
const SimulatorReport & localAccumulatedReports() const
return the statistics of local solves accumulated for this rank
Definition BlackoilModel_impl.hpp:982
SimulatorReportSingle afterStep(const SimulatorTimerInterface &)
Called once after each time step.
Definition BlackoilModel_impl.hpp:350
const ComponentName & compNames() const
Returns const reference to component names.
Definition BlackoilModel.hpp:307
void updateSolution(const BVector &dx)
Apply an update to the primary variables.
Definition BlackoilModel_impl.hpp:526
long int global_nc_
The number of cells of the global grid.
Definition BlackoilModel.hpp:337
const ModelParameters & param() const
Returns const reference to model parameters.
Definition BlackoilModel.hpp:303
std::unique_ptr< BlackoilModelNldd< TypeTag > > nlddSolver_
Non-linear DD solver.
Definition BlackoilModel.hpp:346
bool hasNlddSolver() const
Returns true if an NLDD solver exists.
Definition BlackoilModel.hpp:311
std::pair< std::vector< double >, std::vector< int > > characteriseCnvPvSplit(const std::vector< Scalar > &B_avg, const double dt)
Compute pore-volume/cell count split among "converged", "relaxed converged", "unconverged" cells base...
Definition BlackoilModel_impl.hpp:661
const SimulatorReportSingle & failureReport() const
return the statistics if the nonlinearIteration() method failed
Definition BlackoilModel.hpp:259
BlackoilWellModel< TypeTag > & wellModel()
return the StandardWells object
Definition BlackoilModel.hpp:278
void solveJacobianSystem(BVector &x)
Solve the Jacobian system Jx = r where J is the Jacobian and r is the residual.
Definition BlackoilModel_impl.hpp:464
SimulatorReportSingle prepareStep(const SimulatorTimerInterface &timer)
Called once before each time step.
Definition BlackoilModel_impl.hpp:89
bool terminal_output_
Whether we print something to std::cout.
Definition BlackoilModel.hpp:335
Class for handling the blackoil well model.
Definition BlackoilWellModel.hpp:94
Definition ComponentName.hpp:34
Represents the convergence status of the whole simulator, to make it possible to query and store the ...
Definition ConvergenceReport.hpp:38
Interface class for SimulatorTimer objects, to be improved.
Definition SimulatorTimerInterface.hpp:34
Manages the initializing and running of time dependent problems.
Definition simulator.hh:97
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
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:235
Solver parameters for the BlackoilModel.
Definition BlackoilModelParameters.hpp:174
Definition BlackoilPhases.hpp:46
A struct for returning timing data from a simulator to its caller.
Definition SimulatorReport.hpp:34
Definition SimulatorReport.hpp:119