2018-11-15 04:07:47 -06:00
/*
2020-10-12 09:41:09 -05:00
Copyright 2015 , 2020 SINTEF Digital , Mathematics and Cybernetics .
2018-11-15 04:07:47 -06:00
Copyright 2015 IRIS AS
Copyright 2015 Dr . Blatt - HPC - Simulation - Software & Services
Copyright 2015 NTNU
Copyright 2015 Statoil AS
This file is part of the Open Porous Media project ( OPM ) .
OPM is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
OPM is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with OPM . If not , see < http : //www.gnu.org/licenses/>.
*/
# ifndef OPM_FLOWLINEARSOLVERPARAMETERS_HEADER_INCLUDED
# define OPM_FLOWLINEARSOLVERPARAMETERS_HEADER_INCLUDED
2022-08-16 03:45:32 -05:00
# include <opm/simulators/linalg/MILU.hpp>
2018-11-15 04:07:47 -06:00
2020-05-19 03:04:35 -05:00
# include <opm/simulators/linalg/linalgproperties.hh>
2019-09-16 03:58:20 -05:00
# include <opm/models/utils/parametersystem.hh>
2018-11-15 04:07:47 -06:00
2018-11-12 04:03:54 -06:00
namespace Opm {
template < class TypeTag >
2023-08-09 08:49:42 -05:00
class ISTLSolverEbosBda ;
2023-08-09 07:54:10 -05:00
template < class TypeTag >
2018-11-12 04:03:54 -06:00
class ISTLSolverEbos ;
}
2023-08-09 07:54:10 -05:00
2020-08-21 06:42:08 -05:00
namespace Opm : : Properties {
2018-11-15 04:07:47 -06:00
2020-08-27 03:30:29 -05:00
namespace TTag {
struct FlowIstlSolverParams { } ;
}
2018-11-15 04:07:47 -06:00
2020-08-27 04:38:38 -05:00
template < class TypeTag , class MyTypeTag >
struct LinearSolverReduction {
using type = UndefinedProperty ;
} ;
2023-03-28 04:43:00 -05:00
template < class TypeTag , class MyTypeTag >
struct RelaxedLinearSolverReduction {
using type = UndefinedProperty ;
} ;
2023-08-09 07:54:10 -05:00
2020-08-27 04:38:38 -05:00
template < class TypeTag , class MyTypeTag >
struct LinearSolverMaxIter {
using type = UndefinedProperty ;
} ;
template < class TypeTag , class MyTypeTag >
struct LinearSolverRestart {
using type = UndefinedProperty ;
} ;
2022-09-26 01:27:55 -05:00
//
2022-09-29 01:37:52 -05:00
// LinearSolverVerbosity defined in opm-models
//
2020-08-27 04:38:38 -05:00
template < class TypeTag , class MyTypeTag >
2023-06-09 06:46:45 -05:00
struct IluRelaxation {
using type = UndefinedProperty ;
} ;
template < class TypeTag , class MyTypeTag >
2020-08-27 04:38:38 -05:00
struct IluFillinLevel {
using type = UndefinedProperty ;
} ;
template < class TypeTag , class MyTypeTag >
struct MiluVariant {
using type = UndefinedProperty ;
} ;
template < class TypeTag , class MyTypeTag >
struct IluRedblack {
using type = UndefinedProperty ;
} ;
template < class TypeTag , class MyTypeTag >
struct IluReorderSpheres {
using type = UndefinedProperty ;
} ;
template < class TypeTag , class MyTypeTag >
struct UseGmres {
using type = UndefinedProperty ;
} ;
template < class TypeTag , class MyTypeTag >
struct LinearSolverIgnoreConvergenceFailure {
using type = UndefinedProperty ;
} ;
template < class TypeTag , class MyTypeTag >
2023-06-09 06:46:45 -05:00
struct ScaleLinearSystem {
2020-08-27 04:38:38 -05:00
using type = UndefinedProperty ;
} ;
template < class TypeTag , class MyTypeTag >
2023-06-09 06:46:45 -05:00
struct LinearSolver {
2020-08-27 04:38:38 -05:00
using type = UndefinedProperty ;
} ;
template < class TypeTag , class MyTypeTag >
2023-06-09 06:46:45 -05:00
struct LinearSolverPrintJsonDefinition {
2020-08-27 04:38:38 -05:00
using type = UndefinedProperty ;
} ;
2022-05-10 03:16:18 -05:00
template < class TypeTag , class MyTypeTag >
2023-06-09 06:46:45 -05:00
struct CprReuseSetup {
2022-05-10 03:16:18 -05:00
using type = UndefinedProperty ;
} ;
2020-08-27 04:38:38 -05:00
template < class TypeTag , class MyTypeTag >
2023-06-09 06:46:45 -05:00
struct CprReuseInterval {
2020-08-27 04:38:38 -05:00
using type = UndefinedProperty ;
} ;
template < class TypeTag , class MyTypeTag >
2020-12-22 05:57:01 -06:00
struct AcceleratorMode {
2020-08-27 04:38:38 -05:00
using type = UndefinedProperty ;
} ;
template < class TypeTag , class MyTypeTag >
struct BdaDeviceId {
using type = UndefinedProperty ;
} ;
template < class TypeTag , class MyTypeTag >
struct OpenclPlatformId {
using type = UndefinedProperty ;
} ;
2020-10-15 03:52:10 -05:00
template < class TypeTag , class MyTypeTag >
2022-09-27 08:54:19 -05:00
struct OpenclIluParallel {
2020-10-15 03:52:10 -05:00
using type = UndefinedProperty ;
} ;
2020-08-27 04:38:38 -05:00
template < class TypeTag >
struct LinearSolverReduction < TypeTag , TTag : : FlowIstlSolverParams > {
using type = GetPropType < TypeTag , Scalar > ;
static constexpr type value = 1e-2 ;
} ;
template < class TypeTag >
2023-03-28 04:43:00 -05:00
struct RelaxedLinearSolverReduction < TypeTag , TTag : : FlowIstlSolverParams > {
using type = GetPropType < TypeTag , Scalar > ;
static constexpr type value = 1e-2 ;
2023-08-09 07:54:10 -05:00
} ;
2023-03-28 04:43:00 -05:00
template < class TypeTag >
2020-08-27 04:38:38 -05:00
struct LinearSolverMaxIter < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr int value = 200 ;
} ;
template < class TypeTag >
struct LinearSolverRestart < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr int value = 40 ;
} ;
template < class TypeTag >
2022-09-26 01:27:55 -05:00
struct LinearSolverVerbosity < TypeTag , TTag : : FlowIstlSolverParams > {
2020-08-27 04:38:38 -05:00
static constexpr int value = 0 ;
} ;
template < class TypeTag >
2023-06-09 06:46:45 -05:00
struct IluRelaxation < TypeTag , TTag : : FlowIstlSolverParams > {
using type = GetPropType < TypeTag , Scalar > ;
static constexpr type value = 0.9 ;
} ;
template < class TypeTag >
2020-08-27 04:38:38 -05:00
struct IluFillinLevel < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr int value = 0 ;
} ;
2020-08-27 04:38:38 -05:00
template < class TypeTag >
struct MiluVariant < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr auto value = " ILU " ;
} ;
2020-08-27 04:38:38 -05:00
template < class TypeTag >
struct IluRedblack < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr bool value = false ;
} ;
template < class TypeTag >
struct IluReorderSpheres < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr bool value = false ;
} ;
template < class TypeTag >
struct UseGmres < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr bool value = false ;
} ;
template < class TypeTag >
struct LinearSolverIgnoreConvergenceFailure < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr bool value = false ;
} ;
template < class TypeTag >
2023-06-09 06:46:45 -05:00
struct ScaleLinearSystem < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr bool value = false ;
2020-08-27 04:38:38 -05:00
} ;
2020-08-27 04:38:38 -05:00
template < class TypeTag >
2023-06-09 06:46:45 -05:00
struct LinearSolver < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr auto value = " ilu0 " ;
2020-08-27 04:38:38 -05:00
} ;
2020-08-27 04:38:38 -05:00
template < class TypeTag >
2023-06-09 06:46:45 -05:00
struct LinearSolverPrintJsonDefinition < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr auto value = true ;
2020-08-27 04:38:38 -05:00
} ;
2020-08-27 04:38:38 -05:00
template < class TypeTag >
struct CprReuseSetup < TypeTag , TTag : : FlowIstlSolverParams > {
2022-12-21 06:23:26 -06:00
static constexpr int value = 4 ;
2020-08-27 04:38:38 -05:00
} ;
2022-05-10 03:16:18 -05:00
template < class TypeTag >
struct CprReuseInterval < TypeTag , TTag : : FlowIstlSolverParams > {
2022-12-21 06:23:26 -06:00
static constexpr int value = 30 ;
2022-05-10 03:16:18 -05:00
} ;
2020-08-27 04:38:38 -05:00
template < class TypeTag >
2020-12-22 05:57:01 -06:00
struct AcceleratorMode < TypeTag , TTag : : FlowIstlSolverParams > {
2020-08-27 04:38:38 -05:00
static constexpr auto value = " none " ;
} ;
2020-08-27 04:38:38 -05:00
template < class TypeTag >
struct BdaDeviceId < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr int value = 0 ;
} ;
template < class TypeTag >
struct OpenclPlatformId < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr int value = 0 ;
} ;
2020-10-15 03:52:10 -05:00
template < class TypeTag >
2022-09-27 08:54:19 -05:00
struct OpenclIluParallel < TypeTag , TTag : : FlowIstlSolverParams > {
static constexpr bool value = true ; // note: false should only be used in debug
2020-12-22 05:57:01 -06:00
} ;
2018-11-12 04:03:54 -06:00
2023-06-09 06:46:45 -05:00
// Set the backend to be used.
template < class TypeTag >
struct LinearSolverBackend < TypeTag , TTag : : FlowIstlSolverParams > {
2023-08-09 07:54:10 -05:00
# if COMPLE_BDA_BRIDGE
2023-08-09 08:49:42 -05:00
using type = ISTLSolverEbosBda < TypeTag > ;
2023-08-09 07:54:10 -05:00
# else
2023-06-09 06:46:45 -05:00
using type = ISTLSolverEbos < TypeTag > ;
2023-08-09 07:54:10 -05:00
# endif
2023-06-09 06:46:45 -05:00
} ;
2020-08-21 06:42:08 -05:00
} // namespace Opm::Properties
2018-11-15 04:07:47 -06:00
namespace Opm
{
/// This class carries all parameters for the NewtonIterationBlackoilInterleaved class.
struct FlowLinearSolverParameters
{
double linear_solver_reduction_ ;
2023-03-28 04:43:00 -05:00
double relaxed_linear_solver_reduction_ ;
2018-11-15 04:07:47 -06:00
int linear_solver_maxiter_ ;
int linear_solver_restart_ ;
int linear_solver_verbosity_ ;
2023-06-09 06:46:45 -05:00
double ilu_relaxation_ ;
2018-11-15 04:07:47 -06:00
int ilu_fillin_level_ ;
2021-05-05 04:22:44 -05:00
MILU_VARIANT ilu_milu_ ;
2018-11-15 04:07:47 -06:00
bool ilu_redblack_ ;
bool ilu_reorder_sphere_ ;
bool newton_use_gmres_ ;
bool ignoreConvergenceFailure_ ;
2019-03-12 07:55:11 -05:00
bool scale_linear_system_ ;
2020-10-12 10:03:00 -05:00
std : : string linsolver_ ;
2023-06-09 06:46:45 -05:00
bool linear_solver_print_json_definition_ ;
int cpr_reuse_setup_ ;
int cpr_reuse_interval_ ;
2020-12-22 05:57:01 -06:00
std : : string accelerator_mode_ ;
2020-07-01 12:43:22 -05:00
int bda_device_id_ ;
int opencl_platform_id_ ;
2022-09-27 08:54:19 -05:00
bool opencl_ilu_parallel_ ;
2018-11-15 04:07:47 -06:00
template < class TypeTag >
2023-01-18 14:42:31 -06:00
void init ( bool cprRequestedInDataFile )
2018-11-15 04:07:47 -06:00
{
// TODO: these parameters have undocumented non-trivial dependencies
linear_solver_reduction_ = EWOMS_GET_PARAM ( TypeTag , double , LinearSolverReduction ) ;
2023-03-28 04:43:00 -05:00
relaxed_linear_solver_reduction_ = EWOMS_GET_PARAM ( TypeTag , double , RelaxedLinearSolverReduction ) ;
2018-11-15 04:07:47 -06:00
linear_solver_maxiter_ = EWOMS_GET_PARAM ( TypeTag , int , LinearSolverMaxIter ) ;
linear_solver_restart_ = EWOMS_GET_PARAM ( TypeTag , int , LinearSolverRestart ) ;
2022-09-26 01:27:55 -05:00
linear_solver_verbosity_ = EWOMS_GET_PARAM ( TypeTag , int , LinearSolverVerbosity ) ;
2023-06-09 06:46:45 -05:00
ilu_relaxation_ = EWOMS_GET_PARAM ( TypeTag , double , IluRelaxation ) ;
2018-11-15 04:07:47 -06:00
ilu_fillin_level_ = EWOMS_GET_PARAM ( TypeTag , int , IluFillinLevel ) ;
ilu_milu_ = convertString2Milu ( EWOMS_GET_PARAM ( TypeTag , std : : string , MiluVariant ) ) ;
ilu_redblack_ = EWOMS_GET_PARAM ( TypeTag , bool , IluRedblack ) ;
ilu_reorder_sphere_ = EWOMS_GET_PARAM ( TypeTag , bool , IluReorderSpheres ) ;
newton_use_gmres_ = EWOMS_GET_PARAM ( TypeTag , bool , UseGmres ) ;
ignoreConvergenceFailure_ = EWOMS_GET_PARAM ( TypeTag , bool , LinearSolverIgnoreConvergenceFailure ) ;
2019-03-14 03:04:51 -05:00
scale_linear_system_ = EWOMS_GET_PARAM ( TypeTag , bool , ScaleLinearSystem ) ;
2023-06-09 06:46:45 -05:00
linsolver_ = EWOMS_GET_PARAM ( TypeTag , std : : string , LinearSolver ) ;
linear_solver_print_json_definition_ = EWOMS_GET_PARAM ( TypeTag , bool , LinearSolverPrintJsonDefinition ) ;
2019-03-14 03:04:51 -05:00
cpr_reuse_setup_ = EWOMS_GET_PARAM ( TypeTag , int , CprReuseSetup ) ;
2022-05-10 03:16:18 -05:00
cpr_reuse_interval_ = EWOMS_GET_PARAM ( TypeTag , int , CprReuseInterval ) ;
2023-01-18 14:42:31 -06:00
2023-06-09 06:46:45 -05:00
if ( ! EWOMS_PARAM_IS_SET ( TypeTag , std : : string , LinearSolver ) & & cprRequestedInDataFile ) {
2023-01-18 14:42:31 -06:00
linsolver_ = " cpr " ;
} else {
linsolver_ = EWOMS_GET_PARAM ( TypeTag , std : : string , LinearSolver ) ;
}
2020-12-22 05:57:01 -06:00
accelerator_mode_ = EWOMS_GET_PARAM ( TypeTag , std : : string , AcceleratorMode ) ;
2020-07-01 12:43:22 -05:00
bda_device_id_ = EWOMS_GET_PARAM ( TypeTag , int , BdaDeviceId ) ;
opencl_platform_id_ = EWOMS_GET_PARAM ( TypeTag , int , OpenclPlatformId ) ;
2022-09-27 08:54:19 -05:00
opencl_ilu_parallel_ = EWOMS_GET_PARAM ( TypeTag , bool , OpenclIluParallel ) ;
2018-11-15 04:07:47 -06:00
}
template < class TypeTag >
static void registerParameters ( )
{
2023-06-09 06:46:45 -05:00
EWOMS_REGISTER_PARAM ( TypeTag , double , LinearSolverReduction , " The minimum reduction of the residual which the linear solver must achieve " ) ;
2023-03-28 04:43:00 -05:00
EWOMS_REGISTER_PARAM ( TypeTag , double , RelaxedLinearSolverReduction , " The minimum reduction of the residual which the linear solver need to achieve for the solution to be accepted " ) ;
2018-11-15 04:07:47 -06:00
EWOMS_REGISTER_PARAM ( TypeTag , int , LinearSolverMaxIter , " The maximum number of iterations of the linear solver " ) ;
EWOMS_REGISTER_PARAM ( TypeTag , int , LinearSolverRestart , " The number of iterations after which GMRES is restarted " ) ;
2022-09-26 01:27:55 -05:00
EWOMS_REGISTER_PARAM ( TypeTag , int , LinearSolverVerbosity , " The verbosity level of the linear solver (0: off, 2: all) " ) ;
2023-06-09 06:46:45 -05:00
EWOMS_REGISTER_PARAM ( TypeTag , double , IluRelaxation , " The relaxation factor of the linear solver's ILU preconditioner " ) ;
2018-11-15 04:07:47 -06:00
EWOMS_REGISTER_PARAM ( TypeTag , int , IluFillinLevel , " The fill-in level of the linear solver's ILU preconditioner " ) ;
2021-07-02 07:56:19 -05:00
EWOMS_REGISTER_PARAM ( TypeTag , std : : string , MiluVariant , " Specify which variant of the modified-ILU preconditioner ought to be used. Possible variants are: ILU (default, plain ILU), MILU_1 (lump diagonal with dropped row entries), MILU_2 (lump diagonal with the sum of the absolute values of the dropped row entries), MILU_3 (if diagonal is positive add sum of dropped row entrires. Otherwise subtract them), MILU_4 (if diagonal is positive add sum of dropped row entrires. Otherwise do nothing " ) ;
EWOMS_REGISTER_PARAM ( TypeTag , bool , IluRedblack , " Use red-black partitioning for the ILU preconditioner " ) ;
2018-11-15 04:07:47 -06:00
EWOMS_REGISTER_PARAM ( TypeTag , bool , IluReorderSpheres , " Whether to reorder the entries of the matrix in the red-black ILU preconditioner in spheres starting at an edge. If false the original ordering is preserved in each color. Otherwise why try to ensure D4 ordering (in a 2D structured grid, the diagonal elements are consecutive). " ) ;
EWOMS_REGISTER_PARAM ( TypeTag , bool , UseGmres , " Use GMRES as the linear solver " ) ;
EWOMS_REGISTER_PARAM ( TypeTag , bool , LinearSolverIgnoreConvergenceFailure , " Continue with the simulation like nothing happened after the linear solver did not converge " ) ;
2019-03-14 03:04:51 -05:00
EWOMS_REGISTER_PARAM ( TypeTag , bool , ScaleLinearSystem , " Scale linear system according to equation scale and primary variable types " ) ;
2023-08-31 03:04:18 -05:00
EWOMS_REGISTER_PARAM ( TypeTag , std : : string , LinearSolver , " Configuration of solver. Valid options are: ilu0 (default), cprw, cpr (an alias for cprw), cpr_quasiimpes, cpr_trueimpes, amg or hybrid (experimental). Alternatively, you can request a configuration to be read from a JSON file by giving the filename here, ending with '.json.' " ) ;
2023-06-09 06:46:45 -05:00
EWOMS_REGISTER_PARAM ( TypeTag , bool , LinearSolverPrintJsonDefinition , " Write the JSON definition of the linear solver setup to the DBG file. " ) ;
2022-06-02 06:33:23 -05:00
EWOMS_REGISTER_PARAM ( TypeTag , int , CprReuseSetup , " Reuse preconditioner setup. Valid options are 0: recreate the preconditioner for every linear solve, 1: recreate once every timestep, 2: recreate if last linear solve took more than 10 iterations, 3: never recreate, 4: recreated every CprReuseInterval " ) ;
2022-06-10 08:59:45 -05:00
EWOMS_REGISTER_PARAM ( TypeTag , int , CprReuseInterval , " Reuse preconditioner interval. Used when CprReuseSetup is set to 4, then the preconditioner will be fully recreated instead of reused every N linear solve, where N is this parameter. " ) ;
2022-11-17 02:27:00 -06:00
EWOMS_REGISTER_PARAM ( TypeTag , std : : string , AcceleratorMode , " Choose a linear solver, usage: '--accelerator-mode=[none|cusparse|opencl|amgcl|rocalution]' " ) ;
2020-07-07 07:26:02 -05:00
EWOMS_REGISTER_PARAM ( TypeTag , int , BdaDeviceId , " Choose device ID for cusparseSolver or openclSolver, use 'nvidia-smi' or 'clinfo' to determine valid IDs " ) ;
EWOMS_REGISTER_PARAM ( TypeTag , int , OpenclPlatformId , " Choose platform ID for openclSolver, use 'clinfo' to determine valid platform IDs " ) ;
2022-10-27 02:24:33 -05:00
EWOMS_REGISTER_PARAM ( TypeTag , bool , OpenclIluParallel , " Parallelize ILU decomposition and application on GPU " ) ;
2018-11-15 04:07:47 -06:00
}
FlowLinearSolverParameters ( ) { reset ( ) ; }
// set default values
void reset ( )
{
2023-03-28 04:43:00 -05:00
relaxed_linear_solver_reduction_ = 1e-2 ;
2023-06-09 06:46:45 -05:00
linear_solver_reduction_ = 1e-2 ;
linear_solver_maxiter_ = 200 ;
linear_solver_restart_ = 40 ;
linear_solver_verbosity_ = 0 ;
2018-11-15 04:07:47 -06:00
ilu_relaxation_ = 0.9 ;
2023-06-09 06:46:45 -05:00
ilu_fillin_level_ = 0 ;
2018-11-15 04:07:47 -06:00
ilu_milu_ = MILU_VARIANT : : ILU ;
ilu_redblack_ = false ;
2023-06-09 06:46:45 -05:00
ilu_reorder_sphere_ = false ;
newton_use_gmres_ = false ;
ignoreConvergenceFailure_ = false ;
scale_linear_system_ = false ;
linsolver_ = " ilu0 " ;
linear_solver_print_json_definition_ = true ;
cpr_reuse_setup_ = 4 ;
cpr_reuse_interval_ = 30 ;
2020-12-22 05:57:01 -06:00
accelerator_mode_ = " none " ;
2020-07-01 12:43:22 -05:00
bda_device_id_ = 0 ;
opencl_platform_id_ = 0 ;
2022-09-27 08:54:19 -05:00
opencl_ilu_parallel_ = true ;
2018-11-15 04:07:47 -06:00
}
} ;
} // namespace Opm
# endif // OPM_FLOWLINEARSOLVERPARAMETERS_HEADER_INCLUDED