OpenFOAM logo
Open Source CFD Toolkit

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-2005 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     MapGeometricFields
00027 
00028 Description
00029     Generic Geometric 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 template
00062 <
00063     class Type,
00064     template<class> class PatchField,
00065     class MeshMapper,
00066     class GeoMesh
00067 >
00068 void MapGeometricFields
00069 (
00070     const MeshMapper& mapper
00071 )
00072 {
00073     HashTable<const GeometricField<Type, PatchField, GeoMesh>*> fields
00074     (
00075         mapper.mesh().objectRegistry::lookupClass
00076             <GeometricField<Type, PatchField, GeoMesh> >()
00077     );
00078 
00079     // It is necessary to enforce that all old-time fields are stored
00080     // before the mapping is performed.  Otherwise, if the
00081     // old-time-level field is mapped before the field itself, sizes
00082     // will not match.  
00083 
00084     for
00085     (
00086         typename HashTable<const GeometricField<Type, PatchField, GeoMesh>*>::
00087             iterator fieldIter = fields.begin();
00088         fieldIter != fields.end();
00089         ++fieldIter
00090     )
00091     {
00092         const_cast<GeometricField<Type, PatchField, GeoMesh>*>(fieldIter())
00093             ->storeOldTimes();
00094     }
00095 
00096     for
00097     (
00098         typename HashTable<const GeometricField<Type, PatchField, GeoMesh>*>::
00099             iterator fieldIter = fields.begin();
00100         fieldIter != fields.end();
00101         ++fieldIter
00102     )
00103     {
00104         GeometricField<Type, PatchField, GeoMesh>& field = 
00105             const_cast<GeometricField<Type, PatchField, GeoMesh>&>
00106             (*fieldIter());
00107 
00108         if (polyMesh::debug)
00109         {
00110             Info<< "Mapping field " << field.name() << endl;
00111         }
00112 
00113         // Map the internal field
00114         MapInternalField<Type, MeshMapper, GeoMesh>()
00115         (
00116             field.internalField(),
00117             mapper
00118         );
00119 
00120         // Map the patch fields
00121         forAll(field.boundaryField(), patchi)
00122         {
00123             // Cannot check sizes for patch fields because of
00124             // empty fields in FV and because point fields get their size
00125             // from the patch which has already been resized
00126             // 
00127 
00128             field.boundaryField()[patchi].autoMap
00129             (
00130                 mapper.boundaryMap()[patchi]
00131             );
00132         }
00133     }
00134 }
00135 
00136 
00137 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00138 
00139 } // End namespace Foam
00140 
00141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00142 
00143 #endif
00144 
00145 // ************************************************************************* //
For further information go to www.openfoam.org