geohandlers_example_00001.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 #include <bitpit_common.hpp>
30 
31 // =================================================================================== //
47 // =================================================================================== //
48 
49 void test00001() {
50 
51  /*
52  Read a target geometry from file. CONVERT option will let the block to write
53  the just read file in another file, immediately after the reading.
54  */
56  mimmo0->setName("mimmo0");
57  mimmo0->setReadDir("./geodata");
58  mimmo0->setReadFileType(FileType::STL);
59  mimmo0->setReadFilename("sphere2");
60  mimmo0->setWriteDir("./");
61  mimmo0->setWriteFileType(FileType::STL);
62  mimmo0->setWriteFilename("geohandlers_output_00001.0000");
63 
64  /*
65  Write a geometry to file
66  */
68  mimmo1->setWriteDir(".");
69  mimmo1->setWriteFileType(FileType::SURFVTU);
70  mimmo1->setWriteFilename("geohandlers_output_00001.0001");
71 
72  /*
73  Write a geometry to file
74  */
76  mimmo2->setWriteDir(".");
77  mimmo2->setWriteFileType(FileType::SURFVTU);
78  mimmo2->setWriteFilename("geohandlers_output_00001.0002");
79 
80 #if MIMMO_ENABLE_MPI
81  /*
82  Distribute a target mesh geometry among processors
83  */
84  mimmo::Partition* partition = new mimmo::Partition();
85  partition->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
86  partition->setPlotInExecution(true);
87 #endif
88 
89  /*
90  Select a portion of geometry incapsulated inside a Box/Cube.
91  Span and origin of the box are needed.
92  */
94  boxSel->setOrigin({{-0.5,-0.5,0.2}});
95  boxSel->setSpan(0.6,0.6,0.6);
96 
97  /*
98  Select a portion of geometry incapsulated inside a Sphere.
99  Radius, angular spans and origin of the sphere are needed.
100  */
102  sphSel->setOrigin({{-0.5, 0.5,0.2}});
103  sphSel->setSpan(0.34, 2*BITPIT_PI, BITPIT_PI);
104 
105  /*
106  Block to refine triangles of a target mesh
107  Refine Engine type and number of refinement steps are needed.
108  Smoothing steps >0 activate a n-steps procedure to attempt smoothing/regularizing
109  the final refined mesh.
110  */
113  refine->setRefineSteps(2);
114  refine->setSmoothingSteps(1);
115 
116  /*
117  Define block pin connections.
118  */
119 #if MIMMO_ENABLE_MPI
120  mimmo::pin::addPin(mimmo0, partition, M_GEOM, M_GEOM);
121  mimmo::pin::addPin(partition, boxSel, M_GEOM, M_GEOM);
122  mimmo::pin::addPin(partition, sphSel, M_GEOM, M_GEOM);
123 #else
124  mimmo::pin::addPin(mimmo0, boxSel, M_GEOM, M_GEOM);
125  mimmo::pin::addPin(mimmo0, sphSel, M_GEOM, M_GEOM);
126 #endif
127  mimmo::pin::addPin(boxSel, refine, M_GEOM, M_GEOM);
128  mimmo::pin::addPin(refine, mimmo1, M_GEOM, M_GEOM);
129  mimmo::pin::addPin(sphSel, mimmo2, 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(boxSel);
140  ch0.addObject(refine);
141  ch0.addObject(sphSel);
142  ch0.addObject(mimmo1);
143  ch0.addObject(mimmo2);
144 
145  /*
146  Execute the chain.
147  Use debug flag true to to print out the execution steps.
148  */
149  ch0.exec(true);
150 
151  /*
152  Clean up & exit;
153  */
154  delete boxSel;
155  delete sphSel;
156  delete mimmo0;
157 #if MIMMO_ENABLE_MPI
158  delete partition;
159 #endif
160  delete refine;
161  delete mimmo1;
162  delete mimmo2;
163 
164  return;
165 }
166 
167 // =================================================================================== //
168 
169 int main( int argc, char *argv[] ) {
170 
171  BITPIT_UNUSED(argc);
172  BITPIT_UNUSED(argv);
173 
174 #if MIMMO_ENABLE_MPI
175  MPI_Init(&argc, &argv);
176 #endif
177  try{
179  test00001();
180  }
181  catch(std::exception & e){
182  std::cout<<"geohandlers_example_00001 exited with an error of type : "<<e.what()<<std::endl;
183  return 1;
184  }
185 #if MIMMO_ENABLE_MPI
186  MPI_Finalize();
187 #endif
188 
189  return 0;
190 }
void setOrigin(darray3E)
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 setSmoothingSteps(int steps)
void setWriteFileType(FileType type)
void setName(std::string name)
void setWriteDir(std::string dir)
void setWriteFilename(std::string filename)
void setRefineType(RefineType type)
void setReadFilename(std::string filename)
void setRefineSteps(int steps)
Selection through sphere primitive.
bool addPin(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR, bool forced)
Selection through volume box primitive.
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
RefineGeometry is an executable block class capable of refine a surface geometry.
void setReadFileType(FileType type)
void setSpan(double, double, double)
void setReadDir(std::string dir)
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170