CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   Adaptive refinement on multiphases (

AlGates August 17, 2009 03:11

Adaptive refinement on multiphases
Hi all!

I'm trying to integrate the adaptive mesh refinement on the multiphaseInterFoam or the other way round.

I started from interDyMFoam and integrated the multiphaseMixture package to be able to set more than one phase, but somehow the refinement doesn't work properly. Some mesh grids seem not to be updated so the solver ends with a "mesh does not correspond to level 0" blablabla. This is a message sent by the GAMG solver and I'm trying to find out why the mesh isn't getting always correctly updated.

Maybe some of you has some experience with this problem and tried before to integrate one into the other.


PS: I also tried other solvers and then you don't get that exit message, but it doesn't work as well, because the values in a cell become absolutely nonsense (alphaAir > 1.5, etc.).

pici July 28, 2013 05:14

Hi Alex,
I'm working in a sloshing problem that involves 3 different fluids, so I need to integrate
interDyMFoam and multiphaseInterFoam ; my need is different by yours because I need to rigidly move all tank containing 3 (or more) fluid.
I know that I'm late of 4 years, but I hope that you solved your problem and you can give me some suggestion about integration.
Thank you very much

AlGates July 28, 2013 13:27

Ciao Piero,

unfortunately, I didn't use OpenFOAM since my diploma thesis four years ago and can hardly remember what I did in the end.

I know, that I never solved the problem with the adaptive refinement. I think, I finally did all of my simulation just based on the multiPhaseInterFoam solver, which I extended to

our needs.

So I cannot really help you.

Buona fortuna


aot August 13, 2013 09:17

Hi Alex, hi Piero,

just set cacheAgglomeration off in the GAMG-solver. Then it should work.


mohsen_ba65 November 10, 2015 21:12

Hi aot,

I hope that you still visit this topic. Could you please help me with this problem. I want to use mesh refinement with multiphaseInterFoam. I started adding dynamicMeshDict to the constant folder, and from my understanding I need to include the dynamicFvMesh.H to multphaseInterFoam solver code and compile a new solver in this way. Please correct me.


aot November 13, 2015 04:32

Hi Mohsen,
the easiest way ist to take a look at interDyMFoam and interFoam and just do the same changes in multiphaseInterFoam. It's really easy.


Tobi November 16, 2015 09:36


what Andreas is mentioning,... you just have to add the dynamicFvMesh lib to the solver and derive the mesh creation out of that library. Thats all ;)
Of course do not forget to recalculate the fluxes due to mesh motion.

stephie December 18, 2015 04:19


at the moment I try to use an adaptive mesh at the phase boundray. In my case I use the interDyMFoam solver (OpenFoam 2.3.1). At the beginning I can see a refinement, but after some simulation seconds the refinement disappears and at the end of my simulation it appears again.
Is this also a problem of not updated cells?
Now I changed the cachAgglomeration to false. But I have also seen tutorials where this is true and it works. Do it depends on the solver? Or did I do an other mistake?

Maybe I did a mistake in the dynamicMeshDict - here are my parameters...

dynamicFvMesh dynamicRefineFvMesh;

// How often to refine
refineInterval 20;//1
// Field to be refinement on
field alpha.water;
// Refine field inbetween lower..upper
lowerRefineLevel 0.001;
upperRefineLevel 0.999;
// If value < unrefineLevel unrefine
unrefineLevel 10;
// Have slower than 2:1 refinement
nBufferLayers 1;
// Refine cells only up to maxRefinement levels
maxRefinement 500;//2
// Stop refinement if maxCells reached
maxCells 300000;
// Flux field and corresponding velocity field. Fluxes on changed
// faces get recalculated by interpolating the velocity. Use 'none'
// on surfaceScalarFields that do not need to be reinterpolated.
(phi none)
(nHatf none)
(rhoPhi none)
(ghf none)
// Write the refinement level as a volScalarField
dumpLevel true;

If anyone might help me, I would be very grateful.
Thank you so much and best regards,

Tobi December 18, 2015 04:23

Hi Stephie,

What Do you think is the keyword unrefineLevel stand for ;)

It has nothing to do with the solver settings in fvSolutions.

stephie December 18, 2015 04:26

Okay so I have to set it to a smaller number.

Thank you :)

Tobi December 18, 2015 04:30


yes. Just read it like: if alpha < unrefineLevel --> unrefine. So at least alpha is between [0-1] and therefore you should set it to a value inbetween, depending when you will unrefine the refined cells again.

Notice, that the interface is 0.5. You also (if you want to make a other refinement) can use my lib:

stephie December 18, 2015 05:28

thank you for this explanation. I set the unrefinelevel to 0.005 and it seems to work.
Can I ask you two other questions?
Why they use an unrefinementlevel of 10 in the tutorial damebreakWithObstacle?
My geometry contains a big cylinder and an straight inlet. The refinement at the inlet is consistent, but at the cylinder there are just some cells refined. Could it be, that the mesh is to rude? The cells are really big.

Your lib look very interesting. I will try to test it :)

Thank you for your help!

Tobi December 18, 2015 07:35

Hi Stephie,

Question 1: I don't know. Maybe this unrefine function is called at the beginning, then we refine and apply this to the topo of the mesh. If its like that, you delete every refinement each timestep and refine again after that functoin due to the new alpha field. But then the question would be, why is it not working in your case. To be sure and answer correctly, I should check the lib again, but I am not in the mud to do this (: -- sorry. Just do it yourself and you should get the point.

Question 2: The lib can only split hexaeders. If you have a cylinder (maybe created with snappyHexMesh) then the crazy cells at the surface can not be refined with the algorithm we are using here.

stephie March 9, 2016 11:49

Hello together,

up to now the refinment of alpha.water works well. But today I got a new task - I have to refine alpha.water AND the velocity gradient (all cell over 1.3 m/s have to be refined).
Has anyone experience in refining two fields? How can I implement this in the dynamicMeshDict?

I would be very gratefule for your help!

Thank you so much and best regards,

Tobi March 9, 2016 11:59

Hi stephi,

I did this and the lib is available here:

Instead of using twice alpha, you could use the magnitude of the velocity (scalar). The gradient of a velocity field will return a matrix. I think that is not what you want (:

stephie March 9, 2016 12:39

Hey :)

thank you so much!!!!! It looks amazing, that's what I am searching for.

This might be a stupid question, but I am not so familar with including new libarys into OpenFoam. How do I do this? I downloaded the zip file from bitbucket and now?

It would be fantastic if you might help me again.

best regards,

Bloerb March 9, 2016 16:38

If the lib is compiled simply copy it into your $FOAM_USER_LIBBIN directory
usually the place is something like this
If it is not yet compiled simply type wmake in the directory with the source code.

Once this is done you need to add it to your case.
for example in your controlDict


or this to your dynamicMeshDict for a meshmotionsolver

dynamicFvMeshLibs ( "" );

Tobi March 9, 2016 17:25

Please use wmake libso instead of wmake

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