Initial commit for version 2.0.x patch release
[OpenFOAM-2.0.x.git] / applications / utilities / preProcessing / mapFields / MapLagrangianFields.H
blobae3998e83a6a5c47290db1eac12ce2d60210c02e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2004-2010 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 InNamespace
25     Foam
27 Description
28     Gets the indices of (source)particles that have been appended to the
29     target cloud and maps the lagrangian fields accordingly.
31 \*---------------------------------------------------------------------------*/
33 #ifndef MapLagrangianFields_H
34 #define MapLagrangianFields_H
36 #include "cloud.H"
37 #include "GeometricField.H"
38 #include "meshToMesh.H"
39 #include "IOobjectList.H"
40 #include "CompactIOField.H"
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 namespace Foam
47 //- Gets the indices of (source)particles that have been appended to the
48 //  target cloud and maps the lagrangian fields accordingly.
49 template<class Type>
50 void MapLagrangianFields
52     const string& cloudName,
53     const IOobjectList& objects,
54     const meshToMesh& meshToMeshInterp,
55     const labelList& addParticles
58     const fvMesh& meshTarget = meshToMeshInterp.toMesh();
60     {
61         IOobjectList fields = objects.lookupClass(IOField<Type>::typeName);
63         forAllIter(IOobjectList, fields, fieldIter)
64         {
65             Info<< "    mapping lagrangian field "
66                 << fieldIter()->name() << endl;
68             // Read field (does not need mesh)
69             IOField<Type> fieldSource(*fieldIter());
71             // Map
72             IOField<Type> fieldTarget
73             (
74                 IOobject
75                 (
76                     fieldIter()->name(),
77                     meshTarget.time().timeName(),
78                     cloud::prefix/cloudName,
79                     meshTarget,
80                     IOobject::NO_READ,
81                     IOobject::NO_WRITE,
82                     false
83                 ),
84                 addParticles.size()
85             );
87             forAll(addParticles, i)
88             {
89                 fieldTarget[i] = fieldSource[addParticles[i]];
90             }
92             // Write field
93             fieldTarget.write();
94         }
95     }
97     {
98         IOobjectList fieldFields =
99             objects.lookupClass(IOField<Field<Type> >::typeName);
101         forAllIter(IOobjectList, fieldFields, fieldIter)
102         {
103             Info<< "    mapping lagrangian fieldField "
104                 << fieldIter()->name() << endl;
106             // Read field (does not need mesh)
107             IOField<Field<Type> > fieldSource(*fieldIter());
109             // Map - use CompactIOField to automatically write in
110             // compact form for binary format.
111             CompactIOField<Field<Type>, Type> fieldTarget
112             (
113                 IOobject
114                 (
115                     fieldIter()->name(),
116                     meshTarget.time().timeName(),
117                     cloud::prefix/cloudName,
118                     meshTarget,
119                     IOobject::NO_READ,
120                     IOobject::NO_WRITE,
121                     false
122                 ),
123                 addParticles.size()
124             );
126             forAll(addParticles, i)
127             {
128                 fieldTarget[i] = fieldSource[addParticles[i]];
129             }
131             // Write field
132             fieldTarget.write();
133         }
134     }
136     {
137         IOobjectList fieldFields =
138             objects.lookupClass(CompactIOField<Field<Type>, Type>::typeName);
140         forAllIter(IOobjectList, fieldFields, fieldIter)
141         {
142             Info<< "    mapping lagrangian fieldField "
143                 << fieldIter()->name() << endl;
145             // Read field (does not need mesh)
146             CompactIOField<Field<Type>, Type> fieldSource(*fieldIter());
148             // Map
149             CompactIOField<Field<Type>, Type> fieldTarget
150             (
151                 IOobject
152                 (
153                     fieldIter()->name(),
154                     meshTarget.time().timeName(),
155                     cloud::prefix/cloudName,
156                     meshTarget,
157                     IOobject::NO_READ,
158                     IOobject::NO_WRITE,
159                     false
160                 ),
161                 addParticles.size()
162             );
164             forAll(addParticles, i)
165             {
166                 fieldTarget[i] = fieldSource[addParticles[i]];
167             }
169             // Write field
170             fieldTarget.write();
171         }
172     }
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 } // End namespace Foam
180 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
182 #endif
184 // ************************************************************************* //