globalMeshDataTemplates.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) 2011-2015 OpenFOAM Foundation
9 Copyright (C) 2018-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
29#include "globalMeshData.H"
30#include "polyMesh.H"
31#include "mapDistribute.H"
32
33// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
34
35template<class Type, class CombineOp, class TransformOp>
37(
38 List<Type>& elems,
39 const labelListList& slaves,
40 const labelListList& transformedSlaves,
41 const mapDistribute& slavesMap,
42 const globalIndexAndTransform& transforms,
43 const CombineOp& cop,
44 const TransformOp& top
45)
46{
47 // Pull slave data onto master
48 slavesMap.distribute(transforms, elems, top);
49
50 // Combine master data with slave data
51 forAll(slaves, i)
52 {
53 Type& elem = elems[i];
54
55 const labelList& slavePoints = slaves[i];
56
57 const labelList& transformSlavePoints =
58 (
59 transformedSlaves.empty()
61 : transformedSlaves[i]
62 );
63
64
65 // Combine master with untransformed slave data
66 for (const label pointi : slavePoints)
67 {
68 cop(elem, elems[pointi]);
69 }
70
71 // Combine master with transformed slave data
72 for (const label pointi : transformSlavePoints)
73 {
74 cop(elem, elems[pointi]);
75 }
76
77 // Copy result back to slave slots
78 for (const label pointi : slavePoints)
79 {
80 elems[pointi] = elem;
81 }
82
83 for (const label pointi : transformSlavePoints)
84 {
85 elems[pointi] = elem;
86 }
87 }
88
89 // Push slave-slot data back to slaves
90 slavesMap.reverseDistribute
91 (
92 transforms,
93 elems.size(),
94 elems,
95 top
96 );
97}
98
99
100template<class Type, class CombineOp>
102(
103 List<Type>& elems,
104 const labelListList& slaves,
105 const labelListList& transformedSlaves,
106 const mapDistribute& slavesMap,
107 const CombineOp& cop
108)
109{
110 // Pull slave data onto master
111 slavesMap.distribute(elems);
112
113 // Combine master data with slave data
114 forAll(slaves, i)
115 {
116 Type& elem = elems[i];
117
118 const labelList& slavePoints = slaves[i];
119
120 const labelList& transformSlavePoints =
121 (
122 transformedSlaves.empty()
124 : transformedSlaves[i]
125 );
126
127
128 // Combine master with untransformed slave data
129 for (const label pointi : slavePoints)
130 {
131 cop(elem, elems[pointi]);
132 }
133
134 // Combine master with transformed slave data
135 for (const label pointi : transformSlavePoints)
136 {
137 cop(elem, elems[pointi]);
138 }
139
140 // Copy result back to slave slots
141 for (const label pointi : slavePoints)
142 {
143 elems[pointi] = elem;
144 }
145
146 for (const label pointi : transformSlavePoints)
147 {
148 elems[pointi] = elem;
149 }
150 }
151
152 // Push slave-slot data back to slaves
153 slavesMap.reverseDistribute(elems.size(), elems);
154}
155
156
157template<class Type, class CombineOp, class TransformOp>
159(
160 List<Type>& pointData,
161 const CombineOp& cop,
162 const TransformOp& top
163) const
164{
165 if (pointData.size() != mesh_.nPoints())
166 {
168 << "Number of elements in data:" << pointData.size()
169 << " differs from number of points in mesh:" << mesh_.nPoints()
170 << abort(FatalError);
171 }
172
173 // Transfer onto coupled patch
174 const indirectPrimitivePatch& cpp = coupledPatch();
175 List<Type> cppFld(UIndirectList<Type>(pointData, cpp.meshPoints()));
176
177 syncData
178 (
179 cppFld,
180 globalPointSlaves(),
181 globalPointTransformedSlaves(),
182 globalPointSlavesMap(),
183 globalTransforms(),
184 cop,
185 top
186 );
187
188 // Extract back onto mesh
189 forAll(cpp.meshPoints(), i)
190 {
191 pointData[cpp.meshPoints()[i]] = cppFld[i];
192 }
193}
194
195
196// ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
static const List< label > & null()
Return a null List.
Definition: ListI.H:109
A list of faces which address into the list of points.
const labelList & meshPoints() const
Return labelList of mesh points in patch.
A List with indirect addressing. Like IndirectList but does not store addressing.
Definition: IndirectList.H:79
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
Definition: UListI.H:427
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Determination and storage of the possible independent transforms introduced by coupledPolyPatches,...
static void syncData(List< Type > &elems, const labelListList &slaves, const labelListList &transformedSlaves, const mapDistribute &slavesMap, const globalIndexAndTransform &, const CombineOp &cop, const TransformOp &top)
Helper: synchronise data with transforms.
void syncPointData(List< Type > &pointData, const CombineOp &cop, const TransformOp &top) const
Helper to synchronise coupled patch point data.
Class containing processor-to-processor mapping information.
void reverseDistribute(const label constructSize, List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333