printlinearsolverparameter.hpp
Go to the documentation of this file.
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#ifndef OPM_PRINTLINEARSOLVERPARAMETERS_HEADER_INCLUDED
17#define OPM_PRINTLINEARSOLVERPARAMETERS_HEADER_INCLUDED
18
19#include <ostream>
20#include <vector>
21
22#include <opm/common/OpmLog/OpmLog.hpp>
25
26namespace Opm::detail
27{
28
32inline void writeJsonToStream(const Opm::PropertyTree& prm, std::ostream& os)
33{
34 // Write the property tree in JSON format to the output stream
35 prm.write_json(os, true);
36}
37
41inline void writeJsonToStream(const std::vector<Opm::PropertyTree>& prms, std::ostream& os)
42{
43 // Write each property tree in the vector in JSON format to the output stream
44 for (const auto& p : prms) {
45 writeJsonToStream(p, os);
46 }
47}
48
59template <class VectorOrSingle, class Comm>
60void
62 const VectorOrSingle& prm,
63 const Comm& comm)
64{
65 // Check if we are on the IO rank
66 const bool on_io_rank = comm.rank() == 0;
67 if (on_io_rank && parameters.linear_solver_print_json_definition_) {
68 std::ostringstream os;
69 os << "\nProperty tree for linear solvers:\n";
70 writeJsonToStream(prm, os);
71 // Write the parameters in JSON format
72 OpmLog::note(os.str());
73 }
74}
75
87template <class Comm>
88void
89printLinearSolverParameters(const std::vector<FlowLinearSolverParameters>& parameters,
90 int activeSolverNum,
91 const std::vector<Opm::PropertyTree>& prm,
92 const Comm& comm)
93{
94 printLinearSolverParameters(parameters[activeSolverNum], prm, comm);
95}
96
97} // namespace Opm::detail
98
99#endif // OPM_PRINTLINEARSOLVERPARAMETERS_HEADER_INCLUDED
Dune::OwnerOverlapCopyCommunication< int, int > Comm
Definition: FlexibleSolver_impl.hpp:304
Hierarchical collection of key/value pairs.
Definition: PropertyTree.hpp:39
void write_json(std::ostream &os, bool pretty) const
Definition: alignedallocator.hh:32
void writeJsonToStream(const Opm::PropertyTree &prm, std::ostream &os)
Write a single property tree in JSON format to the stream.
Definition: printlinearsolverparameter.hpp:32
void printLinearSolverParameters(const FlowLinearSolverParameters &parameters, const VectorOrSingle &prm, const Comm &comm)
Print the linear solver parameters to the log if requested.
Definition: printlinearsolverparameter.hpp:61
This class carries all parameters for the NewtonIterationBlackoilInterleaved class.
Definition: FlowLinearSolverParameters.hpp:95
bool linear_solver_print_json_definition_
Definition: FlowLinearSolverParameters.hpp:111