PatchToPatchInterpolate.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 | Copyright (C) 2011-2016 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 Description
25  Patch to patch interpolation functions
26 
27 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
35 
36 template<class FromPatch, class ToPatch>
37 template<class Type>
38 tmp<Field<Type>>
40 (
41  const Field<Type>& pf
42 ) const
43 {
44  if (pf.size() != fromPatch_.nPoints())
45  {
47  << "given field does not correspond to patch. Patch size: "
48  << fromPatch_.nPoints() << " field size: " << pf.size()
49  << abort(FatalError);
50  }
51 
52  tmp<Field<Type>> tresult
53  (
54  new Field<Type>(toPatch_.nPoints(), Zero)
55  );
56 
57  Field<Type>& result = tresult.ref();
58 
59  const List<typename FromPatch::FaceType>& fromPatchLocalFaces =
60  fromPatch_.localFaces();
61 
62  const FieldField<Field, scalar>& weights = pointWeights();
63 
64  const labelList& addr = pointAddr();
65 
66  forAll(result, pointi)
67  {
68  const scalarField& curWeights = weights[pointi];
69 
70  if (addr[pointi] > -1)
71  {
72  const labelList& hitFacePoints =
73  fromPatchLocalFaces[addr[pointi]];
74 
75  forAll(curWeights, wI)
76  {
77  result[pointi] += curWeights[wI]*pf[hitFacePoints[wI]];
78  }
79  }
80  }
81 
82  return tresult;
83 }
84 
85 
86 template<class FromPatch, class ToPatch>
87 template<class Type>
90 (
91  const tmp<Field<Type>>& tpf
92 ) const
93 {
94  tmp<Field<Type>> tint = pointInterpolate<Type>(tpf());
95  tpf.clear();
96  return tint;
97 }
98 
99 
100 template<class FromPatch, class ToPatch>
101 template<class Type>
104 (
105  const Field<Type>& ff
106 ) const
107 {
108  if (ff.size() != fromPatch_.size())
109  {
111  << "given field does not correspond to patch. Patch size: "
112  << fromPatch_.size() << " field size: " << ff.size()
113  << abort(FatalError);
114  }
115 
116  tmp<Field<Type>> tresult
117  (
118  new Field<Type>(toPatch_.size(), Zero)
119  );
120 
121  Field<Type>& result = tresult.ref();
122 
123  const labelListList& fromPatchFaceFaces = fromPatch_.faceFaces();
124 
125  const FieldField<Field, scalar>& weights = faceWeights();
126 
127  const labelList& addr = faceAddr();
128 
129  forAll(result, facei)
130  {
131  const scalarField& curWeights = weights[facei];
132 
133  if (addr[facei] > -1)
134  {
135  const labelList& hitFaceFaces =
136  fromPatchFaceFaces[addr[facei]];
137 
138  // first add the hit face
139  result[facei] += ff[addr[facei]]*curWeights[0];
140 
141  for (label wI = 1; wI < curWeights.size(); wI++)
142  {
143  result[facei] += ff[hitFaceFaces[wI - 1]]*curWeights[wI];
144  }
145  }
146  }
147 
148  return tresult;
149 }
150 
151 
152 template<class FromPatch, class ToPatch>
153 template<class Type>
156 (
157  const tmp<Field<Type>>& tff
158 ) const
159 {
160  tmp<Field<Type>> tint = faceInterpolate(tff());
161  tff.clear();
162  return tint;
163 }
164 
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 } // End namespace Foam
169 
170 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
tmp< Field< Type > > faceInterpolate(const Field< Type > &pf) const
Interpolate face field.
Generic field type.
Definition: FieldField.H:51
tmp< Field< Type > > pointInterpolate(const Field< Type > &pf) const
Interpolate point field.
void clear() const
If object pointer points to valid object:
Definition: tmpI.H:230
Pre-declare SubField and related Field type.
Definition: Field.H:57
static const zero Zero
Definition: zero.H:91
errorManip< error > abort(error &err)
Definition: errorManip.H:131
A class for managing temporary objects.
Definition: PtrList.H:54
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:174
Namespace for OpenFOAM.