parallel_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 #include "mimmo_parallel.hpp"
25 #include "mimmo_manipulators.hpp"
26 #include "mimmo_iogeneric.hpp"
27 #include <bitpit_common.hpp>
28 
29 // =================================================================================== //
42 void test00002() {
43 
44  /*
45  Read a STL sphere
46  */
48  mimmo0->setReadDir("geodata");
49  mimmo0->setReadFileType(FileType::STL);
50  mimmo0->setReadFilename("sphere2");
51 
52  /*
53  Write the partitioned geometry in parallel vtu format
54  */
56  mimmo1->setWriteDir(".");
57  mimmo1->setWriteFileType(FileType::SURFVTU);
58  mimmo1->setWriteFilename("parallel_output_00002.0001");
59 
60  /*
61  Write the partitioned deformed geometry in parallel vtu format
62  */
64  mimmo2->setWriteDir(".");
65  mimmo2->setWriteFileType(FileType::SURFVTU);
66  mimmo2->setWriteFilename("parallel_output_00002.0002");
67 
68  /*
69  Distribute the target mesh among processes.
70  */
71  mimmo::Partition* partition = new mimmo::Partition();
72  partition->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
73  partition->setPlotInExecution(false);
74 
75  /*
76  FFDLattice manipulator - Sphere shaped - creation .
77  It will require the sphere dimensions and lattice number of
78  nodes and nurbs degrees
79  */
80  mimmo::FFDLattice* lattice = new mimmo::FFDLattice();
81  darray3E origin = {0.0, 0.0,0.0};
82  darray3E span;
83  span[0]= 3.01;
84  span[1]= 2*BITPIT_PI;
85  span[2]= BITPIT_PI;
86 
87  /*
88  Set number of nodes of the mesh (dim) and degree of nurbs functions (deg).
89  */
90  iarray3E dim, deg;
91  dim[0] = 30;
92  dim[1] = 30;
93  dim[2] = 30;
94  deg[0] = 2;
95  deg[1] = 2;
96  deg[2] = 2;
97 
98  lattice->setLattice(origin,span,mimmo::ShapeType::SPHERE,dim, deg);
99 
100  /*
101  Change reference system to work in local spherical coordinates.
102  Set coordinates as CLAMPED (continuity in origins of angles).
103  */
104  lattice->setRefSystem(2, darray3E{0,1,0});
106  lattice->setPlotInExecution(false);
107 
108  /*
109  Build mesh of lattice outside the execution chain
110  to use it during setup the displacements.
111  */
112  lattice->build();
113 
114  /*
115  Use random values to set the displacements of the control nodes at a longitude
116  * angle smaller than PI and expansion on radius direction for nodes with longitude
117  * angle greater than PI.
118  */
119  int ndeg = lattice->getNNodes();
120  dvecarr3E displ(ndeg, darray3E{0,0,0});
121  time_t Time = time(NULL);
122  srand(Time);
123  for (int i=0; i<ndeg; i++){
124  int l1,l2,l3;
125  int index = lattice->accessGridFromDOF(i);
126  lattice->accessPointIndex(index,l1,l2,l3);
127  if(l1 > 0 && lattice->getLocalPoint(l1,l2,l3)[1] < BITPIT_PI){
128  displ[i][0] = 1.0*( (double) (rand()) / RAND_MAX );
129  }
130  if( (l1 > 0 && lattice->getLocalPoint(l1,l2,l3)[1] >= BITPIT_PI)
131  || lattice->getLocalPoint(l1,l2,l3)[1] == 0){
132  displ[i][0] = 1.25;
133  }
134 
135  }
136 
137  /*
138  Set Generic input block with the
139  displacements defined above.
140  */
142  input->setInput(displ);
143 
144  /*
145  Create applier block.
146  It applies the deformation displacements to the original input geometry.
147  */
148  mimmo::Apply* applier = new mimmo::Apply();
149 
150  /*
151  Setup pin connections.
152  */
153  mimmo::pin::addPin(mimmo0, partition, M_GEOM, M_GEOM);
154  mimmo::pin::addPin(partition, mimmo1, M_GEOM, M_GEOM);
155  mimmo::pin::addPin(mimmo1, lattice, M_GEOM, M_GEOM);
156  mimmo::pin::addPin(mimmo1, applier, M_GEOM, M_GEOM);
157  mimmo::pin::addPin(input, lattice, M_DISPLS, M_DISPLS);
158  mimmo::pin::addPin(lattice, applier, M_GDISPLS, M_GDISPLS);
159  mimmo::pin::addPin(applier, mimmo2, M_GEOM, M_GEOM);
160 
161  /*
162  Setup execution chain.
163  */
164  mimmo::Chain ch0;
165  ch0.addObject(input);
166  ch0.addObject(partition);
167  ch0.addObject(applier);
168  ch0.addObject(lattice);
169  ch0.addObject(mimmo0);
170  ch0.addObject(mimmo1);
171  ch0.addObject(mimmo2);
172 
173  /*
174  Execute the chain.
175  Use debug flag false to avoid printing intermediate results of the execution steps.
176  */
177  ch0.exec(true);
178 
179  /*
180  Clean up & exit;
181  */
182  delete lattice;
183  delete applier;
184  delete input;
185  delete mimmo0;
186  delete partition;
187  delete mimmo1;
188  delete mimmo2;
189 
190  return;
191 }
192 
193 int main( int argc, char *argv[] ) {
194 
195  BITPIT_UNUSED(argc);
196  BITPIT_UNUSED(argv);
197 
198 #if MIMMO_ENABLE_MPI
199  MPI_Init(&argc, &argv);
200 
201  {
202 #endif
203  try{
205  test00002() ;
206  }
207  catch(std::exception & e){
208  std::cout<<"parallel_example_00002 exited with an error of type : "<<e.what()<<std::endl;
209  return 1;
210  }
211 #if MIMMO_ENABLE_MPI
212  }
213  MPI_Finalize();
214 #endif
215 
216  return 0;
217 }
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
darray3E getLocalPoint(int)
#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 setWriteFileType(FileType type)
void setCoordType(CoordType, int)
void setWriteDir(std::string dir)
int accessPointIndex(int i, int j, int k)
void setInput(T *data)
GENERICINPUT////////////////////////////////////////////////////////////////////////////.
void setWriteFilename(std::string filename)
int getNNodes()
Definition: Lattice.cpp:125
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...
int accessGridFromDOF(int index)
Definition: Lattice.cpp:183
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()