Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / applications / utilities / parallelProcessing / reconstructPar / pointFieldReconstructorReconstructFields.C
blob031cc1baef8d27631e47988bf139378bfd6431a5
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 "pointFieldReconstructor.H"
28 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
30 template<class Type>
31 Foam::tmp<Foam::GeometricField<Type, Foam::pointPatchField, Foam::pointMesh> >
32 Foam::pointFieldReconstructor::reconstructField(const IOobject& fieldIoObject)
34     // Read the field for all the processors
35     PtrList<GeometricField<Type, pointPatchField, pointMesh> > procFields
36     (
37         procMeshes_.size()
38     );
40     forAll (procMeshes_, proci)
41     {
42         procFields.set
43         (
44             proci,
45             new GeometricField<Type, pointPatchField, pointMesh>
46             (
47                 IOobject
48                 (
49                     fieldIoObject.name(),
50                     procMeshes_[proci]().time().timeName(),
51                     procMeshes_[proci](),
52                     IOobject::MUST_READ,
53                     IOobject::NO_WRITE
54                 ),
55                 procMeshes_[proci]
56             )
57         );
58     }
61     // Create the internalField
62     Field<Type> internalField(mesh_.size());
64     // Create the patch fields
65     PtrList<pointPatchField<Type> > patchFields(mesh_.boundary().size());
68     forAll (procMeshes_, proci)
69     {
70         const GeometricField<Type, pointPatchField, pointMesh>&
71             procField = procFields[proci];
73         // Get processor-to-global addressing for use in rmap
74         const labelList& procToGlobalAddr = pointProcAddressing_[proci];
76         // Set the cell values in the reconstructed field
77         internalField.rmap
78         (
79             procField.internalField(),
80             procToGlobalAddr
81         );
83         // Set the boundary patch values in the reconstructed field
84         forAll(boundaryProcAddressing_[proci], patchi)
85         {
86             // Get patch index of the original patch
87             const label curBPatch = boundaryProcAddressing_[proci][patchi];
89             // check if the boundary patch is not a processor patch
90             if (curBPatch >= 0)
91             {
92                 if (!patchFields(curBPatch))
93                 {
94                     patchFields.set
95                     (
96                         curBPatch,
97                         pointPatchField<Type>::New
98                         (
99                             procField.boundaryField()[patchi],
100                             mesh_.boundary()[curBPatch],
101                             DimensionedField<Type, pointMesh>::null(),
102                             pointPatchFieldReconstructor
103                             (
104                                 mesh_.boundary()[curBPatch].size(),
105                                 procField.boundaryField()[patchi].size()
106                             )
107                         )
108                     );
109                 }
111                 patchFields[curBPatch].rmap
112                 (
113                     procField.boundaryField()[patchi],
114                     patchPointAddressing_[proci][patchi]
115                 );
116             }
117         }
118     }
120     // Construct and write the field
121     // setting the internalField and patchFields
122     return tmp<GeometricField<Type, pointPatchField, pointMesh> >
123     (
124         new GeometricField<Type, pointPatchField, pointMesh>
125         (
126             IOobject
127             (
128                 fieldIoObject.name(),
129                 mesh_().time().timeName(),
130                 mesh_(),
131                 IOobject::NO_READ,
132                 IOobject::NO_WRITE
133             ),
134             mesh_,
135             procFields[0].dimensions(),
136             internalField,
137             patchFields
138         )
139     );
143 // Reconstruct and write all point fields
144 template<class Type>
145 void Foam::pointFieldReconstructor::reconstructFields
147     const IOobjectList& objects
150     word fieldClassName
151     (
152         GeometricField<Type, pointPatchField, pointMesh>::typeName
153     );
155     IOobjectList fields = objects.lookupClass(fieldClassName);
157     if (fields.size())
158     {
159         Info<< "    Reconstructing " << fieldClassName << "s\n" << endl;
161         for
162         (
163             IOobjectList::iterator fieldIter = fields.begin();
164             fieldIter != fields.end();
165             ++fieldIter
166         )
167         {
168             Info<< "        " << fieldIter()->name() << endl;
170             reconstructField<Type>(*fieldIter())().write();
171         }
173         Info<< endl;
174     }
178 // ************************************************************************* //