Forward compatibility: flex
[foam-extend-3.2.git] / src / dynamicMesh / dynamicTopoFvMesh / fieldMapping / conservativeMapFields.H
blob2a47bd89abe4f2e0d4fdffe53d78daa18d9a7b78
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "topoMapper.H"
27 #include "topoCellMapper.H"
28 #include "topoSurfaceMapper.H"
29 #include "topoBoundaryMeshMapper.H"
31 namespace Foam
34 // Conservatively map all volFields in the registry
35 template <class Type>
36 void conservativeMapVolFields(const topoMapper& mapper)
38     // Define a few typedefs for convenience
39     typedef typename outerProduct<vector, Type>::type gCmptType;
40     typedef GeometricField<Type, fvPatchField, volMesh> volType;
41     typedef GeometricField<gCmptType, fvPatchField, volMesh> gradVolType;
43     HashTable<const volType*> fields(mapper.mesh().lookupClass<volType>());
45     // Store old-times before mapping
46     forAllIter(typename HashTable<const volType*>, fields, fIter)
47     {
48         fIter()->storeOldTimes();
49     }
51     // Fetch internal/boundary mappers
52     const topoCellMapper& fMap = mapper.volMap();
53     const topoBoundaryMeshMapper& bMap = mapper.boundaryMap();
55     // Now map all fields
56     forAllIter(typename HashTable<const volType*>, fields, fIter)
57     {
58         volType& field = const_cast<volType&>(*fIter());
60         if (fvMesh::debug)
61         {
62             Info<< "Conservatively mapping "
63                 << field.typeName
64                 << ' ' << field.name()
65                 << endl;
66         }
68         // Map the internal field
69         fMap.mapInternalField
70         (
71             field.name(),
72             mapper.gradient<gradVolType>(field.name()).internalField(),
73             field.internalField()
74         );
76         // Map patch fields
77         forAll(bMap, patchI)
78         {
79             bMap[patchI].mapFvPatchField
80             (
81                 field.name(),
82                 field.boundaryField()[patchI]
83             );
84         }
86         // Set the field instance
87         field.instance() = field.mesh().thisDb().time().timeName();
88     }
92 // Conservatively map all surfaceFields in the registry
93 template <class Type>
94 void conservativeMapSurfaceFields(const topoMapper& mapper)
96     // Define a few typedefs for convenience
97     typedef GeometricField<Type, fvsPatchField, surfaceMesh> surfType;
99     HashTable<const surfType*> fields(mapper.mesh().lookupClass<surfType>());
101     // Store old-times before mapping
102     forAllIter(typename HashTable<const surfType*>, fields, fIter)
103     {
104         fIter()->storeOldTimes();
105     }
107     // Fetch internal/boundary mappers
108     const topoSurfaceMapper& fMap = mapper.surfaceMap();
109     const topoBoundaryMeshMapper& bMap = mapper.boundaryMap();
111     // Now map all fields
112     forAllIter(typename HashTable<const surfType*>, fields, fIter)
113     {
114         surfType& field = const_cast<surfType&>(*fIter());
116         if (fvMesh::debug)
117         {
118             Info<< "Conservatively mapping "
119                 << field.typeName
120                 << ' ' << field.name()
121                 << endl;
122         }
124         // Map the internal field
125         fMap.mapInternalField
126         (
127             field.name(),
128             field.internalField()
129         );
131         // Map patch fields
132         forAll(bMap, patchI)
133         {
134             bMap[patchI].mapFvsPatchField
135             (
136                 field.name(),
137                 field.boundaryField()[patchI]
138             );
139         }
141         // Set the field instance
142         field.instance() = field.mesh().thisDb().time().timeName();
143     }
147 } // End namespace Foam
149 // ************************************************************************* //