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 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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
52Foam::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
78{
79 name_.clear();
80 type_.clear();
81
82 ownerPolyPatchId_ = -1;
83 neighPolyPatchId_ = -1;
84
85 ownerProcId_ = -1;
86 neighProcId_ = -1;
87
88 edgeLabels_.clear();
89}
90
91
93{
94 clear();
95
96 // Copy information
97 name_ = fap.name();
98 type_ = fap.type();
99
100 neighPolyPatchId_ = fap.ngbPolyPatchIndex();
101 edgeLabels_ = fap.edgeLabels();
102
103 const auto* fapp = isA<processorFaPatch>(fap);
104 if (fapp)
105 {
106 ownerProcId_ = fapp->myProcNo();
107 neighProcId_ = fapp->neighbProcNo();
108 }
109}
110
111
112bool Foam::faPatchData::assign_coupled(int ownProci, int neiProci)
113{
114 clear();
115
116 if (ownProci == neiProci)
117 {
118 return false;
119 }
120
121 name_ = processorPolyPatch::newName(ownProci, neiProci);
123 ownerProcId_ = ownProci;
124 neighProcId_ = neiProci;
125
126 return true;
127}
128
129
131(
132 const labelPair& patchPair
133) const noexcept
134{
135 int ret = 0;
136 if (patchPair.first() >= 0 && patchPair.first() == ownerPolyPatchId_)
137 {
138 ret |= 1;
139 }
140 if (patchPair.second() >= 0 && patchPair.second() == neighPolyPatchId_)
141 {
142 ret |= 2;
143 }
144 return ret;
145}
146
147
149(
150 const labelPair& patchPair
151) const noexcept
152{
153 // As per edge::compare, with validity check
154
155 if (patchPair.first() >= 0 || patchPair.second() >= 0)
156 {
157 if
158 (
159 ownerPolyPatchId_ == patchPair.first()
160 && neighPolyPatchId_ == patchPair.second()
161 )
162 {
163 return 1;
164 }
165
166 if
167 (
168 ownerPolyPatchId_ == patchPair.second()
169 && neighPolyPatchId_ == patchPair.first()
170 )
171 {
172 return -1;
173 }
174 }
175
176 return 0;
177}
178
179
180// ************************************************************************* //
const polyPatch const word const word const dictionary & dict
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:640
int matchPatchPair(const labelPair &patchPair) const noexcept
Ordered match with owner/neighbour patchPair.
Definition: faPatchData.C:131
const word & name() const noexcept
Return the name.
Definition: faPatchData.C:46
bool assign_coupled(int ownProci, int neiProci)
Set values consistent with a processor coupling.
Definition: faPatchData.C:112
int comparePatchPair(const labelPair &patchPair) const noexcept
Unordered comparison with owner/neighbour patchPair.
Definition: faPatchData.C:149
faPatchData()
Default construct.
Definition: faPatchData.C:35
void assign(const faPatch &fap)
Clear and populate with values from finiteArea patch.
Definition: faPatchData.C:92
void clear()
Reset data.
Definition: faPatchData.C:77
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:78
const labelList & edgeLabels() const noexcept
Return the list of edges.
Definition: faPatch.H:275
label ngbPolyPatchIndex() const noexcept
The neighbour polyPatch index.
Definition: faPatch.H:293
const word & name() const noexcept
The patch name.
static word newName(const label myProcNo, const label neighbProcNo)
Return the name of a processorPolyPatch.
A class for handling words, derived from Foam::string.
Definition: word.H:68
patchWriters clear()
bool coupled(solutionDict.getOrDefault("coupledEnergyField", false))
List< label > labelList
A List of labels.
Definition: List.H:66
const direction noexcept
Definition: Scalar.H:223
static const char *const typeName
The type name used in ensight case files.