ExtractFields.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 "ExtractFields.hpp"
26 
27 namespace mimmo{
28 
33  m_tol = 1.0e-08;
34 }
35 
40  clear();
41 };
42 
48  m_mode = other.m_mode;
49  m_tol = other.m_tol;
50 }
51 
56 void ExtractField::swap(ExtractField & x ) noexcept
57 {
58  std::swap(m_mode,x.m_mode);
59  std::swap(m_tol, x.m_tol);
61 };
62 
69  m_mode = other.m_mode;
70  m_tol = other.m_tol;
71  return *this;
72 };
73 
77 void
79  bool built = true;
80  built = (built && createPortIn<MimmoSharedPointer<MimmoObject>, ExtractField>(this, &mimmo::ExtractField::setGeometry, M_GEOM, true));
81  m_arePortsBuilt = built;
82 }
83 
88 void
90  setMode(static_cast<int>(mode));
91 };
92 
97 void
99  if(mode < 1 ||mode > 3) return;
100  m_mode = static_cast<ExtractMode>(mode);
101 };
102 
107 void
109  m_tol = std::max(1.0e-12, tol);
110 };
111 
116 double
118  return m_tol;
119 };
120 
127  return m_mode;
128 };
129 
133 void
136 };
137 
141 void
143 
144  bool check = extract();
145  if(!check){
146  (*m_log)<<"error in class "<<m_name<<". Field cannot be extracted"<<std::endl;
147  (*m_log)<<"This could be due to not correct setting of geometries or division maps"<<std::endl;
148  return;
149  }
150 }
151 
157 void ExtractField::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
158 
159  BITPIT_UNUSED(name);
160 
161  BaseManipulation::absorbSectionXML(slotXML, name);
162 
163  std::string input;
164 
165  if(slotXML.hasOption("ExtractMode")){
166  input = slotXML.get("ExtractMode");
167  input = bitpit::utils::string::trim(input);
168  int value = 1;
169  if(!input.empty()){
170  std::stringstream ss(input);
171  ss >> value;
172  value = std::min(std::max(1, value),3);
173  }
174  };
175 
176  if(slotXML.hasOption("Tolerance")){
177  std::string input = slotXML.get("Tolerance");
178  input = bitpit::utils::string::trim(input);
179  double temp = 0.0;
180  if(!input.empty()){
181  std::stringstream ss(input);
182  ss>>temp;
183  }
184  setTolerance(temp);
185  }
186 
187 };
188 
194 void ExtractField::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
195 
196  BITPIT_UNUSED(name);
197  BaseManipulation::flushSectionXML(slotXML, name);
198 
199 
200  int value = static_cast<int>(m_mode);
201  slotXML.set("ExtractMode", std::to_string(value));
203  slotXML.set("Tolerance", std::to_string(m_tol));
204 
205 };
206 
207 }
ExtractMode
Modes available to extract fields.See class ExtractField documentation.
void swap(ExtractField &x) noexcept
#define M_GEOM
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
ExtractField is an abstract executable block class for extracting/restricting an input field defined ...
BaseManipulation is the base class of any manipulation object of the library.
ExtractMode getMode()
BaseManipulation & operator=(const BaseManipulation &other)
void setTolerance(double tol)
ExtractField & operator=(const ExtractField &other)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
void setGeometry(MimmoSharedPointer< MimmoObject > geometry)
void swap(BaseManipulation &x) noexcept
void setMode(ExtractMode mode)
virtual bool extract()=0