OpenLB 1.7
Loading...
Searching...
No Matches
printUtils.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2022 Nicolas Hafen, Mathias J. Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24
25
26#ifndef PRINT_UTILS_H
27#define PRINT_UTILS_H
28
29#include <list>
30#include <unordered_set>
31
32namespace olb {
33
35template<class Ch, class Tr, std::size_t... Is>
36void print_index_sequence(std::basic_ostream<Ch,Tr>& os,
37 const std::index_sequence<Is...> is)
38{
39 std::size_t i=0;
40 ((os << (i++==0? "" : ",") << Is), ...);
41}
42
43
44
46
48template<class Ch, class Tr, std::size_t... Is>
49auto& operator<<(std::basic_ostream<Ch, Tr>& os,
50 const std::index_sequence<Is...>& is)
51{
52 os << "<";
54 return os << ">";
55}
56
58template<class Ch, class Tr, typename... args>
59auto& operator<<(std::basic_ostream<Ch, Tr>& os,
60 std::vector<args...>& vec)
61{
62 os << "|[";
63 for(auto it = vec.begin(); it != vec.end(); ++it){
64 os << (it==vec.begin()? "" : ",") << *it;
65 }
66 return os << "]|";
67}
68
70template<class Ch, class Tr, class T, std::size_t N>
71auto& operator<<(std::basic_ostream<Ch, Tr>& os,
72 std::array<T,N>& array)
73{
74 os << "|[";
75 for(auto it = array.begin(); it != array.end(); ++it){
76 os << (it==array.begin()? "" : ",") << *it;
77 }
78 return os << "]|";
79}
80
82template<class Ch, class Tr, typename... args>
83auto& operator<<(std::basic_ostream<Ch, Tr>& os,
84 std::list<args...>& list)
85{
86 os << "|[";
87 for(auto it = list.begin(); it != list.end(); ++it){
88 os << (it==list.begin()? "" : ",") << *it;
89 }
90 return os << "]|";
91}
92
94template<class Ch, class Tr, typename... args>
95auto& operator<<(std::basic_ostream<Ch, Tr>& os,
96 std::set<args...>& set)
97{
98 os << "|[";
99 for(auto it = set.begin(); it != set.end(); ++it){
100 os << (it==set.begin()? "" : ",") << *it;
101 }
102 return os << "]|";
103}
104
106template<class Ch, class Tr, typename... args>
107auto& operator<<(std::basic_ostream<Ch, Tr>& os,
108 std::unordered_set<args...>& set)
109{
110 os << "|[";
111 for(auto it = set.begin(); it != set.end(); ++it){
112 os << (it==set.begin()? "" : ",") << *it;
113 }
114 return os << "]|";
115}
116
118
121template<typename O>
122std::string boolToStr( O input ){
123 //If scalar
124 if constexpr (std::is_arithmetic<O>::value) {
125 if (input){
126 return "true";
127 } else {
128 return "false";
129 }
130 //If e.g. Vector
131 } else {
132 std::stringstream stream;
133 stream << "[";
134 for(unsigned iDim=0; iDim<O::d; ++iDim){
135 stream << (iDim==0 ? "" : ",");
136 if (input[iDim]){
137 stream << "true";
138 } else {
139 stream << "false";
140 }
141 }
142 stream << "]";
143 return stream.str();
144 }
145}
146
147} //namespace olb
148
149
150#endif
Top level namespace for all of OpenLB.
std::string boolToStr(O input)
Create readable bool string.
Definition printUtils.h:122
void print_index_sequence(std::basic_ostream< Ch, Tr > &os, const std::index_sequence< Is... > is)
Print std::index_sequence.
Definition printUtils.h:36
std::ostream & operator<<(std::ostream &os, const ScalarVector< T, D, IMPL > &o)
Print vector entries to ostream in a human-readable fashion.