1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 Patch to patch interpolation functions
28 Hrvoje Jasak, Wikki Ltd. All rights reserved
30 \*---------------------------------------------------------------------------*/
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
39 //- Interpolate point field
40 template<class FromPatch, class ToPatch>
43 PatchToPatchInterpolation<FromPatch, ToPatch>::pointInterpolate
48 if (pf.size() != fromPatch_.nPoints())
52 "PatchToPatchInterpolation::pointInterpolate"
53 "(const Field<Type> pf)"
54 ) << "given field does not correspond to patch. Patch size: "
55 << fromPatch_.nPoints() << " field size: " << pf.size()
59 tmp<Field<Type> > tresult
68 // Escape the interpolation if there are no faces in the target patch
69 if (toPatch_.nPoints() == 0)
74 Field<Type>& result = tresult();
76 const List<typename FromPatch::FaceType>& fromPatchLocalFaces =
77 fromPatch_.localFaces();
79 const FieldField<Field, scalar>& weights = pointWeights();
81 const labelList& addr = pointAddr();
83 forAll (result, pointI)
85 const scalarField& curWeights = weights[pointI];
87 if (addr[pointI] > -1)
89 const labelList& hitFacePoints =
90 fromPatchLocalFaces[addr[pointI]];
92 forAll (curWeights, wI)
94 result[pointI] += curWeights[wI]*pf[hitFacePoints[wI]];
103 template<class FromPatch, class ToPatch>
106 PatchToPatchInterpolation<FromPatch, ToPatch>::pointInterpolate
108 const tmp<Field<Type> >& tpf
111 tmp<Field<Type> > tint = pointInterpolate<Type>(tpf());
117 //- Interpolate face field
118 template<class FromPatch, class ToPatch>
121 PatchToPatchInterpolation<FromPatch, ToPatch>::faceInterpolate
123 const Field<Type>& ff
126 if (ff.size() != fromPatch_.size())
130 "PatchToPatchInterpolation::faceInterpolate"
131 "(const Field<Type> ff)"
132 ) << "given field does not correspond to patch. Patch size: "
133 << fromPatch_.size() << " field size: " << ff.size()
134 << abort(FatalError);
137 tmp<Field<Type> > tresult
146 // Escape the interpolation if there are no faces in the target patch
147 if (toPatch_.size() == 0)
152 Field<Type>& result = tresult();
154 const labelListList& fromPatchFaceFaces = fromPatch_.faceFaces();
156 const FieldField<Field, scalar>& weights = faceWeights();
158 const labelList& addr = faceAddr();
160 forAll (result, faceI)
162 const scalarField& curWeights = weights[faceI];
164 if (addr[faceI] > -1)
166 const labelList& hitFaceFaces =
167 fromPatchFaceFaces[addr[faceI]];
169 // First add the hit face
170 result[faceI] += ff[addr[faceI]]*curWeights[0];
172 for (label wI = 1; wI < curWeights.size(); wI++)
174 result[faceI] += ff[hitFaceFaces[wI - 1]]*curWeights[wI];
183 template<class FromPatch, class ToPatch>
186 PatchToPatchInterpolation<FromPatch, ToPatch>::faceInterpolate
188 const tmp<Field<Type> >& tff
191 tmp<Field<Type> > tint = faceInterpolate(tff());
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 } // End namespace Foam
201 // ************************************************************************* //