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  HashTable<labelList>::const_iterator fnd =
53  pbm.groupPatchIDs().find(name());
54 
55  if (!fnd.found())
56  {
57  if (&mesh == &thisPatch.boundaryMesh().mesh())
58  {
59  // thisPatch should be in patchGroup
61  << "Patch " << thisPatch.name()
62  << " should be in patchGroup " << name()
63  << " in region " << pbm.mesh().name()
64  << exit(FatalError);
65  }
66 
67  return -1;
68  }
69 
70  // Mesh has patch group
71  const labelList& patchIDs = fnd.val();
72 
73  if (&mesh == &thisPatch.boundaryMesh().mesh())
74  {
75  if (patchIDs.size() > 2 || patchIDs.size() == 0)
76  {
78  << "Couple patchGroup " << name()
79  << " with contents " << patchIDs
80  << " not of size < 2"
81  << " on patch " << thisPatch.name()
82  << " region " << thisPatch.boundaryMesh().mesh().name()
83  << exit(FatalError);
84 
85  return -1;
86  }
87 
88  label index = patchIDs.find(thisPatch.index());
89 
90  if (index == -1)
91  {
93  << "Couple patchGroup " << name()
94  << " with contents " << patchIDs
95  << " does not contain patch " << thisPatch.name()
96  << " in region " << pbm.mesh().name()
97  << exit(FatalError);
98 
99  return -1;
100  }
101 
102 
103  if (patchIDs.size() == 2)
104  {
105  // Return the other patch
106  return patchIDs[1-index];
107  }
108  else // size == 1
109  {
110  return -1;
111  }
112  }
113  else
114  {
115  if (patchIDs.size() != 1)
116  {
118  << "Couple patchGroup " << name()
119  << " with contents " << patchIDs
120  << " in region " << mesh.name()
121  << " should only contain a single patch"
122  << " when matching patch " << thisPatch.name()
123  << " in region " << pbm.mesh().name()
124  << exit(FatalError);
125  }
126 
127  return patchIDs[0];
128  }
129 }
130 
131 
132 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
133 
135 :
136  name_()
137 {}
138 
139 
141 :
142  name_(patchGroupName)
143 {}
144 
145 
147 :
148  name_()
149 {
150  dict.readIfPresent("coupleGroup", name_);
151 }
152 
153 
154 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
155 
156 Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
157 (
158  const polyPatch& thisPatch
159 ) const
160 {
161  const polyBoundaryMesh& pbm = thisPatch.boundaryMesh();
162 
163  return findOtherPatchID(pbm.mesh(), thisPatch);
164 }
165 
166 
167 Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
168 (
169  const polyPatch& thisPatch,
170  word& otherRegion
171 ) const
172 {
173  const polyBoundaryMesh& pbm = thisPatch.boundaryMesh();
174  const polyMesh& thisMesh = pbm.mesh();
175  const Time& runTime = thisMesh.time();
176 
177 
178  // Loop over all regions to find other patch in coupleGroup
180 
181  label otherPatchID = -1;
182 
183  forAllConstIters(meshSet, iter)
184  {
185  const polyMesh& mesh = *iter();
186 
187  const label patchID = findOtherPatchID(mesh, thisPatch);
188 
189  if (patchID != -1)
190  {
191  if (otherPatchID != -1)
192  {
194  << "Couple patchGroup " << name()
195  << " should be present on only two patches"
196  << " in any of the meshes in " << meshSet.sortedToc()
197  << endl
198  << " It seems to be present on patch "
199  << thisPatch.name()
200  << " in region " << thisMesh.name()
201  << ", on patch " << otherPatchID
202  << " in region " << otherRegion
203  << " and on patch " << patchID
204  << " in region " << mesh.name()
205  << exit(FatalError);
206  }
207  otherPatchID = patchID;
208  otherRegion = mesh.name();
209  }
210  }
211 
212  if (otherPatchID == -1)
213  {
215  << "Couple patchGroup " << name()
216  << " not found in any of the other meshes " << meshSet.sortedToc()
217  << " on patch " << thisPatch.name()
218  << " region " << thisMesh.name()
219  << exit(FatalError);
220  }
221 
222  return otherPatchID;
223 }
224 
225 
227 {
228  if (valid())
229  {
230  os.writeEntry("coupleGroup", name());
231  }
232 }
233 
234 
235 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
236 
238 {
239  p.write(os);
240  os.check(FUNCTION_NAME);
241  return os;
242 }
243 
244 
245 // ************************************************************************* //
Foam::coupleGroupIdentifier
Encapsulates using patchGroups to specify coupled patch.
Definition: coupleGroupIdentifier.H:64
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
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:46
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:337
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::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::polyPatch::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:305
Foam::coupleGroupIdentifier::name
const word & name() const
Name of patchGroup.
Definition: coupleGroupIdentifierI.H:32
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
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:38
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:355
forAllConstIters
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
Foam::coupleGroupIdentifier::write
void write(Ostream &os) const
Write the data as a dictionary.
Definition: coupleGroupIdentifier.C:226
Foam::coupleGroupIdentifier::coupleGroupIdentifier
coupleGroupIdentifier()
Construct null.
Definition: coupleGroupIdentifier.C:134
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:261
Foam::Ostream::writeEntry
Ostream & writeEntry(const keyType &key, const T &value)
Write a keyword/value entry.
Definition: Ostream.H:219
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
Return the patch name.
Definition: patchIdentifier.H:109
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &)
Definition: boundaryPatch.C:102
Foam::fvMesh::name
const word & name() const
Return reference to name.
Definition: fvMesh.H:266