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-2024 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
35 template<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  // Allocate unique tag for all comms
48  const int oldTag = UPstream::incrMsgType();
49 
50  // Pull slave data onto master
51  slavesMap.distribute(transforms, elems, top);
52 
53  // Combine master data with slave data
54  forAll(slaves, i)
55  {
56  Type& elem = elems[i];
57 
58  const labelList& slavePoints = slaves[i];
59 
60  const labelList& transformSlavePoints =
61  (
62  transformedSlaves.empty()
63  ? labelList::null()
64  : transformedSlaves[i]
65  );
66 
67 
68  // Combine master with untransformed slave data
69  for (const label pointi : slavePoints)
70  {
71  cop(elem, elems[pointi]);
72  }
73 
74  // Combine master with transformed slave data
75  for (const label pointi : transformSlavePoints)
76  {
77  cop(elem, elems[pointi]);
78  }
79 
80  // Copy result back to slave slots
81  for (const label pointi : slavePoints)
82  {
83  elems[pointi] = elem;
84  }
85 
86  for (const label pointi : transformSlavePoints)
87  {
88  elems[pointi] = elem;
89  }
90  }
91 
92  // Push slave-slot data back to slaves
93  slavesMap.reverseDistribute
94  (
95  transforms,
96  elems.size(),
97  elems,
98  top
99  );
100 
101  // Reset tag
102  UPstream::msgType(oldTag);
103 }
104 
105 
106 template<class Type, class CombineOp>
108 (
109  List<Type>& elems,
110  const labelListList& slaves,
111  const labelListList& transformedSlaves,
112  const mapDistribute& slavesMap,
113  const CombineOp& cop
114 )
115 {
116  // Allocate unique tag for all comms
117  const int oldTag = UPstream::incrMsgType();
118 
119  // Pull slave data onto master
120  slavesMap.distribute(elems);
121 
122  // Combine master data with slave data
123  forAll(slaves, i)
124  {
125  Type& elem = elems[i];
126 
127  const labelList& slavePoints = slaves[i];
128 
129  const labelList& transformSlavePoints =
130  (
131  transformedSlaves.empty()
132  ? labelList::null()
133  : transformedSlaves[i]
134  );
135 
136 
137  // Combine master with untransformed slave data
138  for (const label pointi : slavePoints)
139  {
140  cop(elem, elems[pointi]);
141  }
142 
143  // Combine master with transformed slave data
144  for (const label pointi : transformSlavePoints)
145  {
146  cop(elem, elems[pointi]);
147  }
148 
149  // Copy result back to slave slots
150  for (const label pointi : slavePoints)
151  {
152  elems[pointi] = elem;
153  }
154 
155  for (const label pointi : transformSlavePoints)
156  {
157  elems[pointi] = elem;
158  }
159  }
160 
161  // Push slave-slot data back to slaves
162  slavesMap.reverseDistribute(elems.size(), elems);
163 
164  // Reset tag
165  UPstream::msgType(oldTag);
166 }
167 
168 
169 template<class Type, class CombineOp, class TransformOp>
171 (
172  List<Type>& pointData,
173  const CombineOp& cop,
174  const TransformOp& top
175 ) const
176 {
177  if (pointData.size() != mesh_.nPoints())
178  {
180  << "Number of elements in data:" << pointData.size()
181  << " differs from number of points in mesh:" << mesh_.nPoints()
182  << abort(FatalError);
183  }
184 
185  // Transfer onto coupled patch
186  const indirectPrimitivePatch& cpp = coupledPatch();
187  List<Type> cppFld(UIndirectList<Type>(pointData, cpp.meshPoints()));
188 
189  syncData
190  (
191  cppFld,
192  globalPointSlaves(),
193  globalPointTransformedSlaves(),
194  globalPointSlavesMap(),
195  globalTransforms(),
196  cop,
197  top
198  );
199 
200  // Extract back onto mesh
201  forAll(cpp.meshPoints(), i)
202  {
203  pointData[cpp.meshPoints()[i]] = cppFld[i];
204  }
205 }
206 
207 
208 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
static int incrMsgType(int val=1) noexcept
Increment the message tag for standard messages.
Definition: UPstream.H:1809
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:600
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute List data using default commsType, default flip/negate operator.
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:697
static int & msgType() noexcept
Message tag of standard messages.
Definition: UPstream.H:1787
PrimitivePatch< IndirectList< face >, const pointField & > indirectPrimitivePatch
A PrimitivePatch with an IndirectList for the faces, const reference for the point field...
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:286
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.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
void reverseDistribute(const label constructSize, List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
Class containing processor-to-processor mapping information.
static const List< label > & null() noexcept
Return a null List (reference to a nullObject). Behaves like an empty List.
Definition: List.H:158
Determination and storage of the possible independent transforms introduced by coupledPolyPatches, as well as all of the possible permutations of these transforms generated by the presence of multiple coupledPolyPatches, i.e. more than one cyclic boundary. Note that any given point can be on maximum 3 transforms only (and these transforms have to be perpendicular)
void syncPointData(List< Type > &pointData, const CombineOp &cop, const TransformOp &top) const
Helper to synchronise coupled patch point data.