Commit 202d7c1a authored by mattijs's avatar mattijs
Browse files

ENH: snappyHexMesh: fix growing of attraction. Split off debug/writing/output

parent eca628a2
......@@ -576,25 +576,30 @@ void writeMesh
(
const string& msg,
const meshRefinement& meshRefiner,
const bool writeLevel,
const label debug
const meshRefinement::debugType debugLevel,
const meshRefinement::writeType writeLevel
)
{
const fvMesh& mesh = meshRefiner.mesh();
meshRefiner.printMeshInfo(debug, msg);
meshRefiner.printMeshInfo(debugLevel, msg);
Info<< "Writing mesh to time " << meshRefiner.timeName() << endl;
label flag = meshRefinement::MESH;
if (writeLevel)
{
flag |= meshRefinement::SCALARLEVELS;
}
if (debug & meshRefinement::OBJINTERSECTIONS)
{
flag |= meshRefinement::OBJINTERSECTIONS;
}
meshRefiner.write(flag, mesh.time().path()/meshRefiner.timeName());
//label flag = meshRefinement::MESH;
//if (writeLevel)
//{
// flag |= meshRefinement::SCALARLEVELS;
//}
//if (debug & meshRefinement::OBJINTERSECTIONS)
//{
// flag |= meshRefinement::OBJINTERSECTIONS;
//}
meshRefiner.write
(
debugLevel,
meshRefinement::writeType(writeLevel | meshRefinement::WRITEMESH),
mesh.time().path()/meshRefiner.timeName()
);
Info<< "Wrote mesh in = "
<< mesh.time().cpuTimeIncrement() << " s." << endl;
}
......@@ -837,16 +842,74 @@ int main(int argc, char *argv[])
// Debug
// ~~~~~
const label debug = meshDict.lookupOrDefault<label>("debug", 0);
if (debug > 0)
// Set debug level
meshRefinement::debugType debugLevel = meshRefinement::debugType
(
meshDict.lookupOrDefault<label>
(
"debug",
0
)
);
{
meshRefinement::debug = debug;
autoRefineDriver::debug = debug;
autoSnapDriver::debug = debug;
autoLayerDriver::debug = debug;
wordList flags;
if (meshDict.readIfPresent("debugFlags", flags))
{
debugLevel = meshRefinement::debugType
(
meshRefinement::readFlags
(
meshRefinement::IOdebugTypeNames,
flags
)
);
}
}
if (debugLevel > 0)
{
meshRefinement::debug = debugLevel;
autoRefineDriver::debug = debugLevel;
autoSnapDriver::debug = debugLevel;
autoLayerDriver::debug = debugLevel;
}
// Set file writing level
{
wordList flags;
if (meshDict.readIfPresent("writeFlags", flags))
{
meshRefinement::writeLevel
(
meshRefinement::writeType
(
meshRefinement::readFlags
(
meshRefinement::IOwriteTypeNames,
flags
)
)
);
}
}
const bool writeLevel = meshDict.lookupOrDefault<bool>("writeLevel", false);
// Set output level
{
wordList flags;
if (meshDict.readIfPresent("outputFlags", flags))
{
meshRefinement::outputLevel
(
meshRefinement::outputType
(
meshRefinement::readFlags
(
meshRefinement::IOoutputTypeNames,
flags
)
)
);
}
}
// Read geometry
......@@ -1047,11 +1110,12 @@ int main(int argc, char *argv[])
<< mesh.time().cpuTimeIncrement() << " s" << nl << endl;
// Some stats
meshRefiner.printMeshInfo(debug, "Initial mesh");
meshRefiner.printMeshInfo(debugLevel, "Initial mesh");
meshRefiner.write
(
debug & meshRefinement::OBJINTERSECTIONS,
meshRefinement::debugType(debugLevel&meshRefinement::OBJINTERSECTIONS),
meshRefinement::writeType(0),
mesh.time().path()/meshRefiner.timeName()
);
......@@ -1271,7 +1335,7 @@ int main(int argc, char *argv[])
);
if (!overwrite && !debug)
if (!overwrite && !debugLevel)
{
const_cast<Time&>(mesh.time())++;
}
......@@ -1289,8 +1353,8 @@ int main(int argc, char *argv[])
(
"Refined mesh",
meshRefiner,
writeLevel,
debug
debugLevel,
meshRefinement::writeLevel()
);
Info<< "Mesh refined in = "
......@@ -1308,7 +1372,7 @@ int main(int argc, char *argv[])
globalToSlavePatch
);
if (!overwrite && !debug)
if (!overwrite && !debugLevel)
{
const_cast<Time&>(mesh.time())++;
}
......@@ -1330,8 +1394,8 @@ int main(int argc, char *argv[])
(
"Snapped mesh",
meshRefiner,
writeLevel,
debug
debugLevel,
meshRefinement::writeLevel()
);
Info<< "Mesh snapped in = "
......@@ -1357,7 +1421,7 @@ int main(int argc, char *argv[])
);
if (!overwrite && !debug)
if (!overwrite && !debugLevel)
{
const_cast<Time&>(mesh.time())++;
}
......@@ -1376,8 +1440,8 @@ int main(int argc, char *argv[])
(
"Layer mesh",
meshRefiner,
writeLevel,
debug
debugLevel,
meshRefinement::writeLevel()
);
Info<< "Layers added in = "
......
......@@ -475,14 +475,22 @@ meshQualityControls
// Advanced
// Flags for optional output
// 0 : only write final meshes
// 1 : write intermediate meshes
// 2 : write volScalarField with cellLevel for postprocessing
// 4 : write current mesh intersections as .obj files
// 8 : write information about explicit feature edge refinement
// 16 : write information about layers
debug 0;
//// Debug flags
//debugFlags
//(
// mesh // write intermediate meshes
// intersections // write current mesh intersections as .obj files
// featureSeeds, // write information about explicit feature edge refinement
// layerInfo // write information about layers
//);
//
//// Write flags
//writeFlags
//(
// scalarLevels // write volScalarField with cellLevel for postprocessing
// layerSets // write cellSets, faceSets of faces in layer
// layerFields // write volScalarField for layer coverage
//);
// Merge tolerance. Is fraction of overall bounding box of initial mesh.
// Note: the write tolerance needs to be higher than this.
......
......@@ -2472,7 +2472,7 @@ void Foam::autoLayerDriver::getLayerCellsFaces
}
bool Foam::autoLayerDriver::writeLayerData
void Foam::autoLayerDriver::printLayerData
(
const fvMesh& mesh,
const labelList& patchIDs,
......@@ -2481,153 +2481,284 @@ bool Foam::autoLayerDriver::writeLayerData
const scalarField& faceRealThickness
) const
{
bool allOk = true;
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
// Find maximum length of a patch name, for a nicer output
label maxPatchNameLen = 0;
forAll(patchIDs, i)
{
label nAdded = 0;
forAll(cellNLayers, cellI)
label patchI = patchIDs[i];
word patchName = pbm[patchI].name();
maxPatchNameLen = max(maxPatchNameLen, label(patchName.size()));
}
Info<< nl
<< setf(ios_base::left) << setw(maxPatchNameLen) << "patch"
<< setw(0) << " faces layers overall thickness" << nl
<< setf(ios_base::left) << setw(maxPatchNameLen) << " "
<< setw(0) << " [m] [%]" << nl
<< setf(ios_base::left) << setw(maxPatchNameLen) << "-----"
<< setw(0) << " ----- ------ --- ---" << endl;
forAll(patchIDs, i)
{
label patchI = patchIDs[i];
const polyPatch& pp = pbm[patchI];
label sumSize = pp.size();
// Number of layers
const labelList& faceCells = pp.faceCells();
label sumNLayers = 0;
forAll(faceCells, i)
{
if (cellNLayers[cellI] > 0)
{
nAdded++;
}
sumNLayers += cellNLayers[faceCells[i]];
}
cellSet addedCellSet(mesh, "addedCells", nAdded);
forAll(cellNLayers, cellI)
// Thickness
scalarField::subField patchWanted = pbm[patchI].patchSlice
(
faceWantedThickness
);
scalarField::subField patchReal = pbm[patchI].patchSlice
(
faceRealThickness
);
scalar sumRealThickness = sum(patchReal);
scalar sumFraction = 0;
forAll(patchReal, i)
{
if (cellNLayers[cellI] > 0)
if (patchWanted[i] > VSMALL)
{
addedCellSet.insert(cellI);
sumFraction += (patchReal[i]/patchWanted[i]);
}
}
addedCellSet.instance() = meshRefiner_.timeName();
Info<< "Writing "
<< returnReduce(addedCellSet.size(), sumOp<label>())
<< " added cells to cellSet "
<< addedCellSet.name() << endl;
bool ok = addedCellSet.write();
allOk = allOk & ok;
reduce(sumSize, sumOp<label>());
reduce(sumNLayers, sumOp<label>());
reduce(sumRealThickness, sumOp<scalar>());
reduce(sumFraction, sumOp<scalar>());
scalar avgLayers = 0;
scalar avgReal = 0;
scalar avgFraction = 0;
if (sumSize > 0)
{
avgLayers = scalar(sumNLayers)/sumSize;
avgReal = sumRealThickness/sumSize;
avgFraction = sumFraction/sumSize;
}
Info<< setf(ios_base::left) << setw(maxPatchNameLen)
<< pbm[patchI].name() << setprecision(3)
<< " " << setw(8) << sumSize
<< " " << setw(8) << avgLayers
<< " " << setw(8) << avgReal
<< " " << setw(8) << 100*avgFraction
<< endl;
}
Info<< endl;
}
bool Foam::autoLayerDriver::writeLayerData
(
const fvMesh& mesh,
const labelList& patchIDs,
const labelList& cellNLayers,
const scalarField& faceWantedThickness,
const scalarField& faceRealThickness
) const
{
bool allOk = true;
if (meshRefinement::writeLevel() & meshRefinement::WRITELAYERSETS)
{
label nAdded = 0;
forAll(faceRealThickness, faceI)
{
if (faceRealThickness[faceI] > 0)
label nAdded = 0;
forAll(cellNLayers, cellI)
{
nAdded++;
if (cellNLayers[cellI] > 0)
{
nAdded++;
}
}
cellSet addedCellSet(mesh, "addedCells", nAdded);
forAll(cellNLayers, cellI)
{
if (cellNLayers[cellI] > 0)
{
addedCellSet.insert(cellI);
}
}
addedCellSet.instance() = meshRefiner_.timeName();
Info<< "Writing "
<< returnReduce(addedCellSet.size(), sumOp<label>())
<< " added cells to cellSet "
<< addedCellSet.name() << endl;
bool ok = addedCellSet.write();
allOk = allOk & ok;
}
faceSet layerFacesSet(mesh, "layerFaces", nAdded);
forAll(faceRealThickness, faceI)
{
if (faceRealThickness[faceI] > 0)
label nAdded = 0;
forAll(faceRealThickness, faceI)
{
layerFacesSet.insert(faceI);
if (faceRealThickness[faceI] > 0)
{
nAdded++;
}
}
faceSet layerFacesSet(mesh, "layerFaces", nAdded);
forAll(faceRealThickness, faceI)
{
if (faceRealThickness[faceI] > 0)
{
layerFacesSet.insert(faceI);
}
}
layerFacesSet.instance() = meshRefiner_.timeName();
Info<< "Writing "
<< returnReduce(layerFacesSet.size(), sumOp<label>())
<< " faces inside added layer to faceSet "
<< layerFacesSet.name() << endl;
bool ok = layerFacesSet.write();
allOk = allOk & ok;
}
layerFacesSet.instance() = meshRefiner_.timeName();
Info<< "Writing "
<< returnReduce(layerFacesSet.size(), sumOp<label>())
<< " faces inside added layer to faceSet "
<< layerFacesSet.name() << endl;
bool ok = layerFacesSet.write();
allOk = allOk & ok;
}
if (meshRefinement::writeLevel() & meshRefinement::WRITELAYERFIELDS)
{
volScalarField fld
(
IOobject
{
volScalarField fld
(
"nSurfaceLayers",
mesh.time().timeName(),
IOobject
(
"nSurfaceLayers",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
false
),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
false
),
mesh,
dimensionedScalar("zero", dimless, 0),
fixedValueFvPatchScalarField::typeName
);
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
forAll(patchIDs, i)
{
label patchI = patchIDs[i];
const polyPatch& pp = pbm[patchI];
const labelList& faceCells = pp.faceCells();
scalarField pfld(faceCells.size());
forAll(faceCells, i)
dimensionedScalar("zero", dimless, 0),
fixedValueFvPatchScalarField::typeName
);
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
forAll(patchIDs, i)
{
pfld[i] = cellNLayers[faceCells[i]];
label patchI = patchIDs[i];
const polyPatch& pp = pbm[patchI];
const labelList& faceCells = pp.faceCells();
scalarField pfld(faceCells.size());
forAll(faceCells, i)
{
pfld[i] = cellNLayers[faceCells[i]];
}
fld.boundaryField()[patchI] == pfld;
}
fld.boundaryField()[patchI] == pfld;
Info<< "Writing volScalarField " << fld.name()
<< " with actual number of layers" << endl;
bool ok = fld.write();
allOk = allOk & ok;
}
Info<< "Writing volScalarField " << fld.name()
<< " with actual number of layers" << endl;
bool ok = fld.write();
allOk = allOk & ok;
}
{
volScalarField fld
(
IOobject
{
volScalarField fld
(
"wantedThickness",
mesh.time().timeName(),
IOobject
(
"thickness",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
false
),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
false
),
mesh,
dimensionedScalar("zero", dimless, 0),
fixedValueFvPatchScalarField::typeName
);
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
forAll(patchIDs, i)
dimensionedScalar("zero", dimless, 0),
fixedValueFvPatchScalarField::typeName
);
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
forAll(patchIDs, i)
{
label patchI = patchIDs[i];
fld.boundaryField()[patchI] == pbm[patchI].patchSlice
(
faceRealThickness
);
}
Info<< "Writing volScalarField " << fld.name()
<< " with overall layer thickness" << endl;
bool ok = fld.write();
allOk = allOk & ok;
}
{
label patchI = patchIDs[i];
fld.boundaryField()[patchI] == pbm[patchI].patchSlice
volScalarField fld
(
faceWantedThickness
IOobject
(
"thicknessFraction",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
false
),
mesh,
dimensionedScalar("zero", dimless, 0),
fixedValueFvPatchScalarField::typeName
);
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
forAll(patchIDs, i)
{
label patchI = patchIDs[i];
scalarField::subField patchWanted = pbm[patchI].patchSlice
(
faceWantedThickness
);
scalarField::subField patchReal = pbm[patchI].patchSlice
(
faceRealThickness
);
// Convert patchReal to relavtive thickness
scalarField pfld(patchReal.size(), 0.0);
forAll(patchReal, i)
{
if (patchWanted[i] > VSMALL)
{
pfld[i] = patchReal[i]/patchWanted[i];
}
}
fld.boundaryField()[patchI] == pfld;
}
Info<< "Writing volScalarField " << fld.name()
<< " with overall layer thickness as fraction"
<< " of desired thickness" << endl;
bool ok = fld.write();
allOk = allOk & ok;