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 "pyrMatcher.H"
00027 #include "cellMatcher.H"
00028 #include <OpenFOAM/primitiveMesh.H>
00029 #include <OpenFOAM/primitiveMesh.H>
00030 #include <OpenFOAM/cellModeller.H>
00031
00032
00033
00034 const Foam::label Foam::pyrMatcher::vertPerCell = 5;
00035 const Foam::label Foam::pyrMatcher::facePerCell = 5;
00036 const Foam::label Foam::pyrMatcher::maxVertPerFace = 4;
00037
00038
00039
00040
00041
00042 Foam::pyrMatcher::pyrMatcher()
00043 :
00044 cellMatcher
00045 (
00046 vertPerCell,
00047 facePerCell,
00048 maxVertPerFace,
00049 "pyr"
00050 )
00051 {
00052 }
00053
00054
00055
00056 Foam::pyrMatcher::~pyrMatcher()
00057 {}
00058
00059
00060
00061 bool Foam::pyrMatcher::matchShape
00062 (
00063 const bool checkOnly,
00064 const faceList& faces,
00065 const labelList& owner,
00066 const label cellI,
00067 const labelList& myFaces
00068 )
00069 {
00070 if (!faceSizeMatch(faces, myFaces))
00071 {
00072 return false;
00073 }
00074
00075
00076 if (checkOnly)
00077 {
00078 return true;
00079 }
00080
00081
00082 label numVert = calcLocalFaces(faces, myFaces);
00083
00084 if (numVert != vertPerCell)
00085 {
00086 return false;
00087 }
00088
00089
00090 calcEdgeAddressing(numVert);
00091
00092
00093 calcPointFaceIndex();
00094
00095
00096 vertLabels_.setSize(vertPerCell);
00097 faceLabels_.setSize(facePerCell);
00098
00099
00100
00101
00102
00103 label face0I = -1;
00104 forAll(faceSize_, faceI)
00105 {
00106 if (faceSize_[faceI] == 4)
00107 {
00108 face0I = faceI;
00109 break;
00110 }
00111 }
00112 const face& face0 = localFaces_[face0I];
00113 label face0vert0 = 0;
00114
00115
00116
00117
00118
00119
00120
00121 vertLabels_[0] = pointMap_[face0[face0vert0]];
00122 faceLabels_[0] = faceMap_[face0I];
00123
00124
00125 label face0vert1 =
00126 nextVert
00127 (
00128 face0vert0,
00129 faceSize_[face0I],
00130 !(owner[faceMap_[face0I]] == cellI)
00131 );
00132 vertLabels_[1] = pointMap_[face0[face0vert1]];
00133
00134
00135 label face0vert2 =
00136 nextVert
00137 (
00138 face0vert1,
00139 faceSize_[face0I],
00140 !(owner[faceMap_[face0I]] == cellI)
00141 );
00142 vertLabels_[2] = pointMap_[face0[face0vert2]];
00143
00144
00145 label face0vert3 =
00146 nextVert
00147 (
00148 face0vert2,
00149 faceSize_[face0I],
00150 !(owner[faceMap_[face0I]] == cellI)
00151 );
00152 vertLabels_[3] = pointMap_[face0[face0vert3]];
00153
00154
00155 label face1I =
00156 otherFace
00157 (
00158 numVert,
00159 face0[face0vert3],
00160 face0[face0vert0],
00161 face0I
00162 );
00163 faceLabels_[1] = faceMap_[face1I];
00164
00165
00166 label face2I =
00167 otherFace
00168 (
00169 numVert,
00170 face0[face0vert2],
00171 face0[face0vert3],
00172 face0I
00173 );
00174 faceLabels_[2] = faceMap_[face2I];
00175
00176
00177 label face3I =
00178 otherFace
00179 (
00180 numVert,
00181 face0[face0vert1],
00182 face0[face0vert2],
00183 face0I
00184 );
00185 faceLabels_[3] = faceMap_[face3I];
00186
00187
00188 label face4I =
00189 otherFace
00190 (
00191 numVert,
00192 face0[face0vert0],
00193 face0[face0vert1],
00194 face0I
00195 );
00196 faceLabels_[4] = faceMap_[face4I];
00197
00198 const face& face4 = localFaces_[face4I];
00199
00200
00201 label face4vert0 = pointFaceIndex_[face0[face0vert0]][face4I];
00202
00203
00204 label face4vert4 =
00205 nextVert
00206 (
00207 face4vert0,
00208 faceSize_[face4I],
00209 !(owner[faceMap_[face4I]] == cellI)
00210 );
00211 vertLabels_[4] = pointMap_[face4[face4vert4]];
00212
00213 return true;
00214 }
00215
00216
00217 Foam::label Foam::pyrMatcher::faceHashValue() const
00218 {
00219 return 4*3+4;
00220 }
00221
00222
00223 bool Foam::pyrMatcher::faceSizeMatch
00224 (
00225 const faceList& faces,
00226 const labelList& myFaces
00227 ) const
00228 {
00229 if (myFaces.size() != 5)
00230 {
00231 return false;
00232 }
00233
00234 label nTris = 0;
00235 label nQuads = 0;
00236
00237 forAll(myFaces, myFaceI)
00238 {
00239 label size = faces[myFaces[myFaceI]].size();
00240
00241 if (size == 3)
00242 {
00243 nTris++;
00244 }
00245 else if (size == 4)
00246 {
00247 nQuads++;
00248 }
00249 else
00250 {
00251 return false;
00252 }
00253 }
00254
00255 if ((nTris == 4) && (nQuads == 1))
00256 {
00257 return true;
00258 }
00259 else
00260 {
00261 return false;
00262 }
00263 }
00264
00265
00266 bool Foam::pyrMatcher::isA(const primitiveMesh& mesh, const label cellI)
00267 {
00268 return matchShape
00269 (
00270 true,
00271 mesh.faces(),
00272 mesh.faceOwner(),
00273 cellI,
00274 mesh.cells()[cellI]
00275 );
00276 }
00277
00278
00279 bool Foam::pyrMatcher::isA(const faceList& faces)
00280 {
00281
00282 return matchShape
00283 (
00284 true,
00285 faces,
00286 labelList(faces.size(), 0),
00287 0,
00288 makeIdentity(faces.size())
00289 );
00290 }
00291
00292
00293 bool Foam::pyrMatcher::matches
00294 (
00295 const primitiveMesh& mesh,
00296 const label cellI,
00297 cellShape& shape
00298 )
00299 {
00300 if
00301 (
00302 matchShape
00303 (
00304 false,
00305 mesh.faces(),
00306 mesh.faceOwner(),
00307 cellI,
00308 mesh.cells()[cellI]
00309 )
00310 )
00311 {
00312 shape = cellShape(model(), vertLabels());
00313
00314 return true;
00315 }
00316 else
00317 {
00318 return false;
00319 }
00320 }
00321
00322
00323