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  name_()
136 {
137  dict.readIfPresent("coupleGroup", name_);
138 }
139 
140 
141 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
142 
143 Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
144 (
145  const polyPatch& thisPatch
146 ) const
147 {
148  const polyBoundaryMesh& pbm = thisPatch.boundaryMesh();
149 
150  return findOtherPatchID(pbm.mesh(), thisPatch);
151 }
152 
153 
154 Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
155 (
156  const polyPatch& thisPatch,
157  word& otherRegion
158 ) const
159 {
160  const polyBoundaryMesh& pbm = thisPatch.boundaryMesh();
161  const polyMesh& thisMesh = pbm.mesh();
162  const Time& runTime = thisMesh.time();
163 
164 
165  // Loop over all regions to find other patch in coupleGroup
167 
168  label otherPatchID = -1;
169 
170  forAllConstIters(meshSet, iter)
171  {
172  const polyMesh& mesh = *iter();
173 
174  const label patchID = findOtherPatchID(mesh, thisPatch);
175 
176  if (patchID != -1)
177  {
178  if (otherPatchID != -1)
179  {
181  << "Couple patchGroup " << name()
182  << " should be present on only two patches"
183  << " in any of the meshes in " << meshSet.sortedToc()
184  << endl
185  << " It seems to be present on patch "
186  << thisPatch.name()
187  << " in region " << thisMesh.name()
188  << ", on patch " << otherPatchID
189  << " in region " << otherRegion
190  << " and on patch " << patchID
191  << " in region " << mesh.name()
192  << exit(FatalError);
193  }
194  otherPatchID = patchID;
195  otherRegion = mesh.name();
196  }
197  }
198 
199  if (otherPatchID == -1)
200  {
202  << "Couple patchGroup " << name()
203  << " not found in any of the other meshes " << meshSet.sortedToc()
204  << " on patch " << thisPatch.name()
205  << " region " << thisMesh.name()
206  << exit(FatalError);
207  }
208 
209  return otherPatchID;
210 }
211 
212 
214 {
215  if (valid())
216  {
217  os.writeEntry("coupleGroup", name());
218  }
219 }
220 
221 
222 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
223 
225 {
226  p.write(os);
227  os.check(FUNCTION_NAME);
228  return os;
229 }
230 
231 
232 // ************************************************************************* //
Foam::coupleGroupIdentifier
Encapsulates using "patchGroups" to specify coupled patch.
Definition: coupleGroupIdentifier.H:58
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
runTime
engineTime & runTime
Definition: createEngineTime.H:13
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:70
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
coupleGroupIdentifier.H
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:186
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
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::polyPatch::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:307
Foam::coupleGroupIdentifier::name
const word & name() const
Name of patchGroup.
Definition: coupleGroupIdentifierI.H:41
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
patchID
label patchID
Definition: boundaryProcessorFaPatchPoints.H:5
Foam::polyBoundaryMesh::mesh
const polyMesh & mesh() const
Return the mesh reference.
Definition: polyBoundaryMesh.H:144
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:51
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:121
Foam::coupleGroupIdentifier::valid
bool valid() const
Is a valid patchGroup.
Definition: coupleGroupIdentifierI.H:47
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
Time.H
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
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:213
Foam::coupleGroupIdentifier::coupleGroupIdentifier
coupleGroupIdentifier()=default
Default construct.
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:270
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:232
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::patchIdentifier::name
const word & name() const
The patch name.
Definition: patchIdentifier.H:134
Foam::fvMesh::name
const word & name() const
Return reference to name.
Definition: fvMesh.H:295