enrichedPatchFaces.C
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 #include "enrichedPatch.H"
00030 #include "DynamicList.H"
00031
00032
00033
00034
00035 const Foam::label Foam::enrichedPatch::enrichedFaceRatio_ = 3;
00036
00037
00038
00039 void Foam::enrichedPatch::calcEnrichedFaces
00040 (
00041 const labelListList& pointsIntoMasterEdges,
00042 const labelListList& pointsIntoSlaveEdges,
00043 const pointField& projectedSlavePoints
00044 )
00045 {
00046 if (enrichedFacesPtr_)
00047 {
00048 FatalErrorIn
00049 (
00050 "void enrichedPatch::calcEnrichedFaces\n"
00051 "(\n"
00052 " const labelListList& pointsIntoMasterEdges,\n"
00053 " const labelListList& pointsIntoSlaveEdges,\n"
00054 " const pointField& projectedSlavePoints\n"
00055 ")"
00056 ) << "Enriched faces already calculated."
00057 << abort(FatalError);
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 enrichedFacesPtr_ = new faceList(masterPatch_.size() + slavePatch_.size());
00070 faceList& enrichedFaces = *enrichedFacesPtr_;
00071
00072 label nEnrichedFaces = 0;
00073
00074 const pointField& masterLocalPoints = masterPatch_.localPoints();
00075 const faceList& masterLocalFaces = masterPatch_.localFaces();
00076 const labelListList& masterFaceEdges = masterPatch_.faceEdges();
00077
00078 const faceList& slaveLocalFaces = slavePatch_.localFaces();
00079 const labelListList& slaveFaceEdges = slavePatch_.faceEdges();
00080
00081
00082
00083
00084
00085
00086 const Map<label>& pmm = pointMergeMap();
00087
00088
00089
00090 forAll (slavePatch_, faceI)
00091 {
00092 const face oldFace = slavePatch_[faceI];
00093 const face oldLocalFace = slaveLocalFaces[faceI];
00094
00095 const labelList& curEdges = slaveFaceEdges[faceI];
00096
00097 DynamicList<label> newFace(oldFace.size()*enrichedFaceRatio_);
00098
00099
00100
00101 forAll (oldFace, i)
00102 {
00103
00104 Map<label>::const_iterator mpIter =
00105 pmm.find(oldFace[i]);
00106
00107 if (mpIter == pmm.end())
00108 {
00109
00110 newFace.append(oldFace[i]);
00111
00112
00113 pointMap().insert
00114 (
00115 oldFace[i],
00116 projectedSlavePoints[oldLocalFace[i]]
00117 );
00118 }
00119 else
00120 {
00121
00122 newFace.append(mpIter());
00123
00124
00125 pointMap().insert
00126 (
00127 mpIter(),
00128 projectedSlavePoints[oldLocalFace[i]]
00129 );
00130 }
00131
00132
00133
00134 const labelList& slavePointsOnEdge =
00135 pointsIntoSlaveEdges[curEdges[i]];
00136
00137
00138
00139 if (slavePointsOnEdge.size())
00140 {
00141
00142 scalarField edgePointWeights(slavePointsOnEdge.size());
00143 const point& startPoint = projectedSlavePoints[oldLocalFace[i]];
00144
00145 vector e =
00146 projectedSlavePoints[oldLocalFace.nextLabel(i)]
00147 - startPoint;
00148
00149 scalar magSqrE = magSqr(e);
00150
00151 if (magSqrE > SMALL)
00152 {
00153 e /= magSqrE;
00154 }
00155 else
00156 {
00157 FatalErrorIn
00158 (
00159 "void enrichedPatch::calcEnrichedFaces\n"
00160 "(\n"
00161 " const labelListList& pointsIntoMasterEdges,\n"
00162 " const labelListList& pointsIntoSlaveEdges,\n"
00163 " const pointField& projectedSlavePoints\n"
00164 ")"
00165 ) << "Zero length edge in slave patch for face " << i
00166 << ". This is not allowed."
00167 << abort(FatalError);
00168 }
00169
00170 pointField slavePosOnEdge(slavePointsOnEdge.size());
00171
00172 forAll (slavePointsOnEdge, edgePointI)
00173 {
00174 slavePosOnEdge[edgePointI] =
00175 pointMap().find(slavePointsOnEdge[edgePointI])();
00176
00177 edgePointWeights[edgePointI] =
00178 (e & (slavePosOnEdge[edgePointI] - startPoint));
00179 }
00180
00181 if (debug)
00182 {
00183
00184 if (min(edgePointWeights) < 0 || max(edgePointWeights) > 1)
00185 {
00186 FatalErrorIn
00187 (
00188 "void enrichedPatch::calcEnrichedFaces\n"
00189 "(\n"
00190 " const labelListList& pointsIntoMasterEdges,\n"
00191 " const labelListList& pointsIntoSlaveEdges,\n"
00192 " const pointField& projectedSlavePoints\n"
00193 ")"
00194 ) << "Invalid point edge weights. Some of points are"
00195 << " not on the edge for edge " << curEdges[i]
00196 << " of face " << faceI << " in slave patch." << nl
00197 << "Min weight: " << min(edgePointWeights)
00198 << " Max weight: " << max(edgePointWeights)
00199 << abort(FatalError);
00200 }
00201 }
00202
00203
00204
00205
00206 for (label passI = 0; passI < edgePointWeights.size(); passI++)
00207 {
00208
00209
00210 label nextPoint = -1;
00211 scalar dist = 2;
00212
00213 forAll (edgePointWeights, wI)
00214 {
00215 if (edgePointWeights[wI] < dist)
00216 {
00217 dist = edgePointWeights[wI];
00218 nextPoint = wI;
00219 }
00220 }
00221
00222
00223
00224 newFace.append(slavePointsOnEdge[nextPoint]);
00225 edgePointWeights[nextPoint] = GREAT;
00226
00227
00228 pointMap().insert
00229 (
00230 slavePointsOnEdge[nextPoint],
00231 slavePosOnEdge[nextPoint]
00232 );
00233 }
00234 }
00235 }
00236
00237
00238
00239 enrichedFaces[nEnrichedFaces].transfer(newFace);
00240 nEnrichedFaces++;
00241 }
00242
00243
00244
00245 forAll (masterPatch_, faceI)
00246 {
00247 const face& oldFace = masterPatch_[faceI];
00248 const face& oldLocalFace = masterLocalFaces[faceI];
00249
00250 const labelList& curEdges = masterFaceEdges[faceI];
00251
00252 DynamicList<label> newFace(oldFace.size()*enrichedFaceRatio_);
00253
00254
00255
00256 forAll (oldFace, i)
00257 {
00258
00259 Map<label>::const_iterator mpIter =
00260 pmm.find(oldFace[i]);
00261
00262 if (mpIter == pmm.end())
00263 {
00264
00265 newFace.append(oldFace[i]);
00266
00267
00268 pointMap().insert
00269 (
00270 oldFace[i],
00271 masterLocalPoints[oldLocalFace[i]]
00272 );
00273 }
00274 else
00275 {
00276
00277 newFace.append(mpIter());
00278
00279
00280 pointMap().insert(mpIter(), masterLocalPoints[oldLocalFace[i]]);
00281 }
00282
00283
00284
00285 const labelList& masterPointsOnEdge =
00286 pointsIntoMasterEdges[curEdges[i]];
00287
00288
00289
00290 if (masterPointsOnEdge.size())
00291 {
00292
00293 scalarField edgePointWeights(masterPointsOnEdge.size());
00294 const point& startPoint = masterLocalPoints[oldLocalFace[i]];
00295
00296 vector e =
00297 masterLocalPoints[oldLocalFace.nextLabel(i)]
00298 - startPoint;
00299
00300 scalar magSqrE = magSqr(e);
00301
00302 if (magSqrE > SMALL)
00303 {
00304 e /= magSqrE;
00305 }
00306 else
00307 {
00308 FatalErrorIn
00309 (
00310 "void enrichedPatch::calcEnrichedFaces\n"
00311 "(\n"
00312 " const labelListList& pointsIntoMasterEdges,\n"
00313 " const labelListList& pointsIntoSlaveEdges,\n"
00314 " const pointField& projectedSlavePoints\n"
00315 ")"
00316 ) << "Zero length edge in master patch for face " << i
00317 << ". This is not allowed."
00318 << abort(FatalError);
00319 }
00320
00321 pointField masterPosOnEdge(masterPointsOnEdge.size());
00322
00323 forAll (masterPointsOnEdge, edgePointI)
00324 {
00325 masterPosOnEdge[edgePointI] =
00326 pointMap().find(masterPointsOnEdge[edgePointI])();
00327
00328 edgePointWeights[edgePointI] =
00329 (e & (masterPosOnEdge[edgePointI] - startPoint));
00330 }
00331
00332 if (debug)
00333 {
00334
00335 if (min(edgePointWeights) < 0 || max(edgePointWeights) > 1)
00336 {
00337 FatalErrorIn
00338 (
00339 "void enrichedPatch::calcEnrichedFaces\n"
00340 "(\n"
00341 " const labelListList& pointsIntoMasterEdges,\n"
00342 " const labelListList& pointsIntoSlaveEdges,\n"
00343 " const pointField& projectedSlavePoints\n"
00344 ")"
00345 ) << "Invalid point edge weights. Some of points are"
00346 << " not on the edge for edge " << curEdges[i]
00347 << " of face " << faceI << " in master patch." << nl
00348 << "Min weight: " << min(edgePointWeights)
00349 << " Max weight: " << max(edgePointWeights)
00350 << abort(FatalError);
00351 }
00352 }
00353
00354
00355
00356
00357 for (label pass = 0; pass < edgePointWeights.size(); pass++)
00358 {
00359
00360
00361 label nextPoint = -1;
00362 scalar dist = 2;
00363
00364 forAll (edgePointWeights, wI)
00365 {
00366 if (edgePointWeights[wI] < dist)
00367 {
00368 dist = edgePointWeights[wI];
00369 nextPoint = wI;
00370 }
00371 }
00372
00373
00374
00375 newFace.append(masterPointsOnEdge[nextPoint]);
00376 edgePointWeights[nextPoint] = GREAT;
00377
00378
00379 pointMap().insert
00380 (
00381 masterPointsOnEdge[nextPoint],
00382 masterPosOnEdge[nextPoint]
00383 );
00384 }
00385 }
00386 }
00387
00388
00389
00390 enrichedFaces[nEnrichedFaces].transfer(newFace);
00391 nEnrichedFaces++;
00392 }
00393
00394
00395 if (debug)
00396 {
00397 if (!checkSupport())
00398 {
00399 Info<< "Enriched patch support OK. Slave faces: "
00400 << slavePatch_.size() << " Master faces: "
00401 << masterPatch_.size() << endl;
00402 }
00403 else
00404 {
00405 FatalErrorIn
00406 (
00407 "void enrichedPatch::calcEnrichedFaces\n"
00408 "(\n"
00409 " const labelListList& pointsIntoMasterEdges,\n"
00410 " const labelListList& pointsIntoSlaveEdges,\n"
00411 " const pointField& projectedSlavePoints\n"
00412 ")"
00413 ) << "Error in enriched patch support"
00414 << abort(FatalError);
00415 }
00416 }
00417 }
00418
00419
00420
00421
00422 const Foam::faceList& Foam::enrichedPatch::enrichedFaces() const
00423 {
00424 if (!enrichedFacesPtr_)
00425 {
00426 FatalErrorIn("const faceList& enrichedPatch::enrichedFaces() const")
00427 << "Enriched faces not available yet. Please use "
00428 << "void enrichedPatch::calcEnrichedFaces\n"
00429 << "(\n"
00430 << " const labelListList& pointsIntoMasterEdges,\n"
00431 << " const labelListList& pointsIntoSlaveEdges,\n"
00432 << " const pointField& projectedSlavePoints\n"
00433 << ")"
00434 << " before trying to access faces."
00435 << abort(FatalError);
00436 }
00437
00438 return *enrichedFacesPtr_;
00439 }
00440
00441
00442
Copyright © 2000-2009 OpenCFD Ltd