faPatchData.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) 2021-2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "faPatchData.H"
29 #include "dictionary.H"
30 #include "processorFaPatch.H"
31 #include "processorPolyPatch.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
36 :
37  ownerPolyPatchId_(-1),
38  neighPolyPatchId_(-1),
39  ownerProcId_(-1),
40  neighProcId_(-1)
41 {}
42 
43 
44 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
45 
47 {
48  return name_;
49 }
50 
51 
52 Foam::dictionary Foam::faPatchData::dict(const bool withEdgeLabels) const
53 {
54  dictionary patchDict;
55  patchDict.add("type", type_);
56 
57  if (withEdgeLabels)
58  {
59  patchDict.add("edgeLabels", edgeLabels_);
60  }
61  else
62  {
63  patchDict.add("edgeLabels", labelList());
64  }
65  patchDict.add("ngbPolyPatchIndex", neighPolyPatchId_);
66 
67  if (coupled())
68  {
69  patchDict.add("myProcNo", ownerProcId_);
70  patchDict.add("neighbProcNo", neighProcId_);
71  }
72 
73  return patchDict;
74 }
75 
76 
77 bool Foam::faPatchData::good() const
78 {
79  return (!name_.empty() && !type_.empty());
80 }
81 
82 
84 {
85  name_.clear();
86  type_.clear();
87 
88  ownerPolyPatchId_ = -1;
89  neighPolyPatchId_ = -1;
90 
91  ownerProcId_ = -1;
92  neighProcId_ = -1;
93 
94  edgeLabels_.clear();
95 }
96 
97 
98 void Foam::faPatchData::assign(const faPatch& fap)
99 {
100  clear();
101 
102  // Copy information
103  name_ = fap.name();
104  type_ = fap.type();
105 
106  neighPolyPatchId_ = fap.ngbPolyPatchIndex();
107  edgeLabels_ = fap.edgeLabels();
108 
109  const auto* fapp = isA<processorFaPatch>(fap);
110  if (fapp)
111  {
112  ownerProcId_ = fapp->myProcNo();
113  neighProcId_ = fapp->neighbProcNo();
114  }
115 }
116 
117 
118 bool Foam::faPatchData::assign_coupled(int ownProci, int neiProci)
119 {
120  clear();
121 
122  if (ownProci == neiProci)
123  {
124  return false;
125  }
126 
127  name_ = processorPolyPatch::newName(ownProci, neiProci);
128  type_ = processorFaPatch::typeName;
129  ownerProcId_ = ownProci;
130  neighProcId_ = neiProci;
131 
132  return true;
133 }
134 
135 
137 (
138  const labelPair& patchPair
139 ) const noexcept
140 {
141  int ret = 0;
142  if (patchPair.first() >= 0 && patchPair.first() == ownerPolyPatchId_)
143  {
144  ret |= 1;
145  }
146  if (patchPair.second() >= 0 && patchPair.second() == neighPolyPatchId_)
147  {
148  ret |= 2;
149  }
150  return ret;
151 }
152 
153 
155 (
156  const labelPair& patchPair
157 ) const noexcept
158 {
159  // As per edge::compare, with validity check
160 
161  if (patchPair.first() >= 0 || patchPair.second() >= 0)
162  {
163  if
164  (
165  ownerPolyPatchId_ == patchPair.first()
166  && neighPolyPatchId_ == patchPair.second()
167  )
168  {
169  return 1;
170  }
171 
172  if
173  (
174  ownerPolyPatchId_ == patchPair.second()
175  && neighPolyPatchId_ == patchPair.first()
176  )
177  {
178  return -1;
179  }
180  }
181 
182  return 0;
183 }
184 
185 
186 // ************************************************************************* //
int matchPatchPair(const labelPair &patchPair) const noexcept
Ordered match with owner/neighbour patchPair.
Definition: faPatchData.C:130
const T & first() const noexcept
Access the first element.
Definition: Pair.H:137
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
int comparePatchPair(const labelPair &patchPair) const noexcept
Unordered comparison with owner/neighbour patchPair.
Definition: faPatchData.C:148
void clear()
Reset data.
Definition: faPatchData.C:76
const word & name() const noexcept
Return the name.
Definition: faPatchData.C:39
static word newName(const label myProcNo, const label neighbProcNo)
Return the name of a processorPolyPatch ("procBoundary..") constructed from the pair of processor IDs...
bool assign_coupled(int ownProci, int neiProci)
Set values consistent with a processor coupling.
Definition: faPatchData.C:111
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:625
const labelList & edgeLabels() const noexcept
Return the list of edges.
Definition: faPatch.H:335
A class for handling words, derived from Foam::string.
Definition: word.H:63
dictionary dict(const bool withEdgeLabels=true) const
Contents transcribed into a patch dictionary, usually including the edge labels.
Definition: faPatchData.C:45
patchWriters clear()
const word & name() const noexcept
The patch name.
const direction noexcept
Definition: Scalar.H:258
Pair< label > labelPair
A pair of labels.
Definition: Pair.H:51
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:72
faPatchData()
Default construct.
Definition: faPatchData.C:28
bool good() const
Has name/type etc.
Definition: faPatchData.C:70
List< label > labelList
A List of labels.
Definition: List.H:62
bool coupled
const T & second() const noexcept
Access the second element.
Definition: Pair.H:147
void assign(const faPatch &fap)
Clear and populate with values from finiteArea patch.
Definition: faPatchData.C:91
label ngbPolyPatchIndex() const noexcept
The neighbour polyPatch index.
Definition: faPatch.H:359