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() {
/*
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->setReadFileType(FileType::STL);
mimmo0->setWriteFileType(FileType::SURFVTU);
#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}});
/*
Calculate AABB of the Mirrored RBF set accounting for the current support
radius chosen. Mirrored points are passed through port connection.
*/
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->setPlotInExecution(true);
/*
Get deformation on the box selected surface with the current RBF mirrored set,
but not apply it yet.
*/
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
*/
#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
#else
//read target geometry and distribute it to the other subblocks
#endif
//passing mirrored pc to rbfbox
//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
// pass the reconstructed deformation to applier
#if MIMMO_ENABLE_MPI
//add serialization
#endif
/* Setup execution chain.
*/
mimmo::Chain ch0;
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.
*/
//Last step write deformed original geometry in vtu
#if MIMMO_ENABLE_MPI
serialize->getGeometry()->getPatch()->write("utils_mesh_00003.0001");
#else
#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
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;
}
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.
Definition: MimmoObject.hpp:143
Apply is the class that applies the deformation resulting from a manipulation object to the geometry.
Definition: Apply.hpp:89
void setWriteFileType(FileType type)
Definition: MimmoGeometry.cpp:230
void setWriteFilename(std::string filename)
Definition: MimmoGeometry.cpp:268
SpecularPoints is a class that mirrors a point cloud w.r.t. a reference plane, on a target surface ge...
Definition: SpecularPoints.hpp:91
ControlDeformMaxDistance is a class that check a deformation field associated to a MimmoObject surfac...
Definition: ControlDeformMaxDistance.hpp:84
void setReadFilename(std::string filename)
Definition: MimmoGeometry.cpp:221
void setLimitDistance(double dist)
Definition: ControlDeformMaxDistance.cpp:156
bool addPin(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR, bool forced)
Definition: MimmoNamespace.cpp:68
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
Definition: MimmoGeometry.hpp:151
Reconstruct a vector field from daughter mesh to mother mesh.
Definition: ReconstructFields.hpp:188
void setPointCloud(MimmoSharedPointer< MimmoObject > targetpatch)
Definition: SpecularPoints.cpp:250
@ POINT
void setVectorData(dmpvecarr3E *vdata)
Definition: SpecularPoints.cpp:274
void setPlotInExecution(bool)
Definition: BaseManipulation.cpp:443
void setReadFileType(FileType type)
Definition: MimmoGeometry.cpp:192
MimmoSharedPointer< MimmoObject > getGeometry()
Definition: BaseManipulation.cpp:235