geohandlers_example_00001.cpp

Example of usage of selection and refinement of a target geometry sub-patch.Using: MimmoGeometry, SelectionByBox, SelectionBySphere, RefineGeometry, Chain, Partition (only MPI ).

To run : ./geohandlers_example_00001
To run (MPI Version): mpirun -np X geohandlers_example_00001
visit: mimmo website

/*---------------------------------------------------------------------------*\
*
* mimmo
*
* Copyright (C) 2015-2021 OPTIMAD engineering Srl
*
* -------------------------------------------------------------------------
* License
* This file is part of mimmo.
*
* mimmo is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License v3 (LGPL)
* as published by the Free Software Foundation.
*
* mimmo is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with mimmo. If not, see <http://www.gnu.org/licenses/>.
*
\ *---------------------------------------------------------------------------*/
#include "mimmo_geohandlers.hpp"
#if MIMMO_ENABLE_MPI
#include "mimmo_parallel.hpp"
#endif
#include <bitpit_common.hpp>
// =================================================================================== //
// =================================================================================== //
void test00001() {
/*
Read a target geometry from file. CONVERT option will let the block to write
the just read file in another file, immediately after the reading.
*/
mimmo0->setName("mimmo0");
mimmo0->setReadDir("./geodata");
mimmo0->setReadFileType(FileType::STL);
mimmo0->setReadFilename("sphere2");
mimmo0->setWriteDir("./");
mimmo0->setWriteFileType(FileType::STL);
mimmo0->setWriteFilename("geohandlers_output_00001.0000");
/*
Write a geometry to file
*/
mimmo1->setWriteDir(".");
mimmo1->setWriteFileType(FileType::SURFVTU);
mimmo1->setWriteFilename("geohandlers_output_00001.0001");
/*
Write a geometry to file
*/
mimmo2->setWriteDir(".");
mimmo2->setWriteFileType(FileType::SURFVTU);
mimmo2->setWriteFilename("geohandlers_output_00001.0002");
#if MIMMO_ENABLE_MPI
/*
Distribute a target mesh geometry among processors
*/
mimmo::Partition* partition = new mimmo::Partition();
partition->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
partition->setPlotInExecution(true);
#endif
/*
Select a portion of geometry incapsulated inside a Box/Cube.
Span and origin of the box are needed.
*/
boxSel->setOrigin({{-0.5,-0.5,0.2}});
boxSel->setSpan(0.6,0.6,0.6);
/*
Select a portion of geometry incapsulated inside a Sphere.
Radius, angular spans and origin of the sphere are needed.
*/
sphSel->setOrigin({{-0.5, 0.5,0.2}});
sphSel->setSpan(0.34, 2*BITPIT_PI, BITPIT_PI);
/*
Block to refine triangles of a target mesh
Refine Engine type and number of refinement steps are needed.
Smoothing steps >0 activate a n-steps procedure to attempt smoothing/regularizing
the final refined mesh.
*/
refine->setRefineSteps(2);
refine->setSmoothingSteps(1);
/*
Define block pin connections.
*/
#if MIMMO_ENABLE_MPI
mimmo::pin::addPin(mimmo0, partition, M_GEOM, M_GEOM);
mimmo::pin::addPin(partition, boxSel, M_GEOM, M_GEOM);
mimmo::pin::addPin(partition, sphSel, M_GEOM, M_GEOM);
#else
mimmo::pin::addPin(mimmo0, boxSel, M_GEOM, M_GEOM);
mimmo::pin::addPin(mimmo0, sphSel, M_GEOM, M_GEOM);
#endif
mimmo::pin::addPin(boxSel, refine, M_GEOM, M_GEOM);
mimmo::pin::addPin(refine, mimmo1, M_GEOM, M_GEOM);
mimmo::pin::addPin(sphSel, mimmo2, M_GEOM, M_GEOM);
/*
Setup execution chain.
*/
ch0.addObject(mimmo0);
#if MIMMO_ENABLE_MPI
ch0.addObject(partition);
#endif
ch0.addObject(boxSel);
ch0.addObject(refine);
ch0.addObject(sphSel);
ch0.addObject(mimmo1);
ch0.addObject(mimmo2);
/*
Execute the chain.
Use debug flag true to to print out the execution steps.
*/
ch0.exec(true);
/*
Clean up & exit;
*/
delete boxSel;
delete sphSel;
delete mimmo0;
#if MIMMO_ENABLE_MPI
delete partition;
#endif
delete refine;
delete mimmo1;
delete mimmo2;
return;
}
// =================================================================================== //
int main( int argc, char *argv[] ) {
BITPIT_UNUSED(argc);
BITPIT_UNUSED(argv);
#if MIMMO_ENABLE_MPI
MPI_Init(&argc, &argv);
#endif
try{
test00001();
}
catch(std::exception & e){
std::cout<<"geohandlers_example_00001 exited with an error of type : "<<e.what()<<std::endl;
return 1;
}
#if MIMMO_ENABLE_MPI
MPI_Finalize();
#endif
return 0;
}
void setOrigin(darray3E)
void exec(bool debug=false)
Definition: Chain.cpp:284
Chain is the class used to manage the chain execution of multiple executable blocks (manipulation obj...
Definition: Chain.hpp:48
#define M_GEOM
void setSmoothingSteps(int steps)
void setWriteFileType(FileType type)
void setName(std::string name)
void setWriteDir(std::string dir)
void setWriteFilename(std::string filename)
void setRefineType(RefineType type)
void setReadFilename(std::string filename)
void setRefineSteps(int steps)
Selection through sphere primitive.
bool addPin(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR, bool forced)
Selection through volume box primitive.
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
RefineGeometry is an executable block class capable of refine a surface geometry.
void setReadFileType(FileType type)
void setSpan(double, double, double)
void setReadDir(std::string dir)
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170