manipulators_example_00002.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 #if MIMMO_ENABLE_MPI
28 #include "mimmo_parallel.hpp"
29 #endif
30 
31 // =================================================================================== //
45 void test00002() {
46 
47  /*
48  Read a sphere from STL file. Convert mode is to save the just read geometry in
49  another file with name manipulators_output_00002.0000.stl
50  */
52  mimmo0->setReadDir("geodata");
53  mimmo0->setReadFileType(FileType::STL);
54  mimmo0->setReadFilename("sphere2");
55  mimmo0->setBuildSkdTree(true);
56 
57  mimmo0->setWriteDir("./");
58  mimmo0->setWriteFileType(FileType::STL);
59  mimmo0->setWriteFilename("manipulators_output_00002.0000");
60 
61  /*
62  Write final deformed mesh on file
63  */
65  mimmo1->setWriteDir(".");
66  mimmo1->setWriteFileType(FileType::STL);
67  mimmo1->setWriteFilename("manipulators_output_00002.0001");
68 
69 #if MIMMO_ENABLE_MPI
70  /*
71  Distribute target mesh among processes.
72  */
73  mimmo::Partition* partition= new mimmo::Partition();
74  partition->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
75 #endif
76 
77  /*
78  Create a FFDLattice manipulator, shaped as a box.
79  Span and origin of the box are required.
80  Dimensions and nurbs degrees for each spatial directions must be provided.
81  Plot Optional results during execution active for FFD block.
82  */
83  mimmo::FFDLattice* lattice = new mimmo::FFDLattice();
84  darray3E origin = {0.0, 0.0, 0.0};
85  darray3E span;
86  span[0]= 1.2;
87  span[1]= 1.2;
88  span[2]= 1.2;
89 
90  /*
91  Set number of nodes of the mesh (dim) and degree of nurbs functions (deg).
92  */
93  iarray3E dim, deg;
94  dim[0] = 20;
95  dim[1] = 20;
96  dim[2] = 20;
97  deg[0] = 2;
98  deg[1] = 2;
99  deg[2] = 2;
100 
101  lattice->setLattice(origin, span, mimmo::ShapeType::CUBE, dim, deg);
102 
103  /*
104  Reading displacements associated ot the lattice's nodes from external
105  plain file.
106  */
108  input->setReadFromFile(true);
109  input->setReadDir("input");
110  input->setFilename("manipulators_input_00002.txt");
111 
112  /*
113  It applies the deformation displacements to the original input geometry.
114  */
115  mimmo::Apply* applier = new mimmo::Apply();
116 
117  /*
118  Setup pin connections.
119  */
120 #if MIMMO_ENABLE_MPI
121  mimmo::pin::addPin(mimmo0, partition, M_GEOM, M_GEOM);
122  mimmo::pin::addPin(partition, lattice, M_GEOM, M_GEOM);
123 #else
124  mimmo::pin::addPin(mimmo0, lattice, M_GEOM, M_GEOM);
125 #endif
126  mimmo::pin::addPin(input, lattice, M_DISPLS, M_DISPLS);
127  mimmo::pin::addPin(lattice, applier, M_GDISPLS, M_GDISPLS);
128  mimmo::pin::addPin(mimmo0, applier, M_GEOM, M_GEOM);
129  mimmo::pin::addPin(applier, mimmo1, M_GEOM, M_GEOM);
130 
131  /*
132  Setup execution chain.
133  */
134  mimmo::Chain ch0;
135  ch0.addObject(mimmo0);
136 #if MIMMO_ENABLE_MPI
137  ch0.addObject(partition);
138 #endif
139  ch0.addObject(input);
140  ch0.addObject(lattice);
141  ch0.addObject(applier);
142  ch0.addObject(mimmo1);
143 
144  //force the chain to plot all the optional results of its children...
145  ch0.setPlotDebugResults(true);
146  //...in the path specified by the User.
147  ch0.setOutputDebugResults(".");
148 
149  /*
150  Execute the chain.
151  * Use debug flag true to full print out the execution steps.
152  */
153  ch0.exec(true);
154 
155  /* Clean up & exit;
156  */
157 #if MIMMO_ENABLE_MPI
158  delete partition;
159 #endif
160  delete lattice;
161  delete applier;
162  delete input;
163  delete mimmo0;
164  delete mimmo1;
165 
166 }
167 
168 int main( int argc, char *argv[] ) {
169 
170  BITPIT_UNUSED(argc);
171  BITPIT_UNUSED(argv);
172 
173 #if MIMMO_ENABLE_MPI
174  MPI_Init(&argc, &argv);
175 #endif
176 
177  try{
178  test00002() ;
179  }
180  catch(std::exception & e){
181  std::cout<<"manipulators_example_00002 exited with an error of type : "<<e.what()<<std::endl;
182  return 1;
183  }
184 #if MIMMO_ENABLE_MPI
185  MPI_Finalize();
186 #endif
187 
188  return 0;
189 }
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