globalMeshDataTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "globalMeshData.H"
27 #include "polyMesh.H"
28 #include "distributionMap.H"
29 
30 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31 
32 template<class Type, class CombineOp, class TransformOp>
34 (
35  List<Type>& elems,
36  const labelListList& slaves,
37  const labelListList& transformedSlaves,
38  const distributionMap& slavesMap,
40  const CombineOp& cop,
41  const TransformOp& top
42 )
43 {
44  // Pull slave data onto master
45  slavesMap.distribute(transforms, elems, top);
46 
47  // Combine master data with slave data
48  forAll(slaves, i)
49  {
50  Type& elem = elems[i];
51 
52  const labelList& slavePoints = slaves[i];
53  label nTransformSlavePoints =
54  (
55  transformedSlaves.size() == 0
56  ? 0
57  : transformedSlaves[i].size()
58  );
59 
60  if (slavePoints.size()+nTransformSlavePoints > 0)
61  {
62  // Combine master with untransformed slave data
63  forAll(slavePoints, j)
64  {
65  cop(elem, elems[slavePoints[j]]);
66  }
67 
68  // Combine master with transformed slave data
69  if (nTransformSlavePoints)
70  {
71  const labelList& transformSlavePoints = transformedSlaves[i];
72  forAll(transformSlavePoints, j)
73  {
74  cop(elem, elems[transformSlavePoints[j]]);
75  }
76  }
77 
78  // Copy result back to slave slots
79  forAll(slavePoints, j)
80  {
81  elems[slavePoints[j]] = elem;
82  }
83  if (nTransformSlavePoints)
84  {
85  const labelList& transformSlavePoints = transformedSlaves[i];
86  forAll(transformSlavePoints, j)
87  {
88  elems[transformSlavePoints[j]] = elem;
89  }
90  }
91  }
92  }
93 
94  // Push slave-slot data back to slaves
95  slavesMap.reverseDistribute
96  (
97  transforms,
98  elems.size(),
99  elems,
100  top
101  );
102 }
103 
104 
105 template<class Type, class CombineOp>
107 (
108  List<Type>& elems,
109  const labelListList& slaves,
110  const labelListList& transformedSlaves,
111  const distributionMap& slavesMap,
112  const CombineOp& cop
113 )
114 {
115  // Pull slave data onto master
116  slavesMap.distribute(elems);
117 
118  // Combine master data with slave data
119  forAll(slaves, i)
120  {
121  Type& elem = elems[i];
122 
123  const labelList& slavePoints = slaves[i];
124  label nTransformSlavePoints =
125  (
126  transformedSlaves.size() == 0
127  ? 0
128  : transformedSlaves[i].size()
129  );
130 
131  if (slavePoints.size()+nTransformSlavePoints > 0)
132  {
133  // Combine master with untransformed slave data
134  forAll(slavePoints, j)
135  {
136  cop(elem, elems[slavePoints[j]]);
137  }
138 
139  // Combine master with transformed slave data
140  if (nTransformSlavePoints)
141  {
142  const labelList& transformSlavePoints = transformedSlaves[i];
143  forAll(transformSlavePoints, j)
144  {
145  cop(elem, elems[transformSlavePoints[j]]);
146  }
147  }
148 
149  // Copy result back to slave slots
150  forAll(slavePoints, j)
151  {
152  elems[slavePoints[j]] = elem;
153  }
154  if (nTransformSlavePoints)
155  {
156  const labelList& transformSlavePoints = transformedSlaves[i];
157  forAll(transformSlavePoints, j)
158  {
159  elems[transformSlavePoints[j]] = elem;
160  }
161  }
162  }
163  }
164 
165  // Push slave-slot data back to slaves
166  slavesMap.reverseDistribute(elems.size(), elems);
167 }
168 
169 
170 template<class Type, class CombineOp, class TransformOp>
172 (
174  const CombineOp& cop,
175  const TransformOp& top
176 ) const
177 {
178  if (pointData.size() != mesh_.nPoints())
179  {
181  << "Number of elements in data:" << pointData.size()
182  << " differs from number of points in mesh:" << mesh_.nPoints()
183  << abort(FatalError);
184  }
185 
186  // Transfer onto coupled patch
187  const indirectPrimitivePatch& cpp = coupledPatch();
189 
190  syncData
191  (
192  cppFld,
193  globalPointSlaves(),
194  globalPointTransformedSlaves(),
195  globalPointSlavesMap(),
196  globalTransforms(),
197  cop,
198  top
199  );
200 
201  // Extract back onto mesh
202  forAll(cpp.meshPoints(), i)
203  {
204  pointData[cpp.meshPoints()[i]] = cppFld[i];
205  }
206 }
207 
208 
209 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
const labelList & meshPoints() const
Return labelList of mesh points in patch. They are constructed.
A List with indirect addressing.
Definition: UIndirectList.H:60
Class containing processor-to-processor mapping information.
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
void reverseDistribute(const label constructSize, List< T > &, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
Determination and storage of the possible independent transforms introduced by coupledPolyPatches,...
static void syncData(List< Type > &pointData, const labelListList &slaves, const labelListList &transformedSlaves, const distributionMap &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.
Variant of pointEdgePoint with some transported additional data. WIP - should be templated on data li...
Definition: pointData.H:63
transformer transforms
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManip< error > abort(error &err)
Definition: errorManip.H:131
error FatalError