mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
split autoHexMeshDriver; updated header
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -33,12 +33,86 @@ Description
|
||||
#include "argList.H"
|
||||
#include "Time.H"
|
||||
#include "fvMesh.H"
|
||||
#include "autoHexMeshDriver.H"
|
||||
#include "autoRefineDriver.H"
|
||||
#include "autoSnapDriver.H"
|
||||
#include "autoLayerDriver.H"
|
||||
#include "searchableSurfaces.H"
|
||||
#include "refinementSurfaces.H"
|
||||
#include "shellSurfaces.H"
|
||||
#include "decompositionMethod.H"
|
||||
#include "fvMeshDistribute.H"
|
||||
#include "wallPolyPatch.H"
|
||||
#include "refinementParameters.H"
|
||||
#include "snapParameters.H"
|
||||
#include "layerParameters.H"
|
||||
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
// Check writing tolerance before doing any serious work
|
||||
scalar getMergeDistance(const polyMesh& mesh, const scalar mergeTol)
|
||||
{
|
||||
const boundBox& meshBb = mesh.bounds();
|
||||
scalar mergeDist = mergeTol*mag(meshBb.max() - meshBb.min());
|
||||
scalar writeTol = std::pow
|
||||
(
|
||||
scalar(10.0),
|
||||
-scalar(IOstream::defaultPrecision())
|
||||
);
|
||||
|
||||
Info<< nl
|
||||
<< "Overall mesh bounding box : " << meshBb << nl
|
||||
<< "Relative tolerance : " << mergeTol << nl
|
||||
<< "Absolute matching distance : " << mergeDist << nl
|
||||
<< endl;
|
||||
|
||||
if (mesh.time().writeFormat() == IOstream::ASCII && mergeTol < writeTol)
|
||||
{
|
||||
FatalErrorIn("getMergeDistance(const polyMesh&, const scalar)")
|
||||
<< "Your current settings specify ASCII writing with "
|
||||
<< IOstream::defaultPrecision() << " digits precision." << endl
|
||||
<< "Your merging tolerance (" << mergeTol << ") is finer than this."
|
||||
<< endl
|
||||
<< "Please change your writeFormat to binary"
|
||||
<< " or increase the writePrecision" << endl
|
||||
<< "or adjust the merge tolerance (-mergeTol)."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
return mergeDist;
|
||||
}
|
||||
|
||||
|
||||
// Write mesh and additional information
|
||||
void writeMesh
|
||||
(
|
||||
const string& msg,
|
||||
const meshRefinement& meshRefiner,
|
||||
const label debug
|
||||
)
|
||||
{
|
||||
const fvMesh& mesh = meshRefiner.mesh();
|
||||
|
||||
meshRefiner.printMeshInfo(debug, msg);
|
||||
Info<< "Writing mesh to time " << mesh.time().timeName() << endl;
|
||||
|
||||
meshRefiner.write(meshRefinement::MESH|meshRefinement::SCALARLEVELS, "");
|
||||
if (debug & meshRefinement::OBJINTERSECTIONS)
|
||||
{
|
||||
meshRefiner.write
|
||||
(
|
||||
meshRefinement::OBJINTERSECTIONS,
|
||||
mesh.time().path()/mesh.time().timeName()
|
||||
);
|
||||
}
|
||||
Info<< "Written mesh in = "
|
||||
<< mesh.time().cpuTimeIncrement() << " s." << endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
# include "setRootCase.H"
|
||||
@ -49,6 +123,11 @@ int main(int argc, char *argv[])
|
||||
Info<< "Read mesh in = "
|
||||
<< runTime.cpuTimeIncrement() << " s" << endl;
|
||||
|
||||
// Check patches and faceZones are synchronised
|
||||
mesh.boundaryMesh().checkParallelSync(true);
|
||||
meshRefinement::checkCoupledFaceZones(mesh);
|
||||
|
||||
|
||||
// Read decomposePar dictionary
|
||||
IOdictionary decomposeDict
|
||||
(
|
||||
@ -75,51 +154,282 @@ int main(int argc, char *argv[])
|
||||
)
|
||||
);
|
||||
|
||||
// refinement parameters
|
||||
const dictionary& refineDict = meshDict.subDict("castellatedMeshControls");
|
||||
|
||||
// all surface geometry
|
||||
const dictionary& geometryDict = meshDict.subDict("geometry");
|
||||
|
||||
// snap-to-surface parameters
|
||||
const dictionary& snapDict = meshDict.subDict("snapControls");
|
||||
// refinement parameters
|
||||
const dictionary& refineDict = meshDict.subDict("castellatedMeshControls");
|
||||
|
||||
// mesh motion and mesh quality parameters
|
||||
const dictionary& motionDict = meshDict.subDict("meshQualityControls");
|
||||
|
||||
// snap-to-surface parameters
|
||||
const dictionary& snapDict = meshDict.subDict("snapControls");
|
||||
|
||||
// layer addition parameters
|
||||
const dictionary& layerDict = meshDict.subDict("addLayersControls");
|
||||
|
||||
|
||||
// Main meshing driver. Read surfaces. Determine initial intersections.
|
||||
autoHexMeshDriver meshEngine
|
||||
|
||||
// Debug
|
||||
// ~~~~~
|
||||
|
||||
const label debug(readLabel(meshDict.lookup("debug")));
|
||||
if (debug > 0)
|
||||
{
|
||||
meshRefinement::debug = debug;
|
||||
autoRefineDriver::debug = debug;
|
||||
autoSnapDriver::debug = debug;
|
||||
autoLayerDriver::debug = debug;
|
||||
}
|
||||
|
||||
|
||||
// Read geometry
|
||||
// ~~~~~~~~~~~~~
|
||||
|
||||
searchableSurfaces allGeometry
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"abc", // dummy name
|
||||
mesh.time().constant(), // directory
|
||||
"triSurface", // instance
|
||||
mesh.time(), // registry
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
geometryDict
|
||||
);
|
||||
|
||||
|
||||
// Read refinement surfaces
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Info<< "Reading refinement surfaces." << endl;
|
||||
refinementSurfaces surfaces
|
||||
(
|
||||
allGeometry,
|
||||
refineDict.subDict("refinementSurfaces")
|
||||
);
|
||||
Info<< "Read refinement surfaces in = "
|
||||
<< mesh.time().cpuTimeIncrement() << " s" << nl << endl;
|
||||
|
||||
|
||||
// Read refinement shells
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Info<< "Reading refinement shells." << endl;
|
||||
shellSurfaces shells
|
||||
(
|
||||
allGeometry,
|
||||
refineDict.subDict("refinementRegions")
|
||||
);
|
||||
Info<< "Read refinement shells in = "
|
||||
<< mesh.time().cpuTimeIncrement() << " s" << nl << endl;
|
||||
|
||||
|
||||
Info<< "Setting refinement level of surface to be consistent"
|
||||
<< " with shells." << endl;
|
||||
surfaces.setMinLevelFields(shells);
|
||||
Info<< "Checked shell refinement in = "
|
||||
<< mesh.time().cpuTimeIncrement() << " s" << nl << endl;
|
||||
|
||||
|
||||
|
||||
|
||||
// Add all the surface regions as patches
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
labelList globalToPatch;
|
||||
{
|
||||
Info<< nl
|
||||
<< "Adding patches for surface regions" << nl
|
||||
<< "----------------------------------" << nl
|
||||
<< endl;
|
||||
|
||||
// From global region number to mesh patch.
|
||||
globalToPatch.setSize(surfaces.nRegions(), -1);
|
||||
|
||||
Info<< "Patch\tRegion" << nl
|
||||
<< "-----\t------"
|
||||
<< endl;
|
||||
|
||||
const labelList& surfaceGeometry = surfaces.surfaces();
|
||||
forAll(surfaceGeometry, surfI)
|
||||
{
|
||||
label geomI = surfaceGeometry[surfI];
|
||||
|
||||
const wordList& regNames = allGeometry.regionNames()[geomI];
|
||||
|
||||
Info<< surfaces.names()[surfI] << ':' << nl << nl;
|
||||
|
||||
forAll(regNames, i)
|
||||
{
|
||||
label patchI = meshRefinement::addPatch
|
||||
(
|
||||
mesh,
|
||||
regNames[i],
|
||||
wallPolyPatch::typeName
|
||||
);
|
||||
|
||||
Info<< patchI << '\t' << regNames[i] << nl;
|
||||
|
||||
globalToPatch[surfaces.globalRegion(surfI, i)] = patchI;
|
||||
}
|
||||
|
||||
Info<< nl;
|
||||
}
|
||||
Info<< "Added patches in = "
|
||||
<< mesh.time().cpuTimeIncrement() << " s" << nl << endl;
|
||||
}
|
||||
|
||||
|
||||
// Parallel
|
||||
// ~~~~~~~~
|
||||
|
||||
// Decomposition
|
||||
autoPtr<decompositionMethod> decomposerPtr
|
||||
(
|
||||
decompositionMethod::New
|
||||
(
|
||||
decomposeDict,
|
||||
mesh
|
||||
)
|
||||
);
|
||||
decompositionMethod& decomposer = decomposerPtr();
|
||||
|
||||
if (Pstream::parRun() && !decomposer.parallelAware())
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "You have selected decomposition method "
|
||||
<< decomposer.typeName
|
||||
<< " which is not parallel aware." << endl
|
||||
<< "Please select one that is (hierarchical, parMetis)"
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
const scalar mergeDist = getMergeDistance
|
||||
(
|
||||
mesh,
|
||||
meshDict, // global control parameters
|
||||
geometryDict,
|
||||
refineDict, // refinement parameters
|
||||
decomposeDict
|
||||
readScalar(meshDict.lookup("mergeTolerance"))
|
||||
);
|
||||
|
||||
|
||||
// Mesh distribution engine (uses tolerance to reconstruct meshes)
|
||||
fvMeshDistribute distributor(mesh, mergeDist);
|
||||
|
||||
|
||||
// Refinement engine
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
|
||||
Info<< nl
|
||||
<< "Determining initial surface intersections" << nl
|
||||
<< "-----------------------------------------" << nl
|
||||
<< endl;
|
||||
|
||||
// Main refinement engine
|
||||
meshRefinement meshRefiner
|
||||
(
|
||||
mesh,
|
||||
mergeDist, // tolerance used in sorting coordinates
|
||||
surfaces, // for surface intersection refinement
|
||||
shells // for volume (inside/outside) refinement
|
||||
);
|
||||
Info<< "Calculated surface intersections in = "
|
||||
<< mesh.time().cpuTimeIncrement() << " s" << nl << endl;
|
||||
|
||||
// Some stats
|
||||
meshRefiner.printMeshInfo(debug, "Initial mesh");
|
||||
|
||||
meshRefiner.write
|
||||
(
|
||||
debug&meshRefinement::OBJINTERSECTIONS,
|
||||
mesh.time().path()/mesh.time().timeName()
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
// Now do the real work -refinement -snapping -layers
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Switch wantRefine(meshDict.lookup("castellatedMesh"));
|
||||
Switch wantSnap(meshDict.lookup("snap"));
|
||||
Switch wantLayers(meshDict.lookup("addLayers"));
|
||||
|
||||
if (wantRefine)
|
||||
{
|
||||
meshEngine.doRefine(refineDict, wantSnap);
|
||||
autoRefineDriver refineDriver
|
||||
(
|
||||
meshRefiner,
|
||||
decomposer,
|
||||
distributor,
|
||||
globalToPatch
|
||||
);
|
||||
|
||||
// Refinement parameters
|
||||
refinementParameters refineParams(refineDict);
|
||||
|
||||
refineDriver.doRefine(refineDict, refineParams, wantSnap);
|
||||
|
||||
writeMesh
|
||||
(
|
||||
"Refined mesh",
|
||||
meshRefiner,
|
||||
debug
|
||||
);
|
||||
}
|
||||
|
||||
if (wantSnap)
|
||||
{
|
||||
meshEngine.doSnap(snapDict, motionDict);
|
||||
autoSnapDriver snapDriver
|
||||
(
|
||||
meshRefiner,
|
||||
globalToPatch
|
||||
);
|
||||
|
||||
// Snap parameters
|
||||
snapParameters snapParams(snapDict);
|
||||
|
||||
snapDriver.doSnap(snapDict, motionDict, snapParams);
|
||||
|
||||
writeMesh
|
||||
(
|
||||
"Snapped mesh",
|
||||
meshRefiner,
|
||||
debug
|
||||
);
|
||||
}
|
||||
|
||||
if (wantLayers)
|
||||
{
|
||||
meshEngine.doLayers(layerDict, motionDict);
|
||||
autoLayerDriver layerDriver
|
||||
(
|
||||
meshRefiner,
|
||||
globalToPatch
|
||||
);
|
||||
|
||||
// Layer addition parameters
|
||||
layerParameters layerParams(layerDict, mesh.boundaryMesh());
|
||||
|
||||
layerDriver.doLayers
|
||||
(
|
||||
layerDict,
|
||||
motionDict,
|
||||
layerParams,
|
||||
decomposer,
|
||||
distributor
|
||||
);
|
||||
|
||||
writeMesh
|
||||
(
|
||||
"Layer mesh",
|
||||
meshRefiner,
|
||||
debug
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Info<< "Finished meshing in = "
|
||||
<< runTime.elapsedCpuTime() << " s." << endl;
|
||||
|
||||
|
||||
@ -36,26 +36,26 @@ addLayers false;
|
||||
// - to 'snap' the mesh boundary to the surface
|
||||
geometry
|
||||
{
|
||||
// box1x1x1
|
||||
// {
|
||||
// type searchableBox;
|
||||
// min (1.5 1 -0.5);
|
||||
// max (3.5 2 0.5);
|
||||
// }
|
||||
//
|
||||
// sphere.stl
|
||||
// {
|
||||
// type triSurfaceMesh;
|
||||
//
|
||||
// // Per region the patchname. If not provided will be <name>_<region>.
|
||||
// regions
|
||||
// {
|
||||
// secondSolid
|
||||
// {
|
||||
// name mySecondPatch;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
box1x1x1
|
||||
{
|
||||
type searchableBox;
|
||||
min (1.5 1 -0.5);
|
||||
max (3.5 2 0.5);
|
||||
}
|
||||
|
||||
sphere.stl
|
||||
{
|
||||
type triSurfaceMesh;
|
||||
|
||||
// Per region the patchname. If not provided will be <name>_<region>.
|
||||
regions
|
||||
{
|
||||
secondSolid
|
||||
{
|
||||
name mySecondPatch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sphere2
|
||||
{
|
||||
@ -159,11 +159,11 @@ castellatedMeshControls
|
||||
|
||||
refinementRegions
|
||||
{
|
||||
//box1x1x1
|
||||
//{
|
||||
// mode inside;
|
||||
// levels ((1.0 4));
|
||||
//}
|
||||
box1x1x1
|
||||
{
|
||||
mode inside;
|
||||
levels ((1.0 4));
|
||||
}
|
||||
//sphere.stl
|
||||
//{
|
||||
// mode distance;
|
||||
|
||||
Reference in New Issue
Block a user