utils_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_utils.hpp"
26 #if MIMMO_ENABLE_MPI
27  #include "Partition.hpp"
28 #endif
29 // =================================================================================== //
47 void test00001() {
48 
49  /*
50  Read a target polygonal mesh from file. CONVERT option will let the block to write
51  the just read file in another file, immediately after the reading.
52  */
54  bitpit::Logger & log = mimmo0->getLog();
55  log.setPriority(bitpit::log::Priority::NORMAL);
56 
57  mimmo0->setReadDir("geodata");
58  mimmo0->setReadFileType(FileType::SURFVTU);
59  mimmo0->setReadFilename("mixedP2D");
60 
61  mimmo0->setWriteDir(".");
62  mimmo0->setWriteFileType(FileType::SURFVTU);
63  mimmo0->setWriteFilename("utils_mesh_00001.0000");
64 
65  mimmo0->exec();
66  log<<"Reading and converting the initial mesh"<<std::endl;
67 
68 
70 
71 #if MIMMO_ENABLE_MPI
72  /*
73  Distribute the mesh among the processes
74  */
75  mimmo::Partition * part = new mimmo::Partition();
76  part->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
77  part->setGeometry(mimmo0->getGeometry());
78  part->setPlotInExecution(true);
79  part->exec();
80 
81  log<<"Partitioning the initial mesh"<<std::endl;
82 
83  target = part->getGeometry();
84 #else
85  target = mimmo0->getGeometry();
86 #endif
87 
88  /*
89  Create a custom sensitivity field on target points
90  use a linear decay in spherical coordinates from center 0.5,0.5,0.
91  */
93  sensitivity.initialize(target, mimmo::MPVLocation::POINT, 1.);
94 
95  darray3E center({{0.5,0.5,0}});
96  {
97  darray3E pMin,pMax;
98  target->getBoundingBox(pMin, pMax, true);
99  double maxD = norm2(pMax-pMin)/3.;
100  double localvalue;
101  for(bitpit::Vertex & v : target->getVertices()){
102  localvalue = norm2(v.getCoords() - center);
103  if(localvalue < maxD){
104  sensitivity[v.getId()] += -1.0*localvalue/maxD;
105  }else{
106  sensitivity[v.getId()] = 0.0;
107  }
108  }
109  }
110  log<<"Creating artificial sensitivity"<<std::endl;
111 
112 
113  /*
114  Creation of the seeder. Use Level set engine to place 9 points on
115  surface, starting from a seed point in the absolute origin.
116  */
118  cseed->setSeed(center);
119  cseed->setNPoints(20);
120  cseed->setSensitivityMap(&sensitivity);
121  cseed->setEngine(0);
122  cseed->setRandomFixed(true);
123  cseed->setRandomSignature(1599826209);
124  cseed->setPlotInExecution(true);
125  cseed->setGeometry(target);
126 
127  cseed->exec();
128 
129  log<<"Seeding points on surface mesh"<<std::endl;
130 
131  /*
132  plot on screen the id to reproduce random distribution if a Random engine
133  is selected into cseed block.
134  */
135  if(cseed->getEngineENUM() == mimmo::CSeedSurf::RANDOM){
136  log<<"utils_example_0001: Random seeder used signature : "<<cseed->getRandomSignature()<<std::endl;
137  }
138 
139  /*
140  Clean up & exit;
141  */
142  delete mimmo0;
143  delete cseed;
144 #if MIMMO_ENABLE_MPI
145  delete part;
146 #endif
147  return;
148 
149 }
150 
151 
152 int main(int argc, char *argv[]) {
153 
154  BITPIT_UNUSED(argc);
155  BITPIT_UNUSED(argv);
156 
157 #if MIMMO_ENABLE_MPI==1
158  MPI_Init(&argc, &argv);
159 
160  {
161 #endif
162 
164  try{
165  test00001() ;
166  }
167  catch(std::exception & e){
168  std::cout<<"utils_example_00001 exited with an error of type : "<<e.what()<<std::endl;
169  return 1;
170  }
171 
172 #if MIMMO_ENABLE_MPI==1
173  }
174 
175  MPI_Finalize();
176 #endif
177 
178  return 0;
179 }
void setWriteFileType(FileType type)
void setWriteDir(std::string dir)
void setRandomSignature(uint32_t signature)
void setWriteFilename(std::string filename)
void setSensitivityMap(dmpvector1D *field)
bitpit::Logger & getLog()
void setReadFilename(std::string filename)
Distribute a raw list of points on a target 3D surface.
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
void initialize(MimmoSharedPointer< MimmoObject >, MPVLocation, const mpv_t &)
std::array< double, 3 > darray3E
void setReadFileType(FileType type)
void setGeometry(MimmoSharedPointer< MimmoObject >)
MimmoSharedPointer< MimmoObject > getGeometry()
void setReadDir(std::string dir)