ioofoam_example_00001.cpp

Example of reading,morphing and writing of a OpenFOAM case mesh. BEWARE: the case is meant for SERIAL version or MPI version running only with 1 processor.PART1 - reading,morphing and writing of a OpenFOAM case mesh.

Mesh is read from an OpenFOAM case. A FFD deformation is applied. The bulk volume mesh is deformed accordingly. In writing, moved bulk points update those on the target mesh.

PART 2 - Example of reading field from a OpenFOAM case mesh

Mesh and its boundary pressure scalar field are read from an OpenFOAM case. The applier get the scalar field and convert it in a vectorfield of geometrical displacements using the local boundary mesh normals. Then apply the displacements to the boundary mesh and save the deformed version in a vtu file.

Using: IOOFOAM, FFDLattice, IOOFOAMScalarField, Apply, Chain

To run: ./ioofoam_example_00001
To run (MPI version): mpirun -np 1 ioofoam_example_00001
Beware: mpi version of the example works only with np=1

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_iogeneric.hpp"
#include "IOOFOAM.hpp"
#include "mimmo_manipulators.hpp"
// =================================================================================== //
void OFOAM_manip() {
/* read a OpenFoam mesh, expose bulk volume and boundary mesh */
mimmo::IOOFOAM * reader = new mimmo::IOOFOAM(false);
reader->setDir("geodata/OFOAM");
/* Define a FFDLattice manipulation shaped as a box. Default dimension are 2x2x2 */
/* set up origin and span of the lattice box */
darray3E origin = {{0.367, 0., 0.}};
darray3E span = {{0.2, 0.1, 0.1}};
/* define displacements of the lattice nodes */
dvecarr3E displ(12,{{0.0,0.0,0.0}});
displ[4][1] = 0.045;
displ[5][1] = 0.045;
displ[6][1] = -0.045;
displ[7][1] = -0.045;
ffd->setOrigin(origin);
ffd->setSpan(span);
ffd->setDimension(ivector1D({{3,2,2}}));
ffd->setDegrees(iarray3E({{2,2,2}}));
ffd->setDisplacements(displ);
ffd->setPlotInExecution(true);
/* Define Apply block to apply deformation field from ffd to the target volume mesh*/
mimmo::Apply * applier = new mimmo::Apply();
/* In the same openfoam case folder, the block will write the new modified vertices only*/
mimmo::IOOFOAM * writer = new mimmo::IOOFOAM(true);
writer->setDir("geodata/OFOAM");
writer->setWritePointsOnly(true);
writer->setOverwrite(false);
/* define block connections */
/*Define chain */
c0.addObject(reader);
c0.addObject(ffd);
c0.addObject(applier);
c0.addObject(writer);
c0.exec(true);
/*clean up */
delete reader;
delete ffd;
delete applier;
delete writer;
}
// =================================================================================== //
void OFOAM_sensi() {
/* read a OpenFoam mesh, expose bulk volume and boundary mesh */
mimmo::IOOFOAM * reader = new mimmo::IOOFOAM(false);
reader->setDir("geodata/OFOAM");
/* read a scalar field p, defined onto the OpenFoam boundary mesh */
mimmo::IOOFOAMScalarField * fieldreader = new mimmo::IOOFOAMScalarField(false);
fieldreader->setDir("geodata/OFOAM");
fieldreader->setFieldName("p");
/*
Create apply block. Use p field to define a "deformation field" onto the surface
boundary mesh and using the surface normals. Scaling is used to
globally modulate the p value */
mimmo::Apply * applier = new mimmo::Apply();
applier->setScaling(0.1);
/*
Write the modified boundary mesh to vtu file
*/
writer->setWriteDir(".");
writer->setWriteFileType(FileType::SURFVTU);
writer->setWriteFilename("ofoam_sensi_output");
/* Define block pin connections */
mimmo::pin::addPin(reader, fieldreader, M_UMAPIDS, M_UMAPIDS);
mimmo::pin::addPin(applier, writer, M_GEOM, M_GEOM);
/* Define the execution chain*/
c0.addObject(reader);
c0.addObject(fieldreader);
c0.addObject(applier);
c0.addObject(writer);
c0.exec(true);
/*Clean up */
delete reader;
delete fieldreader;
delete applier;
delete writer;
}
// =================================================================================== //
int main( int argc, char *argv[] ) {
BITPIT_UNUSED(argc);
BITPIT_UNUSED(argv);
#if MIMMO_ENABLE_MPI
MPI_Init(&argc, &argv);
#endif
try{
OFOAM_sensi() ;
}
catch(std::exception & e){
std::cout<<"test_ioofoam_00001 PART1 exit with the following errors :"<<e.what()<<std::endl;
return 1;
}
try{
OFOAM_manip() ;
}
catch(std::exception & e){
std::cout<<"test_ioofoam_00001 PART2 exit with the following errors :"<<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
#define M_UMAPIDS
void setDimension(ivector1D dim)
#define M_GEOMOFOAM
Chain is the class used to manage the chain execution of multiple executable blocks (manipulation obj...
Definition: Chain.hpp:48
#define M_GEOM
Apply is the class that applies the deformation resulting from a manipulation object to the geometry.
Definition: Apply.hpp:89
std::vector< darray3E > dvecarr3E
void setDisplacements(dvecarr3E displacements)
Definition: FFDLattice.cpp:284
void setScaling(double alpha)
Definition: Apply.cpp:158
void setWriteFileType(FileType type)
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)
std::vector< int > ivector1D
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...
#define M_SCALARFIELD
std::array< double, 3 > darray3E
void setSpan(double, double, double)
#define M_SCALARFIELD2
Free Form Deformation of a 3D surface and point clouds, with structured lattice.
Definition: FFDLattice.hpp:133
#define M_GEOMOFOAM2
int addObject(BaseManipulation *obj, int id_=-1)
Definition: Chain.cpp:170