utils_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_utils.hpp"
26 #if MIMMO_ENABLE_MPI
27  #include "Partition.hpp"
28 #endif
29 
30 // =================================================================================== //
46 void test00002() {
47 
48  /*
49  reading target stanford Bunny
50  */
52  bitpit::Logger & log = bunny->getLog();
53  bunny->setName("ReaderStanfordBunny");
54  bunny->setReadDir("geodata");
55  bunny->setReadFileType(FileType::STL);
56  bunny->setReadFilename("stanfordBunny2");
57  bunny->exec();
58 
59  //customize the logger output
60  log.setPriority(bitpit::log::Priority::NORMAL);
61  log<<"Target Bunny read"<<std::endl;
62  log.setPriority(bitpit::log::Priority::DEBUG);
63 
64  /*
65  reading constraint inclinedPlane geometry
66  */
68  incplane->setName("ReaderInclinedPlaneConstraint");
69  incplane->setReadDir("geodata");
70  incplane->setReadFileType(FileType::STL);
71  incplane->setReadFilename("inclinedPlane");
72  incplane->exec();
73 
74  log.setPriority(bitpit::log::Priority::NORMAL);
75  log<<"Inclined plane constraint read"<<std::endl;
76  log.setPriority(bitpit::log::Priority::DEBUG);
77 
78 #if MIMMO_ENABLE_MPI
79 
80  /*
81  Partitioner of the bunny -> distribute it among processes.
82  */
83  mimmo::Partition* partbunny = new mimmo::Partition();
84  partbunny->setName("PartitionerBunny");
85  partbunny->setGeometry(bunny->getGeometry());
86  partbunny->setPlotInExecution(true);
87  partbunny->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
88  partbunny->exec();
89 
90  log.setPriority(bitpit::log::Priority::NORMAL);
91  log<<"Target Bunny partitioned"<<std::endl;
92  log.setPriority(bitpit::log::Priority::DEBUG);
93 
94  /*
95  Partitioner of the inclined plane -> distribute it among processes.
96  */
97  mimmo::Partition* partincplane = new mimmo::Partition();
98  partincplane->setName("PartitionerInclinedPlane");
99  partincplane->setGeometry(incplane->getGeometry());
100  partincplane->setPlotInExecution(true);
101  partincplane->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
102  partincplane->exec();
103 
104  log.setPriority(bitpit::log::Priority::NORMAL);
105  log<<"Inclined plane constraint partitioned"<<std::endl;
106  log.setPriority(bitpit::log::Priority::DEBUG);
107 
108 #endif
109 
110  /*
111  Create a dummy deformation field for the target bunny mesh
112  */
113 #if MIMMO_ENABLE_MPI
114  mimmo::MimmoSharedPointer<mimmo::MimmoObject> target = partbunny->getGeometry();
115  mimmo::MimmoSharedPointer<mimmo::MimmoObject> constraint = partincplane->getGeometry();
116 #else
119 #endif
120 
121  mimmo::dmpvecarr3E def;
122  def.initialize(target, mimmo::MPVLocation::POINT, {{0.0,0.0,0.0}});
123 
124  /*
125  Creation of violation/penetration field calculator
126  Please note constraint meshes can be passed as MimmoObjects or
127  can be directly passed as file: in that case the class will parse them.
128  In case of MPI version the parsed result will be retained only on the master rank,.
129  */
131  cdes->setGeometry(target);
132  cdes->addConstraint(constraint);
133  cdes->addConstraintFile("geodata/openBox.stl", FileType::STL);
134  cdes->setDefField(&def);
135  cdes->setTolerance(0.0);
136  cdes->setPlotInExecution(true);
137  cdes->exec();
138 
139  log.setPriority(bitpit::log::Priority::NORMAL);
140  log<<"Violation field calculated"<<std::endl;
141  log.setPriority(bitpit::log::Priority::DEBUG);
142 
143 
144  /* Clean up & exit;
145  */
146  delete bunny;
147  delete incplane;
148  delete cdes;
149 #if MIMMO_ENABLE_MPI
150  delete partbunny;
151  delete partincplane;
152 #endif
153  return;
154 
155 }
156 
157 
158 int main(int argc, char *argv[]) {
159 
160  BITPIT_UNUSED(argc);
161  BITPIT_UNUSED(argv);
162 
163 #if MIMMO_ENABLE_MPI==1
164  MPI_Init(&argc, &argv);
165 
166  {
167 #endif
168 
169  mimmo::setLogger("mimmo");
170 
172  try{
173  test00002() ;
174  }
175  catch(std::exception & e){
176  std::cout<<"utils_example_00002 exited with an error of type : "<<e.what()<<std::endl;
177  return 1;
178  }
179 
180 #if MIMMO_ENABLE_MPI==1
181  }
182 
183  MPI_Finalize();
184 #endif
185 
186  return 0;
187 }
void setLogger(std::string log)
void setName(std::string name)
ControlDeformExtSurface is a class that check a deformation field, associated to a MimmoObject geomet...
bitpit::Logger & getLog()
void setReadFilename(std::string filename)
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
void initialize(MimmoSharedPointer< MimmoObject >, MPVLocation, const mpv_t &)
void addConstraintFile(std::string file, int format)
void addConstraint(MimmoSharedPointer< MimmoObject > constraint)
void setReadFileType(FileType type)
MimmoSharedPointer< MimmoObject > getGeometry()
void setGeometry(MimmoSharedPointer< MimmoObject > target)
void setReadDir(std::string dir)