opm-simulators
LinearSolverAcceleratorType.hpp
1 /*
2  Copyright 2025 Equinor ASA
3 
4  This file is part of the Open Porous Media project (OPM).
5  OPM is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9  OPM is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13  You should have received a copy of the GNU General Public License
14  along with OPM. If not, see <http://www.gnu.org/licenses/>.
15 */
16 
17 #include <algorithm>
18 #include <stdexcept>
19 #include <string>
20 
21 #include <opm/common/ErrorMacros.hpp>
24 
25 
26 namespace Opm::Parameters
27 {
28 
32 struct LinearSolverAccelerator { static constexpr auto value = "cpu"; };
33 
37 enum class LinearSolverAcceleratorType { GPU = 0, CPU = 1 };
38 
45 inline std::string
46 toString(LinearSolverAcceleratorType type)
47 {
48  switch (type) {
49  case LinearSolverAcceleratorType::GPU:
50  return "gpu";
51  case LinearSolverAcceleratorType::CPU:
52  return "cpu";
53  default:
54  OPM_THROW(std::runtime_error, "Unknown LinearSolverAcceleratorType");
55  }
56 }
57 
65 inline LinearSolverAcceleratorType
66 linearSolverAcceleratorTypeFromString(const std::string& str)
67 {
68  std::string lowerStr = str;
69  std::ranges::transform(lowerStr, lowerStr.begin(),
70  [](unsigned char c) { return std::tolower(c); });
71  if (lowerStr == "gpu") {
72  return LinearSolverAcceleratorType::GPU;
73  } else if (lowerStr == "cpu") {
74  return LinearSolverAcceleratorType::CPU;
75  } else {
76  OPM_THROW(std::runtime_error, "Unknown LinearSolverAcceleratorType: " + str);
77  }
78 }
79 
83 inline LinearSolverAcceleratorType
84 linearSolverAcceleratorTypeFromCLI()
85 {
86  return linearSolverAcceleratorTypeFromString(Parameters::Get<LinearSolverAccelerator>());
87 }
88 
89 } // namespace Opm::Parameters
Definition: blackoilnewtonmethodparams.hpp:31
Declares the parameters for the black oil model.
Declares the properties required by the black oil model.
For the CLI options.
Definition: LinearSolverAcceleratorType.hpp:32