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

MapGeometricFields.H

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 Class
00026     Foam::MapInternalField
00027 
00028 Description
00029     Generic internal field mapper.  For "real" mapping, add template
00030     specialisations for mapping of internal fields depending on mesh
00031     type.
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 #ifndef MapGeometricFields_H
00036 #define MapGeometricFields_H
00037 
00038 #include "polyMesh.H"
00039 
00040 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00041 
00042 namespace Foam
00043 {
00044 
00045 template<class Type, class MeshMapper, class GeoMesh>
00046 class MapInternalField
00047 {
00048 public:
00049     
00050     MapInternalField()
00051     {}
00052 
00053     void operator()
00054     (
00055         Field<Type>& field,
00056         const MeshMapper& mapper
00057     ) const;
00058 };
00059 
00060 
00061 //- Generic Geometric field mapper.
00062 //  For "real" mapping, add template specialisations
00063 //  for mapping of internal fields depending on mesh type.
00064 template
00065 <
00066     class Type,
00067     template<class> class PatchField,
00068     class MeshMapper,
00069     class GeoMesh
00070 >
00071 void MapGeometricFields
00072 (
00073     const MeshMapper& mapper
00074 )
00075 {
00076     HashTable<const GeometricField<Type, PatchField, GeoMesh>*> fields
00077     (
00078         mapper.thisDb().objectRegistry::lookupClass
00079             <GeometricField<Type, PatchField, GeoMesh> >()
00080     );
00081 
00082     // It is necessary to enforce that all old-time fields are stored
00083     // before the mapping is performed.  Otherwise, if the
00084     // old-time-level field is mapped before the field itself, sizes
00085     // will not match.  
00086 
00087     for
00088     (
00089         typename HashTable<const GeometricField<Type, PatchField, GeoMesh>*>::
00090             iterator fieldIter = fields.begin();
00091         fieldIter != fields.end();
00092         ++fieldIter
00093     )
00094     {
00095         GeometricField<Type, PatchField, GeoMesh>& field = 
00096             const_cast<GeometricField<Type, PatchField, GeoMesh>&>
00097             (*fieldIter());
00098 
00099         //Note: check can be removed once pointFields are actually stored on
00100         //      the pointMesh instead of now on the polyMesh!
00101         if (&field.mesh() == &mapper.mesh())
00102         {
00103             field.storeOldTimes();
00104         }
00105     }
00106 
00107     for
00108     (
00109         typename HashTable<const GeometricField<Type, PatchField, GeoMesh>*>::
00110             iterator fieldIter = fields.begin();
00111         fieldIter != fields.end();
00112         ++fieldIter
00113     )
00114     {
00115         GeometricField<Type, PatchField, GeoMesh>& field = 
00116             const_cast<GeometricField<Type, PatchField, GeoMesh>&>
00117             (*fieldIter());
00118 
00119         if (&field.mesh() == &mapper.mesh())
00120         {
00121             if (polyMesh::debug)
00122             {
00123                 Info<< "Mapping " << field.typeName << ' ' << field.name()
00124                     << endl;
00125             }
00126 
00127             // Map the internal field
00128             MapInternalField<Type, MeshMapper, GeoMesh>()
00129             (
00130                 field.internalField(),
00131                 mapper
00132             );
00133 
00134             // Map the patch fields
00135             forAll(field.boundaryField(), patchi)
00136             {
00137                 // Cannot check sizes for patch fields because of
00138                 // empty fields in FV and because point fields get their size
00139                 // from the patch which has already been resized
00140                 // 
00141 
00142                 field.boundaryField()[patchi].autoMap
00143                 (
00144                     mapper.boundaryMap()[patchi]
00145                 );
00146             }
00147 
00148             field.instance() = field.time().timeName();
00149         }
00150         else if (polyMesh::debug)
00151         {
00152             Info<< "Not mapping " << field.typeName << ' ' << field.name()
00153                 << " since originating mesh differs from that of mapper."
00154                 << endl;
00155         }
00156     }
00157 }
00158 
00159 
00160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00161 
00162 } // End namespace Foam
00163 
00164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00165 
00166 #endif
00167 
00168 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd