FVSelectionByBox.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 "FVMeshSelection.hpp"
26 
27 namespace mimmo{
28 
39  m_name = "mimmo.FVSelectionByBox";
41 };
42 
47 FVSelectionByBox::FVSelectionByBox(const bitpit::Config::Section & rootXML){
48 
49  m_name = "mimmo.FVSelectionByBox";
51 
52  std::string fallback_name = "ClassNONE";
53  std::string input = rootXML.get("ClassName", fallback_name);
54  input = bitpit::utils::string::trim(input);
55 
56  std::string fallback_name2 = "1";
57  std::string input_topo = rootXML.get("Topology", fallback_name2);
58  input_topo = bitpit::utils::string::trim(input_topo);
59 
60  int topo = std::stoi(input_topo);
61  topo = std::min(2,std::max(1, topo));
62  m_topo = topo;
63 
64  if(input == "mimmo.FVSelectionByBox"){
65  absorbSectionXML(rootXML);
66  }else{
68  };
69 }
70 
78  m_name = "mimmo.FVSelectionByBox";
80 
81  SelectionByBox * weng = static_cast<SelectionByBox*>(m_selectEngine.get());
82  weng->setOrigin(origin);
83  weng->setSpan(span);
84 
85 };
86 
91 
96 
101  swap(other);
102  return *this;
103 };
104 
111 {
113 }
114 
118 void
120 
122  bool built = m_arePortsBuilt;
123 
124  built = (built && createPortIn<darray3E, FVSelectionByBox>(this, &FVSelectionByBox::setOrigin, M_POINT ));
125  built = (built && createPortIn<darray3E, FVSelectionByBox>(this, &FVSelectionByBox::setSpan, M_SPAN));
126  built = (built && createPortIn<dmatrix33E, FVSelectionByBox>(this, &FVSelectionByBox::setRefSystem, M_AXES));
127 
128  m_arePortsBuilt = built;
129 };
130 
131 
137  static_cast<SelectionByBox *>(m_selectEngine.get())->setOrigin(origin);
138 }
139 
145  static_cast<SelectionByBox *>(m_selectEngine.get())->setSpan(span);
146 }
147 
148 
154  static_cast<SelectionByBox *>(m_selectEngine.get())->setRefSystem(axes);
155 }
156 
162 void
163 FVSelectionByBox::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
164 
165  BITPIT_UNUSED(name);
166  BaseManipulation::absorbSectionXML(slotXML, name);
167 
168  if(slotXML.hasOption("Topology")){
169  std::string input = slotXML.get("Topology");
170  input = bitpit::utils::string::trim(input);
171  int value = 1;
172  if(!input.empty()){
173  std::stringstream ss(input);
174  ss >> value;
175  }
176  if (m_topo != value) warningXML(m_log, m_name);
177  }else{
179  }
180 
181 
182  if(slotXML.hasOption("Dual")){
183  std::string input = slotXML.get("Dual");
184  input = bitpit::utils::string::trim(input);
185  bool value = false;
186  if(!input.empty()){
187  std::stringstream ss(input);
188  ss >> value;
189  }
190  setDual(value);
191  }
192 
193  if(slotXML.hasOption("Origin")){
194  std::string input = slotXML.get("Origin");
195  input = bitpit::utils::string::trim(input);
196  darray3E temp = {{0.0,0.0,0.0}};
197  if(!input.empty()){
198  std::stringstream ss(input);
199  ss>>temp[0]>>temp[1]>>temp[2];
200  setOrigin(temp);
201  }else{
202  setOrigin(temp);
203  }
204  }
205 
206  if(slotXML.hasOption("Span")){
207  std::string input = slotXML.get("Span");
208  input = bitpit::utils::string::trim(input);
209  darray3E temp = {{1.0,1.0,1.0}};
210  if(!input.empty()){
211  std::stringstream ss(input);
212  ss>>temp[0]>>temp[1]>>temp[2];
213  setSpan(temp);
214  }else{
215  setSpan(temp);
216  }
217  }
218 
219  if(slotXML.hasSection("RefSystem")){
220 
221  const bitpit::Config::Section & axesXML = slotXML.getSection("RefSystem");
222  dmatrix33E axes;
223  for(int i=0; i<3; ++i){
224  axes[i].fill(0.0);
225  axes[i][i] = 1.0;
226  }
227 
228  if(axesXML.hasOption("axis0")){
229  std::string input = axesXML.get("axis0");
230  input = bitpit::utils::string::trim(input);
231  if(!input.empty()){
232  std::stringstream ss(input);
233  ss>>axes[0][0]>>axes[0][1]>>axes[0][2];
234  }
235  }
236 
237  if(axesXML.hasOption("axis1")){
238  std::string input = axesXML.get("axis1");
239  input = bitpit::utils::string::trim(input);
240  if(!input.empty()){
241  std::stringstream ss(input);
242  ss>>axes[1][0]>>axes[1][1]>>axes[1][2];
243  }
244  }
245 
246  if(axesXML.hasOption("axis2")){
247  std::string input = axesXML.get("axis2");
248  input = bitpit::utils::string::trim(input);
249  if(!input.empty()){
250  std::stringstream ss(input);
251  ss>>axes[2][0]>>axes[2][1]>>axes[2][2];
252  }
253  }
254 
255  setRefSystem(axes);
256  }
257 };
258 
264 void
265 FVSelectionByBox::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
266 
267  BITPIT_UNUSED(name);
268 
269  BaseManipulation::flushSectionXML(slotXML,name);
270 
271  slotXML.set("Topology", std::to_string(m_topo));
272  slotXML.set("Dual", std::to_string(int(m_dual)));
273 
274  SelectionByBox * sel = static_cast<SelectionByBox*>(m_selectEngine.get());
275  {
276  darray3E org = sel->getOrigin();
277  std::stringstream ss;
278  ss<<std::scientific<<org[0]<<'\t'<<org[1]<<'\t'<<org[2];
279  slotXML.set("Origin",ss.str());
280  }
281 
282  {
283  darray3E span = sel->getSpan();
284  std::stringstream ss;
285  ss<<std::scientific<<span[0]<<'\t'<<span[1]<<'\t'<<span[2];
286  slotXML.set("Span",ss.str());
287  }
288 
289  {
290  dmatrix33E axes = sel->getRefSystem();
291  bitpit::Config::Section & axesXML = slotXML.addSection("RefSystem");
292 
293  for(int i=0; i<3; ++i){
294  std::string name = "axis"+std::to_string(i);
295  std::stringstream ss;
296  ss<<std::scientific<<axes[i][0]<<'\t'<<axes[i][1]<<'\t'<<axes[i][2];
297  axesXML.set(name, ss.str());
298  }
299  }
300 
301 };
302 
303 }
void setOrigin(darray3E)
void setDual(bool flag=false)
void setOrigin(darray3E origin)
Interface for applying selection methods simultaneously on bulk+boundary compound meshes.
void setSpan(darray3E span)
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
#define M_POINT
void warningXML(bitpit::Logger *log, std::string name)
FVGenericSelection class specialized for selections with volume box primitive shapes.
void swap(FVSelectionByBox &) noexcept
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
std::array< darray3E, 3 > dmatrix33E
#define M_SPAN
MimmoSharedPointer< GenericSelection > m_selectEngine
#define M_AXES
darray3E getOrigin()
Selection through volume box primitive.
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
darray3E getSpan()
FVSelectionByBox & operator=(FVSelectionByBox other)
std::array< double, 3 > darray3E
dmatrix33E getRefSystem()
void setSpan(double, double, double)
MimmoSharedPointer is a custom implementation of shared pointer.
void setRefSystem(dmatrix33E axes)
void swap(FVGenericSelection &x) noexcept