Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
30#include "polyMesh.H"
31#include "Time.H"
32
33// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
34
35Foam::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 (!good())
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.good())
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
135 dict.readIfPresent("coupleGroup", name_);
136}
137
138
139// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
140
141Foam::label Foam::coupleGroupIdentifier::findOtherPatchID
142(
143 const polyPatch& thisPatch
144) const
146 const polyBoundaryMesh& pbm = thisPatch.boundaryMesh();
147
148 return findOtherPatchID(pbm.mesh(), thisPatch);
149}
150
151
152Foam::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
164 label otherPatchID = -1;
165
166 for (const polyMesh& mesh : runTime.cobjects<polyMesh>())
167 {
168 const label patchID = findOtherPatchID(mesh, thisPatch);
169
170 if (patchID != -1)
171 {
172 if (otherPatchID != -1)
173 {
175 << "Couple patchGroup " << name()
176 << " should be present on only two patches"
177 << " in any of the meshes in "
178 << runTime.sortedNames<polyMesh>() << nl
179 << " It seems to be present on patch "
180 << thisPatch.name()
181 << " in region " << thisMesh.name()
182 << ", on patch " << otherPatchID
183 << " in region " << otherRegion
184 << " and on patch " << patchID
185 << " in region " << mesh.name() << endl
186 << exit(FatalError);
187 }
188 otherPatchID = patchID;
189 otherRegion = mesh.name();
190 }
191 }
192
193 if (otherPatchID == -1)
194 {
196 << "Couple patchGroup " << name()
197 << " not found in any of the other meshes "
199 << " on patch " << thisPatch.name()
200 << " region " << thisMesh.name()
202 }
203
204 return otherPatchID;
205}
206
207
208void Foam::coupleGroupIdentifier::write(Ostream& os) const
209{
210 if (!name_.empty())
211 {
212 os.writeEntry("coupleGroup", name_);
213 }
214}
215
216
217// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
218
219Foam::Ostream& Foam::operator<<(Ostream& os, const coupleGroupIdentifier& ident)
220{
221 ident.write(os);
223 return os;
224}
225
226
227// ************************************************************************* //
labelList patchIDs
const polyBoundaryMesh & pbm
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:45
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition Time.H:75
Encapsulates using "patchGroups" to specify coupled patch.
bool good() const noexcept
The patchGroup has a non-empty name.
coupleGroupIdentifier()=default
Default construct.
void write(Ostream &os) const
Write the coupleGroup dictionary entry.
const word & name() const noexcept
Name of patchGroup.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
wordList sortedNames() const
The sorted names of all objects.
const Time & time() const noexcept
Return time registry.
const word & name() const noexcept
The patch name.
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh,...
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
const polyBoundaryMesh & boundaryMesh() const noexcept
Return boundaryMesh reference.
Definition polyPatch.C:295
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
engineTime & runTime
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
OBJstream os(runTime.globalPath()/outputName)
auto & name
#define FUNCTION_NAME
List< label > labelList
A List of labels.
Definition List.H:62
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict