suanPan
Loading...
Searching...
No Matches
SolverSetting.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 * Copyright (C) 2017-2025 Theodore Chang
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program 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 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 ******************************************************************************/
17
18#ifndef SOLVERSETTING_HPP
19#define SOLVERSETTING_HPP
20
21#include <Toolbox/utility.h>
22
23enum class Precision : std::uint8_t {
24 MIXED,
25 FULL
26};
27
28template<sp_d data_t> struct SolverSetting {
29 std::string option{};
30 data_t tolerance = std::is_same_v<data_t, float> ? 1E-7f : 1E-14;
31 std::uint8_t iterative_refinement = 5;
33
34 auto set_option(std::istringstream& command) { option = get_remaining(command); }
35 auto set_lis_option(std::istringstream& command) {
36 static constexpr auto max_length = 1024;
37
38 const auto sub_command = get_remaining(command);
39
40 if(sub_command.empty()) {
41 option = "-i fgmres -p ilu";
42 return;
43 }
44 if(std::any_of(sub_command.begin(), sub_command.end(), [](const char c) { return !std::isspace(c); })) option = sub_command;
45 if(option.length() < max_length) return;
46
47 const auto pos = option.find_last_of(" \t\n\r", max_length);
48 option = option.substr(0, pos == std::string::npos ? max_length : pos);
49 }
50};
51
52#endif
Precision
Definition SolverSetting.hpp:23
Definition SolverSetting.hpp:28
data_t tolerance
Definition SolverSetting.hpp:30
std::string option
Definition SolverSetting.hpp:29
Precision precision
Definition SolverSetting.hpp:32
auto set_lis_option(std::istringstream &command)
Definition SolverSetting.hpp:35
auto set_option(std::istringstream &command)
Definition SolverSetting.hpp:34
std::uint8_t iterative_refinement
Definition SolverSetting.hpp:31
std::string get_remaining(std::istringstream &I)
Definition utility.cpp:99