genericinput_example_00003.cpp
1 /*---------------------------------------------------------------------------*\
2  *
3  * mimmo
4  *
5  * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6  *
7  * -------------------------------------------------------------------------
8  * License
9  * This file is part of mimmo.
10  *
11  * mimmo is free software: you can redistribute it and/or modify it
12  * under the terms of the GNU Lesser General Public License v3 (LGPL)
13  * as published by the Free Software Foundation.
14  *
15  * mimmo is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18  * License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with mimmo. If not, see <http://www.gnu.org/licenses/>.
22  *
23  \ *---------------------------------------------------------------------------*/
24 
25 #include "mimmo_iogeneric.hpp"
26 #include "FFDLattice.hpp"
27 
42 // =================================================================================== //
43 
44 
45 void test00003() {
46 
47  /*
48  Read and Write a STL geometry of a plane
49  */
51  read->setReadDir("geodata");
52  read->setReadFilename("plane4");
53  read->setReadFileType(FileType::STL);
54  read->setWriteDir(".");
55  read->setWriteFilename("./genericinput_output_00003.0001");
56  read->setWriteFileType(FileType::SURFVTU);
57 
58  /*
59  Creating a FFDLattice manipulator of dimension 3x2x2 around a box centered in 0,0,-0.5
60  with span 2,2,1
61  */
62  mimmo::FFDLattice * latt = new mimmo::FFDLattice();
63  latt->setName("genericinput_example_00003_Lattice");
65  latt->setOrigin({{0.0,0.0,-0.5}});
66  latt->setSpan({{2.0,2.0,1.0}});
67  latt->setDimension(iarray3E({{3,2,2}}));
68  latt->setDegrees(iarray3E{2,1,1});
69  latt->build();
70  latt->setPlotInExecution(true);
71  latt->setApply(true); // when chain executed, this will apply directly deformation onto the target mesh
72 
73  /*
74  Create a reader for the displacement file associated to the lattice and
75  available from file
76  */
77  mimmo::GenericDispls * iodispls = new mimmo::GenericDispls(true);
78  iodispls->setReadDir("input");
79  iodispls->setReadFilename("generic_displ_00002.txt");
80 
81  /*
82  Define pin connections between blocks.
83  */
84  mimmo::pin::addPin(read, latt, M_GEOM, M_GEOM);
85  mimmo::pin::addPin(iodispls, latt, M_DISPLS, M_DISPLS);
86 
87  /*
88  Define execution chain.
89  */
90  mimmo::Chain ch0;
91  ch0.addObject(read);
92  ch0.addObject(latt);
93  ch0.addObject(iodispls);
94 
95 
96  /*
97  Execute the chain.
98  Use debug flag true to print out the execution steps.
99  */
100  ch0.exec(true);
101 
102  /*
103  print out the file the deformed geometry
104  */
105  read->getGeometry()->getPatch()->write("./genericinput_output_00003.0002");
106 
107  /* Clean up & exit;
108  */
109  delete read;
110  delete iodispls;
111  delete latt;
112 
113 }
114 
115 // =================================================================================== //
116 
117 int main( int argc, char *argv[] ) {
118 
119  BITPIT_UNUSED(argc);
120  BITPIT_UNUSED(argv);
121 
122 #if MIMMO_ENABLE_MPI
123  MPI_Init(&argc, &argv);
124 #endif
125 
126  try{
127  test00003();
128  }
129  catch(std::exception & e){
130  std::cout<<"genericinput_example_00003 exited with an error of type : "<<e.what()<<std::endl;
131  return 1;
132  }
133 #if MIMMO_ENABLE_MPI
134  MPI_Finalize();
135 #endif
136 
137  return 0;
138 }
void exec(bool debug=false)
Definition: Chain.cpp:284
std::array< int, 3 > iarray3E
void setDimension(ivector1D dim)
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
void setWriteFileType(FileType type)
void setName(std::string name)
void setOrigin(darray3E origin)
void setWriteDir(std::string dir)
void setDegrees(iarray3E curveDegrees)
Definition: FFDLattice.cpp:273
void setShape(ShapeType type=ShapeType::CUBE)
void setWriteFilename(std::string filename)
void setReadFilename(std::string filename)
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...
void setReadFilename(std::string filename)
GenericDispls is the class to read from file an initial set of displacements as a generic vector fiel...
void setSpan(double, double, double)
void setReadFileType(FileType type)
MimmoSharedPointer< MimmoObject > getGeometry()
void setApply(bool flag=true)
void setReadDir(std::string dir)
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()