initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / parallelProcessing / reconstructPar / pointFieldReconstructorReconstructFields.C
blobc96fcfa7edbc14770fcc0110dc92a38fb8610efe
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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                         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                             )
106                         )
107                     );
108                 }
110                 patchFields[curBPatch].rmap
111                 (
112                     procField.boundaryField()[patchi],
113                     patchPointAddressing_[proci][patchi]
114                 );
115             }
116         }
117     }
119     // Construct and write the field
120     // setting the internalField and patchFields
121     return tmp<GeometricField<Type, pointPatchField, pointMesh> >
122     (
123         new GeometricField<Type, pointPatchField, pointMesh>
124         (
125             IOobject
126             (
127                 fieldIoObject.name(),
128                 mesh_().time().timeName(),
129                 mesh_(),
130                 IOobject::NO_READ,
131                 IOobject::NO_WRITE
132             ),
133             mesh_,
134             procFields[0].dimensions(),
135             internalField,
136             patchFields
137         )
138     );
142 // Reconstruct and write all point fields
143 template<class Type>
144 void Foam::pointFieldReconstructor::reconstructFields
146     const IOobjectList& objects
149     word fieldClassName
150     (
151         GeometricField<Type, pointPatchField, pointMesh>::typeName
152     );
154     IOobjectList fields = objects.lookupClass(fieldClassName);
156     if (fields.size())
157     {
158         Info<< "    Reconstructing " << fieldClassName << "s\n" << endl;
160         for
161         (
162             IOobjectList::iterator fieldIter = fields.begin();
163             fieldIter != fields.end();
164             ++fieldIter
165         )
166         {
167             Info<< "        " << fieldIter()->name() << endl;
169             reconstructField<Type>(*fieldIter())().write();
170         }
172         Info<< endl;
173     }
177 // ************************************************************************* //