Skip to content

Commit

Permalink
Merge pull request #137 from friedenhe/master
Browse files Browse the repository at this point in the history
Added the writting failed mesh to files to checkMesh.
  • Loading branch information
friedenhe authored May 11, 2021
2 parents ab21b8d + d69e0e0 commit dc1f08f
Show file tree
Hide file tree
Showing 18 changed files with 614 additions and 37 deletions.
10 changes: 8 additions & 2 deletions src/adjoint/DACheckMesh/DACheckMesh.C
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ DACheckMesh::DACheckMesh(
const fvMesh& mesh1)
: daOption_(daOption),
runTime(runTime1),
mesh(mesh1)
mesh(mesh1),
surfWriter(nullptr),
setWriter(nullptr)
{
// Give an option to overwrite the default value of mesh quality check threshold
fvMesh& meshNew = const_cast<fvMesh&>(mesh);
Expand All @@ -34,6 +36,10 @@ DACheckMesh::DACheckMesh(
Info << "maxNonOrth: " << maxNonOrth_ << endl;
Info << "maxSkewness: " << maxSkewness_ << endl;
Info << "maxAspectRatio: " << maxAspectRatio_ << endl;

word surfaceFormat = "vtk";
surfWriter.reset(surfaceWriter::New(surfaceFormat));
setWriter.reset(writer<scalar>::New(vtkSetWriter<scalar>::typeName));
}

DACheckMesh::~DACheckMesh()
Expand All @@ -54,7 +60,7 @@ label DACheckMesh::run() const

Info << "Checking mesh quality for time = " << runTime.timeName() << endl;

label nFailedChecks = checkGeometry(mesh);
label nFailedChecks = checkGeometry(mesh, surfWriter, setWriter);

if (nFailedChecks)
{
Expand Down
10 changes: 8 additions & 2 deletions src/adjoint/DACheckMesh/DACheckMesh.H
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ private:

/// Time object
const Time& runTime;

/// fvMesh object
const fvMesh& mesh;

/// max aspect ratio
scalar maxAspectRatio_ = 1000.0;

Expand All @@ -54,6 +54,12 @@ private:
/// max skewness
scalar maxSkewness_ = 4.0;

/// surface writer pointer for failed mesh
autoPtr<surfaceWriter> surfWriter;

/// set writer pointer for failed mesh
autoPtr<writer<scalar>> setWriter;

public:
// Constructors

Expand Down
103 changes: 71 additions & 32 deletions src/adjoint/DACheckMesh/checkGeometry.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,7 @@
\*---------------------------------------------------------------------------*/

#include "PatchTools.H"
#include "checkGeometry.H"
#include "polyMesh.H"
#include "cellSet.H"
#include "faceSet.H"
#include "pointSet.H"
#include "edgeHashes.H"
#include "wedgePolyPatch.H"
#include "unitConversion.H"
#include "polyMeshTetDecomposition.H"
#include "functionObject.H"

#include "cyclicACMIPolyPatch.H"
#include "Time.H"

namespace Foam
{
Expand Down Expand Up @@ -221,7 +208,10 @@ bool Foam::checkCoupledPoints(
}
}

Foam::label Foam::checkGeometry(const polyMesh& mesh)
Foam::label Foam::checkGeometry(
const polyMesh& mesh,
const autoPtr<surfaceWriter>& surfWriter,
const autoPtr<writer<scalar>>& setWriter)
{
label noFailedChecks = 0;

Expand Down Expand Up @@ -274,18 +264,30 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh)

if (nNonClosed > 0)
{
Info << " <<There are " << nNonClosed
<< " non closed cells " << endl;
Info << " <<Writing " << nNonClosed
<< " non closed cells to set " << cells.name() << endl;
cells.instance() = mesh.pointsInstance();
cells.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), cells);
}
}
}

label nHighAspect = returnReduce(aspectCells.size(), sumOp<label>());

if (nHighAspect > 0)
{
Info << " <<There are " << nHighAspect
<< " cells with high aspect ratio"
<< endl;
Info << " <<Writing " << nHighAspect
<< " cells with high aspect ratio to set "
<< aspectCells.name() << endl;
aspectCells.instance() = mesh.pointsInstance();
aspectCells.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), aspectCells);
}
}
}

Expand All @@ -299,8 +301,14 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh)

if (nFaces > 0)
{
Info << " <<There are " << nFaces
<< " zero area faces " << endl;
Info << " <<Writing " << nFaces
<< " zero area faces to set " << faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
}
}
}
}
Expand All @@ -315,8 +323,14 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh)

if (nCells > 0)
{
Info << " <<There are " << nCells
<< " zero volume cells " << endl;
Info << " <<Writing " << nCells
<< " zero volume cells to set " << cells.name() << endl;
cells.instance() = mesh.pointsInstance();
cells.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), cells);
}
}
}
}
Expand All @@ -332,8 +346,14 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh)

if (nFaces > 0)
{
Info << " <<There are " << nFaces
<< " non-orthogonal faces " << endl;
Info << " <<Writing " << nFaces
<< " non-orthogonal faces to set " << faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
}
}
}

Expand All @@ -347,9 +367,15 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh)

if (nFaces > 0)
{
Info << " <<There are " << nFaces
<< " faces with incorrect orientation "
<< endl;
Info << " <<Writing " << nFaces
<< " faces with incorrect orientation to set "
<< faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
}
}
}
}
Expand All @@ -364,8 +390,14 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh)

if (nFaces > 0)
{
Info << " <<There are " << nFaces
<< " skew faces" << endl;
Info << " <<Writing " << nFaces
<< " skew faces to set " << faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
}
}
}
}
Expand All @@ -380,9 +412,16 @@ Foam::label Foam::checkGeometry(const polyMesh& mesh)

if (nFaces > 0)
{
Info << " <<There are " << nFaces
Info << " <<Writing " << nFaces
<< " faces with incorrectly matched 0th (or consecutive)"
<< endl;
<< " vertex to set "
<< faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
}
}
}
}
Expand Down
24 changes: 23 additions & 1 deletion src/adjoint/DACheckMesh/checkGeometry.H
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@
#include "label.H"
#include "HashSet.H"
#include "labelVector.H"
#include "polyMesh.H"
#include "cellSet.H"
#include "faceSet.H"
#include "pointSet.H"
#include "edgeHashes.H"
#include "wedgePolyPatch.H"
#include "unitConversion.H"
#include "polyMeshTetDecomposition.H"
#include "surfaceWriter.H"
#include "checkTools.H"
#include "functionObject.H"

#include "vtkSurfaceWriter.H"
#include "vtkSetWriter.H"
#include "writer.H"

#include "cyclicACMIPolyPatch.H"
#include "Time.H"
#include "PatchTools.H"

namespace Foam
{
Expand All @@ -27,6 +46,9 @@ bool checkWedges(
bool checkCoupledPoints(const polyMesh&, const bool report, labelHashSet*);

/// check mesh quality
label checkGeometry(const polyMesh& mesh);
label checkGeometry(
const polyMesh& mesh,
const autoPtr<surfaceWriter>& surfWriter,
const autoPtr<writer<scalar>>& setWriter);

}
Loading

0 comments on commit dc1f08f

Please sign in to comment.