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