FVSelectionByCylinder.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.FVSelectionByCylinder";
41 };
42 
47 FVSelectionByCylinder::FVSelectionByCylinder(const bitpit::Config::Section & rootXML){
48 
49  m_name = "mimmo.FVSelectionByCylinder";
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 
65  if(input == "mimmo.FVSelectionByCylinder"){
66  absorbSectionXML(rootXML);
67  }else{
69  };
70 }
71 
81  double infLimTheta, darray3E mainAxis):
82  FVGenericSelection(topo)
83 {
84  m_name = "mimmo.FVSelectionByCylinder";
86  SelectionByCylinder *weng = static_cast<SelectionByCylinder *>(m_selectEngine.get());
87  weng->setOrigin(origin);
88  weng->setSpan(span);
89  weng->setInfLimits(infLimTheta,1);
90  weng->setRefSystem(2, mainAxis);
91 };
92 
97 
102 
107  swap(other);
108  return *this;
109 };
110 
117 {
119 }
120 
124 void
126 
128  bool built = m_arePortsBuilt;
129 
130  built = (built && createPortIn<darray3E, FVSelectionByCylinder>(this, &FVSelectionByCylinder::setOrigin,M_POINT));
131  built = (built && createPortIn<darray3E, FVSelectionByCylinder>(this, &FVSelectionByCylinder::setSpan, M_SPAN));
132  built = (built && createPortIn<dmatrix33E, FVSelectionByCylinder>(this, &FVSelectionByCylinder::setRefSystem, M_AXES));
133  built = (built && createPortIn<darray3E, FVSelectionByCylinder>(this, &FVSelectionByCylinder::setInfLimits, M_INFLIMITS));
134 
135  m_arePortsBuilt = built;
136 };
137 
138 
144  static_cast<SelectionByCylinder *>(m_selectEngine.get())->setOrigin(origin);
145 }
146 
153  static_cast<SelectionByCylinder *>(m_selectEngine.get())->setSpan(span);
154 }
155 
156 
162  static_cast<SelectionByCylinder *>(m_selectEngine.get())->setRefSystem(axes);
163 }
164 
171  static_cast<SelectionByCylinder *>(m_selectEngine.get())->setInfLimits(val);
172 }
178 void
179 FVSelectionByCylinder::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
180 
181  BITPIT_UNUSED(name);
182 
183  BaseManipulation::absorbSectionXML(slotXML, name);
184 
185  if(slotXML.hasOption("Topology")){
186  std::string input = slotXML.get("Topology");
187  input = bitpit::utils::string::trim(input);
188  int value = 1;
189  if(!input.empty()){
190  std::stringstream ss(input);
191  ss >> value;
192  }
193  if (m_topo != value) warningXML(m_log, m_name);
194  }else{
196  }
197 
198  if(slotXML.hasOption("Dual")){
199  std::string input = slotXML.get("Dual");
200  input = bitpit::utils::string::trim(input);
201  bool value = false;
202  if(!input.empty()){
203  std::stringstream ss(input);
204  ss >> value;
205  }
206  setDual(value);
207  }
208 
209  if(slotXML.hasOption("Origin")){
210  std::string input = slotXML.get("Origin");
211  input = bitpit::utils::string::trim(input);
212  darray3E temp = {{0.0,0.0,0.0}};
213  if(!input.empty()){
214  std::stringstream ss(input);
215  ss>>temp[0]>>temp[1]>>temp[2];
216  setOrigin(temp);
217  }else{
218  setOrigin(temp);
219  }
220  }
221 
222  if(slotXML.hasOption("Span")){
223  std::string input = slotXML.get("Span");
224  input = bitpit::utils::string::trim(input);
225  darray3E temp = {{1.0,2.0*BITPIT_PI,1.0}};
226  if(!input.empty()){
227  std::stringstream ss(input);
228  ss>>temp[0]>>temp[1]>>temp[2];
229  setSpan(temp);
230  }else{
231  setSpan(temp);
232  }
233  }
234 
235  if(slotXML.hasSection("RefSystem")){
236 
237  const bitpit::Config::Section & axesXML = slotXML.getSection("RefSystem");
238  dmatrix33E axes;
239  for(int i=0; i<3; ++i){
240  axes[i].fill(0.0);
241  axes[i][i] = 1.0;
242  }
243 
244  if(axesXML.hasOption("axis0")){
245  std::string input = axesXML.get("axis0");
246  input = bitpit::utils::string::trim(input);
247  if(!input.empty()){
248  std::stringstream ss(input);
249  ss>>axes[0][0]>>axes[0][1]>>axes[0][2];
250  }
251  }
252 
253  if(axesXML.hasOption("axis1")){
254  std::string input = axesXML.get("axis1");
255  input = bitpit::utils::string::trim(input);
256  if(!input.empty()){
257  std::stringstream ss(input);
258  ss>>axes[1][0]>>axes[1][1]>>axes[1][2];
259  }
260  }
261 
262  if(axesXML.hasOption("axis2")){
263  std::string input = axesXML.get("axis2");
264  input = bitpit::utils::string::trim(input);
265  if(!input.empty()){
266  std::stringstream ss(input);
267  ss>>axes[2][0]>>axes[2][1]>>axes[2][2];
268  }
269  }
270  setRefSystem(axes);
271  }
272 
273  if(slotXML.hasOption("InfLimits")){
274  std::string input = slotXML.get("InfLimits");
275  input = bitpit::utils::string::trim(input);
276  darray3E temp = {{0.0,0.0,0.0}};
277  if(!input.empty()){
278  std::stringstream ss(input);
279  ss>>temp[0]>>temp[1]>>temp[2];
280  setInfLimits(temp);
281  }else{
282  setInfLimits(temp);
283  }
284  }
285 
286 };
287 
293 void
294 FVSelectionByCylinder::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
295 
296  BITPIT_UNUSED(name);
297 
298  BaseManipulation::flushSectionXML(slotXML, name);
299 
300  slotXML.set("Topology", std::to_string(m_topo));
301  slotXML.set("Dual", std::to_string(int(m_dual)));
302  SelectionByCylinder * sel = static_cast<SelectionByCylinder*>(m_selectEngine.get());
303 
304  {
305  darray3E org = sel->getOrigin();
306  std::stringstream ss;
307  ss<<std::scientific<<org[0]<<'\t'<<org[1]<<'\t'<<org[2];
308  slotXML.set("Origin",ss.str());
309  }
310 
311  {
312  darray3E span = sel->getSpan();
313  std::stringstream ss;
314  ss<<std::scientific<<span[0]<<'\t'<<span[1]<<'\t'<<span[2];
315  slotXML.set("Span",ss.str());
316  }
317 
318  {
319  dmatrix33E axes = sel->getRefSystem();
320  bitpit::Config::Section & axesXML = slotXML.addSection("RefSystem");
321 
322  for(int i=0; i<3; ++i){
323  std::string name = "axis"+std::to_string(i);
324  std::stringstream ss;
325  ss<<std::scientific<<axes[i][0]<<'\t'<<axes[i][1]<<'\t'<<axes[i][2];
326  axesXML.set(name, ss.str());
327  }
328  }
329 
330  {
331  darray3E inflim = sel->getInfLimits();
332  std::stringstream ss;
333  ss<<std::scientific<<inflim[0]<<'\t'<<inflim[1]<<'\t'<<inflim[2];
334  slotXML.set("InfLimits",ss.str());
335  }
336 
337 };
338 
339 }
darray3E getInfLimits()
void setOrigin(darray3E)
void swap(FVSelectionByCylinder &) noexcept
void setInfLimits(double val, int dir)
FVGenericSelection class specialized for selections with volume cylindrical primitive shapes.
void setDual(bool flag=false)
Interface for applying selection methods simultaneously on bulk+boundary compound meshes.
#define M_POINT
void warningXML(bitpit::Logger *log, std::string name)
#define M_INFLIMITS
Selection through cylinder primitive.
void setRefSystem(darray3E, darray3E, darray3E)
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()
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
FVSelectionByCylinder & operator=(FVSelectionByCylinder other)
darray3E getSpan()
std::array< double, 3 > darray3E
dmatrix33E getRefSystem()
void setSpan(double, double, double)
MimmoSharedPointer is a custom implementation of shared pointer.
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
void swap(FVGenericSelection &x) noexcept