ioofoam_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_iogeneric.hpp"
26 #include "IOOFOAM.hpp"
27 #include "mimmo_manipulators.hpp"
28 
29 // =================================================================================== //
30 
50 void OFOAM_readwrite() {
51 
52  /* read a OpenFoam mesh, expose bulk volume and boundary mesh */
53  mimmo::IOOFOAM * reader = new mimmo::IOOFOAM(false);
54  reader->setDir("geodata/ofoam.00002");
55 
56  /* write surface boundary mesh to file */
58  surfacewriter->setWriteDir(".");
59  surfacewriter->setWriteFileType(FileType::SURFVTU);
60  surfacewriter->setWriteFilename("ioofoam.00002");
61 
62  /* write bulk volume mesh to file */
64  volumewriter->setWriteDir(".");
65  volumewriter->setWriteFileType(FileType::VOLVTU);
66  volumewriter->setWriteFilename("ioofoam.00003");
67 
68  /* write openfoam mesh to file */
69  mimmo::IOOFOAM * writer = new mimmo::IOOFOAM(true);
70  writer->setDir("geodata/ofoam.00002");
71 
72  /* define block pin connections */
74  mimmo::pin::addPin(reader, surfacewriter, M_GEOMOFOAM2, M_GEOM);
75  mimmo::pin::addPin(reader, volumewriter, M_GEOMOFOAM, M_GEOM);
76  mimmo::pin::addPin(reader, writer, M_GEOMOFOAM, M_GEOMOFOAM);
77  mimmo::pin::addPin(reader, writer, M_UMAPIDS, M_UMAPIDS);
78 
79  /* define chain execution */
80  mimmo::Chain c0;
81  c0.addObject(reader);
82  c0.addObject(surfacewriter);
83  c0.addObject(volumewriter);
84  c0.addObject(writer);
85  c0.exec(true);
86 
87  /*clean up */
88  delete reader;
89  delete surfacewriter;
90  delete volumewriter;
91  delete writer;
92 }
93 
94 // =================================================================================== //
95 
96 int main( int argc, char *argv[] ) {
97 
98  BITPIT_UNUSED(argc);
99  BITPIT_UNUSED(argv);
100 
101 #if MIMMO_ENABLE_MPI
102  MPI_Init(&argc, &argv);
103 #endif
104 
105  try{
106  OFOAM_readwrite() ;
107  }
108  catch(std::exception & e){
109  std::cout<<"ioofoam_example_00002 exit with the following errors :"<<e.what()<<std::endl;
110  return 1;
111  }
112 
113 #if MIMMO_ENABLE_MPI
114  MPI_Finalize();
115 #endif
116 
117  return 0;
118 }
void exec(bool debug=false)
Definition: Chain.cpp:284
#define M_UMAPIDS
#define M_GEOMOFOAM
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 setWriteFilename(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...
#define M_GEOMOFOAM2
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170