utils_example_00005.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_utils.hpp"
26 #if MIMMO_ENABLE_MPI
27  #include "Partition.hpp"
28 #endif
29 
30 // =================================================================================== //
45 void test00005() {
46 
47  /*
48  Reading target surface (bunny). Convert is used to rewrite it as-it-is
49  from reading in a new vtu format.
50  */
52  bitpit::Logger & log = mimmo0->getLog();
53  log.setPriority(bitpit::log::Priority::NORMAL);
54 
55  mimmo0->setReadDir("geodata");
56  mimmo0->setReadFileType(FileType::STL);
57  mimmo0->setReadFilename("stanfordBunny3");
58 
59  mimmo0->setWriteDir(".");
60  mimmo0->setWriteFileType(FileType::SURFVTU);
61  mimmo0->setWriteFilename("utils_mesh_00005_surface");
62  mimmo0->execute();
63 
64  /*
65  Reading 3D Curve to be projected. Convert mode is used to rewrite it as-it-is once read.
66  */
68 
69  mimmo1->setReadDir("geodata");
70  mimmo1->setReadFileType(FileType::CURVEVTU);
71  mimmo1->setReadFilename("curve");
72 
73  mimmo1->setWriteDir(".");
74  mimmo1->setWriteFileType(FileType::CURVEVTU);
75  mimmo1->setWriteFilename("utils_mesh_00005_curve");
76  mimmo1->execute();
77 
78 
79  log<<"read geometries from file"<<std::endl;
80 
83 
84 #if MIMMO_ENABLE_MPI
85  //distribute bunny and curve geometries among processes
86  mimmo::Partition * part0 = new mimmo::Partition();
87  part0->setName("PartitionedBunny");
88  part0->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
89  part0->setGeometry(mimmo0->getGeometry());
90  part0->setPlotInExecution(true);
91  part0->exec();
92 
93  mimmo::Partition * part1 = new mimmo::Partition();
94  part1->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
95  part1->setName("PartitionedCurve");
96  part1->setGeometry(mimmo1->getGeometry());
97  part1->setPlotInExecution(true);
98  part1->exec();
99 
100  curve3D = part1->getGeometry();
101  targetSurf = part0->getGeometry();
102 
103  log<<"geometries distributed on rank"<<std::endl;
104 
105 #else
106  curve3D = mimmo1->getGeometry();
107  targetSurf = mimmo0->getGeometry();
108 #endif
109  /*
110  Project the curve onto the bunny target surface
111  */
113  proj->setGeometry(targetSurf);
114  proj->setPatch(curve3D);
115  proj->setWorkingOnTarget(false);
116  proj->execute();
117 
118  //write projected curve
119  proj->getProjectedElement()->getPatch()->write("utils_example_00005_projectedCurve");
120 
121  log<<"curve projected on bunny"<<std::endl;
122 
123  //re-read and write again the resulting projected curve to test further the IO
125 
126  mimmo3->setReadDir(".");
127  mimmo3->setReadFileType(FileType::CURVEVTU);
128  mimmo3->setReadFilename("utils_example_00005_projectedCurve");
129 
130  mimmo3->setWriteDir(".");
131  mimmo3->setWriteFileType(FileType::CURVEVTU);
132  mimmo3->setWriteFilename("utils_mesh_00005_projectedCurveREREAD");
133  mimmo3->execute();
134 
135  log<<"test IO read and write on the newly projected curve done"<<std::endl;
136 
137  /* Clean up & exit;
138  */
139  delete mimmo0;
140  delete mimmo1;
141  delete mimmo3;
142 #if MIMMO_ENABLE_MPI
143  delete part0;
144  delete part1;
145 #endif
146  delete proj;
147 
148 
149  return;
150 
151 }
152 
153 
154 int main(int argc, char *argv[]) {
155 
156  BITPIT_UNUSED(argc);
157  BITPIT_UNUSED(argv);
158 
159 #if MIMMO_ENABLE_MPI==1
160  MPI_Init(&argc, &argv);
161 
162  {
163 #endif
164 
165  mimmo::setLogger("mimmo");
166 
168  try{
169  test00005() ;
170  }
171  catch(std::exception & e){
172  std::cout<<"utils_example_00005 exited with an error of type : "<<e.what()<<std::endl;
173  return 1;
174  }
175 
176 #if MIMMO_ENABLE_MPI==1
177  }
178 
179  MPI_Finalize();
180 #endif
181 
182  return 0;
183 }
void setLogger(std::string log)
void setGeometry(MimmoSharedPointer< MimmoObject > geo)
void setWriteFileType(FileType type)
void setWriteDir(std::string dir)
void setWriteFilename(std::string filename)
bitpit::Logger & getLog()
void setPatch(MimmoSharedPointer< MimmoObject > geo)
void setReadFilename(std::string filename)
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
Executable block class capable of projecting a surface patch, 3DCurve or PointCloud on a 3D surface,...
MimmoSharedPointer< MimmoObject > getProjectedElement()
void setReadFileType(FileType type)
MimmoSharedPointer< MimmoObject > getGeometry()
void setReadDir(std::string dir)