GenericSelection.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 "MeshSelection.hpp"
26 
27 namespace mimmo {
28 
34  m_topo = 1; /*default to surface geometry*/
35  m_dual = false; /*default to exact selection*/
36 };
37 
42  m_subpatch.reset();
43 };
44 
49  m_type = other.m_type;
50  m_topo = other.m_topo;
51  m_dual = other.m_dual;
52 };
53 
58  *(static_cast<BaseManipulation *>(this)) = *(static_cast<const BaseManipulation * >(&other));
59  m_type = other.m_type;
60  m_topo = other.m_topo;
61  m_dual = other.m_dual;
62  /*m_subpatch is not copied and it is obtained in execution*/
63  return *this;
64 };
65 
72 {
73  std::swap(m_type, x.m_type);
74  std::swap(m_topo, x.m_topo);
75  std::swap(m_dual, x.m_dual);
77 }
78 
82 void
84 
85  bool built = true;
86 
87  built = (built && createPortIn<mimmo::MimmoSharedPointer<MimmoObject>, GenericSelection>(this, &GenericSelection::setGeometry, M_GEOM, true));
88  built = (built && createPortIn<bool, GenericSelection>(this, &GenericSelection::setDual,M_VALUEB));
89 
90  built = (built && createPortOut<mimmo::MimmoSharedPointer<MimmoObject>, GenericSelection>(this, &GenericSelection::getPatch,M_GEOM));
91  built = (built && createPortOut<livector1D, GenericSelection>(this, &GenericSelection::constrainedBoundary, M_VECTORLI));
92  m_arePortsBuilt = built;
93 };
94 
95 
103  return m_type;
104 };
105 
112  return m_subpatch;
113 };
114 
121  return m_subpatch;
122 };
123 
129 void
131  if(target == nullptr) return;
132  m_geometry = target;
133  /*set topology informations*/
134  m_topo = target->getType();
135 
136 };
137 
138 
151 void
153  m_dual = flag;
154 }
155 
160 bool
162  return m_dual;
163 };
164 
177 
178  if(getGeometry() == nullptr || getPatch() == nullptr) return livector1D(0);
179  std::unordered_map<long, std::set<int> > survivors;
180 
181  auto daughterBCells = getPatch()->extractBoundaryFaceCellID(true);
182  auto motherBCells = getGeometry()->extractBoundaryFaceCellID(true);
183 
184  //save all those daughter boundary faces not included in mother pot
185  for(const auto & sT : daughterBCells){
186  if(motherBCells.count(sT.first) > 0){
187  for(const auto & val: sT.second){
188  if(motherBCells[sT.first].count(val) > 0) continue;
189  survivors[sT.first].insert(val);
190  }
191  }else{
192  survivors[sT.first] = daughterBCells[sT.first];
193  }
194  }
195  motherBCells.clear();
196  daughterBCells.clear();
197 
198  //get vertex of the cleaned daughter boundary.
199  std::unordered_set<long> containerVert;
200  containerVert.reserve(getPatch()->getPatch()->getVertexCount());
201  for(const auto & sT :survivors){
202  const bitpit::Cell & cell = getPatch()->getPatch()->getCell(sT.first);
203  for(const auto & val: sT.second){
204  bitpit::ConstProxyVector<long> faceVertIds = cell.getFaceVertexIds(val);
205  containerVert.insert(faceVertIds.begin(), faceVertIds.end());
206  }
207  }
208  //move up in livector1D container.
209  livector1D result;
210  result.reserve(containerVert.size());
211  result.insert(result.end(), containerVert.begin(), containerVert.end());
212 
213  return result;
214 };
215 
216 
221 void
223  if(getGeometry() == nullptr) {
224  (*m_log)<<m_name + " : nullptr pointer to target geometry found"<<std::endl;
225  throw std::runtime_error (m_name + " : nullptr pointer to target geometry found");
226  }
227 
228  m_subpatch.reset();
229 
230 // extract all the interior cell satisfying the extraction criterium.
231  livector1D extracted = extractSelection();
232 
233  /*Create subpatch.*/
235 
236  /* Set the same tolerance of the mother geoemtry*/
237  temp->setTolerance(getGeometry()->getTolerance());
238 
239  if (m_topo != 3){
240 
241  livector1D vertExtracted = getGeometry()->getVertexFromCellList(extracted);
242  for(const auto & idV : vertExtracted){
243  temp->addVertex(getGeometry()->getVertexCoords(idV), idV);
244  }
245 
246  int rank;
247  for(const auto & idCell : extracted){
248  bitpit::Cell & cell = getGeometry()->getPatch()->getCell(idCell);
249  rank = -1;
250 #if MIMMO_ENABLE_MPI
251  rank = getGeometry()->getPatch()->getCellRank(idCell);
252 #endif
253  temp->addCell(cell, idCell, rank);
254  }
255 
256  }else{
257 
258  for(const auto & idV : extracted){
259  temp->addVertex(getGeometry()->getVertexCoords(idV),idV);
260  }
261 
262  }
263 
264  auto originalmap = getGeometry()->getPIDTypeListWNames();
265  auto currentPIDmap = temp->getPIDTypeList();
266  for(const auto & val: currentPIDmap){
267  temp->setPIDName(val, originalmap[val]);
268  }
269  m_subpatch = temp;
270 
271  // Clean and Update selection patch. This will update even parallel structures if needed.
272  m_subpatch->cleanGeometry();
273  m_subpatch->update();
274 
275 };
276 
281 void
283 
284  write(getPatch());
285 
286 }
287 
288 }
Abstract Interface for selection classes.
MimmoObject is the basic geometry container for mimmo library.
#define M_GEOM
std::vector< long > livector1D
mimmo::MimmoSharedPointer< MimmoObject > m_subpatch
SelectionType
Enum class for choiche of method to select sub-patch of a MimmoObject tessellated mesh.
BaseManipulation is the base class of any manipulation object of the library.
void write(MimmoSharedPointer< MimmoObject > geometry)
MimmoSharedPointer< MimmoObject > m_geometry
void swap(GenericSelection &x) noexcept
const mimmo::MimmoSharedPointer< MimmoObject > getPatch() const
virtual void plotOptionalResults()
void setDual(bool flag=false)
virtual void setGeometry(mimmo::MimmoSharedPointer< MimmoObject >)
GenericSelection & operator=(const GenericSelection &other)
MimmoSharedPointer is a custom implementation of shared pointer.
MimmoSharedPointer< MimmoObject > getGeometry()
virtual livector1D extractSelection()=0
void swap(BaseManipulation &x) noexcept
#define M_VALUEB
#define M_VECTORLI