manipulators_example_00003.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_00003
To run (MPI version): mpirun -np X manipulators_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_manipulators.hpp"
#include "mimmo_iogeneric.hpp"
#include <bitpit_common.hpp>
// =================================================================================== //
void test00003() {
/*
Read a pipe from STL file. Convert mode is to save the just read geometry in
another file with name manipulators_output_00003.0000.stl
*/
mimmo0->setReadDir("geodata");
mimmo0->setReadFileType(FileType::STL);
mimmo0->setReadFilename("catpipe");
mimmo0->setWriteDir(".");
mimmo0->setWriteFileType(FileType::STL);
mimmo0->setWriteFilename("manipulators_output_00003.0000");
/*
write the deformed geometry to file
*/
mimmo1->setWriteDir(".");
mimmo1->setWriteFileType(FileType::STL);
mimmo1->setWriteFilename("manipulators_output_00003.0001");
/*
Instantiation of a FFDLattice with cylindrical shape.
Setup of cylinder dimensions and number of lattice nodes/nurbs degrees
for each cylindrical coordinate.
Plot Optional results during execution active for FFD block.
*/
darray3E origin = {-1537.5, -500.0, 3352.5};
darray3E span;
span[0]= 100.0;
span[1]= 2*BITPIT_PI;
span[2]= 1000.0;
/*
Set number of nodes of the mesh (dim) and degree of nurbs functions (deg).
*/
iarray3E dim, deg;
dim[0] = 2;
dim[1] = 15;
dim[2] = 20;
deg[0] = 1;
deg[1] = 2;
deg[2] = 10;
lattice->setLattice(origin,span,mimmo::ShapeType::CYLINDER,dim, deg);
/*
Change reference system to work in local cylindrical coordinates.
*/
lattice->setRefSystem(2, darray3E{0,-1,0});
lattice->setDisplGlobal(false);
lattice->setPlotInExecution(true);
/*
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 a polynomial law in local coordinates to define the displacements.
* The used expression guarantees the continuity of the surface at the interface
* between deformed and the undeformed parts.
* As exercise GenericInput/Output blocks are used to write them down to file
*/
int ndof = lattice->getNNodes();
dvecarr3E displ(ndof, darray3E{0,0,0});
int lt = 2*dim[2]/3;
double lx;
double a, b, c, max;
c = 6;
b = -15;
a = 10;
max = 100;
for (int i=0; i<ndof; i++){
int l1,l2,l3;
int index = lattice->accessGridFromDOF(i);
lattice->accessPointIndex(index,l1,l2,l3);
if (l3 < lt && l1 > 0){
lx = double(l3)/double(lt);
displ[i][0] = max*(c*pow(lx,5) + b*pow(lx,4) + a*pow(lx,3));
}
else if (l1 > 0){
displ[i][0] = max;
}
}
/*
Set Generic input block with the
displacements defined above.
*/
input->setReadFromFile(false);
input->setInput(displ);
/*
Set Generic output block to write the
displacements defined above.
*/
output->setFilename("manipulators_output_00003.csv");
output->setCSV(true);
/*
Create applier block.
It applies the deformation displacements to the original input geometry.
*/
mimmo::Apply* applier = new mimmo::Apply();
/*
Setup pin connections.
*/
mimmo::pin::addPin(mimmo0, lattice, M_GEOM, M_GEOM);
mimmo::pin::addPin(mimmo0, applier, M_GEOM, M_GEOM);
mimmo::pin::addPin(lattice, applier, M_GDISPLS, M_GDISPLS);
mimmo::pin::addPin(applier, mimmo1, M_GEOM, M_GEOM);
/*
Setup execution chain.
*/
ch0.addObject(mimmo0);
ch0.addObject(input);
ch0.addObject(output);
ch0.addObject(lattice);
ch0.addObject(applier);
ch0.addObject(mimmo1);
/*
Execute the chain.
Use debug flag false (default) to avoid to to print out the execution steps.
*/
std::cout << " " << std::endl;
std::cout << " --- execution start --- " << std::endl;
ch0.exec();
std::cout << " --- execution done --- " << std::endl;
std::cout << " " << std::endl;
/*
Clean up & exit;
*/
delete applier;
delete lattice;
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{
test00003() ;
}
catch(std::exception & e){
std::cout<<"manipulators_example_00003 exited with an error of type : "<<e.what()<<std::endl;
return 1;
}
#if MIMMO_ENABLE_MPI
MPI_Finalize();
#endif
return 0;
}
void exec(bool debug=false)
Definition: Chain.cpp:284
#define M_GDISPLS
std::array< int, 3 > iarray3E
Chain is the class used to manage the chain execution of multiple executable blocks (manipulation obj...
Definition: Chain.hpp:48
#define M_DISPLS
#define M_GEOM
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)
std::vector< darray3E > dvecarr3E
void setDisplGlobal(bool flag)
Definition: FFDLattice.cpp:298
void setWriteFileType(FileType type)
void setFilename(std::string filename)
void setWriteDir(std::string dir)
int accessPointIndex(int i, int j, int k)
void setInput(T *data)
GENERICINPUT////////////////////////////////////////////////////////////////////////////.
void setWriteFilename(std::string filename)
GenericOutput is the class that write generic data in a file output.
int getNNodes()
Definition: Lattice.cpp:125
GenericInput is the class that set the initialization of a generic input data.
void setReadFilename(std::string filename)
void setCSV(bool csv)
bool addPin(BaseManipulation *objSend, BaseManipulation *objRec, PortID portS, PortID portR, bool forced)
MimmoGeometry is an executable block class wrapping(linking or internally instantiating) a Mimmo Obje...
int accessGridFromDOF(int index)
Definition: Lattice.cpp:183
void setReadFromFile(bool readFromFile)
void setLattice(darray3E &origin, darray3E &span, ShapeType, iarray3E &dimensions, iarray3E &degrees)
Definition: FFDLattice.cpp:316
std::array< double, 3 > darray3E
void setReadFileType(FileType type)
Free Form Deformation of a 3D surface and point clouds, with structured lattice.
Definition: FFDLattice.hpp:133
void setReadDir(std::string dir)
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170
virtual bool build()