BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / applications / utilities / parallelProcessing / reconstructParMesh / pointFieldReconstructorReconstructFields.C
blob5b97ab1d85a062bb53ae5c0bc1552fbc0a434988
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 "pointFieldReconstructor.H"
29 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
31 template<class Type>
32 Foam::tmp<Foam::GeometricField<Type, Foam::pointPatchField, Foam::pointMesh> >
33 Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
35     // Read the field for all the processors
36     PtrList<GeometricField<Type, pointPatchField, pointMesh> > procFields
37     (
38         procMeshes_.size()
39     );
41     forAll (procMeshes_, proci)
42     {
43         procFields.set
44         (
45             proci,
46             new GeometricField<Type, pointPatchField, pointMesh>
47             (
48                 IOobject
49                 (
50                     fieldIoObject.name(),
51                     procMeshes_[proci]().time().timeName(),
52                     procMeshes_[proci](),
53                     IOobject::MUST_READ,
54                     IOobject::NO_WRITE
55                 ),
56                 procMeshes_[proci]
57             )
58         );
59     }
62     // Create the internalField
63     Field<Type> internalField(mesh_.size());
65     // Create the patch fields
66     PtrList<pointPatchField<Type> > patchFields(mesh_.boundary().size());
69     forAll (procMeshes_, proci)
70     {
71         const GeometricField<Type, pointPatchField, pointMesh>&
72             procField = procFields[proci];
74         // Get processor-to-global addressing for use in rmap
75         const labelList& procToGlobalAddr = pointProcAddressing_[proci];
77         // Set the cell values in the reconstructed field
78         internalField.rmap
79         (
80             procField.internalField(),
81             procToGlobalAddr
82         );
84         // Set the boundary patch values in the reconstructed field
85         forAll(boundaryProcAddressing_[proci], patchi)
86         {
87             // Get patch index of the original patch
88             const label curBPatch = boundaryProcAddressing_[proci][patchi];
90             // check if the boundary patch is not a processor patch
91             if (curBPatch >= 0)
92             {
93                 if (!patchFields(curBPatch))
94                 {
95                     patchFields.set
96                     (
97                         curBPatch,
98                         pointPatchField<Type>::New
99                         (
100                             procField.boundaryField()[patchi],
101                             mesh_.boundary()[curBPatch],
102                             DimensionedField<Type, pointMesh>::null(),
103                             pointPatchFieldReconstructor
104                             (
105                                 mesh_.boundary()[curBPatch].size(),
106                                 procField.boundaryField()[patchi].size()
107                             )
108                         )
109                     );
110                 }
112                 patchFields[curBPatch].rmap
113                 (
114                     procField.boundaryField()[patchi],
115                     patchPointAddressing_[proci][patchi]
116                 );
117             }
118         }
119     }
121     // Construct and write the field
122     // setting the internalField and patchFields
123     return tmp<GeometricField<Type, pointPatchField, pointMesh> >
124     (
125         new GeometricField<Type, pointPatchField, pointMesh>
126         (
127             IOobject
128             (
129                 fieldIoObject.name(),
130                 mesh_().time().timeName(),
131                 mesh_(),
132                 IOobject::NO_READ,
133                 IOobject::NO_WRITE
134             ),
135             mesh_,
136             procFields[0].dimensions(),
137             internalField,
138             patchFields
139         )
140     );
144 // Reconstruct and write all point fields
145 template<class Type>
146 void Foam::pointFieldReconstructor::reconstructFields
148     const IOobjectList& objects
151     word fieldClassName
152     (
153         GeometricField<Type, pointPatchField, pointMesh>::typeName
154     );
156     IOobjectList fields = objects.lookupClass(fieldClassName);
158     if (fields.size())
159     {
160         Info<< "    Reconstructing " << fieldClassName << "s\n" << endl;
162         for
163         (
164             IOobjectList::iterator fieldIter = fields.begin();
165             fieldIter != fields.end();
166             ++fieldIter
167         )
168         {
169             Info<< "        " << fieldIter()->name() << endl;
171             reconstructField<Type>(*fieldIter())().write();
172         }
174         Info<< endl;
175     }
179 // ************************************************************************* //