www.cemf.ir
dataIO.hpp
Go to the documentation of this file.
1 
2 /*------------------------------- phasicFlow ---------------------------------
3  O C enter of
4  O O E ngineering and
5  O O M ultiscale modeling of
6  OOOOOOO F luid flow
7 ------------------------------------------------------------------------------
8  Copyright (C): www.cemf.ir
9  email: hamid.r.norouzi AT gmail.com
10 ------------------------------------------------------------------------------
11 Licence:
12  This file is part of phasicFlow code. It is a free software for simulating
13  granular and multiphase flows. You can redistribute it and/or modify it under
14  the terms of GNU General Public License v3 or any other later versions.
15 
16  phasicFlow is distributed to help others in their research in the field of
17  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
18  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 
20 -----------------------------------------------------------------------------*/
21 
22 #ifndef __dataIO_hpp__
23 #define __dataIO_hpp__
24 
25 #include <vector>
26 
27 #include "span.hpp"
28 #include "IOPattern.hpp"
29 #include "iOstream.hpp"
30 #include "iIstream.hpp"
31 #include "virtualConstructor.hpp"
32 #include "pFlowProcessors.hpp"
33 
34 namespace pFlow
35 {
36 
37 // - Forward
38 template<typename T>
40 (
41  iOstream& os,
42  span<T> data
43 );
44 
45 template<typename T>
46 bool writeDataASCII
47 (
48  iOstream& os,
49  span<T> data
50 );
51 
52 template<typename T>
53 bool readDataAscii
54 (
55  iIstream& is,
56  std::vector<T>& vec
57 );
58 
59 template<typename T>
61 (
62  iIstream& is,
63  std::vector<T>& data
64 );
65 
66 template<typename T>
67 class dataIO
68 {
69 protected:
70 
72 
73  std::vector<T> buffer_;
74 
76 
77 
79  virtual bool gatherData(span<T> data) = 0;
80 
81 public:
82 
84  TypeInfo("dataIO");
85 
86  dataIO(const IOPattern& iop)
87  :
88  ioPattern_(iop)
89  {}
90 
91  dataIO(const dataIO&) = default;
92 
93  dataIO(dataIO &&) = default;
94 
95  dataIO& operator = (const dataIO&) = default;
96 
97  dataIO& operator = (dataIO&&) = default;
98 
99  virtual ~dataIO() = default;
100 
102  (
103  dataIO,
104  IOPattern,
105  (const IOPattern& iop),
106  (iop)
107  );
108 
111  bool writeData(iOstream& os, span<T> data);
112 
113  bool readData(
114  iIstream& is,
115  std::vector<T>& data);
116 
117  static
118  uniquePtr<dataIO> create(const IOPattern& iop);
119 
120 };
121 
122 template<typename T>
123 inline
125 {
126  if(!writeDataAsciiBinary(os, s))
127  {
128  ioErrorInFile(os.name(), os.lineNumber());
129  fatalExit;
130  }
131  return os;
132 }
133 
134 
135 }
136 
137 #include "dataIO.cpp"
138 
139 #endif
pFlow::span
Definition: span.hpp:31
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::writeDataAsciiBinary
bool writeDataAsciiBinary(iOstream &os, span< T > data)
Definition: dataIO.cpp:22
pFlow::dataIO::writeData
bool writeData(iOstream &os, span< T > data)
Write data to the end of file from all processors.
Definition: dataIO.cpp:193
iIstream.hpp
pFlow::dataIO::gatherData
virtual bool gatherData(span< T > data)=0
gather data from all processors and put the results in buffer_
pFlow::dataIO::create
static uniquePtr< dataIO > create(const IOPattern &iop)
Definition: dataIO.cpp:263
pFlow::dataIO
Definition: dataIO.hpp:67
pFlow::dataIO::TypeInfo
TypeInfo("dataIO")
Type info.
pFlow::dataIO::operator=
dataIO & operator=(const dataIO &)=default
pFlow::dataIO::dataIO
dataIO(const IOPattern &iop)
Definition: dataIO.hpp:86
pFlow
Definition: demGeometry.hpp:27
pFlow::writeDataASCII
bool writeDataASCII(iOstream &os, span< T > data)
Definition: dataIO.cpp:57
pFlow::dataIO::bufferSpan_
span< T > bufferSpan_
Definition: dataIO.hpp:75
pFlow::dataIO::ioPattern_
IOPattern ioPattern_
Definition: dataIO.hpp:71
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::readDataAsciiBinary
bool readDataAsciiBinary(iIstream &is, std::vector< T > &data)
Definition: dataIO.cpp:80
pFlow::IOPattern
Definition: IOPattern.hpp:32
pFlow::dataIO::buffer_
std::vector< T > buffer_
Definition: dataIO.hpp:73
pFlow::readDataAscii
bool readDataAscii(iIstream &is, std::vector< T > &vec)
Definition: dataIO.cpp:120
virtualConstructor.hpp
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::dataIO::~dataIO
virtual ~dataIO()=default
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
dataIO.cpp
IOPattern.hpp
pFlow::uniquePtr
Definition: uniquePtr.hpp:42
pFlowProcessors.hpp
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
Definition: error.hpp:87
pFlow::IOstream::lineNumber
int32 lineNumber() const
Const access to the current stream line number.
Definition: IOstream.hpp:223
iOstream.hpp
span.hpp
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::dataIO::create_vCtor
create_vCtor(dataIO, IOPattern,(const IOPattern &iop),(iop))
pFlow::dataIO::readData
bool readData(iIstream &is, std::vector< T > &data)
Definition: dataIO.cpp:245