BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / applications / utilities / parallelProcessing / reconstructParMesh / reconstructLagrangianFields.C
blobe98851360c78cee2560ad6b1add4dfc5c3ab142b
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 #include "IOField.H"
28 #include "Time.H"
30 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
32 template<class Type>
33 Foam::tmp<Foam::IOField<Type> > Foam::reconstructLagrangianField
35     const word& cloudName,
36     const polyMesh& mesh,
37     const PtrList<fvMesh>& meshes,
38     const word& fieldName
41     // Construct empty field on mesh
42     tmp<IOField<Type> > tfield
43     (
44         new IOField<Type>
45         (
46             IOobject
47             (
48                 fieldName,
49                 mesh.time().timeName(),
50                 cloud::prefix/cloudName,
51                 mesh,
52                 IOobject::NO_READ,
53                 IOobject::NO_WRITE
54             ),
55             Field<Type>(0)
56         )
57     );
58     Field<Type>& field = tfield();
60     forAll(meshes, i)
61     {
62         // Check object on local mesh
63         IOobject localIOobject
64         (
65             fieldName,
66             meshes[i].time().timeName(),
67             cloud::prefix/cloudName,
68             meshes[i],
69             IOobject::MUST_READ,
70             IOobject::NO_WRITE
71         );
73         if (localIOobject.headerOk())
74         {
75             IOField<Type> fieldi(localIOobject);
77             label offset = field.size();
78             field.setSize(offset + fieldi.size());
80             forAll(fieldi, j)
81             {
82                 field[offset + j] = fieldi[j];
83             }
84         }
85     }
87     return tfield;
91 template<class Type>
92 void Foam::reconstructLagrangianFields
94     const word& cloudName,
95     const polyMesh& mesh,
96     const PtrList<fvMesh>& meshes,
97     const IOobjectList& objects
100     word fieldClassName(IOField<Type>::typeName);
102     IOobjectList fields = objects.lookupClass(fieldClassName);
104     if (fields.size())
105     {
106         Info<< "    Reconstructing lagrangian "
107             << fieldClassName << "s\n" << endl;
109         forAllIter(IOobjectList, fields, fieldIter)
110         {
111             Info<< "        " << fieldIter()->name() << endl;
112             reconstructLagrangianField<Type>
113             (
114                 cloudName,
115                 mesh,
116                 meshes,
117                 fieldIter()->name()
118             )().write();
119         }
121         Info<< endl;
122     }
126 // ************************************************************************* //