ExaDG
Loading...
Searching...
No Matches
print_functions.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2021 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef INCLUDE_FUNCTIONALITIES_PRINTFUNCTIONS_H_
23#define INCLUDE_FUNCTIONALITIES_PRINTFUNCTIONS_H_
24
25// C/C++
26#include <iomanip>
27
28// deal.II
29#include <deal.II/base/conditional_ostream.h>
30#include <deal.II/base/mpi.h>
31
32// ExaDG
33#include <exadg/utilities/enum_utilities.h>
34
35namespace ExaDG
36{
37template<typename ParameterType>
38void
39print_parameter(dealii::ConditionalOStream const & pcout,
40 std::string const name,
41 ParameterType const value);
42
43void
44print_name(dealii::ConditionalOStream const & pcout, std::string const name);
45
46template<typename ParameterType>
47void
48print_value(dealii::ConditionalOStream const & pcout, ParameterType const value);
49
50template<>
51void
52print_value(dealii::ConditionalOStream const & pcout, bool const value);
53
54template<>
55void
56print_value(dealii::ConditionalOStream const & pcout, double const value);
57
58// print a parameter (which has a name and a value)
59template<typename ParameterType>
60void
61print_parameter(dealii::ConditionalOStream const & pcout,
62 std::string const name,
63 ParameterType const value)
64{
65 print_name(pcout, name);
66 print_value(pcout, value);
67}
68
69// print name and insert spaces so that the output is aligned
70// needs inline because this function has no template
71inline void
72print_name(dealii::ConditionalOStream const & pcout, std::string const name)
73{
74 unsigned int const max_length_name = 45;
75
76 pcout << " " /* 2 */ << name /* name.length*/ << ":" /* 1 */;
77 int const remaining_spaces = max_length_name - 2 - 1 - name.length();
78
79 for(int i = 0; i < remaining_spaces; ++i)
80 pcout << " " /* 1 */;
81}
82
83// print value for general parameter data type
84template<typename ParameterType>
85void
86print_value(dealii::ConditionalOStream const & pcout, ParameterType const value)
87{
88 if constexpr(Utilities::is_enum<ParameterType>())
89 pcout << Utilities::enum_to_string(value) << std::endl;
90 else
91 pcout << value << std::endl;
92}
93
94// specialization of template function for parameters of type bool
95template<>
96inline void
97print_value(dealii::ConditionalOStream const & pcout, bool const value)
98{
99 std::string value_string = "default";
100 value_string = (value == true) ? "true" : "false";
101 print_value(pcout, value_string);
102}
103
104// specialization of template function for parameters of type double
105template<>
106inline void
107print_value(dealii::ConditionalOStream const & pcout, double const value)
108{
109 pcout << std::scientific << std::setprecision(4) << value << std::endl;
110}
111
112inline std::string
113print_horizontal_line()
114{
115 return "________________________________________________________________________________";
116}
117
118inline void
119print_write_output_time(double const time,
120 unsigned int const counter,
121 bool const unsteady,
122 MPI_Comm const & mpi_comm)
123{
124 dealii::ConditionalOStream pcout(std::cout,
125 dealii::Utilities::MPI::this_mpi_process(mpi_comm) == 0);
126 if(unsteady)
127 {
128 pcout << std::endl
129 << "OUTPUT << Write data at time t = " << std::scientific << std::setprecision(4) << time
130 << std::endl;
131 }
132 else
133 {
134 pcout << std::endl
135 << "OUTPUT << Write " << (counter == 0 ? "initial" : "solution") << " data" << std::endl;
136 }
137}
138
139} // namespace ExaDG
140
141#endif /* INCLUDE_FUNCTIONALITIES_PRINTFUNCTIONS_H_ */
std::string enum_to_string(EnumType const enum_type)
Converts and enum to a string, returning the string.
Definition enum_utilities.h:67
Definition driver.cpp:33