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 | Copyright (C) 2013-2015 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 
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 
152 (
153  const polyPatch& thisPatch
154 ) const
155 {
156  const polyBoundaryMesh& pbm = thisPatch.boundaryMesh();
157 
158  return findOtherPatchID(pbm.mesh(), thisPatch);
159 }
160 
161 
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 // ************************************************************************* //
Foam::coupleGroupIdentifier
Encapsulates using patchGroups to specify coupled patch.
Definition: coupleGroupIdentifier.H:62
Foam::polyBoundaryMesh::groupPatchIDs
const HashTable< labelList, word > & groupPatchIDs() const
Per patch group the patch indices.
Definition: polyBoundaryMesh.C:429
Foam::token::END_STATEMENT
@ END_STATEMENT
Definition: token.H:99
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
p
p
Definition: pEqn.H:62
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::polyBoundaryMesh
Foam::polyBoundaryMesh.
Definition: polyBoundaryMesh.H:60
Foam::findIndex
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurence of given element and return index,.
coupleGroupIdentifier.H
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:117
Foam::HashTable::const_iterator
An STL-conforming const_iterator.
Definition: HashTable.H:470
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::objectRegistry::lookupClass
HashTable< const Type * > lookupClass(const bool strict=false) const
Lookup and return all objects of the given Type.
Foam::coupleGroupIdentifier::write
void write(Ostream &) const
Write the data as a dictionary.
Definition: coupleGroupIdentifier.C:221
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:59
Foam::polyPatch::boundaryMesh
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:302
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
Foam::polyBoundaryMesh::mesh
const polyMesh & mesh() const
Return the mesh reference.
Definition: polyBoundaryMesh.H:140
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::coupleGroupIdentifier::findOtherPatchID
label findOtherPatchID(const polyMesh &, const polyPatch &) const
Find other patch in specified mesh. Returns index of patch or -1.
Definition: coupleGroupIdentifier.C:33
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:92
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::HashTable::sortedToc
List< Key > sortedToc() const
Return the table of contents as a sorted list.
Definition: HashTable.C:216
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::HashTable
An STL-conforming hash table.
Definition: HashTable.H:61
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::coupleGroupIdentifier::coupleGroupIdentifier
coupleGroupIdentifier()
Construct null.
Definition: coupleGroupIdentifier.C:131
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::Ostream::writeKeyword
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:59
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::patchIdentifier::name
const word & name() const
Return name.
Definition: patchIdentifier.H:109
Foam::patchIdentifier::index
label index() const
Return the index of this patch in the boundaryMesh.
Definition: patchIdentifier.H:133
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::fvMesh::name
const word & name() const
Return reference to name.
Definition: fvMesh.H:257