ENH: cyclic: added patchGroup coupling

This commit is contained in:
mattijs
2013-11-13 18:07:40 +00:00
parent 40df4488fc
commit 99401a4d54
11 changed files with 97 additions and 33 deletions

View File

@ -125,7 +125,7 @@ void Foam::cyclicAMIPolyPatch::calcTransforms
FatalErrorIn("cyclicAMIPolyPatch::calcTransforms()")
<< "Patch " << name()
<< " has transform type " << transformTypeNames[transform()]
<< ", neighbour patch " << nbrPatchName_
<< ", neighbour patch " << neighbPatchName()
<< " has transform type "
<< neighbPatch().transformTypeNames[neighbPatch().transform()]
<< exit(FatalError);
@ -416,7 +416,8 @@ Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch
)
:
coupledPolyPatch(name, dict, index, bm, patchType),
nbrPatchName_(dict.lookup("neighbourPatch")),
nbrPatchName_(dict.lookupOrDefault<word>("neighbourPatch", "")),
coupleGroup_(dict),
nbrPatchID_(-1),
rotationAxis_(vector::zero),
rotationCentre_(point::zero),
@ -426,6 +427,22 @@ Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch
surfPtr_(NULL),
surfDict_(dict.subOrEmptyDict("surface"))
{
if (nbrPatchName_ == word::null && !coupleGroup_.valid())
{
FatalIOErrorIn
(
"cyclicAMIPolyPatch::cyclicAMIPolyPatch"
"("
"const word&, "
"const dictionary&, "
"const label, "
"const polyBoundaryMesh&"
")",
dict
) << "No \"neighbourPatch\" or \"coupleGroup\" provided."
<< exit(FatalIOError);
}
if (nbrPatchName_ == name)
{
FatalIOErrorIn
@ -495,6 +512,7 @@ Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch
:
coupledPolyPatch(pp, bm),
nbrPatchName_(pp.nbrPatchName_),
coupleGroup_(pp.coupleGroup_),
nbrPatchID_(-1),
rotationAxis_(pp.rotationAxis_),
rotationCentre_(pp.rotationCentre_),
@ -521,6 +539,7 @@ Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch
:
coupledPolyPatch(pp, bm, index, newSize, newStart),
nbrPatchName_(nbrPatchName),
coupleGroup_(pp.coupleGroup_),
nbrPatchID_(-1),
rotationAxis_(pp.rotationAxis_),
rotationCentre_(pp.rotationCentre_),
@ -561,6 +580,7 @@ Foam::cyclicAMIPolyPatch::cyclicAMIPolyPatch
:
coupledPolyPatch(pp, bm, index, mapAddressing, newStart),
nbrPatchName_(pp.nbrPatchName_),
coupleGroup_(pp.coupleGroup_),
nbrPatchID_(-1),
rotationAxis_(pp.rotationAxis_),
rotationCentre_(pp.rotationCentre_),
@ -584,12 +604,12 @@ Foam::label Foam::cyclicAMIPolyPatch::neighbPatchID() const
{
if (nbrPatchID_ == -1)
{
nbrPatchID_ = this->boundaryMesh().findPatchID(nbrPatchName_);
nbrPatchID_ = this->boundaryMesh().findPatchID(neighbPatchName());
if (nbrPatchID_ == -1)
{
FatalErrorIn("cyclicPolyAMIPatch::neighbPatchID() const")
<< "Illegal neighbourPatch name " << nbrPatchName_
<< "Illegal neighbourPatch name " << neighbPatchName()
<< nl << "Valid patch names are "
<< this->boundaryMesh().names()
<< exit(FatalError);
@ -832,8 +852,12 @@ Foam::label Foam::cyclicAMIPolyPatch::pointFace
void Foam::cyclicAMIPolyPatch::write(Ostream& os) const
{
coupledPolyPatch::write(os);
os.writeKeyword("neighbourPatch") << nbrPatchName_
<< token::END_STATEMENT << nl;
if (!nbrPatchName_.empty())
{
os.writeKeyword("neighbourPatch") << nbrPatchName_
<< token::END_STATEMENT << nl;
}
coupleGroup_.write(os);
switch (transform())
{

View File

@ -38,6 +38,7 @@ SourceFiles
#include "coupledPolyPatch.H"
#include "AMIPatchToPatchInterpolation.H"
#include "polyBoundaryMesh.H"
#include "coupleGroupIdentifier.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -58,7 +59,10 @@ private:
// Private data
//- Name of other half
const word nbrPatchName_;
mutable word nbrPatchName_;
//- Optional patchGroup to find neighbPatch
const coupleGroupIdentifier coupleGroup_;
//- Index of other half
mutable label nbrPatchID_;

View File

@ -27,6 +27,13 @@ License
inline const Foam::word& Foam::cyclicAMIPolyPatch::neighbPatchName() const
{
if (nbrPatchName_.empty())
{
// Try and use patchGroup to find samplePatch and sampleRegion
label patchID = coupleGroup_.findOtherPatchID(*this);
nbrPatchName_ = boundaryMesh()[patchID].name();
}
return nbrPatchName_;
}

View File

@ -199,7 +199,6 @@ mappedPatches/mappedPolyPatch/mappedPatchBase.C
mappedPatches/mappedPolyPatch/mappedPolyPatch.C
mappedPatches/mappedPolyPatch/mappedWallPolyPatch.C
mappedPatches/mappedPolyPatch/mappedVariableThicknessWallPolyPatch.C
mappedPatches/mappedPolyPatch/coupleGroupIdentifier.C
mappedPatches/mappedPointPatch/mappedPointPatch.C
mappedPatches/mappedPointPatch/mappedWallPointPatch.C

View File

@ -1,260 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "coupleGroupIdentifier.H"
#include "polyMesh.H"
#include "Time.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
(
const polyMesh& mesh,
const polyPatch& thisPatch
) const
{
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
if (!valid())
{
FatalErrorIn
(
"coupleGroupIdentifier::findOtherPatchID(const polyPatch&) const"
) << "Invalid coupleGroup patch group"
<< " on patch " << thisPatch.name()
<< " in region " << pbm.mesh().name()
<< exit(FatalError);
}
HashTable<labelList, word>::const_iterator fnd =
pbm.groupPatchIDs().find(name());
if (fnd == pbm.groupPatchIDs().end())
{
if (&mesh == &thisPatch.boundaryMesh().mesh())
{
// thisPatch should be in patchGroup
FatalErrorIn
(
"coupleGroupIdentifier::findOtherPatchID"
"(const polyMesh&, const polyPatch&) const"
) << "Patch " << thisPatch.name()
<< " should be in patchGroup " << name()
<< " in region " << pbm.mesh().name()
<< exit(FatalError);
}
return -1;
}
// Mesh has patch group
const labelList& patchIDs = fnd();
if (&mesh == &thisPatch.boundaryMesh().mesh())
{
if (patchIDs.size() > 2 || patchIDs.size() == 0)
{
FatalErrorIn
(
"coupleGroupIdentifier::findOtherPatchID"
"(const polyMesh&, const polyPatch&) const"
) << "Couple patchGroup " << name()
<< " with contents " << patchIDs
<< " not of size < 2"
<< " on patch " << thisPatch.name()
<< " region " << thisPatch.boundaryMesh().mesh().name()
<< exit(FatalError);
return -1;
}
label index = findIndex(patchIDs, thisPatch.index());
if (index == -1)
{
FatalErrorIn
(
"coupleGroupIdentifier::findOtherPatchID"
"(const polyMesh&, const polyPatch&) const"
) << "Couple patchGroup " << name()
<< " with contents " << patchIDs
<< " does not contain patch " << thisPatch.name()
<< " in region " << pbm.mesh().name()
<< exit(FatalError);
return -1;
}
if (patchIDs.size() == 2)
{
// Return the other patch
return patchIDs[1-index];
}
else // size == 1
{
return -1;
}
}
else
{
if (patchIDs.size() != 1)
{
FatalErrorIn
(
"coupleGroupIdentifier::findOtherPatchID"
"(const polyMesh&, const polyPatch&) const"
) << "Couple patchGroup " << name()
<< " with contents " << patchIDs
<< " in region " << mesh.name()
<< " should only contain a single patch"
<< " when matching patch " << thisPatch.name()
<< " in region " << pbm.mesh().name()
<< exit(FatalError);
}
return patchIDs[0];
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::coupleGroupIdentifier::coupleGroupIdentifier()
:
name_()
{}
Foam::coupleGroupIdentifier::coupleGroupIdentifier(const word& name)
:
name_(name)
{}
Foam::coupleGroupIdentifier::coupleGroupIdentifier(const dictionary& dict)
:
name_(dict.lookupOrDefault<word>("coupleGroup", ""))
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
(
const polyPatch& thisPatch
) const
{
const polyBoundaryMesh& pbm = thisPatch.boundaryMesh();
return findOtherPatchID(pbm.mesh(), thisPatch);
}
Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
(
const polyPatch& thisPatch,
word& otherRegion
) const
{
const polyBoundaryMesh& pbm = thisPatch.boundaryMesh();
const polyMesh& thisMesh = pbm.mesh();
const Time& runTime = thisMesh.time();
// Loop over all regions to find other patch in coupleGroup
HashTable<const polyMesh*> meshSet = runTime.lookupClass<polyMesh>();
label otherPatchID = -1;
forAllConstIter(HashTable<const polyMesh*>, meshSet, iter)
{
const polyMesh& mesh = *iter();
label patchID = findOtherPatchID(mesh, thisPatch);
if (patchID != -1)
{
if (otherPatchID != -1)
{
FatalErrorIn
(
"coupleGroupIdentifier::findOtherPatchID"
"(const polyPatch&, word&) const"
) << "Couple patchGroup " << name()
<< " should be present on only two patches"
<< " in any of the meshes in " << meshSet.sortedToc()
<< endl
<< " It seems to be present on patch "
<< thisPatch.name()
<< " in region " << thisMesh.name()
<< ", on patch " << otherPatchID
<< " in region " << otherRegion
<< " and on patch " << patchID
<< " in region " << mesh.name()
<< exit(FatalError);
}
otherPatchID = patchID;
otherRegion = mesh.name();
}
}
if (otherPatchID == -1)
{
FatalErrorIn
(
"coupleGroupIdentifier::findOtherPatchID"
"(const polyPatch&, word&) const"
) << "Couple patchGroup " << name()
<< " not found in any of the other meshes " << meshSet.sortedToc()
<< " on patch " << thisPatch.name()
<< " region " << thisMesh.name()
<< exit(FatalError);
}
return otherPatchID;
}
void Foam::coupleGroupIdentifier::write(Ostream& os) const
{
if (valid())
{
os.writeKeyword("coupleGroup") << name() << token::END_STATEMENT << nl;
}
}
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const coupleGroupIdentifier& p)
{
p.write(os);
os.check("Ostream& operator<<(Ostream& os, const coupleGroupIdentifier& p");
return os;
}
// ************************************************************************* //

View File

@ -1,128 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::coupleGroupIdentifier
Description
Encapsulates using patchGroups to specify coupled patch
SourceFiles
coupleGroupIdentifierI.H
coupleGroupIdentifier.C
coupleGroupIdentifierIO.C
\*---------------------------------------------------------------------------*/
#ifndef coupleGroupIdentifier_H
#define coupleGroupIdentifier_H
#include "word.H"
#include "label.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class dictionary;
class polyMesh;
class polyPatch;
class Ostream;
// Forward declaration of friend functions and operators
class coupleGroupIdentifier;
Ostream& operator<<(Ostream&, const coupleGroupIdentifier&);
/*---------------------------------------------------------------------------*\
Class coupleGroupIdentifier Declaration
\*---------------------------------------------------------------------------*/
class coupleGroupIdentifier
{
// Private data
//- Name of patchGroup
word name_;
// Private Member Functions
//- Find other patch in specified mesh. Returns index of patch or -1.
label findOtherPatchID(const polyMesh&, const polyPatch&) const;
public:
// Constructors
//- Construct null
coupleGroupIdentifier();
//- Construct from components
coupleGroupIdentifier(const word& patchGroupName);
//- Construct from dictionary
coupleGroupIdentifier(const dictionary&);
// Member Functions
//- Name of patchGroup
inline const word& name() const;
//- Is a valid patchGroup
inline bool valid() const;
//- Find other patch in same region. Returns index of patch or -1.
label findOtherPatchID(const polyPatch&) const;
//- Find other patch and region. Returns index of patch and sets
// otherRegion to name of region. Fatal error if patch not found
label findOtherPatchID(const polyPatch&, word&) const;
//- Write the data as a dictionary
void write(Ostream&) const;
// IOstream Operators
friend Ostream& operator<<(Ostream&, const coupleGroupIdentifier&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "coupleGroupIdentifierI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,42 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "coupleGroupIdentifier.H"
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
const Foam::word& Foam::coupleGroupIdentifier::name() const
{
return name_;
}
bool Foam::coupleGroupIdentifier::valid() const
{
return !name_.empty();
}
// ************************************************************************* //

View File

@ -1402,10 +1402,16 @@ void Foam::mappedPatchBase::write(Ostream& os) const
{
os.writeKeyword("sampleMode") << sampleModeNames_[mode_]
<< token::END_STATEMENT << nl;
os.writeKeyword("sampleRegion") << sampleRegion()
<< token::END_STATEMENT << nl;
os.writeKeyword("samplePatch") << samplePatch()
<< token::END_STATEMENT << nl;
if (!sampleRegion_.empty())
{
os.writeKeyword("sampleRegion") << sampleRegion_
<< token::END_STATEMENT << nl;
}
if (!samplePatch_.empty())
{
os.writeKeyword("samplePatch") << samplePatch_
<< token::END_STATEMENT << nl;
}
coupleGroup_.write(os);
if