initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / preProcessing / mapFields / MapConsistentVolFields.H
blob67cfef4a249e545b80cdb4e3d8c55c85e55bc67c
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 \*---------------------------------------------------------------------------*/
27 #ifndef MapConsistentVolFields_H
28 #define MapConsistentVolFields_H
30 #include "GeometricField.H"
31 #include "meshToMesh.H"
32 #include "IOobjectList.H"
34 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 namespace Foam
39 template<class Type>
40 void MapConsistentVolFields
42     const IOobjectList& objects,
43     const meshToMesh& meshToMeshInterp
46     const fvMesh& meshSource = meshToMeshInterp.fromMesh();
47     const fvMesh& meshTarget = meshToMeshInterp.toMesh();
49     word fieldClassName
50     (
51         GeometricField<Type, fvPatchField, volMesh>::typeName
52     );
54     IOobjectList fields = objects.lookupClass(fieldClassName);
56     for
57     (
58         IOobjectList::iterator fieldIter = fields.begin();
59         fieldIter != fields.end();
60         ++fieldIter
61     )
62     {
63         Info<< "    interpolating " << fieldIter()->name()
64             << endl;
66         // Read field
67         GeometricField<Type, fvPatchField, volMesh> fieldSource
68         (
69             *fieldIter(),
70             meshSource
71         );
73         IOobject fieldTargetIOobject
74         (
75             fieldIter()->name(),
76             meshTarget.time().timeName(),
77             meshTarget,
78             IOobject::MUST_READ,
79             IOobject::AUTO_WRITE
80         );
82         if (fieldTargetIOobject.headerOk())
83         {
84             // Read fieldTarget
85             GeometricField<Type, fvPatchField, volMesh> fieldTarget
86             (
87                 fieldTargetIOobject,
88                 meshTarget
89             );
91             // Interpolate field
92             meshToMeshInterp.interpolate
93             (
94                 fieldTarget,
95                 fieldSource,
96                 meshToMesh::INTERPOLATE
97             );
99             // Write field
100             fieldTarget.write();
101         }
102         else
103         {
104             fieldTargetIOobject.readOpt() = IOobject::NO_READ;
106             // Interpolate field
107             GeometricField<Type, fvPatchField, volMesh> fieldTarget
108             (
109                 fieldTargetIOobject,
110                 meshToMeshInterp.interpolate
111                 (
112                     fieldSource,
113                     meshToMesh::INTERPOLATE
114                 )
115             );
117             // Write field
118             fieldTarget.write();
119         }
120     }
124 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 } // End namespace Foam
128 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130 #endif
132 // ************************************************************************* //