calculateMeshToMeshAddressing.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
00030
00031
00032 #include "meshToMesh.H"
00033 #include "SubField.H"
00034
00035 #include "octree.H"
00036 #include "octreeDataCell.H"
00037 #include "octreeDataFace.H"
00038
00039
00040
00041 namespace Foam
00042 {
00043
00044
00045
00046 void meshToMesh::calcAddressing()
00047 {
00048 if (debug)
00049 {
00050 Info<< "meshToMesh::calculateAddressing() : "
00051 << "calculating mesh-to-mesh cell addressing" << endl;
00052 }
00053
00054
00055 const cellList& fromCells = fromMesh_.cells();
00056 const pointField& fromPoints = fromMesh_.points();
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 if (debug)
00070 {
00071 Info<< "meshToMesh::calculateAddressing() : "
00072 << "Setting up rescue" << endl;
00073 }
00074
00075 List<bool> boundaryCell(fromCells.size(), false);
00076
00077
00078 const polyPatchList& patchesFrom = fromMesh_.boundaryMesh();
00079
00080 forAll (patchesFrom, patchI)
00081 {
00082
00083 const unallocLabelList& bCells = patchesFrom[patchI].faceCells();
00084
00085 forAll (bCells, faceI)
00086 {
00087 boundaryCell[bCells[faceI]] = true;
00088 }
00089 }
00090
00091 treeBoundBox meshBb(fromPoints);
00092
00093 scalar typDim = meshBb.avgDim()/(2.0*cbrt(scalar(fromCells.size())));
00094
00095 treeBoundBox shiftedBb
00096 (
00097 meshBb.min(),
00098 meshBb.max() + vector(typDim, typDim, typDim)
00099 );
00100
00101 if (debug)
00102 {
00103 Info<< "\nMesh" << endl;
00104 Info<< " bounding box : " << meshBb << endl;
00105 Info<< " bounding box (shifted) : " << shiftedBb << endl;
00106 Info<< " typical dimension :" << shiftedBb.typDim() << endl;
00107 }
00108
00109
00110 octreeDataCell shapes(fromMesh_);
00111
00112 octree<octreeDataCell> oc
00113 (
00114 shiftedBb,
00115 shapes,
00116 1,
00117 10.0,
00118 10.0
00119 );
00120
00121 if (debug)
00122 {
00123 oc.printStats(Info);
00124 }
00125
00126 cellAddresses
00127 (
00128 cellAddressing_,
00129 toMesh_.cellCentres(),
00130 fromMesh_,
00131 boundaryCell,
00132 oc
00133 );
00134
00135 forAll (toMesh_.boundaryMesh(), patchi)
00136 {
00137 const polyPatch& toPatch = toMesh_.boundaryMesh()[patchi];
00138
00139 if (cuttingPatches_.found(toPatch.name()))
00140 {
00141 boundaryAddressing_[patchi].setSize(toPatch.size());
00142
00143 cellAddresses
00144 (
00145 boundaryAddressing_[patchi],
00146 toPatch.faceCentres(),
00147 fromMesh_,
00148 boundaryCell,
00149 oc
00150 );
00151 }
00152 else if
00153 (
00154 patchMap_.found(toPatch.name())
00155 && fromMeshPatches_.found(patchMap_.find(toPatch.name())())
00156 )
00157 {
00158 const polyPatch& fromPatch = fromMesh_.boundaryMesh()
00159 [
00160 fromMeshPatches_.find(patchMap_.find(toPatch.name())())()
00161 ];
00162
00163 if (fromPatch.empty())
00164 {
00165 WarningIn("meshToMesh::calcAddressing()")
00166 << "Source patch " << fromPatch.name()
00167 << " has no faces. Not performing mapping for it."
00168 << endl;
00169 boundaryAddressing_[patchi] = -1;
00170 }
00171 else
00172 {
00173 treeBoundBox wallBb(fromPatch.localPoints());
00174 scalar typDim =
00175 wallBb.avgDim()/(2.0*sqrt(scalar(fromPatch.size())));
00176
00177 treeBoundBox shiftedBb
00178 (
00179 wallBb.min(),
00180 wallBb.max() + vector(typDim, typDim, typDim)
00181 );
00182
00183
00184 octreeDataFace shapes(fromPatch);
00185
00186 octree<octreeDataFace> oc
00187 (
00188 shiftedBb,
00189 shapes,
00190 1,
00191 20.0,
00192 2.0
00193 );
00194
00195
00196 const vectorField::subField centresToBoundary =
00197 toPatch.faceCentres();
00198
00199 boundaryAddressing_[patchi].setSize(toPatch.size());
00200
00201 treeBoundBox tightest;
00202 scalar tightestDist;
00203
00204 forAll(toPatch, toi)
00205 {
00206 tightest = wallBb;
00207 tightestDist = Foam::GREAT;
00208
00209 boundaryAddressing_[patchi][toi] = oc.findNearest
00210 (
00211 centresToBoundary[toi],
00212 tightest,
00213 tightestDist
00214 );
00215 }
00216 }
00217 }
00218 }
00219
00220 if (debug)
00221 {
00222 Info<< "meshToMesh::calculateAddressing() : "
00223 << "finished calculating mesh-to-mesh acell ddressing" << endl;
00224 }
00225 }
00226
00227
00228 void meshToMesh::cellAddresses
00229 (
00230 labelList& cellAddressing_,
00231 const pointField& points,
00232 const fvMesh& fromMesh,
00233 const List<bool>& boundaryCell,
00234 const octree<octreeDataCell>& oc
00235 ) const
00236 {
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246 register label curCell = 0;
00247
00248
00249 const vectorField& centresFrom = fromMesh.cellCentres();
00250 const labelListList& cc = fromMesh.cellCells();
00251
00252 forAll (points, toI)
00253 {
00254
00255 const vector& p = points[toI];
00256
00257
00258 scalar distSqr = magSqr(p - centresFrom[curCell]);
00259
00260 bool closer;
00261
00262 do
00263 {
00264 closer = false;
00265
00266
00267 const labelList& neighbours = cc[curCell];
00268
00269 forAll (neighbours, nI)
00270 {
00271 scalar curDistSqr =
00272 magSqr(p - centresFrom[neighbours[nI]]);
00273
00274
00275
00276 if (curDistSqr < (1 - SMALL)*distSqr)
00277 {
00278 curCell = neighbours[nI];
00279 distSqr = curDistSqr;
00280 closer = true;
00281 }
00282 }
00283 } while (closer);
00284
00285 cellAddressing_[toI] = -1;
00286
00287
00288 if (fromMesh.pointInCell(p, curCell))
00289 {
00290 cellAddressing_[toI] = curCell;
00291 }
00292 else
00293 {
00294
00295
00296
00297 if (boundaryCell[curCell])
00298 {
00299 cellAddressing_[toI] = oc.find(p);
00300 }
00301 else
00302 {
00303
00304 bool found = false;
00305
00306
00307 const labelList& neighbours = cc[curCell];
00308
00309 forAll (neighbours, nI)
00310 {
00311
00312
00313 if (fromMesh.pointInCell(p, neighbours[nI]))
00314 {
00315 cellAddressing_[toI] = neighbours[nI];
00316 found = true;
00317 break;
00318 }
00319 }
00320
00321 if (!found)
00322 {
00323
00324
00325
00326 const labelList& neighbours = cc[curCell];
00327
00328 forAll (neighbours, nI)
00329 {
00330
00331 const labelList& nn = cc[neighbours[nI]];
00332
00333 forAll (nn, nI)
00334 {
00335
00336
00337 if (fromMesh.pointInCell(p, nn[nI]))
00338 {
00339 cellAddressing_[toI] = nn[nI];
00340 found = true;
00341 break;
00342 }
00343 }
00344 if (found) break;
00345 }
00346 }
00347
00348 if (!found)
00349 {
00350
00351 cellAddressing_[toI] = oc.find(p);
00352 }
00353 }
00354 }
00355 }
00356 }
00357
00358
00359
00360
00361 }
00362
00363
Copyright © 2000-2009 OpenCFD Ltd