initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / OpenFOAM / interpolations / patchToPatchInterpolation / PatchToPatchInterpolate.C
blobfd1b8c829198c8e194f79593565beb4b6e073ee0
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
26     Patch to patch interpolation functions
28 \*---------------------------------------------------------------------------*/
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 namespace Foam
35 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
37 //- Interpolate point field
38 template<class FromPatch, class ToPatch>
39 template<class Type>
40 tmp<Field<Type> >
41 PatchToPatchInterpolation<FromPatch, ToPatch>::pointInterpolate
43     const Field<Type>& pf
44 ) const
46     if (pf.size() != fromPatch_.nPoints())
47     {
48         FatalErrorIn
49         (
50             "PatchToPatchInterpolation::pointInterpolate"
51             "(const Field<Type> pf)"
52         )   << "given field does not correspond to patch. Patch size: "
53             << fromPatch_.nPoints() << " field size: " << pf.size()
54             << abort(FatalError);
55     }
57     tmp<Field<Type> > tresult
58     (
59         new Field<Type>
60         (
61             toPatch_.nPoints(),
62             pTraits<Type>::zero
63         )
64     );
66     Field<Type>& result = tresult();
68     const List<typename FromPatch::FaceType>& fromPatchLocalFaces =
69         fromPatch_.localFaces();
71     const FieldField<Field, scalar>& weights = pointWeights();
73     const labelList& addr = pointAddr();
75     forAll (result, pointI)
76     {
77         const scalarField& curWeights = weights[pointI];
79         if (addr[pointI] > -1)
80         {
81             const labelList& hitFacePoints =
82                 fromPatchLocalFaces[addr[pointI]];
84             forAll (curWeights, wI)
85             {
86                 result[pointI] += curWeights[wI]*pf[hitFacePoints[wI]];
87             }
88         }
89     }
91     return tresult;
95 template<class FromPatch, class ToPatch>
96 template<class Type>
97 tmp<Field<Type> >
98 PatchToPatchInterpolation<FromPatch, ToPatch>::pointInterpolate
100     const tmp<Field<Type> >& tpf
101 ) const
103     tmp<Field<Type> > tint = pointInterpolate<Type>(tpf());
104     tpf.clear();
105     return tint;
109 //- Interpolate face field
110 template<class FromPatch, class ToPatch>
111 template<class Type>
112 tmp<Field<Type> >
113 PatchToPatchInterpolation<FromPatch, ToPatch>::faceInterpolate
115     const Field<Type>& ff
116 ) const
118     if (ff.size() != fromPatch_.size())
119     {
120         FatalErrorIn
121         (
122             "PatchToPatchInterpolation::faceInterpolate"
123             "(const Field<Type> ff)"
124         )   << "given field does not correspond to patch. Patch size: "
125             << fromPatch_.size() << " field size: " << ff.size()
126             << abort(FatalError);
127     }
129     tmp<Field<Type> > tresult
130     (
131         new Field<Type>
132         (
133             toPatch_.size(),
134             pTraits<Type>::zero
135         )
136     );
138     Field<Type>& result = tresult();
140     const labelListList& fromPatchFaceFaces = fromPatch_.faceFaces();
142     const FieldField<Field, scalar>& weights = faceWeights();
144     const labelList& addr = faceAddr();
146     forAll (result, faceI)
147     {
148         const scalarField& curWeights = weights[faceI];
150         if (addr[faceI] > -1)
151         {
152             const labelList& hitFaceFaces =
153                 fromPatchFaceFaces[addr[faceI]];
155             // first add the hit face
156             result[faceI] += ff[addr[faceI]]*curWeights[0];
158             for (label wI = 1; wI < curWeights.size(); wI++)
159             {
160                 result[faceI] += ff[hitFaceFaces[wI - 1]]*curWeights[wI];
161             }
162         }
163     }
165     return tresult;
169 template<class FromPatch, class ToPatch>
170 template<class Type>
171 tmp<Field<Type> >
172 PatchToPatchInterpolation<FromPatch, ToPatch>::faceInterpolate
174     const tmp<Field<Type> >& tff
175 ) const
177     tmp<Field<Type> > tint = faceInterpolate(tff());
178     tff.clear();
179     return tint;
183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
185 } // End namespace Foam
187 // ************************************************************************* //