manipulators_example_00008.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_manipulators.hpp"
26 #include "mimmo_iogeneric.hpp"
27 #include "mimmo_utils.hpp"
28 #include <random>
29 #if MIMMO_ENABLE_MPI
30  #include "mimmo_parallel.hpp"
31 #endif
32 
33 // =================================================================================== //
50 void test00008() {
51 
52  /*
53  Read a pipe sample from vtu mesh. Convert mode is to save the just read geometry in
54  another file with name manipulators_output_00008.0000.stl
55  */
57  mimmo0->setReadDir("geodata");
58  mimmo0->setReadFileType(FileType::SURFVTU);
59  mimmo0->setReadFilename("pipeSample");
60  mimmo0->setWriteDir(".");
61  mimmo0->setWriteFileType(FileType::SURFVTU);
62  mimmo0->setWriteFilename("manipulators_output_00008.0000");
63 
64  /* write the deformed mesh to file */
66  mimmo1->setWriteDir(".");
67  mimmo1->setWriteFileType(FileType::SURFVTU);
68  mimmo1->setWriteFilename("manipulators_output_00008.0001");
69 
70 
71 #if MIMMO_ENABLE_MPI
72  /*
73  Distribute mesh among processes
74  */
75  mimmo::Partition* partition= new mimmo::Partition();
76  partition->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
77  partition->setPlotInExecution(true);
78 #endif
79 
80  /*
81  Seed 10 3D points on the surface. Thi will be used as RBF nodes to
82  create the manipulator
83  */
85  seeder->setNPoints(10);
87  seeder->setMassCenterAsSeed(true);
88  seeder->setRandomFixed(true);
89  seeder->setRandomSignature(12457834);
90  seeder->setPlotInExecution(true);
91 
92  /*
93  Read d.o.f. for RBF Cloud from plain txt file.
94  For each node is associated a scalar DOF, in order to obtain a "scalar"
95  field of displacements from MRBF
96  */
97  mimmo::GenericInput* inputDof = new mimmo::GenericInput(true, false);
98  inputDof->setReadDir("input");
99  inputDof->setFilename("manipulators_input_00008.txt");
100 
101  /*
102  MRBF manipulator. Setting function and support radius.
103  Plot Optional results during execution active for MRBF block.
104  */
106  mrbf->setFunction(bitpit::RBFBasisFunction::C1C2);
107  mrbf->setSupportRadiusReal(0.6);
108  mrbf->setPlotInExecution(true);
109 
110  /*
111  It applies the MRBF output scalar field onto the original input geometry, using
112  the local vertex normals of the original geometry.
113  */
114  mimmo::Apply* applier = new mimmo::Apply();
115 
116  /*
117  Setup pin connections.
118  */
119 #if MIMMO_ENABLE_MPI
120  mimmo::pin::addPin(mimmo0, partition, M_GEOM, M_GEOM);
121  mimmo::pin::addPin(partition, seeder, M_GEOM, M_GEOM);
122  mimmo::pin::addPin(partition, mrbf, M_GEOM, M_GEOM);
123  mimmo::pin::addPin(partition, applier, M_GEOM, M_GEOM);
124 #else
125  mimmo::pin::addPin(mimmo0, seeder, M_GEOM, M_GEOM);
126  mimmo::pin::addPin(mimmo0, mrbf, M_GEOM, M_GEOM);
127  mimmo::pin::addPin(mimmo0, applier, M_GEOM, M_GEOM);
128 #endif
129 
130  mimmo::pin::addPin(inputDof, mrbf, M_DATAFIELD, M_DATAFIELD);
131  mimmo::pin::addPin(seeder, mrbf, M_COORDS, M_COORDS);
133  mimmo::pin::addPin(applier, mimmo1, M_GEOM, M_GEOM);
134 
135  /*
136  Setup execution chain.
137  */
138  mimmo::Chain ch0;
139  ch0.addObject(inputDof);
140 #if MIMMO_ENABLE_MPI
141  ch0.addObject(partition);
142 #endif
143  ch0.addObject(mimmo0);
144  ch0.addObject(seeder);
145  ch0.addObject(applier);
146  ch0.addObject(mrbf);
147  ch0.addObject(mimmo1);
148 
149  /*
150  Execute the chain.
151  Use debug flag true to print out the execution steps.
152  */
153  ch0.exec(true);
154 
155  /*
156  Clean up & exit;
157  */
158  delete mrbf;
159  delete seeder;
160  delete applier;
161  delete inputDof;
162  delete mimmo0;
163  delete mimmo1;
164 #if MIMMO_ENABLE_MPI
165  delete partition;
166 #endif
167 
168  return;
169 }
170 
171 int main( int argc, char *argv[] ) {
172 
173  BITPIT_UNUSED(argc);
174  BITPIT_UNUSED(argv);
175 
176 #if MIMMO_ENABLE_MPI
177  MPI_Init(&argc, &argv);
178 #endif
179  try{
181  test00008() ;
182  }
183  catch(std::exception & e){
184  std::cout<<"manipulators_example_00008 exited with an error of type : "<<e.what()<<std::endl;
185  return 1;
186  }
187 #if MIMMO_ENABLE_MPI
188  MPI_Finalize();
189 #endif
190 
191  return 0;
192 }
void setReadDir(std::string dir)
void exec(bool debug=false)
Definition: Chain.cpp:284
Chain is the class used to manage the chain execution of multiple executable blocks (manipulation obj...
Definition: Chain.hpp:48
#define M_DATAFIELD
#define M_GEOM
Apply is the class that applies the deformation resulting from a manipulation object to the geometry.
Definition: Apply.hpp:89
void setSupportRadiusReal(double suppR_)
Definition: MRBF.cpp:436
void setWriteFileType(FileType type)
void setWriteDir(std::string dir)
void setRandomSignature(uint32_t signature)
void setWriteFilename(std::string filename)
GenericInput is the class that set the initialization of a generic input data.
void setReadFilename(std::string filename)
bool addPin(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR, bool forced)
Distribute a raw list of points on a target 3D surface.
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
void setFilename(std::string filename)
#define M_SCALARFIELD
Radial Basis Function evaluation from clouds of control points.
Definition: MRBF.hpp:146
void setReadFileType(FileType type)
void setReadDir(std::string dir)
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170
#define M_COORDS
void setFunction(const MRBFBasisFunction &funct, bool isCompact=false)
Definition: MRBF.cpp:594