mirror of
https://github.com/OPM/opm-simulators.git
synced 2024-12-02 05:49:09 -06:00
NewtonIterationBlackoilInterleaved: make parameter a struct to avoid multi reading.
This commit is contained in:
parent
28902065cf
commit
885aedb1e8
@ -85,25 +85,14 @@ namespace Opm
|
|||||||
public:
|
public:
|
||||||
typedef NewtonIterationBlackoilInterface :: SolutionVector SolutionVector;
|
typedef NewtonIterationBlackoilInterface :: SolutionVector SolutionVector;
|
||||||
/// Construct a system solver.
|
/// Construct a system solver.
|
||||||
/// \param[in] param parameters controlling the behaviour of
|
/// \param[in] param parameters controlling the behaviour of the linear solvers
|
||||||
/// the preconditioning and choice of
|
|
||||||
/// linear solvers.
|
|
||||||
/// Parameters:
|
|
||||||
/// cpr_relax (default 1.0) relaxation for the preconditioner
|
|
||||||
/// cpr_ilu_n (default 0) use ILU(n) for preconditioning of the linear system
|
|
||||||
/// cpr_use_amg (default false) if true, use AMG preconditioner for elliptic part
|
|
||||||
/// cpr_use_bicgstab (default true) if true, use BiCGStab (else use CG) for elliptic part
|
|
||||||
/// \param[in] parallelInformation In the case of a parallel run
|
/// \param[in] parallelInformation In the case of a parallel run
|
||||||
/// with dune-istl the information about the parallelization.
|
/// with dune-istl the information about the parallelization.
|
||||||
NewtonIterationBlackoilInterleavedImpl(const parameter::ParameterGroup& param,
|
NewtonIterationBlackoilInterleavedImpl(const NewtonIterationBlackoilInterleavedParameters& param,
|
||||||
const boost::any& parallelInformation_arg=boost::any())
|
const boost::any& parallelInformation_arg=boost::any())
|
||||||
: iterations_( 0 ),
|
: iterations_( 0 ),
|
||||||
parallelInformation_(parallelInformation_arg),
|
parallelInformation_(parallelInformation_arg),
|
||||||
newton_use_gmres_( param.getDefault("newton_use_gmres", false ) ),
|
parameters_( param )
|
||||||
linear_solver_reduction_( param.getDefault("linear_solver_reduction", 1e-2 ) ),
|
|
||||||
linear_solver_maxiter_( param.getDefault("linear_solver_maxiter", 50 ) ),
|
|
||||||
linear_solver_restart_( param.getDefault("linear_solver_restart", 40 ) ),
|
|
||||||
linear_solver_verbosity_( param.getDefault("linear_solver_verbosity", 0 ))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,15 +193,20 @@ namespace Opm
|
|||||||
// TODO: Revise when linear solvers interface opm-core is done
|
// TODO: Revise when linear solvers interface opm-core is done
|
||||||
// Construct linear solver.
|
// Construct linear solver.
|
||||||
// GMRes solver
|
// GMRes solver
|
||||||
if ( newton_use_gmres_ ) {
|
if ( parameters_.newton_use_gmres_ ) {
|
||||||
Dune::RestartedGMResSolver<Vector> linsolve(opA, sp, precond,
|
Dune::RestartedGMResSolver<Vector> linsolve(opA, sp, precond,
|
||||||
linear_solver_reduction_, linear_solver_restart_, linear_solver_maxiter_, linear_solver_verbosity_);
|
parameters_.linear_solver_reduction_,
|
||||||
|
parameters_.linear_solver_restart_,
|
||||||
|
parameters_.linear_solver_maxiter_,
|
||||||
|
parameters_.linear_solver_verbosity_);
|
||||||
// Solve system.
|
// Solve system.
|
||||||
linsolve.apply(x, istlb, result);
|
linsolve.apply(x, istlb, result);
|
||||||
}
|
}
|
||||||
else { // BiCGstab solver
|
else { // BiCGstab solver
|
||||||
Dune::BiCGSTABSolver<Vector> linsolve(opA, sp, precond,
|
Dune::BiCGSTABSolver<Vector> linsolve(opA, sp, precond,
|
||||||
linear_solver_reduction_, linear_solver_maxiter_, linear_solver_verbosity_);
|
parameters_.linear_solver_reduction_,
|
||||||
|
parameters_.linear_solver_maxiter_,
|
||||||
|
parameters_.linear_solver_verbosity_);
|
||||||
// Solve system.
|
// Solve system.
|
||||||
linsolve.apply(x, istlb, result);
|
linsolve.apply(x, istlb, result);
|
||||||
}
|
}
|
||||||
@ -423,12 +417,7 @@ namespace Opm
|
|||||||
mutable int iterations_;
|
mutable int iterations_;
|
||||||
boost::any parallelInformation_;
|
boost::any parallelInformation_;
|
||||||
|
|
||||||
const bool newton_use_gmres_;
|
NewtonIterationBlackoilInterleavedParameters parameters_;
|
||||||
const double linear_solver_reduction_;
|
|
||||||
const int linear_solver_maxiter_;
|
|
||||||
const int linear_solver_restart_;
|
|
||||||
const int linear_solver_verbosity_;
|
|
||||||
|
|
||||||
}; // end NewtonIterationBlackoilInterleavedImpl
|
}; // end NewtonIterationBlackoilInterleavedImpl
|
||||||
|
|
||||||
|
|
||||||
@ -437,7 +426,7 @@ namespace Opm
|
|||||||
NewtonIterationBlackoilInterleaved::NewtonIterationBlackoilInterleaved(const parameter::ParameterGroup& param,
|
NewtonIterationBlackoilInterleaved::NewtonIterationBlackoilInterleaved(const parameter::ParameterGroup& param,
|
||||||
const boost::any& parallelInformation_arg)
|
const boost::any& parallelInformation_arg)
|
||||||
: newtonIncrement_(),
|
: newtonIncrement_(),
|
||||||
param_( param ),
|
parameters_( param ),
|
||||||
parallelInformation_(parallelInformation_arg),
|
parallelInformation_(parallelInformation_arg),
|
||||||
iterations_( 0 )
|
iterations_( 0 )
|
||||||
{
|
{
|
||||||
@ -451,7 +440,7 @@ namespace Opm
|
|||||||
template <class NewtonIncVector>
|
template <class NewtonIncVector>
|
||||||
static const NewtonIterationBlackoilInterface&
|
static const NewtonIterationBlackoilInterface&
|
||||||
get( NewtonIncVector& newtonIncrements,
|
get( NewtonIncVector& newtonIncrements,
|
||||||
const parameter::ParameterGroup& param,
|
const NewtonIterationBlackoilInterleavedParameters& param,
|
||||||
const boost::any& parallelInformation,
|
const boost::any& parallelInformation,
|
||||||
const int np )
|
const int np )
|
||||||
{
|
{
|
||||||
@ -471,17 +460,16 @@ namespace Opm
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct NewtonIncrement< 1 >
|
struct NewtonIncrement< 0 >
|
||||||
{
|
{
|
||||||
template <class NewtonIncVector>
|
template <class NewtonIncVector>
|
||||||
static const NewtonIterationBlackoilInterface&
|
static const NewtonIterationBlackoilInterface&
|
||||||
get( NewtonIncVector& newtonIncrements,
|
get( NewtonIncVector& newtonIncrements,
|
||||||
const parameter::ParameterGroup& param,
|
const NewtonIterationBlackoilInterleavedParameters&,
|
||||||
const boost::any& parallelInformation,
|
const boost::any&,
|
||||||
const int np )
|
const int )
|
||||||
{
|
{
|
||||||
OPM_THROW(std::runtime_error,"NewtonIncrement::get: number of variables not supported yet. Adjust maxNumberEquations appropriately to cover np = " << np);
|
OPM_THROW(std::runtime_error,"NewtonIncrement::get: number of variables not supported yet. Adjust maxNumberEquations appropriately to cover np = " << 0);
|
||||||
return *(newtonIncrements[ 0 ]);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -497,7 +485,7 @@ namespace Opm
|
|||||||
// covered, this is mostly to reduce compile time. Adjust accordingly to cover
|
// covered, this is mostly to reduce compile time. Adjust accordingly to cover
|
||||||
// more cases
|
// more cases
|
||||||
const NewtonIterationBlackoilInterface& newtonIncrement =
|
const NewtonIterationBlackoilInterface& newtonIncrement =
|
||||||
detail::NewtonIncrement< maxNumberEquations_ > :: get( newtonIncrement_, param_, parallelInformation_, np );
|
detail::NewtonIncrement< maxNumberEquations_ > :: get( newtonIncrement_, parameters_, parallelInformation_, np );
|
||||||
|
|
||||||
// compute newton increment
|
// compute newton increment
|
||||||
SolutionVector dx = newtonIncrement.computeNewtonIncrement( residual );
|
SolutionVector dx = newtonIncrement.computeNewtonIncrement( residual );
|
||||||
|
@ -34,6 +34,41 @@
|
|||||||
|
|
||||||
namespace Opm
|
namespace Opm
|
||||||
{
|
{
|
||||||
|
/// This class carries all parameters for the NewtonIterationBlackoilInterleaved class
|
||||||
|
struct NewtonIterationBlackoilInterleavedParameters
|
||||||
|
{
|
||||||
|
double linear_solver_reduction_;
|
||||||
|
int linear_solver_maxiter_;
|
||||||
|
int linear_solver_restart_;
|
||||||
|
int linear_solver_verbosity_;
|
||||||
|
bool newton_use_gmres_;
|
||||||
|
|
||||||
|
NewtonIterationBlackoilInterleavedParameters() { reset(); }
|
||||||
|
// read values from parameter class
|
||||||
|
NewtonIterationBlackoilInterleavedParameters( const parameter::ParameterGroup& param )
|
||||||
|
{
|
||||||
|
// set default parameters
|
||||||
|
reset();
|
||||||
|
|
||||||
|
// read parameters (using previsouly set default values)
|
||||||
|
newton_use_gmres_ = param.getDefault("newton_use_gmres", newton_use_gmres_ );
|
||||||
|
linear_solver_reduction_ = param.getDefault("linear_solver_reduction", linear_solver_reduction_ );
|
||||||
|
linear_solver_maxiter_ = param.getDefault("linear_solver_maxiter", linear_solver_maxiter_);
|
||||||
|
linear_solver_restart_ = param.getDefault("linear_solver_restart", linear_solver_restart_);
|
||||||
|
linear_solver_verbosity_ = param.getDefault("linear_solver_verbosity", linear_solver_verbosity_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set default values
|
||||||
|
void reset()
|
||||||
|
{
|
||||||
|
newton_use_gmres_ = false;
|
||||||
|
linear_solver_reduction_ = 1e-2;
|
||||||
|
linear_solver_maxiter_ = 50;
|
||||||
|
linear_solver_restart_ = 40;
|
||||||
|
linear_solver_verbosity_ = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/// This class solves the fully implicit black-oil system by
|
/// This class solves the fully implicit black-oil system by
|
||||||
/// solving the reduced system (after eliminating well variables)
|
/// solving the reduced system (after eliminating well variables)
|
||||||
@ -73,8 +108,8 @@ namespace Opm
|
|||||||
// max number of equations supported, increase if necessary
|
// max number of equations supported, increase if necessary
|
||||||
static const int maxNumberEquations_ = 6 ;
|
static const int maxNumberEquations_ = 6 ;
|
||||||
|
|
||||||
mutable std::array< std::unique_ptr< NewtonIterationBlackoilInterface >, maxNumberEquations_ > newtonIncrement_;
|
mutable std::array< std::unique_ptr< NewtonIterationBlackoilInterface >, maxNumberEquations_+1 > newtonIncrement_;
|
||||||
const parameter::ParameterGroup& param_;
|
NewtonIterationBlackoilInterleavedParameters parameters_;
|
||||||
boost::any parallelInformation_;
|
boost::any parallelInformation_;
|
||||||
mutable int iterations_;
|
mutable int iterations_;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user