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 "mirrorFvMesh.H"
00028 #include "Time.H"
00029 #include "plane.H"
00030
00031
00032
00033 const Foam::label Foam::mirrorFvMesh::cellRenumber[8][8] =
00034 {
00035 {-1, -1, -1, -1, -1, -1, -1, -1},
00036 {-1, -1, -1, -1, -1, -1, -1, -1},
00037 {-1, -1, -1, -1, -1, -1, -1, -1},
00038 { 0, 3, 2, 1, 4, 7, 6, 5},
00039 { 2, 1, 0, 5, 4, 3, 6, -1},
00040 { 0, 2, 1, 3, 5, 4, -1, -1},
00041 { 0, 3, 2, 1, 4, -1, -1, -1},
00042 { 2, 1, 0, 3, -1, -1, -1, -1},
00043 };
00044
00045
00046
00047 Foam::mirrorFvMesh::mirrorFvMesh(const IOobject& io)
00048 :
00049 fvMesh(io),
00050 mirrorMeshDict_
00051 (
00052 IOobject
00053 (
00054 "mirrorMeshDict",
00055 time().system(),
00056 *this,
00057 IOobject::MUST_READ,
00058 IOobject::NO_WRITE
00059 )
00060 ),
00061 mirrorMeshPtr_(NULL)
00062 {
00063 plane mirrorPlane(mirrorMeshDict_);
00064
00065 scalar planeTolerance
00066 (
00067 readScalar(mirrorMeshDict_.lookup("planeTolerance"))
00068 );
00069
00070 const pointField& oldPoints = points();
00071 const faceList& oldFaces = faces();
00072 const cellList& oldCells = cells();
00073 const label nOldInternalFaces = nInternalFaces();
00074 const polyPatchList& oldPatches = boundaryMesh();
00075
00076
00077 Info << "Mirroring points. Old points: " << oldPoints.size();
00078
00079 pointField newPoints(2*oldPoints.size());
00080 label nNewPoints = 0;
00081
00082 labelList mirrorPointLookup(oldPoints.size(), -1);
00083
00084
00085 forAll (oldPoints, pointI)
00086 {
00087 newPoints[nNewPoints] = oldPoints[pointI];
00088 nNewPoints++;
00089 }
00090
00091 forAll (oldPoints, pointI)
00092 {
00093 scalar alpha =
00094 mirrorPlane.normalIntersect
00095 (
00096 oldPoints[pointI],
00097 mirrorPlane.normal()
00098 );
00099
00100
00101 if (mag(alpha) > planeTolerance)
00102 {
00103
00104 newPoints[nNewPoints] =
00105 oldPoints[pointI] + 2.0*alpha*mirrorPlane.normal();
00106
00107
00108 mirrorPointLookup[pointI] = nNewPoints;
00109 nNewPoints++;
00110 }
00111 else
00112 {
00113
00114
00115 newPoints[nNewPoints] =
00116 oldPoints[pointI] + alpha*mirrorPlane.normal();
00117
00118 mirrorPointLookup[pointI] = pointI;
00119 }
00120 }
00121
00122
00123 Info << " New points: " << nNewPoints << endl;
00124 newPoints.setSize(nNewPoints);
00125
00126 Info << "Mirroring faces. Old faces: " << oldFaces.size();
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 labelListList newCellFaces(oldCells.size());
00145
00146 const unallocLabelList& oldOwnerStart = lduAddr().ownerStartAddr();
00147
00148 forAll (newCellFaces, cellI)
00149 {
00150 labelList& curFaces = newCellFaces[cellI];
00151
00152 const label s = oldOwnerStart[cellI];
00153 const label e = oldOwnerStart[cellI + 1];
00154
00155 curFaces.setSize(e - s);
00156
00157 forAll (curFaces, i)
00158 {
00159 curFaces[i] = s + i;
00160 }
00161 }
00162
00163
00164
00165 boolListList insertedBouFace(oldPatches.size());
00166
00167 forAll (oldPatches, patchI)
00168 {
00169 const polyPatch& curPatch = oldPatches[patchI];
00170 boolList& curInsBouFace = insertedBouFace[patchI];
00171
00172 curInsBouFace.setSize(curPatch.size());
00173 curInsBouFace = false;
00174
00175
00176 const unallocLabelList& curFaceCells = curPatch.faceCells();
00177 const label curStart = curPatch.start();
00178
00179 forAll (curPatch, faceI)
00180 {
00181
00182
00183
00184 const face& origFace = curPatch[faceI];
00185
00186 face mirrorFace(origFace.size());
00187 forAll (mirrorFace, pointI)
00188 {
00189 mirrorFace[pointI] = mirrorPointLookup[origFace[pointI]];
00190 }
00191
00192 if (origFace == mirrorFace)
00193 {
00194
00195
00196 const label oldSize = newCellFaces[curFaceCells[faceI]].size();
00197
00198 newCellFaces[curFaceCells[faceI]].setSize(oldSize + 1);
00199 newCellFaces[curFaceCells[faceI]][oldSize] = curStart + faceI;
00200
00201 curInsBouFace[faceI] = true;
00202 }
00203 }
00204 }
00205
00206
00207
00208
00209
00210
00211 labelList masterFaceLookup(oldFaces.size(), -1);
00212 labelList mirrorFaceLookup(oldFaces.size(), -1);
00213
00214 faceList newFaces(2*oldFaces.size());
00215 label nNewFaces = 0;
00216
00217
00218 forAll (newCellFaces, cellI)
00219 {
00220 const labelList& curCellFaces = newCellFaces[cellI];
00221
00222 forAll (curCellFaces, cfI)
00223 {
00224 newFaces[nNewFaces] = oldFaces[curCellFaces[cfI]];
00225 masterFaceLookup[curCellFaces[cfI]] = nNewFaces;
00226
00227 nNewFaces++;
00228 }
00229 }
00230
00231
00232 for (label faceI = 0; faceI < nOldInternalFaces; faceI++)
00233 {
00234 const face& oldFace = oldFaces[faceI];
00235 face& nf = newFaces[nNewFaces];
00236 nf.setSize(oldFace.size());
00237
00238 nf[0] = mirrorPointLookup[oldFace[0]];
00239
00240 for (label i = 1; i < oldFace.size(); i++)
00241 {
00242 nf[i] = mirrorPointLookup[oldFace[oldFace.size() - i]];
00243 }
00244
00245 mirrorFaceLookup[faceI] = nNewFaces;
00246 nNewFaces++;
00247 }
00248
00249
00250
00251 wordList newPatchTypes(boundary().size());
00252 wordList newPatchNames(boundary().size());
00253 labelList newPatchSizes(boundary().size(), -1);
00254 labelList newPatchStarts(boundary().size(), -1);
00255 label nNewPatches = 0;
00256
00257 forAll (boundaryMesh(), patchI)
00258 {
00259 const label curPatchSize = boundaryMesh()[patchI].size();
00260 const label curPatchStart = boundaryMesh()[patchI].start();
00261 const boolList& curInserted = insertedBouFace[patchI];
00262
00263 newPatchStarts[nNewPatches] = nNewFaces;
00264
00265
00266 for (label faceI = 0; faceI < curPatchSize; faceI++)
00267 {
00268
00269
00270 if (!curInserted[faceI])
00271 {
00272 newFaces[nNewFaces] = oldFaces[curPatchStart + faceI];
00273
00274 masterFaceLookup[curPatchStart + faceI] = nNewFaces;
00275 nNewFaces++;
00276 }
00277 }
00278
00279
00280 for (label faceI = 0; faceI < curPatchSize; faceI++)
00281 {
00282
00283
00284 if (!curInserted[faceI])
00285 {
00286 const face& oldFace = oldFaces[curPatchStart + faceI];
00287 face& nf = newFaces[nNewFaces];
00288 nf.setSize(oldFace.size());
00289
00290 nf[0] = mirrorPointLookup[oldFace[0]];
00291
00292 for (label i = 1; i < oldFace.size(); i++)
00293 {
00294 nf[i] = mirrorPointLookup[oldFace[oldFace.size() - i]];
00295 }
00296
00297 mirrorFaceLookup[curPatchStart + faceI] = nNewFaces;
00298 nNewFaces++;
00299 }
00300 else
00301 {
00302
00303 mirrorFaceLookup[curPatchStart + faceI] =
00304 masterFaceLookup[curPatchStart + faceI];
00305 }
00306 }
00307
00308
00309 if (nNewFaces > newPatchStarts[nNewPatches])
00310 {
00311 newPatchTypes[nNewPatches] = boundaryMesh()[patchI].type();
00312 newPatchNames[nNewPatches] = boundaryMesh()[patchI].name();
00313 newPatchSizes[nNewPatches] =
00314 nNewFaces - newPatchStarts[nNewPatches];
00315
00316 nNewPatches++;
00317 }
00318 }
00319
00320
00321 newFaces.setSize(nNewFaces);
00322 Info << " New faces: " << nNewFaces << endl;
00323
00324 newPatchTypes.setSize(nNewPatches);
00325 newPatchNames.setSize(nNewPatches);
00326 newPatchSizes.setSize(nNewPatches);
00327 newPatchStarts.setSize(nNewPatches);
00328
00329 Info << "Mirroring patches. Old patches: " << boundary().size()
00330 << " New patches: " << nNewPatches << endl;
00331
00332 Info<< "Mirroring cells. Old cells: " << oldCells.size()
00333 << " New cells: " << 2*oldCells.size() << endl;
00334
00335 cellList newCells(2*oldCells.size());
00336 label nNewCells = 0;
00337
00338
00339 forAll (oldCells, cellI)
00340 {
00341 const cell& oc = oldCells[cellI];
00342
00343 cell& nc = newCells[nNewCells];
00344 nc.setSize(oc.size());
00345
00346 forAll (oc, i)
00347 {
00348 nc[i] = masterFaceLookup[oc[i]];
00349 }
00350
00351 nNewCells++;
00352 }
00353
00354
00355 forAll (oldCells, cellI)
00356 {
00357 const cell& oc = oldCells[cellI];
00358
00359 cell& nc = newCells[nNewCells];
00360 nc.setSize(oc.size());
00361
00362 forAll (oc, i)
00363 {
00364 nc[i] = mirrorFaceLookup[oc[i]];
00365 }
00366
00367 nNewCells++;
00368 }
00369
00370
00371 Info << "Mirroring cell shapes." << endl;
00372
00373 Info << nl << "Creating new mesh" << endl;
00374 mirrorMeshPtr_ = new fvMesh
00375 (
00376 io,
00377 xferMove(newPoints),
00378 xferMove(newFaces),
00379 xferMove(newCells)
00380 );
00381
00382 fvMesh& pMesh = *mirrorMeshPtr_;
00383
00384
00385 List<polyPatch*> p(newPatchTypes.size());
00386
00387 forAll (p, patchI)
00388 {
00389 p[patchI] = polyPatch::New
00390 (
00391 newPatchTypes[patchI],
00392 newPatchNames[patchI],
00393 newPatchSizes[patchI],
00394 newPatchStarts[patchI],
00395 patchI,
00396 pMesh.boundaryMesh()
00397 ).ptr();
00398 }
00399
00400 pMesh.addPatches(p);
00401 }
00402
00403
00404
00405
00406 Foam::mirrorFvMesh::~mirrorFvMesh()
00407 {}
00408
00409
00410