CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   addPatchCellLayer (https://www.cfd-online.com/Forums/openfoam/75705-addpatchcelllayer.html)

nikwin May 3, 2010 12:13

addPatchCellLayer
 
Hi,

I would like to add a cell layer on a wall patch of a pipe to be able to calculate the gradient over the original patch faces.

To add a cell layer it seems that the addPatchCellLayer class should be able to do it for me, but I don't understand how to obtain the arguments for the setRefinement function?

Thanks
/NW

nikwin May 14, 2010 06:37

Copy and paste from autoLayerDriver.C did it.
/NW

deepsterblue December 14, 2010 15:49

Niklas,
Did you add a cell-layer towards the interior of the domain (fluid)? Or was it an addition outside the mesh? Could you post your code, if that's possible... It would be really helpful.

Thanks

nikwin December 15, 2010 12:12

Hi,

I just added a cell layer as an addition to the mesh to be able to compute derivatives of a field on the "old" boundaries. Adding the code below but as I wrote it's just a copy and paste from the doxygen manual.

All the Best
/NW

int main(int argc, char *argv[])
{

# include "setRootCase.H"
# include "createTime.H"
# include "createMesh.H"

//////////////////////////////////////////////
// AddCellLayer
//////////////////////////////////////////////

addPatchCellLayer addLayer(mesh);
label nLayers=1;
polyTopoChange meshMod(mesh);

const polyBoundaryMesh& patches = mesh.boundaryMesh();

// Count faces.
label nFaces = 0;

nFaces = patches[0].size();
// Collect faces.
labelList addressing(nFaces);
nFaces = 0;

const polyPatch& pp = patches[0];

label meshFaceI = pp.start();

forAll(pp, i)
{
addressing[nFaces++] = meshFaceI++;
}
indirectPrimitivePatch ipp(IndirectList<face>(mesh.faces(), addressing),mesh.points());

// scalar thickness = 1e-4;
scalar thickness = 3e-4;

vectorField faceNormals = pp.faceNormals();
pointField patchDispl(pp.nPoints(), vector::zero);

pointField pointNormals(pp.pointNormals()); // Determine pointNormal

// Start off from same thickness everywhere (except where no extrusion)
patchDispl = thickness*pointNormals;

// Add topo regardless of whether extrudeStatus is extruderemove.
// Not add layer if patchDisp is zero.

addLayer.setRefinement(nLayers,ipp,patchDispl,mesh Mod);

// With the stored topo changes we create a new mesh so we can
// undo if neccesary.

autoPtr<fvMesh> meshPtr;
autoPtr<mapPolyMesh> map = meshMod.makeMesh
(
meshPtr,
IOobject
(
mesh.name(),
static_cast<polyMesh&>(mesh).instance(),
mesh.thisDb(),
static_cast<polyMesh&>(mesh).readOpt(),
static_cast<polyMesh&>(mesh).writeOpt()
), // io params from original mesh but new name
mesh, // original mesh
true // parallel sync
);

// Update numbering on addLayer:
// - cell/point labels to be newMesh.
// - patchFaces to remain in oldMesh order.
addLayer.updateMesh
(
map,
identity(pp.size()),
identity(pp.nPoints())
);

mesh.write();

runTime.write();

Info<< "END" << endl;
return(0);
}

deepsterblue December 15, 2010 13:00

Thanks a ton for the code, Niklas.

Just in case someone's looking for a simple solution, here's the alternative:

0. Backup the original mesh.

1. Call extrudeMesh using the following settings for extrudeProperties:

Code:


FoamFile
{
    version    2.0;
    format      ascii;
    class      dictionary;
    object      extrudeProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    // Where to get surface from: either from surface ('surface') or
    // from (flipped) patch of existing case ('patch')
    constructFrom patch;

    // If construct from (flipped) patch
    sourceCase "$FOAM_RUN/myCase";
    sourcePatch myPatchName;

    // Flip surface normals before usage.
    flipNormals false;

    // Do front and back need to be merged? Usually only makes sense for 360
    // degree wedges.
    mergeFaces false;

    //- Linear extrusion in point-normal direction
    extrudeModel        linearNormal;

    nLayers 1;

    linearNormalCoeffs
    {
        thickness      0.05;
    }

2. Copy the extrudeMesh result to a new case.

3. Use mergeMeshes with the original and new cases.

4. Use stitchMesh with the -perfect flag.


All times are GMT -4. The time now is 03:19.