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

pointPatchInterpolate.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 "pointPatchInterpolation.H"
00028 #include "volFields.H"
00029 #include "pointFields.H"
00030 #include "emptyFvPatch.H"
00031 #include "valuePointPatchField.H"
00032 #include "coupledPointPatchField.H"
00033 #include "coupledFacePointPatch.H"
00034 #include "transform.H"
00035 
00036 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00037 
00038 namespace Foam
00039 {
00040 
00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00042 
00043 template<class Type>
00044 void pointPatchInterpolation::interpolate
00045 (
00046     const GeometricField<Type, fvPatchField, volMesh>& vf,
00047     GeometricField<Type, pointPatchField, pointMesh>& pf,
00048     bool overrideFixedValue
00049 ) const
00050 {
00051     if (debug)
00052     {
00053         Info<< "pointPatchInterpolation::interpolate("
00054             << "const GeometricField<Type, fvPatchField, volMesh>&, "
00055             << "GeometricField<Type, pointPatchField, pointMesh>&) : "
00056             << "interpolating field from cells to points"
00057             << endl;
00058     }
00059 
00060     // Interpolate patch values: over-ride the internal values for the points
00061     // on the patch with the interpolated point values from the faces of the
00062     // patch
00063 
00064     const fvBoundaryMesh& bm = fvMesh_.boundary();
00065     const pointBoundaryMesh& pbm = pointMesh::New(fvMesh_).boundary();
00066 
00067     forAll(bm, patchi)
00068     {
00069         if (!isA<emptyFvPatch>(bm[patchi]) && !bm[patchi].coupled())
00070         {
00071             pointPatchField<Type>& ppf = pf.boundaryField()[patchi];
00072 
00073             // Only map the values corresponding to the points associated with
00074             // faces, not "lone" points due to decomposition
00075             ppf.setInInternalField
00076             (
00077                 pf.internalField(),
00078                 patchInterpolators_[patchi]
00079                .faceToPointInterpolate(vf.boundaryField()[patchi])(),
00080                 bm[patchi].patch().meshPoints()
00081             );
00082 
00083             if
00084             (
00085                 overrideFixedValue
00086              && isA<valuePointPatchField<Type> >(ppf)
00087             )
00088             {
00089                 refCast<valuePointPatchField<Type> >(ppf) = ppf;
00090             }
00091         }
00092         else if (bm[patchi].coupled())
00093         {
00094             // Initialise the "lone" points on the coupled patch to zero,
00095             // these values are obtained from the couple-transfer
00096 
00097             const labelList& loneMeshPoints =
00098                 refCast<const coupledFacePointPatch>(pbm[patchi])
00099                .loneMeshPoints();
00100 
00101             forAll(loneMeshPoints, i)
00102             {
00103                 pf[loneMeshPoints[i]] = pTraits<Type>::zero;
00104             }
00105         }
00106 
00107     }
00108 
00109 
00110     // Correct patch-patch boundary points by interpolation "around" corners
00111     const labelListList& PointFaces = fvMesh_.pointFaces();
00112 
00113     forAll(patchPatchPoints_, pointi)
00114     {
00115         const label curPoint = patchPatchPoints_[pointi];
00116         const labelList& curFaces = PointFaces[curPoint];
00117 
00118         label fI = 0;
00119 
00120         // Reset the boundary value before accumulation
00121         pf[curPoint] = pTraits<Type>::zero;
00122 
00123         // Go through all the faces
00124         forAll(curFaces, facei)
00125         {
00126             if (!fvMesh_.isInternalFace(curFaces[facei]))
00127             {
00128                 label patchi =
00129                     fvMesh_.boundaryMesh().whichPatch(curFaces[facei]);
00130 
00131                 if (!isA<emptyFvPatch>(bm[patchi]) && !bm[patchi].coupled())
00132                 {
00133                     label faceInPatchi =
00134                         bm[patchi].patch().whichFace(curFaces[facei]);
00135 
00136                     pf[curPoint] +=
00137                         patchPatchPointWeights_[pointi][fI]
00138                        *vf.boundaryField()[patchi][faceInPatchi];
00139 
00140                     fI++;
00141                 }
00142             }
00143         }
00144     }
00145 
00146     // Update coupled boundaries
00147     forAll(pf.boundaryField(), patchi)
00148     {
00149         if (pf.boundaryField()[patchi].coupled())
00150         {
00151             refCast<coupledPointPatchField<Type> >(pf.boundaryField()[patchi])
00152                 .initSwapAdd(pf.internalField());
00153         }
00154     }
00155 
00156     forAll(pf.boundaryField(), patchi)
00157     {
00158         if (pf.boundaryField()[patchi].coupled())
00159         {
00160             refCast<coupledPointPatchField<Type> >(pf.boundaryField()[patchi])
00161                 .swapAdd(pf.internalField());
00162         }
00163     }
00164 
00165 
00166     // Override constrained pointPatchField types with the constraint value.
00167     // This relys on only constrained pointPatchField implementing the evaluate
00168     // function
00169     pf.correctBoundaryConditions();
00170 
00171 
00172     // Apply multiple constraints on edge/corner points
00173     applyCornerConstraints(pf);
00174 
00175 
00176     if (debug)
00177     {
00178         Info<< "pointPatchInterpolation::interpolate("
00179             << "const GeometricField<Type, fvPatchField, volMesh>&, "
00180             << "GeometricField<Type, pointPatchField, pointMesh>&) : "
00181             << "finished interpolating field from cells to points"
00182             << endl;
00183     }
00184 }
00185 
00186 
00187 template<class Type>
00188 void pointPatchInterpolation::applyCornerConstraints
00189 (
00190     GeometricField<Type, pointPatchField, pointMesh>& pf
00191 ) const
00192 {
00193     forAll(patchPatchPointConstraintPoints_, pointi)
00194     {
00195         pf[patchPatchPointConstraintPoints_[pointi]] = transform
00196         (
00197             patchPatchPointConstraintTensors_[pointi],
00198             pf[patchPatchPointConstraintPoints_[pointi]]
00199         );
00200     }
00201 }
00202 
00203 
00204 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00205 
00206 } // End namespace Foam
00207 
00208 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd