BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / applications / utilities / parallelProcessing / reconstructParMesh / tetPointFieldReconstructorReconstructFields.C
blobb4b05ec1a1bb4a616f2ef1a68b7a26c5c0f48921
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 "tetPointFieldReconstructor.H"
28 #include "PtrList.H"
29 #include "tetPolyPatchFields.H"
30 #include "tetFemMatrices.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 namespace Foam
37 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
39 template<class Type>
40 tmp<GeometricField<Type, tetPolyPatchField, tetPointMesh> >
41 tetPointFieldReconstructor::reconstructTetPointField
43     const IOobject& fieldIoObject
46     // Read the field for all the processors
47     PtrList<GeometricField<Type, tetPolyPatchField, tetPointMesh> > procFields
48     (
49         procMeshes_.size()
50     );
52     forAll (procMeshes_, procI)
53     {
54         procFields.set
55         (
56             procI,
57             new GeometricField<Type, tetPolyPatchField, tetPointMesh>
58             (
59                 IOobject
60                 (
61                     fieldIoObject.name(),
62                     procMeshes_[procI]().time().timeName(),
63                     procMeshes_[procI](),
64                     IOobject::MUST_READ,
65                     IOobject::NO_WRITE
66                 ),
67                 procMeshes_[procI]
68             )
69         );
70     }
73     // Create the internalField
74     Field<Type> internalField(mesh_.nPoints());
76     // Create the patch fields
77     PtrList<tetPolyPatchField<Type> > patchFields(mesh_.boundary().size());
80     forAll (procMeshes_, procI)
81     {
82         const GeometricField<Type, tetPolyPatchField, tetPointMesh>&
83             procField = procFields[procI];
85         // Get processor-to-global addressing for use in rmap
86         labelList procToGlobalAddr = procAddressing(procI);
88         // Set the cell values in the reconstructed field
89         internalField.rmap
90         (
91             procField.internalField(),
92             procToGlobalAddr
93         );
95         // Set the boundary patch values in the reconstructed field
96         forAll(boundaryProcAddressing_[procI], patchI)
97         {
98             // Get patch index of the original patch
99             const label curBPatch = boundaryProcAddressing_[procI][patchI];
101             // check if the boundary patch is not a processor patch
102             if (curBPatch >= 0)
103             {
104                 if (!patchFields(curBPatch))
105                 {
106                     patchFields.set
107                     (
108                         curBPatch,
109                         tetPolyPatchField<Type>::New
110                         (
111                             procField.boundaryField()[patchI],
112                             mesh_.boundary()[curBPatch],
113                             DimensionedField<Type, tetPointMesh>::null(),
114                             tetPolyPatchFieldReconstructor
115                             (
116                                 mesh_.boundary()[curBPatch].size(),
117                                 procField.boundaryField()[patchI].size()
118                             )
119                         )
120                     );
121                 }
123                 // If the field stores values, do the rmap
124                 if (patchFields[curBPatch].storesFieldData())
125                 {
126                     patchFields[curBPatch].rmap
127                     (
128                         procField.boundaryField()[patchI],
129                         procPatchAddressing
130                         (
131                             procToGlobalAddr,
132                             procI,
133                             patchI
134                         )
135                     );
136                 }
137             }
138         }
139     }
141     // Now construct and write the field
142     // setting the internalField and patchFields
143     return tmp<GeometricField<Type, tetPolyPatchField, tetPointMesh> >
144     (
145         new GeometricField<Type, tetPolyPatchField, tetPointMesh>
146         (
147             IOobject
148             (
149                 fieldIoObject.name(),
150                 mesh_().time().timeName(),
151                 mesh_(),
152                 IOobject::NO_READ,
153                 IOobject::NO_WRITE
154             ),
155             mesh_,
156             procFields[0].dimensions(),
157             internalField,
158             patchFields
159         )
160     );
164 template<class Type>
165 tmp<GeometricField<Type, elementPatchField, elementMesh> >
166 tetPointFieldReconstructor::reconstructElementField
168     const IOobject& fieldIoObject
171     // Read the field for all the processors
172     PtrList<GeometricField<Type, elementPatchField, elementMesh> > procFields
173     (
174         procMeshes_.size()
175     );
177     forAll (procMeshes_, procI)
178     {
179         procFields.set
180         (
181             procI,
182             new GeometricField<Type, elementPatchField, elementMesh>
183             (
184                 IOobject
185                 (
186                     fieldIoObject.name(),
187                     procMeshes_[procI]().time().timeName(),
188                     procMeshes_[procI](),
189                     IOobject::MUST_READ,
190                     IOobject::NO_WRITE
191                 ),
192                 procMeshes_[procI]
193             )
194         );
195     }
198     // Create the internalField
199     Field<Type> internalField(mesh_.nCells());
201     // Create the patch fields
202     PtrList<elementPatchField<Type> > patchFields(mesh_.boundary().size());
205     forAll (procMeshes_, procI)
206     {
207         const GeometricField<Type, elementPatchField, elementMesh>&
208             procField = procFields[procI];
210         // Set the cell values in the reconstructed field
211         internalField.rmap
212         (
213             procField.internalField(),
214             cellProcAddressing_[procI]
215         );
217         // Set the boundary patch values in the reconstructed field
218         forAll(boundaryProcAddressing_[procI], patchI)
219         {
220             // Get patch index of the original patch
221             const label curBPatch = boundaryProcAddressing_[procI][patchI];
223             // Get addressing slice for this patch
224             const labelList::subList cp =
225                 procMeshes_[procI]().boundaryMesh()[patchI].patchSlice
226                 (
227                     faceProcAddressing_[procI]
228                 );
230             // check if the boundary patch is not a processor patch
231             if (curBPatch >= 0)
232             {
233                 if (!patchFields(curBPatch))
234                 {
235                     patchFields.set
236                     (
237                         curBPatch,
238                         elementPatchField<Type>::New
239                         (
240                             procField.boundaryField()[patchI],
241                             mesh_.boundary()[curBPatch],
242                             DimensionedField<Type, elementMesh>::null(),
243                             tetPolyPatchFieldReconstructor
244                             (
245                                 mesh_.boundary()[curBPatch].size(),
246                                 procField.boundaryField()[patchI].size()
247                             )
248                         )
249                     );
250                 }
252                 // If the field stores values, do the rmap
253                 if (patchFields[curBPatch].storesFieldData())
254                 {
255                     const label curPatchStart =
256                         mesh_().boundaryMesh()[curBPatch].start();
258                     labelList reverseAddressing(cp.size());
260                     forAll(cp, faceI)
261                     {
262                         // Subtract one to take into account offsets for
263                         // face direction.
264                         reverseAddressing[faceI] = cp[faceI] - 1
265                             - curPatchStart;
266                     }
268                     patchFields[curBPatch].rmap
269                     (
270                         procField.boundaryField()[patchI],
271                         reverseAddressing
272                     );
273                 }
274             }
275         }
276     }
278     // Now construct and write the field
279     // setting the internalField and patchFields
280     return tmp<GeometricField<Type, elementPatchField, elementMesh> >
281     (
282         new GeometricField<Type, elementPatchField, elementMesh>
283         (
284             IOobject
285             (
286                 fieldIoObject.name(),
287                 mesh_().time().timeName(),
288                 mesh_(),
289                 IOobject::NO_READ,
290                 IOobject::NO_WRITE
291             ),
292             mesh_,
293             procFields[0].dimensions(),
294             internalField,
295             patchFields
296         )
297     );
301 template<class Type>
302 void tetPointFieldReconstructor::reconstructTetPointFields
304     const IOobjectList& objects
307     word fieldClassName
308     (
309         GeometricField<Type, tetPolyPatchField, tetPointMesh>::typeName
310     );
312     IOobjectList fields = objects.lookupClass(fieldClassName);
314     if (fields.size())
315     {
316         Info<< "    Reconstructing " << fieldClassName << "s\n" << endl;
318         for
319         (
320             IOobjectList::iterator fieldIter = fields.begin();
321             fieldIter != fields.end();
322             ++fieldIter
323         )
324         {
325             Info<< "        " << fieldIter()->name() << endl;
327             reconstructTetPointField<Type>(*fieldIter())().write();
328         }
330         Info<< endl;
331     }
335 template<class Type>
336 void tetPointFieldReconstructor::reconstructElementFields
338     const IOobjectList& objects
341     word fieldClassName
342     (
343         GeometricField<Type, elementPatchField, elementMesh>::typeName
344     );
346     IOobjectList fields = objects.lookupClass(fieldClassName);
348     if (fields.size())
349     {
350         Info<< "    Reconstructing " << fieldClassName << "s\n" << endl;
352         for
353         (
354             IOobjectList::iterator fieldIter = fields.begin();
355             fieldIter != fields.end();
356             ++fieldIter
357         )
358         {
359             Info<< "        " << fieldIter()->name() << endl;
361             reconstructElementField<Type>(*fieldIter())().write();
362         }
364         Info<< endl;
365     }
369 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
371 } // End namespace Foam
373 // ************************************************************************* //