ENH: patchCloud: return pTraits<Type>::max for unfound points
[OpenFOAM-1.7.x.git] / applications / utilities / parallelProcessing / reconstructPar / processorMeshes.C
blobac0e5e83b2cbc09096bc5d60321b2d1affe90504
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2010 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
13     the Free Software Foundation, either version 3 of the License, or
14     (at your 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, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "processorMeshes.H"
27 #include "Time.H"
28 #include "primitiveMesh.H"
30 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
32 void Foam::processorMeshes::read()
34     forAll (databases_, procI)
35     {
36         meshes_.set
37         (
38             procI,
39             new fvMesh
40             (
41                 IOobject
42                 (
43                     meshName_,
44                     databases_[procI].timeName(),
45                     databases_[procI]
46                 )
47             )
48         );
50         pointProcAddressing_.set
51         (
52             procI,
53             new labelIOList
54             (
55                 IOobject
56                 (
57                     "pointProcAddressing",
58                     meshes_[procI].facesInstance(),
59                     meshes_[procI].meshSubDir,
60                     meshes_[procI],
61                     IOobject::MUST_READ,
62                     IOobject::NO_WRITE
63                 )
64             )
65         );
67         faceProcAddressing_.set
68         (
69             procI,
70             new labelIOList
71             (
72                 IOobject
73                 (
74                     "faceProcAddressing",
75                     meshes_[procI].facesInstance(),
76                     meshes_[procI].meshSubDir,
77                     meshes_[procI],
78                     IOobject::MUST_READ,
79                     IOobject::NO_WRITE
80                 )
81             )
82         );
84         cellProcAddressing_.set
85         (
86             procI,
87             new labelIOList
88             (
89                 IOobject
90                 (
91                     "cellProcAddressing",
92                     meshes_[procI].facesInstance(),
93                     meshes_[procI].meshSubDir,
94                     meshes_[procI],
95                     IOobject::MUST_READ,
96                     IOobject::NO_WRITE
97                 )
98             )
99         );
101         boundaryProcAddressing_.set
102         (
103             procI,
104             new labelIOList
105             (
106                 IOobject
107                 (
108                     "boundaryProcAddressing",
109                     meshes_[procI].facesInstance(),
110                     meshes_[procI].meshSubDir,
111                     meshes_[procI],
112                     IOobject::MUST_READ,
113                     IOobject::NO_WRITE
114                 )
115             )
116         );
117     }
121 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
123 Foam::processorMeshes::processorMeshes
125     PtrList<Time>& databases,
126     const word& meshName
129     databases_(databases),
130     meshName_(meshName),
131     meshes_(databases.size()),
132     pointProcAddressing_(databases.size()),
133     faceProcAddressing_(databases.size()),
134     cellProcAddressing_(databases.size()),
135     boundaryProcAddressing_(databases.size())
137     read();
141 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
143 Foam::fvMesh::readUpdateState Foam::processorMeshes::readUpdate()
145     fvMesh::readUpdateState stat = fvMesh::UNCHANGED;
147     forAll (databases_, procI)
148     {
149         // Check if any new meshes need to be read.
150         fvMesh::readUpdateState procStat = meshes_[procI].readUpdate();
152         /*
153         if (procStat != fvMesh::UNCHANGED)
154         {
155             Info<< "Processor " << procI
156                 << " at time " << databases_[procI].timeName()
157                 << " detected mesh change " << procStat
158                 << endl;
159         }
160         */
162         // Combine into overall mesh change status
163         if (stat == fvMesh::UNCHANGED)
164         {
165             stat = procStat;
166         }
167         else
168         {
169             if (stat != procStat)
170             {
171                 FatalErrorIn("processorMeshes::readUpdate()")
172                     << "Processor " << procI
173                     << " has a different polyMesh at time "
174                     << databases_[procI].timeName()
175                     << " compared to any previous processors." << nl
176                     << "Please check time " << databases_[procI].timeName()
177                     << " directories on all processors for consistent"
178                     << " mesh files."
179                     << exit(FatalError);
180             }
181         }
182     }
184     if
185     (
186         stat == fvMesh::TOPO_CHANGE
187      || stat == fvMesh::TOPO_PATCH_CHANGE
188     )
189     {
190         // Reread all meshes and addresssing
191         read();
192     }
193     return stat;
197 void Foam::processorMeshes::reconstructPoints(fvMesh& mesh)
199     // Read the field for all the processors
200     PtrList<pointIOField> procsPoints(meshes_.size());
202     forAll (meshes_, procI)
203     {
204         procsPoints.set
205         (
206             procI,
207             new pointIOField
208             (
209                 IOobject
210                 (
211                     "points",
212                     meshes_[procI].time().timeName(),
213                     polyMesh::meshSubDir,
214                     meshes_[procI],
215                     IOobject::MUST_READ,
216                     IOobject::NO_WRITE
217                 )
218             )
219         );
220     }
222     // Create the new points
223     vectorField newPoints(mesh.nPoints());
225     forAll (meshes_, procI)
226     {
227         const vectorField& procPoints = procsPoints[procI];
229         // Set the cell values in the reconstructed field
231         const labelList& pointProcAddressingI = pointProcAddressing_[procI];
233         if (pointProcAddressingI.size() != procPoints.size())
234         {
235             FatalErrorIn("processorMeshes")
236                 << "problem :"
237                 << " pointProcAddressingI:" << pointProcAddressingI.size()
238                 << " procPoints:" << procPoints.size()
239                 << abort(FatalError);
240         }
242         forAll(pointProcAddressingI, pointI)
243         {
244             newPoints[pointProcAddressingI[pointI]] = procPoints[pointI];
245         }
246     }
248     mesh.movePoints(newPoints);
249     mesh.write();
253 // ************************************************************************* //