geohandlers_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_geohandlers.hpp"
26 #if MIMMO_ENABLE_MPI
27 #include "mimmo_parallel.hpp"
28 #endif
29 
30 // =================================================================================== //
45 // =================================================================================== //
46 
47 void test00002() {
48 
49  /*
50  Read a sphere from STL file. Convert mode is to save the just read geometry in
51  another file with name geohandlers_output_00002.0000.stl
52  */
54  mimmo0->setReadDir("geodata");
55  mimmo0->setReadFilename("sphere2");
56  mimmo0->setReadFileType(FileType::STL);
57  mimmo0->setWriteDir("./");
58  mimmo0->setWriteFileType(FileType::STL);
59  mimmo0->setWriteFilename("geohandlers_output_00002.0000");
60 
61  /*
62  Read the Stanford bunny from STL file. Convert mode is to save the just read geometry in
63  another file with name geohandlers_output_00002.0001.stl
64  */
66  mimmo1->setReadDir("geodata");
67  mimmo1->setReadFilename("stanfordBunny2");
68  mimmo1->setReadFileType(FileType::STL);
69  mimmo1->setWriteDir("./");
70  mimmo1->setWriteFileType(FileType::STL);
71  mimmo1->setWriteFilename("geohandlers_output_00002.0001");
72 
73  /*
74  Write the stiched geometry to STL file.
75  */
77  mimmo2->setWriteDir("./");
78  mimmo2->setWriteFileType(FileType::STL);
79  mimmo2->setWriteFilename("geohandlers_output_00002.0002");
80 
81 #if MIMMO_ENABLE_MPI
82 
83  /* Block to distribute among processors the sphere geometry */
84  mimmo::Partition* partition0 = new mimmo::Partition();
85  partition0->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
86  partition0->setPlotInExecution(true);
87 
88  /* Block to distribute among processors the bunny geometry */
89  mimmo::Partition* partition1 = new mimmo::Partition();
90  partition1->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
91  partition1->setPlotInExecution(true);
92 #endif
93 
94  /*
95  Stitcher of multiple geometries.
96  * Plot Optional results during execution active for Stitcher block.
97  */
98  mimmo::StitchGeometry * stitcher = new mimmo::StitchGeometry(1);
99  stitcher->setPlotInExecution(true);
100  stitcher->setOutputPlot(".");
101 
102  /*
103  Setup block pin connections.
104  */
105 #if MIMMO_ENABLE_MPI
106  mimmo::pin::addPin(mimmo0, partition0, M_GEOM, M_GEOM);
107  mimmo::pin::addPin(partition0, stitcher, M_GEOM, M_GEOM);
108  mimmo::pin::addPin(mimmo1, partition1, M_GEOM, M_GEOM);
109  mimmo::pin::addPin(partition1, stitcher, M_GEOM, M_GEOM);
110 #else
111  mimmo::pin::addPin(mimmo0, stitcher, M_GEOM, M_GEOM);
112  mimmo::pin::addPin(mimmo1, stitcher, M_GEOM, M_GEOM);
113 #endif
114  mimmo::pin::addPin(stitcher, mimmo2, M_GEOM, M_GEOM);
115 
116  /*
117  Setup execution chain.
118  */
119  mimmo::Chain ch0;
120  ch0.addObject(mimmo0);
121  ch0.addObject(mimmo1);
122 #if MIMMO_ENABLE_MPI
123  ch0.addObject(partition0);
124  ch0.addObject(partition1);
125 #endif
126  ch0.addObject(stitcher);
127  ch0.addObject(mimmo2);
128 
129  /*
130  Execution the chain.
131  Use debug flag true to to print out the execution steps.
132  */
133  ch0.exec(true);
134 
135  /* Clean up & exit;
136  */
137  delete mimmo0;
138  delete mimmo1;
139 #if MIMMO_ENABLE_MPI
140  delete partition0;
141  delete partition1;
142 #endif
143  delete mimmo2;
144  delete stitcher;
145 
146  return;
147 }
148 
149 // =================================================================================== //
150 
151 int main( int argc, char *argv[] ) {
152 
153  BITPIT_UNUSED(argc);
154  BITPIT_UNUSED(argv);
155 
156 #if MIMMO_ENABLE_MPI
157  MPI_Init(&argc, &argv);
158 #endif
159 
160  try{
161  test00002() ;
162  }
163  catch(std::exception & e){
164  std::cout<<"geohandlers_example_00002 exited with an error of type : "<<e.what()<<std::endl;
165  return 1;
166  }
167 #if MIMMO_ENABLE_MPI
168  MPI_Finalize();
169 #endif
170 
171  return 0;
172 }
void exec(bool debug=false)
Definition: Chain.cpp:284
Chain is the class used to manage the chain execution of multiple executable blocks (manipulation obj...
Definition: Chain.hpp:48
#define M_GEOM
void setWriteFileType(FileType type)
void setWriteDir(std::string dir)
void setOutputPlot(std::string path)
void setWriteFilename(std::string filename)
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...
StitchGeometry is an executable block class capable of stitch multiple MimmoObject geometries of the ...
void setReadFileType(FileType type)
void setReadDir(std::string dir)
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170