ENH: cyclicPolyPatch: have local 'matchTolerance' entry in dictionary

This commit is contained in:
mattijs
2011-04-27 20:41:17 +01:00
parent eaa6a98ff7
commit 8782283d62
9 changed files with 95 additions and 73 deletions

View File

@ -526,13 +526,6 @@ int main(int argc, char *argv[])
// Whether to synchronise points // Whether to synchronise points
const Switch pointSync(dict.lookup("pointSync")); const Switch pointSync(dict.lookup("pointSync"));
// Set the matching tolerance so we can read illegal meshes
scalar tol = readScalar(dict.lookup("matchTolerance"));
Info<< "Using relative tolerance " << tol
<< " to match up faces and points" << nl << endl;
coupledPolyPatch::matchTol = tol;
# include "createNamedPolyMesh.H" # include "createNamedPolyMesh.H"
const word oldInstance = mesh.pointsInstance(); const word oldInstance = mesh.pointsInstance();

View File

@ -34,16 +34,12 @@ FoamFile
// This will usually fail upon loading: // This will usually fail upon loading:
// "face 0 area does not match neighbour 2 by 0.0100005%" // "face 0 area does not match neighbour 2 by 0.0100005%"
// " -- possible face ordering problem." // " -- possible face ordering problem."
// - change patch type from 'cyclic' to 'patch' in the polyMesh/boundary file. // - in polyMesh/boundary file:
// - loosen match tolerance to get case to load // - loosen matchTolerance of all cyclics to get case to load
// - or change patch type from 'cyclic' to 'patch'
// - regenerate cyclic as above // - regenerate cyclic as above
// Tolerance used in matching faces. Absolute tolerance is span of
// face times this factor. To load incorrectly matches meshes set this
// to a higher value.
matchTolerance 1E-3;
// Do a synchronisation of coupled points after creation of any patches. // Do a synchronisation of coupled points after creation of any patches.
// Note: this does not work with points that are on multiple coupled patches // Note: this does not work with points that are on multiple coupled patches
// with transformations. // with transformations.
@ -67,6 +63,12 @@ patches
transform rotational; transform rotational;
rotationAxis (1 0 0); rotationAxis (1 0 0);
rotationCentre (0 0 0); rotationCentre (0 0 0);
// transform translational;
// separationVector (1 0 0);
// Optional non-default tolerance to be able to define cyclics
// on bad meshes
//matchTolerance 1E-2;
} }
// How to construct: either from 'patches' or 'set' // How to construct: either from 'patches' or 'set'

View File

@ -34,7 +34,7 @@ namespace Foam
{ {
defineTypeNameAndDebug(coupledPolyPatch, 0); defineTypeNameAndDebug(coupledPolyPatch, 0);
scalar coupledPolyPatch::matchTol = 1E-3; const scalar coupledPolyPatch::defaultMatchTol_ = 1E-4;
template<> template<>
const char* NamedEnum<coupledPolyPatch::transformType, 4>::names[] = const char* NamedEnum<coupledPolyPatch::transformType, 4>::names[] =
@ -145,6 +145,7 @@ Foam::pointField Foam::coupledPolyPatch::getAnchorPoints
Foam::scalarField Foam::coupledPolyPatch::calcFaceTol Foam::scalarField Foam::coupledPolyPatch::calcFaceTol
( (
const scalar matchTol,
const UList<face>& faces, const UList<face>& faces,
const pointField& points, const pointField& points,
const pointField& faceCentres const pointField& faceCentres
@ -401,7 +402,8 @@ Foam::coupledPolyPatch::coupledPolyPatch
const polyBoundaryMesh& bm const polyBoundaryMesh& bm
) )
: :
polyPatch(name, size, start, index, bm) polyPatch(name, size, start, index, bm),
matchTolerance_(defaultMatchTol_)
{} {}
@ -413,7 +415,8 @@ Foam::coupledPolyPatch::coupledPolyPatch
const polyBoundaryMesh& bm const polyBoundaryMesh& bm
) )
: :
polyPatch(name, dict, index, bm) polyPatch(name, dict, index, bm),
matchTolerance_(dict.lookupOrDefault("matchTolerance", defaultMatchTol_))
{} {}
@ -423,7 +426,8 @@ Foam::coupledPolyPatch::coupledPolyPatch
const polyBoundaryMesh& bm const polyBoundaryMesh& bm
) )
: :
polyPatch(pp, bm) polyPatch(pp, bm),
matchTolerance_(pp.matchTolerance_)
{} {}
@ -436,7 +440,8 @@ Foam::coupledPolyPatch::coupledPolyPatch
const label newStart const label newStart
) )
: :
polyPatch(pp, bm, index, newSize, newStart) polyPatch(pp, bm, index, newSize, newStart),
matchTolerance_(pp.matchTolerance_)
{} {}
@ -449,7 +454,8 @@ Foam::coupledPolyPatch::coupledPolyPatch
const label newStart const label newStart
) )
: :
polyPatch(pp, bm, index, mapAddressing, newStart) polyPatch(pp, bm, index, mapAddressing, newStart),
matchTolerance_(pp.matchTolerance_)
{} {}
@ -459,4 +465,17 @@ Foam::coupledPolyPatch::~coupledPolyPatch()
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::coupledPolyPatch::write(Ostream& os) const
{
polyPatch::write(os);
//if (matchTolerance_ != defaultMatchTol_)
{
os.writeKeyword("matchTolerance") << matchTolerance_
<< token::END_STATEMENT << nl;
}
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -69,6 +69,12 @@ private:
// Private data // Private data
//- default matching tolerance
static const scalar defaultMatchTol_;
//- local matching tolerance
const scalar matchTolerance_;
//- offset (distance) vector from one side of the couple to the other //- offset (distance) vector from one side of the couple to the other
mutable vectorField separation_; mutable vectorField separation_;
@ -81,14 +87,6 @@ private:
//- Are faces collocated. Either size 0,1 or length of patch. //- Are faces collocated. Either size 0,1 or length of patch.
mutable boolList collocated_; mutable boolList collocated_;
public:
// Static data members
//- Relative tolerance (for geometric matching).
static scalar matchTol;
protected: protected:
// Protected Member Functions // Protected Member Functions
@ -105,7 +103,7 @@ protected:
const vectorField& nf, const vectorField& nf,
const vectorField& nr, const vectorField& nr,
const scalarField& smallDist, const scalarField& smallDist,
const scalar absTol = matchTol, const scalar absTol,
const transformType = UNKNOWN const transformType = UNKNOWN
) const; ) const;
@ -162,6 +160,7 @@ protected:
// from face centre to any of the face vertices. // from face centre to any of the face vertices.
static scalarField calcFaceTol static scalarField calcFaceTol
( (
const scalar matchTol,
const UList<face>& faces, const UList<face>& faces,
const pointField& points, const pointField& points,
const pointField& faceCentres const pointField& faceCentres
@ -295,6 +294,11 @@ public:
return collocated_; return collocated_;
} }
scalar matchTolerance() const
{
return matchTolerance_;
}
//- Calculate the patch geometry //- Calculate the patch geometry
virtual void calcGeometry virtual void calcGeometry
@ -328,6 +332,9 @@ public:
labelList& faceMap, labelList& faceMap,
labelList& rotation labelList& rotation
) const = 0; ) const = 0;
//- Write the polyPatch data as a dictionary
virtual void write(Ostream&) const;
}; };

View File

@ -212,7 +212,7 @@ void Foam::cyclicPolyPatch::calcTransforms
maxAreaFacei = facei; maxAreaFacei = facei;
} }
if (areaDiff > coupledPolyPatch::matchTol) if (areaDiff > matchTolerance())
{ {
FatalErrorIn FatalErrorIn
( (
@ -224,13 +224,17 @@ void Foam::cyclicPolyPatch::calcTransforms
<< "patch:" << name() << "patch:" << name()
<< " my area:" << magSf << " my area:" << magSf
<< " neighbour area:" << nbrMagSf << " neighbour area:" << nbrMagSf
<< " matching tolerance:" << coupledPolyPatch::matchTol << " matching tolerance:" << matchTolerance()
<< endl << endl
<< "Mesh face:" << start()+facei << "Mesh face:" << start()+facei
<< " fc:" << half0Ctrs[facei] << " fc:" << half0Ctrs[facei]
<< endl << endl
<< "Neighbour fc:" << half1Ctrs[facei] << "Neighbour fc:" << half1Ctrs[facei]
<< endl << endl
<< "If you are certain your matching is correct"
<< " you can increase the 'matchTolerance' setting"
<< " in the patch dictionary in the boundary file."
<< endl
<< "Rerun with cyclic debug flag set" << "Rerun with cyclic debug flag set"
<< " for more information." << exit(FatalError); << " for more information." << exit(FatalError);
} }
@ -302,6 +306,7 @@ void Foam::cyclicPolyPatch::calcTransforms
( (
calcFaceTol calcFaceTol
( (
matchTolerance(),
half0, half0,
half0.points(), half0.points(),
static_cast<const pointField&>(half0Ctrs) static_cast<const pointField&>(half0Ctrs)
@ -315,7 +320,7 @@ void Foam::cyclicPolyPatch::calcTransforms
half0Normals, half0Normals,
half1Normals, half1Normals,
half0Tols, half0Tols,
matchTol, matchTolerance(),
transform_ transform_
); );
@ -506,7 +511,7 @@ void Foam::cyclicPolyPatch::getCentresAndAnchors
vector n1 = pp1[max1I].normal(pp1.points()); vector n1 = pp1[max1I].normal(pp1.points());
n1 /= mag(n1) + VSMALL; n1 /= mag(n1) + VSMALL;
if (mag(n0 & n1) < 1-coupledPolyPatch::matchTol) if (mag(n0 & n1) < 1-matchTolerance())
{ {
if (debug) if (debug)
{ {
@ -557,7 +562,7 @@ void Foam::cyclicPolyPatch::getCentresAndAnchors
// Calculate typical distance per face // Calculate typical distance per face
tols = calcFaceTol(pp1, pp1.points(), half1Ctrs); tols = calcFaceTol(matchTolerance(), pp1, pp1.points(), half1Ctrs);
} }
@ -1445,7 +1450,7 @@ bool Foam::cyclicPolyPatch::order
void Foam::cyclicPolyPatch::write(Ostream& os) const void Foam::cyclicPolyPatch::write(Ostream& os) const
{ {
polyPatch::write(os); coupledPolyPatch::write(os);
os.writeKeyword("neighbourPatch") << neighbPatchName_ os.writeKeyword("neighbourPatch") << neighbPatchName_
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
switch (transform_) switch (transform_)

View File

@ -386,7 +386,7 @@ void Foam::oldCyclicPolyPatch::getCentresAndAnchors
vector n1 = half1Faces[max1I].normal(pp.points()); vector n1 = half1Faces[max1I].normal(pp.points());
n1 /= mag(n1) + VSMALL; n1 /= mag(n1) + VSMALL;
if (mag(n0 & n1) < 1-coupledPolyPatch::matchTol) if (mag(n0 & n1) < 1-matchTolerance())
{ {
if (debug) if (debug)
{ {
@ -444,7 +444,7 @@ void Foam::oldCyclicPolyPatch::getCentresAndAnchors
// Calculate typical distance per face // Calculate typical distance per face
tols = calcFaceTol(half1Faces, pp.points(), half1Ctrs); tols = calcFaceTol(matchTolerance(), half1Faces, pp.points(), half1Ctrs);
} }

View File

@ -194,7 +194,7 @@ void Foam::processorPolyPatch::calcGeometry(PstreamBuffers& pBufs)
faceNormals[facei] = point(1, 0, 0); faceNormals[facei] = point(1, 0, 0);
nbrFaceNormals[facei] = faceNormals[facei]; nbrFaceNormals[facei] = faceNormals[facei];
} }
else if (mag(magSf - nbrMagSf)/avSf > coupledPolyPatch::matchTol) else if (mag(magSf - nbrMagSf)/avSf > matchTolerance())
{ {
fileName nm fileName nm
( (
@ -214,12 +214,16 @@ void Foam::processorPolyPatch::calcGeometry(PstreamBuffers& pBufs)
<< "patch:" << name() << "patch:" << name()
<< " my area:" << magSf << " my area:" << magSf
<< " neighbour area:" << nbrMagSf << " neighbour area:" << nbrMagSf
<< " matching tolerance:" << coupledPolyPatch::matchTol << " matching tolerance:" << matchTolerance()
<< endl << endl
<< "Mesh face:" << start()+facei << "Mesh face:" << start()+facei
<< " vertices:" << " vertices:"
<< UIndirectList<point>(points(), operator[](facei))() << UIndirectList<point>(points(), operator[](facei))()
<< endl << endl
<< "If you are certain your matching is correct"
<< " you can increase the 'matchTolerance' setting"
<< " in the patch dictionary in the boundary file."
<< endl
<< "Rerun with processor debug flag set for" << "Rerun with processor debug flag set for"
<< " more information." << exit(FatalError); << " more information." << exit(FatalError);
} }
@ -236,7 +240,8 @@ void Foam::processorPolyPatch::calcGeometry(PstreamBuffers& pBufs)
neighbFaceCentres_, neighbFaceCentres_,
faceNormals, faceNormals,
nbrFaceNormals, nbrFaceNormals,
calcFaceTol(*this, points(), faceCentres()) calcFaceTol(matchTolerance(), *this, points(), faceCentres()),
matchTolerance()
); );
} }
} }
@ -538,7 +543,10 @@ bool Foam::processorPolyPatch::order
} }
// Calculate typical distance from face centre // Calculate typical distance from face centre
scalarField tols(calcFaceTol(pp, pp.points(), pp.faceCentres())); scalarField tols
(
calcFaceTol(matchTolerance(), pp, pp.points(), pp.faceCentres())
);
if (debug || masterCtrs.size() != pp.size()) if (debug || masterCtrs.size() != pp.size())
{ {
@ -697,7 +705,7 @@ bool Foam::processorPolyPatch::order
void Foam::processorPolyPatch::write(Ostream& os) const void Foam::processorPolyPatch::write(Ostream& os) const
{ {
polyPatch::write(os); coupledPolyPatch::write(os);
os.writeKeyword("myProcNo") << myProcNo_ os.writeKeyword("myProcNo") << myProcNo_
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
os.writeKeyword("neighbProcNo") << neighbProcNo_ os.writeKeyword("neighbProcNo") << neighbProcNo_

View File

@ -125,6 +125,7 @@ void Foam::globalIndexAndTransform::determineTransforms()
const polyBoundaryMesh& patches = mesh_.boundaryMesh(); const polyBoundaryMesh& patches = mesh_.boundaryMesh();
transforms_ = List<vectorTensorTransform>(6); transforms_ = List<vectorTensorTransform>(6);
scalarField maxTol(6);
label nextTrans = 0; label nextTrans = 0;
@ -148,8 +149,6 @@ void Foam::globalIndexAndTransform::determineTransforms()
if (mag(sepVec) > SMALL) if (mag(sepVec) > SMALL)
{ {
scalar tol = coupledPolyPatch::matchTol;
vectorTensorTransform transform(sepVec); vectorTensorTransform transform(sepVec);
if if
@ -159,12 +158,13 @@ void Foam::globalIndexAndTransform::determineTransforms()
transforms_, transforms_,
dummyMatch, dummyMatch,
transform, transform,
tol, cpp.matchTolerance(),
false false
) == 0 ) == 0
) )
{ {
transforms_[nextTrans++] = transform; transforms_[nextTrans] = transform;
maxTol[nextTrans++] = cpp.matchTolerance();
} }
if (nextTrans > 6) if (nextTrans > 6)
@ -191,8 +191,6 @@ void Foam::globalIndexAndTransform::determineTransforms()
if (mag(transT - I) > SMALL) if (mag(transT - I) > SMALL)
{ {
scalar tol = coupledPolyPatch::matchTol;
vectorTensorTransform transform(transT); vectorTensorTransform transform(transT);
if if
@ -202,12 +200,13 @@ void Foam::globalIndexAndTransform::determineTransforms()
transforms_, transforms_,
dummyMatch, dummyMatch,
transform, transform,
tol, cpp.matchTolerance(),
false false
) == 0 ) == 0
) )
{ {
transforms_[nextTrans++] = transform; transforms_[nextTrans] = transform;
maxTol[nextTrans++] = cpp.matchTolerance();
} }
if (nextTrans > 6) if (nextTrans > 6)
@ -227,12 +226,18 @@ void Foam::globalIndexAndTransform::determineTransforms()
} }
} }
// Collect transforms on master
List<List<vectorTensorTransform> > allTransforms(Pstream::nProcs()); List<List<vectorTensorTransform> > allTransforms(Pstream::nProcs());
allTransforms[Pstream::myProcNo()] = transforms_; allTransforms[Pstream::myProcNo()] = transforms_;
Pstream::gatherList(allTransforms); Pstream::gatherList(allTransforms);
// Collect matching tolerance on master
List<scalarField> allTols(Pstream::nProcs());
allTols[Pstream::myProcNo()] = maxTol;
Pstream::gatherList(allTols);
if (Pstream::master()) if (Pstream::master())
{ {
transforms_ = List<vectorTensorTransform>(3); transforms_ = List<vectorTensorTransform>(3);
@ -250,8 +255,6 @@ void Foam::globalIndexAndTransform::determineTransforms()
if (mag(transform.t()) > SMALL || transform.hasR()) if (mag(transform.t()) > SMALL || transform.hasR())
{ {
scalar tol = coupledPolyPatch::matchTol;
if if
( (
matchTransform matchTransform
@ -259,7 +262,7 @@ void Foam::globalIndexAndTransform::determineTransforms()
transforms_, transforms_,
dummyMatch, dummyMatch,
transform, transform,
tol, allTols[procI][pSVI],
true true
) == 0 ) == 0
) )
@ -378,8 +381,6 @@ void Foam::globalIndexAndTransform::determinePatchTransformSign()
if (mag(sepVec) > SMALL) if (mag(sepVec) > SMALL)
{ {
scalar tol = coupledPolyPatch::matchTol;
vectorTensorTransform t(sepVec); vectorTensorTransform t(sepVec);
label sign = matchTransform label sign = matchTransform
@ -387,7 +388,7 @@ void Foam::globalIndexAndTransform::determinePatchTransformSign()
transforms_, transforms_,
matchTransI, matchTransI,
t, t,
tol, cpp.matchTolerance(),
true true
); );
@ -424,8 +425,6 @@ void Foam::globalIndexAndTransform::determinePatchTransformSign()
if (mag(transT - I) > SMALL) if (mag(transT - I) > SMALL)
{ {
scalar tol = coupledPolyPatch::matchTol;
vectorTensorTransform t(transT); vectorTensorTransform t(transT);
label sign = matchTransform label sign = matchTransform
@ -433,7 +432,7 @@ void Foam::globalIndexAndTransform::determinePatchTransformSign()
transforms_, transforms_,
matchTransI, matchTransI,
t, t,
tol, cpp.matchTolerance(),
true true
); );

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -52,17 +52,6 @@ void Foam::cyclicFvPatch::makeWeights(scalarField& w) const
forAll(magFa, facei) forAll(magFa, facei)
{ {
scalar avFa = (magFa[facei] + nbrMagFa[facei])/2.0;
if (mag(magFa[facei] - nbrMagFa[facei])/avFa > 1e-4)
{
FatalErrorIn("cyclicFvPatch::makeWeights(scalarField&) const")
<< "face " << facei << " areas do not match by "
<< 100*mag(magFa[facei] - nbrMagFa[facei])/avFa
<< "% -- possible face ordering problem"
<< abort(FatalError);
}
scalar di = deltas[facei]; scalar di = deltas[facei];
scalar dni = nbrDeltas[facei]; scalar dni = nbrDeltas[facei];