coupleGroupIdentifier.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "coupleGroupIdentifier.H"
27 #include "polyMesh.H"
28 #include "Time.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
33 (
34  const polyMesh& mesh,
35  const polyPatch& thisPatch
36 ) const
37 {
38  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
39 
40  if (!valid())
41  {
43  << "Invalid coupleGroup patch group"
44  << " on patch " << thisPatch.name()
45  << " in region " << pbm.mesh().name()
46  << exit(FatalError);
47  }
48 
50  pbm.groupPatchIDs().find(name());
51 
52  if (fnd == pbm.groupPatchIDs().end())
53  {
54  if (&mesh == &thisPatch.boundaryMesh().mesh())
55  {
56  // thisPatch should be in patchGroup
58  << "Patch " << thisPatch.name()
59  << " should be in patchGroup " << name()
60  << " in region " << pbm.mesh().name()
61  << exit(FatalError);
62  }
63 
64  return -1;
65  }
66 
67  // Mesh has patch group
68  const labelList& patchIDs = fnd();
69 
70  if (&mesh == &thisPatch.boundaryMesh().mesh())
71  {
72  if (patchIDs.size() > 2 || patchIDs.size() == 0)
73  {
75  << "Couple patchGroup " << name()
76  << " with contents " << patchIDs
77  << " not of size < 2"
78  << " on patch " << thisPatch.name()
79  << " region " << thisPatch.boundaryMesh().mesh().name()
80  << exit(FatalError);
81 
82  return -1;
83  }
84 
85  label index = findIndex(patchIDs, thisPatch.index());
86 
87  if (index == -1)
88  {
90  << "Couple patchGroup " << name()
91  << " with contents " << patchIDs
92  << " does not contain patch " << thisPatch.name()
93  << " in region " << pbm.mesh().name()
94  << exit(FatalError);
95 
96  return -1;
97  }
98 
99 
100  if (patchIDs.size() == 2)
101  {
102  // Return the other patch
103  return patchIDs[1-index];
104  }
105  else // size == 1
106  {
107  return -1;
108  }
109  }
110  else
111  {
112  if (patchIDs.size() != 1)
113  {
115  << "Couple patchGroup " << name()
116  << " with contents " << patchIDs
117  << " in region " << mesh.name()
118  << " should only contain a single patch"
119  << " when matching patch " << thisPatch.name()
120  << " in region " << pbm.mesh().name()
121  << exit(FatalError);
122  }
123 
124  return patchIDs[0];
125  }
126 }
127 
128 
129 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
130 
132 :
133  name_()
134 {}
135 
136 
138 :
139  name_(name)
140 {}
141 
142 
144 :
145  name_(dict.lookupOrDefault<word>("coupleGroup", ""))
146 {}
147 
148 
149 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
150 
151 Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
152 (
153  const polyPatch& thisPatch
154 ) const
155 {
156  const polyBoundaryMesh& pbm = thisPatch.boundaryMesh();
157 
158  return findOtherPatchID(pbm.mesh(), thisPatch);
159 }
160 
161 
162 Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
163 (
164  const polyPatch& thisPatch,
165  word& otherRegion
166 ) const
167 {
168  const polyBoundaryMesh& pbm = thisPatch.boundaryMesh();
169  const polyMesh& thisMesh = pbm.mesh();
170  const Time& runTime = thisMesh.time();
171 
172 
173  // Loop over all regions to find other patch in coupleGroup
174  HashTable<const polyMesh*> meshSet = runTime.lookupClass<polyMesh>();
175 
176  label otherPatchID = -1;
177 
179  {
180  const polyMesh& mesh = *iter();
181 
182  label patchID = findOtherPatchID(mesh, thisPatch);
183 
184  if (patchID != -1)
185  {
186  if (otherPatchID != -1)
187  {
189  << "Couple patchGroup " << name()
190  << " should be present on only two patches"
191  << " in any of the meshes in " << meshSet.sortedToc()
192  << endl
193  << " It seems to be present on patch "
194  << thisPatch.name()
195  << " in region " << thisMesh.name()
196  << ", on patch " << otherPatchID
197  << " in region " << otherRegion
198  << " and on patch " << patchID
199  << " in region " << mesh.name()
200  << exit(FatalError);
201  }
202  otherPatchID = patchID;
203  otherRegion = mesh.name();
204  }
205  }
206 
207  if (otherPatchID == -1)
208  {
210  << "Couple patchGroup " << name()
211  << " not found in any of the other meshes " << meshSet.sortedToc()
212  << " on patch " << thisPatch.name()
213  << " region " << thisMesh.name()
214  << exit(FatalError);
215  }
216 
217  return otherPatchID;
218 }
219 
220 
222 {
223  if (valid())
224  {
225  os.writeKeyword("coupleGroup") << name() << token::END_STATEMENT << nl;
226  }
227 }
228 
229 
230 // * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
231 
233 {
234  p.write(os);
235  os.check("Ostream& operator<<(Ostream& os, const coupleGroupIdentifier& p");
236  return os;
237 }
238 
239 
240 // ************************************************************************* //
dictionary dict
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:59
const word & name() const
Return name.
const word & name() const
Return name.
Definition: IOobject.H:297
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:278
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
void write(Ostream &) const
Write the data as a dictionary.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
bool valid() const
Is a valid patchGroup.
A class for handling words, derived from string.
Definition: word.H:59
friend class const_iterator
Declare friendship with the const_iterator.
Definition: HashTable.H:197
const polyMesh & mesh() const
Return the mesh reference.
List< label > labelList
A List of labels.
Definition: labelList.H:56
An STL-conforming hash table.
Definition: HashTable.H:62
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
Encapsulates using patchGroups to specify coupled patch.
Foam::polyBoundaryMesh.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:265
const Time & time() const
Return time.
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
const word & name() const
Name of patchGroup.
List< Key > sortedToc() const
Return the table of contents as a sorted list.
Definition: HashTable.C:217
Ostream & operator<<(Ostream &, const ensightPart &)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
volScalarField & p
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
HashTable< const Type * > lookupClass(const bool strict=false) const
Lookup and return all objects of the given Type.