23 #ifndef OPM_BLACKOILMODELBASE_HEADER_INCLUDED 24 #define OPM_BLACKOILMODELBASE_HEADER_INCLUDED 28 #include <opm/autodiff/AutoDiffBlock.hpp> 29 #include <opm/autodiff/AutoDiffHelpers.hpp> 30 #include <opm/autodiff/BlackoilPropsAdFromDeck.hpp> 31 #include <opm/autodiff/LinearisedBlackoilResidual.hpp> 32 #include <opm/autodiff/NewtonIterationBlackoilInterface.hpp> 33 #include <opm/autodiff/BlackoilModelEnums.hpp> 34 #include <opm/autodiff/VFPProperties.hpp> 36 #include <opm/autodiff/IterationReport.hpp> 37 #include <opm/autodiff/DefaultBlackoilSolutionState.hpp> 38 #include <opm/parser/eclipse/EclipseState/Grid/NNC.hpp> 39 #include <opm/simulators/timestepping/SimulatorTimerInterface.hpp> 40 #include <opm/core/simulator/SimulatorReport.hpp> 42 #include <opm/common/data/SimulationDataContainer.hpp> 52 class RockCompressibility;
53 class NewtonIterationBlackoilInterface;
59 template <
class ConcreteModel>
75 template<
class Gr
id,
class WellModel,
class Implementation>
86 std::vector<ADB> accum;
99 using Opm::FIPDataEnums :: FipId ;
100 using Opm::FIPDataEnums :: fipValues ;
102 std::vector<ReservoirResidualQuant> rq;
106 std::vector<double> soMax;
108 std::vector<double> Pb;
109 std::vector<double> Pd;
112 std::vector<double> krnswdc_ow;
113 std::vector<double> krnswdc_go;
114 std::vector<double> pcswmdc_ow;
115 std::vector<double> pcswmdc_go;
117 std::array<V, fipValues> fip;
129 SurfaceToReservoirVoidage<BlackoilPropsAdFromDeck::FluidSystem, std::vector<int> >;
152 const RockCompressibility* rock_comp_props,
153 const WellModel& well_model,
155 std::shared_ptr< const EclipseState > eclState,
156 const bool has_disgas,
157 const bool has_vapoil,
158 const bool terminal_output);
175 const ReservoirState& reservoir_state,
176 const WellState& well_state);
187 template <
class NonlinearSolverType>
190 NonlinearSolverType& nonlinear_solver,
191 ReservoirState& reservoir_state,
192 WellState& well_state);
200 ReservoirState& reservoir_state,
201 WellState& well_state);
208 assemble(
const ReservoirState& reservoir_state,
209 WellState& well_state,
210 const bool initial_assembly);
220 double relativeChange(
const SimulationDataContainer& previous,
const SimulationDataContainer& current )
const;
237 ReservoirState& reservoir_state,
238 WellState& well_state);
262 const std::string&
materialName(
int material_index)
const;
269 const WellModel&
wellModel()
const {
return well_model_; }
285 std::vector<std::vector<double> >
287 const std::vector<int>& fipnum);
293 const WellState& well_state,
294 std::vector<double>& well_voidage_rates,
295 std::vector<double>& voidage_conversion_coeffs);
298 void applyVREPGroupControl(
const ReservoirState& reservoir_state,
299 WellState& well_state);
306 {
return failureReport_; }
312 typedef Eigen::Array<double,
315 Eigen::RowMajor> DataBlock;
320 SimulatorReport failureReport_;
324 const RockCompressibility* rock_comp_props_;
328 const std::vector<bool> active_;
330 const std::vector<int> canph_;
331 const std::vector<int> cells_;
333 const bool has_disgas_;
334 const bool has_vapoil_;
336 ModelParameters param_;
337 bool use_threshold_pressure_;
338 V threshold_pressures_by_connection_;
340 mutable SimulatorData sd_;
341 std::vector<PhasePresence> phaseCondition_;
344 WellModel well_model_;
358 std::vector<std::string> material_name_;
359 std::vector<std::vector<double>> residual_norms_history_;
360 double current_relaxation_;
372 return static_cast<Implementation&
>(*this);
379 return static_cast<const Implementation&
>(*this);
383 const Wells&
wells()
const {
return well_model_.wells(); }
392 makeConstantState(SolutionState& state)
const;
395 variableState(
const ReservoirState& x,
396 const WellState& xw)
const;
399 variableStateInitials(
const ReservoirState& x,
400 const WellState& xw)
const;
402 variableReservoirStateInitials(
const ReservoirState& x,
403 std::vector<V>& vars0)
const;
406 variableStateIndices()
const;
409 variableStateExtractVars(
const ReservoirState& x,
410 const std::vector<int>& indices,
411 std::vector<ADB>& vars)
const;
414 computeAccum(
const SolutionState& state,
418 assembleMassBalanceEq(
const SolutionState& state);
422 solveWellEq(
const std::vector<ADB>& mob_perfcells,
423 const std::vector<ADB>& b_perfcells,
424 const ReservoirState& reservoir_state,
425 SolutionState& state,
426 WellState& well_state);
429 addWellContributionToMassBalanceEq(
const std::vector<ADB>& cq_s,
430 const SolutionState& state,
431 const WellState& xw);
433 bool getWellConvergence(
const int iteration);
435 bool isVFPActive()
const;
438 computePressures(
const ADB& po,
441 const ADB& sg)
const;
444 computeGasPressure(
const V& po,
450 computeRelPerm(
const SolutionState& state)
const;
453 computeMassFlux(
const int actph ,
459 const SolutionState& state );
461 void applyThresholdPressures(
ADB& dp);
464 fluidViscosity(
const int phase,
469 const std::vector<PhasePresence>& cond)
const;
472 fluidReciprocFVF(
const int phase,
477 const std::vector<PhasePresence>& cond)
const;
480 fluidDensity(
const int phase,
483 const ADB& rv)
const;
486 fluidRsSat(
const V& p,
488 const std::vector<int>& cells)
const;
491 fluidRsSat(
const ADB& p,
493 const std::vector<int>& cells)
const;
496 fluidRvSat(
const V& p,
498 const std::vector<int>& cells)
const;
501 fluidRvSat(
const ADB& p,
503 const std::vector<int>& cells)
const;
506 poroMult(
const ADB& p)
const;
509 transMult(
const ADB& p)
const;
511 const std::vector<PhasePresence>
512 phaseCondition()
const {
return phaseCondition_;}
515 classifyCondition(
const ReservoirState& state);
531 computeWellConnectionPressures(
const SolutionState& state,
532 const WellState& well_state);
556 const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic>& tempV,
557 const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic>& R,
558 std::vector<double>& R_sum,
559 std::vector<double>& maxCoeff,
560 std::vector<double>& B_avg,
561 std::vector<double>& maxNormWell,
567 WellState& well_state);
569 double dpMaxRel()
const {
return param_.dp_max_rel_; }
570 double dbhpMaxRel()
const {
return param_.dbhp_max_rel_; }
571 double dsMax()
const {
return param_.ds_max_; }
572 double drMaxRel()
const {
return param_.dr_max_rel_; }
573 double maxResidualAllowed()
const {
return param_.max_residual_allowed_; }
578 #include "BlackoilModelBase_impl.hpp" 580 #endif // OPM_BLACKOILMODELBASE_HEADER_INCLUDED Contains vectors and sparse matrices that represent subsets or operations on (AD or regular) vectors ...
Definition: AutoDiffHelpers.hpp:44
Definition: BlackoilModelEnums.hpp:66
A thin wrapper class that holds one VFPProdProperties and one VFPInjProperties object.
Definition: VFPProperties.hpp:37
void computeWellVoidageRates(const ReservoirState &reservoir_state, const WellState &well_state, std::vector< double > &well_voidage_rates, std::vector< double > &voidage_conversion_coeffs)
Function to compute the resevoir voidage for the production wells.
Definition: BlackoilModelBase_impl.hpp:2458
Definition: BlackoilModelBase.hpp:96
bool getConvergence(const SimulatorTimerInterface &timer, const int iteration)
Compute convergence based on total mass balance (tol_mb) and maximum residual mass balance (tol_cnv)...
Definition: BlackoilModelBase_impl.hpp:1721
std::vector< double > computeResidualNorms() const
Compute the residual norms of the mass balance for each phase, the well flux, and the well equation...
Definition: BlackoilModelBase_impl.hpp:1552
SimulatorReport assemble(const ReservoirState &reservoir_state, WellState &well_state, const bool initial_assembly)
Assemble the residual and Jacobian of the nonlinear system.
Definition: BlackoilModelBase_impl.hpp:758
bool localWellsActive() const
return true if wells are available on this process
Definition: BlackoilModelBase.hpp:389
AutoDiffMatrix is a wrapper class that optimizes matrix operations.
Definition: AutoDiffMatrix.hpp:43
const Implementation & asImpl() const
Access the most-derived class used for static polymorphism (CRTP).
Definition: BlackoilModelBase.hpp:377
FIPDataType getFIPData() const
Return fluid-in-place data (for output functionality)
Definition: BlackoilModelBase.hpp:277
A model implementation for three-phase black oil.
Definition: BlackoilModelBase.hpp:76
bool terminalOutputEnabled() const
Return true if output to cout is wanted.
Definition: BlackoilModelBase_impl.hpp:371
int linearIterationsLastSolve() const
Number of linear iterations used in last call to solveJacobianSystem().
Definition: BlackoilModelBase_impl.hpp:359
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: AdditionalObjectDeleter.hpp:22
Facility for converting component rates at surface conditions to phase (voidage) rates at reservoir c...
void updateState(const V &dx, ReservoirState &reservoir_state, WellState &well_state)
Apply an update to the primary variables, chopped if appropriate.
Definition: BlackoilModelBase_impl.hpp:1148
void prepareStep(const SimulatorTimerInterface &timer, const ReservoirState &reservoir_state, const WellState &well_state)
Called once before each time step.
Definition: BlackoilModelBase_impl.hpp:220
Definition: BlackoilModelEnums.hpp:51
void afterStep(const SimulatorTimerInterface &timer, ReservoirState &reservoir_state, WellState &well_state)
Called once after each time step.
Definition: BlackoilModelBase_impl.hpp:333
V solveJacobianSystem() const
Solve the Jacobian system Jx = r where J is the Jacobian and r is the residual.
Definition: BlackoilModelBase_impl.hpp:1140
std::vector< std::vector< double > > computeFluidInPlace(const ReservoirState &x, const std::vector< int > &fipnum)
Compute fluid in place.
Definition: BlackoilModelBase_impl.hpp:2261
const std::string & materialName(int material_index) const
The name of an active material in the model.
Definition: BlackoilModelBase_impl.hpp:406
int global_nc_
The number of cells of the global grid.
Definition: BlackoilModelBase.hpp:355
void updatePrimalVariableFromState(const ReservoirState &state)
update the primal variable for Sg, Rv or Rs.
Definition: BlackoilModelBase_impl.hpp:2193
Definition: BlackoilModelBase.hpp:84
Traits to encapsulate the types used by classes using or extending this model.
Definition: BlackoilModelBase.hpp:60
WellModel & wellModel()
return the WellModel object
Definition: BlackoilModelBase.hpp:268
const SimulatorData & getSimulatorData(const SimulationDataContainer &) const
Return reservoir simulation data (for output functionality)
Definition: BlackoilModelBase.hpp:272
Residual structure of the fully implicit solver.
Definition: LinearisedBlackoilResidual.hpp:47
BlackoilModelBase(const ModelParameters ¶m, const Grid &grid, const BlackoilPropsAdFromDeck &fluid, const DerivedGeology &geo, const RockCompressibility *rock_comp_props, const WellModel &well_model, const NewtonIterationBlackoilInterface &linsolver, std::shared_ptr< const EclipseState > eclState, const bool has_disgas, const bool has_vapoil, const bool terminal_output)
Construct the model.
Definition: BlackoilModelBase_impl.hpp:101
void setThresholdPressures(const std::vector< double > &threshold_pressures_by_face)
Set threshold pressures that prevent or reduce flow.
Definition: BlackoilModelBase_impl.hpp:419
double relativeChange(const SimulationDataContainer &previous, const SimulationDataContainer ¤t) const
compute the relative change between to simulation states
Definition: BlackoilModelBase_impl.hpp:1593
bool terminal_output_
Whether we print something to std::cout.
Definition: BlackoilModelBase.hpp:353
void updateEquationsScaling()
Update the scaling factors for mass balance equations.
Definition: BlackoilModelBase_impl.hpp:920
Interface class for SimulatorTimer objects, to be improved.
Definition: SimulatorTimerInterface.hpp:35
const Wells & wells() const
return the Well struct in the WellModel
Definition: BlackoilModelBase.hpp:383
Class containing static geological properties that are derived from grid and petrophysical properties...
Definition: GeoProps.hpp:59
bool isParallel() const
Return true if this is a parallel run.
Definition: BlackoilModelBase_impl.hpp:198
Implementation & asImpl()
Access the most-derived class used for static polymorphism (CRTP).
Definition: BlackoilModelBase.hpp:370
int numPhases() const
The number of active fluid phases in the model.
Definition: BlackoilModelBase_impl.hpp:383
bool wellsActive() const
return true if wells are available in the reservoir
Definition: BlackoilModelBase.hpp:386
void setupGroupControl(const ReservoirState &reservoir_state, WellState &well_state)
Set up the group control related at the beginning of each time step.
Definition: BlackoilModelBase_impl.hpp:2573
Interface class for (linear) solvers for the fully implicit black-oil system.
Definition: NewtonIterationBlackoilInterface.hpp:31
double convergenceReduction(const Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic > &B, const Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic > &tempV, const Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic > &R, std::vector< double > &R_sum, std::vector< double > &maxCoeff, std::vector< double > &B_avg, std::vector< double > &maxNormWell, int nc) const
Compute the reduction within the convergence check.
Definition: BlackoilModelBase_impl.hpp:1634
This class implements the AD-adapted fluid interface for three-phase black-oil.
Definition: BlackoilPropsAdFromDeck.hpp:61
int sizeNonLinear() const
The size (number of unknowns) of the nonlinear system of equations.
Definition: BlackoilModelBase_impl.hpp:347
void updatePhaseCondFromPrimalVariable(const ReservoirState &state)
Update the phaseCondition_ member based on the primalVariable_ member.
Definition: BlackoilModelBase_impl.hpp:2206
const SimulatorReport & failureReport() const
return the statistics if the nonlinearIteration() method failed.
Definition: BlackoilModelBase.hpp:305
Eigen::Array< Scalar, Eigen::Dynamic, 1 > V
Underlying type for values.
Definition: AutoDiffBlock.hpp:99
int numMaterials() const
The number of active materials in the model.
Definition: BlackoilModelBase_impl.hpp:394
SimulatorReport nonlinearIteration(const int iteration, const SimulatorTimerInterface &timer, NonlinearSolverType &nonlinear_solver, ReservoirState &reservoir_state, WellState &well_state)
Called once per nonlinear iteration.
Definition: BlackoilModelBase_impl.hpp:240