patchToPatchToolsTemplates.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) 2022-2023 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 "patchToPatchTools.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 template<class SubListA, class SubListB>
32 (
33  List<SubListA>& a,
34  List<SubListB>& b
35 )
36 {
37  a.resize(b.size());
38  forAll(a, i)
39  {
40  a[i].transfer(b[i]);
41  }
42 }
43 
44 
45 template<class Type>
47 (
48  const label size,
49  const distributionMap& map,
50  List<List<Type>>& data
51 )
52 {
53  distributionMapBase::distribute
54  (
55  Pstream::commsTypes::nonBlocking,
56  List<labelPair>(),
57  size,
58  map.constructMap(),
59  false,
60  map.subMap(),
61  false,
62  data,
63  ListAppendEqOp<Type>(),
64  flipOp(),
65  List<Type>()
66  );
67 }
68 
69 
70 template<class Type>
72 (
73  const label size,
74  const distributionMap& map,
75  List<DynamicList<Type>>& data
76 )
77 {
78  List<List<Type>> tData;
79  transferListList(tData, data);
80  rDistributeListList(size, map, tData);
81  transferListList(data, tData);
82 }
83 
84 
85 template<class Type>
87 {
88  Type result;
89 
90  for (direction cmpt = 0; cmpt < pTraits<Type>::nComponents; cmpt++)
91  {
92  setComponent(result, cmpt) = Foam::NaN;
93  }
94 
95  return result;
96 }
97 
98 
99 template<class Type, class LabelList, class ScalarList>
101 (
102  const List<LabelList>& localOtherFaces,
103  const List<ScalarList>& weights,
104  const autoPtr<distributionMap>& otherMapPtr,
105  const Field<Type>& otherFld
106 )
107 {
108  // Distribute the other field if necessary
109  tmp<Field<Type>> tLocalOtherFld;
110  if (otherMapPtr.valid())
111  {
112  tLocalOtherFld = tmp<Field<Type>>(new Field<Type>(otherFld));
113  otherMapPtr->distribute(tLocalOtherFld.ref());
114  }
115  const Field<Type>& localOtherFld =
116  otherMapPtr.valid() ? tLocalOtherFld() : otherFld;
117 
118  // Allocate the result
119  tmp<Field<Type>> tFld(new Field<Type>(localOtherFaces.size(), NaN<Type>()));
120  Field<Type>& fld = tFld.ref();
121 
122  // Compute the result as a weighted sum
123  forAll(localOtherFaces, facei)
124  {
125  scalar sumW = 0;
126  Type sumWF = Zero;
127 
128  forAll(localOtherFaces[facei], i)
129  {
130  const scalar w = weights[facei][i];
131  sumW += w;
132  sumWF += w*localOtherFld[localOtherFaces[facei][i]];
133  }
134 
135  if (localOtherFaces[facei].size())
136  {
137  fld[facei] = sumWF/sumW;
138  }
139  }
140 
141  return tFld;
142 }
143 
144 
145 template<class Type, class LabelList, class ScalarList>
147 (
148  const List<LabelList>& localOtherFaces,
149  const List<ScalarList>& weights,
150  const autoPtr<distributionMap>& otherMapPtr,
151  const Field<Type>& otherFld,
152  const Field<Type>& leftOverFld
153 )
154 {
155  // Distribute the other field if necessary
156  tmp<Field<Type>> tLocalOtherFld;
157  if (otherMapPtr.valid())
158  {
159  tLocalOtherFld = tmp<Field<Type>>(new Field<Type>(otherFld));
160  otherMapPtr->distribute(tLocalOtherFld.ref());
161  }
162  const Field<Type>& localOtherFld =
163  otherMapPtr.valid() ? tLocalOtherFld() : otherFld;
164 
165  // Allocate the result
166  tmp<Field<Type>> tFld(new Field<Type>(localOtherFaces.size(), NaN<Type>()));
167  Field<Type>& fld = tFld.ref();
168 
169  // Compute the result as a weighted sum
170  forAll(localOtherFaces, facei)
171  {
172  scalar sumW = 0;
173  Type sumWF = Zero;
174 
175  forAll(localOtherFaces[facei], i)
176  {
177  const scalar w = weights[facei][i];
178  sumW += w;
179  sumWF += w*localOtherFld[localOtherFaces[facei][i]];
180  }
181 
182  fld[facei] = sumWF + (1 - sumW)*leftOverFld[facei];
183  }
184 
185  return tFld;
186 }
187 
188 
189 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A class for managing temporary objects.
Definition: tmp.H:55
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
volScalarField & b
Definition: createFields.H:27
static tmp< Field< Type > > interpolate(const List< LabelList > &localOtherFaces, const List< ScalarList > &weights, const autoPtr< distributionMap > &otherMapPtr, const Field< Type > &otherFld)
Interpolate with normalisation.
static void rDistributeListList(const label size, const distributionMap &map, List< List< Type >> &data)
Reverse distribute a list-list given the map.
static Type NaN()
Return a primitive with all components set to NaN.
static void transferListList(List< SubListA > &a, List< SubListB > &b)
Transfer list-list b into list-list a.
static const zero Zero
Definition: zero.H:97
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
label & setComponent(label &l, const direction)
Definition: label.H:86
uint8_t direction
Definition: direction.H:45