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
00029
00030 #include "cellShapeRecognition.H"
00031 #include "labelList.H"
00032
00033
00034
00035 namespace Foam
00036 {
00037
00038
00039
00040 cellShape create3DCellShape
00041 (
00042 const label cellIndex,
00043 const labelList& faceLabels,
00044 const faceList& faces,
00045 const labelList& owner,
00046 const labelList& neighbour,
00047 const label fluentCellModelID
00048 )
00049 {
00050
00051 static List<const cellModel*> fluentCellModelLookup
00052 (
00053 7,
00054 reinterpret_cast<const cellModel*>(0)
00055 );
00056
00057 fluentCellModelLookup[2] = cellModeller::lookup("tet");
00058 fluentCellModelLookup[4] = cellModeller::lookup("hex");
00059 fluentCellModelLookup[5] = cellModeller::lookup("pyr");
00060 fluentCellModelLookup[6] = cellModeller::lookup("prism");
00061
00062 static label faceMatchingOrder[7][6] =
00063 {
00064 {-1, -1, -1, -1, -1, -1},
00065 {-1, -1, -1, -1, -1, -1},
00066 { 0, 1, 2, 3, -1, -1},
00067 {-1, -1, -1, -1, -1, -1},
00068 { 0, 2, 4, 3, 5, 1},
00069 { 0, 1, 2, 3, 4, -1},
00070 { 0, 2, 3, 4, 1, -1},
00071 };
00072
00073 const cellModel& curModel = *fluentCellModelLookup[fluentCellModelID];
00074
00075
00076 if (faceLabels.size() != curModel.nFaces())
00077 {
00078 FatalErrorIn
00079 (
00080 "create3DCellShape(const label cellIndex, "
00081 "const labelList& faceLabels, const labelListList& faces, "
00082 "const labelList& owner, const labelList& neighbour, "
00083 "const label fluentCellModelID)"
00084 ) << "Number of face labels not equal to"
00085 << "number of face in the model. "
00086 << "Number of face labels: " << faceLabels.size()
00087 << " number of faces in model: " << curModel.nFaces()
00088 << abort(FatalError);
00089 }
00090
00091
00092 labelListList localFaces(faceLabels.size());
00093
00094 forAll (faceLabels, faceI)
00095 {
00096 const label curFaceLabel = faceLabels[faceI];
00097
00098 const labelList& curFace = faces[curFaceLabel];
00099
00100 if (owner[curFaceLabel] == cellIndex)
00101 {
00102 localFaces[faceI] = curFace;
00103 }
00104 else if (neighbour[curFaceLabel] == cellIndex)
00105 {
00106
00107 localFaces[faceI].setSize(curFace.size());
00108
00109 forAllReverse(curFace, i)
00110 {
00111 localFaces[faceI][curFace.size() - i - 1] =
00112 curFace[i];
00113 }
00114 }
00115 else
00116 {
00117 FatalErrorIn
00118 (
00119 "create3DCellShape(const label cellIndex, "
00120 "const labelList& faceLabels, const labelListList& faces, "
00121 "const labelList& owner, const labelList& neighbour, "
00122 "const label fluentCellModelID)"
00123 ) << "face " << curFaceLabel
00124 << " does not belong to cell " << cellIndex
00125 << ". Face owner: " << owner[curFaceLabel] << " neighbour: "
00126 << neighbour[curFaceLabel]
00127 << abort(FatalError);
00128 }
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 labelList pointLabels(curModel.nPoints(), -1);
00145
00146
00147 List<bool> meshFaceUsed(localFaces.size(), false);
00148
00149
00150 const faceList& modelFaces = curModel.modelFaces();
00151
00152
00153 const labelList& firstModelFace =
00154 modelFaces[faceMatchingOrder[fluentCellModelID][0]];
00155
00156 bool found = false;
00157
00158 forAll (localFaces, meshFaceI)
00159 {
00160 if (localFaces[meshFaceI].size() == firstModelFace.size())
00161 {
00162
00163 found = true;
00164
00165 const labelList& curMeshFace = localFaces[meshFaceI];
00166
00167 meshFaceUsed[meshFaceI] = true;
00168
00169 forAll (curMeshFace, pointI)
00170 {
00171 pointLabels[firstModelFace[pointI]] = curMeshFace[pointI];
00172 }
00173
00174 break;
00175 }
00176 }
00177
00178 if (!found)
00179 {
00180 FatalErrorIn
00181 (
00182 "create3DCellShape(const label cellIndex, "
00183 "const labelList& faceLabels, const labelListList& faces, "
00184 "const labelList& owner, const labelList& neighbour, "
00185 "const label fluentCellModelID)"
00186 ) << "Cannot find match for first face. "
00187 << "cell model: " << curModel.name() << " first model face: "
00188 << firstModelFace << " Mesh faces: " << localFaces
00189 << abort(FatalError);
00190 }
00191
00192 for (label modelFaceI = 1; modelFaceI < modelFaces.size(); modelFaceI++)
00193 {
00194
00195 const labelList& curModelFace =
00196 modelFaces
00197 [faceMatchingOrder[fluentCellModelID][modelFaceI]];
00198
00199 found = false;
00200
00201
00202 forAll (localFaces, meshFaceI)
00203 {
00204 if
00205 (
00206 !meshFaceUsed[meshFaceI]
00207 && localFaces[meshFaceI].size() == curModelFace.size()
00208 )
00209 {
00210
00211 labelList meshFaceLabels = localFaces[meshFaceI];
00212
00213 for
00214 (
00215 label rotation = 0;
00216 rotation < meshFaceLabels.size();
00217 rotation++
00218 )
00219 {
00220
00221 label nMatchedLabels = 0;
00222
00223 forAll (meshFaceLabels, pointI)
00224 {
00225 if
00226 (
00227 pointLabels[curModelFace[pointI]]
00228 == meshFaceLabels[pointI]
00229 )
00230 {
00231 nMatchedLabels++;
00232 }
00233 }
00234
00235 if (nMatchedLabels >= 2)
00236 {
00237
00238 found = true;
00239 }
00240
00241 if (found)
00242 {
00243
00244 forAll (meshFaceLabels, pointI)
00245 {
00246 pointLabels[curModelFace[pointI]] =
00247 meshFaceLabels[pointI];
00248 }
00249
00250 meshFaceUsed[meshFaceI] = true;
00251
00252 break;
00253 }
00254 else
00255 {
00256
00257 label firstLabel = meshFaceLabels[0];
00258
00259 for (label i = 1; i < meshFaceLabels.size(); i++)
00260 {
00261 meshFaceLabels[i - 1] = meshFaceLabels[i];
00262 }
00263
00264 meshFaceLabels[meshFaceLabels.size() - 1] = firstLabel;
00265 }
00266 }
00267
00268 if (found) break;
00269 }
00270 }
00271
00272 if (!found)
00273 {
00274
00275 FatalErrorIn
00276 (
00277 "create3DCellShape(const label cellIndex, "
00278 "const labelList& faceLabels, const labelListList& faces, "
00279 "const labelList& owner, const labelList& neighbour, "
00280 "const label fluentCellModelID)"
00281 ) << "Cannot find match for face "
00282 << modelFaceI
00283 << ".\nModel: " << curModel.name() << " model face: "
00284 << curModelFace << " Mesh faces: " << localFaces
00285 << "Matched points: " << pointLabels
00286 << abort(FatalError);
00287 }
00288 }
00289
00290 return cellShape(curModel, pointLabels);
00291 }
00292
00293
00294
00295
00296 }
00297
00298