FreeFOAM The Cross-Platform CFD Toolkit
processorMeshes.C
Go to the documentation of this file.
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.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "processorMeshes.H"
27 #include <OpenFOAM/Time.H>
28 #include <OpenFOAM/primitiveMesh.H>
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 void Foam::processorMeshes::read()
33 {
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  );
49 
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],
63  )
64  )
65  );
66 
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],
80  )
81  )
82  );
83 
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],
97  )
98  )
99  );
100 
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],
114  )
115  )
116  );
117  }
118 }
119 
120 
121 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
122 
123 Foam::processorMeshes::processorMeshes
124 (
125  PtrList<Time>& databases,
126  const word& meshName
127 )
128 :
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())
136 {
137  read();
138 }
139 
140 
141 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
142 
144 {
146 
147  forAll (databases_, procI)
148  {
149  // Check if any new meshes need to be read.
150  fvMesh::readUpdateState procStat = meshes_[procI].readUpdate();
151 
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  */
161 
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  }
183 
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;
194 }
195 
196 
198 {
199  // Read the field for all the processors
200  PtrList<pointIOField> procsPoints(meshes_.size());
201 
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(),
214  meshes_[procI],
217  )
218  )
219  );
220  }
221 
222  // Create the new points
223  vectorField newPoints(mesh.nPoints());
224 
225  forAll (meshes_, procI)
226  {
227  const vectorField& procPoints = procsPoints[procI];
228 
229  // Set the cell values in the reconstructed field
230 
231  const labelList& pointProcAddressingI = pointProcAddressing_[procI];
232 
233  if (pointProcAddressingI.size() != procPoints.size())
234  {
235  FatalErrorIn("processorMeshes")
236  << "problem :"
237  << " pointProcAddressingI:" << pointProcAddressingI.size()
238  << " procPoints:" << procPoints.size()
239  << abort(FatalError);
240  }
241 
242  forAll(pointProcAddressingI, pointI)
243  {
244  newPoints[pointProcAddressingI[pointI]] = procPoints[pointI];
245  }
246  }
247 
248  mesh.movePoints(newPoints);
249  mesh.write();
250 }
251 
252 
253 // ************************ vim: set sw=4 sts=4 et: ************************ //