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
265 const std::vector<StepReport>& stepReports() const
266 { return convergence_reports_; }
267
268 void writePartitions(const std::filesystem::path& odir) const;
269
273 { return well_model_; }
274
276 wellModel() const
277 { return well_model_; }
278
279 void beginReportStep()
280 { simulator_.problem().beginEpisode(); }
281
282 void endReportStep()
283 { simulator_.problem().endEpisode(); }
284
285 template<class FluidState, class Residual>
286 void getMaxCoeff(const unsigned cell_idx,
287 const IntensiveQuantities& intQuants,
288 const FluidState& fs,
289 const Residual& modelResid,
290 const Scalar pvValue,
291 std::vector<Scalar>& B_avg,
292 std::vector<Scalar>& R_sum,
293 std::vector<Scalar>& maxCoeff,
294 std::vector<int>& maxCoeffCell);
295
297 const ModelParameters& param() const
298 { return param_; }
299
302 { return compNames_; }
303
304protected:
305 // --------- Data members ---------
306 Simulator& simulator_;
307 const Grid& grid_;
308 const PhaseUsage phaseUsage_;
309 static constexpr bool has_solvent_ = getPropValue<TypeTag, Properties::EnableSolvent>();
310 static constexpr bool has_extbo_ = getPropValue<TypeTag, Properties::EnableExtbo>();
311 static constexpr bool has_polymer_ = getPropValue<TypeTag, Properties::EnablePolymer>();
312 static constexpr bool has_polymermw_ = getPropValue<TypeTag, Properties::EnablePolymerMW>();
313 static constexpr bool has_energy_ = getPropValue<TypeTag, Properties::EnableEnergy>();
314 static constexpr bool has_foam_ = getPropValue<TypeTag, Properties::EnableFoam>();
315 static constexpr bool has_brine_ = getPropValue<TypeTag, Properties::EnableBrine>();
316 static constexpr bool has_micp_ = getPropValue<TypeTag, Properties::EnableMICP>();
317
318 ModelParameters param_;
319 SimulatorReportSingle failureReport_;
320
321 // Well Model
322 BlackoilWellModel<TypeTag>& well_model_;
323
327 long int global_nc_;
328
329 std::vector<std::vector<Scalar>> residual_norms_history_;
330 Scalar current_relaxation_;
331 BVector dx_old_;
332
333 std::vector<StepReport> convergence_reports_;
334 ComponentName compNames_{};
335
336 std::unique_ptr<BlackoilModelNldd<TypeTag>> nlddSolver_;
338
339private:
340 Scalar dpMaxRel() const { return param_.dp_max_rel_; }
341 Scalar dsMax() const { return param_.ds_max_; }
342 Scalar drMaxRel() const { return param_.dr_max_rel_; }
343 Scalar maxResidualAllowed() const { return param_.max_residual_allowed_; }
344 double linear_solve_setup_time_;
345 std::vector<bool> wasSwitched_;
346};
347
348} // namespace Opm
349
350#include <opm/simulators/flow/BlackoilModel_impl.hpp>
351
352#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
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
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
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:301
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:327
const ModelParameters & param() const
Returns const reference to model parameters.
Definition BlackoilModel.hpp:297
std::unique_ptr< BlackoilModelNldd< TypeTag > > nlddSolver_
Non-linear DD solver.
Definition BlackoilModel.hpp:336
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:272
SimulatorReportSingle localAccumulatedReports() const
return the statistics if the nonlinearIteration() method failed
Definition BlackoilModel_impl.hpp:982
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:325
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:92
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