coupleGroupIdentifier.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2013-2015 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "coupleGroupIdentifier.H"
30 #include "polyMesh.H"
31 #include "Time.H"
32 
33 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34 
35 Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
36 (
37  const polyMesh& mesh,
38  const polyPatch& thisPatch
39 ) const
40 {
41  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
42 
43  if (!valid())
44  {
46  << "Invalid coupleGroup patch group"
47  << " on patch " << thisPatch.name()
48  << " in region " << pbm.mesh().name()
49  << exit(FatalError);
50  }
51 
52  const auto fnd = pbm.groupPatchIDs().cfind(name());
53 
54  if (!fnd.found())
55  {
56  if (&mesh == &thisPatch.boundaryMesh().mesh())
57  {
58  // thisPatch should be in patchGroup
60  << "Patch " << thisPatch.name()
61  << " should be in patchGroup " << name()
62  << " in region " << pbm.mesh().name()
63  << exit(FatalError);
64  }
65 
66  return -1;
67  }
68 
69  // Mesh has patch group
70  const labelList& patchIDs = fnd.val();
71 
72  if (&mesh == &thisPatch.boundaryMesh().mesh())
73  {
74  if (patchIDs.size() > 2 || patchIDs.size() == 0)
75  {
77  << "Couple patchGroup " << name()
78  << " with contents " << patchIDs
79  << " not of size < 2"
80  << " on patch " << thisPatch.name()
81  << " region " << thisPatch.boundaryMesh().mesh().name()
82  << exit(FatalError);
83 
84  return -1;
85  }
86 
87  label index = patchIDs.find(thisPatch.index());
88 
89  if (index == -1)
90  {
92  << "Couple patchGroup " << name()
93  << " with contents " << patchIDs
94  << " does not contain patch " << thisPatch.name()
95  << " in region " << pbm.mesh().name()
96  << exit(FatalError);
97 
98  return -1;
99  }
100 
101 
102  if (patchIDs.size() == 2)
103  {
104  // Return the other patch
105  return patchIDs[1-index];
106  }
107  else // size == 1
108  {
109  return -1;
110  }
111  }
112  else
113  {
114  if (patchIDs.size() != 1)
115  {
117  << "Couple patchGroup " << name()
118  << " with contents " << patchIDs
119  << " in region " << mesh.name()
120  << " should only contain a single patch"
121  << " when matching patch " << thisPatch.name()
122  << " in region " << pbm.mesh().name()
123  << exit(FatalError);
124  }
125 
126  return patchIDs[0];
127  }
128 }
129 
130 
131 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
132 
134 {
135  dict.readIfPresent("coupleGroup", name_);
136 }
137 
138 
139 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
140 
141 Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
142 (
143  const polyPatch& thisPatch
144 ) const
145 {
146  const polyBoundaryMesh& pbm = thisPatch.boundaryMesh();
147 
148  return findOtherPatchID(pbm.mesh(), thisPatch);
149 }
150 
151 
152 Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
153 (
154  const polyPatch& thisPatch,
155  word& otherRegion
156 ) const
157 {
158  const polyBoundaryMesh& pbm = thisPatch.boundaryMesh();
159  const polyMesh& thisMesh = pbm.mesh();
160  const Time& runTime = thisMesh.time();
161 
162 
163  // Loop over all regions to find other patch in coupleGroup
165 
166  label otherPatchID = -1;
167 
168  forAllConstIters(meshSet, iter)
169  {
170  const polyMesh& mesh = *iter();
171 
172  const label patchID = findOtherPatchID(mesh, thisPatch);
173 
174  if (patchID != -1)
175  {
176  if (otherPatchID != -1)
177  {
179  << "Couple patchGroup " << name()
180  << " should be present on only two patches"
181  << " in any of the meshes in " << meshSet.sortedToc()
182  << endl
183  << " It seems to be present on patch "
184  << thisPatch.name()
185  << " in region " << thisMesh.name()
186  << ", on patch " << otherPatchID
187  << " in region " << otherRegion
188  << " and on patch " << patchID
189  << " in region " << mesh.name()
190  << exit(FatalError);
191  }
192  otherPatchID = patchID;
193  otherRegion = mesh.name();
194  }
195  }
196 
197  if (otherPatchID == -1)
198  {
200  << "Couple patchGroup " << name()
201  << " not found in any of the other meshes " << meshSet.sortedToc()
202  << " on patch " << thisPatch.name()
203  << " region " << thisMesh.name()
204  << exit(FatalError);
205  }
206 
207  return otherPatchID;
208 }
209 
210 
212 {
213  if (!name_.empty())
214  {
215  os.writeEntry("coupleGroup", name_);
216  }
217 }
218 
219 
220 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
221 
223 {
224  ident.write(os);
226  return os;
227 }
228 
229 
230 // ************************************************************************* //
Foam::coupleGroupIdentifier
Encapsulates using "patchGroups" to specify coupled patch.
Definition: coupleGroupIdentifier.H:57
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:63
coupleGroupIdentifier.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::objectRegistry::lookupClass
HashTable< const Type * > lookupClass(const bool strict=false) const
Return all objects with a class satisfying isA<Type>
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::polyBoundaryMesh::mesh
const polyMesh & mesh() const noexcept
Return the mesh reference.
Definition: polyBoundaryMesh.H:152
Foam::polyPatch::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:315
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
patchID
label patchID
Definition: boundaryProcessorFaPatchPoints.H:5
Foam::coupleGroupIdentifier::name
const word & name() const noexcept
Name of patchGroup.
Definition: coupleGroupIdentifier.H:99
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::HashTable::sortedToc
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:136
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::HashTable
A HashTable similar to std::unordered_map.
Definition: HashTable.H:105
Foam::IOobject::name
const word & name() const noexcept
Return name.
Definition: IOobjectI.H:65
Time.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::coupleGroupIdentifier::write
void write(Ostream &os) const
Write the coupleGroup dictionary entry.
Definition: coupleGroupIdentifier.C:211
Foam::coupleGroupIdentifier::coupleGroupIdentifier
coupleGroupIdentifier()=default
Default construct.
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:236
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::patchIdentifier::name
const word & name() const noexcept
The patch name.
Definition: patchIdentifier.H:135
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::objectRegistry::time
const Time & time() const noexcept
Return time registry.
Definition: objectRegistry.H:178
Foam::dictionary::readIfPresent
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:405
Foam::fvMesh::name
const word & name() const
Return reference to name.
Definition: fvMesh.H:300
Foam::coupleGroupIdentifier::valid
bool valid() const noexcept
Is a valid patchGroup (non-empty) name.
Definition: coupleGroupIdentifier.H:105