iocgns_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 #include "mimmo_iocgns.hpp"
25 #include "mimmo_geohandlers.hpp"
26 #include "mimmo_manipulators.hpp"
27 #include "mimmo_propagators.hpp"
28 #if MIMMO_ENABLE_MPI
29 #include "mimmo_parallel.hpp"
30 #endif
31 
54 // =================================================================================== //
55 
56 void example00001() {
57 
58  /* Create IOCGNS object to import cgns input file. Bulk volume and its boundary
59  meshes will be available.
60  */
61  mimmo::IOCGNS * cgnsI = new mimmo::IOCGNS(mimmo::IOCGNS::IOCGNS_Mode::READ);
62  cgnsI->setDir("geodata");
63  cgnsI->setFilename("grid");
64  cgnsI->setTolerance(1.0e-12);
65 
66  /* Create IOCGNS object to export deformed volume mesh and its boundary to a cgns file. */
67  mimmo::IOCGNS * cgnsO = new mimmo::IOCGNS(mimmo::IOCGNS::IOCGNS_Mode::WRITE);
68  cgnsO->setDir(".");
69  cgnsO->setFilename("iocgns_output_00001");
70 
71 #if MIMMO_ENABLE_MPI
72 
73  /*
74  Distribute the target compound of volume/boundary meshes among processes.
75  Plot Optional results during execution active for Partition block.
76  */
77  mimmo::Partition *partition = new mimmo::Partition();
78  partition->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
79  partition->setPlotInExecution(true);
80 
81  /*
82  Serialize the distributed target compound volume/boundary meshes
83  right before writing it in a cgns file.
84  */
85  mimmo::Partition *serialize = new mimmo::Partition();
86  serialize->setPartitionMethod(mimmo::PartitionMethod::SERIALIZE);
87  serialize->setPlotInExecution(true);
88 #endif
89 
90  /*
91  Select and extract from target boundary mesh the compound of PID = 1,2
92  (Wing wall and outer part boundaries where Dirichlet conditions for field propagator
93  must be enforced).
94  */
95  mimmo::SelectionByPID * cgnsDirichlet = new mimmo::SelectionByPID();
96  cgnsDirichlet->setPID({1, 2});
97  cgnsDirichlet->setPlotInExecution(true);
98 
99  /*
100  Select and extract from target boundary mesh the PID = 3
101  (Simmetry plane where Slip/impermeability conditions for field propagator
102  will be imposed).
103  */
104  mimmo::SelectionByPID * cgnsSlip = new mimmo::SelectionByPID();
105  cgnsSlip->setPID({3});
106  cgnsSlip->setPlotInExecution(true);
107 
108  /*
109  Sub-select with a Box primitive the result of cgnDirichlet block.
110  to isolate the wing surface
111  It will require span and origin to define properly the box .
112  */
114  boxSel->setOrigin({{700., 800., 0.}});
115  boxSel->setSpan(1500.,1600.,100.);
116  boxSel->setPlotInExecution(true);
117 
118  /*
119  Create a Rotation global manipulator. It will Rotate the isolated wing sub-selection
120  of a prescribed rotation angle around a prescribed axis direction, and make the
121  relative deformation field available
122  */
124  rotation->setDirection(darray3E{0.1,1.,0.});
125  rotation->setRotation((BITPIT_PI/18.0));
126 
127  /*
128  It will reconstruct the rotation deformation field defined on the isolated wing patch to
129  the cgnsDirichlet compound sub-patch.
130  */
132  recon->setPlotInExecution(true);
133 
134  /*
135  The block will propagate the reconstructed deformation field defined on
136  cgnsDirichlet subpatch into the bulk volume mesh, moving its internal points
137  coherently.
138  Dirichlet conditions will be applied connecting cgnsDirichlet subpatch and
139  the field just reconstructed on it.
140  Slip/impermeability conditions will be enforced on cgnsSlip sub-patch to
141  keep the simmetry of the wall.
142  The final result will be a consistent deformation field defined on the whole
143  volume mesh, boundaries included.
144  For set up of damping and narrowband features of the class please visit the
145  doxygen documentation
146  */
147  mimmo::PropagateVectorField* prop = new mimmo::PropagateVectorField();
148  prop->setPlotInExecution(true);
149  prop->setTolerance(1.0e-9);
150  prop->setUpdateThreshold(1.0e-12);
151  prop->setDamping(true);
152  prop->setDampingType(0);
153  prop->setDampingInnerDistance(0.01);
154  prop->setDampingOuterDistance(80.0);
155  prop->setDampingDecayFactor(3.0);
156  prop->setNarrowBand(true);
157  prop->setNarrowBandWidth(80.0);
158  prop->setNarrowBandRelaxation(0.3);
159  prop->forcePlanarSlip(true);
160  prop->setSolverMultiStep(1);
161 
162  /*
163  Extract the deformation field of the whole boundary mesh from
164  the deformation field of the whole volume mesh resulting from the prop block
165  Using the id association of bulk volume and boundary meshes
166  */
168  extrF->setMode(1);
169  extrF->setPlotInExecution(true);
170 
171  /*
172  Create an Apply block.
173  It applies the deformation displacements
174  to the selected input volume geometry.
175  */
176  mimmo::Apply* applier = new mimmo::Apply();
177 
178  /*
179  Create an Apply block.
180  It applies the deformation displacements
181  to the selected input surface boundary geometry.
182  */
183  mimmo::Apply* applierS = new mimmo::Apply();
184 
185  /* Define connection between blocks. */
186 #if MIMMO_ENABLE_MPI
187  mimmo::pin::addPin(cgnsI, partition, M_GEOM, M_GEOM) ;
188  mimmo::pin::addPin(cgnsI, partition, M_GEOM2, M_GEOM2) ;
189  mimmo::pin::addPin(partition, cgnsDirichlet, M_GEOM2, M_GEOM) ;
190  mimmo::pin::addPin(partition, cgnsSlip, M_GEOM2, M_GEOM) ;
191 #else
192  mimmo::pin::addPin(cgnsI, cgnsDirichlet, M_GEOM2, M_GEOM) ;
193  mimmo::pin::addPin(cgnsI, cgnsSlip, M_GEOM2, M_GEOM) ;
194 #endif
195 
196  mimmo::pin::addPin(cgnsDirichlet, boxSel, M_GEOM, M_GEOM) ;
197 
198  mimmo::pin::addPin(boxSel, rotation, M_GEOM, M_GEOM) ;
199  mimmo::pin::addPin(rotation, recon, M_GDISPLS, M_VECTORFIELD) ;
200  mimmo::pin::addPin(cgnsDirichlet, recon, M_GEOM, M_GEOM) ;
201 
202 #if MIMMO_ENABLE_MPI
203  mimmo::pin::addPin(partition, prop, M_GEOM, M_GEOM) ;
204 #else
205  mimmo::pin::addPin(cgnsI, prop, M_GEOM, M_GEOM) ;
206 #endif
207  mimmo::pin::addPin(cgnsDirichlet, prop, M_GEOM, M_GEOM2) ;
208  mimmo::pin::addPin(cgnsSlip, prop, M_GEOM, M_GEOM4) ;
209  mimmo::pin::addPin(boxSel, prop, M_GEOM, M_GEOM3) ;
210  mimmo::pin::addPin(boxSel, prop, M_GEOM, M_GEOM7) ;
211 
213  mimmo::pin::addPin(prop, applier, M_GDISPLS, M_GDISPLS) ;
214 
215 #if MIMMO_ENABLE_MPI
216  mimmo::pin::addPin(partition, applier, M_GEOM, M_GEOM) ;
217  mimmo::pin::addPin(partition, extrF, M_GEOM2, M_GEOM) ;
218  mimmo::pin::addPin(partition, applierS, M_GEOM2, M_GEOM) ;
219 #else
220  mimmo::pin::addPin(cgnsI, applier, M_GEOM, M_GEOM) ;
221  mimmo::pin::addPin(cgnsI, extrF, M_GEOM2, M_GEOM) ;
222  mimmo::pin::addPin(cgnsI, applierS, M_GEOM2, M_GEOM) ;
223 #endif
224 
226  mimmo::pin::addPin(extrF, applierS, M_VECTORFIELD, M_GDISPLS) ;
227 
228 #if MIMMO_ENABLE_MPI
229  mimmo::pin::addPin(applier, serialize, M_GEOM, M_GEOM) ;
230  mimmo::pin::addPin(applierS, serialize, M_GEOM, M_GEOM2) ;
231  mimmo::pin::addPin(serialize, cgnsO, M_GEOM, M_GEOM) ;
232  mimmo::pin::addPin(serialize, cgnsO, M_GEOM2, M_GEOM2) ;
233 #else
234  mimmo::pin::addPin(applier, cgnsO, M_GEOM, M_GEOM) ;
235  mimmo::pin::addPin(applierS, cgnsO, M_GEOM, M_GEOM2) ;
236 #endif
237 
238  mimmo::pin::addPin(cgnsI, cgnsO, M_BCCGNS, M_BCCGNS) ;
239 
240  /* Create chains and execute them */
241  mimmo::Chain ch0, ch1;
242 
243  //first one
244  ch0.addObject(cgnsI);
245 #if MIMMO_ENABLE_MPI
246  ch0.addObject(partition);
247 #endif
248  ch0.addObject(cgnsDirichlet);
249  ch0.addObject(cgnsSlip);
250  ch0.addObject(boxSel);
251  ch0.addObject(rotation);
252  ch0.addObject(recon);
253  ch0.addObject(prop);
254  ch0.addObject(extrF);
255  ch0.addObject(applier);
256  ch0.addObject(applierS);
257  #if MIMMO_ENABLE_MPI
258  ch0.addObject(serialize);
259  #endif
260 
261  //second one
262  ch1.addObject(cgnsO);
263 
264  //executing them with debug flag on to provide info on execution.
265  ch0.exec(true);
266  ch1.exec(true);
267 
268  /* Destroy objects. */
269  delete cgnsI;
270 #if MIMMO_ENABLE_MPI
271  delete partition;
272  delete serialize;
273 #endif
274  delete cgnsDirichlet;
275  delete cgnsSlip;
276  delete boxSel;
277  delete rotation;
278  delete recon;
279  delete prop;
280  delete extrF;
281  delete applier;
282  delete applierS;
283  delete cgnsO;
284 
285  return;
286 }
287 
288 // =================================================================================== //
289 
290 int main( int argc, char *argv[] ) {
291 
292  BITPIT_UNUSED(argc);
293  BITPIT_UNUSED(argv);
294 
295 #if MIMMO_ENABLE_MPI
296  MPI_Init(&argc, &argv);
297 
298  {
299 #endif
300  try{
302  example00001();
303  }
304  catch(std::exception & e){
305  std::cout<<"iocgns_example_00001 exited with an error of type : "<<e.what()<<std::endl;
306  return 1;
307  }
308 #if MIMMO_ENABLE_MPI
309  }
310 
311  MPI_Finalize();
312 #endif
313 
314  return 0;
315 }
void setOrigin(darray3E)
void exec(bool debug=false)
Definition: Chain.cpp:284
void setPID(long i=-1)
#define M_GDISPLS
Chain is the class used to manage the chain execution of multiple executable blocks (manipulation obj...
Definition: Chain.hpp:48
#define M_GEOM
RotationGeometry is the class that applies a rotation to a given geometry patch.
Apply is the class that applies the deformation resulting from a manipulation object to the geometry.
Definition: Apply.hpp:89
#define M_GEOM2
#define M_BCCGNS
#define M_GEOM7
#define M_VECTORFIELD
void setRotation(double alpha)
Selection using target mesh Part Identifiers.
bool addPin(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR, bool forced)
Selection through volume box primitive.
Reconstruct a vector field from daughter mesh to mother mesh.
#define M_GEOM3
std::array< double, 3 > darray3E
void setSpan(double, double, double)
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170
void setMode(ExtractMode mode)
void setDirection(darray3E direction)
#define M_GEOM4
ExtractVectorField is specialized derived class of ExtractField to extract a vector field of array<do...