Loading...
Searching...
No Matches
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-2022 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{
37// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
38
39template<class FromPatch, class ToPatch>
40template<class 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 auto tresult = tmp<Field<Type>>::New(toPatch_.nPoints(), Zero);
56 auto& result = tresult.ref();
57
58 const auto& fromPatchLocalFaces = fromPatch_.localFaces();
59
60 const FieldField<Field, scalar>& weights = pointWeights();
61
62 const labelList& addr = pointAddr();
63
64 forAll(result, pointi)
65 {
66 const scalarField& curWeights = weights[pointi];
67
68 if (addr[pointi] > -1)
69 {
70 const labelList& hitFacePoints =
71 fromPatchLocalFaces[addr[pointi]];
72
73 forAll(curWeights, wI)
74 {
75 result[pointi] += curWeights[wI]*pf[hitFacePoints[wI]];
76 }
77 }
78 }
79
80 return tresult;
82
83
84template<class FromPatch, class ToPatch>
85template<class Type>
88(
89 const tmp<Field<Type>>& tpf
90) const
91{
92 tmp<Field<Type>> tint = pointInterpolate<Type>(tpf());
93 tpf.clear();
94 return tint;
96
97
98template<class FromPatch, class ToPatch>
99template<class Type>
102(
103 const Field<Type>& ff
104) const
105{
106 if (ff.size() != fromPatch_.size())
107 {
109 << "given field does not correspond to patch. Patch size: "
110 << fromPatch_.size() << " field size: " << ff.size()
111 << abort(FatalError);
112 }
113
114 auto tresult = tmp<Field<Type>>::New(toPatch_.size(), Zero);
115 auto& result = tresult.ref();
116
117 const labelListList& fromPatchFaceFaces = fromPatch_.faceFaces();
118
119 const FieldField<Field, scalar>& weights = faceWeights();
120
121 const labelList& addr = faceAddr();
122
123 forAll(result, facei)
124 {
125 const scalarField& curWeights = weights[facei];
126
127 if (addr[facei] > -1)
128 {
129 const labelList& hitFaceFaces =
130 fromPatchFaceFaces[addr[facei]];
131
132 // first add the hit face
133 result[facei] += ff[addr[facei]]*curWeights[0];
134
135 for (label wI = 1; wI < curWeights.size(); wI++)
136 {
137 result[facei] += ff[hitFaceFaces[wI - 1]]*curWeights[wI];
138 }
139 }
140 }
141
142 return tresult;
144
145
146template<class FromPatch, class ToPatch>
147template<class Type>
150(
151 const tmp<Field<Type>>& tff
152) const
153{
154 tmp<Field<Type>> tint = faceInterpolate(tff());
155 tff.clear();
156 return tint;
157}
158
159
160// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161
162} // End namespace Foam
163
164// ************************************************************************* //
A field of fields is a PtrList of fields with reference counting.
Definition FieldField.H:77
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
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:118
A class for managing temporary objects.
Definition tmp.H:75
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
Namespace for OpenFOAM.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
List< label > labelList
A List of labels.
Definition List.H:62
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
errorManip< error > abort(error &err)
Definition errorManip.H:139
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299