mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Use the Curiously Recurring Template Pattern for BlackoilModel.
This commit is contained in:
parent
92ab1d7974
commit
05bb1e4f42
@ -23,29 +23,13 @@
|
||||
#ifndef OPM_BLACKOILMODEL_HEADER_INCLUDED
|
||||
#define OPM_BLACKOILMODEL_HEADER_INCLUDED
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <opm/autodiff/AutoDiffBlock.hpp>
|
||||
#include <opm/autodiff/AutoDiffHelpers.hpp>
|
||||
#include <opm/autodiff/BlackoilPropsAdInterface.hpp>
|
||||
#include <opm/autodiff/LinearisedBlackoilResidual.hpp>
|
||||
#include <opm/autodiff/NewtonIterationBlackoilInterface.hpp>
|
||||
|
||||
#include <array>
|
||||
|
||||
struct UnstructuredGrid;
|
||||
struct Wells;
|
||||
#include <opm/autodiff/BlackoilModelBase.hpp>
|
||||
#include <opm/core/simulator/BlackoilState.hpp>
|
||||
#include <opm/autodiff/WellStateFullyImplicitBlackoil.hpp>
|
||||
#include <opm/autodiff/BlackoilModelParameters.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
namespace parameter { class ParameterGroup; }
|
||||
class DerivedGeology;
|
||||
class RockCompressibility;
|
||||
class NewtonIterationBlackoilInterface;
|
||||
class BlackoilState;
|
||||
class WellStateFullyImplicitBlackoil;
|
||||
|
||||
|
||||
/// A model implementation for three-phase black oil.
|
||||
///
|
||||
/// The simulator is capable of handling three-phase problems
|
||||
@ -56,34 +40,10 @@ namespace Opm {
|
||||
/// It uses automatic differentiation via the class AutoDiffBlock
|
||||
/// to simplify assembly of the jacobian matrix.
|
||||
template<class Grid>
|
||||
class BlackoilModel
|
||||
class BlackoilModel : public BlackoilModelBase<Grid, BlackoilModel<Grid> >
|
||||
{
|
||||
public:
|
||||
// --------- Types and enums ---------
|
||||
typedef AutoDiffBlock<double> ADB;
|
||||
typedef ADB::V V;
|
||||
typedef ADB::M M;
|
||||
typedef BlackoilState ReservoirState;
|
||||
typedef WellStateFullyImplicitBlackoil WellState;
|
||||
|
||||
/// Model-specific solver parameters.
|
||||
struct ModelParameters
|
||||
{
|
||||
double dp_max_rel_;
|
||||
double ds_max_;
|
||||
double dr_max_rel_;
|
||||
double max_residual_allowed_;
|
||||
double tolerance_mb_;
|
||||
double tolerance_cnv_;
|
||||
double tolerance_wells_;
|
||||
|
||||
explicit ModelParameters( const parameter::ParameterGroup& param );
|
||||
ModelParameters();
|
||||
|
||||
void reset();
|
||||
};
|
||||
|
||||
// --------- Public methods ---------
|
||||
typedef BlackoilModelBase<Grid, BlackoilModel<Grid> > Base;
|
||||
|
||||
/// Construct the model. It will retain references to the
|
||||
/// arguments of this functions, and they are expected to
|
||||
@ -98,344 +58,34 @@ namespace Opm {
|
||||
/// \param[in] has_disgas turn on dissolved gas
|
||||
/// \param[in] has_vapoil turn on vaporized oil feature
|
||||
/// \param[in] terminal_output request output to cout/cerr
|
||||
BlackoilModel(const ModelParameters& param,
|
||||
const Grid& grid ,
|
||||
BlackoilModel(const typename Base::ModelParameters& param,
|
||||
const Grid& grid,
|
||||
const BlackoilPropsAdInterface& fluid,
|
||||
const DerivedGeology& geo ,
|
||||
const DerivedGeology& geo,
|
||||
const RockCompressibility* rock_comp_props,
|
||||
const Wells* wells,
|
||||
const NewtonIterationBlackoilInterface& linsolver,
|
||||
const bool has_disgas,
|
||||
const bool has_vapoil,
|
||||
const bool terminal_output);
|
||||
|
||||
/// \brief Set threshold pressures that prevent or reduce flow.
|
||||
/// This prevents flow across faces if the potential
|
||||
/// difference is less than the threshold. If the potential
|
||||
/// difference is greater, the threshold value is subtracted
|
||||
/// before calculating flow. This is treated symmetrically, so
|
||||
/// flow is prevented or reduced in both directions equally.
|
||||
/// \param[in] threshold_pressures_by_face array of size equal to the number of faces
|
||||
/// of the grid passed in the constructor.
|
||||
void setThresholdPressures(const std::vector<double>& threshold_pressures_by_face);
|
||||
|
||||
/// Called once before each time step.
|
||||
/// \param[in] dt time step size
|
||||
/// \param[in, out] reservoir_state reservoir state variables
|
||||
/// \param[in, out] well_state well state variables
|
||||
void prepareStep(const double dt,
|
||||
ReservoirState& reservoir_state,
|
||||
WellState& well_state);
|
||||
|
||||
/// Called once after each time step.
|
||||
/// In this class, this function does nothing.
|
||||
/// \param[in] dt time step size
|
||||
/// \param[in, out] reservoir_state reservoir state variables
|
||||
/// \param[in, out] well_state well state variables
|
||||
void afterStep(const double dt,
|
||||
ReservoirState& reservoir_state,
|
||||
WellState& well_state);
|
||||
|
||||
/// Assemble the residual and Jacobian of the nonlinear system.
|
||||
/// \param[in] reservoir_state reservoir state variables
|
||||
/// \param[in, out] well_state well state variables
|
||||
/// \param[in] initial_assembly pass true if this is the first call to assemble() in this timestep
|
||||
void assemble(const BlackoilState& reservoir_state,
|
||||
WellStateFullyImplicitBlackoil& well_state,
|
||||
const bool initial_assembly);
|
||||
|
||||
/// \brief Compute the residual norms of the mass balance for each phase,
|
||||
/// the well flux, and the well equation.
|
||||
/// \return a vector that contains for each phase the norm of the mass balance
|
||||
/// and afterwards the norm of the residual of the well flux and the well equation.
|
||||
std::vector<double> computeResidualNorms() const;
|
||||
|
||||
/// The size (number of unknowns) of the nonlinear system of equations.
|
||||
int sizeNonLinear() const;
|
||||
|
||||
/// Number of linear iterations used in last call to solveJacobianSystem().
|
||||
int linearIterationsLastSolve() const;
|
||||
|
||||
/// Solve the Jacobian system Jx = r where J is the Jacobian and
|
||||
/// r is the residual.
|
||||
V solveJacobianSystem() const;
|
||||
|
||||
/// Apply an update to the primary variables, chopped if appropriate.
|
||||
/// \param[in] dx updates to apply to primary variables
|
||||
/// \param[in, out] reservoir_state reservoir state variables
|
||||
/// \param[in, out] well_state well state variables
|
||||
void updateState(const V& dx,
|
||||
BlackoilState& reservoir_state,
|
||||
WellStateFullyImplicitBlackoil& well_state);
|
||||
|
||||
/// Return true if output to cout is wanted.
|
||||
bool terminalOutputEnabled() const;
|
||||
|
||||
/// Compute convergence based on total mass balance (tol_mb) and maximum
|
||||
/// residual mass balance (tol_cnv).
|
||||
/// \param[in] dt timestep length
|
||||
/// \param[in] iteration current iteration number
|
||||
bool getConvergence(const double dt, const int iteration);
|
||||
|
||||
/// The number of active phases in the model.
|
||||
int numPhases() const;
|
||||
|
||||
private:
|
||||
|
||||
// --------- Types and enums ---------
|
||||
|
||||
typedef Eigen::Array<double,
|
||||
Eigen::Dynamic,
|
||||
Eigen::Dynamic,
|
||||
Eigen::RowMajor> DataBlock;
|
||||
|
||||
struct ReservoirResidualQuant {
|
||||
ReservoirResidualQuant();
|
||||
std::vector<ADB> accum; // Accumulations
|
||||
ADB mflux; // Mass flux (surface conditions)
|
||||
ADB b; // Reciprocal FVF
|
||||
ADB head; // Pressure drop across int. interfaces
|
||||
ADB mob; // Phase mobility (per cell)
|
||||
const bool terminal_output)
|
||||
: Base(param, grid, fluid, geo, rock_comp_props, wells, linsolver,
|
||||
has_disgas, has_vapoil, terminal_output)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct SolutionState {
|
||||
SolutionState(const int np);
|
||||
ADB pressure;
|
||||
ADB temperature;
|
||||
std::vector<ADB> saturation;
|
||||
ADB rs;
|
||||
ADB rv;
|
||||
ADB qs;
|
||||
ADB bhp;
|
||||
// Below are quantities stored in the state for optimization purposes.
|
||||
std::vector<ADB> canonical_phase_pressures; // Always has 3 elements, even if only 2 phases active.
|
||||
|
||||
/// Providing types by template specialisation of ModelTraits for BlackoilModel.
|
||||
template <class Grid>
|
||||
struct ModelTraits< BlackoilModel<Grid> >
|
||||
{
|
||||
typedef BlackoilState ReservoirState;
|
||||
typedef WellStateFullyImplicitBlackoil WellState;
|
||||
typedef BlackoilModelBase< Grid, BlackoilModel<Grid> > Base;
|
||||
typedef BlackoilModelParameters ModelParameters;
|
||||
};
|
||||
|
||||
struct WellOps {
|
||||
WellOps(const Wells* wells);
|
||||
M w2p; // well -> perf (scatter)
|
||||
M p2w; // perf -> well (gather)
|
||||
};
|
||||
|
||||
enum { Water = BlackoilPropsAdInterface::Water,
|
||||
Oil = BlackoilPropsAdInterface::Oil ,
|
||||
Gas = BlackoilPropsAdInterface::Gas ,
|
||||
MaxNumPhases = BlackoilPropsAdInterface::MaxNumPhases
|
||||
};
|
||||
|
||||
enum PrimalVariables { Sg = 0, RS = 1, RV = 2 };
|
||||
|
||||
// --------- Data members ---------
|
||||
|
||||
const Grid& grid_;
|
||||
const BlackoilPropsAdInterface& fluid_;
|
||||
const DerivedGeology& geo_;
|
||||
const RockCompressibility* rock_comp_props_;
|
||||
const Wells* wells_;
|
||||
const NewtonIterationBlackoilInterface& linsolver_;
|
||||
// For each canonical phase -> true if active
|
||||
const std::vector<bool> active_;
|
||||
// Size = # active phases. Maps active -> canonical phase indices.
|
||||
const std::vector<int> canph_;
|
||||
const std::vector<int> cells_; // All grid cells
|
||||
HelperOps ops_;
|
||||
const WellOps wops_;
|
||||
const bool has_disgas_;
|
||||
const bool has_vapoil_;
|
||||
|
||||
ModelParameters param_;
|
||||
bool use_threshold_pressure_;
|
||||
V threshold_pressures_by_interior_face_;
|
||||
|
||||
std::vector<ReservoirResidualQuant> rq_;
|
||||
std::vector<PhasePresence> phaseCondition_;
|
||||
V well_perforation_pressure_diffs_; // Diff to bhp for each well perforation.
|
||||
|
||||
LinearisedBlackoilResidual residual_;
|
||||
|
||||
/// \brief Whether we print something to std::cout
|
||||
bool terminal_output_;
|
||||
|
||||
std::vector<int> primalVariable_;
|
||||
V pvdt_;
|
||||
|
||||
// --------- Private methods ---------
|
||||
|
||||
// return true if wells are available
|
||||
bool wellsActive() const { return wells_ ? wells_->number_of_wells > 0 : false ; }
|
||||
// return wells object
|
||||
const Wells& wells () const { assert( bool(wells_ != 0) ); return *wells_; }
|
||||
|
||||
SolutionState
|
||||
constantState(const BlackoilState& x,
|
||||
const WellStateFullyImplicitBlackoil& xw) const;
|
||||
|
||||
void
|
||||
makeConstantState(SolutionState& state) const;
|
||||
|
||||
SolutionState
|
||||
variableState(const BlackoilState& x,
|
||||
const WellStateFullyImplicitBlackoil& xw) const;
|
||||
|
||||
void
|
||||
computeAccum(const SolutionState& state,
|
||||
const int aix );
|
||||
|
||||
void computeWellConnectionPressures(const SolutionState& state,
|
||||
const WellStateFullyImplicitBlackoil& xw);
|
||||
|
||||
void
|
||||
addWellControlEq(const SolutionState& state,
|
||||
const WellStateFullyImplicitBlackoil& xw,
|
||||
const V& aliveWells);
|
||||
|
||||
void
|
||||
addWellEq(const SolutionState& state,
|
||||
WellStateFullyImplicitBlackoil& xw,
|
||||
V& aliveWells);
|
||||
|
||||
void updateWellControls(WellStateFullyImplicitBlackoil& xw) const;
|
||||
|
||||
std::vector<ADB>
|
||||
computePressures(const SolutionState& state) const;
|
||||
|
||||
std::vector<ADB>
|
||||
computePressures(const ADB& po,
|
||||
const ADB& sw,
|
||||
const ADB& so,
|
||||
const ADB& sg) const;
|
||||
|
||||
V
|
||||
computeGasPressure(const V& po,
|
||||
const V& sw,
|
||||
const V& so,
|
||||
const V& sg) const;
|
||||
|
||||
std::vector<ADB>
|
||||
computeRelPerm(const SolutionState& state) const;
|
||||
|
||||
void
|
||||
computeMassFlux(const int actph ,
|
||||
const V& transi,
|
||||
const ADB& kr ,
|
||||
const ADB& p ,
|
||||
const SolutionState& state );
|
||||
|
||||
void applyThresholdPressures(ADB& dp);
|
||||
|
||||
ADB
|
||||
fluidViscosity(const int phase,
|
||||
const ADB& p ,
|
||||
const ADB& temp ,
|
||||
const ADB& rs ,
|
||||
const ADB& rv ,
|
||||
const std::vector<PhasePresence>& cond,
|
||||
const std::vector<int>& cells) const;
|
||||
|
||||
ADB
|
||||
fluidReciprocFVF(const int phase,
|
||||
const ADB& p ,
|
||||
const ADB& temp ,
|
||||
const ADB& rs ,
|
||||
const ADB& rv ,
|
||||
const std::vector<PhasePresence>& cond,
|
||||
const std::vector<int>& cells) const;
|
||||
|
||||
ADB
|
||||
fluidDensity(const int phase,
|
||||
const ADB& p ,
|
||||
const ADB& temp ,
|
||||
const ADB& rs ,
|
||||
const ADB& rv ,
|
||||
const std::vector<PhasePresence>& cond,
|
||||
const std::vector<int>& cells) const;
|
||||
|
||||
V
|
||||
fluidRsSat(const V& p,
|
||||
const V& so,
|
||||
const std::vector<int>& cells) const;
|
||||
|
||||
ADB
|
||||
fluidRsSat(const ADB& p,
|
||||
const ADB& so,
|
||||
const std::vector<int>& cells) const;
|
||||
|
||||
V
|
||||
fluidRvSat(const V& p,
|
||||
const V& so,
|
||||
const std::vector<int>& cells) const;
|
||||
|
||||
ADB
|
||||
fluidRvSat(const ADB& p,
|
||||
const ADB& so,
|
||||
const std::vector<int>& cells) const;
|
||||
|
||||
ADB
|
||||
poroMult(const ADB& p) const;
|
||||
|
||||
ADB
|
||||
transMult(const ADB& p) const;
|
||||
|
||||
void
|
||||
classifyCondition(const SolutionState& state,
|
||||
std::vector<PhasePresence>& cond ) const;
|
||||
|
||||
const std::vector<PhasePresence>
|
||||
phaseCondition() const {return phaseCondition_;}
|
||||
|
||||
void
|
||||
classifyCondition(const BlackoilState& state);
|
||||
|
||||
|
||||
/// update the primal variable for Sg, Rv or Rs. The Gas phase must
|
||||
/// be active to call this method.
|
||||
void
|
||||
updatePrimalVariableFromState(const BlackoilState& state);
|
||||
|
||||
/// Update the phaseCondition_ member based on the primalVariable_ member.
|
||||
void
|
||||
updatePhaseCondFromPrimalVariable();
|
||||
|
||||
/// \brief Compute the reduction within the convergence check.
|
||||
/// \param[in] B A matrix with MaxNumPhases columns and the same number rows
|
||||
/// as the number of cells of the grid. B.col(i) contains the values
|
||||
/// for phase i.
|
||||
/// \param[in] tempV A matrix with MaxNumPhases columns and the same number rows
|
||||
/// as the number of cells of the grid. tempV.col(i) contains the
|
||||
/// values
|
||||
/// for phase i.
|
||||
/// \param[in] R A matrix with MaxNumPhases columns and the same number rows
|
||||
/// as the number of cells of the grid. B.col(i) contains the values
|
||||
/// for phase i.
|
||||
/// \param[out] R_sum An array of size MaxNumPhases where entry i contains the sum
|
||||
/// of R for the phase i.
|
||||
/// \param[out] maxCoeff An array of size MaxNumPhases where entry i contains the
|
||||
/// maximum of tempV for the phase i.
|
||||
/// \param[out] B_avg An array of size MaxNumPhases where entry i contains the average
|
||||
/// of B for the phase i.
|
||||
/// \param[out] maxNormWell The maximum of the well equations for each phase.
|
||||
/// \param[in] nc The number of cells of the local grid.
|
||||
/// \param[in] nw The number of wells on the local grid.
|
||||
/// \return The total pore volume over all cells.
|
||||
double
|
||||
convergenceReduction(const Eigen::Array<double, Eigen::Dynamic, MaxNumPhases>& B,
|
||||
const Eigen::Array<double, Eigen::Dynamic, MaxNumPhases>& tempV,
|
||||
const Eigen::Array<double, Eigen::Dynamic, MaxNumPhases>& R,
|
||||
std::array<double,MaxNumPhases>& R_sum,
|
||||
std::array<double,MaxNumPhases>& maxCoeff,
|
||||
std::array<double,MaxNumPhases>& B_avg,
|
||||
std::vector<double>& maxNormWell,
|
||||
int nc,
|
||||
int nw) const;
|
||||
|
||||
double dpMaxRel() const { return param_.dp_max_rel_; }
|
||||
double dsMax() const { return param_.ds_max_; }
|
||||
double drMaxRel() const { return param_.dr_max_rel_; }
|
||||
double maxResidualAllowed() const { return param_.max_residual_allowed_; }
|
||||
|
||||
};
|
||||
} // namespace Opm
|
||||
|
||||
#include "BlackoilModel_impl.hpp"
|
||||
|
||||
#endif // OPM_BLACKOILMODEL_HEADER_INCLUDED
|
||||
|
@ -46,6 +46,13 @@ namespace Opm {
|
||||
class WellStateFullyImplicitBlackoil;
|
||||
|
||||
|
||||
/// Traits to encapsulate the types used by classes using or
|
||||
/// extending this model. Forward declared here, must be
|
||||
/// specialised for each concrete model class.
|
||||
template <class ConcreteModel>
|
||||
struct ModelTraits;
|
||||
|
||||
|
||||
/// A model implementation for three-phase black oil.
|
||||
///
|
||||
/// The simulator is capable of handling three-phase problems
|
||||
@ -55,7 +62,9 @@ namespace Opm {
|
||||
///
|
||||
/// It uses automatic differentiation via the class AutoDiffBlock
|
||||
/// to simplify assembly of the jacobian matrix.
|
||||
template<class Grid>
|
||||
/// \tparam Grid UnstructuredGrid or CpGrid.
|
||||
/// \tparam Implementation Provides concrete state types.
|
||||
template<class Grid, class Implementation>
|
||||
class BlackoilModelBase
|
||||
{
|
||||
public:
|
||||
@ -63,25 +72,10 @@ namespace Opm {
|
||||
typedef AutoDiffBlock<double> ADB;
|
||||
typedef ADB::V V;
|
||||
typedef ADB::M M;
|
||||
typedef BlackoilState ReservoirState;
|
||||
typedef WellStateFullyImplicitBlackoil WellState;
|
||||
|
||||
/// Model-specific solver parameters.
|
||||
struct ModelParameters
|
||||
{
|
||||
double dp_max_rel_;
|
||||
double ds_max_;
|
||||
double dr_max_rel_;
|
||||
double max_residual_allowed_;
|
||||
double tolerance_mb_;
|
||||
double tolerance_cnv_;
|
||||
double tolerance_wells_;
|
||||
|
||||
explicit ModelParameters( const parameter::ParameterGroup& param );
|
||||
ModelParameters();
|
||||
|
||||
void reset();
|
||||
};
|
||||
typedef typename ModelTraits<Implementation>::ReservoirState ReservoirState;
|
||||
typedef typename ModelTraits<Implementation>::WellState WellState;
|
||||
typedef typename ModelTraits<Implementation>::ModelParameters ModelParameters;
|
||||
|
||||
// --------- Public methods ---------
|
||||
|
||||
@ -180,7 +174,7 @@ namespace Opm {
|
||||
/// The number of active phases in the model.
|
||||
int numPhases() const;
|
||||
|
||||
private:
|
||||
protected:
|
||||
|
||||
// --------- Types and enums ---------
|
||||
|
||||
@ -259,7 +253,7 @@ namespace Opm {
|
||||
std::vector<int> primalVariable_;
|
||||
V pvdt_;
|
||||
|
||||
// --------- Private methods ---------
|
||||
// --------- Protected methods ---------
|
||||
|
||||
// return true if wells are available
|
||||
bool wellsActive() const { return wells_ ? wells_->number_of_wells > 0 : false ; }
|
||||
|
@ -136,48 +136,9 @@ namespace detail {
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <class Grid>
|
||||
void BlackoilModelBase<Grid>::ModelParameters::
|
||||
reset()
|
||||
{
|
||||
// default values for the solver parameters
|
||||
dp_max_rel_ = 1.0e9;
|
||||
ds_max_ = 0.2;
|
||||
dr_max_rel_ = 1.0e9;
|
||||
max_residual_allowed_ = 1e7;
|
||||
tolerance_mb_ = 1.0e-5;
|
||||
tolerance_cnv_ = 1.0e-2;
|
||||
tolerance_wells_ = 5.0e-1;
|
||||
}
|
||||
|
||||
template <class Grid>
|
||||
BlackoilModelBase<Grid>::ModelParameters::
|
||||
ModelParameters()
|
||||
{
|
||||
// set default values
|
||||
reset();
|
||||
}
|
||||
|
||||
template <class Grid>
|
||||
BlackoilModelBase<Grid>::ModelParameters::
|
||||
ModelParameters( const parameter::ParameterGroup& param )
|
||||
{
|
||||
// set default values
|
||||
reset();
|
||||
|
||||
// overload with given parameters
|
||||
dp_max_rel_ = param.getDefault("dp_max_rel", dp_max_rel_);
|
||||
ds_max_ = param.getDefault("ds_max", ds_max_);
|
||||
dr_max_rel_ = param.getDefault("dr_max_rel", dr_max_rel_);
|
||||
max_residual_allowed_ = param.getDefault("max_residual_allowed", max_residual_allowed_);
|
||||
tolerance_mb_ = param.getDefault("tolerance_mb", tolerance_mb_);
|
||||
tolerance_cnv_ = param.getDefault("tolerance_cnv", tolerance_cnv_);
|
||||
tolerance_wells_ = param.getDefault("tolerance_wells", tolerance_wells_ );
|
||||
}
|
||||
|
||||
|
||||
template <class Grid>
|
||||
BlackoilModelBase<Grid>::
|
||||
template <class Grid, class Implementation>
|
||||
BlackoilModelBase<Grid, Implementation>::
|
||||
BlackoilModelBase(const ModelParameters& param,
|
||||
const Grid& grid ,
|
||||
const BlackoilPropsAdInterface& fluid,
|
||||
@ -225,9 +186,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
void
|
||||
BlackoilModelBase<Grid>::
|
||||
BlackoilModelBase<Grid, Implementation>::
|
||||
prepareStep(const double dt,
|
||||
ReservoirState& reservoir_state,
|
||||
WellState& /* well_state */)
|
||||
@ -241,9 +202,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
void
|
||||
BlackoilModelBase<Grid>::
|
||||
BlackoilModelBase<Grid, Implementation>::
|
||||
afterStep(const double /* dt */,
|
||||
ReservoirState& /* reservoir_state */,
|
||||
WellState& /* well_state */)
|
||||
@ -254,9 +215,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
int
|
||||
BlackoilModelBase<Grid>::
|
||||
BlackoilModelBase<Grid, Implementation>::
|
||||
sizeNonLinear() const
|
||||
{
|
||||
return residual_.sizeNonLinear();
|
||||
@ -265,9 +226,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
int
|
||||
BlackoilModelBase<Grid>::
|
||||
BlackoilModelBase<Grid, Implementation>::
|
||||
linearIterationsLastSolve() const
|
||||
{
|
||||
return linsolver_.iterations();
|
||||
@ -276,9 +237,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
bool
|
||||
BlackoilModelBase<Grid>::
|
||||
BlackoilModelBase<Grid, Implementation>::
|
||||
terminalOutputEnabled() const
|
||||
{
|
||||
return terminal_output_;
|
||||
@ -287,9 +248,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
int
|
||||
BlackoilModelBase<Grid>::
|
||||
BlackoilModelBase<Grid, Implementation>::
|
||||
numPhases() const
|
||||
{
|
||||
return fluid_.numPhases();
|
||||
@ -298,9 +259,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
void
|
||||
BlackoilModelBase<Grid>::
|
||||
BlackoilModelBase<Grid, Implementation>::
|
||||
setThresholdPressures(const std::vector<double>& threshold_pressures_by_face)
|
||||
{
|
||||
const int num_faces = AutoDiffGrid::numFaces(grid_);
|
||||
@ -319,8 +280,8 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
BlackoilModelBase<Grid>::ReservoirResidualQuant::ReservoirResidualQuant()
|
||||
template <class Grid, class Implementation>
|
||||
BlackoilModelBase<Grid, Implementation>::ReservoirResidualQuant::ReservoirResidualQuant()
|
||||
: accum(2, ADB::null())
|
||||
, mflux( ADB::null())
|
||||
, b ( ADB::null())
|
||||
@ -333,8 +294,8 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
BlackoilModelBase<Grid>::SolutionState::SolutionState(const int np)
|
||||
template <class Grid, class Implementation>
|
||||
BlackoilModelBase<Grid, Implementation>::SolutionState::SolutionState(const int np)
|
||||
: pressure ( ADB::null())
|
||||
, temperature( ADB::null())
|
||||
, saturation(np, ADB::null())
|
||||
@ -350,8 +311,8 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
BlackoilModelBase<Grid>::
|
||||
template <class Grid, class Implementation>
|
||||
BlackoilModelBase<Grid, Implementation>::
|
||||
WellOps::WellOps(const Wells* wells)
|
||||
: w2p(),
|
||||
p2w()
|
||||
@ -386,9 +347,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
typename BlackoilModelBase<Grid>::SolutionState
|
||||
BlackoilModelBase<Grid>::constantState(const BlackoilState& x,
|
||||
template <class Grid, class Implementation>
|
||||
typename BlackoilModelBase<Grid, Implementation>::SolutionState
|
||||
BlackoilModelBase<Grid, Implementation>::constantState(const BlackoilState& x,
|
||||
const WellStateFullyImplicitBlackoil& xw) const
|
||||
{
|
||||
auto state = variableState(x, xw);
|
||||
@ -400,9 +361,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
void
|
||||
BlackoilModelBase<Grid>::makeConstantState(SolutionState& state) const
|
||||
BlackoilModelBase<Grid, Implementation>::makeConstantState(SolutionState& state) const
|
||||
{
|
||||
// HACK: throw away the derivatives. this may not be the most
|
||||
// performant way to do things, but it will make the state
|
||||
@ -429,9 +390,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
typename BlackoilModelBase<Grid>::SolutionState
|
||||
BlackoilModelBase<Grid>::variableState(const BlackoilState& x,
|
||||
template <class Grid, class Implementation>
|
||||
typename BlackoilModelBase<Grid, Implementation>::SolutionState
|
||||
BlackoilModelBase<Grid, Implementation>::variableState(const BlackoilState& x,
|
||||
const WellStateFullyImplicitBlackoil& xw) const
|
||||
{
|
||||
using namespace Opm::AutoDiffGrid;
|
||||
@ -587,9 +548,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
void
|
||||
BlackoilModelBase<Grid>::computeAccum(const SolutionState& state,
|
||||
BlackoilModelBase<Grid, Implementation>::computeAccum(const SolutionState& state,
|
||||
const int aix )
|
||||
{
|
||||
const Opm::PhaseUsage& pu = fluid_.phaseUsage();
|
||||
@ -634,8 +595,8 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
void BlackoilModelBase<Grid>::computeWellConnectionPressures(const SolutionState& state,
|
||||
template <class Grid, class Implementation>
|
||||
void BlackoilModelBase<Grid, Implementation>::computeWellConnectionPressures(const SolutionState& state,
|
||||
const WellStateFullyImplicitBlackoil& xw)
|
||||
{
|
||||
if( ! wellsActive() ) return ;
|
||||
@ -727,9 +688,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
void
|
||||
BlackoilModelBase<Grid>::
|
||||
BlackoilModelBase<Grid, Implementation>::
|
||||
assemble(const BlackoilState& reservoir_state,
|
||||
WellStateFullyImplicitBlackoil& well_state,
|
||||
const bool initial_assembly)
|
||||
@ -820,8 +781,8 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
void BlackoilModelBase<Grid>::addWellEq(const SolutionState& state,
|
||||
template <class Grid, class Implementation>
|
||||
void BlackoilModelBase<Grid, Implementation>::addWellEq(const SolutionState& state,
|
||||
WellStateFullyImplicitBlackoil& xw,
|
||||
V& aliveWells)
|
||||
{
|
||||
@ -1062,8 +1023,8 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
void BlackoilModelBase<Grid>::updateWellControls(WellStateFullyImplicitBlackoil& xw) const
|
||||
template <class Grid, class Implementation>
|
||||
void BlackoilModelBase<Grid, Implementation>::updateWellControls(WellStateFullyImplicitBlackoil& xw) const
|
||||
{
|
||||
if( ! wellsActive() ) return ;
|
||||
|
||||
@ -1138,8 +1099,8 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
void BlackoilModelBase<Grid>::addWellControlEq(const SolutionState& state,
|
||||
template <class Grid, class Implementation>
|
||||
void BlackoilModelBase<Grid, Implementation>::addWellControlEq(const SolutionState& state,
|
||||
const WellStateFullyImplicitBlackoil& xw,
|
||||
const V& aliveWells)
|
||||
{
|
||||
@ -1209,8 +1170,8 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
V BlackoilModelBase<Grid>::solveJacobianSystem() const
|
||||
template <class Grid, class Implementation>
|
||||
V BlackoilModelBase<Grid, Implementation>::solveJacobianSystem() const
|
||||
{
|
||||
return linsolver_.computeNewtonIncrement(residual_);
|
||||
}
|
||||
@ -1228,6 +1189,7 @@ namespace detail {
|
||||
/// \param info In a parallel this holds the information about the data distribution.
|
||||
double infinityNorm( const ADB& a, const boost::any& pinfo = boost::any() )
|
||||
{
|
||||
static_cast<void>(pinfo); // Suppress warning in non-MPI case.
|
||||
#if HAVE_MPI
|
||||
if ( pinfo.type() == typeid(ParallelISTLInformation) )
|
||||
{
|
||||
@ -1254,6 +1216,7 @@ namespace detail {
|
||||
/// \param info In a parallel this holds the information about the data distribution.
|
||||
double infinityNormWell( const ADB& a, const boost::any& pinfo )
|
||||
{
|
||||
static_cast<void>(pinfo); // Suppress warning in non-MPI case.
|
||||
double result=0;
|
||||
if( a.value().size() > 0 ) {
|
||||
result = a.value().matrix().lpNorm<Eigen::Infinity> ();
|
||||
@ -1275,8 +1238,8 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
void BlackoilModelBase<Grid>::updateState(const V& dx,
|
||||
template <class Grid, class Implementation>
|
||||
void BlackoilModelBase<Grid, Implementation>::updateState(const V& dx,
|
||||
BlackoilState& reservoir_state,
|
||||
WellStateFullyImplicitBlackoil& well_state)
|
||||
{
|
||||
@ -1537,9 +1500,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
std::vector<ADB>
|
||||
BlackoilModelBase<Grid>::computeRelPerm(const SolutionState& state) const
|
||||
BlackoilModelBase<Grid, Implementation>::computeRelPerm(const SolutionState& state) const
|
||||
{
|
||||
using namespace Opm::AutoDiffGrid;
|
||||
const int nc = numCells(grid_);
|
||||
@ -1566,9 +1529,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
std::vector<ADB>
|
||||
BlackoilModelBase<Grid>::computePressures(const SolutionState& state) const
|
||||
BlackoilModelBase<Grid, Implementation>::computePressures(const SolutionState& state) const
|
||||
{
|
||||
using namespace Opm::AutoDiffGrid;
|
||||
const int nc = numCells(grid_);
|
||||
@ -1596,9 +1559,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
std::vector<ADB>
|
||||
BlackoilModelBase<Grid>::
|
||||
BlackoilModelBase<Grid, Implementation>::
|
||||
computePressures(const ADB& po,
|
||||
const ADB& sw,
|
||||
const ADB& so,
|
||||
@ -1633,9 +1596,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
V
|
||||
BlackoilModelBase<Grid>::computeGasPressure(const V& po,
|
||||
BlackoilModelBase<Grid, Implementation>::computeGasPressure(const V& po,
|
||||
const V& sw,
|
||||
const V& so,
|
||||
const V& sg) const
|
||||
@ -1652,9 +1615,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
void
|
||||
BlackoilModelBase<Grid>::computeMassFlux(const int actph ,
|
||||
BlackoilModelBase<Grid, Implementation>::computeMassFlux(const int actph ,
|
||||
const V& transi,
|
||||
const ADB& kr ,
|
||||
const ADB& phasePressure,
|
||||
@ -1698,9 +1661,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
void
|
||||
BlackoilModelBase<Grid>::applyThresholdPressures(ADB& dp)
|
||||
BlackoilModelBase<Grid, Implementation>::applyThresholdPressures(ADB& dp)
|
||||
{
|
||||
// We support reversible threshold pressures only.
|
||||
// Method: if the potential difference is lower (in absolute
|
||||
@ -1729,9 +1692,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
std::vector<double>
|
||||
BlackoilModelBase<Grid>::computeResidualNorms() const
|
||||
BlackoilModelBase<Grid, Implementation>::computeResidualNorms() const
|
||||
{
|
||||
std::vector<double> residualNorms;
|
||||
|
||||
@ -1771,9 +1734,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
double
|
||||
BlackoilModelBase<Grid>::convergenceReduction(const Eigen::Array<double, Eigen::Dynamic, MaxNumPhases>& B,
|
||||
BlackoilModelBase<Grid, Implementation>::convergenceReduction(const Eigen::Array<double, Eigen::Dynamic, MaxNumPhases>& B,
|
||||
const Eigen::Array<double, Eigen::Dynamic, MaxNumPhases>& tempV,
|
||||
const Eigen::Array<double, Eigen::Dynamic, MaxNumPhases>& R,
|
||||
std::array<double,MaxNumPhases>& R_sum,
|
||||
@ -1855,9 +1818,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
bool
|
||||
BlackoilModelBase<Grid>::getConvergence(const double dt, const int iteration)
|
||||
BlackoilModelBase<Grid, Implementation>::getConvergence(const double dt, const int iteration)
|
||||
{
|
||||
const double tol_mb = param_.tolerance_mb_;
|
||||
const double tol_cnv = param_.tolerance_cnv_;
|
||||
@ -1960,9 +1923,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
ADB
|
||||
BlackoilModelBase<Grid>::fluidViscosity(const int phase,
|
||||
BlackoilModelBase<Grid, Implementation>::fluidViscosity(const int phase,
|
||||
const ADB& p ,
|
||||
const ADB& temp ,
|
||||
const ADB& rs ,
|
||||
@ -1987,9 +1950,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
ADB
|
||||
BlackoilModelBase<Grid>::fluidReciprocFVF(const int phase,
|
||||
BlackoilModelBase<Grid, Implementation>::fluidReciprocFVF(const int phase,
|
||||
const ADB& p ,
|
||||
const ADB& temp ,
|
||||
const ADB& rs ,
|
||||
@ -2014,9 +1977,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
ADB
|
||||
BlackoilModelBase<Grid>::fluidDensity(const int phase,
|
||||
BlackoilModelBase<Grid, Implementation>::fluidDensity(const int phase,
|
||||
const ADB& p ,
|
||||
const ADB& temp ,
|
||||
const ADB& rs ,
|
||||
@ -2042,9 +2005,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
V
|
||||
BlackoilModelBase<Grid>::fluidRsSat(const V& p,
|
||||
BlackoilModelBase<Grid, Implementation>::fluidRsSat(const V& p,
|
||||
const V& satOil,
|
||||
const std::vector<int>& cells) const
|
||||
{
|
||||
@ -2055,9 +2018,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
ADB
|
||||
BlackoilModelBase<Grid>::fluidRsSat(const ADB& p,
|
||||
BlackoilModelBase<Grid, Implementation>::fluidRsSat(const ADB& p,
|
||||
const ADB& satOil,
|
||||
const std::vector<int>& cells) const
|
||||
{
|
||||
@ -2065,9 +2028,9 @@ namespace detail {
|
||||
}
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
V
|
||||
BlackoilModelBase<Grid>::fluidRvSat(const V& p,
|
||||
BlackoilModelBase<Grid, Implementation>::fluidRvSat(const V& p,
|
||||
const V& satOil,
|
||||
const std::vector<int>& cells) const
|
||||
{
|
||||
@ -2078,9 +2041,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
ADB
|
||||
BlackoilModelBase<Grid>::fluidRvSat(const ADB& p,
|
||||
BlackoilModelBase<Grid, Implementation>::fluidRvSat(const ADB& p,
|
||||
const ADB& satOil,
|
||||
const std::vector<int>& cells) const
|
||||
{
|
||||
@ -2089,9 +2052,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
ADB
|
||||
BlackoilModelBase<Grid>::poroMult(const ADB& p) const
|
||||
BlackoilModelBase<Grid, Implementation>::poroMult(const ADB& p) const
|
||||
{
|
||||
const int n = p.size();
|
||||
if (rock_comp_props_ && rock_comp_props_->isActive()) {
|
||||
@ -2117,9 +2080,9 @@ namespace detail {
|
||||
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
ADB
|
||||
BlackoilModelBase<Grid>::transMult(const ADB& p) const
|
||||
BlackoilModelBase<Grid, Implementation>::transMult(const ADB& p) const
|
||||
{
|
||||
const int n = p.size();
|
||||
if (rock_comp_props_ && rock_comp_props_->isActive()) {
|
||||
@ -2143,9 +2106,9 @@ namespace detail {
|
||||
|
||||
|
||||
/*
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
void
|
||||
BlackoilModelBase<Grid>::
|
||||
BlackoilModelBase<Grid, Implementation>::
|
||||
classifyCondition(const SolutionState& state,
|
||||
std::vector<PhasePresence>& cond ) const
|
||||
{
|
||||
@ -2185,9 +2148,9 @@ namespace detail {
|
||||
} */
|
||||
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
void
|
||||
BlackoilModelBase<Grid>::classifyCondition(const BlackoilState& state)
|
||||
BlackoilModelBase<Grid, Implementation>::classifyCondition(const BlackoilState& state)
|
||||
{
|
||||
using namespace Opm::AutoDiffGrid;
|
||||
const int nc = numCells(grid_);
|
||||
@ -2223,9 +2186,9 @@ namespace detail {
|
||||
|
||||
}
|
||||
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
void
|
||||
BlackoilModelBase<Grid>::updatePrimalVariableFromState(const BlackoilState& state)
|
||||
BlackoilModelBase<Grid, Implementation>::updatePrimalVariableFromState(const BlackoilState& state)
|
||||
{
|
||||
using namespace Opm::AutoDiffGrid;
|
||||
const int nc = numCells(grid_);
|
||||
@ -2273,9 +2236,9 @@ namespace detail {
|
||||
|
||||
|
||||
/// Update the phaseCondition_ member based on the primalVariable_ member.
|
||||
template <class Grid>
|
||||
template <class Grid, class Implementation>
|
||||
void
|
||||
BlackoilModelBase<Grid>::updatePhaseCondFromPrimalVariable()
|
||||
BlackoilModelBase<Grid, Implementation>::updatePhaseCondFromPrimalVariable()
|
||||
{
|
||||
if (! active_[Gas]) {
|
||||
OPM_THROW(std::logic_error, "updatePhaseCondFromPrimarVariable() logic requires active gas phase.");
|
||||
|
@ -136,44 +136,6 @@ namespace detail {
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <class Grid>
|
||||
void BlackoilModel<Grid>::ModelParameters::
|
||||
reset()
|
||||
{
|
||||
// default values for the solver parameters
|
||||
dp_max_rel_ = 1.0e9;
|
||||
ds_max_ = 0.2;
|
||||
dr_max_rel_ = 1.0e9;
|
||||
max_residual_allowed_ = 1e7;
|
||||
tolerance_mb_ = 1.0e-5;
|
||||
tolerance_cnv_ = 1.0e-2;
|
||||
tolerance_wells_ = 5.0e-1;
|
||||
}
|
||||
|
||||
template <class Grid>
|
||||
BlackoilModel<Grid>::ModelParameters::
|
||||
ModelParameters()
|
||||
{
|
||||
// set default values
|
||||
reset();
|
||||
}
|
||||
|
||||
template <class Grid>
|
||||
BlackoilModel<Grid>::ModelParameters::
|
||||
ModelParameters( const parameter::ParameterGroup& param )
|
||||
{
|
||||
// set default values
|
||||
reset();
|
||||
|
||||
// overload with given parameters
|
||||
dp_max_rel_ = param.getDefault("dp_max_rel", dp_max_rel_);
|
||||
ds_max_ = param.getDefault("ds_max", ds_max_);
|
||||
dr_max_rel_ = param.getDefault("dr_max_rel", dr_max_rel_);
|
||||
max_residual_allowed_ = param.getDefault("max_residual_allowed", max_residual_allowed_);
|
||||
tolerance_mb_ = param.getDefault("tolerance_mb", tolerance_mb_);
|
||||
tolerance_cnv_ = param.getDefault("tolerance_cnv", tolerance_cnv_);
|
||||
tolerance_wells_ = param.getDefault("tolerance_wells", tolerance_wells_ );
|
||||
}
|
||||
|
||||
|
||||
template <class Grid>
|
||||
|
Loading…
Reference in New Issue
Block a user