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
00027 #include "surfMesh.H"
00028 #include "MeshedSurfaceProxy.H"
00029
00030 #include "Time.H"
00031 #include "cellIOList.H"
00032 #include "SubList.H"
00033 #include "OSspecific.H"
00034 #include "MeshedSurface.H"
00035 #include "demandDrivenData.H"
00036
00037
00038
00039 defineTypeNameAndDebug(Foam::surfMesh, 0);
00040
00041 Foam::word Foam::surfMesh::meshSubDir = "surfMesh";
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName)
00074 :
00075 surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
00076 Allocator
00077 (
00078 IOobject
00079 (
00080 "points",
00081 time().findInstance(meshDir(), "points"),
00082 meshSubDir,
00083 *this,
00084 IOobject::MUST_READ,
00085 IOobject::NO_WRITE
00086 ),
00087 IOobject
00088 (
00089 "faces",
00090 time().findInstance(meshDir(), "faces"),
00091 meshSubDir,
00092 *this,
00093 IOobject::MUST_READ,
00094 IOobject::NO_WRITE
00095 ),
00096 IOobject
00097 (
00098 "surfZones",
00099 time().findInstance(meshDir(), "surfZones"),
00100 meshSubDir,
00101 *this,
00102 IOobject::MUST_READ,
00103 IOobject::NO_WRITE
00104 )
00105 ),
00106 MeshReference(this->storedIOFaces(), this->storedIOPoints())
00107 {}
00108
00109
00110 Foam::surfMesh::surfMesh
00111 (
00112 const IOobject& io,
00113 const Xfer< pointField >& pointLst,
00114 const Xfer< faceList >& faceLst,
00115 const word& surfName
00116 )
00117 :
00118 surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
00119 Allocator
00120 (
00121 IOobject
00122 (
00123 "points",
00124 instance(),
00125 meshSubDir,
00126 *this,
00127 IOobject::NO_READ,
00128 IOobject::AUTO_WRITE
00129 ),
00130 pointLst,
00131 IOobject
00132 (
00133 "faces",
00134 instance(),
00135 meshSubDir,
00136 *this,
00137 IOobject::NO_READ,
00138 IOobject::AUTO_WRITE
00139 ),
00140 faceLst,
00141 IOobject
00142 (
00143 "surfZones",
00144 instance(),
00145 meshSubDir,
00146 *this,
00147 IOobject::NO_READ,
00148 IOobject::AUTO_WRITE
00149 ),
00150 Xfer<surfZoneList>()
00151 ),
00152 MeshReference(this->storedIOFaces(), this->storedIOPoints())
00153 {}
00154
00155
00156 Foam::surfMesh::surfMesh
00157 (
00158 const IOobject& io,
00159 const Xfer< MeshedSurface<face> >& surf,
00160 const word& surfName
00161 )
00162 :
00163 surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
00164 Allocator
00165 (
00166 IOobject
00167 (
00168 "points",
00169 instance(),
00170 meshSubDir,
00171 *this,
00172 IOobject::NO_READ,
00173 IOobject::AUTO_WRITE
00174 ),
00175 pointField(),
00176 IOobject
00177 (
00178 "faces",
00179 instance(),
00180 meshSubDir,
00181 *this,
00182 IOobject::NO_READ,
00183 IOobject::AUTO_WRITE
00184 ),
00185 faceList(),
00186 IOobject
00187 (
00188 "surfZones",
00189 instance(),
00190 meshSubDir,
00191 *this,
00192 IOobject::NO_READ,
00193 IOobject::AUTO_WRITE
00194 ),
00195 surfZoneList()
00196 ),
00197 MeshReference(this->storedIOFaces(), this->storedIOPoints())
00198 {
00199 if (debug)
00200 {
00201 Info<<"IOobject: " << io.path() << nl
00202 <<" name: " << io.name()
00203 <<" instance: " << io.instance()
00204 <<" local: " << io.local()
00205 <<" dbDir: " << io.db().dbDir() << endl;
00206 Info<<"creating surfMesh at instance " << instance() << endl;
00207 Info<<"timeName: " << instance() << endl;
00208 }
00209
00210
00211 if (&surf)
00212 {
00213 transfer(surf());
00214 }
00215 }
00216
00217
00218
00219
00220 Foam::surfMesh::~surfMesh()
00221 {
00222
00223
00224 }
00225
00226
00227
00228
00229 void Foam::surfMesh::updatePointsRef()
00230 {
00231
00232 reinterpret_cast<SubField<point>&>
00233 (
00234 const_cast<Field<point>&>(MeshReference::points())
00235 ) = reinterpret_cast<SubField<point>&>(this->storedPoints());
00236 }
00237
00238
00239 void Foam::surfMesh::updateFacesRef()
00240 {
00241
00242 static_cast<UList<face>&>(*this) = this->storedFaces();
00243 }
00244
00245
00246 void Foam::surfMesh::updateRefs()
00247 {
00248 this->updatePointsRef();
00249 this->updateFacesRef();
00250 }
00251
00252
00253 void Foam::surfMesh::resetPrimitives
00254 (
00255 const Xfer< pointField >& points,
00256 const Xfer< faceList >& faces,
00257 const Xfer< surfZoneList >& zones,
00258 const bool validate
00259 )
00260 {
00261
00262 MeshReference::clearGeom();
00263
00264 Allocator::reset(points, faces, zones);
00265 this->updateRefs();
00266
00267 if (validate)
00268 {
00269 checkZones();
00270 }
00271 }
00272
00273
00274 void Foam::surfMesh::transfer
00275 (
00276 MeshedSurface<face>& surf
00277 )
00278 {
00279
00280 MeshReference::clearGeom();
00281
00282 this->storedIOPoints().transfer(surf.storedPoints());
00283 this->storedIOFaces().transfer(surf.storedFaces());
00284 this->storedIOZones().transfer(surf.storedZones());
00285
00286 this->updateRefs();
00287 }
00288
00289
00290 Foam::Xfer< Foam::MeshedSurface<Foam::face> >
00291 Foam::surfMesh::xfer()
00292 {
00293 Xfer< MeshedSurface<face> > xf;
00294
00295 xf().storedPoints().transfer(this->storedPoints());
00296 xf().storedFaces().transfer(this->storedFaces());
00297 xf().storedZones().transfer(this->storedZones());
00298
00299
00300 this->updateRefs();
00301
00302
00303 MeshReference::clearGeom();
00304
00305 return xf;
00306 }
00307
00308
00309 Foam::fileName Foam::surfMesh::meshDir() const
00310 {
00311 return dbDir()/meshSubDir;
00312 }
00313
00314
00315 const Foam::fileName& Foam::surfMesh::pointsInstance() const
00316 {
00317 return this->storedIOPoints().instance();
00318 }
00319
00320
00321 const Foam::fileName& Foam::surfMesh::facesInstance() const
00322 {
00323 return this->storedIOFaces().instance();
00324 }
00325
00326
00327 Foam::label Foam::surfMesh::nPoints() const
00328 {
00329 return this->points().size();
00330 }
00331
00332
00333 Foam::label Foam::surfMesh::nFaces() const
00334 {
00335 return this->faces().size();
00336 }
00337
00338
00339 const Foam::pointField& Foam::surfMesh::points() const
00340 {
00341 return this->storedIOPoints();
00342 }
00343
00344
00345 const Foam::faceList& Foam::surfMesh::faces() const
00346 {
00347 return this->storedIOFaces();
00348 }
00349
00350
00351 void Foam::surfMesh::checkZones()
00352 {
00353
00354
00355 surfZoneList& zones = Allocator::storedIOZones();
00356
00357 if (zones.size() <= 1)
00358 {
00359 removeZones();
00360 }
00361 else
00362 {
00363 label count = 0;
00364 forAll(zones, zoneI)
00365 {
00366 zones[zoneI].start() = count;
00367 count += zones[zoneI].size();
00368 }
00369
00370 if (count < nFaces())
00371 {
00372 WarningIn
00373 (
00374 "surfMesh::checkZones()\n"
00375 )
00376 << "more faces " << nFaces() << " than zones " << count
00377 << " ... extending final zone"
00378 << endl;
00379
00380 zones[zones.size()-1].size() += count - nFaces();
00381 }
00382 else if (count > size())
00383 {
00384 FatalErrorIn
00385 (
00386 "surfMesh::checkZones()\n"
00387 )
00388 << "more zones " << count << " than faces " << nFaces()
00389 << exit(FatalError);
00390 }
00391 }
00392 }
00393
00394
00395
00396 void Foam::surfMesh::addZones
00397 (
00398 const surfZoneList& srfZones,
00399 const bool validate
00400 )
00401 {
00402 surfZoneList& zones = Allocator::storedIOZones();
00403
00404 forAll(zones, zoneI)
00405 {
00406 zones[zoneI] = surfZone(srfZones[zoneI], zoneI);
00407 }
00408
00409 if (validate)
00410 {
00411 checkZones();
00412 }
00413 }
00414
00415
00416
00417 void Foam::surfMesh::removeFiles(const fileName& instanceDir) const
00418 {
00419 fileName meshFilesPath = db().path()/instanceDir/meshSubDir;
00420
00421 rm(meshFilesPath/"points");
00422 rm(meshFilesPath/"faces");
00423 rm(meshFilesPath/"surfZones");
00424 }
00425
00426 void Foam::surfMesh::removeFiles() const
00427 {
00428 removeFiles(instance());
00429 }
00430
00431
00432 void Foam::surfMesh::write(const fileName& name, const surfMesh& surf)
00433 {
00434 MeshedSurfaceProxy<face>
00435 (
00436 surf.points(),
00437 surf.faces(),
00438 surf.surfZones()
00439 ).write(name);
00440 }
00441
00442
00443 void Foam::surfMesh::write(const fileName& name)
00444 {
00445 write(name, *this);
00446 }
00447
00448
00449