SelectField.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 "SelectField.hpp"
26 
27 namespace mimmo{
28 
33  m_fieldname = "data";
34  m_tol = 1.0e-12;
35 }
36 
41  clear();
42 };
43 
47  m_mode = other.m_mode;
48  m_fieldname = other.m_fieldname;
49  m_tol = other.m_tol;
50 };
51 
56 void SelectField::swap(SelectField & x) noexcept
57 {
58  std::swap(m_mode, x.m_mode);
59  std::swap(m_fieldname, x.m_fieldname);
60  std::swap(m_tol, x.m_tol);
62 }
63 
67 void
69  bool built = true;
70  built = (built && createPortIn<mimmo::MimmoSharedPointer<MimmoObject>, SelectField>(this, &mimmo::SelectField::setGeometry, M_GEOM));
71  built = (built && createPortIn<std::string, SelectField>(this, &mimmo::SelectField::setFieldName, M_NAME));
72  built = (built && createPortOut<std::string, SelectField>(this, &mimmo::SelectField::getFieldName, M_NAME));
73  built = (built && createPortOut<mimmo::MimmoSharedPointer<MimmoObject>, SelectField>(this, &mimmo::BaseManipulation::getGeometry, M_GEOM));
74  m_arePortsBuilt = built;
75 }
76 
83 void
84 SelectField::setFieldName(std::string fieldname){
85  m_fieldname = fieldname;
86 };
87 
92 void
94  m_mode = mode;
95 };
96 
101 void
103  setMode(static_cast<SelectType>(mode));
104 };
105 
110 void
112  m_tol = std::max(1.0e-12, tol);
113 };
114 
119 std::string
121  return m_fieldname;
122 };
126 void
129 };
130 
134 void
136 
137  bool check = mSelect();
138  if(!check){
139  (*m_log)<<"Error in "<<m_name<<". Field cannot be Selected"<<std::endl;
140  (*m_log)<<"This could be due to not correct settings:"<<std::endl;
141  switch(m_mode){
142  case SelectType::GEOMETRY :
143  (*m_log)<<" missing or unfound ref Geometry to select field ->see method setGeometry//M_GEOM port"<<std::endl;
144  break;
145  case SelectType::MAPPING :
146  (*m_log)<<" missing mapping Geometry to select field ->see method setGeometry//M_GEOM port"<<std::endl;
147  break;
148  case SelectType::NAME :
149  (*m_log)<<" missing or unfound name to select field ->see method setFieldName//M_NAME port"<<std::endl;
150  break;
151  default:
152  //never been reached
153  break;
154  }
155  (*m_log)<<"Return empty field"<<std::endl;
156  }
157 }
158 
164 void SelectField::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
165 
166  BITPIT_UNUSED(name);
167 
168  BaseManipulation::absorbSectionXML(slotXML, name);
169 
170 
171  if(slotXML.hasOption("SelectType")){
172  std::string input = slotXML.get("SelectType");
173  input = bitpit::utils::string::trim(input);
174  bool value = false;
175  if(!input.empty()){
176  std::stringstream ss(input);
177  ss >> value;
178  }
179  setMode(value);
180  }
181 
182  if(slotXML.hasOption("FieldName")){
183  std::string input = slotXML.get("FieldName");
184  input = bitpit::utils::string::trim(input);
185  if(!input.empty()){
186  setFieldName(input);
187  }
188  }
189  if(slotXML.hasOption("Tolerance")){
190  std::string input = slotXML.get("Tolerance");
191  input = bitpit::utils::string::trim(input);
192  double temp = 0.0;
193  if(!input.empty()){
194  std::stringstream ss(input);
195  ss>>temp;
196  }
197  setTolerance(temp);
198  }
199 
200 };
201 
207 void SelectField::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
208 
209  BITPIT_UNUSED(name);
210  BaseManipulation::flushSectionXML(slotXML, name);
211 
212  slotXML.set("SelectType", std::to_string(static_cast<int>(m_mode)));
214  slotXML.set("Tolerance", std::to_string(m_tol));
215 
216  slotXML.set("FieldName", m_fieldname);
217 
218 };
219 
220 }
virtual ~SelectField()
Definition: SelectField.cpp:40
void swap(SelectField &) noexcept
Definition: SelectField.cpp:56
#define M_GEOM
void setMode(SelectType mode)
Definition: SelectField.cpp:93
void setFieldName(std::string fieldname)
Definition: SelectField.cpp:84
BaseManipulation is the base class of any manipulation object of the library.
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
std::string getFieldName()
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
SelectType
Methods available for selecting a field.
Definition: SelectField.hpp:35
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
std::string m_fieldname
#define M_NAME
void setGeometry(MimmoSharedPointer< MimmoObject > geometry)
SelectField is an abstract executable block class capable of Selecting a field from a list of fields.
Definition: SelectField.hpp:97
MimmoSharedPointer< MimmoObject > getGeometry()
void swap(BaseManipulation &x) noexcept
void setTolerance(double tol)
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")