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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Description
28 Patch to patch interpolation functions
29
30\*---------------------------------------------------------------------------*/
31
32// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33
34namespace Foam
35{
36
37// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
38
39template<class FromPatch, class ToPatch>
40template<class Type>
41tmp<Field<Type>>
43(
44 const Field<Type>& pf
45) const
46{
47 if (pf.size() != fromPatch_.nPoints())
48 {
50 << "given field does not correspond to patch. Patch size: "
51 << fromPatch_.nPoints() << " field size: " << pf.size()
52 << abort(FatalError);
53 }
54
55 tmp<Field<Type>> tresult
56 (
57 new Field<Type>(toPatch_.nPoints(), Zero)
58 );
59
60 Field<Type>& result = tresult.ref();
61
62 const List<typename FromPatch::face_type>& fromPatchLocalFaces =
63 fromPatch_.localFaces();
64
65 const FieldField<Field, scalar>& weights = pointWeights();
66
67 const labelList& addr = pointAddr();
68
69 forAll(result, pointi)
70 {
71 const scalarField& curWeights = weights[pointi];
72
73 if (addr[pointi] > -1)
74 {
75 const labelList& hitFacePoints =
76 fromPatchLocalFaces[addr[pointi]];
77
78 forAll(curWeights, wI)
79 {
80 result[pointi] += curWeights[wI]*pf[hitFacePoints[wI]];
81 }
82 }
83 }
84
85 return tresult;
86}
87
88
89template<class FromPatch, class ToPatch>
90template<class Type>
93(
94 const tmp<Field<Type>>& tpf
95) const
96{
97 tmp<Field<Type>> tint = pointInterpolate<Type>(tpf());
98 tpf.clear();
99 return tint;
100}
101
102
103template<class FromPatch, class ToPatch>
104template<class Type>
107(
108 const Field<Type>& ff
109) const
110{
111 if (ff.size() != fromPatch_.size())
112 {
114 << "given field does not correspond to patch. Patch size: "
115 << fromPatch_.size() << " field size: " << ff.size()
116 << abort(FatalError);
117 }
118
119 tmp<Field<Type>> tresult
120 (
121 new Field<Type>(toPatch_.size(), Zero)
122 );
123
124 Field<Type>& result = tresult.ref();
125
126 const labelListList& fromPatchFaceFaces = fromPatch_.faceFaces();
127
128 const FieldField<Field, scalar>& weights = faceWeights();
129
130 const labelList& addr = faceAddr();
131
132 forAll(result, facei)
133 {
134 const scalarField& curWeights = weights[facei];
135
136 if (addr[facei] > -1)
137 {
138 const labelList& hitFaceFaces =
139 fromPatchFaceFaces[addr[facei]];
140
141 // first add the hit face
142 result[facei] += ff[addr[facei]]*curWeights[0];
143
144 for (label wI = 1; wI < curWeights.size(); wI++)
145 {
146 result[facei] += ff[hitFaceFaces[wI - 1]]*curWeights[wI];
147 }
148 }
149 }
150
151 return tresult;
152}
153
154
155template<class FromPatch, class ToPatch>
156template<class Type>
159(
160 const tmp<Field<Type>>& tff
161) const
162{
163 tmp<Field<Type>> tint = faceInterpolate(tff());
164 tff.clear();
165 return tint;
166}
167
168
169// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
170
171} // End namespace Foam
172
173// ************************************************************************* //
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:80
Generic templated field type.
Definition: Field.H:82
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
tmp< Field< Type > > pointInterpolate(const Field< Type > &pf) const
Interpolate point field.
tmp< Field< Type > > faceInterpolate(const Field< Type > &pf) const
Interpolate face field.
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A class for managing temporary objects.
Definition: tmp.H:65
T & ref() const
Definition: tmpI.H:227
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Namespace for OpenFOAM.
errorManip< error > abort(error &err)
Definition: errorManip.H:144
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
error FatalError
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333