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

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