Forward compatibility: flex
[foam-extend-3.2.git] / applications / utilities / parallelProcessing / reconstructParMesh / tetPointFieldReconstructorReconstructFields.C
blob93a5fb119c2e44fcad55b63e46298c117823988c
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "tetPointFieldReconstructor.H"
27 #include "PtrList.H"
28 #include "tetPolyPatchFields.H"
29 #include "tetFemMatrices.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 namespace Foam
36 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
38 template<class Type>
39 tmp<GeometricField<Type, tetPolyPatchField, tetPointMesh> >
40 tetPointFieldReconstructor::reconstructTetPointField
42     const IOobject& fieldIoObject
45     // Read the field for all the processors
46     PtrList<GeometricField<Type, tetPolyPatchField, tetPointMesh> > procFields
47     (
48         procMeshes_.size()
49     );
51     forAll (procMeshes_, procI)
52     {
53         procFields.set
54         (
55             procI,
56             new GeometricField<Type, tetPolyPatchField, tetPointMesh>
57             (
58                 IOobject
59                 (
60                     fieldIoObject.name(),
61                     procMeshes_[procI]().time().timeName(),
62                     procMeshes_[procI](),
63                     IOobject::MUST_READ,
64                     IOobject::NO_WRITE
65                 ),
66                 procMeshes_[procI]
67             )
68         );
69     }
72     // Create the internalField
73     Field<Type> internalField(mesh_.nPoints());
75     // Create the patch fields
76     PtrList<tetPolyPatchField<Type> > patchFields(mesh_.boundary().size());
79     forAll (procMeshes_, procI)
80     {
81         const GeometricField<Type, tetPolyPatchField, tetPointMesh>&
82             procField = procFields[procI];
84         // Get processor-to-global addressing for use in rmap
85         labelList procToGlobalAddr = procAddressing(procI);
87         // Set the cell values in the reconstructed field
88         internalField.rmap
89         (
90             procField.internalField(),
91             procToGlobalAddr
92         );
94         // Set the boundary patch values in the reconstructed field
95         forAll(boundaryProcAddressing_[procI], patchI)
96         {
97             // Get patch index of the original patch
98             const label curBPatch = boundaryProcAddressing_[procI][patchI];
100             // check if the boundary patch is not a processor patch
101             if (curBPatch >= 0)
102             {
103                 if (!patchFields(curBPatch))
104                 {
105                     patchFields.set
106                     (
107                         curBPatch,
108                         tetPolyPatchField<Type>::New
109                         (
110                             procField.boundaryField()[patchI],
111                             mesh_.boundary()[curBPatch],
112                             DimensionedField<Type, tetPointMesh>::null(),
113                             tetPolyPatchFieldReconstructor
114                             (
115                                 mesh_.boundary()[curBPatch].size(),
116                                 procField.boundaryField()[patchI].size()
117                             )
118                         )
119                     );
120                 }
122                 // If the field stores values, do the rmap
123                 if (patchFields[curBPatch].storesFieldData())
124                 {
125                     patchFields[curBPatch].rmap
126                     (
127                         procField.boundaryField()[patchI],
128                         procPatchAddressing
129                         (
130                             procToGlobalAddr,
131                             procI,
132                             patchI
133                         )
134                     );
135                 }
136             }
137         }
138     }
140     // Now construct and write the field
141     // setting the internalField and patchFields
142     return tmp<GeometricField<Type, tetPolyPatchField, tetPointMesh> >
143     (
144         new GeometricField<Type, tetPolyPatchField, tetPointMesh>
145         (
146             IOobject
147             (
148                 fieldIoObject.name(),
149                 mesh_().time().timeName(),
150                 mesh_(),
151                 IOobject::NO_READ,
152                 IOobject::NO_WRITE
153             ),
154             mesh_,
155             procFields[0].dimensions(),
156             internalField,
157             patchFields
158         )
159     );
163 template<class Type>
164 tmp<GeometricField<Type, elementPatchField, elementMesh> >
165 tetPointFieldReconstructor::reconstructElementField
167     const IOobject& fieldIoObject
170     // Read the field for all the processors
171     PtrList<GeometricField<Type, elementPatchField, elementMesh> > procFields
172     (
173         procMeshes_.size()
174     );
176     forAll (procMeshes_, procI)
177     {
178         procFields.set
179         (
180             procI,
181             new GeometricField<Type, elementPatchField, elementMesh>
182             (
183                 IOobject
184                 (
185                     fieldIoObject.name(),
186                     procMeshes_[procI]().time().timeName(),
187                     procMeshes_[procI](),
188                     IOobject::MUST_READ,
189                     IOobject::NO_WRITE
190                 ),
191                 procMeshes_[procI]
192             )
193         );
194     }
197     // Create the internalField
198     Field<Type> internalField(mesh_.nCells());
200     // Create the patch fields
201     PtrList<elementPatchField<Type> > patchFields(mesh_.boundary().size());
204     forAll (procMeshes_, procI)
205     {
206         const GeometricField<Type, elementPatchField, elementMesh>&
207             procField = procFields[procI];
209         // Set the cell values in the reconstructed field
210         internalField.rmap
211         (
212             procField.internalField(),
213             cellProcAddressing_[procI]
214         );
216         // Set the boundary patch values in the reconstructed field
217         forAll(boundaryProcAddressing_[procI], patchI)
218         {
219             // Get patch index of the original patch
220             const label curBPatch = boundaryProcAddressing_[procI][patchI];
222             // Get addressing slice for this patch
223             const labelList::subList cp =
224                 procMeshes_[procI]().boundaryMesh()[patchI].patchSlice
225                 (
226                     faceProcAddressing_[procI]
227                 );
229             // check if the boundary patch is not a processor patch
230             if (curBPatch >= 0)
231             {
232                 if (!patchFields(curBPatch))
233                 {
234                     patchFields.set
235                     (
236                         curBPatch,
237                         elementPatchField<Type>::New
238                         (
239                             procField.boundaryField()[patchI],
240                             mesh_.boundary()[curBPatch],
241                             DimensionedField<Type, elementMesh>::null(),
242                             tetPolyPatchFieldReconstructor
243                             (
244                                 mesh_.boundary()[curBPatch].size(),
245                                 procField.boundaryField()[patchI].size()
246                             )
247                         )
248                     );
249                 }
251                 // If the field stores values, do the rmap
252                 if (patchFields[curBPatch].storesFieldData())
253                 {
254                     const label curPatchStart =
255                         mesh_().boundaryMesh()[curBPatch].start();
257                     labelList reverseAddressing(cp.size());
259                     forAll(cp, faceI)
260                     {
261                         // Subtract one to take into account offsets for
262                         // face direction.
263                         reverseAddressing[faceI] = cp[faceI] - 1
264                             - curPatchStart;
265                     }
267                     patchFields[curBPatch].rmap
268                     (
269                         procField.boundaryField()[patchI],
270                         reverseAddressing
271                     );
272                 }
273             }
274         }
275     }
277     // Now construct and write the field
278     // setting the internalField and patchFields
279     return tmp<GeometricField<Type, elementPatchField, elementMesh> >
280     (
281         new GeometricField<Type, elementPatchField, elementMesh>
282         (
283             IOobject
284             (
285                 fieldIoObject.name(),
286                 mesh_().time().timeName(),
287                 mesh_(),
288                 IOobject::NO_READ,
289                 IOobject::NO_WRITE
290             ),
291             mesh_,
292             procFields[0].dimensions(),
293             internalField,
294             patchFields
295         )
296     );
300 template<class Type>
301 void tetPointFieldReconstructor::reconstructTetPointFields
303     const IOobjectList& objects
306     word fieldClassName
307     (
308         GeometricField<Type, tetPolyPatchField, tetPointMesh>::typeName
309     );
311     IOobjectList fields = objects.lookupClass(fieldClassName);
313     if (fields.size())
314     {
315         Info<< "    Reconstructing " << fieldClassName << "s\n" << endl;
317         for
318         (
319             IOobjectList::iterator fieldIter = fields.begin();
320             fieldIter != fields.end();
321             ++fieldIter
322         )
323         {
324             Info<< "        " << fieldIter()->name() << endl;
326             reconstructTetPointField<Type>(*fieldIter())().write();
327         }
329         Info<< endl;
330     }
334 template<class Type>
335 void tetPointFieldReconstructor::reconstructElementFields
337     const IOobjectList& objects
340     word fieldClassName
341     (
342         GeometricField<Type, elementPatchField, elementMesh>::typeName
343     );
345     IOobjectList fields = objects.lookupClass(fieldClassName);
347     if (fields.size())
348     {
349         Info<< "    Reconstructing " << fieldClassName << "s\n" << endl;
351         for
352         (
353             IOobjectList::iterator fieldIter = fields.begin();
354             fieldIter != fields.end();
355             ++fieldIter
356         )
357         {
358             Info<< "        " << fieldIter()->name() << endl;
360             reconstructElementField<Type>(*fieldIter())().write();
361         }
363         Info<< endl;
364     }
368 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
370 } // End namespace Foam
372 // ************************************************************************* //