mappedPatchBase: Added user control of matchTolerance
The tolerance used for geometric checking and transformation calculation between mapped patches can now be set per patch by the user. A "matchTolerance" setting can be specified in the mapped patches' dictionaries in the "polyMesh/boundary" file. The default remains 1e-4. This is exactly the same control as is used for cyclic patches. The error message that is generated when the geometric check fails has also been improved to provide better information and more explicit instruction as to how to resolve the problem.
This commit is contained in:
@ -26,6 +26,7 @@ License
|
||||
#include "cyclicTransform.H"
|
||||
#include "unitConversion.H"
|
||||
#include "IOmanip.H"
|
||||
#include "stringOps.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -512,19 +513,25 @@ Foam::cyclicTransform::cyclicTransform
|
||||
|
||||
if (ctrNbrCtrTDistance > lengthScale*matchTolerance)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "The distance between the centre of patch " << name
|
||||
<< " and the transformed centre of patch " << nbrName << " is "
|
||||
<< ctrNbrCtrTDistance << "."
|
||||
<< nl
|
||||
<< "This is greater than the match tolerance of "
|
||||
<< lengthScale*matchTolerance << " for the patch."
|
||||
<< nl
|
||||
OStringStream str;
|
||||
|
||||
str << nl
|
||||
<< "Patches " << name << " and " << nbrName << " are potentially "
|
||||
<< "not geometrically similar enough to be coupled." << nl << nl
|
||||
<< "The distance between the transformed centres of these patches "
|
||||
<< "is " << ctrNbrCtrTDistance << ", which is greater than the "
|
||||
<< "patch length scale (" << lengthScale << ") multiplied by the "
|
||||
<< "match tolerance (" << matchTolerance << ")." << nl << nl
|
||||
<< "Check that the patches are geometrically similar and that any "
|
||||
<< "transformations defined between them are correct"
|
||||
<< nl
|
||||
<< "It might be possible to fix this problem by increasing the "
|
||||
<< "\"matchTolerance\" setting for this patch in the boundary "
|
||||
<< "transformations defined between them are correct." << nl << nl
|
||||
<< "If the patches and their transformations are defined correctly "
|
||||
<< "but small irregularities in the mesh mean this geometric test "
|
||||
<< "is failing, then it might be appropriate to relax the failure "
|
||||
<< "criteria by increasing the \"matchTolerance\" setting for "
|
||||
<< "these patches in the \"polyMesh/boundary\" file.";
|
||||
|
||||
FatalErrorInFunction
|
||||
<< stringOps::breakIntoIndentedLines(str.str(), 80, 4).c_str()
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -946,4 +946,60 @@ Foam::string& Foam::stringOps::inplaceTrim(string& s)
|
||||
}
|
||||
|
||||
|
||||
Foam::string Foam::stringOps::breakIntoIndentedLines
|
||||
(
|
||||
const string& message,
|
||||
const string::size_type nLength,
|
||||
const string::size_type nIndent
|
||||
)
|
||||
{
|
||||
const string indent(nIndent, token::SPACE);
|
||||
|
||||
string result;
|
||||
|
||||
word::size_type i0 = 0, i1 = 0;
|
||||
while (true)
|
||||
{
|
||||
const word::size_type iNewLine =
|
||||
message.find_first_of(token::NL, i1);
|
||||
const word::size_type iSpace =
|
||||
message.find_first_of(token::SPACE, i1);
|
||||
|
||||
// New line next
|
||||
if
|
||||
(
|
||||
iNewLine != string::npos
|
||||
&& (iSpace == string::npos || iNewLine < iSpace)
|
||||
)
|
||||
{
|
||||
result += indent + message.substr(i0, iNewLine - i0) + '\n';
|
||||
i0 = i1 = iNewLine + 1;
|
||||
}
|
||||
|
||||
// Space next
|
||||
else if (iSpace != string::npos)
|
||||
{
|
||||
if (iSpace - i0 > nLength - nIndent)
|
||||
{
|
||||
result += indent + message.substr(i0, i1 - i0) + '\n';
|
||||
i0 = i1;
|
||||
}
|
||||
else
|
||||
{
|
||||
i1 = iSpace + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// End of string
|
||||
else
|
||||
{
|
||||
result += indent + message.substr(i0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration | Website: https://openfoam.org
|
||||
\\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -292,6 +292,15 @@ namespace stringOps
|
||||
string& inplaceTrim(string&);
|
||||
|
||||
|
||||
//- Break a string up into indented lines
|
||||
string breakIntoIndentedLines
|
||||
(
|
||||
const string& str,
|
||||
const string::size_type nLength = 80,
|
||||
const string::size_type nIndent = 0
|
||||
);
|
||||
|
||||
|
||||
} // End namespace stringOps
|
||||
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(mappedPatchBase, 0);
|
||||
|
||||
const scalar mappedPatchBase::matchTol_ = 1e-4;
|
||||
const scalar mappedPatchBase::defaultMatchTol_ = 1e-4;
|
||||
}
|
||||
|
||||
|
||||
@ -86,7 +86,7 @@ void Foam::mappedPatchBase::calcMapping() const
|
||||
nbrPatchIsMapped()
|
||||
? nbrMappedPatch().transform_
|
||||
: cyclicTransform(false),
|
||||
mappedPatchBase::matchTol_,
|
||||
matchTol_,
|
||||
true
|
||||
);
|
||||
|
||||
@ -327,7 +327,8 @@ Foam::mappedPatchBase::mappedPatchBase
|
||||
nbrPatchFaceIndices_(),
|
||||
patchToPatchIsUsed_(false),
|
||||
patchToPatchIsValid_(false),
|
||||
patchToPatchPtr_(nullptr)
|
||||
patchToPatchPtr_(nullptr),
|
||||
matchTol_(defaultMatchTol_)
|
||||
{}
|
||||
|
||||
|
||||
@ -348,7 +349,8 @@ Foam::mappedPatchBase::mappedPatchBase
|
||||
nbrPatchFaceIndices_(),
|
||||
patchToPatchIsUsed_(false),
|
||||
patchToPatchIsValid_(false),
|
||||
patchToPatchPtr_(nullptr)
|
||||
patchToPatchPtr_(nullptr),
|
||||
matchTol_(defaultMatchTol_)
|
||||
{}
|
||||
|
||||
|
||||
@ -396,7 +398,8 @@ Foam::mappedPatchBase::mappedPatchBase
|
||||
false
|
||||
).ptr()
|
||||
: nullptr
|
||||
)
|
||||
),
|
||||
matchTol_(dict.lookupOrDefault("matchTolerance", defaultMatchTol_))
|
||||
{
|
||||
if (!coupleGroup_.valid() && nbrRegionName_.empty())
|
||||
{
|
||||
@ -425,7 +428,8 @@ Foam::mappedPatchBase::mappedPatchBase
|
||||
patchToPatchIsUsed_
|
||||
? patchToPatch::New(mpb.patchToPatchPtr_->type(), false).ptr()
|
||||
: nullptr
|
||||
)
|
||||
),
|
||||
matchTol_(mpb.matchTol_)
|
||||
{}
|
||||
|
||||
|
||||
@ -495,6 +499,8 @@ void Foam::mappedPatchBase::write(Ostream& os) const
|
||||
{
|
||||
writeEntry(os, "method", patchToPatchPtr_->type());
|
||||
}
|
||||
|
||||
writeEntryIfDifferent(os, "matchTolerance", defaultMatchTol_, matchTol_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -106,8 +106,11 @@ protected:
|
||||
//- Patch-to-patch intersection engine (if using patch-to-patch)
|
||||
mutable autoPtr<patchToPatch> patchToPatchPtr_;
|
||||
|
||||
//- Default Matching tolerance
|
||||
static const scalar defaultMatchTol_;
|
||||
|
||||
//- Matching tolerance
|
||||
static const scalar matchTol_;
|
||||
const scalar matchTol_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
Reference in New Issue
Block a user