Forward compatibility: flex
[foam-extend-3.2.git] / src / dynamicMesh / dynamicTopoFvMesh / fieldMapping / topoMapperTemplates.C
blobb3604ccf0a584972b5f109935373695ec09e6225
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 "fvc.H"
27 #include "leastSquaresGrad.H"
29 namespace Foam
32 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
34 // Store gradients of fields on the mesh prior to topology changes
35 template <class Type, class gradType>
36 void topoMapper::storeGradients
38     GradientTable& gradTable,
39     PtrList<gradType>& gradList
40 ) const
42     // Define a few typedefs for convenience
43     typedef GeometricField<Type, fvPatchField, volMesh> volType;
44     typedef const GeometricField<Type, fvPatchField, volMesh> constVolType;
46     typedef HashTable<constVolType*> volTypeTable;
48     // Fetch all fields from registry
49     volTypeTable fields(mesh_.objectRegistry::lookupClass<volType>());
51     // Track field count
52     label nFields = 0;
54     // Store old-times before gradient computation
55     for
56     (
57         typename volTypeTable::iterator fIter = fields.begin();
58         fIter != fields.end();
59         ++fIter
60     )
61     {
62         fIter()->storeOldTimes();
63         nFields++;
64     }
66     // Size up the list
67     gradList.setSize(nFields);
69     label fieldIndex = 0;
71     for
72     (
73         typename volTypeTable::const_iterator fIter = fields.begin();
74         fIter != fields.end();
75         ++fIter
76     )
77     {
78         const volType& field = *fIter();
80         // Compute the gradient.
82         // If the fvSolution dictionary contains an entry,
83         // use that, otherwise, default to leastSquares
84         word gradName("grad(" + field.name() + ')');
86         // Register field under a name that's unique
87         word registerName("remapGradient(" + field.name() + ')');
89         // Make a new entry
90         if (mesh_.schemesDict().subDict("gradSchemes").found(gradName))
91         {
92             gradList.set
93             (
94                 fieldIndex,
95                 new gradType
96                 (
97                     IOobject
98                     (
99                         registerName,
100                         mesh_.time().timeName(),
101                         mesh_,
102                         IOobject::NO_READ,
103                         IOobject::NO_WRITE,
104                         true
105                     ),
106                     fvc::grad(field, gradName)()
107                 )
108             );
109         }
110         else
111         {
112             gradList.set
113             (
114                 fieldIndex,
115                 new gradType
116                 (
117                     IOobject
118                     (
119                         registerName,
120                         mesh_.time().timeName(),
121                         mesh_,
122                         IOobject::NO_READ,
123                         IOobject::NO_WRITE,
124                         true
125                     ),
126                     fv::leastSquaresGrad<Type>(mesh_).grad(field)()
127                 )
128             );
129         }
131         // Add a map entry
132         gradTable.insert
133         (
134             field.name(),
135             GradientMap(registerName, fieldIndex++)
136         );
137     }
141 } // End namespace Foam
143 // ************************************************************************* //