utils_example_00003.cpp

Deform a sphere using a set of mirrored RBF points. Check for collisions of the deformed object with the D=0.25 level-set isolevel of the original geometry.Using: MimmoGeometry, SpecularPoints, RBFBox, SelectionByBox, MRBF, ReconstructVector, ControlDeformMaxDistance, Apply, Chain, Partition(MPI version)

To run : ./utils_example_00003
To run (MPI version): mpirun -np X utils_example_00003
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_utils.hpp"
#include "MeshSelection.hpp"
#include "ReconstructFields.hpp"
#include "MRBF.hpp"
#include "Apply.hpp"
#if MIMMO_ENABLE_MPI
#include "Partition.hpp"
#endif
// =================================================================================== //
void test00003() {
mimmo::setExpertMode(true); // avoid control of unlinked ports.
/*
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("converterGeometry");
mimmo0->setReadDir("geodata");
mimmo0->setReadFileType(FileType::STL);
mimmo0->setReadFilename("sphere2");
mimmo0->setWriteDir(".");
mimmo0->setWriteFileType(FileType::SURFVTU);
mimmo0->setWriteFilename("utils_mesh_00003.0000");
#if MIMMO_ENABLE_MPI
/*
Distribute target mesh among processes.
*/
mimmo::Partition* partitioner = new mimmo::Partition();
partitioner->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
partitioner->setName("mimmo.Partitioner");
partitioner->setPlotInExecution(true);
#endif
//declare a support Radius for RBF cloud
double suppR = 0.2;
//create manually a RBF cloud with a set of displacements attached.
#if MIMMO_ENABLE_MPI
if(rbfPointCloud->getRank() == 0)
{
#endif
//create 4 points on a y-plane at {{0.0,-0.6,0.0}}
rbfPointCloud->addVertex({{0.0,-0.6,0.0}}, 0);
rbfPointCloud->addVertex({{-0.1,-0.6,0.0}}, 1);
rbfPointCloud->addVertex({{0.1,-0.6,0.12}}, 2);
rbfPointCloud->addVertex({{-0.03,-0.6,-0.1}}, 3);
rbfPointCloud->addConnectedCell(std::vector<long>(1,0), bitpit::ElementType::VERTEX, 0, 10, 0);
rbfPointCloud->addConnectedCell(std::vector<long>(1,1), bitpit::ElementType::VERTEX, 0, 11, 0);
rbfPointCloud->addConnectedCell(std::vector<long>(1,2), bitpit::ElementType::VERTEX, 0, 12, 0);
rbfPointCloud->addConnectedCell(std::vector<long>(1,3), bitpit::ElementType::VERTEX, 0, 13, 0);
// insert displacements for POINTS
rbfDispls.insert(0, {{0.0,-0.2,0.0}});
rbfDispls.insert(1, {{-0.6,-0.2,0.0}});
rbfDispls.insert(2, {{0.16,-0.2,0.4}});
rbfDispls.insert(3, {{-0.4,-0.2,-0.18}});
#if MIMMO_ENABLE_MPI
}
rbfPointCloud->cleanPatchInfo();
rbfPointCloud->updateAdjacencies();
rbfPointCloud->update();
#endif
/*
Project onto surface and mirror these rbf points with their displacements attached
w.r.t. the y plane crossing the origin
*/
spec->setName("MirroringRBF");
spec->setPointCloud(rbfPointCloud);
spec->setVectorData(&rbfDispls);
spec->setOrigin({{0.0,0.0,0.0}});
spec->setNormal({{0.0,1.0,0.0}});
spec->setInsideOut(true);
spec->setForce(false);
spec->setPlotInExecution(true);
/*
Calculate AABB of the Mirrored RBF set accounting for the current support
radius chosen. Mirrored points are passed through port connection.
*/
mimmo::RBFBox * rbfbox = new mimmo::RBFBox();
rbfbox->setName("AABB_RBFBox");
rbfbox->setSupportRadius(suppR);
rbfbox->setPlotInExecution(true);
/*
Use RBFBox to provide a sub-selection of the original geometry.
Origin and span of RBFBox AABB are provided through ports.
*/
sel->setName("RBFBoxSelection");
sel->setDual(false);
sel->setPlotInExecution(true);
/*
Get deformation on the box selected surface with the current RBF mirrored set,
but not apply it yet.
*/
mimmo::MRBF * manip = new mimmo::MRBF();
manip->setName("RBFManipulator");
manip->setSupportRadiusReal(suppR);
/*
Reconstruct the deformation field on the whole body
*/
recon->setName("ReconstructDeformation");
recon->setPlotInExecution(true);
/*
Verify actual geometry deformation vs the original geometry
level-set isolevel at d=0.14. Get the max penetration value on file.
Original geometry and its to-check deformation are passed through ports
*/
isolevelCheck->setName("IsoLevelCheckCollision");
isolevelCheck->setLimitDistance(0.5);
isolevelCheck->setPlotInExecution(true);
/*
Apply deformation to the original geometry
*/
mimmo::Apply * applier = new mimmo::Apply();
#if MIMMO_ENABLE_MPI
/*
Serialize the final deformed mesh
*/
mimmo::Partition* serialize = new mimmo::Partition();
serialize->setName("mimmo.Serialization");
serialize->setPlotInExecution(false);
serialize->setPartitionMethod(mimmo::PartitionMethod::SERIALIZE);
#endif
/* Setup pin connections.
*/
// original geometry passed to spec
#if MIMMO_ENABLE_MPI
//read target geometry, partition it and distribute it to the other subblocks
mimmo::pin::addPin(mimmo0, partitioner, M_GEOM, M_GEOM);
mimmo::pin::addPin(partitioner, spec, M_GEOM, M_GEOM);
mimmo::pin::addPin(partitioner, sel, M_GEOM, M_GEOM);
mimmo::pin::addPin(partitioner, recon, M_GEOM, M_GEOM);
mimmo::pin::addPin(partitioner, isolevelCheck, M_GEOM, M_GEOM);
mimmo::pin::addPin(partitioner, applier, M_GEOM, M_GEOM);
#else
//read target geometry and distribute it to the other subblocks
mimmo::pin::addPin(mimmo0, spec, M_GEOM, M_GEOM);
mimmo::pin::addPin(mimmo0, recon, M_GEOM, M_GEOM);
mimmo::pin::addPin(mimmo0, isolevelCheck, M_GEOM, M_GEOM);
mimmo::pin::addPin(mimmo0, applier, M_GEOM, M_GEOM);
#endif
//passing mirrored pc to rbfbox
mimmo::pin::addPin(spec, rbfbox, M_GEOM, M_GEOM);
//passing box dimension from rbfbox to box selection
// manip get as working geometry the selected patch of sel.
// rbf point cloud and displacements are provided by spec
//pass the deformation field of manip to reconstructor
//pass the reconstructed deformation field to isolevelCheck
mimmo::pin::addPin(recon, isolevelCheck, M_VECTORFIELD, M_GDISPLS);
// pass the reconstructed deformation to applier
#if MIMMO_ENABLE_MPI
//add serialization
mimmo::pin::addPin(applier, serialize, M_GEOM, M_GEOM);
#endif
/* Setup execution chain.
*/
ch0.addObject(mimmo0);
ch0.addObject(manip);
ch0.addObject(spec);
ch0.addObject(rbfbox);
ch0.addObject(sel);
ch0.addObject(recon);
ch0.addObject(isolevelCheck);
ch0.addObject(applier);
#if MIMMO_ENABLE_MPI
ch0.addObject(partitioner);
ch0.addObject(serialize);
#endif
/* Execute the chain.
* Use debug flag false to avoid to print out the execution steps on console.
*/
ch0.exec(true);
//Last step write deformed original geometry in vtu
#if MIMMO_ENABLE_MPI
serialize->getGeometry()->getPatch()->write("utils_mesh_00003.0001");
#else
mimmo0->getGeometry()->getPatch()->write("utils_mesh_00003.0001");
#endif
/* Clean up & exit;
*/
delete mimmo0;
delete spec;
delete rbfbox;
delete sel;
delete manip;
delete recon;
delete isolevelCheck;
delete applier;
#if MIMMO_ENABLE_MPI
delete partitioner;
delete serialize;
#endif
return;
}
int main(int argc, char *argv[]) {
BITPIT_UNUSED(argc);
BITPIT_UNUSED(argv);
#if MIMMO_ENABLE_MPI==1
MPI_Init(&argc, &argv);
{
#endif
mimmo::setLogger("mimmo");
try{
test00003() ;
}
catch(std::exception & e){
std::cout<<"utils_example_00003 exited with an error of type : "<<e.what()<<std::endl;
return 1;
}
#if MIMMO_ENABLE_MPI==1
}
MPI_Finalize();
#endif
return 0;
}
void setInsideOut(bool flag)
void exec(bool debug=false)
Definition: Chain.cpp:284
void setLogger(std::string log)
#define M_GDISPLS
Chain is the class used to manage the chain execution of multiple executable blocks (manipulation obj...
Definition: Chain.hpp:48
MimmoObject is the basic geometry container for mimmo library.
#define M_GEOM
Apply is the class that applies the deformation resulting from a manipulation object to the geometry.
Definition: Apply.hpp:89
void setSupportRadiusReal(double suppR_)
Definition: MRBF.cpp:436
void setWriteFileType(FileType type)
void setName(std::string name)
void setSupportRadius(double suppR_)
Definition: RBFBox.cpp:153
void setWriteDir(std::string dir)
#define M_GEOM2
#define M_POINT
void setWriteFilename(std::string filename)
Radial Basis Functions Bounding Box calculator.
Definition: RBFBox.hpp:74
#define M_VECTORFIELD
SpecularPoints is a class that mirrors a point cloud w.r.t. a reference plane, on a target surface ge...
ControlDeformMaxDistance is a class that check a deformation field associated to a MimmoObject surfac...
void setReadFilename(std::string filename)
#define M_SPAN
bool addPin(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR, bool forced)
void setOrigin(darray3E origin)
Selection through volume box primitive.
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
Reconstruct a vector field from daughter mesh to mother mesh.
void setPointCloud(MimmoSharedPointer< MimmoObject > targetpatch)
void setVectorData(dmpvecarr3E *vdata)
void setDual(bool flag=false)
void setExpertMode(bool flag)
Radial Basis Function evaluation from clouds of control points.
Definition: MRBF.hpp:146
void setForce(bool flag)
void setReadFileType(FileType type)
MimmoSharedPointer< MimmoObject > getGeometry()
void setReadDir(std::string dir)
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170
void setNormal(darray3E normal)