00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "polyMesh.H"
00027 #include <OpenFOAM/Time.H>
00028 #include <OpenFOAM/cellIOList.H>
00029
00030
00031
00032 void Foam::polyMesh::setInstance(const fileName& inst)
00033 {
00034 if (debug)
00035 {
00036 Info<< "void polyMesh::setInstance(const fileName& inst) : "
00037 << "Resetting file instance to " << inst << endl;
00038 }
00039
00040 points_.writeOpt() = IOobject::AUTO_WRITE;
00041 points_.instance() = inst;
00042
00043 faces_.writeOpt() = IOobject::AUTO_WRITE;
00044 faces_.instance() = inst;
00045
00046 owner_.writeOpt() = IOobject::AUTO_WRITE;
00047 owner_.instance() = inst;
00048
00049 neighbour_.writeOpt() = IOobject::AUTO_WRITE;
00050 neighbour_.instance() = inst;
00051
00052 boundary_.writeOpt() = IOobject::AUTO_WRITE;
00053 boundary_.instance() = inst;
00054
00055 pointZones_.writeOpt() = IOobject::AUTO_WRITE;
00056 pointZones_.instance() = inst;
00057
00058 faceZones_.writeOpt() = IOobject::AUTO_WRITE;
00059 faceZones_.instance() = inst;
00060
00061 cellZones_.writeOpt() = IOobject::AUTO_WRITE;
00062 cellZones_.instance() = inst;
00063 }
00064
00065
00066 Foam::polyMesh::readUpdateState Foam::polyMesh::readUpdate()
00067 {
00068 if (debug)
00069 {
00070 Info<< "polyMesh::readUpdateState polyMesh::readUpdate() : "
00071 << "Updating mesh based on saved data." << endl;
00072 }
00073
00074
00075 fileName pointsInst(time().findInstance(meshDir(), "points"));
00076 fileName facesInst(time().findInstance(meshDir(), "faces"));
00077
00078 if (debug)
00079 {
00080 Info<< "Faces instance: old = " << facesInstance()
00081 << " new = " << facesInst << nl
00082 << "Points instance: old = " << pointsInstance()
00083 << " new = " << pointsInst << endl;
00084 }
00085
00086 if (facesInst != facesInstance())
00087 {
00088
00089 if (debug)
00090 {
00091 Info << "Topological change" << endl;
00092 }
00093
00094 clearOut();
00095
00096
00097
00098 setInstance(facesInst);
00099 points_.instance() = pointsInst;
00100
00101 points_ = pointIOField
00102 (
00103 IOobject
00104 (
00105 "points",
00106 pointsInst,
00107 meshSubDir,
00108 *this,
00109 IOobject::MUST_READ,
00110 IOobject::NO_WRITE,
00111 false
00112 )
00113 );
00114
00115 faces_ = faceIOList
00116 (
00117 IOobject
00118 (
00119 "faces",
00120 facesInst,
00121 meshSubDir,
00122 *this,
00123 IOobject::MUST_READ,
00124 IOobject::NO_WRITE,
00125 false
00126 )
00127 );
00128
00129 owner_ = labelIOList
00130 (
00131 IOobject
00132 (
00133 "owner",
00134 facesInst,
00135 meshSubDir,
00136 *this,
00137 IOobject::READ_IF_PRESENT,
00138 IOobject::NO_WRITE,
00139 false
00140 )
00141 );
00142
00143 neighbour_ = labelIOList
00144 (
00145 IOobject
00146 (
00147 "neighbour",
00148 facesInst,
00149 meshSubDir,
00150 *this,
00151 IOobject::READ_IF_PRESENT,
00152 IOobject::NO_WRITE,
00153 false
00154 )
00155 );
00156
00157
00158 polyBoundaryMesh newBoundary
00159 (
00160 IOobject
00161 (
00162 "boundary",
00163 facesInst,
00164 meshSubDir,
00165 *this,
00166 IOobject::MUST_READ,
00167 IOobject::NO_WRITE,
00168 false
00169 ),
00170 *this
00171 );
00172
00173
00174 bool boundaryChanged = false;
00175
00176 if (newBoundary.size() != boundary_.size())
00177 {
00178 boundaryChanged = true;
00179 }
00180 else
00181 {
00182 wordList newTypes = newBoundary.types();
00183 wordList newNames = newBoundary.names();
00184
00185 wordList oldTypes = boundary_.types();
00186 wordList oldNames = boundary_.names();
00187
00188 forAll (oldTypes, patchI)
00189 {
00190 if
00191 (
00192 oldTypes[patchI] != newTypes[patchI]
00193 || oldNames[patchI] != newNames[patchI]
00194 )
00195 {
00196 boundaryChanged = true;
00197 break;
00198 }
00199 }
00200 }
00201
00202 if (boundaryChanged)
00203 {
00204 WarningIn("polyMesh::readUpdateState polyMesh::readUpdate()")
00205 << "Number of patches has changed. This may have "
00206 << "unexpected consequences. Proceed with care." << endl;
00207
00208 boundary_.clear();
00209 boundary_.setSize(newBoundary.size());
00210
00211 forAll (newBoundary, patchI)
00212 {
00213 boundary_.set(patchI, newBoundary[patchI].clone(boundary_));
00214 }
00215 }
00216 else
00217 {
00218 forAll (boundary_, patchI)
00219 {
00220 boundary_[patchI] = polyPatch
00221 (
00222 newBoundary[patchI].name(),
00223 newBoundary[patchI].size(),
00224 newBoundary[patchI].start(),
00225 patchI,
00226 boundary_
00227 );
00228 }
00229 }
00230
00231
00232
00233
00234
00235 if (exists(owner_.objectPath()))
00236 {
00237 initMesh();
00238 }
00239 else
00240 {
00241 cellIOList cells
00242 (
00243 IOobject
00244 (
00245 "cells",
00246 facesInst,
00247 meshSubDir,
00248 *this,
00249 IOobject::MUST_READ,
00250 IOobject::NO_WRITE,
00251 false
00252 )
00253 );
00254
00255
00256
00257 initMesh(cells);
00258 }
00259
00260
00261
00262
00263
00264
00265 boundary_.updateMesh();
00266
00267
00268 boundary_.calcGeometry();
00269
00270
00271 bounds_ = boundBox(points_);
00272 geometricD_ = Vector<label>::zero;
00273 solutionD_ = Vector<label>::zero;
00274
00275
00276 pointZoneMesh newPointZones
00277 (
00278 IOobject
00279 (
00280 "pointZones",
00281 facesInst,
00282 meshSubDir,
00283 *this,
00284 IOobject::READ_IF_PRESENT,
00285 IOobject::NO_WRITE,
00286 false
00287 ),
00288 *this
00289 );
00290
00291 label oldSize = pointZones_.size();
00292
00293 if (newPointZones.size() <= pointZones_.size())
00294 {
00295 pointZones_.setSize(newPointZones.size());
00296 }
00297
00298
00299 forAll (pointZones_, czI)
00300 {
00301 pointZones_[czI] = newPointZones[czI];
00302 }
00303
00304
00305 pointZones_.setSize(newPointZones.size());
00306
00307 for (label czI = oldSize; czI < newPointZones.size(); czI++)
00308 {
00309 pointZones_.set(czI, newPointZones[czI].clone(pointZones_));
00310 }
00311
00312
00313 faceZoneMesh newFaceZones
00314 (
00315 IOobject
00316 (
00317 "faceZones",
00318 facesInst,
00319 meshSubDir,
00320 *this,
00321 IOobject::READ_IF_PRESENT,
00322 IOobject::NO_WRITE,
00323 false
00324 ),
00325 *this
00326 );
00327
00328 oldSize = faceZones_.size();
00329
00330 if (newFaceZones.size() <= faceZones_.size())
00331 {
00332 faceZones_.setSize(newFaceZones.size());
00333 }
00334
00335
00336 forAll (faceZones_, fzI)
00337 {
00338 faceZones_[fzI].resetAddressing
00339 (
00340 newFaceZones[fzI],
00341 newFaceZones[fzI].flipMap()
00342 );
00343 }
00344
00345
00346 faceZones_.setSize(newFaceZones.size());
00347
00348 for (label fzI = oldSize; fzI < newFaceZones.size(); fzI++)
00349 {
00350 faceZones_.set(fzI, newFaceZones[fzI].clone(faceZones_));
00351 }
00352
00353
00354 cellZoneMesh newCellZones
00355 (
00356 IOobject
00357 (
00358 "cellZones",
00359 facesInst,
00360 meshSubDir,
00361 *this,
00362 IOobject::READ_IF_PRESENT,
00363 IOobject::NO_WRITE,
00364 false
00365 ),
00366 *this
00367 );
00368
00369 oldSize = cellZones_.size();
00370
00371 if (newCellZones.size() <= cellZones_.size())
00372 {
00373 cellZones_.setSize(newCellZones.size());
00374 }
00375
00376
00377 forAll (cellZones_, czI)
00378 {
00379 cellZones_[czI] = newCellZones[czI];
00380 }
00381
00382
00383 cellZones_.setSize(newCellZones.size());
00384
00385 for (label czI = oldSize; czI < newCellZones.size(); czI++)
00386 {
00387 cellZones_.set(czI, newCellZones[czI].clone(cellZones_));
00388 }
00389
00390
00391 if (boundaryChanged)
00392 {
00393 return polyMesh::TOPO_PATCH_CHANGE;
00394 }
00395 else
00396 {
00397 return polyMesh::TOPO_CHANGE;
00398 }
00399 }
00400 else if (pointsInst != pointsInstance())
00401 {
00402
00403 if (debug)
00404 {
00405 Info << "Point motion" << endl;
00406 }
00407
00408 clearGeom();
00409
00410 points_.instance() = pointsInst;
00411
00412 points_ = pointIOField
00413 (
00414 IOobject
00415 (
00416 "points",
00417 pointsInst,
00418 meshSubDir,
00419 *this,
00420 IOobject::MUST_READ,
00421 IOobject::NO_WRITE,
00422 false
00423 )
00424 );
00425
00426
00427 bounds_ = boundBox(points_);
00428
00429
00430 geometricD_ = Vector<label>::zero;
00431 solutionD_ = Vector<label>::zero;
00432
00433 return polyMesh::POINTS_MOVED;
00434 }
00435 else
00436 {
00437 if (debug)
00438 {
00439 Info << "No change" << endl;
00440 }
00441
00442 return polyMesh::UNCHANGED;
00443 }
00444 }
00445
00446
00447