GenericInput.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 
25 #ifndef __INPUTDOF_HPP__
26 #define __INPUTDOF_HPP__
27 
28 #include "BaseManipulation.hpp"
29 #include "IOData.hpp"
30 
31 namespace mimmo{
32 
37 namespace inputCSVStream{
38  template<typename T>
39  std::fstream& ifstreamcsv(std::fstream &in, T &x);
40  template<typename T>
41  std::fstream& ifstreamcsvend(std::fstream &in, T &x);
42  template<typename T>
43  std::fstream& ifstreamcsv(std::fstream &in, std::vector< T > &x);
44  template<typename T, size_t d>
45  std::fstream& ifstreamcsv(std::fstream &in, std::array< T,d > &x);
46  template<typename T>
47  std::fstream& ifstreamcsvend(std::fstream &in, std::vector< T > &x);
48  template<typename T, size_t d>
49  std::fstream& ifstreamcsvend(std::fstream &in, std::array< T,d > &x);
50  template<typename T>
51  std::fstream& ifstreamcsv(std::fstream &in, MimmoPiercedVector< T > &x);
52  template<typename T, size_t d>
53  std::fstream& ifstreamcsv(std::fstream &in, MimmoPiercedVector< std::array< T,d > > &x);
54 
55 }
56 
111 
112 private:
113  bool m_readFromFile;
114  bool m_csv;
115  std::string m_dir;
116  std::string m_filename;
118  std::unique_ptr<IOData> m_input;
119  std::unique_ptr<IOData> m_result;
121 public:
122  GenericInput(bool readFromFile = false, bool csv = false);
123  GenericInput(const bitpit::Config::Section & rootXML);
124  GenericInput(std::string dir, std::string filename, bool csv = false);
125 
130  BITPIT_DEPRECATED( template<typename T>
131  GenericInput(T data){
132  setInput<T>(data);
133  });
134  ~GenericInput();
135 
136  GenericInput(const GenericInput & other);
138 
139  void buildPorts();
140 
141  BITPIT_DEPRECATED( template<typename T> T* getInput());
142 
143  template<typename T>
144  T getResult();
145 
146  void setReadFromFile(bool readFromFile);
147  void setCSV(bool csv);
148  void setReadDir(std::string dir);
149  void setFilename(std::string filename);
150 
151  template<typename T>
152  void setInput(T* data);
153  template<typename T>
154  void setInput(T& data);
155 
156  BITPIT_DEPRECATED( template<typename T>
157  void setResult(T* data));
158  BITPIT_DEPRECATED( template<typename T>
159  void setResult(T& data));
160 
161  void clearInput();
162  void clearResult();
163 
164  void execute();
165 
166  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name = "");
167  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name= "");
168 
169 protected:
170  void swap(GenericInput & x) noexcept;
171 #if MIMMO_ENABLE_MPI
172  template<typename T>
173  void sendReadDataToAllProcs(T & data);
174 #endif
175 
176 private:
177 
178  template<typename T>
179  void _setInput(T* data);
180  template<typename T>
181  void _setInput(T& data);
182 
183  template<typename T>
184  void _setResult(T* data);
185  template<typename T>
186  void _setResult(T& data);
187 
188  template<typename T>
189  T* _getInput();
190 
191  template<typename T>
192  T* _getResult();
193 
194 };
195 
247 private:
248  bool m_csv;
249  std::string m_dir;
250  std::string m_filename;
252  std::unique_ptr<IOData> m_result;
254  bool m_binary;
256 public:
257  GenericInputMPVData(bool csv = false);
258  GenericInputMPVData(const bitpit::Config::Section & rootXML);
259  GenericInputMPVData(std::string dir, std::string filename, bool csv = false);
260 
262 
265 
266  void buildPorts();
267 
268  template<typename T>
270 
271 
272  void setCSV(bool csv);
273  void setReadDir(std::string dir);
274  void setFilename(std::string filename);
275  void setBinary(bool binary);
276 
277  void clearResult();
278 
279  void execute();
280 
281  virtual void absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name = "");
282  virtual void flushSectionXML(bitpit::Config::Section & slotXML, std::string name= "");
283 
284 protected:
285  void swap(GenericInputMPVData & x) noexcept;
286 #if MIMMO_ENABLE_MPI
287  template<typename T>
288  void sendReadDataToAllProcs(MimmoPiercedVector<T> & data);
289 #endif
290 
291 private:
292 
293  template<typename T>
294  MimmoPiercedVector< T >* _getResult();
295  template<typename T>
296  void _setResult(MimmoPiercedVector< T >*);
297  template<typename T>
298  void _setResult(MimmoPiercedVector< T >&);
299 
300 
301 };
302 
303 REGISTER_PORT(M_COORDS, MC_VECARR3, MD_FLOAT,__INPUTDOF_HPP__)
304 REGISTER_PORT(M_DISPLS, MC_VECARR3, MD_FLOAT,__INPUTDOF_HPP__)
305 REGISTER_PORT(M_DATAFIELD, MC_VECTOR, MD_FLOAT,__INPUTDOF_HPP__)
306 REGISTER_PORT(M_POINT, MC_ARRAY3, MD_FLOAT,__INPUTDOF_HPP__)
307 REGISTER_PORT(M_SPAN, MC_ARRAY3, MD_FLOAT,__INPUTDOF_HPP__)
308 REGISTER_PORT(M_DIMENSION, MC_ARRAY3, MD_INT,__INPUTDOF_HPP__)
309 REGISTER_PORT(M_VALUED, MC_SCALAR, MD_FLOAT,__INPUTDOF_HPP__)
310 REGISTER_PORT(M_VALUEI, MC_SCALAR, MD_INT,__INPUTDOF_HPP__)
311 REGISTER_PORT(M_VALUEB, MC_SCALAR, MD_BOOL,__INPUTDOF_HPP__)
312 REGISTER_PORT(M_DEG, MC_ARRAY3, MD_INT,__INPUTDOF_HPP__)
315 REGISTER_PORT(M_GEOM, MC_SCALAR, MD_MIMMO_ ,__INPUTDOF_HPP__)
316 
317 REGISTER(BaseManipulation, GenericInput, "mimmo.GenericInput")
319 
320 }
321 
322 #include "GenericInput.tpp"
323 
324 #endif /* __INPUTDOF_HPP__ */
GenericInputMPVData(bool csv=false)
void setReadDir(std::string dir)
GenericInputMPVData is the class that set a generic input data as mimmo::MimmoPiercedVector.
GenericInput & operator=(GenericInput other)
#define M_DATAFIELD
std::fstream & ifstreamcsv(std::fstream &in, T &x)
#define M_DISPLS
#define M_GEOM
GenericInputMPVData & operator=(GenericInputMPVData other)
#define MC_ARRAY3
#define MD_FLOAT
#define M_VALUEI
void setInput(T *data)
GENERICINPUT////////////////////////////////////////////////////////////////////////////.
#define M_POINT
#define M_DIMENSION
BaseManipulation is the base class of any manipulation object of the library.
void setCSV(bool csv)
void setReadDir(std::string dir)
MimmoPiercedVector is the basic data container for mimmo library.
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
#define M_VECTORFIELD
GenericInput is the class that set the initialization of a generic input data.
std::fstream & ifstreamcsvend(std::fstream &in, T &x)
#define MC_SCALAR
void swap(GenericInput &x) noexcept
void setBinary(bool binary)
#define MD_MPVECARR3FLOAT_
#define REGISTER_PORT(Name, Container, Datatype, ManipBlock)
MimmoPiercedVector< T > * getResult()
void setFilename(std::string filename)
#define M_SPAN
#define MC_VECTOR
#define MD_BOOL
GenericInput(bool readFromFile=false, bool csv=false)
#define M_VALUED
void setReadFromFile(bool readFromFile)
#define M_DEG
#define MD_MIMMO_
void setFilename(std::string filename)
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void swap(GenericInputMPVData &x) noexcept
#define MD_MPVECFLOAT_
#define M_SCALARFIELD
void setResult(T *data)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
#define MD_INT
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
#define M_COORDS
#define MC_VECARR3
#define M_VALUEB
#define REGISTER(Base, Derived, name)
Definition: factory.hpp:206