ProjPatchOnSurface.cpp
1 /*----------------------------------------------------------------------------*\
2  *
3  * mimmo
4  *
5  * Optimad Engineering S.r.l. ("COMPANY") CONFIDENTIAL
6  * Copyright (c) 2015-2021 Optimad Engineering S.r.l., All Rights Reserved.
7  *
8  * --------------------------------------------------------------------------
9  *
10  * NOTICE: All information contained herein is, and remains the property
11  * of COMPANY. The intellectual and technical concepts contained herein are
12  * proprietary to COMPANY and may be covered by Italian and Foreign Patents,
13  * patents in process, and are protected by trade secret or copyright law.
14  * Dissemination of this information or reproduction of this material is
15  * strictly forbidden unless prior written permission is obtained from
16  * COMPANY. Access to the source code contained herein is hereby forbidden
17  * to anyone except current COMPANY employees, managers or contractors who
18  * have executed Confidentiality and Non-disclosure agreements explicitly
19  * covering such access.
20  *
21  * The copyright notice above does not evidence any actual or intended
22  * publication or disclosure of this source code, which includes information
23  * that is confidential and/or proprietary, and is a trade secret, of
24  * COMPANY. ANY REPRODUCTION, MODIFICATION, DISTRIBUTION, PUBLIC PERFORMANCE,
25  * OR PUBLIC DISPLAY OF OR THROUGH USE OF THIS SOURCE CODE WITHOUT THE
26  * EXPRESS WRITTEN CONSENT OF COMPANY IS STRICTLY PROHIBITED, AND IN
27  * VIOLATION OF APPLICABLE LAWS AND INTERNATIONAL TREATIES. THE RECEIPT OR
28  * POSSESSION OF THIS SOURCE CODE AND/OR RELATED INFORMATION DOES NOT CONVEY
29  * OR IMPLY ANY RIGHTS TO REPRODUCE, DISCLOSE OR DISTRIBUTE ITS CONTENTS, OR
30  * TO MANUFACTURE, USE, OR SELL ANYTHING THAT IT MAY DESCRIBE, IN WHOLE OR
31  * IN PART.
32  *
33 \*----------------------------------------------------------------------------*/
34 
35 #include "ProjPatchOnSurface.hpp"
36 #include <SkdTreeUtils.hpp>
37 
38 namespace mimmo{
39 
44  m_name = "mimmo.ProjPatchOnSurface";
45  m_topo = 2; //2D- surface tessellation
46  m_cobj = nullptr;
47  m_workingOnTarget = false;
48 };
49 
54 ProjPatchOnSurface::ProjPatchOnSurface(const bitpit::Config::Section & rootXML){
55 
56  m_name = "mimmo.ProjPatchOnSurface";
57  m_topo = 2; //2D- surface tessellation
58  m_cobj = nullptr;
59  m_workingOnTarget = false;
60 
61  std::string fallback_name = "ClassNONE";
62  std::string input = rootXML.get("ClassName", fallback_name);
63  input = bitpit::utils::string::trim(input);
64  if(input == "mimmo.ProjPatchOnSurface"){
65  absorbSectionXML(rootXML);
66  }else{
68  };
69 }
70 
75  clear();
76 };
77 
81  m_cobj = other.m_cobj;
83 
84 };
85 
90  swap(other);
91  return *this;
92 };
93 
99 {
100  std::swap(m_cobj, x.m_cobj);
101  std::swap(m_workingOnTarget, x.m_workingOnTarget);
103 }
104 
108 void
111  m_cobj = nullptr;
112  m_workingOnTarget = false;
113 }
114 
121 void
123 
124  if(geo == nullptr) return;
125  int type = geo->getType();
126  if(type == 2 ) return;
127  m_cobj = geo;
128  m_topo = 2;
129  if(type == 3) m_topo = 0;
130  if(type == 4) m_topo = 1;
131 
132 }
133 
139 bool
141  return m_workingOnTarget;
142 }
143 
149 void
151  m_workingOnTarget = flag;
152 }
153 
154 
160 void ProjPatchOnSurface::absorbSectionXML(const bitpit::Config::Section & slotXML, std::string name){
161 
162  BITPIT_UNUSED(name);
163 
164  std::string input;
165 
166  BaseManipulation::absorbSectionXML(slotXML, name);
167 
168  if(slotXML.hasOption("SkdTree")){
169  input = slotXML.get("SkdTree");
170  bool value = false;
171  if(!input.empty()){
172  std::stringstream ss(bitpit::utils::string::trim(input));
173  ss >> value;
174  }
175  setBuildSkdTree(value);
176  };
177 
178  if(slotXML.hasOption("KdTree")){
179  input = slotXML.get("KdTree");
180  bool value = false;
181  if(!input.empty()){
182  std::stringstream ss(bitpit::utils::string::trim(input));
183  ss >> value;
184  }
185  setBuildKdTree(value);
186  };
187 
188  if(slotXML.hasOption("WorkingOnTarget")){
189  input = slotXML.get("WorkingOnTarget");
190  bool value = false;
191  if(!input.empty()){
192  std::stringstream ss(bitpit::utils::string::trim(input));
193  ss >> value;
194  }
195  setWorkingOnTarget(value);
196  };
197 
198 };
199 
205 void ProjPatchOnSurface::flushSectionXML(bitpit::Config::Section & slotXML, std::string name){
206 
207  BITPIT_UNUSED(name);
208 
209  BaseManipulation::flushSectionXML(slotXML, name);
210 
211  if(m_buildSkdTree){
212  slotXML.set("SkdTree", std::to_string(m_buildSkdTree));
213  }
214 
215  if(m_buildKdTree){
216  slotXML.set("KdTree", std::to_string(m_buildKdTree));
217  }
218  slotXML.set("WorkingOnTarget", std::to_string(m_workingOnTarget));
219 
220 };
221 
222 
226 void
229  bool built = m_arePortsBuilt;
230 
231  built = (built && createPortIn<MimmoSharedPointer<MimmoObject>, ProjPatchOnSurface>(this, &mimmo::ProjPatchOnSurface::setPatch, M_GEOM2, true));
232  m_arePortsBuilt = built;
233 }
234 
235 
239 void
241  if(m_workingOnTarget){
242  m_patch = m_cobj;
243  }else{
244  m_patch = m_cobj->clone();
245  }
246  //...and projecting them onto target surface
247  getGeometry()->buildSkdTree();
248 
249  dvecarr3E points;
250  livector1D originalIds;
251  points.reserve(m_patch->getNVertices());
252  originalIds.reserve(points.size());
253  for(bitpit::Vertex & vert : m_patch->getVertices()){
254  points.push_back(vert.getCoords());
255  originalIds.push_back(vert.getId());
256  }
257 
258  std::size_t npoints = points.size();
259  dvecarr3E projs(npoints);
260  livector1D cell_ids(npoints);
261 #if MIMMO_ENABLE_MPI
262  ivector1D ranks(npoints);
263  double radius = std::numeric_limits<double>::max();
264  skdTreeUtils::projectPointGlobal(npoints, points.data(), getGeometry()->getSkdTree(), projs.data(), cell_ids.data(), ranks.data(), radius, false);
265 #else
266  skdTreeUtils::projectPoint(npoints, points.data(), getGeometry()->getSkdTree(), projs.data(), cell_ids.data());
267 #endif
268 
269  std::size_t counter = 0;
270  for(long id: originalIds){
271  m_patch->modifyVertex(projs[counter], id);
272  counter++;
273  }
274 
275  m_patch->cleanPatchInfo();
276 #if MIMMO_ENABLE_MPI
277  m_patch->resetPointGhostExchangeInfo();
278 #endif
279  m_patch->update();
280 
281 };
282 
283 
284 }
MimmoSharedPointer< MimmoObject > m_patch
std::vector< darray3E > dvecarr3E
std::vector< long > livector1D
#define M_GEOM2
void warningXML(bitpit::Logger *log, std::string name)
void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
std::vector< int > ivector1D
void setPatch(MimmoSharedPointer< MimmoObject > geo)
virtual void absorbSectionXML(const bitpit::Config::Section &slotXML, std::string name="")
virtual void flushSectionXML(bitpit::Config::Section &slotXML, std::string name="")
Class for projecting 1D/2D primitives on a target 3D surface mesh.
void swap(ProjPrimitivesOnSurfaces &x) noexcept
Executable block class capable of projecting a surface patch, 3DCurve or PointCloud on a 3D surface,...
MimmoSharedPointer< MimmoObject > m_cobj
darray3E projectPoint(const std::array< double, 3 > *point, const bitpit::PatchSkdTree *skdtree, double r)
MimmoSharedPointer is a custom implementation of shared pointer.
MimmoSharedPointer< MimmoObject > getGeometry()
void swap(ProjPatchOnSurface &x) noexcept
ProjPatchOnSurface & operator=(ProjPatchOnSurface other)