GenericOutput.hpp
1 /*---------------------------------------------------------------------------*\
2  *
3  * mimmo
4  *
5  * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6  *
7  * -------------------------------------------------------------------------
8  * License
9  * This file is part of mimmo.
10  *
11  * mimmo is free software: you can redistribute it and/or modify it
12  * under the terms of the GNU Lesser General Public License v3 (LGPL)
13  * as published by the Free Software Foundation.
14  *
15  * mimmo is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with mimmo. If not, see <http://www.gnu.org/licenses/>.
22  *
23 \*---------------------------------------------------------------------------*/
24 #ifndef __OUTPUTDOF_HPP__
25 #define __OUTPUTDOF_HPP__
26 
27 #include "BaseManipulation.hpp"
28 #include "IOData.hpp"
29 
30 namespace mimmo{
31 
36 namespace outputCSVStream{
37  template<typename T>
38  std::fstream& ofstreamcsv(std::fstream &in, const T &x);
39  template<typename T>
40  std::fstream& ofstreamcsvend(std::fstream &in, const T &x);
41  template<typename T>
42  std::fstream& ofstreamcsv(std::fstream &in, const std::vector< T > &x);
43  template<typename T, size_t d>
44  std::fstream& ofstreamcsv(std::fstream &in, const std::array< T,d > &x);
45  template<typename T>
46  std::fstream& ofstreamcsvend(std::fstream &in, const std::vector< T > &x);
47  template<typename T, size_t d>
48  std::fstream& ofstreamcsvend(std::fstream &in, const std::array< T,d > &x);
49  template<typename T>
50  std::fstream& ofstreamcsv(std::fstream &in, const MimmoPiercedVector< T > &x);
51  template<typename T, size_t d>
52  std::fstream& ofstreamcsvend(std::fstream &in, const MimmoPiercedVector< T > &x);
53 }
110 private:
111  std::string m_dir;
112  std::string m_filename;
115  bool m_csv;
116  std::unique_ptr<IOData> m_input;
118 public:
119  GenericOutput(std::string dir = "./", std::string filename = "output.txt", bool csv = false);
120  GenericOutput(const bitpit::Config::Section & rootXML);
121  ~GenericOutput();
122 
123  GenericOutput(const GenericOutput & other);
125 
126  void buildPorts();
127 
128  BITPIT_DEPRECATED( template<typename T>
129  T* getInput());
130 
131  template<typename T>
132  void setInput(T* data);
133 
134  template<typename T>
135  void setInput(T data);
136 
137  void clearInput();
138 
139  void setWriteDir(std::string dir);
140  void setFilename(std::string filename);
141  void setCSV(bool csv);
142 
143  void execute();
144 
145  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name = "");
146  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name= "");
147 
148 protected:
149  void swap(GenericOutput & x) noexcept;
150 
151 private:
152  template<typename T>
153  void _setInput(T & data);
154 };
155 
204 private:
205  std::string m_dir;
206  std::string m_filename;
209  bool m_csv;
210  std::unique_ptr<IOData> m_input;
212  bool m_binary;
214 public:
215  GenericOutputMPVData(std::string dir = "./", std::string filename = "output.txt", bool csv = false);
216  GenericOutputMPVData(const bitpit::Config::Section & rootXML);
218 
221 
222  void buildPorts();
223 
224  BITPIT_DEPRECATED(template<typename T>
226 
227  template<typename T>
228  void setInput(MimmoPiercedVector< T > *data);
229 
230  template<typename T>
232 
233  void clearInput();
234 
235  void setWriteDir(std::string dir);
236  void setFilename(std::string filename);
237  void setCSV(bool csv);
238  void setBinary(bool binary);
239 
240  void execute();
241 
242  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name = "");
243  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name= "");
244 
245 protected:
246  void swap(GenericOutputMPVData & x) noexcept;
247 #if MIMMO_ENABLE_MPI
248  template<typename T>
249  void collectDataFromAllProcs(MimmoPiercedVector<T> & locdata, MimmoPiercedVector<T> * dataglobal);
250 #endif
251 
252 private:
253  template<typename T>
254  void _setInput(MimmoPiercedVector< T > & data);
255 
256 };
257 
258 REGISTER_PORT(M_COORDS, MC_VECARR3, MD_FLOAT,__OUTPUTDOF_HPP__)
259 REGISTER_PORT(M_DISPLS, MC_VECARR3, MD_FLOAT,__OUTPUTDOF_HPP__)
260 REGISTER_PORT(M_DATAFIELD, MC_VECTOR, MD_FLOAT,__OUTPUTDOF_HPP__)
263 REGISTER_PORT(M_POINT, MC_ARRAY3, MD_FLOAT,__OUTPUTDOF_HPP__)
264 REGISTER_PORT(M_SPAN, MC_ARRAY3, MD_FLOAT,__OUTPUTDOF_HPP__)
265 REGISTER_PORT(M_DIMENSION, MC_ARRAY3, MD_INT,__OUTPUTDOF_HPP__)
266 REGISTER_PORT(M_VALUED, MC_SCALAR, MD_FLOAT,__OUTPUTDOF_HPP__)
267 REGISTER_PORT(M_VALUEI, MC_SCALAR, MD_INT,__OUTPUTDOF_HPP__)
268 REGISTER_PORT(M_VALUEB, MC_SCALAR, MD_BOOL,__OUTPUTDOF_HPP__)
269 REGISTER_PORT(M_DEG, MC_ARRAY3, MD_INT,__OUTPUTDOF_HPP__)
270 
271 REGISTER(BaseManipulation, GenericOutput, "mimmo.GenericOutput")
273 
274 }
275 
276 #include "GenericOutput.tpp"
277 
278 #endif /* __OUTPUTDOF_HPP__ */
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
GenericOutputMPVData is the class that write a generic data to file output as mimmo::MimmoPiercedVect...
void swap(GenericOutput &x) noexcept
void setFilename(std::string filename)
void swap(GenericOutputMPVData &x) noexcept
void setInput(MimmoPiercedVector< T > *data)
#define M_DATAFIELD
#define M_DISPLS
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
GenericOutput & operator=(GenericOutput other)
#define MC_ARRAY3
#define MD_FLOAT
void setInput(T *data)
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void setFilename(std::string filename)
#define M_VALUEI
#define M_POINT
#define M_DIMENSION
void setWriteDir(std::string dir)
BaseManipulation is the base class of any manipulation object of the library.
MimmoPiercedVector is the basic data container for mimmo library.
#define M_VECTORFIELD
GenericOutput is the class that write generic data in a file output.
GenericOutputMPVData(std::string dir="./", std::string filename="output.txt", bool csv=false)
#define MC_SCALAR
#define MD_MPVECARR3FLOAT_
#define REGISTER_PORT(Name, Container, Datatype, ManipBlock)
void setCSV(bool csv)
#define M_SPAN
#define MC_VECTOR
#define MD_BOOL
#define M_VALUED
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
std::fstream & ofstreamcsvend(std::fstream &in, const T &x)
#define M_DEG
void setWriteDir(std::string dir)
#define MD_MPVECFLOAT_
#define M_SCALARFIELD
std::fstream & ofstreamcsv(std::fstream &in, const T &x)
GenericOutputMPVData & operator=(GenericOutputMPVData other)
#define MD_INT
MimmoPiercedVector< T > * getInput()
GenericOutput(std::string dir="./", std::string filename="output.txt", bool csv=false)
#define M_COORDS
#define MC_VECARR3
#define M_VALUEB
#define REGISTER(Base, Derived, name)
Definition: factory.hpp:206