OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

PatchToPatchInterpolate.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Patch to patch interpolation functions
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 
00035 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00036 
00037 //- Interpolate point field
00038 template<class FromPatch, class ToPatch>
00039 template<class Type>
00040 tmp<Field<Type> >
00041 PatchToPatchInterpolation<FromPatch, ToPatch>::pointInterpolate
00042 (
00043     const Field<Type>& pf
00044 ) const
00045 {
00046     if (pf.size() != fromPatch_.nPoints())
00047     {
00048         FatalErrorIn
00049         (
00050             "PatchToPatchInterpolation::pointInterpolate"
00051             "(const Field<Type> pf)"
00052         )   << "given field does not correspond to patch. Patch size: "
00053             << fromPatch_.nPoints() << " field size: " << pf.size()
00054             << abort(FatalError);
00055     }
00056 
00057     tmp<Field<Type> > tresult
00058     (
00059         new Field<Type>
00060         (
00061             toPatch_.nPoints(),
00062             pTraits<Type>::zero
00063         )
00064     );
00065 
00066     Field<Type>& result = tresult();
00067 
00068     const List<typename FromPatch::FaceType>& fromPatchLocalFaces =
00069         fromPatch_.localFaces();
00070 
00071     const FieldField<Field, scalar>& weights = pointWeights();
00072 
00073     const labelList& addr = pointAddr();
00074 
00075     forAll (result, pointI)
00076     {
00077         const scalarField& curWeights = weights[pointI];
00078 
00079         if (addr[pointI] > -1)
00080         {
00081             const labelList& hitFacePoints =
00082                 fromPatchLocalFaces[addr[pointI]];
00083 
00084             forAll (curWeights, wI)
00085             {
00086                 result[pointI] += curWeights[wI]*pf[hitFacePoints[wI]];
00087             }
00088         }
00089     }
00090 
00091     return tresult;
00092 }
00093 
00094 
00095 template<class FromPatch, class ToPatch>
00096 template<class Type>
00097 tmp<Field<Type> >
00098 PatchToPatchInterpolation<FromPatch, ToPatch>::pointInterpolate
00099 (
00100     const tmp<Field<Type> >& tpf
00101 ) const
00102 {
00103     tmp<Field<Type> > tint = pointInterpolate<Type>(tpf());
00104     tpf.clear();
00105     return tint;
00106 }
00107 
00108 
00109 //- Interpolate face field
00110 template<class FromPatch, class ToPatch>
00111 template<class Type>
00112 tmp<Field<Type> >
00113 PatchToPatchInterpolation<FromPatch, ToPatch>::faceInterpolate
00114 (
00115     const Field<Type>& ff
00116 ) const
00117 {
00118     if (ff.size() != fromPatch_.size())
00119     {
00120         FatalErrorIn
00121         (
00122             "PatchToPatchInterpolation::faceInterpolate"
00123             "(const Field<Type> ff)"
00124         )   << "given field does not correspond to patch. Patch size: "
00125             << fromPatch_.size() << " field size: " << ff.size()
00126             << abort(FatalError);
00127     }
00128 
00129     tmp<Field<Type> > tresult
00130     (
00131         new Field<Type>
00132         (
00133             toPatch_.size(),
00134             pTraits<Type>::zero
00135         )
00136     );
00137 
00138     Field<Type>& result = tresult();
00139 
00140     const labelListList& fromPatchFaceFaces = fromPatch_.faceFaces();
00141 
00142     const FieldField<Field, scalar>& weights = faceWeights();
00143 
00144     const labelList& addr = faceAddr();
00145 
00146     forAll (result, faceI)
00147     {
00148         const scalarField& curWeights = weights[faceI];
00149 
00150         if (addr[faceI] > -1)
00151         {
00152             const labelList& hitFaceFaces =
00153                 fromPatchFaceFaces[addr[faceI]];
00154 
00155             // first add the hit face
00156             result[faceI] += ff[addr[faceI]]*curWeights[0];
00157 
00158             for (label wI = 1; wI < curWeights.size(); wI++)
00159             {
00160                 result[faceI] += ff[hitFaceFaces[wI - 1]]*curWeights[wI];
00161             }
00162         }
00163     }
00164 
00165     return tresult;
00166 }
00167 
00168 
00169 template<class FromPatch, class ToPatch>
00170 template<class Type>
00171 tmp<Field<Type> >
00172 PatchToPatchInterpolation<FromPatch, ToPatch>::faceInterpolate
00173 (
00174     const tmp<Field<Type> >& tff
00175 ) const
00176 {
00177     tmp<Field<Type> > tint = faceInterpolate(tff());
00178     tff.clear();
00179     return tint;
00180 }
00181 
00182 
00183 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00184 
00185 } // End namespace Foam
00186 
00187 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd