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()
205  }
206 
207  return otherPatchID;
208 }
209 
210 
211 void Foam::coupleGroupIdentifier::write(Ostream& os) const
212 {
213  if (!name_.empty())
214  {
215  os.writeEntry("coupleGroup", name_);
216  }
217 }
218 
219 
220 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
221 
222 Foam::Ostream& Foam::operator<<(Ostream& os, const coupleGroupIdentifier& ident)
223 {
224  ident.write(os);
226  return os;
227 }
228 
229 
230 // ************************************************************************* //
dictionary dict
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:45
bool valid() const noexcept
Is a valid patchGroup (non-empty) name.
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:150
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:309
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:312
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
const word & name() const noexcept
Name of patchGroup.
dynamicFvMesh & mesh
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
const polyMesh & mesh() const noexcept
Return the mesh reference.
A class for handling words, derived from Foam::string.
Definition: word.H:63
const Time & time() const noexcept
Return time registry.
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
A HashTable similar to std::unordered_map.
Definition: HashTable.H:102
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO...
const word & name() const noexcept
The patch name.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:55
bool readIfPresent(const word &keyword, T &val, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry if present, and assign to T val. FatalIOError if it is found and the number of tokens i...
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:76
const word & name() const
Return reference to name.
Definition: fvMesh.H:388
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition: HashTable.C:130
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:73
List< label > labelList
A List of labels.
Definition: List.H:62
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
void write(Ostream &os) const
Write the coupleGroup dictionary entry.
HashTable< const Type * > lookupClass(const bool strict=false) const
Return all objects with a class satisfying isA<Type>
coupleGroupIdentifier()=default
Default construct.
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28