FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Description
00025     Patch to patch interpolation functions
00026 
00027 \*---------------------------------------------------------------------------*/
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00035 
00036 //- Interpolate point field
00037 template<class FromPatch, class ToPatch>
00038 template<class Type>
00039 tmp<Field<Type> >
00040 PatchToPatchInterpolation<FromPatch, ToPatch>::pointInterpolate
00041 (
00042     const Field<Type>& pf
00043 ) const
00044 {
00045     if (pf.size() != fromPatch_.nPoints())
00046     {
00047         FatalErrorIn
00048         (
00049             "PatchToPatchInterpolation::pointInterpolate"
00050             "(const Field<Type> pf)"
00051         )   << "given field does not correspond to patch. Patch size: "
00052             << fromPatch_.nPoints() << " field size: " << pf.size()
00053             << abort(FatalError);
00054     }
00055 
00056     tmp<Field<Type> > tresult
00057     (
00058         new Field<Type>
00059         (
00060             toPatch_.nPoints(),
00061             pTraits<Type>::zero
00062         )
00063     );
00064 
00065     Field<Type>& result = tresult();
00066 
00067     const List<typename FromPatch::FaceType>& fromPatchLocalFaces =
00068         fromPatch_.localFaces();
00069 
00070     const FieldField<Field, scalar>& weights = pointWeights();
00071 
00072     const labelList& addr = pointAddr();
00073 
00074     forAll (result, pointI)
00075     {
00076         const scalarField& curWeights = weights[pointI];
00077 
00078         if (addr[pointI] > -1)
00079         {
00080             const labelList& hitFacePoints =
00081                 fromPatchLocalFaces[addr[pointI]];
00082 
00083             forAll (curWeights, wI)
00084             {
00085                 result[pointI] += curWeights[wI]*pf[hitFacePoints[wI]];
00086             }
00087         }
00088     }
00089 
00090     return tresult;
00091 }
00092 
00093 
00094 template<class FromPatch, class ToPatch>
00095 template<class Type>
00096 tmp<Field<Type> >
00097 PatchToPatchInterpolation<FromPatch, ToPatch>::pointInterpolate
00098 (
00099     const tmp<Field<Type> >& tpf
00100 ) const
00101 {
00102     tmp<Field<Type> > tint = pointInterpolate<Type>(tpf());
00103     tpf.clear();
00104     return tint;
00105 }
00106 
00107 
00108 //- Interpolate face field
00109 template<class FromPatch, class ToPatch>
00110 template<class Type>
00111 tmp<Field<Type> >
00112 PatchToPatchInterpolation<FromPatch, ToPatch>::faceInterpolate
00113 (
00114     const Field<Type>& ff
00115 ) const
00116 {
00117     if (ff.size() != fromPatch_.size())
00118     {
00119         FatalErrorIn
00120         (
00121             "PatchToPatchInterpolation::faceInterpolate"
00122             "(const Field<Type> ff)"
00123         )   << "given field does not correspond to patch. Patch size: "
00124             << fromPatch_.size() << " field size: " << ff.size()
00125             << abort(FatalError);
00126     }
00127 
00128     tmp<Field<Type> > tresult
00129     (
00130         new Field<Type>
00131         (
00132             toPatch_.size(),
00133             pTraits<Type>::zero
00134         )
00135     );
00136 
00137     Field<Type>& result = tresult();
00138 
00139     const labelListList& fromPatchFaceFaces = fromPatch_.faceFaces();
00140 
00141     const FieldField<Field, scalar>& weights = faceWeights();
00142 
00143     const labelList& addr = faceAddr();
00144 
00145     forAll (result, faceI)
00146     {
00147         const scalarField& curWeights = weights[faceI];
00148 
00149         if (addr[faceI] > -1)
00150         {
00151             const labelList& hitFaceFaces =
00152                 fromPatchFaceFaces[addr[faceI]];
00153 
00154             // first add the hit face
00155             result[faceI] += ff[addr[faceI]]*curWeights[0];
00156 
00157             for (label wI = 1; wI < curWeights.size(); wI++)
00158             {
00159                 result[faceI] += ff[hitFaceFaces[wI - 1]]*curWeights[wI];
00160             }
00161         }
00162     }
00163 
00164     return tresult;
00165 }
00166 
00167 
00168 template<class FromPatch, class ToPatch>
00169 template<class Type>
00170 tmp<Field<Type> >
00171 PatchToPatchInterpolation<FromPatch, ToPatch>::faceInterpolate
00172 (
00173     const tmp<Field<Type> >& tff
00174 ) const
00175 {
00176     tmp<Field<Type> > tint = faceInterpolate(tff());
00177     tff.clear();
00178     return tint;
00179 }
00180 
00181 
00182 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00183 
00184 } // End namespace Foam
00185 
00186 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines