zoneDistributeI.H
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) 2019-2020 DLR
9 Copyright (C) 2020-2022 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
29#include "DynamicField.H"
30
31// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32
33template<typename Type>
34Type Foam::zoneDistribute::getLocalValue
35(
36 const VolumeField<Type>& phi,
37 const label localIdx
38) const
39{
40 if (localIdx < mesh_.nCells()) // internal: cellI
41 {
42 return phi[localIdx];
43 }
44
45 return faceValue(phi,localIdx);
46}
47
48
49template<typename Type>
50Type Foam::zoneDistribute::faceValue
51(
52 const VolumeField<Type>& phi,
53 const label localIdx
54) const
55{
56 const label faceI = localIdx + mesh_.nInternalFaces() - mesh_.nCells();
57
58 const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
59
60 // Boundary face. Find out which face of which patch
61 const label patchI = pbm.whichPatch(faceI);
62
63 if (patchI < 0 || patchI >= pbm.size())
64 {
66 << "Cannot find patch for face " << faceI
67 << abort(FatalError);
68 }
69
70 const polyPatch& pp = pbm[patchI];
71
72 const label patchFaceI = pp.whichFace(faceI);
73
74 return phi.boundaryField()[patchI][patchFaceI];
75}
76
77
78template<typename Type>
80(
82 const Map<Type>& valuesFromOtherProc,
83 const label gblIdx
84) const
85{
86 if (globalNumbering_.isLocal(gblIdx))
87 {
88 const label localIdx = globalNumbering_.toLocal(gblIdx);
89 return getLocalValue(phi,localIdx);
90 }
91 else
92 {
93 // From other proc
94 return valuesFromOtherProc[gblIdx];
95 }
96}
97
98
99template<typename Type>
101(
102 const boolList& zone,
104)
105{
106 if (zone.size() != phi.size())
107 {
109 << "size of zone: " << zone.size()
110 << "size of phi:" << phi.size()
111 << "do not match. Did the mesh change?"
112 << exit(FatalError);
113 }
114
115
116 // Get values from other proc
117 Map<Type> neiValues = getDatafromOtherProc(zone, phi);
118
119 Map<Field<Type>> stencilWithValues;
120
121 DynamicField<Type> tmpField(128);
122
123 forAll(zone, celli)
124 {
125 if (zone[celli])
126 {
127 tmpField.clear();
128
129 for (const label gblIdx : stencil_[celli])
130 {
131 tmpField.append(getValue(phi,neiValues,gblIdx));
132 }
133
134 stencilWithValues.emplace(celli, tmpField);
135 }
136 }
137
138 return stencilWithValues;
139}
140
141
142template<typename Type>
144(
145 const boolList& zone,
147)
148{
149 if (zone.size() != phi.size())
150 {
152 << "size of zone: " << zone.size()
153 << "size of phi:" << phi.size()
154 << "do not match. Did the mesh change?"
155 << exit(FatalError);
156 }
157
158
159 // Get values from other proc
160 Map<Type> neiValues;
161
162 if (UPstream::parRun())
163 {
164 if (sendConnections_.empty())
165 {
167 << "The send/recv connections not initialized - "
168 << "likely that setUpCommforZone() was not called"
169 << endl;
170 // But don't exit/abort for now
171 }
172
173 // Stream the send data into PstreamBuffers,
174 // which we also use to track the current topology.
175
177
178 for (const int proci : UPstream::allProcs())
179 {
180 if (proci != UPstream::myProcNo() && !send_[proci].empty())
181 {
182 // Serialize as Map
183 Map<Type> sendValues(2*send_[proci].size());
184
185 for (const label sendIdx : send_[proci])
186 {
187 sendValues.insert
188 (
189 sendIdx,
190 getLocalValue(phi, globalNumbering_.toLocal(sendIdx))
191 );
192 }
193
194 UOPstream toProc(proci, pBufs);
195 toProc << sendValues;
196 }
197 }
198
199 pBufs.finishedSends(sendConnections_, sendProcs_, recvProcs_);
200
201 for (const int proci : pBufs.allProcs())
202 {
203 if (proci != UPstream::myProcNo() && pBufs.recvDataCount(proci))
204 {
205 UIPstream fromProc(proci, pBufs);
206 Map<Type> tmpValues(fromProc);
207
208 neiValues += tmpValues;
209 }
210 }
211 }
212
213 return neiValues;
214}
215
216
217// ************************************************************************* //
surfaceScalarField & phi
Dynamically sized Field.
Definition: DynamicField.H:65
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
void append(const T &val)
Append an element at the end of the list.
Generic GeometricField class.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:180
bool emplace(const Key &key, Args &&... args)
Emplace insert a new entry, not overwriting existing entries.
Definition: HashTableI.H:157
A HashTable to objects of type <T> with a label key.
Definition: Map.H:60
Buffers for inter-processor communications streams (UOPstream, UIPstream).
UPstream::rangeType allProcs() const noexcept
Range of ranks indices associated with PstreamBuffers.
label recvDataCount(const label proci) const
void finishedSends(const bool wait=true)
Mark sends as done.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
@ nonBlocking
"nonBlocking"
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:433
label nCells() const noexcept
Number of mesh cells.
int myProcNo() const noexcept
Return processor number.
Map< Type > getDatafromOtherProc(const boolList &zone, const VolumeField< Type > &phi)
Returns stencil and provides a Map with globalNumbering.
Map< Field< Type > > getFields(const boolList &zone, const VolumeField< Type > &phi)
Returns stencil and provides a Map with globalNumbering.
Base class for mesh zones.
Definition: zone.H:67
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#define WarningInFunction
Report a warning using Foam::Warning.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333