BUGFIX: Illegal use of uninitialised value (backport)
[foam-extend-3.2.git] / applications / utilities / parallelProcessing / decomposeSets / decomposeSets.C
blobe05c67b1086be879e7703dd08adfbe2fb16a7856
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 Application
26     reconstructPar
28 Description
29     Decompose point, face and cell sets after the case has been decomposed
31 \*---------------------------------------------------------------------------*/
33 #include "fvCFD.H"
34 #include "processorMeshes.H"
35 #include "cellSet.H"
36 #include "faceSet.H"
37 #include "pointSet.H"
38 #include "IOobjectList.H"
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 int main(int argc, char *argv[])
44     argList::noParallel();
45 #   include "addRegionOption.H"
47 #   include "setRootCase.H"
48 #   include "createTime.H"
50     Info<< "Time = " << runTime.timeName() << endl;
52     // Determine the processor count directly
53     label nProcs = 0;
54     while (isDir(args.path()/(word("processor") + name(nProcs))))
55     {
56         ++nProcs;
57     }
59     if (!nProcs)
60     {
61         FatalErrorIn(args.executable())
62             << "No processor* directories found"
63             << exit(FatalError);
64     }
66     PtrList<Time> databases(nProcs);
68     forAll (databases, procI)
69     {
70         databases.set
71         (
72             procI,
73             new Time
74             (
75                 Time::controlDictName,
76                 args.rootPath(),
77                 args.caseName()/fileName(word("processor") + name(procI))
78             )
79         );
80     }
82 #   include "createNamedMesh.H"
84     // Set all times on processor meshes equal to decomposed mesh
85     forAll (databases, procI)
86     {
87         databases[procI].setTime(runTime.timeName(), runTime.timeIndex());
88     }
90     // Read all meshes and addressing to reconstructed mesh
91     processorMeshes procMeshes(databases, regionName);
93     // Find all sets on complete mesh
96     // Search for list of objects for the time of the mesh
97     IOobjectList objects
98     (
99         mesh,
100         mesh.facesInstance(),
101         polyMesh::meshSubDir/"sets"
102     );
104     Info<< "Searched : " << mesh.facesInstance()/polyMesh::meshSubDir/"sets"
105         << nl
106         << "Found    : " << objects.names() << nl
107         << endl;
110     IOobjectList pointObjects(objects.lookupClass(pointSet::typeName));
112     for
113     (
114         IOobjectList::const_iterator iter = pointObjects.begin();
115         iter != pointObjects.end();
116         ++iter
117     )
118     {
119         // Set not in memory. Load it.
120         pointSet set(*iter());
122         // Go through all processors
123         forAll (procMeshes.meshes(), procI)
124         {
125             const labelList& addr = procMeshes.pointProcAddressing()[procI];
127             labelHashSet procSet;
129             forAll (addr, pointI)
130             {
131                 if (set.found(addr[pointI]))
132                 {
133                     procSet.insert(pointI);
134                 }
135             }
137             if (!procSet.empty())
138             {
139                 // Set created, write it
140                 Info<< "Writing point set " << set.name()
141                     << " on processor " << procI << endl;
142                 pointSet cs
143                 (
144                     procMeshes.meshes()[procI],
145                     set.name(),
146                     procSet,
147                     IOobject::NO_WRITE
148                 );
149                 cs.write();
150             }
151         }
152     }
154     IOobjectList faceObjects(objects.lookupClass(faceSet::typeName));
156     for
157     (
158         IOobjectList::const_iterator iter = faceObjects.begin();
159         iter != faceObjects.end();
160         ++iter
161     )
162     {
163         // Set not in memory. Load it.
164         faceSet set(*iter());
166         // Go through all processors
167         forAll (procMeshes.meshes(), procI)
168         {
169             const labelList& addr = procMeshes.faceProcAddressing()[procI];
171             labelHashSet procSet;
173             forAll (addr, faceI)
174             {
175                 // Note faceProcAddressing peculiarity:
176                 // change of sign and offset.  HJ, 7/Mar/2011
177                 if (set.found(mag(addr[faceI]) - 1))
178                 {
179                     procSet.insert(faceI);
180                 }
181             }
183             if (!procSet.empty())
184             {
185                 // Set created, write it
186                 Info<< "Writing face set " << set.name()
187                     << " on processor " << procI << endl;
188                 faceSet cs
189                 (
190                     procMeshes.meshes()[procI],
191                     set.name(),
192                     procSet,
193                     IOobject::NO_WRITE
194                 );
195                 cs.write();
196             }
197         }
198     }
200     IOobjectList cellObjects(objects.lookupClass(cellSet::typeName));
202     for
203     (
204         IOobjectList::const_iterator iter = cellObjects.begin();
205         iter != cellObjects.end();
206         ++iter
207     )
208     {
209         // Set not in memory. Load it.
210         cellSet set(*iter());
212         // Go through all processors
213         forAll (procMeshes.meshes(), procI)
214         {
215             const labelList& addr = procMeshes.cellProcAddressing()[procI];
217             labelHashSet procSet;
219             forAll (addr, cellI)
220             {
221                 if (set.found(addr[cellI]))
222                 {
223                     procSet.insert(cellI);
224                 }
225             }
227             if (!procSet.empty())
228             {
229                 // Set created, write it
230                 Info<< "Writing cell set " << set.name()
231                     << " on processor " << procI << endl;
232                 cellSet cs
233                 (
234                     procMeshes.meshes()[procI],
235                     set.name(),
236                     procSet,
237                     IOobject::NO_WRITE
238                 );
239                 cs.write();
240             }
241         }
242     }
245     Info<< "End.\n" << endl;
247     return 0;
251 // ************************************************************************* //