Newer
Older
/*---------------------------------------------------------------------------*\
========= |
\\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
\\/ M anipulation | Copyright (C) Creative Fields, Ltd.
-------------------------------------------------------------------------------
License
cfMesh 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 3 of the License, or (at your
cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
Description
\*---------------------------------------------------------------------------*/
#include "cartesianMeshGenerator.H"
#include "triSurf.H"
franjo_j@hotmail.com
committed
#include "triSurfacePatchManipulator.H"
#include "demandDrivenData.H"
#include "Time.H"
#include "meshOctreeCreator.H"
#include "cartesianMeshExtractor.H"
#include "meshSurfaceEngine.H"
#include "meshSurfaceMapper.H"
#include "meshSurfaceEdgeExtractorNonTopo.H"
#include "meshOptimizer.H"
#include "meshSurfaceOptimizer.H"
#include "topologicalCleaner.H"
#include "boundaryLayers.H"
#include "refineBoundaryLayers.H"
#include "renameBoundaryPatches.H"
#include "checkMeshDict.H"
#include "checkCellConnectionsOverFaces.H"
#include "checkIrregularSurfaceConnections.H"
#include "checkNonMappableCellConnections.H"
#include "checkBoundaryFacesSharingTwoEdges.H"
#include "removeCellsInSelectedDomains.H"
//#define DEBUG
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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();
}
//::exit(EXIT_SUCCESS);
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//- 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();
}
//- removes unnecessary cells and morph the boundary
//- It also checks topology of cells after morphing is performed
franjo_j@hotmail.com
committed
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();
returnReduce(1, sumOp<label>());
franjo.juretic@c-fields.com
committed
::exit(EXIT_SUCCESS);
//- pre-map mesh surface
meshSurfaceMapper mapper(*msePtr, *octreePtr_);
mapper.preMapVertices();
returnReduce(1, sumOp<label>());
//::exit(EXIT_SUCCESS);
//- map mesh surface on the geometry surface
//::exit(EXIT_SUCCESS);
franjo.juretic@c-fields.com
committed
meshSurfaceOptimizer(*msePtr, *octreePtr_).untangleSurface();
//::exit(EXIT_SUCCESS);
deleteDemandDrivenData(msePtr);
}
void cartesianMeshGenerator::mapEdgesAndCorners()
{
meshSurfaceEdgeExtractorNonTopo(mesh_, *octreePtr_);
//::exit(EXIT_SUCCESS);
}
void cartesianMeshGenerator::optimiseMeshSurface()
{
meshSurfaceEngine mse(mesh_);
meshSurfaceOptimizer(mse, *octreePtr_).optimizeSurface();
//::exit(EXIT_SUCCESS);
void cartesianMeshGenerator::generateBoundaryLayers()
franjo.juretic@c-fields.com
committed
//- add boundary layers
bl.addLayerForAllPatches();
//::exit(EXIT_SUCCESS);
void cartesianMeshGenerator::refBoundaryLayers()
{
if( meshDict_.isDict("boundaryLayers") )
{
refineBoundaryLayers refLayers(mesh_);
refineBoundaryLayers::readSettings(meshDict_, refLayers);
refLayers.refineLayers();
meshOptimizer optimizer(mesh_);
optimizer.untangleMeshFV();
}
}
franjo.juretic@c-fields.com
committed
//- untangle the surface if needed
meshSurfaceEngine mse(mesh_);
meshSurfaceOptimizer(mse, *octreePtr_).optimizeSurface();
franjo.juretic@c-fields.com
committed
//- final optimisation
meshOptimizer optimizer(mesh_);
franjo.juretic@c-fields.com
committed
optimizer.optimizeLowQualityFaces();
optimizer.untangleMeshFV();
mesh_.write();
//::exit(EXIT_SUCCESS);
}
void cartesianMeshGenerator::replaceBoundaries()
{
renameBoundaryPatches rbp(mesh_, meshDict_);
mesh_.write();
//::exit(EXIT_SUCCESS);
}
void cartesianMeshGenerator::renumberMesh()
{
polyMeshGenModifier(mesh_).renumberMesh();
mesh_.write();
//::exit(EXIT_SUCCESS);
generateBoundaryLayers();
refBoundaryLayers();
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
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