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
00028
00029
00030 #include "starMesh.H"
00031 #include <OpenFOAM/demandDrivenData.H>
00032
00033
00034
00035 void starMesh::mergeCoupleFacePoints()
00036 {
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 Info << endl << "Creating merge sets" << endl;
00053
00054
00055
00056
00057 labelList renumberPoints(points_.size(), -1);
00058
00059
00060 label mergeIncrement = points_.size()/10;
00061 labelList mergeSetID(mergeIncrement, -1);
00062
00063 label nMergeSets = 0;
00064
00065 forAll (cellFaces_, cellI)
00066 {
00067 const faceList& curFaces = cellFaces_[cellI];
00068
00069
00070
00071
00072 label nPointsInCell = 0;
00073
00074 scalar pointMergeTol = GREAT;
00075
00076 forAll (curFaces, faceI)
00077 {
00078 nPointsInCell += curFaces[faceI].size();
00079
00080 edgeList curEdges = curFaces[faceI].edges();
00081
00082 forAll (curEdges, edgeI)
00083 {
00084 scalar length = curEdges[edgeI].mag(points_);
00085
00086 if (length < pointMergeTol)
00087 {
00088 pointMergeTol = length;
00089 }
00090 }
00091 }
00092
00093
00094 pointMergeTol /= 100.0;
00095
00096
00097 labelList cellPoints(nPointsInCell);
00098 label nAddedPoints = 0;
00099
00100 forAll (curFaces, faceI)
00101 {
00102 const face& f = curFaces[faceI];
00103
00104 forAll (f, fI)
00105 {
00106 cellPoints[nAddedPoints] = f[fI];
00107 nAddedPoints++;
00108 }
00109 }
00110
00111
00112 for (label firstPI = 0; firstPI < cellPoints.size() - 1; firstPI++)
00113 {
00114 for
00115 (
00116 label otherPI = firstPI;
00117 otherPI < cellPoints.size();
00118 otherPI++
00119 )
00120 {
00121 if (cellPoints[firstPI] != cellPoints[otherPI])
00122 {
00123 label a = cellPoints[firstPI];
00124 label b = cellPoints[otherPI];
00125
00126 if (edge (a, b).mag(points_) < pointMergeTol)
00127 {
00128
00129 # ifdef DEBUG_MERGE
00130 Info<< "Merging points " << a << " and " << b << endl;
00131 # endif
00132
00133
00134 label mergeSetA = -1;
00135 label mergeSetB = -1;
00136
00137 if (renumberPoints[a] > -1)
00138 {
00139 mergeSetA = renumberPoints[a];
00140 }
00141
00142 if (renumberPoints[b] > -1)
00143 {
00144 mergeSetB = renumberPoints[b];
00145 }
00146
00147 if (mergeSetA == -1 && mergeSetB == -1)
00148 {
00149
00150 # ifdef DEBUG_MERGE
00151 Info<< "adding new merge group " << nMergeSets
00152 << endl;
00153 # endif
00154
00155
00156 renumberPoints[a] = nMergeSets;
00157 renumberPoints[b] = nMergeSets;
00158
00159 mergeSetID[nMergeSets] = min(a, b);
00160 nMergeSets++;
00161
00162 if (nMergeSets >= mergeSetID.size())
00163 {
00164 Info << "Resizing mergeSetID" << endl;
00165
00166 mergeSetID.setSize
00167 (mergeSetID.size() + mergeIncrement);
00168 }
00169 }
00170 else if (mergeSetA == -1 && mergeSetB != -1)
00171 {
00172 # ifdef DEBUG_MERGE
00173 Info<< "adding point a into the merge set of b. "
00174 << "a: " << a << endl;
00175 # endif
00176
00177
00178 renumberPoints[a] = mergeSetB;
00179
00180
00181 mergeSetID[mergeSetB] =
00182 min(a, mergeSetID[mergeSetB]);
00183 }
00184 else if (mergeSetA != -1 && mergeSetB == -1)
00185 {
00186 # ifdef DEBUG_MERGE
00187 Info<< "adding point b into the merge set of a. "
00188 << "b: " << b << endl;
00189 # endif
00190
00191
00192 renumberPoints[b] = mergeSetA;
00193
00194
00195 mergeSetID[mergeSetA] =
00196 min(b, mergeSetID[mergeSetA]);
00197 }
00198 else if (mergeSetA != mergeSetB)
00199 {
00200
00201
00202 label minMerge = min(mergeSetA, mergeSetB);
00203 label maxMerge = max(mergeSetA, mergeSetB);
00204
00205 # ifdef DEBUG_MERGE
00206 Info<< "Points already belong to two "
00207 << "different merge sets. "
00208 << "Eliminate the higher merge set. Sets: "
00209 << minMerge << " and " << maxMerge << endl;
00210 # endif
00211
00212 forAll (renumberPoints, elimI)
00213 {
00214 if (renumberPoints[elimI] == maxMerge)
00215 {
00216 renumberPoints[elimI] = minMerge;
00217 }
00218 }
00219
00220
00221 mergeSetID[minMerge] =
00222 min(mergeSetID[minMerge], mergeSetID[maxMerge]);
00223 }
00224 }
00225 }
00226 }
00227 }
00228 }
00229
00230 mergeSetID.setSize(nMergeSets);
00231
00232 Info<< "Finished creating merge sets. Number of merge sets: "
00233 << nMergeSets << "." << endl;
00234
00235
00236
00237 forAll (renumberPoints, pointI)
00238 {
00239 if (renumberPoints[pointI] < 0)
00240 {
00241
00242 renumberPoints[pointI] = pointI;
00243 }
00244 else
00245 {
00246 renumberPoints[pointI] = mergeSetID[renumberPoints[pointI]];
00247 }
00248 }
00249
00250
00251
00252
00253
00254
00255 forAll (cellFaces_, cellI)
00256 {
00257 faceList& prelimFaces = cellFaces_[cellI];
00258
00259 forAll (prelimFaces, faceI)
00260 {
00261 face oldFacePoints = prelimFaces[faceI];
00262
00263 face& prelimFacePoints = prelimFaces[faceI];
00264
00265 forAll (prelimFacePoints, pointI)
00266 {
00267 if (renumberPoints[oldFacePoints[pointI]] < 0)
00268 {
00269 FatalErrorIn("starMesh::mergeCoupleFacePoints()")
00270 << "Error in point renumbering. Old face: "
00271 << oldFacePoints << endl
00272 << "prelim face: " << prelimFacePoints
00273 << abort(FatalError);
00274 }
00275
00276 prelimFacePoints[pointI] =
00277 renumberPoints[oldFacePoints[pointI]];
00278 }
00279 }
00280 }
00281
00282
00283
00284 renumberPoints = 0;
00285
00286 forAll (cellFaces_, cellI)
00287 {
00288 const faceList& curFaces = cellFaces_[cellI];
00289
00290 forAll (curFaces, faceI)
00291 {
00292 const face& curFacePoints = curFaces[faceI];
00293
00294 forAll (curFacePoints, pointI)
00295 {
00296 renumberPoints[curFacePoints[pointI]]++;
00297 }
00298 }
00299 }
00300
00301 forAll (cellShapes_, cellI)
00302 {
00303 const labelList& curLabels = cellShapes_[cellI];
00304
00305 forAll (curLabels, pointI)
00306 {
00307 if (renumberPoints[curLabels[pointI]] == 0)
00308 {
00309 FatalErrorIn("starMesh::mergeCoupleFacePoints()")
00310 << "Error in point merging for cell "
00311 << cellI << ". STAR index: " << starCellID_[cellI]
00312 << ". " << endl
00313 << "Point index: " << curLabels[pointI] << " STAR index "
00314 << starPointID_[curLabels[pointI]] << endl
00315 << "Please check the geometry for the cell." << endl;
00316 }
00317 }
00318 }
00319
00320 label nUsedPoints = 0;
00321
00322 forAll (renumberPoints, pointI)
00323 {
00324 if (renumberPoints[pointI] > 0)
00325 {
00326
00327
00328
00329
00330 renumberPoints[pointI] = nUsedPoints;
00331 points_[nUsedPoints] = points_[pointI];
00332
00333 nUsedPoints++;
00334 }
00335 else
00336 {
00337 renumberPoints[pointI] = -1;
00338 }
00339 }
00340
00341 Info<< "Total number of points: " << points_.size() << endl
00342 << "Number of used points: " << nUsedPoints << endl;
00343
00344
00345 points_.setSize(nUsedPoints);
00346
00347 Info << "Renumbering all faces" << endl;
00348
00349 forAll (cellFaces_, cellI)
00350 {
00351 faceList& newFaces = cellFaces_[cellI];
00352
00353 forAll (newFaces, faceI)
00354 {
00355 face oldFacePoints = newFaces[faceI];
00356
00357 face& newFacePoints = newFaces[faceI];
00358
00359 forAll (newFacePoints, pointI)
00360 {
00361 if (renumberPoints[oldFacePoints[pointI]] < 0)
00362 {
00363 FatalErrorIn("starMesh::mergeCoupleFacePoints()")
00364 << "Error in point renumbering for point "
00365 << oldFacePoints[pointI]
00366 << ". Renumbering index is -1." << endl
00367 << "Old face: " << oldFacePoints << endl
00368 << "New face: " << newFacePoints << abort(FatalError);
00369 }
00370
00371 newFacePoints[pointI] = renumberPoints[oldFacePoints[pointI]];
00372 }
00373 }
00374 }
00375
00376 Info << "Renumbering all cell shapes" << endl;
00377
00378 forAll (cellShapes_, cellI)
00379 {
00380 labelList oldLabels = cellShapes_[cellI];
00381
00382 labelList& curLabels = cellShapes_[cellI];
00383
00384 forAll (curLabels, pointI)
00385 {
00386 if (renumberPoints[curLabels[pointI]] < 0)
00387 {
00388 FatalErrorIn("starMesh::mergeCoupleFacePoints()")
00389 << "Error in point renumbering for cell "
00390 << cellI << ". STAR index: " << starCellID_[cellI]
00391 << ". " << endl
00392 << "Point index: " << curLabels[pointI] << " STAR index "
00393 << starPointID_[curLabels[pointI]] << " returns invalid "
00394 << "renumbering index: "
00395 << renumberPoints[curLabels[pointI]] << "." << endl
00396 << "Old cellShape: " << oldLabels << endl
00397 << "New cell shape: " << curLabels << abort(FatalError);
00398 }
00399
00400 curLabels[pointI] = renumberPoints[oldLabels[pointI]];
00401 }
00402 }
00403
00404 Info << "Renumbering STAR point lookup" << endl;
00405
00406 labelList oldStarPointID = starPointID_;
00407
00408 starPointID_ = -1;
00409
00410 forAll (starPointID_, pointI)
00411 {
00412 if (renumberPoints[pointI] > -1)
00413 {
00414 starPointID_[renumberPoints[pointI]] = oldStarPointID[pointI];
00415 }
00416 }
00417
00418
00419 deleteDemandDrivenData(pointCellsPtr_);
00420 }
00421
00422
00423