OpenLB 1.7
Loading...
Searching...
No Matches
plainWriter.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#ifndef PLAIN_WRITER_H
26#define PLAIN_WRITER_H
27
28namespace olb {
29
33 template<class Ch, class Tr>
34 friend auto& operator<<(std::basic_ostream<Ch, Tr>&, FileName&);
35private:
36 std::stringstream _fileName;
37 std::string _suffix;
38 std::string _fullname;
39public:
41 FileName( std::string baseName, std::string suffix=".dat" )
42 : _fileName(baseName, std::ios_base::app | std::ios_base::out), _suffix(suffix)
43 {}
45 template<typename T>
46 std::string addParameter( std::string quantity, T value, int digits=6, int precision=2 ){
47 _fileName << "_" << quantity;
48 if constexpr(std::is_same_v<T,double>){
49 _fileName << std::setw(digits) << std::setfill('0') << std::setprecision(precision) << value;
50 } else {
51 _fileName << std::setw(digits) << std::setfill('0') << value;
52 }
53 return _fileName.str();
54 };
55 //Return full name as string
56 std::string str(){
57 return _fileName.str()+_suffix;
58 }
59 //Return full name as const char* (necessary for disk operations)
60 const char* c_str(){
61 _fullname = str();
62 return _fullname.c_str();
63 }
64};
65
66//Operator << for FielName
67template<class Ch, class Tr>
68auto& operator<<(std::basic_ostream<Ch, Tr>& os,FileName& fileName)
69{
70 return os << fileName.str();
71}
72
75
77template <typename ARRAYTYPE>
78void writeScalarData( std::ofstream& dataWriterOpened,
79 std::string fullFileName, std::string headLine,
80 ARRAYTYPE& dataVector, int iE, int iE0 = 0 );
82template <typename ARRAYTYPE>
83void writeScalarData( std::string fullFileName, std::string headLine,
84 ARRAYTYPE& dataVector, int iE, int iE0 = 0 );
86template <typename ARRAYTYPE>
87void writeScalarData( std::string fullFileName, std::vector<std::string>& headLineVector,
88 ARRAYTYPE& dataVector, int iT, int iTinit = 0 );
89
90
92void writeArrayData( std::string fullFileName, std::string headLine,
93 std::vector<std::string>& dataVector );
95template <typename ARRAYTYPE>
96void writeArrayData( std::string fullFileName, std::string headLine,
97 std::vector<ARRAYTYPE>& dataVector );
99template <typename ARRAYTYPE>
100void writeArrayData( std::string fullFileName, std::vector<std::string>& headLineVector,
101 std::vector<ARRAYTYPE>& dataVector );
102
103} //namespace olb
104
105#endif
FileName class.
Definition plainWriter.h:31
const char * c_str()
Definition plainWriter.h:60
friend auto & operator<<(std::basic_ostream< Ch, Tr > &, FileName &)
Befriend overloaded << operator.
Definition plainWriter.h:68
FileName(std::string baseName, std::string suffix=".dat")
Constructor.
Definition plainWriter.h:41
std::string addParameter(std::string quantity, T value, int digits=6, int precision=2)
Add parameters.
Definition plainWriter.h:46
std::string str()
Definition plainWriter.h:56
Top level namespace for all of OpenLB.
void writeArrayData(std::string fullFileName, std::string headLine, std::vector< std::string > &dataVector)
Write array data.
void writeScalarData(std::ofstream &dataWriterOpened, std::string fullFileName, std::string headLine, ARRAYTYPE &dataVector, int iE, int iE0=0)
Write functions for scalar and array data.
std::ostream & operator<<(std::ostream &os, const ScalarVector< T, D, IMPL > &o)
Print vector entries to ostream in a human-readable fashion.