From e6cdada5d6e336755f0559c6cd233d2b5509f36d Mon Sep 17 00:00:00 2001 From: mattijs <mattijs@hunt.opencfd.co.uk> Date: Thu, 9 Jul 2009 16:01:36 +0100 Subject: [PATCH] correct extrudeMesh --- .../mesh/generation/extrudeMesh/extrudeMesh.C | 26 +++++-- .../extrudeModel/linearNormal/linearNormal.C | 9 ++- .../generation/extrudeMesh/extrudeProperties | 21 ++++-- .../extrudeMesh/extrudedMesh/extrudedMesh.C | 72 ++++++++++++------- 4 files changed, 90 insertions(+), 38 deletions(-) diff --git a/applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C b/applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C index 69dc36bccf8..7380562664f 100644 --- a/applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C +++ b/applications/utilities/mesh/generation/extrudeMesh/extrudeMesh.C @@ -23,8 +23,9 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Description - Extrude mesh from existing patch (flipped so has inwards pointing - normals) or from patch read from file. + Extrude mesh from existing patch (by default outwards facing normals; + optional flips faces) + or from patch read from file. Note: Merges close points so be careful. Type of extrusion prescribed by run-time selectable model. @@ -108,14 +109,11 @@ int main(int argc, char *argv[]) const polyPatch& pp = mesh.boundaryMesh()[patchID]; fMesh.reset(new faceMesh(pp.localFaces(), pp.localPoints())); - fMesh().flip(); { - fileName surfName(patchName + ".sMesh"); - - Info<< "Writing (flipped) patch as surfaceMesh to " + fileName surfName(runTime.path()/patchName + ".sMesh"); + Info<< "Writing patch as surfaceMesh to " << surfName << nl << endl; - OFstream os(surfName); os << fMesh() << nl; } @@ -142,6 +140,20 @@ int main(int argc, char *argv[]) << "patch or surface." << exit(FatalError); } + Switch flipNormals(dict.lookup("flipNormals")); + + if (flipNormals) + { + Info<< "Flipping faces." << nl << endl; + + faceList faces(fMesh().size()); + forAll(faces, i) + { + faces[i] = fMesh()[i].reverseFace(); + } + fMesh.reset(new faceMesh(faces, fMesh().localPoints())); + } + Info<< "Extruding patch with :" << nl << " points : " << fMesh().points().size() << nl diff --git a/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/linearNormal/linearNormal.C b/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/linearNormal/linearNormal.C index 99c02d214fa..c36098ab1e6 100644 --- a/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/linearNormal/linearNormal.C +++ b/applications/utilities/mesh/generation/extrudeMesh/extrudeModel/linearNormal/linearNormal.C @@ -47,7 +47,14 @@ linearNormal::linearNormal(const dictionary& dict) : extrudeModel(typeName, dict), thickness_(readScalar(coeffDict_.lookup("thickness"))) -{} +{ + if (thickness_ <= 0) + { + FatalErrorIn("linearNormal(const dictionary&)") + << "thickness should be positive : " << thickness_ + << exit(FatalError); + } +} // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // diff --git a/applications/utilities/mesh/generation/extrudeMesh/extrudeProperties b/applications/utilities/mesh/generation/extrudeMesh/extrudeProperties index 20de7b21524..8bf73c4bf2c 100644 --- a/applications/utilities/mesh/generation/extrudeMesh/extrudeProperties +++ b/applications/utilities/mesh/generation/extrudeMesh/extrudeProperties @@ -19,31 +19,40 @@ FoamFile constructFrom patch; //surface; // If construct from (flipped) patch -sourceCase "../cavity"; +sourceCase "$FOAM_RUN/icoFoam/cavity"; sourcePatch movingWall; +// Flip surface normals before usage. +flipNormals false; + // If construct from surface surface "movingWall.sMesh"; -// Do front and back need to be merged? -mergeFaces false; +// Do front and back need to be merged? Usually only makes sense for 360 +// degree wedges. +mergeFaces true; + //- Linear extrusion in point-normal direction //extrudeModel linearNormal; + //- Wedge extrusion. If nLayers is 1 assumes symmetry around plane. extrudeModel wedge; + //- Extrudes into sphere around (0 0 0) //extrudeModel linearRadial; + +//- Extrudes into sphere with grading according to pressure (atmospherics) //extrudeModel sigmaRadial; -nLayers 6; +nLayers 20; wedgeCoeffs { axisPt (0 0.1 0); - axis (1 0 0); - angle 90.0; // For nLayers=1 assume symmetry so angle/2 on each side + axis (-1 0 0); + angle 360; // For nLayers=1 assume symmetry so angle/2 on each side } linearNormalCoeffs diff --git a/applications/utilities/mesh/generation/extrudeMesh/extrudedMesh/extrudedMesh.C b/applications/utilities/mesh/generation/extrudeMesh/extrudedMesh/extrudedMesh.C index b258c594451..16bab41094a 100644 --- a/applications/utilities/mesh/generation/extrudeMesh/extrudedMesh/extrudedMesh.C +++ b/applications/utilities/mesh/generation/extrudeMesh/extrudedMesh/extrudedMesh.C @@ -109,15 +109,33 @@ Foam::Xfer<Foam::faceList> Foam::extrudedMesh::extrudedFaces label currentLayerOffset = layer*surfacePoints.size(); label nextLayerOffset = currentLayerOffset + surfacePoints.size(); - // Side faces from layer to layer+1 - for (label i=0; i<nInternalEdges; i++) + // Vertical faces from layer to layer+1 + for (label edgeI=0; edgeI<nInternalEdges; edgeI++) { - quad[0] = surfaceEdges[i][1] + currentLayerOffset; - quad[1] = surfaceEdges[i][0] + currentLayerOffset; - quad[2] = surfaceEdges[i][0] + nextLayerOffset; - quad[3] = surfaceEdges[i][1] + nextLayerOffset; + const edge& e = surfaceEdges[edgeI]; + const labelList& edgeFaces = extrudePatch.edgeFaces()[edgeI]; + + face& f = eFaces[facei++]; + f.setSize(4); - eFaces[facei++] = face(quad).reverseFace(); + if + ( + (edgeFaces[0] < edgeFaces[1]) + == sameOrder(surfaceFaces[edgeFaces[0]], e) + ) + { + f[0] = e[0] + currentLayerOffset; + f[1] = e[1] + currentLayerOffset; + f[2] = e[1] + nextLayerOffset; + f[3] = e[0] + nextLayerOffset; + } + else + { + f[0] = e[1] + currentLayerOffset; + f[1] = e[0] + currentLayerOffset; + f[2] = e[0] + nextLayerOffset; + f[3] = e[1] + nextLayerOffset; + } } // Faces between layer and layer+1 @@ -128,9 +146,9 @@ Foam::Xfer<Foam::faceList> Foam::extrudedMesh::extrudedFaces eFaces[facei++] = face ( - surfaceFaces[i].reverseFace() + surfaceFaces[i] //.reverseFace() + nextLayerOffset - ).reverseFace(); + ); } } } @@ -142,40 +160,46 @@ Foam::Xfer<Foam::faceList> Foam::extrudedMesh::extrudedFaces label nextLayerOffset = currentLayerOffset + surfacePoints.size(); // Side faces across layer - for (label i=nInternalEdges; i<surfaceEdges.size(); i++) + for (label edgeI=nInternalEdges; edgeI<surfaceEdges.size(); edgeI++) { - const edge& e = surfaceEdges[i]; - quad[0] = e[1] + currentLayerOffset; - quad[1] = e[0] + currentLayerOffset; - quad[2] = e[0] + nextLayerOffset; - quad[3] = e[1] + nextLayerOffset; + const edge& e = surfaceEdges[edgeI]; + const labelList& edgeFaces = extrudePatch.edgeFaces()[edgeI]; - label ownerFace = extrudePatch.edgeFaces()[i][0]; + face& f = eFaces[facei++]; + f.setSize(4); - if (sameOrder(surfaceFaces[ownerFace], e)) + if (sameOrder(surfaceFaces[edgeFaces[0]], e)) { - reverse(quad); + f[0] = e[0] + currentLayerOffset; + f[1] = e[1] + currentLayerOffset; + f[2] = e[1] + nextLayerOffset; + f[3] = e[0] + nextLayerOffset; + } + else + { + f[0] = e[1] + currentLayerOffset; + f[1] = e[0] + currentLayerOffset; + f[2] = e[0] + nextLayerOffset; + f[3] = e[1] + nextLayerOffset; } - - eFaces[facei++] = face(quad); } } - // Top faces + // Bottom faces forAll(surfaceFaces, i) { eFaces[facei++] = face(surfaceFaces[i]).reverseFace(); } - // Bottom faces + // Top faces forAll(surfaceFaces, i) { eFaces[facei++] = face ( - surfaceFaces[i].reverseFace() + surfaceFaces[i] + nLayers*surfacePoints.size() - ).reverseFace(); + ); } // return points for transferring -- GitLab