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

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