initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / OpenFOAM / fields / GeometricFields / GeometricField / MapGeometricFields.H
blob5f5896893bb22544fd7f1ce03381d0c3bfdb0626
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software; you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::MapInternalField
28 Description
29     Generic internal field mapper.  For "real" mapping, add template
30     specialisations for mapping of internal fields depending on mesh
31     type.
33 \*---------------------------------------------------------------------------*/
35 #ifndef MapGeometricFields_H
36 #define MapGeometricFields_H
38 #include "polyMesh.H"
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 namespace Foam
45 template<class Type, class MeshMapper, class GeoMesh>
46 class MapInternalField
48 public:
49     
50     MapInternalField()
51     {}
53     void operator()
54     (
55         Field<Type>& field,
56         const MeshMapper& mapper
57     ) const;
61 //- Generic Geometric field mapper.
62 //  For "real" mapping, add template specialisations
63 //  for mapping of internal fields depending on mesh type.
64 template
66     class Type,
67     template<class> class PatchField,
68     class MeshMapper,
69     class GeoMesh
71 void MapGeometricFields
73     const MeshMapper& mapper
76     HashTable<const GeometricField<Type, PatchField, GeoMesh>*> fields
77     (
78         mapper.thisDb().objectRegistry::lookupClass
79             <GeometricField<Type, PatchField, GeoMesh> >()
80     );
82     // It is necessary to enforce that all old-time fields are stored
83     // before the mapping is performed.  Otherwise, if the
84     // old-time-level field is mapped before the field itself, sizes
85     // will not match.  
87     for
88     (
89         typename HashTable<const GeometricField<Type, PatchField, GeoMesh>*>::
90             iterator fieldIter = fields.begin();
91         fieldIter != fields.end();
92         ++fieldIter
93     )
94     {
95         GeometricField<Type, PatchField, GeoMesh>& field = 
96             const_cast<GeometricField<Type, PatchField, GeoMesh>&>
97             (*fieldIter());
99         //Note: check can be removed once pointFields are actually stored on
100         //      the pointMesh instead of now on the polyMesh!
101         if (&field.mesh() == &mapper.mesh())
102         {
103             field.storeOldTimes();
104         }
105     }
107     for
108     (
109         typename HashTable<const GeometricField<Type, PatchField, GeoMesh>*>::
110             iterator fieldIter = fields.begin();
111         fieldIter != fields.end();
112         ++fieldIter
113     )
114     {
115         GeometricField<Type, PatchField, GeoMesh>& field = 
116             const_cast<GeometricField<Type, PatchField, GeoMesh>&>
117             (*fieldIter());
119         if (&field.mesh() == &mapper.mesh())
120         {
121             if (polyMesh::debug)
122             {
123                 Info<< "Mapping " << field.typeName << ' ' << field.name()
124                     << endl;
125             }
127             // Map the internal field
128             MapInternalField<Type, MeshMapper, GeoMesh>()
129             (
130                 field.internalField(),
131                 mapper
132             );
134             // Map the patch fields
135             forAll(field.boundaryField(), patchi)
136             {
137                 // Cannot check sizes for patch fields because of
138                 // empty fields in FV and because point fields get their size
139                 // from the patch which has already been resized
140                 // 
142                 field.boundaryField()[patchi].autoMap
143                 (
144                     mapper.boundaryMap()[patchi]
145                 );
146             }
148             field.instance() = field.time().timeName();
149         }
150         else if (polyMesh::debug)
151         {
152             Info<< "Not mapping " << field.typeName << ' ' << field.name()
153                 << " since originating mesh differs from that of mapper."
154                 << endl;
155         }
156     }
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 } // End namespace Foam
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
166 #endif
168 // ************************************************************************* //