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

volPointInterpolate.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 \*---------------------------------------------------------------------------*/
00025 
00026 #include "volPointInterpolation.H"
00027 #include <finiteVolume/volFields.H>
00028 #include <OpenFOAM/pointFields.H>
00029 #include <OpenFOAM/globalPointPatch.H>
00030 
00031 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00032 
00033 namespace Foam
00034 {
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 template<class Type>
00039 void volPointInterpolation::interpolateInternalField
00040 (
00041     const GeometricField<Type, fvPatchField, volMesh>& vf,
00042     GeometricField<Type, pointPatchField, pointMesh>& pf
00043 ) const
00044 {
00045     if (debug)
00046     {
00047         Info<< "volPointInterpolation::interpolateInternalField("
00048             << "const GeometricField<Type, fvPatchField, volMesh>&, "
00049             << "GeometricField<Type, pointPatchField, pointMesh>&) : "
00050             << "interpolating field from cells to points"
00051             << endl;
00052     }
00053 
00054     const labelListList& pointCells = vf.mesh().pointCells();
00055 
00056     // Multiply volField by weighting factor matrix to create pointField
00057     forAll(pointCells, pointi)
00058     {
00059         const scalarList& pw = pointWeights_[pointi];
00060         const labelList& ppc = pointCells[pointi];
00061 
00062         pf[pointi] = pTraits<Type>::zero;
00063 
00064         forAll(ppc, pointCelli)
00065         {
00066             pf[pointi] += pw[pointCelli]*vf[ppc[pointCelli]];
00067         }
00068     }
00069 }
00070 
00071 
00072 template<class Type>
00073 void volPointInterpolation::interpolate
00074 (
00075     const GeometricField<Type, fvPatchField, volMesh>& vf,
00076     GeometricField<Type, pointPatchField, pointMesh>& pf
00077 ) const
00078 {
00079     if (debug)
00080     {
00081         Info<< "volPointInterpolation::interpolate("
00082             << "const GeometricField<Type, fvPatchField, volMesh>&, "
00083             << "GeometricField<Type, pointPatchField, pointMesh>&) : "
00084             << "interpolating field from cells to points"
00085             << endl;
00086     }
00087 
00088     interpolateInternalField(vf, pf);
00089 
00090     // Interpolate to the patches preserving fixed value BCs
00091     boundaryInterpolator_.interpolate(vf, pf, false);
00092 }
00093 
00094 
00095 template<class Type>
00096 tmp<GeometricField<Type, pointPatchField, pointMesh> >
00097 volPointInterpolation::interpolate
00098 (
00099     const GeometricField<Type, fvPatchField, volMesh>& vf,
00100     const wordList& patchFieldTypes
00101 ) const
00102 {
00103     wordList types(patchFieldTypes);
00104 
00105     const pointMesh& pMesh = pointMesh::New(vf.mesh());
00106 
00107     // If the last patch of the pointBoundaryMesh is the global patch
00108     // it must be added to the list of patchField types
00109     if
00110     (
00111         isType<globalPointPatch>
00112         (
00113             pMesh.boundary()[pMesh.boundary().size() - 1]
00114         )
00115     )
00116     {
00117         types.setSize(types.size() + 1);
00118         types[types.size()-1] = pMesh.boundary()[types.size()-1].type();
00119     }
00120 
00121     // Construct tmp<pointField>
00122     tmp<GeometricField<Type, pointPatchField, pointMesh> > tpf
00123     (
00124         new GeometricField<Type, pointPatchField, pointMesh>
00125         (
00126             IOobject
00127             (
00128                 "volPointInterpolate(" + vf.name() + ')',
00129                 vf.instance(),
00130                 pMesh.thisDb()
00131             ),
00132             pMesh,
00133             vf.dimensions(),
00134             types
00135         )
00136     );
00137 
00138     interpolateInternalField(vf, tpf());
00139 
00140     // Interpolate to the patches overriding fixed value BCs
00141     boundaryInterpolator_.interpolate(vf, tpf(), true);
00142 
00143     return tpf;
00144 }
00145 
00146 
00147 template<class Type>
00148 tmp<GeometricField<Type, pointPatchField, pointMesh> >
00149 volPointInterpolation::interpolate
00150 (
00151     const tmp<GeometricField<Type, fvPatchField, volMesh> >& tvf,
00152     const wordList& patchFieldTypes
00153 ) const
00154 {
00155     // Construct tmp<pointField>
00156     tmp<GeometricField<Type, pointPatchField, pointMesh> > tpf =
00157         interpolate(tvf(), patchFieldTypes);
00158     tvf.clear();
00159     return tpf;
00160 }
00161 
00162 
00163 template<class Type>
00164 tmp<GeometricField<Type, pointPatchField, pointMesh> >
00165 volPointInterpolation::interpolate
00166 (
00167     const GeometricField<Type, fvPatchField, volMesh>& vf
00168 ) const
00169 {
00170     const pointMesh& pm = pointMesh::New(vf.mesh());
00171 
00172     tmp<GeometricField<Type, pointPatchField, pointMesh> > tpf
00173     (
00174         new GeometricField<Type, pointPatchField, pointMesh>
00175         (
00176             IOobject
00177             (
00178                 "volPointInterpolate(" + vf.name() + ')',
00179                 vf.instance(),
00180                 pm.thisDb()
00181             ),
00182             pm,
00183             vf.dimensions()
00184         )
00185     );
00186 
00187     interpolateInternalField(vf, tpf());
00188     boundaryInterpolator_.interpolate(vf, tpf(), false);
00189 
00190     return tpf;
00191 }
00192 
00193 
00194 template<class Type>
00195 tmp<GeometricField<Type, pointPatchField, pointMesh> >
00196 volPointInterpolation::interpolate
00197 (
00198     const tmp<GeometricField<Type, fvPatchField, volMesh> >& tvf
00199 ) const
00200 {
00201     // Construct tmp<pointField>
00202     tmp<GeometricField<Type, pointPatchField, pointMesh> > tpf =
00203         interpolate(tvf());
00204     tvf.clear();
00205     return tpf;
00206 }
00207 
00208 
00209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00210 
00211 } // End namespace Foam
00212 
00213 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines