CreatePointCloud.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 "CreatePointCloud.hpp"
26 
27 namespace mimmo {
28 
33  m_name = "mimmo.CreatePointCloud";
34 };
35 
40 CreatePointCloud::CreatePointCloud(const bitpit::Config::Section & rootXML){
41 
42  m_name = "mimmo.CreatePointCloud";
43 
44  std::string fallback_name = "ClassNONE";
45  std::string input = rootXML.get("ClassName", fallback_name);
46  input = bitpit::utils::string::trim(input);
47 
48  if(input == "mimmo.CreatePointCloud"){
49  absorbSectionXML(rootXML);
50  }else{
52  };
53 }
54 
55 
56 CreatePointCloud::~CreatePointCloud(){};
57 
62  m_rawpoints = other.m_rawpoints;
63  m_rawvector = other.m_rawvector;
64  m_rawscalar = other.m_rawscalar;
65 };
66 
70  swap(other);
71  return *this;
72 };
73 
79 {
80  m_rawpoints.swap(x.m_rawpoints);
81  m_rawscalar.swap(x.m_rawscalar);
82  m_rawvector.swap(x.m_rawvector);
83  m_scalarfield.swap(x.m_scalarfield);
84  m_vectorfield.swap(x.m_vectorfield);
85 
87 }
88 
92 void
94  bool built = true;
95 
96  built = (built && createPortIn<dvecarr3E, CreatePointCloud>(this, &mimmo::CreatePointCloud::setRawPoints, M_COORDS, true,1));
97  built = (built && createPortIn<dvecarr3E, CreatePointCloud>(this, &mimmo::CreatePointCloud::setRawVectorField, M_DISPLS));
98  built = (built && createPortIn<dvector1D, CreatePointCloud>(this, &mimmo::CreatePointCloud::setRawScalarField, M_DATAFIELD));
99 
100  built = (built && createPortIn<dmpvecarr3E*, CreatePointCloud>(this, &mimmo::CreatePointCloud::setRawPoints, M_VECTORFIELD, true,1));
101  built = (built && createPortIn<dmpvecarr3E*, CreatePointCloud>(this, &mimmo::CreatePointCloud::setRawVectorField, M_VECTORFIELD2));
102  built = (built && createPortIn<dmpvector1D*, CreatePointCloud>(this, &mimmo::CreatePointCloud::setRawScalarField, M_SCALARFIELD));
103 
104  built = (built && createPortOut<MimmoSharedPointer<MimmoObject>, CreatePointCloud>(this, &mimmo::CreatePointCloud::getGeometry, M_GEOM));
105  built = (built && createPortOut<dmpvector1D*, CreatePointCloud>(this, &mimmo::CreatePointCloud::getScalarField, M_SCALARFIELD));
106  built = (built && createPortOut<dmpvecarr3E*, CreatePointCloud>(this, &mimmo::CreatePointCloud::getVectorField, M_VECTORFIELD));
107 
108  m_arePortsBuilt = built;
109 }
110 
117  return &m_scalarfield;
118 };
119 
126  return &m_vectorfield;
127 };
128 
129 
134 void
136  if(rawPoints) m_rawpoints = *rawPoints;
137 };
138 
143 void
145  m_rawpoints.clear();
146  m_rawpoints.reserve(rawPoints.size());
147  long count(0);
148  for(std::array<double,3> &val : rawPoints){
149  m_rawpoints.insert(count, val);
150  ++count;
151  }
152 };
153 
158 void
160  if(rawVectorField) m_rawvector = *rawVectorField;
161 };
162 
167 void
169  m_rawvector.clear();
170  m_rawvector.reserve(rawVectorField.size());
171  long count(0);
172  for(std::array<double,3> &val : rawVectorField){
173  m_rawvector.insert(count, val);
174  ++count;
175  }
176 };
177 
182 void
184  if(rawScalarField) m_rawscalar = *rawScalarField;
185 };
186 
191 void
193  m_rawscalar.clear();
194  m_rawscalar.reserve(rawScalarField.size());
195  long count(0);
196  for(double &val : rawScalarField){
197  m_rawscalar.insert(count, val);
198  ++count;
199  }
200 };
201 
205 void
209  m_rawscalar.clear();
210  m_rawvector.clear();
211  m_rawpoints.clear();
213 }
214 
219 void
221 
222  long np = m_rawpoints.size();
223 
224 #if MIMMO_ENABLE_MPI
225  // Rawpoints can be shared among all procs or retained by 0 only.
226  // The condition is that rank 0 must have the input points, because
227  // the geometry is filled only by master processor 0. The only useful
228  // points are those owned by rank 0.
229  // Check if rank 0 owns some points (not communicated to the other processors).
230  MPI_Bcast(&np, 1, MPI_INT, 0, m_communicator);
231 #endif
232 
233  if(np == 0){
234  (*m_log)<< "Warning in "<<m_name<<" : no raw points to work on"<<std::endl;
235  }
236 
237  //fill the point cloud
238  {
240  m_geometry = dum;
241  }
242 #if MIMMO_ENABLE_MPI
243  //leave the filling to the master rank
244  if(getRank() == 0)
245 #endif
246  {
247  m_geometry->getPatch()->reserveVertices(np);
248  m_geometry->getPatch()->reserveCells(np);
249 
250  long id;
251  for(auto it= m_rawpoints.begin(); it != m_rawpoints.end(); ++it){
252  id = it.getId();
253  m_geometry->addVertex(*it, id);
254  m_geometry->addConnectedCell(livector1D(1,id), bitpit::ElementType::VERTEX, 0, id, 0);
255  }
256  }
257 
259  m_scalarfield.setName("PCScalar");
260 
262  m_vectorfield.setName("PCVector");
263 
264  //fill data attached
265 #if MIMMO_ENABLE_MPI
266  //leave the filling to the master rank
267  if(getRank() == 0)
268 #endif
269  {
270  for(auto it=m_rawscalar.begin(); it!=m_rawscalar.end(); ++it){
271  if(m_scalarfield.exists(it.getId())) m_scalarfield[it.getId()] = *it;
272  }
273  for(auto it=m_rawvector.begin(); it!=m_rawvector.end(); ++it){
274  if(m_vectorfield.exists(it.getId())) m_vectorfield[it.getId()] = *it;
275  }
276  }
277 
278  m_geometry->update();
279 };
280 
286 void
287 CreatePointCloud::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
288 
289  BITPIT_UNUSED(name);
290 
291  BaseManipulation::absorbSectionXML(slotXML, name);
292 }
293 
299 void
300 CreatePointCloud::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
301 
302  BITPIT_UNUSED(name);
303 
304  BaseManipulation::flushSectionXML(slotXML, name);
305 
306 };
307 
308 
312 void
314 
315  if (getGeometry() == nullptr) return;
317 }
318 
319 }
void setRawVectorField(dvecarr3E rawVectorField)
#define M_DATAFIELD
MimmoObject is the basic geometry container for mimmo library.
#define M_DISPLS
#define M_GEOM
dmpvecarr3E * getVectorField()
std::vector< darray3E > dvecarr3E
void setName(std::string name)
std::vector< long > livector1D
void warningXML(bitpit::Logger *log, std::string name)
BaseManipulation is the base class of any manipulation object of the library.
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
#define M_VECTORFIELD
dmpvector1D * getScalarField()
void write(MimmoSharedPointer< MimmoObject > geometry)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
void setRawPoints(dvecarr3E rawPoints)
std::vector< double > dvector1D
void initialize(MimmoSharedPointer< MimmoObject >, MPVLocation, const mpv_t &)
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
MimmoSharedPointer< MimmoObject > m_geometry
#define M_SCALARFIELD
#define M_VECTORFIELD2
CreatePointCloud & operator=(CreatePointCloud other)
MimmoSharedPointer is a custom implementation of shared pointer.
MimmoSharedPointer< MimmoObject > getGeometry()
void swap(CreatePointCloud &x) noexcept
void swap(BaseManipulation &x) noexcept
CreatePointCloud manages cloud point data in raw format to create a MimmoObject Point Cloud container...
#define M_COORDS
void setRawScalarField(dvector1D rawScalarField)