manipulators_example_00004.cpp
Example of usage of free form deformation Lattice to manipulate an input geometry.Using: MimmoGeometry, FFDLattice , GenericInput, GenericOutput, Apply, Chain.
To run : ./manipulators_example_00004
To run (MPI version): mpirun -np X manipulators_example_00004
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_manipulators.hpp"
#include "mimmo_iogeneric.hpp"
#include <bitpit_common.hpp>
#include <random>
// =================================================================================== //
void test00004() {
/*
Read a sphere from STL file. Convert mode is to save the just read geometry in
another file with name manipulators_output_00004.0000.stl
*/
mimmo0->setReadFileType(FileType::STL);
mimmo0->setWriteFileType(FileType::STL);
/*
write the deformed geometry to file
*/
mimmo1->setWriteDir(".");
mimmo1->setWriteFileType(FileType::STL);
mimmo1->setWriteFilename("manipulators_output_00004.0001");
/*
Instantiation of a FFDobject with spherical shape.
Setup of sphere dimensions and number of lattice nodes/nurbs degrees
for each spherical coordinate.
*/
darray3E origin = {0.0, 0.0,0.0};
darray3E span;
span[0]= 3.01;
span[1]= 2*BITPIT_PI;
span[2]= BITPIT_PI;
/* Set number of nodes of the mesh (dim) and degree of nurbs functions (deg).
*/
iarray3E dim, deg;
dim[0] = 30;
dim[1] = 30;
dim[2] = 30;
deg[0] = 2;
deg[1] = 2;
deg[2] = 2;
/*
Change reference system to work in local spherical coordinates.
Set coordinates as CLAMPED (continuity in origins of angles).
*/
/*
Build mesh of lattice outside the execution chain
to use it during setup the displacements.
*/
lattice->build();
/* Creation of displacements for control nodes of the lattice.
* Use random values to set the displacements of the control nodes at a longitude
* angle smaller than PI and expansion on radius direction for nodes with longitude
* angle greater than PI.
* As exercise GenericInput/Output blocks are used to write them down to file
*/
std::minstd_rand rgen;
rgen.seed(16);
double distRand = (rgen.max()-rgen.min());
for (int i=0; i<ndeg; i++){
int l1,l2,l3;
lattice->accessPointIndex(index,l1,l2,l3);
displ[i][0] = 1.0*( double( rgen() - rgen.min() ) / distRand );
}
if( (l1 > 0 && lattice->getLocalPoint(l1,l2,l3)[1] >= BITPIT_PI)
|| lattice->getLocalPoint(l1,l2,l3)[1] == 0){
displ[i][0] = 1.25;
}
}
/*
Set Generic input block with the
displacements defined above.
*/
input->setInput(displ);
/*
Set Generic output block to write the
displacements defined above.
*/
/*
Create applier block.
It applies the deformation displacements to the original input geometry.
*/
/*
Setup pin connections.
*/
/*
Setup execution chain.
*/
mimmo::Chain ch0;
ch0.addObject(input);
ch0.addObject(output);
ch0.addObject(applier);
ch0.addObject(lattice);
ch0.addObject(mimmo1);
ch0.addObject(mimmo0);
/* Execute the chain.
* Use debug flag false to avoid printing intermediate results of the execution steps.
*/
/*
Clean up & exit;
*/
delete lattice;
delete applier;
delete input;
delete output;
delete mimmo0;
delete mimmo1;
return;
}
int main( int argc, char *argv[] ) {
BITPIT_UNUSED(argc);
BITPIT_UNUSED(argv);
#if MIMMO_ENABLE_MPI
MPI_Init(&argc, &argv);
#endif
try{
test00004() ;
}
catch(std::exception & e){
std::cout<<"manipulators_example_00004 exited with an error of type : "<<e.what()<<std::endl;
return 1;
}
#if MIMMO_ENABLE_MPI
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
Apply is the class that applies the deformation resulting from a manipulation object to the geometry.
Definition: Apply.hpp:89
void setRefSystem(darray3E, darray3E, darray3E)
Definition: BasicMeshes.cpp:619
void setWriteFileType(FileType type)
Definition: MimmoGeometry.cpp:230
void setFilename(std::string filename)
Definition: GenericOutput.cpp:134
int accessPointIndex(int i, int j, int k)
Definition: BasicMeshes.hpp:204
void setInput(T *data)
GENERICINPUT////////////////////////////////////////////////////////////////////////////.
Definition: GenericInput.tpp:209
void setWriteFilename(std::string filename)
Definition: MimmoGeometry.cpp:268
GenericOutput is the class that write generic data in a file output.
Definition: GenericOutput.hpp:109
GenericInput is the class that set the initialization of a generic input data.
Definition: GenericInput.hpp:110
void setReadFilename(std::string filename)
Definition: MimmoGeometry.cpp:221
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
void setLattice(darray3E &origin, darray3E &span, ShapeType, iarray3E &dimensions, iarray3E °rees)
Definition: FFDLattice.cpp:316
@ SPHERE
void setPlotInExecution(bool)
Definition: BaseManipulation.cpp:443
@ CLAMPED
void setReadFileType(FileType type)
Definition: MimmoGeometry.cpp:192
Free Form Deformation of a 3D surface and point clouds, with structured lattice.
Definition: FFDLattice.hpp:133