initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / parallelProcessing / reconstructPar / processorMeshes.C
blob8c77b9f85562f15912fc72d340206ab92643834c
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 "processorMeshes.H"
28 #include "Time.H"
29 #include "primitiveMesh.H"
31 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
33 void Foam::processorMeshes::read()
35     forAll (databases_, procI)
36     {
37         meshes_.set
38         (
39             procI,
40             new fvMesh
41             (
42                 IOobject
43                 (
44                     meshName_,
45                     databases_[procI].timeName(),
46                     databases_[procI]
47                 )
48             )
49         );
51         pointProcAddressing_.set
52         (
53             procI,
54             new labelIOList
55             (
56                 IOobject
57                 (
58                     "pointProcAddressing",
59                     meshes_[procI].facesInstance(),
60                     meshes_[procI].meshSubDir,
61                     meshes_[procI],
62                     IOobject::MUST_READ,
63                     IOobject::NO_WRITE
64                 )
65             )
66         );
68         faceProcAddressing_.set
69         (
70             procI,
71             new labelIOList
72             (
73                 IOobject
74                 (
75                     "faceProcAddressing",
76                     meshes_[procI].facesInstance(),
77                     meshes_[procI].meshSubDir,
78                     meshes_[procI],
79                     IOobject::MUST_READ,
80                     IOobject::NO_WRITE
81                 )
82             )
83         );
85         cellProcAddressing_.set
86         (
87             procI,
88             new labelIOList
89             (
90                 IOobject
91                 (
92                     "cellProcAddressing",
93                     meshes_[procI].facesInstance(),
94                     meshes_[procI].meshSubDir,
95                     meshes_[procI],
96                     IOobject::MUST_READ,
97                     IOobject::NO_WRITE
98                 )
99             )
100         );
102         boundaryProcAddressing_.set
103         (
104             procI,
105             new labelIOList
106             (
107                 IOobject
108                 (
109                     "boundaryProcAddressing",
110                     meshes_[procI].facesInstance(),
111                     meshes_[procI].meshSubDir,
112                     meshes_[procI],
113                     IOobject::MUST_READ,
114                     IOobject::NO_WRITE
115                 )
116             )
117         );
118     }
122 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
124 Foam::processorMeshes::processorMeshes
126     PtrList<Time>& databases,
127     const word& meshName
130     databases_(databases),
131     meshName_(meshName),
132     meshes_(databases.size()),
133     pointProcAddressing_(databases.size()),
134     faceProcAddressing_(databases.size()),
135     cellProcAddressing_(databases.size()),
136     boundaryProcAddressing_(databases.size())
138     read();
142 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
144 Foam::fvMesh::readUpdateState Foam::processorMeshes::readUpdate()
146     fvMesh::readUpdateState stat = fvMesh::UNCHANGED;
148     forAll (databases_, procI)
149     {
150         // Check if any new meshes need to be read.
151         fvMesh::readUpdateState procStat = meshes_[procI].readUpdate();
153         /*
154         if (procStat != fvMesh::UNCHANGED)
155         {
156             Info<< "Processor " << procI
157                 << " at time " << databases_[procI].timeName()
158                 << " detected mesh change " << procStat
159                 << endl;
160         }
161         */
163         // Combine into overall mesh change status
164         if (stat == fvMesh::UNCHANGED)
165         {
166             stat = procStat;
167         }
168         else
169         {
170             if (stat != procStat)
171             {
172                 FatalErrorIn("processorMeshes::readUpdate()")
173                     << "Processor " << procI
174                     << " has a different polyMesh at time "
175                     << databases_[procI].timeName()
176                     << " compared to any previous processors." << nl
177                     << "Please check time " << databases_[procI].timeName()
178                     << " directories on all processors for consistent"
179                     << " mesh files."
180                     << exit(FatalError);
181             }
182         }
183     }
185     if
186     (
187         stat == fvMesh::TOPO_CHANGE
188      || stat == fvMesh::TOPO_PATCH_CHANGE
189     )
190     {
191         // Reread all meshes and addresssing
192         read();
193     }
194     return stat;
198 void Foam::processorMeshes::reconstructPoints(fvMesh& mesh)
200     // Read the field for all the processors
201     PtrList<pointIOField> procsPoints(meshes_.size());
203     forAll (meshes_, procI)
204     {
205         procsPoints.set
206         (
207             procI,
208             new pointIOField
209             (
210                 IOobject
211                 (
212                     "points",
213                     meshes_[procI].time().timeName(),
214                     polyMesh::meshSubDir,
215                     meshes_[procI],
216                     IOobject::MUST_READ,
217                     IOobject::NO_WRITE
218                 )
219             )
220         );
221     }
223     // Create the new points
224     vectorField newPoints(mesh.nPoints());
226     forAll (meshes_, procI)
227     {
228         const vectorField& procPoints = procsPoints[procI];
230         // Set the cell values in the reconstructed field
232         const labelList& pointProcAddressingI = pointProcAddressing_[procI];
234         if (pointProcAddressingI.size() != procPoints.size())
235         {
236             FatalErrorIn("processorMeshes")
237                 << "problem :"
238                 << " pointProcAddressingI:" << pointProcAddressingI.size()
239                 << " procPoints:" << procPoints.size()
240                 << abort(FatalError);
241         }
243         forAll(pointProcAddressingI, pointI)
244         {
245             newPoints[pointProcAddressingI[pointI]] = procPoints[pointI];
246         }
247     }
249     mesh.movePoints(newPoints);
250     mesh.write();
254 // ************************************************************************* //