SelectionByElementList.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 
33  m_name = "mimmo.SelectionByElementList";
34 };
35 
40 SelectionByElementList::SelectionByElementList(const bitpit::Config::Section & rootXML){
41 
42  m_name = "mimmo.SelectionByElementList";
43 
44  std::string fallback_name = "ClassNONE";
45  std::string input = rootXML.get("ClassName", fallback_name);
46  input = bitpit::utils::string::trim(input);
47  if(input == "mimmo.SelectionByElementList"){
48  absorbSectionXML(rootXML);
49  }else{
51  };
52 }
53 
58 
59 
66 {
68  std::swap(m_annotatedcells, x.m_annotatedcells);
69  std::swap(m_annotatedvertices, x.m_annotatedvertices);
70  std::swap(m_rawcells, x.m_rawcells);
71  std::swap(m_rawvertices, x.m_rawvertices);
72 }
73 
77 void
79 
81  bool built = m_arePortsBuilt;
82 
83  built = (built && createPortIn<MimmoPiercedVector<long> *, SelectionByElementList>(this, &SelectionByElementList::addAnnotatedCellList, M_LONGFIELD2,true,2 ));
84  built = (built && createPortIn<MimmoPiercedVector<long> *, SelectionByElementList>(this, &SelectionByElementList::addAnnotatedVertexList, M_LONGFIELD,true,2 ));
85  built = (built && createPortIn<std::vector<long>, SelectionByElementList>(this, &SelectionByElementList::addRawCellList, M_VECTORLI3,true,2 ));
86  built = (built && createPortIn<std::vector<long>, SelectionByElementList>(this, &SelectionByElementList::addRawVertexList, M_VECTORLI2,true,2 ));
87 
88  m_arePortsBuilt = built;
89 };
90 
96 void
98  if(!celldata) return;
99  if(celldata->getDataLocation() != MPVLocation::CELL) return;
100  m_annotatedcells.push_back(celldata);
101 }
102 
109 void
111  if(!vertexdata) return;
112  if(vertexdata->getDataLocation() != MPVLocation::POINT) return;
113  m_annotatedvertices.push_back(vertexdata);
114 }
115 
121 void
122 SelectionByElementList::addRawCellList(std::vector<long> celldata){
123  if(celldata.empty()) return;
124  m_rawcells.push_back(celldata);
125 }
126 
133 void
134 SelectionByElementList::addRawVertexList(std::vector<long> vertexdata){
135  if(vertexdata.empty()) return;
136  m_rawvertices.push_back(vertexdata);
137 }
138 
139 
143 void
145  m_subpatch.reset();
147  m_annotatedcells.clear();
148  m_annotatedvertices.clear();
149  m_rawcells.clear();
150  m_rawvertices.clear();
151 };
152 
153 
154 
162 
164  std::unordered_set<long> setstruct;
165  //fill a non repeated list of vertices ids
167  std::vector<long> temp = ptr->getIds();
168  setstruct.insert(temp.begin(), temp.end());
169  }
170  for(std::vector<long> list: m_rawvertices){
171  setstruct.insert(list.begin(), list.end());
172  }
173 
174  //check them w.r.t the geometry ids, then get their intersection vertexSureList;
175  long id;
176  livector1D vertexSureList;
177  vertexSureList.reserve(std::min(setstruct.size(), std::size_t(geo->getNVertices())));
178  for(auto it=geo->getPatch()->vertexBegin(); it!=geo->getPatch()->vertexEnd(); ++it){
179  id = it.getId();
180  if(setstruct.count(id) > 0){
181  vertexSureList.push_back(id);
182  }
183  }
184  vertexSureList.shrink_to_fit();
185 
186  //check if you are dealing with point clouds. if it's the case, return the vertex list;
187  if(m_topo == 3) return vertexSureList;
188 
189  //otherwise you need to do the same for cells.
190  setstruct.clear();
191 
192  // push the cells identified by vertices in the unordered struct.
193  livector1D addOtherCells = geo->getCellFromVertexList(vertexSureList, true);
194  setstruct.insert(addOtherCells.begin(), addOtherCells.end());
195  vertexSureList.clear();
196  addOtherCells.clear();
197 
198  //fill the list with the cell ids from inputs.
200  std::vector<long> temp = ptr->getIds();
201  setstruct.insert(temp.begin(), temp.end());
202  }
203  for(std::vector<long> list: m_rawcells){
204  setstruct.insert(list.begin(), list.end());
205  }
206 
207  //check them w.r.t the geometry ids, then get their intersection cellSureList;
208  livector1D cellSureList;
209  cellSureList.reserve(std::min(setstruct.size(), std::size_t(geo->getNCells())));
210  for(auto it=geo->getPatch()->cellBegin(); it!=geo->getPatch()->cellEnd(); ++it){
211  id = it.getId();
212  if(setstruct.count(id) > 0){
213  cellSureList.push_back(id);
214  }
215  }
216 
217  cellSureList.shrink_to_fit();
218 
219  return cellSureList;
220 };
221 
222 
228 void
229 SelectionByElementList::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
230 
231  BITPIT_UNUSED(name);
232  BaseManipulation::absorbSectionXML(slotXML, name);
233 
234  if(slotXML.hasOption("Dual")){
235  std::string input = slotXML.get("Dual");
236  input = bitpit::utils::string::trim(input);
237  bool value = false;
238  if(!input.empty()){
239  std::stringstream ss(input);
240  ss >> value;
241  }
242  setDual(value);
243  }
244 
245 };
246 
252 void
253 SelectionByElementList::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
254 
255  BITPIT_UNUSED(name);
256 
257  BaseManipulation::flushSectionXML(slotXML,name);
258 
259  slotXML.set("Dual", std::to_string(m_dual));
260 
261 };
262 
263 }
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
#define M_LONGFIELD
void addRawVertexList(std::vector< long > vertexdata)
Selection through list of cells/vertices of the target mesh.
std::vector< long > livector1D
#define M_VECTORLI3
mimmo::MimmoSharedPointer< MimmoObject > m_subpatch
#define M_LONGFIELD2
std::vector< MimmoPiercedVector< long > * > m_annotatedvertices
void warningXML(bitpit::Logger *log, std::string name)
std::vector< MimmoPiercedVector< long > * > m_annotatedcells
void swap(SelectionByElementList &) noexcept
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void swap(GenericSelection &x) noexcept
void addAnnotatedVertexList(MimmoPiercedVector< long > *vertexdata)
void addAnnotatedCellList(MimmoPiercedVector< long > *celldata)
#define M_VECTORLI2
std::vector< std::vector< long > > m_rawvertices
void setDual(bool flag=false)
std::vector< std::vector< long > > m_rawcells
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
MimmoSharedPointer is a custom implementation of shared pointer.
MimmoSharedPointer< MimmoObject > getGeometry()
void addRawCellList(std::vector< long > celldata)