manipulators_example_00005.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 
28 // =================================================================================== //
42 void test00005() {
43 
44  /*
45  Read a sphere as point cloud from VTU file. Convert mode is to save the just read geometry in
46  another file with name manipulators_output_00005.0000.stl
47  */
49  mimmo0->setReadDir("geodata");
50  mimmo0->setReadFileType(FileType::PCVTU);
51  mimmo0->setReadFilename("spherepc_binary");
52  mimmo0->setBuildSkdTree(true);
53  mimmo0->setWriteDir("./");
54  mimmo0->setWriteFileType(FileType::PCVTU);
55  mimmo0->setWriteFilename("manipulators_output_00005.0000");
56 
57  /*
58  write the deformed geometry to file
59  */
61  mimmo1->setWriteDir(".");
62  mimmo1->setWriteFileType(FileType::PCVTU);
63  mimmo1->setWriteFilename("manipulators_output_00005.0001");
64 
65  /*
66  Instantiation of a FFDobject with the default shape as a box
67  Set span, origin, lattice number of nodes and nurbs degrees.
68  Plot Optional results during execution active for FFD block.
69  */
70  mimmo::FFDLattice* lattice = new mimmo::FFDLattice();
71  darray3E origin = {0.0, 0.0, 0.0};
72  darray3E span;
73  span[0]= 1.2;
74  span[1]= 1.2;
75  span[2]= 1.2;
76 
77  /*
78  Set number of nodes of the mesh (dim) and degree of nurbs functions (deg).
79  */
80  iarray3E dim, deg;
81  dim[0] = 20;
82  dim[1] = 20;
83  dim[2] = 20;
84  deg[0] = 2;
85  deg[1] = 2;
86  deg[2] = 2;
87 
88  lattice->setLattice(origin, span, mimmo::ShapeType::CUBE, dim, deg);
89 
90  /*
91  Creation of Generic input block to read the
92  * displacements of the control nodes of the lattice from file.
93  */
95  input->setReadFromFile(true);
96  input->setReadDir("input");
97  input->setFilename("manipulators_input_00005.txt");
98 
99  /*
100  Create applier block.
101  It applies the deformation displacements to the original input geometry.
102  */
103  mimmo::Apply* applier = new mimmo::Apply();
104 
105  /*
106  Setup pin connections.
107  */
108  std::cout << " --- create pin ---" << std::endl;
109  std::cout << " " << std::endl;
110  std::cout << " add pin info : " << std::boolalpha << mimmo::pin::addPin(mimmo0, lattice, M_GEOM, M_GEOM) << std::endl;
111  std::cout << " add pin info : " << std::boolalpha << mimmo::pin::addPin(input, lattice, M_DISPLS, M_DISPLS) << std::endl;
112  std::cout << " add pin info : " << std::boolalpha << mimmo::pin::addPin(lattice, applier, M_GDISPLS, M_GDISPLS) << std::endl;
113  std::cout << " add pin info : " << std::boolalpha << mimmo::pin::addPin(mimmo0, applier, M_GEOM, M_GEOM) << std::endl;
114  std::cout << " add pin info : " << std::boolalpha << mimmo::pin::addPin(applier, mimmo1, M_GEOM, M_GEOM) << std::endl;
115  std::cout << " " << std::endl;
116 
117  /*
118  Setup execution chain.
119  */
120  mimmo::Chain ch0;
121  ch0.addObject(mimmo0);
122  ch0.addObject(input);
123  ch0.addObject(lattice);
124  ch0.addObject(applier);
125  ch0.addObject(mimmo1);
126 
127  //force the chain to plot all the optional results of its children...
128  ch0.setPlotDebugResults(true);
129  //...in the path specified by the User.
130  ch0.setOutputDebugResults(".");
131 
132  /*
133  Execute the chain.
134  * Use debug flag true to full print out the execution steps.
135  */
136  std::cout << " " << std::endl;
137  std::cout << " --- execution start ---" << std::endl;
138  ch0.exec(true);
139  std::cout << " --- execution done --- " << std::endl;
140  std::cout << " " << std::endl;
141 
142  /*
143  Clean up & exit;
144  */
145  delete lattice;
146  delete applier;
147  delete input;
148  delete mimmo0;
149  delete mimmo1;
150 
151 }
152 
153 int main( int argc, char *argv[] ) {
154 
155  BITPIT_UNUSED(argc);
156  BITPIT_UNUSED(argv);
157 
158 #if MIMMO_ENABLE_MPI
159  MPI_Init(&argc, &argv);
160 #endif
161 
162  try{
163  test00005() ;
164  }
165  catch(std::exception & e){
166  std::cout<<"manipulators_example_00005 exited with an error of type : "<<e.what()<<std::endl;
167  return 1;
168  }
169 #if MIMMO_ENABLE_MPI
170  MPI_Finalize();
171 #endif
172 
173  return 0;
174 }
void setReadDir(std::string dir)
void exec(bool debug=false)
Definition: Chain.cpp:284
#define M_GDISPLS
std::array< int, 3 > iarray3E
Chain is the class used to manage the chain execution of multiple executable blocks (manipulation obj...
Definition: Chain.hpp:48
#define M_DISPLS
#define M_GEOM
Apply is the class that applies the deformation resulting from a manipulation object to the geometry.
Definition: Apply.hpp:89
void setWriteFileType(FileType type)
void setBuildSkdTree(bool build)
void setWriteDir(std::string dir)
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)
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
void setOutputDebugResults(std::string path)
Definition: Chain.cpp:256
void setPlotDebugResults(bool active)
Definition: Chain.cpp:248
void setReadFromFile(bool readFromFile)
void setFilename(std::string filename)
void setLattice(darray3E &origin, darray3E &span, ShapeType, iarray3E &dimensions, iarray3E &degrees)
Definition: FFDLattice.cpp:316
std::array< double, 3 > darray3E
void setReadFileType(FileType type)
Free Form Deformation of a 3D surface and point clouds, with structured lattice.
Definition: FFDLattice.hpp:133
void setReadDir(std::string dir)
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170