Friday, July 10, 2015

How to automate renaming of STL patches without Salome using only OpenFOAM surface utilities and a script

This describes how to automate naming of patches of the stl file without using Salome or other software but with native OpenFOAM tools and a bash script. This is for use with cfMesh but a similar approach could be used with snappyHexMesh.

Allmesh Script

#!/bin/sh
cd ${0%/*} || exit 1    # run from this directory

# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions


rm log.*
rm -r input
rm -r output
mkdir input
mkdir output

# split stl into inlet and walls
runApplication surfaceSubset system/surfaceSubsetDictInlet constant/triSurface/input.stl input/inlet.stl

mv log.surfaceSubset log.surfaceSubsetInlet

runApplication surfaceSubset system/surfaceSubsetDictRInlet constant/triSurface/input.stl input/walls.stl

mv log.surfaceSubset log.surfaceSubsetInletR

# split walls into outlet and walls
runApplication surfaceSubset system/surfaceSubsetDictOutlet input/walls.stl input/outlet.stl

mv log.surfaceSubset log.surfaceSubsetInletROutlet

runApplication surfaceSubset system/surfaceSubsetDictROutlet input/walls.stl input/walls.stl

mv log.surfaceSubset log.surfaceSubsetInletROutletR

# combine files
../../scripts/./stlCombine input output

#generate fms file with edges but retaining patches
runApplication surfaceFeatureEdges output/mergedStl.stl output/elbow.fms -angle 45

#generate mesh
runApplication cartesianMesh

#change definitions of patches
runApplication changeDictionary

surfaceSubsetDictInlet file

/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.4.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      surfaceSubsetDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

// Select triangles by label
faces ();//#include "badFaces";

// Select triangles using given points (local point numbering)
localPoints ( );

// Select triangles using given edges
edges ();

// Select triangles (with face centre) inside box
zone
(
    (.507  .25  -.101)
    (.509 .36 .101)
);

// Select triangles (with face centre) inside or outside of another surface.
// (always selects triangles that are 'on' other surface)
/*
surface
{
    name "sphere.stl";
    outside     yes;
}

// Select triangles on plane
plane
{
    planeType embeddedPoints;
    embeddedPointsDict
    {
        //point1 (-937.259845440205 160.865349115986 240.738791238078);
        //point2 (-934.767379895778 9.63875523747379 14.412359671298);
        //point3 (44.4744688899417 121.852927962709 182.352485273106);
        point1 (-957.895294591874 242.865936478961 162.286611511875);
        point2 (-961.43140327772 4.53895551562943 3.04159982093444);
        point3 (91.2414146173805 72.1504381996692 48.2181961945329);
    }

    // Distance from plane
    distance 0.1;
    // Normal difference to plane
    cosAngle 0.99;
}
*/

// Extend selection with edge neighbours
addFaceNeighbours no;

// Invert selection
invertSelection false;

// ************************************************************************* //

surfaceSubsetDictInletR  change  invertSelection true;

surfaceSubsetDictOutlet  change coordinates of 

box;surfaceSubsetDictOutletR  change  invertSelection true;


stlCombine code from Kruno at

https://openfoamwiki.net/index.php/Thread:Talk:Sig_Numerical_Optimization/Salome_and_cfMesh_parametrization

meshDict for cfMesh


/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                |
| \\      /  F ield         | cfMesh: A library for mesh generation          |
|  \\    /   O peration     |                                                |
|   \\  /    A nd           | Author: Franjo Juretic                         |
|    \\/     M anipulation  | E-mail: franjo.juretic@c-fields.com            |
\*---------------------------------------------------------------------------*/

FoamFile
{
    version   2.0;
    format    ascii;
    class     dictionary;
    location  "system";
    object    meshDict;
}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

surfaceFile "output/elbow.fms";

maxCellSize .05;

boundaryCellSize .0049;

minCellSize .0049;

localRefinement
{
    walls
    {
        cellSize 0.0025;
    }
}


boundaryLayers
{
    nLayers 1;

    thicknessRatio 1.1;

    maxFirstLayerThickness 0.003;

    patchBoundaryLayers
    {
      "walls.*"
        {
            nLayers           3;

            thicknessRatio    1.2;

            maxFirstLayerThickness .005;

            allowDiscontinuity 0;
        }

    }
}



/*
renameBoundary
{
    defaultName        junk;
    defaultType        wall;

    newPatchNames
    {
        "inl.*"
        {
            newName     testo;
            newType     patch;
        }

    }
}*/
              
    
// ************************************************************************* //


changeDictionaryDict


/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  2.3.0                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      changeDictionaryDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dictionaryReplacement
{
    boundary
    {
        "inlet"
        {
            type            patch;
        }
        "outlet"
        {
            type            patch;
        }
        "walls"
        {
                name                 walls;
            type            wall;
          
        }
    }

}

// ************************************************************************* //

No comments:

Post a Comment