My Project
Loading...
Searching...
No Matches
FlowLinearSolverParameters.hpp
1/*
2 Copyright 2015, 2020 SINTEF Digital, Mathematics and Cybernetics.
3 Copyright 2015 IRIS AS
4 Copyright 2015 Dr. Blatt - HPC-Simulation-Software & Services
5 Copyright 2015 NTNU
6 Copyright 2015 Statoil 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_FLOWLINEARSOLVERPARAMETERS_HEADER_INCLUDED
25#define OPM_FLOWLINEARSOLVERPARAMETERS_HEADER_INCLUDED
26
27#include <opm/simulators/linalg/MILU.hpp>
28
29#include <opm/simulators/linalg/linalgproperties.hh>
30#include <opm/models/utils/parametersystem.hh>
31
32namespace Opm {
33template <class TypeTag>
34class ISTLSolverEbosBda;
35template <class TypeTag>
36class ISTLSolverEbos;
37}
38
39
40
41namespace Opm::Properties {
42
43namespace TTag {
45}
46
47template<class TypeTag, class MyTypeTag>
51
52template<class TypeTag, class MyTypeTag>
56
57template<class TypeTag, class MyTypeTag>
59 using type = UndefinedProperty;
60};
61template<class TypeTag, class MyTypeTag>
63 using type = UndefinedProperty;
64};
65//
66// LinearSolverVerbosity defined in opm-models
67//
68template<class TypeTag, class MyTypeTag>
70 using type = UndefinedProperty;
71};
72template<class TypeTag, class MyTypeTag>
74 using type = UndefinedProperty;
75};
76template<class TypeTag, class MyTypeTag>
78 using type = UndefinedProperty;
79};
80template<class TypeTag, class MyTypeTag>
82 using type = UndefinedProperty;
83};
84template<class TypeTag, class MyTypeTag>
86 using type = UndefinedProperty;
87};
88template<class TypeTag, class MyTypeTag>
89struct UseGmres {
90 using type = UndefinedProperty;
91};
92template<class TypeTag, class MyTypeTag>
96template<class TypeTag, class MyTypeTag>
98 using type = UndefinedProperty;
99};
100template<class TypeTag, class MyTypeTag>
102 using type = UndefinedProperty;
103};
104template<class TypeTag, class MyTypeTag>
108template<class TypeTag, class MyTypeTag>
110 using type = UndefinedProperty;
111};
112template<class TypeTag, class MyTypeTag>
114 using type = UndefinedProperty;
115};
116template<class TypeTag, class MyTypeTag>
118 using type = UndefinedProperty;
119};
120template<class TypeTag, class MyTypeTag>
122 using type = UndefinedProperty;
123};
124template<class TypeTag, class MyTypeTag>
126 using type = UndefinedProperty;
127};
128template<class TypeTag, class MyTypeTag>
130 using type = UndefinedProperty;
131};
132template<class TypeTag>
133struct LinearSolverReduction<TypeTag, TTag::FlowIstlSolverParams> {
134 using type = GetPropType<TypeTag, Scalar>;
135 static constexpr type value = 1e-2;
136};
137template<class TypeTag>
138struct RelaxedLinearSolverReduction<TypeTag, TTag::FlowIstlSolverParams> {
139 using type = GetPropType<TypeTag, Scalar>;
140 static constexpr type value = 1e-2;
141};
142template<class TypeTag>
143struct LinearSolverMaxIter<TypeTag, TTag::FlowIstlSolverParams> {
144 static constexpr int value = 200;
145};
146template<class TypeTag>
147struct LinearSolverRestart<TypeTag, TTag::FlowIstlSolverParams> {
148 static constexpr int value = 40;
149};
150template<class TypeTag>
151struct LinearSolverVerbosity<TypeTag, TTag::FlowIstlSolverParams> {
152 static constexpr int value = 0;
153};
154template<class TypeTag>
155struct IluRelaxation<TypeTag, TTag::FlowIstlSolverParams> {
156 using type = GetPropType<TypeTag, Scalar>;
157 static constexpr type value = 0.9;
158};
159template<class TypeTag>
160struct IluFillinLevel<TypeTag, TTag::FlowIstlSolverParams> {
161 static constexpr int value = 0;
162};
163template<class TypeTag>
164struct MiluVariant<TypeTag, TTag::FlowIstlSolverParams> {
165 static constexpr auto value = "ILU";
166};
167template<class TypeTag>
168struct IluRedblack<TypeTag, TTag::FlowIstlSolverParams> {
169 static constexpr bool value = false;
170};
171template<class TypeTag>
172struct IluReorderSpheres<TypeTag, TTag::FlowIstlSolverParams> {
173 static constexpr bool value = false;
174};
175template<class TypeTag>
176struct UseGmres<TypeTag, TTag::FlowIstlSolverParams> {
177 static constexpr bool value = false;
178};
179template<class TypeTag>
180struct LinearSolverIgnoreConvergenceFailure<TypeTag, TTag::FlowIstlSolverParams> {
181 static constexpr bool value = false;
182};
183template<class TypeTag>
184struct ScaleLinearSystem<TypeTag, TTag::FlowIstlSolverParams> {
185 static constexpr bool value = false;
186};
187template<class TypeTag>
188struct LinearSolver<TypeTag, TTag::FlowIstlSolverParams> {
189 static constexpr auto value = "ilu0";
190};
191template<class TypeTag>
192struct LinearSolverPrintJsonDefinition<TypeTag, TTag::FlowIstlSolverParams> {
193 static constexpr auto value = true;
194};
195template<class TypeTag>
196struct CprReuseSetup<TypeTag, TTag::FlowIstlSolverParams> {
197 static constexpr int value = 4;
198};
199template<class TypeTag>
200struct CprReuseInterval<TypeTag, TTag::FlowIstlSolverParams> {
201 static constexpr int value = 30;
202};
203template<class TypeTag>
204struct AcceleratorMode<TypeTag, TTag::FlowIstlSolverParams> {
205 static constexpr auto value = "none";
206};
207template<class TypeTag>
208struct BdaDeviceId<TypeTag, TTag::FlowIstlSolverParams> {
209 static constexpr int value = 0;
210};
211template<class TypeTag>
212struct OpenclPlatformId<TypeTag, TTag::FlowIstlSolverParams> {
213 static constexpr int value = 0;
214};
215template<class TypeTag>
216struct OpenclIluParallel<TypeTag, TTag::FlowIstlSolverParams> {
217 static constexpr bool value = true; // note: false should only be used in debug
218};
219
220// Set the backend to be used.
221template<class TypeTag>
222struct LinearSolverBackend<TypeTag, TTag::FlowIstlSolverParams> {
223#if COMPILE_BDA_BRIDGE
225#else
227#endif
228};
229} // namespace Opm::Properties
230
231namespace Opm
232{
233
234
237 {
238 double linear_solver_reduction_;
239 double relaxed_linear_solver_reduction_;
240 int linear_solver_maxiter_;
241 int linear_solver_restart_;
242 int linear_solver_verbosity_;
243 double ilu_relaxation_;
244 int ilu_fillin_level_;
245 MILU_VARIANT ilu_milu_;
246 bool ilu_redblack_;
247 bool ilu_reorder_sphere_;
248 bool newton_use_gmres_;
249 bool ignoreConvergenceFailure_;
250 bool scale_linear_system_;
251 std::string linsolver_;
252 bool linear_solver_print_json_definition_;
253 int cpr_reuse_setup_;
254 int cpr_reuse_interval_;
255 std::string accelerator_mode_;
256 int bda_device_id_;
257 int opencl_platform_id_;
258 bool opencl_ilu_parallel_;
259
260 template <class TypeTag>
261 void init(bool cprRequestedInDataFile)
262 {
263 // TODO: these parameters have undocumented non-trivial dependencies
264 linear_solver_reduction_ = EWOMS_GET_PARAM(TypeTag, double, LinearSolverReduction);
265 relaxed_linear_solver_reduction_ = EWOMS_GET_PARAM(TypeTag, double, RelaxedLinearSolverReduction);
266 linear_solver_maxiter_ = EWOMS_GET_PARAM(TypeTag, int, LinearSolverMaxIter);
267 linear_solver_restart_ = EWOMS_GET_PARAM(TypeTag, int, LinearSolverRestart);
268 linear_solver_verbosity_ = EWOMS_GET_PARAM(TypeTag, int, LinearSolverVerbosity);
269 ilu_relaxation_ = EWOMS_GET_PARAM(TypeTag, double, IluRelaxation);
270 ilu_fillin_level_ = EWOMS_GET_PARAM(TypeTag, int, IluFillinLevel);
271 ilu_milu_ = convertString2Milu(EWOMS_GET_PARAM(TypeTag, std::string, MiluVariant));
272 ilu_redblack_ = EWOMS_GET_PARAM(TypeTag, bool, IluRedblack);
273 ilu_reorder_sphere_ = EWOMS_GET_PARAM(TypeTag, bool, IluReorderSpheres);
274 newton_use_gmres_ = EWOMS_GET_PARAM(TypeTag, bool, UseGmres);
275 ignoreConvergenceFailure_ = EWOMS_GET_PARAM(TypeTag, bool, LinearSolverIgnoreConvergenceFailure);
276 scale_linear_system_ = EWOMS_GET_PARAM(TypeTag, bool, ScaleLinearSystem);
277 linsolver_ = EWOMS_GET_PARAM(TypeTag, std::string, LinearSolver);
278 linear_solver_print_json_definition_ = EWOMS_GET_PARAM(TypeTag, bool, LinearSolverPrintJsonDefinition);
279 cpr_reuse_setup_ = EWOMS_GET_PARAM(TypeTag, int, CprReuseSetup);
280 cpr_reuse_interval_ = EWOMS_GET_PARAM(TypeTag, int, CprReuseInterval);
281
282 if (!EWOMS_PARAM_IS_SET(TypeTag, std::string, LinearSolver) && cprRequestedInDataFile) {
283 linsolver_ = "cpr";
284 } else {
285 linsolver_ = EWOMS_GET_PARAM(TypeTag, std::string, LinearSolver);
286 }
287
288 accelerator_mode_ = EWOMS_GET_PARAM(TypeTag, std::string, AcceleratorMode);
289 bda_device_id_ = EWOMS_GET_PARAM(TypeTag, int, BdaDeviceId);
290 opencl_platform_id_ = EWOMS_GET_PARAM(TypeTag, int, OpenclPlatformId);
291 opencl_ilu_parallel_ = EWOMS_GET_PARAM(TypeTag, bool, OpenclIluParallel);
292 }
293
294 template <class TypeTag>
295 static void registerParameters()
296 {
297 EWOMS_REGISTER_PARAM(TypeTag, double, LinearSolverReduction, "The minimum reduction of the residual which the linear solver must achieve");
298 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");
299 EWOMS_REGISTER_PARAM(TypeTag, int, LinearSolverMaxIter, "The maximum number of iterations of the linear solver");
300 EWOMS_REGISTER_PARAM(TypeTag, int, LinearSolverRestart, "The number of iterations after which GMRES is restarted");
301 EWOMS_REGISTER_PARAM(TypeTag, int, LinearSolverVerbosity, "The verbosity level of the linear solver (0: off, 2: all)");
302 EWOMS_REGISTER_PARAM(TypeTag, double, IluRelaxation, "The relaxation factor of the linear solver's ILU preconditioner");
303 EWOMS_REGISTER_PARAM(TypeTag, int, IluFillinLevel, "The fill-in level of the linear solver's ILU preconditioner");
304 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");
305 EWOMS_REGISTER_PARAM(TypeTag, bool, IluRedblack, "Use red-black partitioning for the ILU preconditioner");
306 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).");
307 EWOMS_REGISTER_PARAM(TypeTag, bool, UseGmres, "Use GMRES as the linear solver");
308 EWOMS_REGISTER_PARAM(TypeTag, bool, LinearSolverIgnoreConvergenceFailure, "Continue with the simulation like nothing happened after the linear solver did not converge");
309 EWOMS_REGISTER_PARAM(TypeTag, bool, ScaleLinearSystem, "Scale linear system according to equation scale and primary variable types");
310 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.'");
311 EWOMS_REGISTER_PARAM(TypeTag, bool, LinearSolverPrintJsonDefinition, "Write the JSON definition of the linear solver setup to the DBG file.");
312 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");
313 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.");
314 EWOMS_REGISTER_PARAM(TypeTag, std::string, AcceleratorMode, "Choose a linear solver, usage: '--accelerator-mode=[none|cusparse|opencl|amgcl|rocalution]'");
315 EWOMS_REGISTER_PARAM(TypeTag, int, BdaDeviceId, "Choose device ID for cusparseSolver or openclSolver, use 'nvidia-smi' or 'clinfo' to determine valid IDs");
316 EWOMS_REGISTER_PARAM(TypeTag, int, OpenclPlatformId, "Choose platform ID for openclSolver, use 'clinfo' to determine valid platform IDs");
317 EWOMS_REGISTER_PARAM(TypeTag, bool, OpenclIluParallel, "Parallelize ILU decomposition and application on GPU");
318 }
319
320 FlowLinearSolverParameters() { reset(); }
321
322 // set default values
323 void reset()
324 {
325 relaxed_linear_solver_reduction_ = 1e-2;
326 linear_solver_reduction_ = 1e-2;
327 linear_solver_maxiter_ = 200;
328 linear_solver_restart_ = 40;
329 linear_solver_verbosity_ = 0;
330 ilu_relaxation_ = 0.9;
331 ilu_fillin_level_ = 0;
332 ilu_milu_ = MILU_VARIANT::ILU;
333 ilu_redblack_ = false;
334 ilu_reorder_sphere_ = false;
335 newton_use_gmres_ = false;
336 ignoreConvergenceFailure_ = false;
337 scale_linear_system_ = false;
338 linsolver_ = "ilu0";
339 linear_solver_print_json_definition_ = true;
340 cpr_reuse_setup_ = 4;
341 cpr_reuse_interval_ = 30;
342 accelerator_mode_ = "none";
343 bda_device_id_ = 0;
344 opencl_platform_id_ = 0;
345 opencl_ilu_parallel_ = true;
346 }
347 };
348
349
350} // namespace Opm
351
352
353
354
355#endif // OPM_FLOWLINEARSOLVERPARAMETERS_HEADER_INCLUDED
Definition AquiferInterface.hpp:35
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition BlackoilPhases.hpp:27
MILU_VARIANT
Definition MILU.hpp:34
@ ILU
Do not perform modified ILU.
This class carries all parameters for the NewtonIterationBlackoilInterleaved class.
Definition FlowLinearSolverParameters.hpp:237
Definition FlowLinearSolverParameters.hpp:117
Definition FlowLinearSolverParameters.hpp:121
Definition FlowLinearSolverParameters.hpp:113
Definition FlowLinearSolverParameters.hpp:109
Definition FlowLinearSolverParameters.hpp:73
Definition FlowLinearSolverParameters.hpp:81
Definition FlowLinearSolverParameters.hpp:69
Definition FlowLinearSolverParameters.hpp:85
Definition FlowLinearSolverParameters.hpp:93
Definition FlowLinearSolverParameters.hpp:58
Definition FlowLinearSolverParameters.hpp:105
Definition FlowLinearSolverParameters.hpp:48
Definition FlowLinearSolverParameters.hpp:62
Definition FlowLinearSolverParameters.hpp:101
Definition FlowLinearSolverParameters.hpp:77
Definition FlowLinearSolverParameters.hpp:129
Definition FlowLinearSolverParameters.hpp:125
Definition FlowLinearSolverParameters.hpp:53
Definition FlowLinearSolverParameters.hpp:97
Definition FlowLinearSolverParameters.hpp:44
Definition FlowLinearSolverParameters.hpp:89