geohandlers_example_00004.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 // =================================================================================== //
46 // =================================================================================== //
47 
48 /*
49  * Create a surface polygonal mesh and return it in a MimmoObject.
50  * Pidding the "M I O" mesh subpart with PID = 1;
51  *
52  * \return pointer to the filled polygonal surface mesh
53  */
55 
57 
58  int rank = -1;
59 #if MIMMO_ENABLE_MPI
60  rank = mesh->getRank();
61  if ( rank == 0)
62 #endif
63  {
64  //create the vertices set.
65  mesh->addVertex({{0.0,0.0,0.0}}, 0);
66  mesh->addVertex({{0.0,1.0,0.0}}, 1);
67  mesh->addVertex({{0.3,0.0,0.0}}, 2);
68  mesh->addVertex({{0.3,1.0,0.0}}, 3);
69  mesh->addVertex({{0.4,0.0,0.0}}, 4);
70  mesh->addVertex({{0.4,0.75,0.0}}, 5);
71  mesh->addVertex({{0.4,1.0,0.0}}, 6);
72  mesh->addVertex({{0.65,0.25,0.0}}, 7);
73  mesh->addVertex({{0.65,0.5,0.0}}, 8);
74  mesh->addVertex({{0.9,0.0,0.0}}, 9);
75  mesh->addVertex({{0.9,0.75,0.0}}, 10);
76  mesh->addVertex({{0.9,1.0,0.0}}, 11);
77  mesh->addVertex({{1.0,0.0,0.0}}, 12);
78  mesh->addVertex({{1.0,1.0,0.0}}, 13);
79  mesh->addVertex({{1.3,0.0,0.0}}, 14);
80  mesh->addVertex({{1.3,1.0,0.0}}, 15);
81  mesh->addVertex({{1.4,0.0,0.0}}, 16);
82  mesh->addVertex({{1.4,1.0,0.0}}, 17);
83  mesh->addVertex({{1.7,0.0,0.0}}, 20);
84  mesh->addVertex({{1.7,1.0,0.0}}, 21);
85  mesh->addVertex({{1.8,0.0,0.0}}, 22);
86  mesh->addVertex({{1.8,0.1,0.0}}, 23);
87  mesh->addVertex({{1.8,0.9,0.0}}, 24);
88  mesh->addVertex({{1.8,1.0,0.0}}, 25);
89  mesh->addVertex({{2.3,0.0,0.0}}, 26);
90  mesh->addVertex({{2.3,0.1,0.0}}, 27);
91  mesh->addVertex({{2.3,0.9,0.0}}, 28);
92  mesh->addVertex({{2.3,1.0,0.0}}, 29);
93  mesh->addVertex({{2.4,0.0,0.0}}, 30);
94  mesh->addVertex({{2.4,1.0,0.0}}, 31);
95  mesh->addVertex({{2.7,0.0,0.0}}, 32);
96  mesh->addVertex({{2.7,1.0,0.0}}, 33);
97 
98  //add and create polygonal cells
99  mesh->addConnectedCell(livector1D({{0,2,3,1}}), bitpit::ElementType::QUAD, long(0), long(0), rank);
100  mesh->addConnectedCell(livector1D({{5,2,4,5,6,3}}), bitpit::ElementType::POLYGON, long(1), long(1), rank);
101  mesh->addConnectedCell(livector1D({{5,4,9,10,7,5}}), bitpit::ElementType::POLYGON, long(0), long(2), rank);
102  mesh->addConnectedCell(livector1D({{5,7,8,6}}), bitpit::ElementType::QUAD, long(1), long(3), rank);
103  mesh->addConnectedCell(livector1D({{7,10,11,8}}), bitpit::ElementType::QUAD, long(1), long(4), rank);
104  mesh->addConnectedCell(livector1D({{6,8,11}}), bitpit::ElementType::TRIANGLE, long(0), long(5), rank);
105  mesh->addConnectedCell(livector1D({{5,9,12,13,11,10}}), bitpit::ElementType::POLYGON, long(1), long(6), rank);
106  mesh->addConnectedCell(livector1D({{12,14,15,13}}), bitpit::ElementType::QUAD, long(0), long(7), rank);
107  mesh->addConnectedCell(livector1D({{14,16,17,15}}), bitpit::ElementType::QUAD, long(1), long(8), rank);
108  mesh->addConnectedCell(livector1D({{16,20,21,17}}), bitpit::ElementType::QUAD, long(0), long(9), rank);
109  mesh->addConnectedCell(livector1D({{6, 20,22, 23,24,25,21}}), bitpit::ElementType::POLYGON, long(1), long(10), rank);
110  mesh->addConnectedCell(livector1D({{22,26,27,23}}), bitpit::ElementType::QUAD, long(1), long(11), rank);
111  mesh->addConnectedCell(livector1D({{23,27,28,24}}), bitpit::ElementType::QUAD, long(0), long(12), rank);
112  mesh->addConnectedCell(livector1D({{24,28,29,25}}), bitpit::ElementType::QUAD, long(1), long(13), rank);
113  mesh->addConnectedCell(livector1D({{6,26,30,31,29,28,27}}), bitpit::ElementType::POLYGON, long(1), long(14), rank);
114  mesh->addConnectedCell(livector1D({{30,32,33,31}}), bitpit::ElementType::QUAD, long(0), long(15), rank);
115 
116  }
117 
118  mesh->update();
119 
120  return mesh;
121 }
122 
123 
124 // core function
125 void test00001() {
126 
127  mimmo::setExpertMode(true);
128 
129  /*
130  * Create a surface polygonal mesh with sub-part MIO pidded as PID=1
131  */
132  mimmo::MimmoSharedPointer<mimmo::MimmoObject> geo = createMIOMesh();
133 
134 #if MIMMO_ENABLE_MPI
135  /*
136  Distribute geo among the processes.
137  */
138  std::unique_ptr<mimmo::Partition> partition(new mimmo::Partition());
139  partition->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
140  partition->setPlotInExecution(true);
141  partition->setGeometry(geo);
142 #endif
143 
144  /*
145  * extract subpart MIO with SelectionByPID
146  MPI version will absorb distributed geo from partition block input connection.
147  Serial case will require an explicit set of the target geometry
148  */
149  std::unique_ptr<mimmo::SelectionByPID> sel(new mimmo::SelectionByPID());
150  sel->setName("PIDExtraction");
151 #if MIMMO_ENABLE_MPI==0
152  sel->setGeometry(geo);
153 #endif
154  sel->setPID(1);
155  sel->setDual(false);
156  sel->setPlotInExecution(true);
157 
158  /*
159  * Isolate M from MIO sub part using a plane clipping.
160  The block will require the input of a point and normal to define the plane
161  InsideOut will control the emispace active for the clipping
162  */
163  std::unique_ptr<mimmo::ClipGeometry> clip(new mimmo::ClipGeometry());
164  clip->setName("PlaneClipping");
165  clip->setOrigin({{1.1,0.0,0.0}});
166  clip->setNormal({{1.0,0.0,0.0}});
167  clip->setInsideOut(true);
168  clip->setPlotInExecution(true);
169 
170  /*
171  * Triangulate the polygonal tessellation of the M subpart
172  */
173  std::unique_ptr<mimmo::SurfaceTriangulator> triang(new mimmo::SurfaceTriangulator());
174  triang->setName("TriangulateSurface");
175  triang->setPlotInExecution(true);
176 
177 
178  /*
179  Define block pin connections.
180  */
181 #if MIMMO_ENABLE_MPI
182  mimmo::pin::addPin(partition.get(), sel.get(), M_GEOM, M_GEOM);
183 #endif
184  mimmo::pin::addPin(sel.get(), clip.get(), M_GEOM, M_GEOM);
185  mimmo::pin::addPin(clip.get(), triang.get(), M_GEOM, M_GEOM);
186 
187  /*
188  Setup execution chain.
189  */
190  mimmo::Chain ch0;
191 #if MIMMO_ENABLE_MPI
192  ch0.addObject(partition.get());
193 #endif
194  ch0.addObject(sel.get());
195  ch0.addObject(clip.get());
196  ch0.addObject(triang.get());
197 
198  /*
199  Execute the chain.
200  Use debug flag true to to print out the execution steps.
201  */
202  ch0.exec(true);
203 
204  return;
205 }
206 
207 // =================================================================================== //
208 
209 int main( int argc, char *argv[] ) {
210 
211  BITPIT_UNUSED(argc);
212  BITPIT_UNUSED(argv);
213 
214 #if MIMMO_ENABLE_MPI
215  MPI_Init(&argc, &argv);
216 #endif
217  try{
219  test00001();
220  }
221  catch(std::exception & e){
222  std::cout<<"geohandlers_example_00004 exited with an error of type : "<<e.what()<<std::endl;
223  return 1;
224  }
225 #if MIMMO_ENABLE_MPI
226  MPI_Finalize();
227 #endif
228 
229  return 0;
230 }
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
MimmoObject is the basic geometry container for mimmo library.
#define M_GEOM
std::vector< long > livector1D
Selection using target mesh Part Identifiers.
bool addPin(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR, bool forced)
ClipGeometry is a class that clip a 3D geometry according to a plane intersecting it.
Triangulate a target MimmoObject non-homogeneous and/or non-triangular surface mesh.
void setExpertMode(bool flag)
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170