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

fvMeshSubsetInterpolate.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 "fvMeshSubset.H"
00028 #include "emptyFvsPatchField.H"
00029 #include "emptyPointPatchField.H"
00030 #include "emptyFvPatchFields.H"
00031 
00032 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00033 
00034 namespace Foam
00035 {
00036 
00037 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00038 
00039 template<class Type>
00040 tmp<GeometricField<Type, fvPatchField, volMesh> > fvMeshSubset::interpolate
00041 (
00042     const GeometricField<Type, fvPatchField, volMesh>& vf,
00043     const fvMesh& sMesh,
00044     const labelList& patchMap,
00045     const labelList& cellMap,
00046     const labelList& faceMap
00047 )
00048 {
00049     // Create and map the internal-field values
00050     Field<Type> internalField(vf.internalField(), cellMap);
00051 
00052     // Create and map the patch field values
00053     PtrList<fvPatchField<Type> > patchFields(patchMap.size());
00054 
00055     forAll (patchFields, patchI)
00056     {
00057         // Set the first one by hand as it corresponds to the
00058         // exposed internal faces.  Additional interpolation can be put here
00059         // as necessary.  
00060         if (patchMap[patchI] == -1)
00061         {
00062             patchFields.set
00063             (
00064                 patchI,
00065                 new emptyFvPatchField<Type>
00066                 (
00067                     sMesh.boundary()[patchI],
00068                     DimensionedField<Type, volMesh>::null()
00069                 )
00070             );
00071         }
00072         else
00073         {
00074             // Construct addressing
00075             const fvPatch& subPatch = sMesh.boundary()[patchI];
00076             const fvPatch& basePatch = vf.mesh().boundary()[patchMap[patchI]];
00077             label baseStart = basePatch.patch().start();
00078             label baseSize = basePatch.size();
00079 
00080             labelList directAddressing(subPatch.size());
00081 
00082             forAll(directAddressing, i)
00083             {
00084                 label baseFaceI = faceMap[subPatch.patch().start()+i];
00085 
00086                 if (baseFaceI >= baseStart && baseFaceI < baseStart+baseSize)
00087                 {
00088                     directAddressing[i] = baseFaceI-baseStart;
00089                 }
00090                 else
00091                 {
00092                     // Mapped from internal face. Do what? Map from element
00093                     // 0 for now.
00094                     directAddressing[i] = 0;
00095                 }
00096             }
00097 
00098             patchFields.set
00099             (
00100                 patchI,
00101                 fvPatchField<Type>::New
00102                 (
00103                     vf.boundaryField()[patchMap[patchI]],
00104                     sMesh.boundary()[patchI],
00105                     DimensionedField<Type, volMesh>::null(),
00106                     patchFieldSubset(directAddressing)
00107                 )
00108             );
00109 
00110             // What to do with exposed internal faces if put into this patch?
00111         }
00112     }
00113 
00114 
00115     // Create the complete field from the pieces
00116     tmp<GeometricField<Type, fvPatchField, volMesh> > tresF
00117     (
00118         new GeometricField<Type, fvPatchField, volMesh>
00119         (
00120             IOobject
00121             (
00122                 "subset"+vf.name(),
00123                 sMesh.time().timeName(),
00124                 sMesh,
00125                 IOobject::NO_READ,
00126                 IOobject::NO_WRITE
00127             ),
00128             sMesh,
00129             vf.dimensions(),
00130             internalField,
00131             patchFields
00132         )
00133     );
00134 
00135     return tresF;
00136 }
00137 
00138 
00139 template<class Type>
00140 tmp<GeometricField<Type, fvPatchField, volMesh> > fvMeshSubset::interpolate
00141 (
00142     const GeometricField<Type, fvPatchField, volMesh>& vf
00143 ) const
00144 {
00145     return interpolate
00146     (
00147         vf,
00148         subMesh(),
00149         patchMap(),
00150         cellMap(),
00151         faceMap()
00152     );
00153 }
00154 
00155 
00156 template<class Type>
00157 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > fvMeshSubset::interpolate
00158 (
00159     const GeometricField<Type, fvsPatchField, surfaceMesh>& vf,
00160     const fvMesh& sMesh,
00161     const labelList& patchMap,
00162     const labelList& faceMap
00163 )
00164 {
00165     // Create and map the internal-field values
00166     Field<Type> internalField
00167     (
00168         vf.internalField(),
00169         SubList<label>
00170         (
00171             faceMap,
00172             sMesh.nInternalFaces()
00173         )
00174     );
00175 
00176     // Create and map the patch field values
00177     PtrList<fvsPatchField<Type> > patchFields(patchMap.size());
00178 
00179     forAll (patchFields, patchI)
00180     {
00181         // Set the first one by hand as it corresponds to the
00182         // exposed internal faces.  Additional interpolation can be put here
00183         // as necessary.  
00184         if (patchMap[patchI] == -1)
00185         {
00186             patchFields.set
00187             (
00188                 patchI,
00189                 new emptyFvsPatchField<Type>
00190                 (
00191                     sMesh.boundary()[patchI],
00192                     DimensionedField<Type, surfaceMesh>::null()
00193                 )
00194             );
00195         }
00196         else
00197         {
00198             // Construct addressing
00199             const fvPatch& subPatch = sMesh.boundary()[patchI];
00200             const fvPatch& basePatch = vf.mesh().boundary()[patchMap[patchI]];
00201             label baseStart = basePatch.patch().start();
00202             label baseSize = basePatch.size();
00203 
00204             labelList directAddressing(subPatch.size());
00205 
00206             forAll(directAddressing, i)
00207             {
00208                 label baseFaceI = faceMap[subPatch.patch().start()+i];
00209 
00210                 if (baseFaceI >= baseStart && baseFaceI < baseStart+baseSize)
00211                 {
00212                     directAddressing[i] = baseFaceI-baseStart;
00213                 }
00214                 else
00215                 {
00216                     // Mapped from internal face. Do what? Map from element
00217                     // 0 for now.
00218                     directAddressing[i] = 0;
00219                 }
00220             }
00221 
00222             patchFields.set
00223             (
00224                 patchI,
00225                 fvsPatchField<Type>::New
00226                 (
00227                     vf.boundaryField()[patchMap[patchI]],
00228                     sMesh.boundary()[patchI],
00229                     DimensionedField<Type, surfaceMesh>::null(),
00230                     patchFieldSubset(directAddressing)
00231                 )
00232             );
00233         }
00234     }
00235 
00236 
00237     // Map exposed internal faces. Note: Only nessecary if exposed faces added
00238     // into existing patch but since we don't know that at this point...
00239     forAll(patchFields, patchI)
00240     {
00241         fvsPatchField<Type>& pfld = patchFields[patchI];
00242 
00243         label meshFaceI = pfld.patch().patch().start();
00244 
00245         forAll(pfld, i)
00246         {
00247             label oldFaceI = faceMap[meshFaceI++];
00248 
00249             if (oldFaceI < vf.internalField().size())
00250             {
00251                 pfld[i] = vf.internalField()[oldFaceI];
00252             }
00253         }
00254     }
00255 
00256     // Create the complete field from the pieces
00257     tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > tresF
00258     (
00259         new GeometricField<Type, fvsPatchField, surfaceMesh>
00260         (
00261             IOobject
00262             (
00263                 "subset"+vf.name(),
00264                 sMesh.time().timeName(),
00265                 sMesh,
00266                 IOobject::NO_READ,
00267                 IOobject::NO_WRITE
00268             ),
00269             sMesh,
00270             vf.dimensions(),
00271             internalField,
00272             patchFields
00273         )
00274     );
00275 
00276     return tresF;
00277 }
00278 
00279 
00280 template<class Type>
00281 tmp<GeometricField<Type, fvsPatchField, surfaceMesh> > fvMeshSubset::interpolate
00282 (
00283     const GeometricField<Type, fvsPatchField, surfaceMesh>& sf
00284 ) const
00285 {
00286     return interpolate
00287     (
00288         sf,
00289         subMesh(),
00290         patchMap(),
00291         faceMap()
00292     );
00293 }
00294 
00295 
00296 template<class Type>
00297 tmp<GeometricField<Type, pointPatchField, pointMesh> >
00298 fvMeshSubset::interpolate
00299 (
00300     const GeometricField<Type, pointPatchField, pointMesh>& vf,
00301     const pointMesh& sMesh,
00302     const labelList& patchMap,
00303     const labelList& pointMap
00304 )
00305 {
00306     // Create and map the internal-field values
00307     Field<Type> internalField(vf.internalField(), pointMap);
00308 
00309     // Create and map the patch field values
00310     PtrList<pointPatchField<Type> > patchFields(patchMap.size());
00311 
00312     forAll (patchFields, patchI)
00313     {
00314         // Set the first one by hand as it corresponds to the
00315         // exposed internal faces.  Additional interpolation can be put here
00316         // as necessary.  
00317         if (patchMap[patchI] == -1)
00318         {
00319             patchFields.set
00320             (
00321                 patchI,
00322                 new emptyPointPatchField<Type>
00323                 (
00324                     sMesh.boundary()[patchI],
00325                     DimensionedField<Type, pointMesh>::null()
00326                 )
00327             );
00328         }
00329         else
00330         {
00331             // Construct addressing
00332             const pointPatch& basePatch =
00333                 vf.mesh().boundary()[patchMap[patchI]];
00334 
00335             const labelList& meshPoints = basePatch.meshPoints();
00336 
00337             // Make addressing from mesh to patch point
00338             Map<label> meshPointMap(2*meshPoints.size());
00339             forAll(meshPoints, localI)
00340             {
00341                 meshPointMap.insert(meshPoints[localI], localI);
00342             }
00343 
00344             // Find which subpatch points originate from which patch point
00345             const pointPatch& subPatch = sMesh.boundary()[patchI];
00346             const labelList& subMeshPoints = subPatch.meshPoints();
00347 
00348             // If mapped from outside patch use point 0 for lack of better.
00349             labelList directAddressing(subPatch.size(), 0);
00350 
00351             forAll(subMeshPoints, localI)
00352             {
00353                 // Get mesh point on original mesh.
00354                 label meshPointI = pointMap[subMeshPoints[localI]];
00355 
00356                 Map<label>::const_iterator iter = meshPointMap.find(meshPointI);
00357 
00358                 if (iter != meshPointMap.end())
00359                 {
00360                     directAddressing[localI] = iter();
00361                 }
00362             }
00363 
00364             patchFields.set
00365             (
00366                 patchI,
00367                 pointPatchField<Type>::New
00368                 (
00369                     vf.boundaryField()[patchMap[patchI]],
00370                     subPatch,
00371                     DimensionedField<Type, pointMesh>::null(),
00372                     pointPatchFieldSubset(directAddressing)
00373                 )
00374             );
00375         }
00376     }
00377 
00378     // Create the complete field from the pieces
00379     tmp<GeometricField<Type, pointPatchField, pointMesh> > tresF
00380     (
00381         new GeometricField<Type, pointPatchField, pointMesh>
00382         (
00383             IOobject
00384             (
00385                 "subset"+vf.name(),
00386                 vf.time().timeName(),
00387                 sMesh.thisDb(),
00388                 IOobject::NO_READ,
00389                 IOobject::NO_WRITE
00390             ),
00391             sMesh,
00392             vf.dimensions(),
00393             internalField,
00394             patchFields
00395         )
00396     );
00397 
00398     return tresF;
00399 }
00400 
00401 
00402 template<class Type>
00403 tmp<GeometricField<Type, pointPatchField, pointMesh> > fvMeshSubset::interpolate
00404 (
00405     const GeometricField<Type, pointPatchField, pointMesh>& sf
00406 ) const
00407 {
00408     return interpolate
00409     (
00410         sf,
00411         pointMesh::New(subMesh()),     // subsetted point mesh
00412         patchMap(),
00413         pointMap()
00414     );
00415 }
00416 
00417 
00418 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00419 
00420 } // End namespace Foam
00421 
00422 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd