GenericInput.cpp
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 #include "GenericInput.hpp"
26 
27 namespace mimmo {
28 
30 
36 GenericInput::GenericInput(bool readFromFile, bool csv){
37  m_readFromFile = readFromFile;
38  m_csv = csv;
39  m_portsType = BaseManipulation::ConnectionType::BOTH;
40  m_name = "mimmo.GenericInput";
41  m_dir = "./";
42 };
43 
48 GenericInput::GenericInput(const bitpit::Config::Section & rootXML){
49 
50  m_readFromFile = false;
51  m_csv = false;
52  m_portsType = BaseManipulation::ConnectionType::BOTH;
53  m_name = "mimmo.GenericInput";
54  m_dir = "./";
55  m_filename = "input.txt";
56 
57  std::string fallback_name = "ClassNONE";
58  std::string input = rootXML.get("ClassName", fallback_name);
59  input = bitpit::utils::string::trim(input);
60  if(input == "mimmo.GenericInput"){
61  absorbSectionXML(rootXML);
62  }else{
64  };
65 }
66 
74 GenericInput::GenericInput(std::string dir, std::string filename, bool csv){
75  m_name = "mimmo.GenericInput";
76  m_readFromFile = true;
77  m_csv = csv;
78  m_dir = dir;
79  m_filename = filename;
80  m_portsType = BaseManipulation::ConnectionType::BOTH;
81 };
82 
83 GenericInput::~GenericInput(){};
84 
89  m_readFromFile = other.m_readFromFile;
90  m_csv = other.m_csv;
91  m_dir = other.m_dir;
92  m_filename = other.m_filename;
93 };
94 
99  swap(other);
100  return *this;
101 }
102 
108 {
109  std::swap(m_readFromFile, x.m_readFromFile);
110  std::swap(m_csv , x.m_csv);
111  std::swap(m_dir , x.m_dir);
112  std::swap(m_filename , x.m_filename);
113  std::swap(m_input , x.m_input);
114  std::swap(m_result , x.m_result);
116 }
117 
122 void
123 GenericInput::setReadFromFile(bool readFromFile){
124  m_readFromFile = readFromFile;
125 };
126 
130 void
131 GenericInput::setFilename(std::string filename){
132  m_filename = filename;
133 };
134 
138 void
139 GenericInput::setReadDir(std::string dir){
140  m_dir = dir;
141 };
142 
146 void
148  m_csv = csv;
149 };
150 
153 void
155 
156  bool built = true;
157 
158  built = (built && createPortOut<dvecarr3E, GenericInput>(this, &mimmo::GenericInput::getResult<dvecarr3E>, M_COORDS));
159  built = (built && createPortOut<dvecarr3E, GenericInput>(this, &mimmo::GenericInput::getResult<dvecarr3E>, M_DISPLS));
160  built = (built && createPortOut<dvector1D, GenericInput>(this, &mimmo::GenericInput::getResult<dvector1D>, M_DATAFIELD));
161  built = (built && createPortOut<darray3E, GenericInput>(this, &mimmo::GenericInput::getResult<darray3E>, M_POINT));
162  built = (built && createPortOut<darray3E, GenericInput>(this, &mimmo::GenericInput::getResult<darray3E>, M_SPAN));
163  built = (built && createPortOut<iarray3E, GenericInput>(this, &mimmo::GenericInput::getResult<iarray3E>, M_DIMENSION));;
164  built = (built && createPortOut<double, GenericInput>(this, &mimmo::GenericInput::getResult<double>, M_VALUED));
165  built = (built && createPortOut<int, GenericInput>(this, &mimmo::GenericInput::getResult<int>, M_VALUEI));
166  built = (built && createPortOut<bool, GenericInput>(this, &mimmo::GenericInput::getResult<bool>, M_VALUEB));
167  built = (built && createPortOut<iarray3E, GenericInput>(this, &mimmo::GenericInput::getResult<iarray3E>, M_DEG));
168 
169  m_arePortsBuilt = built;
170 }
171 
174 void
176  m_input.reset(nullptr);
177 }
178 
181 void
183  m_result.reset(nullptr);
184 }
185 
190 void
192 
198 void
199 GenericInput::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
200 
201  BITPIT_UNUSED(name);
202 
203  std::string input;
204 
205  BaseManipulation::absorbSectionXML(slotXML, name);
206 
207  if(slotXML.hasOption("ReadFromFile")){
208  std::string input = slotXML.get("ReadFromFile");
209  input = bitpit::utils::string::trim(input);
210  bool temp = false;
211  if(!input.empty()){
212  std::stringstream ss(input);
213  ss>>temp;
214  }
215  setReadFromFile(temp);
216  };
217 
218  if(slotXML.hasOption("CSV")){
219  std::string input = slotXML.get("CSV");
220  input = bitpit::utils::string::trim(input);
221  bool temp = false;
222  if(!input.empty()){
223  std::stringstream ss(input);
224  ss>>temp;
225  }
226  setCSV(temp);
227  };
228 
229  if(slotXML.hasOption("Filename") && m_readFromFile){
230  std::string input = slotXML.get("Filename");
231  input = bitpit::utils::string::trim(input);
232  setFilename(input);
233  };
234 
235  if(slotXML.hasOption("ReadDir") && m_readFromFile){
236  std::string input = slotXML.get("ReadDir");
237  input = bitpit::utils::string::trim(input);
238  setReadDir(input);
239  };
240 
241 }
242 
248 void
249 GenericInput::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
250 
251  BITPIT_UNUSED(name);
252 
253  BaseManipulation::flushSectionXML(slotXML, name);
254 
255  slotXML.set("ReadFromFile", std::to_string((int)m_readFromFile));
256  slotXML.set("CSV", std::to_string((int)m_csv));
257  slotXML.set("ReadDir", m_dir);
258  slotXML.set("Filename", m_filename);
259 };
260 
261 
267  m_csv = csv;
268  m_portsType = BaseManipulation::ConnectionType::BOTH;
269  m_name = "mimmo.GenericInputMPVData";
270  m_dir = "./";
271  m_binary = false;
272 };
273 
278 GenericInputMPVData::GenericInputMPVData(const bitpit::Config::Section & rootXML){
279 
280  m_csv = false;
281  m_portsType = BaseManipulation::ConnectionType::BOTH;
282  m_name = "mimmo.GenericInputMPVData";
283  m_dir = "./";
284  m_filename = "input.txt";
285  m_binary = false;
286 
287  std::string fallback_name = "ClassNONE";
288  std::string input = rootXML.get("ClassName", fallback_name);
289  input = bitpit::utils::string::trim(input);
290  if(input == "mimmo.GenericInputMPVData"){
291  absorbSectionXML(rootXML);
292  }else{
294  };
295 }
296 
304 GenericInputMPVData::GenericInputMPVData(std::string dir, std::string filename, bool csv){
305  m_csv = csv;
306  m_dir = dir;
307  m_filename = filename;
308  m_name = "mimmo.GenericInputMPVData";
309  m_binary = false;
310  m_portsType = BaseManipulation::ConnectionType::BOTH;
311 };
312 
313 GenericInputMPVData::~GenericInputMPVData(){};
314 
319  m_csv = other.m_csv;
320  m_dir = other.m_dir;
321  m_filename = other.m_filename;
322  m_binary = other.m_binary;
323 };
324 
329  swap(other);
330  return *this;
331 }
332 
338 {
339  std::swap(m_csv , x.m_csv);
340  std::swap(m_dir , x.m_dir);
341  std::swap(m_filename , x.m_filename);
342  std::swap(m_binary , x.m_binary);
343  std::swap(m_result , x.m_result);
345 }
346 
347 
351 void
353  m_csv = csv;
354 };
355 
359 void
361  m_binary = binary;
362 };
363 
367 void
368 GenericInputMPVData::setFilename(std::string filename){
369  m_filename = filename;
370 };
371 
375 void
377  m_dir = dir;
378 };
379 
382 void
384 
385  bool built = true;
386 
387  built = (built && createPortIn<MimmoSharedPointer<MimmoObject>, GenericInputMPVData>(this, &mimmo::GenericInputMPVData::setGeometry, M_GEOM));
388  built = (built && createPortOut<dmpvector1D*, GenericInputMPVData>(this, &mimmo::GenericInputMPVData::getResult<double>, M_SCALARFIELD));
389  built = (built && createPortOut<dmpvecarr3E*, GenericInputMPVData>(this, &mimmo::GenericInputMPVData::getResult<darray3E>, M_VECTORFIELD));
390 
391 
392  m_arePortsBuilt = built;
393 }
394 
397 void
399  m_result.reset(nullptr);
400 }
401 
406 void
408 
414 void
415 GenericInputMPVData::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
416 
417  BITPIT_UNUSED(name);
418 
419  std::string input;
420 
421  BaseManipulation::absorbSectionXML(slotXML, name);
422 
423  if(slotXML.hasOption("CSV")){
424  std::string input = slotXML.get("CSV");
425  input = bitpit::utils::string::trim(input);
426  bool temp = false;
427  if(!input.empty()){
428  std::stringstream ss(input);
429  ss>>temp;
430  }
431  setCSV(temp);
432  };
433 
434  if(slotXML.hasOption("Filename")){
435  std::string input = slotXML.get("Filename");
436  input = bitpit::utils::string::trim(input);
437  setFilename(input);
438  };
439 
440  if(slotXML.hasOption("ReadDir")){
441  std::string input = slotXML.get("ReadDir");
442  input = bitpit::utils::string::trim(input);
443  setReadDir(input);
444  };
445 
446  if(slotXML.hasOption("Binary")){
447  std::string input = slotXML.get("Binary");
448  input = bitpit::utils::string::trim(input);
449  bool temp = false;
450  if(!input.empty()){
451  std::stringstream ss(input);
452  ss>>temp;
453  }
454  setBinary(temp);
455  };
456 
457 }
458 
464 void
465 GenericInputMPVData::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
466 
467  BITPIT_UNUSED(name);
468 
469  BaseManipulation::flushSectionXML(slotXML, name);
470 
471  slotXML.set("CSV", std::to_string((int)m_csv));
472  slotXML.set("ReadDir", m_dir);
473  slotXML.set("Filename", m_filename);
474  slotXML.set("Binary", std::to_string((int)m_binary));
475 };
476 
477 }
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
#define M_DISPLS
#define M_GEOM
GenericInputMPVData & operator=(GenericInputMPVData other)
#define M_VALUEI
#define M_POINT
#define M_DIMENSION
void warningXML(bitpit::Logger *log, std::string name)
BaseManipulation is the base class of any manipulation object of the library.
void setCSV(bool csv)
void setReadDir(std::string dir)
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.
void swap(GenericInput &x) noexcept
void setBinary(bool binary)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
void setFilename(std::string filename)
#define M_SPAN
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
GenericInput(bool readFromFile=false, bool csv=false)
#define M_VALUED
void setReadFromFile(bool readFromFile)
#define M_DEG
void setFilename(std::string filename)
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void swap(GenericInputMPVData &x) noexcept
#define M_SCALARFIELD
void setGeometry(MimmoSharedPointer< MimmoObject > geometry)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
void swap(BaseManipulation &x) noexcept
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
#define M_COORDS
#define M_VALUEB