CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   dynamicRefineFvMesh - Protect cells from refinement (boundary) (https://www.cfd-online.com/Forums/openfoam-programming-development/234361-dynamicrefinefvmesh-protect-cells-refinement-boundary.html)

jairoandres March 3, 2021 18:04

dynamicRefineFvMesh - Protect cells from refinement (boundary)
 
Hello Forum

In my AMR case, I want to protect wall-cells from refinement. This basically because the y+ size is well defined there and because of other reasons (I have found issues in OpenFOAM 2012 and older versions when tracking a particle with a containing near-wall cell which is being refined / unrefined).

The protection of wall boundaries has to be done in dynamicRefineFvMesh.C, however, it has given me issues as mesh() is not defined there.

I can assign a SMALL value to the field used for refinement criteria in near-wall cells (already implemented in other thread), but dynamicRefineFvMesh does at least 1-buffer cell refinement, therefore, in many cases, the wall-cells get refined. I don't honestly want to remove the 1-buffer refinement as it would bring many issues. A possible solution would be extending this set value to neighbour cells, but it would hamper the solution accuracy in some regions, so protecting the cells seems a better solution.

I've tried something like this (among many other things) :

forAll(cells(), celli)
{
const cell& cFaces = cells()[celli];

// if (cFaces.nFaces() - cFaces.nInternalFaces() > 0)
if (cFaces.nFaces() - cFaces.nInternalFaces() > 0)
{
protectedCell_.set(celli);
}


}

but, of course, it does not work as nInternalFaces() is not defined for cells() (as nFaces is). I am running out of ideas. I would be very happy to receive feedback on this.

Naturally, using topoSet to selected all boundaryCells and then saving those to a protectedCells file does not work as the cell-protection decision is performed each refining step inside dynamicRefineFvMesh

Thank you for your support

clapointe March 3, 2021 19:25

What if you looped over patches and checked if they're walls? Something like :

Code:

    //Protect walls
    const fvMesh& mesh(*this);
    const fvPatchList& patches = mesh.boundary();
    forAll(patches, patchi)
    {
        if(isA<wallFvPatch>(patches[patchi]))
        {
            labelList faceCells = patches[patchi].faceCells();

            forAll(patches[patchi], facei)
            {
                label celli = faceCells[facei];
                protectedCell_.set(celli);
            }
        }
    }

Tested the above (make sure to include wallFvPatch.H) with the dam break tutorial and wall cells were not refined.

Caelan

jairoandres March 3, 2021 21:31

Dear Caelan, thank you very much, it worked just fine!. I was looking at the code because I expected OF to write the protected cells, but anyway, it does not matter. I owe you part of the last objective of my PhD thesis :).

I remember I tried something similar to what you posted, but my mistake was not defining the fvMesh& using "(*this)".

I suppose it is possible to include below "if(isA<wallFvPatch>(patches[patchi]))", a specific walll patch name (for example walls1, or walls2?), right?

By the way, nice github contributions.

Best regards from Bogota,

J.A. Gutiérrez.

Quote:

Originally Posted by clapointe (Post 797841)
What if you looped over patches and checked if they're walls? Something like :

Code:

    //Protect walls
    const fvMesh& mesh(*this);
    const fvPatchList& patches = mesh.boundary();
    forAll(patches, patchi)
    {
        if(isA<wallFvPatch>(patches[patchi]))
        {
            labelList faceCells = patches[patchi].faceCells();

            forAll(patches[patchi], facei)
            {
                label celli = faceCells[facei];
                protectedCell_.set(celli);
            }
        }
    }

Tested the above (make sure to include wallFvPatch.H) with the dam break tutorial and wall cells were not refined.

Caelan


clapointe March 3, 2021 21:51

I'm sure there's a nicer way to do it, but a quick hard code would be something like :

Code:

if (patches[patchi].name() == "wall1")
Given that the above comparison is hard coded, you could probably grab a list of patch names from dynamicMeshDict instead... if you went that route, you could do something like :

Code:

    //Protect some walls
    const fvMesh& mesh(*this);
    forAll(patchList, namei)
    {
        label patchLabel = mesh.boundaryMesh().findPatchID(patchList[namei]);
        const fvPatch& patch = mesh.boundary()[patchLabel];
                         
        forAll(patch,facei)
        {
            label celli = patch.faceCells()[facei];
            protectedCell_.set(celli);
        }
    }

Note that I've not tested the above code (and pieced it together from various snippets) -- you'd also need to create the wordList "patchList" somewhere. Good luck with the rest of your thesis!

Caelan

jairoandres March 6, 2021 12:57

Thank you again, I'm going to test it soon and let you know how it works.

benedip November 8, 2022 13:56

Hi,

I guess this only works for the first cell at the wall, right? I mean, it prevent just the first cell layer not to be refined right? Not the entire boundary layer mesh. The loop is done over the cells adjacent to the wall if I'm not wrong

Can you just confirm if so?
Regards
Benedetto

mAlletto November 8, 2022 14:48

One could use the wall distance field ( see the spalart allmaras model how to create it https://www.openfoam.com/documentati...s.html#details ) the shield the cells from refinement. Maybe this helps

Best

Michael


All times are GMT -4. The time now is 14:52.