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