From 4f85f763091367b0a1f7ddb5a526ebe5e8cf1fea Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 19 Aug 2009 15:23:24 +0100 Subject: [PATCH] allow stand-alone extrusion --- .../polyTopoChange/addPatchCellLayer.C | 215 ++++++++++++++---- .../polyTopoChange/addPatchCellLayer.H | 8 +- 2 files changed, 171 insertions(+), 52 deletions(-) diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/addPatchCellLayer.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/addPatchCellLayer.C index 2f842e6d66..c3b104134c 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/addPatchCellLayer.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/addPatchCellLayer.C @@ -335,17 +335,19 @@ Foam::label Foam::addPatchCellLayer::addSideFace label inflateEdgeI = -1; // Check mesh faces using edge - forAll(meshFaces, i) + if (addToMesh_) { - if (mesh_.isInternalFace(meshFaces[i])) + forAll(meshFaces, i) { - // meshEdge uses internal faces so ok to inflate from it - inflateEdgeI = meshEdgeI; - break; + if (mesh_.isInternalFace(meshFaces[i])) + { + // meshEdge uses internal faces so ok to inflate from it + inflateEdgeI = meshEdgeI; + break; + } } } - // Get my mesh face and its zone. label meshFaceI = pp.addressing()[ownFaceI]; label zoneI = mesh_.faceZones().whichZone(meshFaceI); @@ -504,9 +506,14 @@ Foam::label Foam::addPatchCellLayer::addSideFace // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // Construct from mesh -Foam::addPatchCellLayer::addPatchCellLayer(const polyMesh& mesh) +Foam::addPatchCellLayer::addPatchCellLayer +( + const polyMesh& mesh, + const bool addToMesh +) : mesh_(mesh), + addToMesh_(addToMesh), addedPoints_(0), layerFaces_(0) {} @@ -827,6 +834,19 @@ void Foam::addPatchCellLayer::setRefinement } + const polyBoundaryMesh& patches = mesh_.boundaryMesh(); + + // Precalculated patchID for each patch face + labelList patchID(pp.size()); + + forAll(pp, patchFaceI) + { + label meshFaceI = pp.addressing()[patchFaceI]; + + patchID[patchFaceI] = patches.whichPatch(meshFaceI); + } + + // From master point (in patch point label) to added points (in mesh point // label) addedPoints_.setSize(pp.nPoints()); @@ -857,6 +877,33 @@ void Foam::addPatchCellLayer::setRefinement // Create new points // + // If creating new mesh: copy existing patch points + labelList copiedPatchPoints; + if (!addToMesh_) + { + copiedPatchPoints.setSize(firstLayerDisp.size()); + forAll(firstLayerDisp, patchPointI) + { + if (addedPoints_[patchPointI].size()) + { + label meshPointI = meshPoints[patchPointI]; + label zoneI = mesh_.pointZones().whichZone(meshPointI); + copiedPatchPoints[patchPointI] = meshMod.setAction + ( + polyAddPoint + ( + mesh_.points()[meshPointI], // point + -1, // master point + zoneI, // zone for point + true // supports a cell + ) + ); + } + } + } + + + // Create points for additional layers forAll(firstLayerDisp, patchPointI) { if (addedPoints_[patchPointI].size()) @@ -878,7 +925,7 @@ void Foam::addPatchCellLayer::setRefinement polyAddPoint ( pt, // point - meshPointI, // master point + (addToMesh_ ? meshPointI : -1), // master point zoneI, // zone for point true // supports a cell ) @@ -922,7 +969,7 @@ void Foam::addPatchCellLayer::setRefinement -1, // master point -1, // master edge -1, // master face - mesh_.faceOwner()[meshFaceI], // master cell id + (addToMesh_ ? mesh_.faceOwner()[meshFaceI] : -1),//master ownZoneI // zone for cell ) ); @@ -930,26 +977,12 @@ void Foam::addPatchCellLayer::setRefinement //Pout<< "For patchFace:" << patchFaceI // << " meshFace:" << pp.addressing()[patchFaceI] // << " layer:" << i << " added cell:" - // << addedCells[patchFaceI][i] - // << endl; + // << addedCells[patchFaceI][i] << endl; } } } - const polyBoundaryMesh& patches = mesh_.boundaryMesh(); - - // Precalculated patchID for each patch face - labelList patchID(pp.size()); - - forAll(pp, patchFaceI) - { - label meshFaceI = pp.addressing()[patchFaceI]; - - patchID[patchFaceI] = patches.whichPatch(meshFaceI); - } - - // Create faces on top of the original patch faces. // These faces are created from original patch faces outwards so in order @@ -981,7 +1014,12 @@ void Foam::addPatchCellLayer::setRefinement if (addedPoints_[f[fp]].empty()) { // Keep original point - newFace[fp] = meshPoints[f[fp]]; + newFace[fp] = + ( + addToMesh_ + ? meshPoints[f[fp]] + : copiedPatchPoints[f[fp]] + ); } else { @@ -1040,35 +1078,85 @@ void Foam::addPatchCellLayer::setRefinement // // Modify old patch faces to be on the inside // - forAll(pp, patchFaceI) + + labelList copiedPatchFaces; + if (addToMesh_) { - if (addedCells[patchFaceI].size()) + forAll(pp, patchFaceI) { - label meshFaceI = pp.addressing()[patchFaceI]; + if (addedCells[patchFaceI].size()) + { + label meshFaceI = pp.addressing()[patchFaceI]; - label zoneI = mesh_.faceZones().whichZone(meshFaceI); + label zoneI = mesh_.faceZones().whichZone(meshFaceI); - meshMod.setAction - ( - polyModifyFace + meshMod.setAction ( - pp[patchFaceI], // modified face - meshFaceI, // label of face - mesh_.faceOwner()[meshFaceI], // owner - addedCells[patchFaceI][0], // neighbour - false, // face flip - -1, // patch for face - false, // remove from zone - zoneI, // zone for face - false // face flip in zone - ) - ); - //Pout<< "Modified old patch face " << meshFaceI - // << " own:" << mesh_.faceOwner()[meshFaceI] - // << " nei:" << addedCells[patchFaceI][0] - // << endl; + polyModifyFace + ( + pp[patchFaceI], // modified face + meshFaceI, // label of face + mesh_.faceOwner()[meshFaceI], // owner + addedCells[patchFaceI][0], // neighbour + false, // face flip + -1, // patch for face + false, // remove from zone + zoneI, // zone for face + false // face flip in zone + ) + ); + //Pout<< "Modified old patch face " << meshFaceI + // << " own:" << mesh_.faceOwner()[meshFaceI] + // << " nei:" << addedCells[patchFaceI][0] + // << endl; + } } } + else + { + // If creating new mesh: copy existing patch points + copiedPatchFaces.setSize(pp.size()); + forAll(pp, patchFaceI) + { + if (nFaceLayers[patchFaceI] > 0) + { + label meshFaceI = pp.addressing()[patchFaceI]; + label zoneI = mesh_.faceZones().whichZone(meshFaceI); + bool zoneFlip = false; + if (zoneI != -1) + { + const faceZone& fz = mesh_.faceZones()[zoneI]; + zoneFlip = !fz.flipMap()[fz.whichFace(meshFaceI)]; + } + + // Reverse and renumber old patch face. + face f(pp.localFaces()[patchFaceI].reverseFace()); + forAll(f, fp) + { + f[fp] = copiedPatchPoints[f[fp]]; + } + + copiedPatchFaces[patchFaceI] = meshMod.setAction + ( + polyAddFace + ( + f, // modified face + addedCells[patchFaceI][0], // owner + -1, // neighbour + -1, // masterPoint + -1, // masterEdge + -1, // masterFace + true, // face flip + patchID[patchFaceI], // patch for face + zoneI, // zone for face + zoneFlip // face flip in zone + ) + ); + } + } + } + + // @@ -1255,7 +1343,16 @@ void Foam::addPatchCellLayer::setRefinement forAll(stringedVerts, stringedI) { label v = stringedVerts[stringedI]; - addVertex(meshPoints[v], newFace, newFp); + addVertex + ( + ( + addToMesh_ + ? meshPoints[v] + : copiedPatchPoints[v] + ), + newFace, + newFp + ); } } else @@ -1276,7 +1373,16 @@ void Foam::addPatchCellLayer::setRefinement } else { - addVertex(meshPoints[v], newFace, newFp); + addVertex + ( + ( + addToMesh_ + ? meshPoints[v] + : copiedPatchPoints[v] + ), + newFace, + newFp + ); } } } @@ -1316,7 +1422,16 @@ void Foam::addPatchCellLayer::setRefinement } else { - addVertex(meshPoints[v], newFace, newFp); + addVertex + ( + ( + addToMesh_ + ? meshPoints[v] + : copiedPatchPoints[v] + ), + newFace, + newFp + ); } } diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/addPatchCellLayer.H b/src/dynamicMesh/polyTopoChange/polyTopoChange/addPatchCellLayer.H index f03d23e214..f950ca2619 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/addPatchCellLayer.H +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/addPatchCellLayer.H @@ -26,7 +26,8 @@ Class Foam::addPatchCellLayer Description - Adds layers of cells to outside of polyPatch. + Adds layers of cells to outside of polyPatch. Can optionally create + stand-alone extruded mesh (addToMesh=false). Call setRefinement with offset vector for every patch point and number of layers per patch face and number of layers per patch point. @@ -164,6 +165,9 @@ class addPatchCellLayer //- Reference to mesh const polyMesh& mesh_; + //- Add layers to existing mesh or create new mesh + const bool addToMesh_; + //- For all patchpoints: list of added points (size 0 or nLayers) // First point in list is one nearest to original point in patch, // last one is the new point on the surface. @@ -253,7 +257,7 @@ public: // Constructors //- Construct from mesh. - addPatchCellLayer(const polyMesh& mesh); + addPatchCellLayer(const polyMesh& mesh, const bool addToMesh = true); // Member Functions