edgeFaceCirculatorI.H
Go to the documentation of this file.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 "primitiveMesh.H"
00028
00029
00030
00031 void Foam::edgeFaceCirculator::setEnd()
00032 {
00033 faceLabel_ = -1;
00034 index_ = -1;
00035 }
00036
00037
00038 void Foam::edgeFaceCirculator::setFace
00039 (
00040 const label faceI,
00041 const label cellI
00042 )
00043 {
00044 faceLabel_ = faceI;
00045
00046 if (!isBoundaryEdge_ && !mesh_.isInternalFace(faceI))
00047 {
00048 FatalErrorIn
00049 (
00050 "edgeFaceCirculator::setFace(const label, const label)"
00051 ) << "Edge is not defined as boundary edge but still walked to"
00052 << " boundary face:" << faceI << " on cell:" << cellI
00053 << abort(FatalError);
00054 }
00055 }
00056
00057
00058 void Foam::edgeFaceCirculator::otherFace(const label cellI)
00059 {
00060 const face& f = mesh_.faces()[faceLabel_];
00061 label v0 = f[index_];
00062 label v1 = f.nextLabel(index_);
00063
00064 const cell& cFaces = mesh_.cells()[cellI];
00065
00066 forAll(cFaces, i)
00067 {
00068 label faceB = cFaces[i];
00069
00070 if (faceB != faceLabel_)
00071 {
00072 label fp = getMinIndex(mesh_.faces()[faceB], v0, v1);
00073
00074 if (fp >= 0)
00075 {
00076 index_ = fp;
00077 setFace(faceB, cellI);
00078 return;
00079 }
00080 }
00081 }
00082
00083 FatalErrorIn("edgeFaceCirculator::otherFace(const label)")
00084 << "Could not find next face stepping"
00085 << " through cell along edge." << endl
00086 << "face:" << faceLabel_ << " index in face:" << index_
00087 << " edge:" << mesh_.points()[v0] << mesh_.points()[v1]
00088 << abort(FatalError);
00089 }
00090
00091
00092
00093
00094
00095 Foam::edgeFaceCirculator::edgeFaceCirculator
00096 (
00097 const primitiveMesh& mesh,
00098 const label faceLabel,
00099 const bool ownerSide,
00100 const label index,
00101 const bool isBoundaryEdge
00102 )
00103 :
00104 mesh_(mesh),
00105 faceLabel_(faceLabel),
00106 ownerSide_(ownerSide),
00107 index_(index),
00108 isBoundaryEdge_(isBoundaryEdge),
00109 startFaceLabel_(faceLabel_)
00110 {}
00111
00112
00113
00114 Foam::edgeFaceCirculator::edgeFaceCirculator(const edgeFaceCirculator& circ)
00115 :
00116 mesh_(circ.mesh_),
00117 faceLabel_(circ.faceLabel_),
00118 ownerSide_(circ.ownerSide_),
00119 index_(circ.index_),
00120 isBoundaryEdge_(circ.isBoundaryEdge_),
00121 startFaceLabel_(circ.startFaceLabel_)
00122 {}
00123
00124
00125
00126
00127 Foam::label Foam::edgeFaceCirculator::getMinIndex
00128 (
00129 const face& f,
00130 const label v0,
00131 const label v1
00132 )
00133 {
00134 label fp = findIndex(f, v0);
00135
00136 if (fp != -1)
00137 {
00138 label fpMin1 = f.rcIndex(fp);
00139
00140 if (f[fpMin1] == v1)
00141 {
00142 fp = fpMin1;
00143 }
00144 else
00145 {
00146 label fpPlus1 = f.fcIndex(fp);
00147
00148 if (f[fpPlus1] != v1)
00149 {
00150 fp = -1;
00151 }
00152 }
00153 }
00154 return fp;
00155 }
00156
00157
00158 Foam::label Foam::edgeFaceCirculator::faceLabel() const
00159 {
00160 return faceLabel_;
00161 }
00162
00163
00164 bool Foam::edgeFaceCirculator::ownerSide() const
00165 {
00166 return ownerSide_;
00167 }
00168
00169
00170 Foam::label Foam::edgeFaceCirculator::index() const
00171 {
00172 return index_;
00173 }
00174
00175
00176 Foam::label Foam::edgeFaceCirculator::cellLabel() const
00177 {
00178 if (ownerSide_)
00179 {
00180 return mesh_.faceOwner()[faceLabel_];
00181 }
00182 else if (mesh_.isInternalFace(faceLabel_))
00183 {
00184 return mesh_.faceNeighbour()[faceLabel_];
00185 }
00186 else
00187 {
00188 return -1;
00189 }
00190 }
00191
00192
00193 bool Foam::edgeFaceCirculator::sameOrder(const label v0, const label v1) const
00194 {
00195 const face& f = mesh_.faces()[faceLabel_];
00196
00197 label fp = getMinIndex(f, v0, v1);
00198
00199 if (fp != index_)
00200 {
00201 FatalErrorIn
00202 (
00203 "edgeFaceCirculator::sameOrder(const label, const label) const"
00204 ) << "v0:" << v1 << " and v1:" << v1
00205 << " not on position:" << index_ << " on face:" << faceLabel_
00206 << " verts:" << f << " or not consecutive." << abort(FatalError);
00207 }
00208
00209
00210
00211 return ownerSide_ != (f[index_] == v0);
00212 }
00213
00214
00215 void Foam::edgeFaceCirculator::setCanonical()
00216 {
00217 if (isBoundaryEdge_)
00218 {
00219
00220 label i = 0;
00221
00222 while (true)
00223 {
00224 if (mesh_.isInternalFace(faceLabel_))
00225 {
00226 if (ownerSide_)
00227 {
00228 label cellI = mesh_.faceNeighbour()[faceLabel_];
00229 otherFace(cellI);
00230
00231 ownerSide_ = (mesh_.faceOwner()[faceLabel_] == cellI);
00232 }
00233 else
00234 {
00235 label cellI = mesh_.faceOwner()[faceLabel_];
00236 otherFace(cellI);
00237
00238 ownerSide_ = (mesh_.faceOwner()[faceLabel_] == cellI);
00239 }
00240 }
00241 else if (ownerSide_)
00242 {
00243 break;
00244 }
00245 else
00246 {
00247 label cellI = mesh_.faceOwner()[faceLabel_];
00248 otherFace(cellI);
00249
00250 ownerSide_ = (mesh_.faceOwner()[faceLabel_] == cellI);
00251 }
00252
00253 i++;
00254
00255 if (i >= 1000)
00256 {
00257 const face& f = mesh_.faces()[faceLabel_];
00258
00259 FatalErrorIn("Foam::edgeFaceCirculator::setCanonical()")
00260 << "Walked " << i << " cells around edge "
00261 << mesh_.points()[f[index_]]
00262 << mesh_.points()[f.nextLabel(index_)]
00263 << " without reaching a boundary face."
00264 << " Are you sure this is a boundary edge?"
00265 << abort(FatalError);
00266 }
00267 }
00268
00269
00270 ownerSide_ = true;
00271 startFaceLabel_ = faceLabel_;
00272 }
00273 else
00274 {
00275
00276 label minFaceI = faceLabel_;
00277 bool minOwnerSide = ownerSide_;
00278 label minIndex = index_;
00279
00280 while (true)
00281 {
00282 operator++();
00283
00284 if (operator==(end()))
00285 {
00286 break;
00287 }
00288
00289 if (!mesh_.isInternalFace(faceLabel_))
00290 {
00291 const face& f = mesh_.faces()[faceLabel_];
00292
00293 FatalErrorIn("Foam::edgeFaceCirculator::setCanonical()")
00294 << "Reached boundary face " << faceLabel_
00295 << " when walking around internal edge "
00296 << mesh_.points()[f[index_]]
00297 << mesh_.points()[f.nextLabel(index_)]
00298 << "." << endl
00299 << "Are you sure this is an internal edge?"
00300 << abort(FatalError);
00301 }
00302
00303 if (faceLabel_ < minFaceI)
00304 {
00305 minFaceI = faceLabel_;
00306 minOwnerSide = ownerSide_;
00307 minIndex = index_;
00308 }
00309 }
00310
00311 faceLabel_ = minFaceI;
00312 ownerSide_ = minOwnerSide;
00313 index_ = minIndex;
00314 startFaceLabel_ = faceLabel_;
00315 }
00316 }
00317
00318
00319 void Foam::edgeFaceCirculator::operator=(const edgeFaceCirculator& circ)
00320 {
00321 faceLabel_ = circ.faceLabel_;
00322 ownerSide_ = circ.ownerSide_;
00323 index_ = circ.index_;
00324 isBoundaryEdge_ = circ.isBoundaryEdge_;
00325 startFaceLabel_ = circ.startFaceLabel_;
00326 }
00327
00328
00329 bool Foam::edgeFaceCirculator::operator==(const edgeFaceCirculator& circ) const
00330 {
00331 return faceLabel_ == circ.faceLabel_ && index_ == circ.index_;
00332
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346 }
00347
00348
00349 bool Foam::edgeFaceCirculator::operator!=(const edgeFaceCirculator& circ) const
00350 {
00351 return !(*this == circ);
00352 }
00353
00354
00355
00356 Foam::edgeFaceCirculator::edgeFaceCirculator&
00357 Foam::edgeFaceCirculator::operator++()
00358 {
00359 if (faceLabel_ == -1)
00360 {
00361 FatalErrorIn("edgeFaceCirculator::operator++()")
00362 << "Already reached end(). Cannot walk any further."
00363 << abort(FatalError);
00364 }
00365 else if (ownerSide_)
00366 {
00367
00368 label cellI = mesh_.faceOwner()[faceLabel_];
00369 otherFace(cellI);
00370
00371 ownerSide_ = (mesh_.faceOwner()[faceLabel_] != cellI);
00372
00373
00374 if (!isBoundaryEdge_ && faceLabel_ == startFaceLabel_)
00375 {
00376 setEnd();
00377 }
00378 }
00379 else if (mesh_.isInternalFace(faceLabel_))
00380 {
00381
00382 label cellI = mesh_.faceNeighbour()[faceLabel_];
00383 otherFace(cellI);
00384
00385 ownerSide_ = (mesh_.faceOwner()[faceLabel_] != cellI);
00386
00387
00388 if (!isBoundaryEdge_ && faceLabel_ == startFaceLabel_)
00389 {
00390 setEnd();
00391 }
00392 }
00393 else
00394 {
00395
00396 setEnd();
00397 }
00398
00399 return *this;
00400 }
00401
00402
00403 Foam::edgeFaceCirculator Foam::edgeFaceCirculator::begin() const
00404 {
00405 edgeFaceCirculator iter
00406 (
00407 mesh_,
00408 faceLabel_,
00409 ownerSide_,
00410 index_,
00411 isBoundaryEdge_
00412 );
00413
00414 if (isBoundaryEdge_)
00415 {
00416 iter.setCanonical();
00417 }
00418 return iter;
00419 }
00420
00421
00422 Foam::edgeFaceCirculator Foam::edgeFaceCirculator::cbegin() const
00423 {
00424 edgeFaceCirculator iter
00425 (
00426 mesh_,
00427 faceLabel_,
00428 ownerSide_,
00429 index_,
00430 isBoundaryEdge_
00431 );
00432
00433 if (isBoundaryEdge_)
00434 {
00435 iter.setCanonical();
00436 }
00437 return iter;
00438 }
00439
00440
00441 const Foam::edgeFaceCirculator& Foam::edgeFaceCirculator::end() const
00442 {
00443 return endConstIter;
00444 }
00445
00446 const Foam::edgeFaceCirculator& Foam::edgeFaceCirculator::cend() const
00447 {
00448 return endConstIter;
00449 }
00450
00451
00452
Copyright © 2000-2009 OpenCFD Ltd