manipulators_example_00001.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 <bitpit_common.hpp>
28 #if MIMMO_ENABLE_MPI
29 #include "mimmo_parallel.hpp"
30 #endif
31 
32 // =================================================================================== //
48 void test00001() {
49 
50  /*
51  Read a prism from STL file. Convert mode is to save the just read geometry in
52  another file with name manipulators_output_00001.stl
53  */
55  mimmo0->setReadDir("geodata");
56  mimmo0->setReadFileType(FileType::STL);
57  mimmo0->setReadFilename("prism");
58  mimmo0->setWriteDir(".");
59  mimmo0->setWriteFileType(FileType::STL);
60  mimmo0->setWriteFilename("manipulators_output_00001.0000");
61 
62 
63  /*
64  It will write to file the first partial deformation due to translation manipulation
65  */
67  mimmo1->setWriteDir(".");
68  mimmo1->setWriteFileType(FileType::STL);
69  mimmo1->setWriteFilename("manipulators_output_00001.0001");
70 
71  /*
72  It will write to file the second partial deformation due to both translation and scaling
73  */
75  mimmo2->setWriteDir(".");
76  mimmo2->setWriteFileType(FileType::STL);
77  mimmo2->setWriteFilename("manipulators_output_00001.0002");
78 
79  /*
80  It will write to file the third partial deformation due to translation/scaling and twisting
81  */
83  mimmo3->setWriteDir(".");
84  mimmo3->setWriteFileType(FileType::STL);
85  mimmo3->setWriteFilename("manipulators_output_00001.0003");
86 
87  /*
88  It will write to file the fourth deformation due to translation/scaling/twisting and bending
89  */
91  mimmo4->setWriteDir(".");
92  mimmo4->setWriteFileType(FileType::STL);
93  mimmo4->setWriteFilename("manipulators_output_00001.0004");
94 
95  /*
96  It will write to file the final deformation due to translation/scaling/twisting/bending and rotation
97  */
99  mimmo5->setWriteDir(".");
100  mimmo5->setWriteFileType(FileType::STL);
101  mimmo5->setWriteFilename("manipulators_output_00001.0005");
102 
103 #if MIMMO_ENABLE_MPI
104  /*
105  Distribute the target mesh among the processes.
106  */
107  mimmo::Partition* partition= new mimmo::Partition();
108  partition->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
109 #endif
110 
111  /*
112  Creation of translation block.
113  Translation performed in z direction by -1.0 unit length.
114  */
116  translation->setDirection(darray3E{0.0, 0.0, -1.0});
117  translation->setTranslation(1.0);
118 
119  /*
120  Apply the translation deformation to the mesh.
121  */
122  mimmo::Apply* applierTranslation = new mimmo::Apply();
123 
124 
125  /*
126  Creation of scaling block.
127  Scaling performed in y & z direction by 0.5 factor.
128  */
130  scaling->setScaling(darray3E{1.0, 0.5, 0.5});
131 
132  /*
133  Apply the scaling deformation to the mesh.
134  */
135  mimmo::Apply* applierScaling = new mimmo::Apply();
136 
137  /*
138  Creation of twisting block.
139  Twisting performed in x direction by a maximum angle at a distance 1.0
140  from the origin equal to pi/3 radiants.
141  */
143  twist->setDirection(darray3E{1.0, 0.0, 0.0});
144  twist->setTwist((BITPIT_PI/3));
145  twist->setMaxDistance(1.0);
146 
147  /*
148  Apply the twisting deformation to the mesh.
149  */
150  mimmo::Apply* applierTwist = new mimmo::Apply();
151 
152  /*
153  Creation of bending block.
154  Bending performed in x direction by a maximum angle at a distance 1.0
155  from the origin equal to pi/3 radiants.
156  */
158  umatrix33E degree = {0,0,0, 0,0,0, 2,0,0};
159  bend->setDegree(degree);
160  dmat33Evec coeffs;
161  coeffs[2][0].resize(3);
162  coeffs[2][0][0] = 0;
163  coeffs[2][0][1] = 0;
164  coeffs[2][0][2] = 0.5;
165  bend->setCoeffs(&coeffs);
166 
167  /*
168  * Bend directly applied during execution, no external applier for it!
169  */
170  bend->setApply();
171 
172  /*
173  Creation of rotation block.
174  Rotation performed around an axis through the origin and
175  with direction (0.25,0.25,0.75) by pi/4 radiants.
176  */
178  rotation->setDirection(darray3E{0.25,0.25,0.75});
179  rotation->setRotation((BITPIT_PI/4));
180 
181  /*
182  Apply the rotation deformation to the mesh.
183  */
184  mimmo::Apply* applierRotation = new mimmo::Apply();
185 
186  /* Setup pin connections.
187  */
188 #if MIMMO_ENABLE_MPI
189  mimmo::pin::addPin(mimmo0, partition, M_GEOM, M_GEOM);
190  mimmo::pin::addPin(partition, translation, M_GEOM, M_GEOM);
191 #else
192  mimmo::pin::addPin(mimmo0, translation, M_GEOM, M_GEOM);
193 #endif
194  mimmo::pin::addPin(mimmo0, applierTranslation, M_GEOM, M_GEOM);
195  mimmo::pin::addPin(translation, applierTranslation, M_GDISPLS, M_GDISPLS);
196  mimmo::pin::addPin(applierTranslation, mimmo1, M_GEOM, M_GEOM);
197 
198  mimmo::pin::addPin(applierTranslation, scaling, M_GEOM, M_GEOM);
199  mimmo::pin::addPin(applierTranslation, applierScaling, M_GEOM, M_GEOM);
200  mimmo::pin::addPin(scaling, applierScaling, M_GDISPLS, M_GDISPLS);
201  mimmo::pin::addPin(applierScaling, mimmo2, M_GEOM, M_GEOM);
202 
203  mimmo::pin::addPin(applierScaling, twist, M_GEOM, M_GEOM);
204  mimmo::pin::addPin(applierScaling, applierTwist, M_GEOM, M_GEOM);
205  mimmo::pin::addPin(twist, applierTwist, M_GDISPLS, M_GDISPLS);
206  mimmo::pin::addPin(applierTwist, mimmo3, M_GEOM, M_GEOM);
207 
208  mimmo::pin::addPin(applierTwist, bend, M_GEOM, M_GEOM);
209  mimmo::pin::addPin(bend, mimmo4, M_GEOM, M_GEOM);
210 
211  mimmo::pin::addPin(bend, rotation, M_GEOM, M_GEOM);
212  mimmo::pin::addPin(bend, applierRotation, M_GEOM, M_GEOM);
213  mimmo::pin::addPin(rotation, applierRotation, M_GDISPLS, M_GDISPLS);
214  mimmo::pin::addPin(applierRotation, mimmo5, M_GEOM, M_GEOM);
215 
216  /*
217  Setup execution chain.
218  */
219  mimmo::Chain ch0;
220 #if MIMMO_ENABLE_MPI
221  ch0.addObject(partition);
222 #endif
223  ch0.addObject(mimmo0);
224  ch0.addObject(translation);
225  ch0.addObject(applierTranslation);
226  ch0.addObject(mimmo1);
227  ch0.addObject(scaling);
228  ch0.addObject(applierScaling);
229  ch0.addObject(mimmo2);
230  ch0.addObject(twist);
231  ch0.addObject(applierTwist);
232  ch0.addObject(mimmo3);
233  ch0.addObject(bend);
234  ch0.addObject(mimmo4);
235  ch0.addObject(rotation);
236  ch0.addObject(applierRotation);
237  ch0.addObject(mimmo5);
238 
239  /*
240  Execute the chain.
241  Use debug flag false to avoid to print out the execution steps on console.
242  */
243  ch0.exec(true);
244 
245  /*
246  Clean up & exit;
247  */
248 #if MIMMO_ENABLE_MPI
249  delete partition;
250 #endif
251  delete mimmo0;
252  delete translation;
253  delete applierTranslation;
254  delete mimmo1;
255  delete scaling;
256  delete applierScaling;
257  delete mimmo2;
258  delete twist;
259  delete applierTwist;
260  delete mimmo3;
261  delete bend;
262  delete mimmo4;
263  delete rotation;
264  delete applierRotation;
265  delete mimmo5;
266 
267  return;
268 }
269 
270 int main(int argc, char *argv[]) {
271 
272  BITPIT_UNUSED(argc);
273  BITPIT_UNUSED(argv);
274 
275 #if MIMMO_ENABLE_MPI==1
276  MPI_Init(&argc, &argv);
277 
278  {
279 #endif
280  try{
282  test00001() ;
283  }
284 
285  catch(std::exception & e){
286  std::cout<<"manipulators_example_00001 exited with an error of type : "<<e.what()<<std::endl;
287  return 1;
288  }
289 
290 #if MIMMO_ENABLE_MPI==1
291  }
292 
293  MPI_Finalize();
294 #endif
295 
296  return 0;
297 }
void exec(bool debug=false)
Definition: Chain.cpp:284
#define M_GDISPLS
void setMaxDistance(double distance)
ScaleGeometry is the class that applies a scaling to a given geometry patch in respect to the mean po...
void setDirection(darray3E direction)
Chain is the class used to manage the chain execution of multiple executable blocks (manipulation obj...
Definition: Chain.hpp:48
std::array< darr3Evec, 3 > dmat33Evec
#define M_GEOM
RotationGeometry is the class that applies a rotation to a given geometry patch.
Apply is the class that applies the deformation resulting from a manipulation object to the geometry.
Definition: Apply.hpp:89
void setDirection(darray3E direction)
void setWriteFileType(FileType type)
void setDegree(umatrix33E degree)
void setWriteDir(std::string dir)
BendGeometry applies custom bending deformations along axis-directions of a target geometry.
void setWriteFilename(std::string filename)
void setReadFilename(std::string filename)
void setRotation(double alpha)
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...
std::array< uarray3E, 3 > umatrix33E
void setTwist(double alpha)
std::array< double, 3 > darray3E
TranslationGeometry is the class that applies a translation to a given geometry patch.
void setCoeffs(dmat33Evec *coeffs)
void setReadFileType(FileType type)
TwistGeometry is the class that applies a twist to a given geometry patch.
void setApply(bool flag=true)
void setReadDir(std::string dir)
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170
void setDirection(darray3E direction)
void setScaling(darray3E scaling)