manipulators_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_manipulators.hpp"
26 #include "mimmo_iogeneric.hpp"
27 #include <bitpit_common.hpp>
28 
29 // =================================================================================== //
30 
44 void test00003() {
45 
46  /*
47  Read a pipe from STL file. Convert mode is to save the just read geometry in
48  another file with name manipulators_output_00003.0000.stl
49  */
51  mimmo0->setReadDir("geodata");
52  mimmo0->setReadFileType(FileType::STL);
53  mimmo0->setReadFilename("catpipe");
54  mimmo0->setWriteDir(".");
55  mimmo0->setWriteFileType(FileType::STL);
56  mimmo0->setWriteFilename("manipulators_output_00003.0000");
57 
58  /*
59  write the deformed geometry to file
60  */
62  mimmo1->setWriteDir(".");
63  mimmo1->setWriteFileType(FileType::STL);
64  mimmo1->setWriteFilename("manipulators_output_00003.0001");
65 
66  /*
67  Instantiation of a FFDLattice with cylindrical shape.
68  Setup of cylinder dimensions and number of lattice nodes/nurbs degrees
69  for each cylindrical coordinate.
70  Plot Optional results during execution active for FFD block.
71  */
72  mimmo::FFDLattice* lattice = new mimmo::FFDLattice();
73  darray3E origin = {-1537.5, -500.0, 3352.5};
74  darray3E span;
75  span[0]= 100.0;
76  span[1]= 2*BITPIT_PI;
77  span[2]= 1000.0;
78 
79  /*
80  Set number of nodes of the mesh (dim) and degree of nurbs functions (deg).
81  */
82  iarray3E dim, deg;
83  dim[0] = 2;
84  dim[1] = 15;
85  dim[2] = 20;
86 
87  deg[0] = 1;
88  deg[1] = 2;
89  deg[2] = 10;
90 
91  lattice->setLattice(origin,span,mimmo::ShapeType::CYLINDER,dim, deg);
92 
93  /*
94  Change reference system to work in local cylindrical coordinates.
95  */
96  lattice->setRefSystem(2, darray3E{0,-1,0});
97  lattice->setDisplGlobal(false);
98  lattice->setPlotInExecution(true);
99 
100  /*
101  Build mesh of lattice outside the execution chain
102  to use it during setup the displacements.
103  */
104  lattice->build();
105 
106  /* Creation of displacements for control nodes of the lattice.
107  * Use a polynomial law in local coordinates to define the displacements.
108  * The used expression guarantees the continuity of the surface at the interface
109  * between deformed and the undeformed parts.
110  * As exercise GenericInput/Output blocks are used to write them down to file
111  */
112  int ndof = lattice->getNNodes();
113  dvecarr3E displ(ndof, darray3E{0,0,0});
114  int lt = 2*dim[2]/3;
115  double lx;
116  double a, b, c, max;
117  c = 6;
118  b = -15;
119  a = 10;
120  max = 100;
121  for (int i=0; i<ndof; i++){
122  int l1,l2,l3;
123  int index = lattice->accessGridFromDOF(i);
124  lattice->accessPointIndex(index,l1,l2,l3);
125  if (l3 < lt && l1 > 0){
126  lx = double(l3)/double(lt);
127  displ[i][0] = max*(c*pow(lx,5) + b*pow(lx,4) + a*pow(lx,3));
128  }
129  else if (l1 > 0){
130  displ[i][0] = max;
131  }
132  }
133 
134  /*
135  Set Generic input block with the
136  displacements defined above.
137  */
139  input->setReadFromFile(false);
140  input->setInput(displ);
141 
142  /*
143  Set Generic output block to write the
144  displacements defined above.
145  */
147  output->setFilename("manipulators_output_00003.csv");
148  output->setCSV(true);
149 
150  /*
151  Create applier block.
152  It applies the deformation displacements to the original input geometry.
153  */
154  mimmo::Apply* applier = new mimmo::Apply();
155 
156  /*
157  Setup pin connections.
158  */
159  mimmo::pin::addPin(mimmo0, lattice, M_GEOM, M_GEOM);
160  mimmo::pin::addPin(input, lattice, M_DISPLS, M_DISPLS);
161  mimmo::pin::addPin(input, output, M_DISPLS, M_DISPLS);
162  mimmo::pin::addPin(mimmo0, applier, M_GEOM, M_GEOM);
163  mimmo::pin::addPin(lattice, applier, M_GDISPLS, M_GDISPLS);
164  mimmo::pin::addPin(applier, mimmo1, M_GEOM, M_GEOM);
165 
166  /*
167  Setup execution chain.
168  */
169  mimmo::Chain ch0;
170  ch0.addObject(mimmo0);
171  ch0.addObject(input);
172  ch0.addObject(output);
173  ch0.addObject(lattice);
174  ch0.addObject(applier);
175  ch0.addObject(mimmo1);
176 
177  /*
178  Execute the chain.
179  Use debug flag false (default) to avoid to to print out the execution steps.
180  */
181  std::cout << " " << std::endl;
182  std::cout << " --- execution start --- " << std::endl;
183  ch0.exec();
184  std::cout << " --- execution done --- " << std::endl;
185  std::cout << " " << std::endl;
186 
187  /*
188  Clean up & exit;
189  */
190  delete applier;
191  delete lattice;
192  delete input;
193  delete output;
194  delete mimmo0;
195  delete mimmo1;
196 
197  return;
198 }
199 
200 int main( int argc, char *argv[] ) {
201 
202  BITPIT_UNUSED(argc);
203  BITPIT_UNUSED(argv);
204 
205 #if MIMMO_ENABLE_MPI
206  MPI_Init(&argc, &argv);
207 #endif
208  try{
210  test00003() ;
211  }
212  catch(std::exception & e){
213  std::cout<<"manipulators_example_00003 exited with an error of type : "<<e.what()<<std::endl;
214  return 1;
215  }
216 #if MIMMO_ENABLE_MPI
217  MPI_Finalize();
218 #endif
219 
220  return 0;
221 }
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 setRefSystem(darray3E, darray3E, darray3E)
std::vector< darray3E > dvecarr3E
void setDisplGlobal(bool flag)
Definition: FFDLattice.cpp:298
void setWriteFileType(FileType type)
void setFilename(std::string filename)
void setWriteDir(std::string dir)
int accessPointIndex(int i, int j, int k)
void setInput(T *data)
GENERICINPUT////////////////////////////////////////////////////////////////////////////.
void setWriteFilename(std::string filename)
GenericOutput is the class that write generic data in a file output.
int getNNodes()
Definition: Lattice.cpp:125
GenericInput is the class that set the initialization of a generic input data.
void setReadFilename(std::string filename)
void setCSV(bool csv)
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...
int accessGridFromDOF(int index)
Definition: Lattice.cpp:183
void setReadFromFile(bool readFromFile)
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
virtual bool build()