opm-simulators
Loading...
Searching...
No Matches
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
26namespace Opm::Parameters
27{
28
32struct LinearSolverAccelerator { static constexpr auto value = "cpu"; };
33
37enum class LinearSolverAcceleratorType { GPU = 0, CPU = 1 };
38
45inline std::string
46toString(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
65inline LinearSolverAcceleratorType
66linearSolverAcceleratorTypeFromString(const std::string& str)
67{
68 std::string lowerStr = str;
69 std::transform(lowerStr.begin(), lowerStr.end(), lowerStr.begin(), [](unsigned char c) { return std::tolower(c); });
70 if (lowerStr == "gpu") {
71 return LinearSolverAcceleratorType::GPU;
72 } else if (lowerStr == "cpu") {
73 return LinearSolverAcceleratorType::CPU;
74 } else {
75 OPM_THROW(std::runtime_error, "Unknown LinearSolverAcceleratorType: " + str);
76 }
77}
78
82inline LinearSolverAcceleratorType
83linearSolverAcceleratorTypeFromCLI()
84{
85 return linearSolverAcceleratorTypeFromString(Parameters::Get<LinearSolverAccelerator>());
86}
87
88} // namespace Opm::Parameters
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