OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

addPatchCellLayer.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "addPatchCellLayer.H"
00028 #include "polyMesh.H"
00029 #include "polyTopoChange.H"
00030 #include "meshTools.H"
00031 #include "mapPolyMesh.H"
00032 #include "syncTools.H"
00033 #include "polyAddPoint.H"
00034 #include "polyAddFace.H"
00035 #include "polyModifyFace.H"
00036 #include "polyAddCell.H"
00037 #include "wallPoint.H"
00038 #include "globalIndex.H"
00039 
00040 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00041 
00042 defineTypeNameAndDebug(Foam::addPatchCellLayer, 0);
00043 
00044 
00045 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00046 
00047 // Calculate global faces per pp edge.
00048 Foam::labelListList Foam::addPatchCellLayer::calcGlobalEdgeFaces
00049 (
00050     const polyMesh& mesh,
00051     const globalIndex& globalFaces,
00052     const indirectPrimitivePatch& pp,
00053     const labelList& meshEdges
00054 )
00055 {
00058     //
00059     //PackedBoolList isCoupledEdge(mesh.nEdges());
00060     //
00061     //const polyBoundaryMesh& patches = mesh.boundaryMesh();
00062     //
00063     //forAll(patches, patchI)
00064     //{
00065     //    const polyPatch& pp = patches[patchI];
00066     //
00067     //    if (pp.coupled())
00068     //    {
00069     //        const labelList& meshEdges = pp.meshEdges();
00070     //
00071     //        forAll(meshEdges, i)
00072     //        {
00073     //            isCoupledEdge.set(meshEdges[i], 1);
00074     //        }
00075     //    }
00076     //}
00077 
00078     // From mesh edge to global face labels. Sized only for pp edges.
00079     labelListList globalEdgeFaces(mesh.nEdges());
00080 
00081     const labelListList& edgeFaces = pp.edgeFaces();
00082 
00083     forAll(edgeFaces, edgeI)
00084     {
00085         label meshEdgeI = meshEdges[edgeI];
00086 
00087         //if (isCoupledEdge.get(meshEdgeI) == 1)
00088         {
00089             const labelList& eFaces = edgeFaces[edgeI];
00090 
00091             // Store face and processor as unique tag.
00092             labelList& globalEFaces = globalEdgeFaces[meshEdgeI];
00093             globalEFaces.setSize(eFaces.size());
00094             forAll(eFaces, i)
00095             {
00096                 globalEFaces[i] =
00097                     globalFaces.toGlobal(pp.addressing()[eFaces[i]]);
00098             }
00099         }
00100     }
00101 
00102     // Synchronise across coupled edges.
00103     syncTools::syncEdgeList
00104     (
00105         mesh,
00106         globalEdgeFaces,
00107         uniqueEqOp(),
00108         labelList(),    // null value
00109         false           // no separation
00110     );
00111 
00112     // Extract pp part
00113     return UIndirectList<labelList>(globalEdgeFaces, meshEdges);
00114 }
00115 
00116 
00117 Foam::label Foam::addPatchCellLayer::nbrFace
00118 (
00119     const labelListList& edgeFaces,
00120     const label edgeI,
00121     const label faceI
00122 )
00123 {
00124     const labelList& eFaces = edgeFaces[edgeI];
00125 
00126     if (eFaces.size() == 2)
00127     {
00128         return (eFaces[0] != faceI ? eFaces[0] : eFaces[1]);
00129     }
00130     else
00131     {
00132         return -1;
00133     }
00134 }
00135 
00136 
00137 void Foam::addPatchCellLayer::addVertex
00138 (
00139     const label pointI,
00140     face& f,
00141     label& fp
00142 )
00143 {
00144     if (fp == 0)
00145     {
00146         f[fp++] = pointI;
00147     }
00148     else
00149     {
00150         if (f[fp-1] != pointI && f[0] != pointI)
00151         {
00152             f[fp++] = pointI;
00153         }
00154     }
00155 
00156     // Check for duplicates.
00157     if (debug)
00158     {
00159         label n = 0;
00160         for (label i = 0; i < fp; i++)
00161         {
00162             if (f[i] == pointI)
00163             {
00164                 n++;
00165 
00166                 if (n == 2)
00167                 {
00168                     f.setSize(fp);
00169                     FatalErrorIn
00170                     (
00171                         "addPatchCellLayer::addVertex(const label, face&"
00172                         ", label&)"
00173                     )   << "Point " << pointI << " already present in face "
00174                         << f << abort(FatalError);
00175                 }
00176             }
00177         }
00178     }
00179 }
00180 
00181 
00182 // Is edge to the same neighbour? (and needs extrusion and has not been
00183 // dealt with already)
00184 bool Foam::addPatchCellLayer::sameEdgeNeighbour
00185 (
00186     const indirectPrimitivePatch& pp,
00187     const labelListList& globalEdgeFaces,
00188     const boolList& doneEdge,
00189     const label thisGlobalFaceI,
00190     const label nbrGlobalFaceI,
00191     const label edgeI
00192 ) const
00193 {
00194     const edge& e = pp.edges()[edgeI];
00195 
00196     return
00197         !doneEdge[edgeI]                            // not yet handled
00198      && (
00199             addedPoints_[e[0]].size()               // is extruded
00200          || addedPoints_[e[1]].size()
00201         )
00202      && (
00203             nbrFace(globalEdgeFaces, edgeI, thisGlobalFaceI)
00204          == nbrGlobalFaceI  // is to same neighbour
00205         );
00206 }
00207 
00208 
00209 // Collect consecutive string of edges that connects the same two
00210 // (possibly coupled) faces. Returns -1 if no unvisited edge can be found.
00211 // Otherwise returns start and end index in face.
00212 Foam::labelPair Foam::addPatchCellLayer::getEdgeString
00213 (
00214     const indirectPrimitivePatch& pp,
00215     const labelListList& globalEdgeFaces,
00216     const boolList& doneEdge,
00217     const label patchFaceI,
00218     const label globalFaceI
00219 ) const
00220 {
00221     const labelList& fEdges = pp.faceEdges()[patchFaceI];
00222 
00223     label startFp = -1;
00224     label endFp = -1;
00225 
00226     // Get edge that hasn't been done yet but needs extrusion
00227     forAll(fEdges, fp)
00228     {
00229         label edgeI = fEdges[fp];
00230         const edge& e = pp.edges()[edgeI];
00231 
00232         if
00233         (
00234             !doneEdge[edgeI]
00235          && ( addedPoints_[e[0]].size() || addedPoints_[e[1]].size() )
00236         )
00237         {
00238             startFp = fp;
00239             break;
00240         }
00241     }
00242 
00243     if (startFp != -1)
00244     {
00245         // We found an edge that needs extruding but hasn't been done yet.
00246         // Now find the face on the other side
00247         label nbrGlobalFaceI = nbrFace
00248         (
00249             globalEdgeFaces,
00250             fEdges[startFp],
00251             globalFaceI
00252         );
00253 
00254         if (nbrGlobalFaceI == -1)
00255         {
00256             // Proper boundary edge. Only extrude single edge.
00257             endFp = startFp;
00258         }
00259         else
00260         {
00261             // Search back for edge
00262             // - which hasn't been handled yet
00263             // - with same neighbour
00264             // - that needs extrusion
00265             while(true)
00266             {
00267                 label prevFp = fEdges.rcIndex(startFp);
00268 
00269                 if
00270                 (
00271                     !sameEdgeNeighbour
00272                     (
00273                         pp,
00274                         globalEdgeFaces,
00275                         doneEdge,
00276                         globalFaceI,
00277                         nbrGlobalFaceI,
00278                         fEdges[prevFp]
00279                     )
00280                 )
00281                 {
00282                     break;
00283                 }
00284                 startFp = prevFp;
00285             }
00286 
00287             // Search forward for end of string
00288             endFp = startFp;
00289             while(true)
00290             {
00291                 label nextFp = fEdges.fcIndex(endFp);
00292 
00293                 if
00294                 (
00295                     !sameEdgeNeighbour
00296                     (
00297                         pp,
00298                         globalEdgeFaces,
00299                         doneEdge,
00300                         globalFaceI,
00301                         nbrGlobalFaceI,
00302                         fEdges[nextFp]
00303                     )
00304                 )
00305                 {
00306                     break;
00307                 }
00308                 endFp = nextFp;
00309             }
00310         }
00311     }
00312 
00313     return labelPair(startFp, endFp);
00314 }
00315 
00316 
00317 // Adds a side face i.e. extrudes a patch edge.
00318 Foam::label Foam::addPatchCellLayer::addSideFace
00319 (
00320     const indirectPrimitivePatch& pp,
00321     const labelList& patchID,           // prestored patch per pp face
00322     const labelListList& addedCells,    // per pp face the new extruded cell
00323     const face& newFace,
00324     const label ownFaceI,               // pp face that provides owner
00325     const label nbrFaceI,
00326     const label patchEdgeI,             // edge to add to
00327     const label meshEdgeI,              // corresponding mesh edge
00328     const label layerI,                 // layer
00329     const label numEdgeFaces,           // number of layers for edge
00330     const labelList& meshFaces,         // precalculated edgeFaces
00331     polyTopoChange& meshMod
00332 ) const
00333 {
00334     // Edge to 'inflate' from
00335     label inflateEdgeI = -1;
00336 
00337     // Check mesh faces using edge
00338     forAll(meshFaces, i)
00339     {
00340         if (mesh_.isInternalFace(meshFaces[i]))
00341         {
00342             // meshEdge uses internal faces so ok to inflate from it
00343             inflateEdgeI = meshEdgeI;
00344             break;
00345         }
00346     }
00347 
00348 
00349     // Get my mesh face and its zone.
00350     label meshFaceI = pp.addressing()[ownFaceI];
00351     label zoneI = mesh_.faceZones().whichZone(meshFaceI);
00352 
00353     label addedFaceI = -1;
00354 
00355     // Is patch edge external edge of indirectPrimitivePatch?
00356     if (nbrFaceI == -1)
00357     {
00358         // External edge so external face. Patch id is obtained from
00359         // any other patch connected to edge.
00360 
00361         const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00362 
00363         // Loop over all faces connected to edge to inflate and
00364         // see if any boundary face (but not meshFaceI)
00365         label otherPatchID = patchID[ownFaceI];
00366 
00367         forAll(meshFaces, k)
00368         {
00369             label faceI = meshFaces[k];
00370 
00371             if
00372             (
00373                 faceI != meshFaceI
00374              && !mesh_.isInternalFace(faceI)
00375             )
00376             {
00377                 otherPatchID = patches.whichPatch(faceI);
00378                 break;
00379             }
00380         }
00381 
00382         // Determine if different number of layer on owner and neighbour side
00383         // (relevant only for coupled faces). See section for internal edge
00384         // below.
00385 
00386         label layerOwn;
00387 
00388         if (addedCells[ownFaceI].size() < numEdgeFaces)
00389         {
00390             label offset = numEdgeFaces - addedCells[ownFaceI].size();
00391             if (layerI <= offset)
00392             {
00393                 layerOwn = 0;
00394             }
00395             else
00396             {
00397                 layerOwn = layerI - offset;
00398             }
00399         }
00400         else
00401         {
00402             layerOwn = layerI;
00403         }
00404 
00405 
00406         //Pout<< "Added boundary face:" << newFace
00407         //    << " own:" << addedCells[ownFaceI][layerOwn]
00408         //    << " patch:" << otherPatchID
00409         //    << endl;
00410 
00411         addedFaceI = meshMod.setAction
00412         (
00413             polyAddFace
00414             (
00415                 newFace,                    // face
00416                 addedCells[ownFaceI][layerOwn],   // owner
00417                 -1,                         // neighbour
00418                 -1,                         // master point
00419                 inflateEdgeI,               // master edge
00420                 -1,                         // master face
00421                 false,                      // flux flip
00422                 otherPatchID,               // patch for face
00423                 zoneI,                      // zone for face
00424                 false                       // face zone flip
00425             )
00426         );
00427     }
00428     else
00429     {
00430         // When adding side faces we need to modify neighbour and owners
00431         // in region where layer mesh is stopped. Determine which side
00432         // has max number of faces and make sure layers match closest to
00433         // original pp if there are different number of layers.
00434 
00435         label layerNbr;
00436         label layerOwn;
00437 
00438         if (addedCells[ownFaceI].size() > addedCells[nbrFaceI].size())
00439         {
00440             label offset =
00441                 addedCells[ownFaceI].size() - addedCells[nbrFaceI].size();
00442 
00443             layerOwn = layerI;
00444 
00445             if (layerI <= offset)
00446             {
00447                 layerNbr = 0;
00448             }
00449             else
00450             {
00451                 layerNbr = layerI - offset;
00452             }
00453         }
00454         else if (addedCells[nbrFaceI].size() > addedCells[ownFaceI].size())
00455         {
00456             label offset =
00457                 addedCells[nbrFaceI].size() - addedCells[ownFaceI].size();
00458 
00459             layerNbr = layerI;
00460 
00461             if (layerI <= offset)
00462             {
00463                 layerOwn = 0;
00464             }
00465             else
00466             {
00467                 layerOwn = layerI - offset;
00468             }
00469         }
00470         else
00471         {
00472             // Same number of layers on both sides.
00473             layerNbr = layerI;
00474             layerOwn = layerI;
00475         }
00476 
00477         addedFaceI = meshMod.setAction
00478         (
00479             polyAddFace
00480             (
00481                 newFace,                    // face
00482                 addedCells[ownFaceI][layerOwn],   // owner
00483                 addedCells[nbrFaceI][layerNbr],   // neighbour
00484                 -1,                         // master point
00485                 inflateEdgeI,               // master edge
00486                 -1,                         // master face
00487                 false,                      // flux flip
00488                 -1,                         // patch for face
00489                 zoneI,                      // zone for face
00490                 false                       // face zone flip
00491             )
00492         );
00493 
00494        //Pout<< "Added internal face:" << newFace
00495         //    << " own:" << addedCells[ownFaceI][layerOwn]
00496         //    << " nei:" << addedCells[nbrFaceI][layerNbr]
00497         //    << endl;
00498     }
00499 
00500     return addedFaceI;
00501 }
00502 
00503 
00504 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00505 
00506 // Construct from mesh
00507 Foam::addPatchCellLayer::addPatchCellLayer(const polyMesh& mesh)
00508 :
00509     mesh_(mesh),
00510     addedPoints_(0),
00511     layerFaces_(0)
00512 {}
00513 
00514 
00515 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00516 
00517 Foam::labelListList Foam::addPatchCellLayer::addedCells
00518 (
00519     const polyMesh& mesh,
00520     const labelListList& layerFaces
00521 )
00522 {
00523     labelListList layerCells(layerFaces.size());
00524 
00525     forAll(layerFaces, patchFaceI)
00526     {
00527         const labelList& faceLabels = layerFaces[patchFaceI];
00528 
00529         if (faceLabels.size())
00530         {
00531             labelList& added = layerCells[patchFaceI];
00532             added.setSize(faceLabels.size()-1);
00533 
00534             for (label i = 0; i < faceLabels.size()-1; i++)
00535             {
00536                 added[i] = mesh.faceNeighbour()[faceLabels[i]];
00537             }
00538         }
00539     }
00540     return layerCells;
00541 }
00542 
00543 
00544 Foam::labelListList Foam::addPatchCellLayer::addedCells() const
00545 {
00546     return addedCells(mesh_, layerFaces_);
00547 }
00548 
00549 
00550 void Foam::addPatchCellLayer::setRefinement
00551 (
00552     const scalarField& expansionRatio,
00553     const indirectPrimitivePatch& pp,
00554     const labelList& nFaceLayers,
00555     const labelList& nPointLayers,
00556     const vectorField& firstLayerDisp,
00557     polyTopoChange& meshMod
00558 )
00559 {
00560     if (debug)
00561     {
00562         Pout<< "addPatchCellLayer::setRefinement : Adding up to "
00563             << max(nPointLayers)
00564             << " layers of cells to indirectPrimitivePatch with "
00565             << pp.nPoints() << " points" << endl;
00566     }
00567 
00568     if
00569     (
00570         pp.nPoints() != firstLayerDisp.size()
00571      || pp.nPoints() != nPointLayers.size()
00572      || pp.size() != nFaceLayers.size()
00573     )
00574     {
00575         FatalErrorIn
00576         (
00577             "addPatchCellLayer::setRefinement"
00578             "(const scalar, const indirectPrimitivePatch&"
00579             ", const labelList&, const vectorField&, polyTopoChange&)"
00580         )   << "Size of new points is not same as number of points used by"
00581             << " the face subset" << endl
00582             << "  patch.nPoints:" << pp.nPoints()
00583             << "  displacement:" << firstLayerDisp.size()
00584             << "  nPointLayers:" << nPointLayers.size() << nl
00585             << " patch.nFaces:" << pp.size()
00586             << "  nFaceLayers:" << nFaceLayers.size()
00587             << abort(FatalError);
00588     }
00589 
00590     forAll(nPointLayers, i)
00591     {
00592         if (nPointLayers[i] < 0)
00593         {
00594             FatalErrorIn
00595             (
00596                 "addPatchCellLayer::setRefinement"
00597                 "(const scalar, const indirectPrimitivePatch&"
00598                 ", const labelList&, const vectorField&, polyTopoChange&)"
00599             )   << "Illegal number of layers " << nPointLayers[i]
00600                 << " at patch point " << i << abort(FatalError);
00601         }
00602     }
00603     forAll(nFaceLayers, i)
00604     {
00605         if (nFaceLayers[i] < 0)
00606         {
00607             FatalErrorIn
00608             (
00609                 "addPatchCellLayer::setRefinement"
00610                 "(const scalar, const indirectPrimitivePatch&"
00611                 ", const labelList&, const vectorField&, polyTopoChange&)"
00612             )   << "Illegal number of layers " << nFaceLayers[i]
00613                 << " at patch face " << i << abort(FatalError);
00614         }
00615     }
00616 
00617     const labelList& meshPoints = pp.meshPoints();
00618 
00619     // Some storage for edge-face-addressing.
00620     DynamicList<label> ef;
00621 
00622     // Precalculate mesh edges for pp.edges.
00623     labelList meshEdges(calcMeshEdges(mesh_, pp));
00624 
00625     if (debug)
00626     {
00627         // Check synchronisation
00628         // ~~~~~~~~~~~~~~~~~~~~~
00629 
00630         {
00631             labelList n(mesh_.nPoints(), 0);
00632             UIndirectList<label>(n, meshPoints) = nPointLayers;
00633             syncTools::syncPointList(mesh_, n, maxEqOp<label>(), 0, false);
00634 
00635             // Non-synced
00636             forAll(meshPoints, i)
00637             {
00638                 label meshPointI = meshPoints[i];
00639 
00640                 if (n[meshPointI] != nPointLayers[i])
00641                 {
00642                     FatalErrorIn
00643                     (
00644                         "addPatchCellLayer::setRefinement"
00645                         "(const scalar, const indirectPrimitivePatch&"
00646                         ", const labelList&, const vectorField&"
00647                         ", polyTopoChange&)"
00648                     )   << "At mesh point:" << meshPointI
00649                         << " coordinate:" << mesh_.points()[meshPointI]
00650                         << " specified nLayers:" << nPointLayers[i] << endl
00651                         << "On coupled point a different nLayers:"
00652                         << n[meshPointI] << " was specified."
00653                         << abort(FatalError);
00654                 }
00655             }
00656 
00657 
00658             // Check that nPointLayers equals the max layers of connected faces
00659             // (or 0). Anything else makes no sense.
00660             labelList nFromFace(mesh_.nPoints(), 0);
00661             forAll(nFaceLayers, i)
00662             {
00663                 const face& f = pp[i];
00664 
00665                 forAll(f, fp)
00666                 {
00667                     label pointI = f[fp];
00668 
00669                     nFromFace[pointI] = max(nFromFace[pointI], nFaceLayers[i]);
00670                 }
00671             }
00672             syncTools::syncPointList
00673             (
00674                 mesh_,
00675                 nFromFace,
00676                 maxEqOp<label>(),
00677                 0,
00678                 false
00679             );
00680 
00681             forAll(nPointLayers, i)
00682             {
00683                 label meshPointI = meshPoints[i];
00684 
00685                 if
00686                 (
00687                     nPointLayers[i] > 0
00688                  && nPointLayers[i] != nFromFace[meshPointI]
00689                 )
00690                 {
00691                     FatalErrorIn
00692                     (
00693                         "addPatchCellLayer::setRefinement"
00694                         "(const scalar, const indirectPrimitivePatch&"
00695                         ", const labelList&, const vectorField&"
00696                         ", polyTopoChange&)"
00697                     )   << "At mesh point:" << meshPointI
00698                         << " coordinate:" << mesh_.points()[meshPointI]
00699                         << " specified nLayers:" << nPointLayers[i] << endl
00700                         << "but the max nLayers of surrounding faces is:"
00701                         << nFromFace[meshPointI]
00702                         << abort(FatalError);
00703                 }
00704             }
00705         }
00706 
00707         {
00708             pointField d(mesh_.nPoints(), wallPoint::greatPoint);
00709             UIndirectList<point>(d, meshPoints) = firstLayerDisp;
00710             syncTools::syncPointList
00711             (
00712                 mesh_,
00713                 d,
00714                 minEqOp<vector>(),
00715                 wallPoint::greatPoint,
00716                 false
00717             );
00718 
00719             forAll(meshPoints, i)
00720             {
00721                 label meshPointI = meshPoints[i];
00722 
00723                 if (mag(d[meshPointI] - firstLayerDisp[i]) > SMALL)
00724                 {
00725                     FatalErrorIn
00726                     (
00727                         "addPatchCellLayer::setRefinement"
00728                         "(const scalar, const indirectPrimitivePatch&"
00729                         ", const labelList&, const vectorField&"
00730                         ", polyTopoChange&)"
00731                     )   << "At mesh point:" << meshPointI
00732                         << " coordinate:" << mesh_.points()[meshPointI]
00733                         << " specified displacement:" << firstLayerDisp[i]
00734                         << endl
00735                         << "On coupled point a different displacement:"
00736                         << d[meshPointI] << " was specified."
00737                         << abort(FatalError);
00738                 }
00739             }
00740         }
00741 
00742         // Check that edges of pp (so ones that become boundary faces)
00743         // connect to only one boundary face. Guarantees uniqueness of
00744         // patch that they go into so if this is a coupled patch both
00745         // sides decide the same.
00746         // ~~~~~~~~~~~~~~~~~~~~~~
00747 
00748         for (label edgeI = pp.nInternalEdges(); edgeI < pp.nEdges(); edgeI++)
00749         {
00750             const edge& e = pp.edges()[edgeI];
00751 
00752             if (nPointLayers[e[0]] > 0 || nPointLayers[e[1]] > 0)
00753             {
00754                 // Edge is to become a face
00755 
00756                 const labelList& eFaces = pp.edgeFaces()[edgeI];
00757 
00758                 // First check: pp should be single connected.
00759                 if (eFaces.size() != 1)
00760                 {
00761                     FatalErrorIn
00762                     (
00763                         "addPatchCellLayer::setRefinement"
00764                         "(const scalar, const indirectPrimitivePatch&"
00765                         ", const labelList&, const vectorField&"
00766                         ", polyTopoChange&)"
00767                     )   << "boundary-edge-to-be-extruded:"
00768                         << pp.points()[meshPoints[e[0]]]
00769                         << pp.points()[meshPoints[e[0]]]
00770                         << " has more than two faces using it:" << eFaces
00771                         << abort(FatalError);
00772                 }
00773 
00774                 label myFaceI = pp.addressing()[eFaces[0]];
00775 
00776                 label meshEdgeI = meshEdges[edgeI];
00777 
00778                 // Mesh faces using edge
00779 
00780                 // Mesh faces using edge
00781                 const labelList& meshFaces = mesh_.edgeFaces(meshEdgeI, ef);
00782 
00783                 // Check that there is only one patchface using edge.
00784                 const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00785 
00786                 label bFaceI = -1;
00787 
00788                 forAll(meshFaces, i)
00789                 {
00790                     label faceI = meshFaces[i];
00791 
00792                     if (faceI != myFaceI)
00793                     {
00794                         if (!mesh_.isInternalFace(faceI))
00795                         {
00796                             if (bFaceI == -1)
00797                             {
00798                                 bFaceI = faceI;
00799                             }
00800                             else
00801                             {
00802                                 FatalErrorIn
00803                                 (
00804                                     "addPatchCellLayer::setRefinement"
00805                                     "(const scalar"
00806                                     ", const indirectPrimitivePatch&"
00807                                     ", const labelList&, const vectorField&"
00808                                     ", polyTopoChange&)"
00809                                 )   << "boundary-edge-to-be-extruded:"
00810                                     << pp.points()[meshPoints[e[0]]]
00811                                     << pp.points()[meshPoints[e[0]]]
00812                                     << " has more than two boundary faces"
00813                                     << " using it:"
00814                                     << bFaceI << " fc:"
00815                                     << mesh_.faceCentres()[bFaceI]
00816                                     << " patch:" << patches.whichPatch(bFaceI)
00817                                     << " and " << faceI << " fc:"
00818                                     << mesh_.faceCentres()[faceI]
00819                                     << " patch:" << patches.whichPatch(faceI)
00820                                     << abort(FatalError);
00821                             }
00822                         }
00823                     }
00824                 }
00825             }
00826         }
00827     }
00828 
00829 
00830     // From master point (in patch point label) to added points (in mesh point
00831     // label)
00832     addedPoints_.setSize(pp.nPoints());
00833 
00834     // Mark points that do not get extruded by setting size of addedPoints_ to 0
00835     label nTruncated = 0;
00836 
00837     forAll(nPointLayers, patchPointI)
00838     {
00839         if (nPointLayers[patchPointI] > 0)
00840         {
00841             addedPoints_[patchPointI].setSize(nPointLayers[patchPointI]);
00842         }
00843         else
00844         {
00845             nTruncated++;
00846         }
00847     }
00848 
00849     if (debug)
00850     {
00851         Pout<< "Not adding points at " << nTruncated << " out of "
00852             << pp.nPoints() << " points" << endl;
00853     }
00854 
00855 
00856     //
00857     // Create new points
00858     //
00859 
00860     forAll(firstLayerDisp, patchPointI)
00861     {
00862         if (addedPoints_[patchPointI].size())
00863         {
00864             label meshPointI = meshPoints[patchPointI];
00865 
00866             label zoneI = mesh_.pointZones().whichZone(meshPointI);
00867 
00868             point pt = mesh_.points()[meshPointI];
00869 
00870             vector disp = firstLayerDisp[patchPointI];
00871 
00872             for (label i = 0; i < addedPoints_[patchPointI].size(); i++)
00873             {
00874                 pt += disp;
00875 
00876                 label addedVertI = meshMod.setAction
00877                 (
00878                     polyAddPoint
00879                     (
00880                         pt,         // point
00881                         meshPointI, // master point
00882                         zoneI,      // zone for point
00883                         true        // supports a cell
00884                     )
00885                 );
00886 
00887                 addedPoints_[patchPointI][i] = addedVertI;
00888 
00889                 disp *= expansionRatio[patchPointI];
00890             }
00891         }
00892     }
00893 
00894 
00895     //
00896     // Add cells to all boundaryFaces
00897     //
00898 
00899     labelListList addedCells(pp.size());
00900 
00901     forAll(pp, patchFaceI)
00902     {
00903         if (nFaceLayers[patchFaceI] > 0)
00904         {
00905             addedCells[patchFaceI].setSize(nFaceLayers[patchFaceI]);
00906 
00907             label meshFaceI = pp.addressing()[patchFaceI];
00908 
00909             label ownZoneI = mesh_.cellZones().whichZone
00910             (
00911                 mesh_.faceOwner()[meshFaceI]
00912             );
00913 
00914             for (label i = 0; i < nFaceLayers[patchFaceI]; i++)
00915             {
00916                 // Note: add from cell (owner of patch face) or from face?
00917                 // for now add from cell so we can map easily.
00918                 addedCells[patchFaceI][i] = meshMod.setAction
00919                 (
00920                     polyAddCell
00921                     (
00922                         -1,             // master point
00923                         -1,             // master edge
00924                         -1,             // master face
00925                         mesh_.faceOwner()[meshFaceI],   // master cell id
00926                         ownZoneI        // zone for cell
00927                     )
00928                 );
00929 
00930                 //Pout<< "For patchFace:" << patchFaceI
00931                 //    << " meshFace:" << pp.addressing()[patchFaceI]
00932                 //    << " layer:" << i << " added cell:"
00933                 //    << addedCells[patchFaceI][i]
00934                 //    << endl;
00935             }
00936         }
00937     }
00938 
00939 
00940     const polyBoundaryMesh& patches = mesh_.boundaryMesh();
00941 
00942     // Precalculated patchID for each patch face
00943     labelList patchID(pp.size());
00944 
00945     forAll(pp, patchFaceI)
00946     {
00947         label meshFaceI = pp.addressing()[patchFaceI];
00948 
00949         patchID[patchFaceI] = patches.whichPatch(meshFaceI);
00950     }
00951 
00952 
00953 
00954     // Create faces on top of the original patch faces.
00955     // These faces are created from original patch faces outwards so in order
00956     // of increasing cell number. So orientation should be same as original
00957     // patch face for them to have owner<neighbour.
00958 
00959     layerFaces_.setSize(pp.size());
00960 
00961     forAll(pp.localFaces(), patchFaceI)
00962     {
00963         label meshFaceI = pp.addressing()[patchFaceI];
00964 
00965         if (addedCells[patchFaceI].size())
00966         {
00967             layerFaces_[patchFaceI].setSize(addedCells[patchFaceI].size() + 1);
00968             layerFaces_[patchFaceI][0] = meshFaceI;
00969 
00970             label zoneI = mesh_.faceZones().whichZone(meshFaceI);
00971 
00972             // Get duplicated vertices on the patch face.
00973             const face& f = pp.localFaces()[patchFaceI];
00974 
00975             face newFace(f.size());
00976 
00977             for (label i = 0; i < addedCells[patchFaceI].size(); i++)
00978             {
00979                 forAll(f, fp)
00980                 {
00981                     if (addedPoints_[f[fp]].empty())
00982                     {
00983                         // Keep original point
00984                         newFace[fp] = meshPoints[f[fp]];
00985                     }
00986                     else
00987                     {
00988                         // Get new outside point
00989                         label offset =
00990                             addedPoints_[f[fp]].size()
00991                           - addedCells[patchFaceI].size();
00992                         newFace[fp] = addedPoints_[f[fp]][i+offset];
00993                     }
00994                 }
00995 
00996 
00997                 // Get new neighbour
00998                 label nei;
00999                 label patchI;
01000 
01001                 if (i == addedCells[patchFaceI].size()-1)
01002                 {
01003                     // Top layer so is patch face.
01004                     nei = -1;
01005                     patchI = patchID[patchFaceI];
01006                 }
01007                 else
01008                 {
01009                     // Internal face between layer i and i+1
01010                     nei = addedCells[patchFaceI][i+1];
01011                     patchI = -1;
01012                 }
01013 
01014 
01015                 layerFaces_[patchFaceI][i+1] = meshMod.setAction
01016                 (
01017                     polyAddFace
01018                     (
01019                         newFace,                    // face
01020                         addedCells[patchFaceI][i],  // owner
01021                         nei,                        // neighbour
01022                         -1,                         // master point
01023                         -1,                         // master edge
01024                         meshFaceI,                  // master face for addition
01025                         false,                      // flux flip
01026                         patchI,                     // patch for face
01027                         zoneI,                      // zone for face
01028                         false                       // face zone flip
01029                     )
01030                 );
01031                 //Pout<< "Added inbetween face " << newFace
01032                 //    << " own:" << addedCells[patchFaceI][i]
01033                 //    << " nei:" << nei
01034                 //    << " patch:" << patchI
01035                 //    << endl;
01036             }
01037         }
01038     }
01039 
01040     //
01041     // Modify old patch faces to be on the inside
01042     //
01043     forAll(pp, patchFaceI)
01044     {
01045         if (addedCells[patchFaceI].size())
01046         {
01047             label meshFaceI = pp.addressing()[patchFaceI];
01048 
01049             label zoneI = mesh_.faceZones().whichZone(meshFaceI);
01050 
01051             meshMod.setAction
01052             (
01053                 polyModifyFace
01054                 (
01055                     pp[patchFaceI],                 // modified face
01056                     meshFaceI,                      // label of face
01057                     mesh_.faceOwner()[meshFaceI],   // owner
01058                     addedCells[patchFaceI][0],      // neighbour
01059                     false,                          // face flip
01060                     -1,                             // patch for face
01061                     false,                          // remove from zone
01062                     zoneI,                          // zone for face
01063                     false                           // face flip in zone
01064                 )
01065             );
01066             //Pout<< "Modified old patch face " << meshFaceI
01067             //    << " own:" << mesh_.faceOwner()[meshFaceI]
01068             //    << " nei:" << addedCells[patchFaceI][0]
01069             //    << endl;
01070         }
01071     }
01072 
01073 
01074     //
01075     // Create 'side' faces, one per edge that is being extended.
01076     //
01077 
01078     const labelListList& faceEdges = pp.faceEdges();
01079     const faceList& localFaces = pp.localFaces();
01080     const edgeList& edges = pp.edges();
01081 
01082     // Get number of layers per edge. This is 0 if edge is not extruded;
01083     // max of connected faces otherwise.
01084     labelList edgeLayers(pp.nEdges());
01085 
01086     {
01087         // Use list over mesh.nEdges() since syncTools does not yet support
01088         // partial list synchronisation.
01089         labelList meshEdgeLayers(mesh_.nEdges(), -1);
01090 
01091         forAll(meshEdges, edgeI)
01092         {
01093             const edge& e = edges[edgeI];
01094 
01095             label meshEdgeI = meshEdges[edgeI];
01096 
01097             if ((nPointLayers[e[0]] == 0) && (nPointLayers[e[1]] == 0))
01098             {
01099                 meshEdgeLayers[meshEdgeI] = 0;
01100             }
01101             else
01102             {
01103                 const labelList& eFaces = pp.edgeFaces()[edgeI];
01104 
01105                 forAll(eFaces, i)
01106                 {
01107                     meshEdgeLayers[meshEdgeI] = max
01108                     (
01109                         nFaceLayers[eFaces[i]],
01110                         meshEdgeLayers[meshEdgeI]
01111                     );
01112                 }
01113             }
01114         }
01115 
01116         syncTools::syncEdgeList
01117         (
01118             mesh_,
01119             meshEdgeLayers,
01120             maxEqOp<label>(),
01121             0,                  // initial value
01122             false               // no separation
01123         );
01124 
01125         forAll(meshEdges, edgeI)
01126         {
01127             edgeLayers[edgeI] = meshEdgeLayers[meshEdges[edgeI]];
01128         }
01129     }
01130 
01131 
01132     // Global indices engine
01133     const globalIndex globalFaces(mesh_.nFaces());
01134 
01135     // Get for all pp edgeFaces a unique faceID
01136     labelListList globalEdgeFaces
01137     (
01138          calcGlobalEdgeFaces
01139          (
01140             mesh_,
01141             globalFaces,
01142             pp,
01143             meshEdges
01144         )
01145     );
01146 
01147 
01148     // Mark off which edges have been extruded
01149     boolList doneEdge(pp.nEdges(), false);
01150 
01151 
01152     // Create faces. Per face walk connected edges and find string of edges
01153     // between the same two faces and extrude string into a single face.
01154     forAll(pp, patchFaceI)
01155     {
01156         const labelList& fEdges = faceEdges[patchFaceI];
01157 
01158         forAll(fEdges, fp)
01159         {
01160             // Get string of edges that needs to be extruded as a single face.
01161             // Returned as indices in fEdges.
01162             labelPair indexPair
01163             (
01164                 getEdgeString
01165                 (
01166                     pp,
01167                     globalEdgeFaces,
01168                     doneEdge,
01169                     patchFaceI,
01170                     globalFaces.toGlobal(pp.addressing()[patchFaceI])
01171                 )
01172             );
01173 
01174             //Pout<< "Found unextruded edges in edges:" << fEdges
01175             //    << " start:" << indexPair[0]
01176             //    << " end:" << indexPair[1]
01177             //    << endl;
01178 
01179             const label startFp = indexPair[0];
01180             const label endFp = indexPair[1];
01181 
01182             if (startFp != -1)
01183             {
01184                 // Extrude edges from indexPair[0] up to indexPair[1]
01185                 // (note indexPair = indices of edges. There is one more vertex
01186                 //  than edges)
01187                 const face& f = localFaces[patchFaceI];
01188 
01189                 labelList stringedVerts;
01190                 if (endFp >= startFp)
01191                 {
01192                     stringedVerts.setSize(endFp-startFp+2);
01193                 }
01194                 else
01195                 {
01196                     stringedVerts.setSize(endFp+f.size()-startFp+2);
01197                 }
01198 
01199                 label fp = startFp;
01200 
01201                 for (label i = 0; i < stringedVerts.size()-1; i++)
01202                 {
01203                     stringedVerts[i] = f[fp];
01204                     doneEdge[fEdges[fp]] = true;
01205                     fp = f.fcIndex(fp);
01206                 }
01207                 stringedVerts[stringedVerts.size()-1] = f[fp];
01208 
01209 
01210                 // Now stringedVerts contains the vertices in order of face f.
01211                 // This is consistent with the order if f becomes the owner cell
01212                 // and nbrFaceI the neighbour cell. Note that the cells get
01213                 // added in order of pp so we can just use face ordering and
01214                 // because we loop in incrementing order as well we will
01215                 // always have nbrFaceI > patchFaceI.
01216 
01217                 label startEdgeI = fEdges[startFp];
01218 
01219                 label meshEdgeI = meshEdges[startEdgeI];
01220 
01221                 label numEdgeSideFaces = edgeLayers[startEdgeI];
01222 
01223                 for (label i = 0; i < numEdgeSideFaces; i++)
01224                 {
01225                     label vEnd = stringedVerts[stringedVerts.size()-1];
01226                     label vStart = stringedVerts[0];
01227 
01228                     // calculate number of points making up a face
01229                     label newFp = 2*stringedVerts.size();
01230 
01231                     if (i == 0)
01232                     {
01233                         // layer 0 gets all the truncation of neighbouring
01234                         // faces with more layers.
01235                         if (addedPoints_[vEnd].size())
01236                         {
01237                             newFp += 
01238                                 addedPoints_[vEnd].size() - numEdgeSideFaces;
01239                         }
01240                         if (addedPoints_[vStart].size())
01241                         {
01242                             newFp +=
01243                                 addedPoints_[vStart].size() - numEdgeSideFaces;
01244                         }
01245                     }
01246 
01247                     face newFace(newFp);
01248 
01249                     newFp = 0;
01250 
01251                     // For layer 0 get pp points, for all other layers get
01252                     // points of layer-1.
01253                     if (i == 0)
01254                     {
01255                         forAll(stringedVerts, stringedI)
01256                         {
01257                             label v = stringedVerts[stringedI];
01258                             addVertex(meshPoints[v], newFace, newFp);
01259                         }
01260                     }
01261                     else
01262                     {
01263                         forAll(stringedVerts, stringedI)
01264                         {
01265                             label v = stringedVerts[stringedI];
01266                             if (addedPoints_[v].size())
01267                             {
01268                                 label offset =
01269                                     addedPoints_[v].size() - numEdgeSideFaces;
01270                                 addVertex
01271                                 (
01272                                     addedPoints_[v][i+offset-1],
01273                                     newFace,
01274                                     newFp
01275                                 );
01276                             }
01277                             else
01278                             {
01279                                 addVertex(meshPoints[v], newFace, newFp);
01280                             }
01281                         }
01282                     }
01283 
01284                     // add points between stringed vertices (end)
01285                     if (numEdgeSideFaces < addedPoints_[vEnd].size())
01286                     {
01287                         if (i == 0 && addedPoints_[vEnd].size())
01288                         {
01289                             label offset =
01290                                 addedPoints_[vEnd].size() - numEdgeSideFaces;
01291                             for (label ioff = 0; ioff < offset; ioff++)
01292                             {
01293                                 addVertex
01294                                 (
01295                                     addedPoints_[vEnd][ioff],
01296                                     newFace,
01297                                     newFp
01298                                 );
01299                             }
01300                         }
01301                     }
01302 
01303                     forAllReverse(stringedVerts, stringedI)
01304                     {
01305                         label v = stringedVerts[stringedI];
01306                         if (addedPoints_[v].size())
01307                         {
01308                             label offset =
01309                                 addedPoints_[v].size() - numEdgeSideFaces;
01310                             addVertex
01311                             (
01312                                 addedPoints_[v][i+offset],
01313                                 newFace,
01314                                 newFp
01315                             );
01316                         }
01317                         else
01318                         {
01319                             addVertex(meshPoints[v], newFace, newFp);
01320                         }
01321                     }
01322 
01323 
01324                     // add points between stringed vertices (start)
01325                     if (numEdgeSideFaces < addedPoints_[vStart].size())
01326                     {
01327                         if (i == 0 && addedPoints_[vStart].size())
01328                         {
01329                             label offset =
01330                                 addedPoints_[vStart].size() - numEdgeSideFaces;
01331                             for (label ioff = offset; ioff > 0; ioff--)
01332                             {
01333                                 addVertex
01334                                 (
01335                                     addedPoints_[vStart][ioff-1],
01336                                     newFace,
01337                                     newFp
01338                                 );
01339                             }
01340                         }
01341                     }
01342 
01343                     if (newFp >= 3)
01344                     {
01345                         // Add face inbetween faces patchFaceI and nbrFaceI
01346                         // (possibly -1 for external edges)
01347 
01348                         newFace.setSize(newFp);
01349 
01350                         label nbrFaceI = nbrFace
01351                         (
01352                             pp.edgeFaces(),
01353                             startEdgeI,
01354                             patchFaceI
01355                         );
01356 
01357                         const labelList& meshFaces = mesh_.edgeFaces
01358                         (
01359                             meshEdgeI,
01360                             ef
01361                         );
01362 
01363                         addSideFace
01364                         (
01365                             pp,
01366                             patchID,
01367                             addedCells,
01368                             newFace,
01369                             patchFaceI,
01370                             nbrFaceI,
01371                             startEdgeI,     // edge to inflate from
01372                             meshEdgeI,      // corresponding mesh edge
01373                             i,
01374                             numEdgeSideFaces,
01375                             meshFaces,
01376                             meshMod
01377                         );
01378                     }
01379                 }
01380             }
01381         }
01382     }
01383 }
01384 
01385 
01386 void Foam::addPatchCellLayer::updateMesh
01387 (
01388     const mapPolyMesh& morphMap,
01389     const labelList& faceMap,   // new to old patch faces
01390     const labelList& pointMap   // new to old patch points
01391 )
01392 {
01393     {
01394         labelListList newAddedPoints(pointMap.size());
01395 
01396         forAll(newAddedPoints, newPointI)
01397         {
01398             label oldPointI = pointMap[newPointI];
01399 
01400             const labelList& added = addedPoints_[oldPointI];
01401 
01402             labelList& newAdded = newAddedPoints[newPointI];
01403             newAdded.setSize(added.size());
01404             label newI = 0;
01405 
01406             forAll(added, i)
01407             {
01408                 label newPointI = morphMap.reversePointMap()[added[i]];
01409 
01410                 if (newPointI >= 0)
01411                 {
01412                     newAdded[newI++] = newPointI;
01413                 }
01414             }
01415             newAdded.setSize(newI);
01416         }
01417         addedPoints_.transfer(newAddedPoints);
01418     }
01419 
01420     {
01421         labelListList newLayerFaces(faceMap.size());
01422 
01423         forAll(newLayerFaces, newFaceI)
01424         {
01425             label oldFaceI = faceMap[newFaceI];
01426 
01427             const labelList& added = layerFaces_[oldFaceI];
01428 
01429             labelList& newAdded = newLayerFaces[newFaceI];
01430             newAdded.setSize(added.size());
01431             label newI = 0;
01432 
01433             forAll(added, i)
01434             {
01435                 label newFaceI = morphMap.reverseFaceMap()[added[i]];
01436 
01437                 if (newFaceI >= 0)
01438                 {
01439                     newAdded[newI++] = newFaceI;
01440                 }
01441             }
01442             newAdded.setSize(newI);
01443         }
01444         layerFaces_.transfer(newLayerFaces);
01445     }
01446 }
01447 
01448 
01449 Foam::labelList Foam::addPatchCellLayer::calcMeshEdges
01450 (
01451     const primitiveMesh& mesh,
01452     const indirectPrimitivePatch& pp
01453 )
01454 {
01455     labelList meshEdges(pp.nEdges());
01456 
01457     forAll(meshEdges, patchEdgeI)
01458     {
01459         const edge& e = pp.edges()[patchEdgeI];
01460 
01461         label v0 = pp.meshPoints()[e[0]];
01462         label v1 = pp.meshPoints()[e[1]];
01463         meshEdges[patchEdgeI] = meshTools::findEdge
01464         (
01465             mesh.edges(),
01466             mesh.pointEdges()[v0],
01467             v0,
01468             v1
01469         );
01470     }
01471     return meshEdges;
01472 }
01473 
01474 
01475 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd