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
00028 #include "directionInfo.H"
00029 #include "hexMatcher.H"
00030 #include "meshTools.H"
00031 #include "polyMesh.H"
00032
00033
00034
00035
00036 bool Foam::directionInfo::equal(const edge& e, const label v0, const label v1)
00037 {
00038 return
00039 (e.start() == v0 && e.end() == v1)
00040 || (e.start() == v1 && e.end() == v0);
00041 }
00042
00043
00044 Foam::point Foam::directionInfo::eMid
00045 (
00046 const primitiveMesh& mesh,
00047 const label edgeI
00048 )
00049 {
00050 const edge& e = mesh.edges()[edgeI];
00051
00052 return
00053 0.5
00054 * (mesh.points()[e.start()] + mesh.points()[e.end()]);
00055 }
00056
00057
00058
00059 Foam::label Foam::directionInfo::findEdge
00060 (
00061 const primitiveMesh& mesh,
00062 const labelList& edgeLabels,
00063 const label v1,
00064 const label v0
00065 )
00066 {
00067 forAll(edgeLabels, edgeLabelI)
00068 {
00069 label edgeI = edgeLabels[edgeLabelI];
00070
00071 const edge& e = mesh.edges()[edgeI];
00072
00073 if (equal(e, v0, v1))
00074 {
00075 return edgeI;
00076 }
00077 }
00078
00079 FatalErrorIn("directionInfo::findEdge")
00080 << "Cannot find an edge among " << edgeLabels << endl
00081 << "that uses vertices " << v0
00082 << " and " << v1
00083 << abort(FatalError);
00084
00085 return -1;
00086 }
00087
00088
00089 Foam::label Foam::directionInfo::lowest
00090 (
00091 const label size,
00092 const label a,
00093 const label b
00094 )
00095 {
00096
00097 label a1 = (a + 1) % size;
00098
00099 if (a1 == b)
00100 {
00101 return a;
00102 }
00103 else
00104 {
00105 label b1 = (b + 1) % size;
00106
00107 if (b1 != a)
00108 {
00109 FatalErrorIn("directionInfo::lowest")
00110 << "Problem : a:" << a << " b:" << b << " size:" << size
00111 << abort(FatalError);
00112 }
00113
00114 return b;
00115 }
00116 }
00117
00118
00119
00120
00121 Foam::label Foam::directionInfo::edgeToFaceIndex
00122 (
00123 const primitiveMesh& mesh,
00124 const label cellI,
00125 const label faceI,
00126 const label edgeI
00127 )
00128 {
00129 if ((edgeI < 0) || (edgeI >= mesh.nEdges()))
00130 {
00131 FatalErrorIn("directionInfo::edgeToFaceIndex")
00132 << "Illegal edge label:" << edgeI
00133 << " when projecting cut edge from cell " << cellI
00134 << " to face " << faceI
00135 << abort(FatalError);
00136 }
00137
00138 const edge& e = mesh.edges()[edgeI];
00139
00140 const face& f = mesh.faces()[faceI];
00141
00142
00143
00144
00145
00146
00147 label fpA = findIndex(f, e.start());
00148 label fpB = findIndex(f, e.end());
00149
00150 if (fpA != -1)
00151 {
00152 if (fpB != -1)
00153 {
00154 return lowest(f.size(), fpA, fpB);
00155 }
00156 else
00157 {
00158
00159 return -1;
00160 }
00161 }
00162 else
00163 {
00164 if (fpB != -1)
00165 {
00166
00167 return -1;
00168 }
00169 else
00170 {
00171
00172
00173
00174
00175
00176
00177
00178 label f0I, f1I;
00179
00180 meshTools::getEdgeFaces(mesh, cellI, edgeI, f0I, f1I);
00181
00182
00183 label edge0I =
00184 meshTools::walkFace(mesh, f0I, edgeI, e.start(), 2);
00185
00186
00187
00188 const edge& e0 = mesh.edges()[edge0I];
00189
00190 fpA = findIndex(f, e0.start());
00191 fpB = findIndex(f, e0.end());
00192
00193 if ((fpA != -1) && (fpB != -1))
00194 {
00195 return lowest(f.size(), fpA, fpB);
00196 }
00197
00198
00199
00200
00201
00202 label edge1I =
00203 meshTools::walkFace(mesh, f1I, edgeI, e.start(), 2);
00204
00205
00206 const edge& e1 = mesh.edges()[edge1I];
00207
00208 fpA = findIndex(f, e1.start());
00209 fpB = findIndex(f, e1.end());
00210
00211 if ((fpA != -1) && (fpB != -1))
00212 {
00213 return lowest(f.size(), fpA, fpB);
00214 }
00215
00216 FatalErrorIn("directionInfo::edgeToFaceIndex")
00217 << "Found connected faces " << mesh.faces()[f0I] << " and "
00218 << mesh.faces()[f1I] << " sharing edge " << edgeI << endl
00219 << "But none seems to be connected to face " << faceI
00220 << " vertices:" << f
00221 << abort(FatalError);
00222
00223 return -1;
00224 }
00225 }
00226 }
00227
00228
00229
00230
00231
00232 bool Foam::directionInfo::updateCell
00233 (
00234 const polyMesh& mesh,
00235 const label thisCellI,
00236 const label neighbourFaceI,
00237 const directionInfo& neighbourInfo,
00238 const scalar
00239 )
00240 {
00241 if (index_ >= -2)
00242 {
00243
00244 return false;
00245 }
00246
00247 if (hexMatcher().isA(mesh, thisCellI))
00248 {
00249 const face& f = mesh.faces()[neighbourFaceI];
00250
00251 if (neighbourInfo.index() == -2)
00252 {
00253
00254 index_ = -2;
00255 }
00256 else if (neighbourInfo.index() == -1)
00257 {
00258
00259
00260
00261
00262 label edgeI = mesh.faceEdges()[neighbourFaceI][0];
00263
00264 const edge& e = mesh.edges()[edgeI];
00265
00266
00267 label faceI =
00268 meshTools::otherFace
00269 (
00270 mesh,
00271 thisCellI,
00272 neighbourFaceI,
00273 edgeI
00274 );
00275
00276
00277 index_ =
00278 meshTools::otherEdge
00279 (
00280 mesh,
00281 mesh.faceEdges()[faceI],
00282 edgeI,
00283 e.start()
00284 );
00285 }
00286 else
00287 {
00288
00289
00290
00291 label v0 = f[neighbourInfo.index()];
00292 label v1 = f[(neighbourInfo.index() + 1) % f.size()];
00293
00294 index_ = findEdge(mesh, mesh.faceEdges()[neighbourFaceI], v0, v1);
00295 }
00296 }
00297 else
00298 {
00299
00300 index_ = -2;
00301 }
00302
00303
00304 n_ = neighbourInfo.n();
00305
00306 return true;
00307 }
00308
00309
00310
00311 bool Foam::directionInfo::updateFace
00312 (
00313 const polyMesh& mesh,
00314 const label thisFaceI,
00315 const label neighbourCellI,
00316 const directionInfo& neighbourInfo,
00317 const scalar
00318 )
00319 {
00320
00321
00322 if (index_ >= -2)
00323 {
00324
00325 return false;
00326 }
00327
00328
00329
00330
00331 if (neighbourInfo.index() >= 0)
00332 {
00333
00334
00335 index_ =
00336 edgeToFaceIndex
00337 (
00338 mesh,
00339 neighbourCellI,
00340 thisFaceI,
00341 neighbourInfo.index()
00342 );
00343 }
00344 else
00345 {
00346
00347 index_ = -2;
00348 }
00349
00350
00351 n_ = neighbourInfo.n();
00352
00353 return true;
00354 }
00355
00356
00357
00358 bool Foam::directionInfo::updateFace
00359 (
00360 const polyMesh& mesh,
00361 const label,
00362 const directionInfo& neighbourInfo,
00363 const scalar
00364 )
00365 {
00366 if (index_ >= -2)
00367 {
00368
00369 return false;
00370 }
00371 else
00372 {
00373 index_ = neighbourInfo.index();
00374
00375 n_ = neighbourInfo.n();
00376
00377 return true;
00378 }
00379 }
00380
00381
00382
00383
00384 Foam::Ostream& Foam::operator<<
00385 (
00386 Foam::Ostream& os,
00387 const Foam::directionInfo& wDist
00388 )
00389 {
00390 return os << wDist.index_ << wDist.n_;
00391 }
00392
00393
00394 Foam::Istream& Foam::operator>>(Foam::Istream& is, Foam::directionInfo& wDist)
00395 {
00396 return is >> wDist.index_ >> wDist.n_;
00397 }
00398
00399