All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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, class LabelList, class ScalarList>
87 (
88  const List<LabelList>& localOtherFaces,
89  const List<ScalarList>& weights,
90  const autoPtr<distributionMap>& otherMapPtr,
91  const Field<Type>& otherFld
92 )
93 {
94  // Distribute the other field if necessary
95  tmp<Field<Type>> tLocalOtherFld;
96  if (otherMapPtr.valid())
97  {
98  tLocalOtherFld = tmp<Field<Type>>(new Field<Type>(otherFld));
99  otherMapPtr->distribute(tLocalOtherFld.ref());
100  }
101  const Field<Type>& localOtherFld =
102  otherMapPtr.valid() ? tLocalOtherFld() : otherFld;
103 
104  // Allocate the result
105  tmp<Field<Type>> tFld
106  (
107  new Field<Type>(localOtherFaces.size(), pTraits<Type>::nan)
108  );
109  Field<Type>& fld = tFld.ref();
110 
111  // Compute the result as a weighted sum
112  forAll(localOtherFaces, facei)
113  {
114  scalar sumW = 0;
115  Type sumWF = Zero;
116 
117  forAll(localOtherFaces[facei], i)
118  {
119  const scalar w = weights[facei][i];
120  sumW += w;
121  sumWF += w*localOtherFld[localOtherFaces[facei][i]];
122  }
123 
124  if (localOtherFaces[facei].size())
125  {
126  fld[facei] = sumWF/sumW;
127  }
128  }
129 
130  return tFld;
131 }
132 
133 
134 template<class Type, class LabelList, class ScalarList>
136 (
137  const List<LabelList>& localOtherFaces,
138  const List<ScalarList>& weights,
139  const autoPtr<distributionMap>& otherMapPtr,
140  const Field<Type>& otherFld,
141  const Field<Type>& leftOverFld
142 )
143 {
144  // Distribute the other field if necessary
145  tmp<Field<Type>> tLocalOtherFld;
146  if (otherMapPtr.valid())
147  {
148  tLocalOtherFld = tmp<Field<Type>>(new Field<Type>(otherFld));
149  otherMapPtr->distribute(tLocalOtherFld.ref());
150  }
151  const Field<Type>& localOtherFld =
152  otherMapPtr.valid() ? tLocalOtherFld() : otherFld;
153 
154  // Allocate the result
155  tmp<Field<Type>> tFld
156  (
157  new Field<Type>(localOtherFaces.size(), pTraits<Type>::nan)
158  );
159  Field<Type>& fld = tFld.ref();
160 
161  // Compute the result as a weighted sum
162  forAll(localOtherFaces, facei)
163  {
164  scalar sumW = 0;
165  Type sumWF = Zero;
166 
167  forAll(localOtherFaces[facei], i)
168  {
169  const scalar w = weights[facei][i];
170  sumW += w;
171  sumWF += w*localOtherFld[localOtherFaces[facei][i]];
172  }
173 
174  fld[facei] = sumWF + (1 - sumW)*leftOverFld[facei];
175  }
176 
177  return tFld;
178 }
179 
180 
181 // ************************************************************************* //
#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:25
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 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