nonConformalPolyPatch.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) 2021-2022 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 "nonConformalPolyPatch.H"
27 #include "polyMesh.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(nonConformalPolyPatch, 0);
34 }
35 
36 
37 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
38 
39 void Foam::nonConformalPolyPatch::validateSize() const
40 {
41  if (patch_.size() != 0)
42  {
44  << "Patch " << patch_.name() << " has " << patch_.size()
45  << " faces. Patches of type " << patch_.type()
46  << " must have zero faces." << exit(FatalError);
47  }
48 }
49 
50 
51 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
52 
54 {
55  if (origPatchID_ != -1)
56  {
57  origPatchName_ = newNames[origPatchID_];
58  }
59  else
60  {
62  << "Cannot rename " << nonConformalPolyPatch::typeName
63  << " without the original patch index"
64  << exit(FatalError);
65  }
66 }
67 
68 
70 {
71  if (origPatchID_ != -1)
72  {
73  origPatchID_ = findIndex(newToOldIndex, origPatchID_);
74  }
75 }
76 
77 
78 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
79 
81 :
82  patch_(patch),
83  origPatchName_(word::null),
84  origPatchID_(-1)
85 {
86  validateSize();
87 }
88 
89 
91 (
92  const polyPatch& patch,
93  const word& origPatchName
94 )
95 :
96  patch_(patch),
97  origPatchName_(origPatchName),
98  origPatchID_(-1)
99 {
100  validateSize();
101 }
102 
103 
105 (
106  const polyPatch& patch,
107  const dictionary& dict
108 )
109 :
110  patch_(patch),
111  origPatchName_(dict.lookup<word>("originalPatch")),
112  origPatchID_(-1)
113 {
114  validateSize();
115 }
116 
117 
119 (
120  const polyPatch& patch,
121  const nonConformalPolyPatch& ncPatch
122 )
123 :
124  patch_(patch),
125  origPatchName_(ncPatch.origPatchName_),
126  origPatchID_(-1)
127 {
128  validateSize();
129 }
130 
131 
132 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
133 
135 {}
136 
137 
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
139 
141 {
142  return origPatchName_;
143 }
144 
145 
147 {
148  if (origPatchID_ == -1)
149  {
150  origPatchID_ = patch_.boundaryMesh().findPatchID(origPatchName());
151 
152  if (origPatchID_ == -1)
153  {
155  << "Illegal neighbourPatch name " << origPatchName()
156  << endl << "Valid patch names are "
157  << patch_.boundaryMesh().names()
158  << exit(FatalError);
159  }
160 
161  const polyPatch& p = patch_.boundaryMesh()[origPatchID_];
162 
163  if (isA<nonConformalPolyPatch>(p))
164  {
166  << "The originalPatch for the "
167  << patch_.type() << " patch " << patch_.name() << " is "
168  << p.name() << " which is also of "
169  << nonConformalPolyPatch::typeName << " type. This is not "
170  << "allowed. The originalPatch must be of a non-"
171  << nonConformalPolyPatch::typeName << " type."
172  << exit(FatalError);
173  }
174  }
175 
176  return origPatchID_;
177 }
178 
179 
181 {
182  return patch_.boundaryMesh()[origPatchID()];
183 }
184 
185 
187 {
188  writeEntry(os, "originalPatch", origPatchName_);
189 }
190 
191 
192 // ************************************************************************* //
nonConformalPolyPatch(const polyPatch &patch)
Construct from a patch.
const word & name() const
Return name.
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:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
const polyBoundaryMesh & boundaryMesh() const
Return boundaryMesh reference.
Definition: polyPatch.C:297
const word & origPatchName() const
Original patch name.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
label findPatchID(const word &patchName) const
Find patch index given a name.
A class for handling words, derived from string.
Definition: word.H:59
wordList names() const
Return a list of patch names.
Non-conformal poly patch. This patch is a placeholder and must have no faces. This patch is linked to...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
const polyPatch & origPatch() const
Original patch.
virtual void rename(const wordList &newNames)
Reset the patch name.
defineTypeNameAndDebug(combustionModel, 0)
virtual void write(Ostream &) const
Write the polyPatch data as a dictionary.
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
virtual void reorder(const labelUList &newToOldIndex)
Reset the patch index.
label origPatchID() const
Original patchID.
volScalarField & p
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:66
virtual ~nonConformalPolyPatch()
Destructor.
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:864