geohandlers_example_00003.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 "mimmo_geohandlers.hpp"
26 #include "mimmo_manipulators.hpp"
27 #if MIMMO_ENABLE_MPI
28 #include "mimmo_parallel.hpp"
29 #endif
30 
31 // =================================================================================== //
47 // =================================================================================== //
48 
49 void test00003() {
50 
51  /*
52  Read a sphere geometry. Convert mode is to save the just read geometry in
53  another file with name geohandlers_output_00003.0000.stl
54  */
56  mimmo0->setReadDir("geodata");
57  mimmo0->setReadFileType(FileType::STL);
58  mimmo0->setReadFilename("sphere2");
59  mimmo0->setWriteDir("./");
60  mimmo0->setWriteFileType(FileType::STL);
61  mimmo0->setWriteFilename("geohandlers_output_00003.0000");
62 
63  /*
64  Read a plane geometry. Convert mode is to save the just read geometry in
65  another file with name geohandlers_output_00003p1.0000.stl
66  */
68  mimmo1->setReadDir("geodata");
69  mimmo1->setReadFileType(FileType::STL);
70  mimmo1->setReadFilename("plane1");
71  mimmo1->setWriteDir("./");
72  mimmo1->setWriteFileType(FileType::STL);
73  mimmo1->setWriteFilename("geohandlers_output_00003p1.0000");
74 
75  /*
76  Read another plane geometry. Convert mode is to save the just read geometry in
77  another file with name geohandlers_output_00003p2.0000.stl
78  */
80  mimmo2->setReadDir("geodata");
81  mimmo2->setReadFileType(FileType::STL);
82  mimmo2->setReadFilename("plane2");
83  mimmo2->setWriteDir("./");
84  mimmo2->setWriteFileType(FileType::STL);
85  mimmo2->setWriteFilename("geohandlers_output_00003p2.0000");
86 
87  /*
88  Write the deformed sphere on file
89  */
91  mimmo3->setWriteDir(".");
92  mimmo3->setWriteFileType(FileType::STL);
93  mimmo3->setWriteFilename("geohandlers_output_00003.0001");
94 
95  /*
96  Write the first deformed sub-patch selection on file
97  */
99  mimmo4->setWriteDir(".");
100  mimmo4->setWriteFileType(FileType::STL);
101  mimmo4->setWriteFilename("geohandlers_output_00003.0002");
102 
103  /*
104  Write the second deformed sub-patch selection on file
105  */
107  mimmo5->setWriteDir(".");
108  mimmo5->setWriteFileType(FileType::STL);
109  mimmo5->setWriteFilename("geohandlers_output_00003.0003");
110 
111 #if MIMMO_ENABLE_MPI
112  /*
113  Distribute the sphere geometry among processes.
114  Plot Optional results during execution active for Partition block.
115  */
116  mimmo::Partition* partition0 = new mimmo::Partition();
117  partition0->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
118  partition0->setPlotInExecution(true);
119 
120  /*
121  Distribute the plane1 geometry among processes.
122  Plot Optional results during execution active for Partition block.
123  */
124  mimmo::Partition* partition1 = new mimmo::Partition();
125  partition1->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
126  partition1->setPlotInExecution(true);
127 
128  /*
129  Please note MPI version of this example will not distribute plane2 geometry
130  among processes. This is done on purpose, just to prove the code works
131  even if the plane2 geometry is retained only on a single rank (that is namely the master rank)
132  */
133 #endif
134 
135  /*
136  Create two sub-patches of the sphere using proximity selection with the two external
137  geometries plane1 and plane2. The sphere cells within a certain offset distance
138  (tolerance) from the chosen external geometry will be selected to form the subpatch.
139  */
141  mapSel1->setTolerance(1.0e-01);
142  mapSel1->setPlotInExecution(true);
143 
145  mapSel2->setTolerance(1.0e-01);
146  mapSel2->setPlotInExecution(true);
147 
148  /*
149  Creation of a two points with x coordinates -0.5 and 0.5 (y=z=0.0)
150  to be used as RBF nodes
151  */
152  dvecarr3E rbfNodes1(1, {{-0.5, 0.0, 0.0}});
153  dvecarr3E rbfNodes2(1, {{0.5, 0.0, 0.0}});
154 
155  /*
156  Creation of a two displacement list associated to RBF nodes
157  */
158  dvecarr3E displ1(1, {{-0.25, 0.0, 0.0}});
159  dvecarr3E displ2(1, {{0.25, 0.0, 0.0}});
160 
161  /*
162  Create two RBF manipulators, with nodes and displacements defined before.
163  Each manipulator will act on a specific subpatch selected before
164  */
166  mrbf1->setSupportRadiusLocal(0.4);
167  mrbf1->setPlotInExecution(true);
168  mrbf1->setNode(rbfNodes1);
169  mrbf1->setDisplacements(displ1);
170  mrbf1->setApply(false);
171 
173  mrbf2->setSupportRadiusLocal(0.4);
174  mrbf2->setPlotInExecution(true);
175  mrbf2->setNode(rbfNodes2);
176  mrbf2->setDisplacements(displ2);
177  mrbf2->setApply(false);
178 
179  //please note apply is set to false, because the two deformation fields onto
180  //the subpatches will be combined to form a single deformation field on the
181  //whole sphere
182 
183  /*
184  Recombine the two deformation field calculated on subpatches into a unique
185  field defined on the mother sphere mesh. The block will deal with possible
186  overlaps and resolve them with its default overlapMethod engine. See doxy documentation.
187  */
189  recon->setPlotInExecution(true);
190 
191  /*
192  Create an applier block.
193  * It applies the reconstructed deformation field onto the sphere.
194  */
195  mimmo::Apply* applier = new mimmo::Apply();
196 
197  /*
198  Extract the portion of the whole recostructed deformation field
199  referring to the first subpatch. Method of extraction is the ID association
200  between mother mesh and sub-patch vertices.
201  */
204  extr->setPlotInExecution(true);
205 
206  /*
207  Create an applier block.
208  It will deform the first subpatch with the result of the extr block
209  */
210  mimmo::Apply* applierextr = new mimmo::Apply();
211 
212  /*
213  Extract the portion of the whole recostructed deformation field
214  referring to the second subpatch. Method of extraction is the MAPPING that is
215  data extracted will be imported from the portion of sphere mesh near to the
216  second subpatch, within a prescribed proximity distance(tolerance).
217  */
220  extr2->setTolerance(1.0e-01);
221  extr2->setPlotInExecution(true);
222 
223  /*
224  Create an applier block.
225  It will deform the second subpatch with the result of the extr2 block
226  */
227  mimmo::Apply* applierextr2 = new mimmo::Apply();
228 
229  /*
230  Define block pin connections.
231  */
232 #if MIMMO_ENABLE_MPI
233  mimmo::pin::addPin(mimmo0, partition0, M_GEOM, M_GEOM);
234  mimmo::pin::addPin(partition0, mapSel1, M_GEOM, M_GEOM);
235  mimmo::pin::addPin(partition0, mapSel2, M_GEOM, M_GEOM);
236  mimmo::pin::addPin(partition0, applier, M_GEOM, M_GEOM);
237  mimmo::pin::addPin(mimmo1, partition1, M_GEOM, M_GEOM);
238  mimmo::pin::addPin(partition1, mapSel1, M_GEOM, M_GEOM2);
239 #else
240  mimmo::pin::addPin(mimmo0, mapSel1, M_GEOM, M_GEOM);
241  mimmo::pin::addPin(mimmo0, mapSel2, M_GEOM, M_GEOM);
242  mimmo::pin::addPin(mimmo0, applier, M_GEOM, M_GEOM);
243  mimmo::pin::addPin(mimmo1, mapSel1, M_GEOM, M_GEOM2);
244 #endif
245 
246  mimmo::pin::addPin(mimmo2, mapSel2, M_GEOM, M_GEOM2);
247 
248  mimmo::pin::addPin(mapSel1, mrbf1, M_GEOM, M_GEOM);
249  mimmo::pin::addPin(mapSel2, mrbf2, M_GEOM, M_GEOM);
250 
251  mimmo::pin::addPin(mimmo0, recon, M_GEOM, M_GEOM);
254 
255  mimmo::pin::addPin(recon, applier, M_VECTORFIELD, M_GDISPLS);
256  mimmo::pin::addPin(applier, mimmo3, M_GEOM, M_GEOM);
257 
258  mimmo::pin::addPin(mapSel1, extr, M_GEOM, M_GEOM);
260  mimmo::pin::addPin(mapSel1, applierextr, M_GEOM, M_GEOM);
261  mimmo::pin::addPin(extr, applierextr, M_VECTORFIELD, M_GDISPLS);
262  mimmo::pin::addPin(applierextr, mimmo4, M_GEOM, M_GEOM);
263 
264  mimmo::pin::addPin(mapSel2, extr2, M_GEOM, M_GEOM);
266  mimmo::pin::addPin(mapSel2, applierextr2, M_GEOM, M_GEOM);
267  mimmo::pin::addPin(extr2, applierextr2, M_VECTORFIELD, M_GDISPLS);
268  mimmo::pin::addPin(applierextr2, mimmo5, M_GEOM, M_GEOM);
269 
270  /*
271  Setup execution chain.
272  */
273  mimmo::Chain ch0;
274  ch0.addObject(mimmo0);
275  ch0.addObject(mimmo1);
276  ch0.addObject(mimmo2);
277 #if MIMMO_ENABLE_MPI
278  ch0.addObject(partition0);
279  ch0.addObject(partition1);
280 #endif
281  ch0.addObject(mapSel1);
282  ch0.addObject(mapSel2);
283  ch0.addObject(mrbf1);
284  ch0.addObject(mrbf2);
285  ch0.addObject(recon);
286  ch0.addObject(applier);
287  ch0.addObject(mimmo3);
288  ch0.addObject(extr);
289  ch0.addObject(applierextr);
290  ch0.addObject(mimmo4);
291  ch0.addObject(extr2);
292  ch0.addObject(applierextr2);
293  ch0.addObject(mimmo5);
294 
295  /*
296  Execute the chain.
297  Use debug flag true to to print out the execution steps.
298  */
299  ch0.exec(true);
300 
301  /*
302  Clean up & exit;
303  */
304  delete mimmo0;
305  delete mimmo1;
306 #if MIMMO_ENABLE_MPI
307  delete partition0;
308  delete partition1;
309 #endif
310  delete mimmo2;
311  delete mimmo3;
312  delete mimmo4;
313  delete mimmo5;
314  delete mapSel1;
315  delete mapSel2;
316  delete mrbf1;
317  delete mrbf2;
318  delete recon;
319  delete extr;
320  delete extr2;
321  delete applier;
322  delete applierextr;
323  delete applierextr2;
324 
325  return;
326 }
327 
328 // =================================================================================== //
329 
330 int main( int argc, char *argv[] ) {
331 
332  BITPIT_UNUSED(argc);
333  BITPIT_UNUSED(argv);
334 
335 #if MIMMO_ENABLE_MPI
336  MPI_Init(&argc, &argv);
337 #endif
338 
339  try{
340  test00003();
341  }
342  catch(std::exception & e){
343  std::cout<<"geohandlers_example_00003 exited with an error of type : "<<e.what()<<std::endl;
344  return 1;
345  }
346 
347 #if MIMMO_ENABLE_MPI
348  MPI_Finalize();
349 #endif
350 
351  return 0;
352 }
void exec(bool debug=false)
Definition: Chain.cpp:284
void setTolerance(double tol=1.e-8)
#define M_GDISPLS
Chain is the class used to manage the chain execution of multiple executable blocks (manipulation obj...
Definition: Chain.hpp:48
#define M_GEOM
void setNode(darray3E)
Definition: MRBF.cpp:329
Apply is the class that applies the deformation resulting from a manipulation object to the geometry.
Definition: Apply.hpp:89
void setDisplacements(dvecarr3E displ)
Definition: MRBF.cpp:514
std::vector< darray3E > dvecarr3E
void setWriteFileType(FileType type)
void setWriteDir(std::string dir)
#define M_GEOM2
Selection mapping external surfaces/volume/3D curves on a target mesh of the same topology.
void setSupportRadiusLocal(double suppR_)
Definition: MRBF.cpp:419
void setWriteFilename(std::string filename)
#define M_VECTORFIELD
void setTolerance(double tol)
void setReadFilename(std::string filename)
bool addPin(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR, bool forced)
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
Reconstruct a vector field from daughter mesh to mother mesh.
Radial Basis Function evaluation from clouds of control points.
Definition: MRBF.hpp:146
void setReadFileType(FileType type)
void setApply(bool flag=true)
void setReadDir(std::string dir)
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170
void setMode(ExtractMode mode)
ExtractVectorField is specialized derived class of ExtractField to extract a vector field of array<do...