Newer
Older
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2005-2007 Franjo Juretic
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM 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 General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Description
\*---------------------------------------------------------------------------*/
#include "cartesianMeshGenerator.H"
#include "triSurf.H"
franjo_j@hotmail.com
committed
#include "triSurfacePatchManipulator.H"
#include "demandDrivenData.H"
#include "objectRegistry.H"
#include "Time.H"
#include "meshOctreeCreator.H"
#include "cartesianMeshExtractor.H"
#include "meshSurfaceEngine.H"
#include "meshSurfaceMapper.H"
#include "meshSurfaceEdgeExtractorNonTopo.H"
#include "surfaceMorpherCells.H"
#include "meshOptimizer.H"
#include "meshSurfaceOptimizer.H"
#include "topologicalCleaner.H"
#include "boundaryLayers.H"
#include "renameBoundaryPatches.H"
#include "checkMeshDict.H"
#include "checkCellConnectionsOverFaces.H"
#include "checkIrregularSurfaceConnections.H"
#include "checkNonMappableCellConnections.H"
#include "checkBoundaryFacesSharingTwoEdges.H"
#include "removeCellsInSelectedDomains.H"
//#define DEBUG
//#define DEBUGEnsight
# ifdef DEBUG
#include "writeMeshEnsight.H"
#include "writeMeshFPMA.H"
# endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * Private member functions * * * * * * * * * * * * //
//- create polyMesh from octree boxes
cartesianMeshExtractor cme(*octreePtr_, meshDict_, mesh_);
if( meshDict_.found("decomposePolyhedraIntoTetsAndPyrs") )
{
if( readBool(meshDict_.lookup("decomposePolyhedraIntoTetsAndPyrs")) )
cme.decomposeSplitHexes();
}
# ifdef DEBUG
mesh_.write();
# ifdef DEBUGfpma
writeMeshFPMA(mesh_, "cartesianMesh");
# elif DEBUGEnsight
writeMeshEnsight(mesh_, "cartesianMesh");
# endif
//::exit(EXIT_FAILURE);
# endif
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//- remove cells inside the domains specified by the user
if( meshDict_.found("removeDomains") )
{
if( Pstream::parRun() )
{
WarningIn
(
"void cartesianMeshGenerator::surfacePreparation()"
) << "The feature removeDomains is not availabel for MPI runs"
<< exit(FatalError);
}
const dictionary& dict = meshDict_.subDict("removeDomains");
const wordList domainNames = dict.toc();
mesh_.clearAddressingData();
removeCellsInSelectedDomains rCells(mesh_, *octreePtr_);
//- read the patches/subsets forming this domain
forAll(domainNames, domainI)
{
wordList domainParts(dict.lookup(domainNames[domainI]));
rCells.selectCellsInDomain(domainParts);
}
rCells.removeCells();
mesh_.write();
::exit(1);
}
//- removes unnecessary cells and morph the boundary
//- It also checks topology of cells after morphing is performed
/* do
{
surfaceMorpherCells* cmPtr = new surfaceMorpherCells(mesh_);
cmPtr->morphMesh();
deleteDemandDrivenData(cmPtr);
} while( topologicalCleaner(mesh_).cleanTopology() );
bool changed;
do
{
changed = false;
checkIrregularSurfaceConnections checkConnections(mesh_);
if( checkConnections.checkAndFixIrregularConnections() )
changed = true;
if( checkNonMappableCellConnections(mesh_).removeCells() )
changed = true;
if( checkCellConnectionsOverFaces(mesh_).checkCellGroups() )
changed = true;
checkBoundaryFacesSharingTwoEdges(mesh_).improveTopology();
# ifdef DEBUG
mesh_.write();
# ifdef DEBUGfpma
writeMeshFPMA(mesh_, "afterTopoCleaning");
# elif DEBUGEnsight
writeMeshEnsight(mesh_, "afterTopoCleaning");
# endif
//::exit(EXIT_FAILURE);
# endif
//- pre-map mesh surface
meshSurfaceMapper mapper(*msePtr, *octreePtr_);
mapper.preMapVertices();
# elif DEBUGEnsight
writeMeshEnsight(mesh_, "preMappedMesh");
# endif
mesh_.write();
//::exit(EXIT_FAILURE);
# endif
//- map mesh surface on the geometry surface
# ifdef DEBUG
# ifdef DEBUGfpma
writeMeshFPMA(mesh_, "afterMapping");
# elif DEBUGEnsight
writeMeshEnsight(mesh_, "afterMapping");
# endif
mesh_.write();
//::exit(EXIT_FAILURE);
# endif
//- untangle surface faces
meshSurfaceOptimizer(*msePtr, *octreePtr_).preOptimizeSurface();
# ifdef DEBUG
# ifdef DEBUGfpma
writeMeshFPMA(mesh_, "afterSurfaceSmoothing");
# elif DEBUGEnsight
writeMeshEnsight(mesh_, "afterSurfaceSmoothing");
# endif
mesh_.write();
::exit(EXIT_FAILURE);
deleteDemandDrivenData(msePtr);
}
void cartesianMeshGenerator::mapEdgesAndCorners()
{
meshSurfaceEdgeExtractorNonTopo(mesh_, *octreePtr_);
//mesh_.write();
meshOptimizer(mesh_).optimizeSurface(*octreePtr_);
::exit(EXIT_FAILURE);
# ifdef DEBUGfpma
writeMeshFPMA(mesh_, "withEdges");
# elif DEBUGEnsight
writeMeshEnsight(mesh_, "withEdges");
#endif
//::exit(EXIT_FAILURE);
# endif
}
void cartesianMeshGenerator::optimiseMeshSurface()
{
meshSurfaceEngine mse(mesh_);
meshSurfaceOptimizer(mse, *octreePtr_).optimizeSurface();
# ifdef DEBUG
mesh_.write();
# ifdef DEBUGfpma
writeMeshFPMA(mesh_, "optSurfaceWithEdges");
# elif DEBUGEnsight
writeMeshEnsight(mesh_, "optSurfaceWithEdges");
#endif
//::exit(EXIT_FAILURE);
# endif
void cartesianMeshGenerator::generateBoudaryLayers()
{
wordList createLayers;
if( meshDict_.isDict("boundaryLayers") )
{
const dictionary& dict = meshDict_.subDict("boundaryLayers");
createLayers = dict.toc();
}
else
{
wordList bndLayers(meshDict_.lookup("boundaryLayers"));
createLayers.transfer(bndLayers);
}
forAll(createLayers, patchI)
bl.addLayerForPatch(createLayers[patchI]);
}
else
{
//bl.createOTopologyLayers();
bl.addLayerForAllPatches();
# ifdef DEBUGfpma
writeMeshFPMA(mesh_, "meshWithBndLayer");
# elif DEBUGEnsight
writeMeshEnsight(mesh_, "meshWithBndLayer");
# endif
mesh_.write();
//::exit(EXIT_FAILURE);
//- final optimisation
meshOptimizer optimizer(mesh_);
# ifdef DEBUG
# ifdef DEBUGfpma
writeMeshFPMA(mesh_,"optimisedMesh");
# elif DEBUGEnsight
writeMeshEnsight(mesh_, "optimisedMesh");
#endif
# endif
}
void cartesianMeshGenerator::replaceBoundaries()
{
renameBoundaryPatches rbp(mesh_, meshDict_);
# ifdef DEBUGfpma
writeMeshFPMA(mesh_,"renamedPatchesMesh");
# elif DEBUGEnsight
writeMeshEnsight(mesh_, "renamedPatchesMesh");
#endif
# endif
}
void cartesianMeshGenerator::renumberMesh()
{
polyMeshGenModifier(mesh_).renumberMesh();
# ifdef DEBUG
# ifdef DEBUGfpma
writeMeshFPMA(mesh_,"renumberedMesh");
# elif DEBUGEnsight
writeMeshEnsight(mesh_, "renumberedMesh");
#endif
# endif
optimiseMeshSurface();
generateBoudaryLayers();
replaceBoundaries();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from objectRegistry
cartesianMeshGenerator::cartesianMeshGenerator(const Time& time)
:
db_(time),
surfacePtr_(NULL),
meshDict_
(
IOobject
(
"meshDict",
db_.system(),
db_,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
),
octreePtr_(NULL),
{
if( true )
{
checkMeshDict cmd(meshDict_);
}
fileName surfaceFile = meshDict_.lookup("surfaceFile");
if( Pstream::parRun() )
franjo_j@hotmail.com
committed
surfacePtr_->writeSurface("geom.fms");
franjo_j@hotmail.com
committed
if( surfacePtr_->featureEdges().size() != 0 )
{
//- create surface patches based on the feature edges
//- and update the meshDict based on the given data
triSurfacePatchManipulator manipulator(*surfacePtr_);
const triSurf* surfaceWithPatches =
manipulator.surfaceWithPatches(&meshDict_);
//- delete the old surface and assign the new one
deleteDemandDrivenData(surfacePtr_);
surfacePtr_ = surfaceWithPatches;
}
meshOctreeCreator(*octreePtr_, meshDict_).createOctreeBoxes();
generateMesh();
}
/*
cartesianMeshGenerator::cartesianMeshGenerator
(
const objectRegistry& time,
const volScalarField& localCellSize
)
:
db_(time),
surfacePtr_(NULL),
meshDict_
(
IOobject
(
"meshDict",
db_.time().constant(),
db_,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
),
octreePtr_(NULL),
{
fileName surfaceFile = meshDict_.lookup("surfaceFile");
surfacePtr_ = new triSurface(db_.path()/surfaceFile);
octreePtr_ = new meshOctree(*surfacePtr_);
generateMesh();
}
*/
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
cartesianMeshGenerator::~cartesianMeshGenerator()
{
deleteDemandDrivenData(surfacePtr_);
deleteDemandDrivenData(octreePtr_);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void cartesianMeshGenerator::writeMesh() const