CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   icoDyMFoam - sclar transport with adaptive mesh refinement (

makaveli_lcf May 28, 2011 18:41

icoDyMFoam - sclar transport with adaptive mesh refinement
Please check,
here I submitted a small example (todays between-coffees-made solver)
how to use dynamicRefineFvMesh class in generic applications.

Thanks to developers for such hard work) Your years of designing - our "one click" lines in solver))) Thanks once more!

FlinkFingerFlo. July 3, 2011 15:21

Hi makaveli_lcf,
hi foamers,

based on your example and Anne Kösters example I try to build a solver using the residuum to refine the mesh... but I can't get it running :confused:


yhaomin2007 July 17, 2013 15:05

I read your solver code, it seems that after mesh.update, you directly goes into U equation and p equation. I also tried this on my solver for steady state.
There is error information like this :

field does not correspond to level 0 sizes: field = 115185 level = 112000

I looked into the mesh, it seems mesh.update refined the mesh, but when it goes to solve equations, there is an inconsistent. Do you think if there is any additional setting I should do?~

thank you.

makaveli_lcf July 17, 2013 18:25

there already some standard solvers in OF 2.2.1, please check them, they are more consistent than mine)))

yhaomin2007 July 17, 2013 21:28

Hi, Alex
I think I found out the problem, I should "cacheAgglomeration off;" in fvSolutions file.
But I met a another problem, when it dynamic refine the mesh, it always produce some triangle cells. This also happens in your example case.
I have seen some papers talking about adaptive mesh refinement in OpenFOAM, they can make every cell hexagon. Do you know how to do that in settings?
thank you in advance~

makaveli_lcf July 18, 2013 02:25


first you are totally right about aglomeration caching:

1. it should be switched off when doing dynamic refinement
2. no triangles are produced! it is just a postprocessing issue in paraview. Switch on "Use VTKPolyhedron" in Object Inspector. It is because your refined hex becomes a polyhedron, despite it looks still like a hex)))) In paraview it is splitted into pyramids giving you triangles. Please check here in Galery my first animation, it is done "properly")))
3. There was some issues (I think I was using OF 1.7) with tet cells: poly cells were excluded from refinement, but tet cells were not! I just patch dynamicRefine lib a little bit to avoid that, bevcause by engeneering geometries has sometimes tet cells... But all in all dynamic refinement is doing actually pure hex refinement


yhaomin2007 July 18, 2013 10:24

Hi, Alex,

thank you for your reply. I think you are right, OpenFOAM did not split those cells. It is just problem of paraview. But I have another question, in my research there is some pentahedral cells. Because I am simulating a axisymmetric geometry. Is there a way to tell OpenFOAM to just refine those hexagon cells, and ignore those pentahedral cells?

thank you.

makaveli_lcf July 18, 2013 10:34

I think it is already there... It is refining hex only... Look at the dynamicRefineFvMesh.C:


00951    // Set cells that should not be refined.
00952    // This is currently any cell which does not have 8 anchor points or
00953    // uses any face which does not have 4 anchor points.
00954    // Note: do not use cellPoint addressing
00956    // Count number of points <= cellLevel
00957    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00959    labelList nAnchors(nCells(), 0);
00961    label nProtected = 0;
00963    forAll(pointCells(), pointI)
00964    {
00965        const labelList& pCells = pointCells()[pointI];
00967        forAll(pCells, i)
00968        {
00969            label cellI = pCells[i];
00971            if (!protectedCell_.get(cellI))
00972            {
00973                if (pointLevel[pointI] <= cellLevel[cellI])
00974                {
00975                    nAnchors[cellI]++;
00977                    if (nAnchors[cellI] > 8)
00978                    {
00979                        protectedCell_.set(cellI, 1);
00980                        nProtected++;
00981                    }
00982                }
00983            }
00984        }
00985    }

Here they check for none hex cells...

yhaomin2007 July 18, 2013 10:49

Yes, you are right, it checked whether the anchor points of this cell. But it only protected the cell whose anchor point number is larger than 8. It will not protect those cells with less than 8 anchor points.

For my case, there are pentahedral cells. The error message is this:


cell 5129 of level 0 does not seem to have 8 points of equal or lower level
cellPoints:6(12234 12235 13288 13289 12284 12285)

From function hexRef8::setRefinement(const labelList&, polyTopoChange&)
in file polyTopoChange/polyTopoChange/hexRef8.C at line 3527.

FOAM aborting
I think I should change
if (nAnchors[cellI] > 8) to if( (nAnchors[cellI] > 8)||(nAnchors[cellI] < 8))
to make sure it only refine those hexagon cells.

makaveli_lcf July 18, 2013 10:50

Yep! Right direction! Just build a new library for dynamicMeshRefine

makaveli_lcf July 18, 2013 10:51

For tet it didn't work as well, so I modified that condition

yhaomin2007 July 18, 2013 10:53

I will try this.
Thank you very much~

yhaomin2007 July 18, 2013 15:21

I think I have figured out how to do that, I will post my code here if other people are interested. We have to judge whether this cell is hex or not. But we cannot just
change "if (nAnchors[cellI] > 8)" to "if( (nAnchors[cellI] > 8)||(nAnchors[cellI] < 8))"

because the anchor number of this cell (nAnchors) is not completely calculated after this whole loop. So we have make a judgement after this loop.

// Set cells that should not be refined.
// This is currently any cell which does not have 8 anchor points or
// uses any face which does not have 4 anchor points.
// Note: do not use cellPoint addressing

// Count number of points <= cellLevel
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

labelList nAnchors(nCells(), 0);

label nProtected = 0;

forAll(pointCells(), pointI)
const labelList& pCells = pointCells()[pointI];

forAll(pCells, i)
label cellI = pCells[i];

if (!protectedCell_.get(cellI))
if (pointLevel[pointI] <= cellLevel[cellI]) l

//if (nAnchors[cellI] > 8)
// protectedCell_.set(cellI, 1);
// nProtected++;

for(label cellI = 0; cellI < nCells() ; cellI++) // after nAnchors[cellI] is complete caculated, determine whether it should be protect or not. Only hex cells are not protected.
if ((nAnchors[cellI] > 8)||(nAnchors[cellI] < 8))
protectedCell_.set(cellI, 1);
Now, only hex cells are not protected, other non-hex cell are all in protection, and will not cause fatal error.
I hope this will be useful to somebody.

makaveli_lcf July 19, 2013 11:38

Great job, this issue was also there, I can remember!

All times are GMT -4. The time now is 17:13.