- **OpenFOAM Running, Solving & CFD**
(*https://www.cfd-online.com/Forums/openfoam-solving/*)

- - **How to calculate liquid volume as the interface moves for interFoam Solver**
(*https://www.cfd-online.com/Forums/openfoam-solving/58044-how-calculate-liquid-volume-interface-moves-interfoam-solver.html*)

Hello All,
How do I calculaHello All,
How do I calculate the volume of the liquid phase as the interface moves for a transient interFoam simulation. Help from the forum members will be appreciated. |

hi,
i can give you a code shi,
i can give you a code snipet, that calculates the total mass for fluid 1. just divide this by rho1. Even simplier: integrate over gamma field with the comand found below ;-) regards Christian volScalarField rho1gamma ( IOobject ( "rho1gamma", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), gamma*rho1, gamma.boundaryField().types() ); dimensionedScalar totalMass = fvc::domainIntegrate(rho1gamma); Info << "Mass of Fluid 1 = " << totalMass.value() << " kg" << endl; |

Hello Christian,
Thanks a lHello Christian,
Thanks a lot for the code snippet. I have not written/used code earlier in interFoam. I would appreciate if you can give hint on using this appropriately (0, constant, system - directory)? Thanks. |

Hello Asaha,
No, that's notHello Asaha,
No, that's not part of any case dictionary! The first snippet (IOobject) you'd have to put into the top-level solver file createFields.h. For the second code snippet I recommend a separate header-file (just create one) and include it at the appropriate place in solver.C. Then recompile (wmake). Btw, I think it's a good idea to make a custom solver (see User Guide for details). regards Holger |

Hi,
you have to build this Hi,
you have to build this into the interFoam solver itself. Simply add it to the source code within the timestep loop at the end of each timestep. Then recomplie interFoam: voila. Look here: ./OpenFOAM/OpenFOAM-1.4.1/applications/solvers/multiphase/interFoam/interFoam.C If you run interFoam from now on, it states the information you want after each timestep. Kind regards Christian |

Hello,
Thanks for your adviHello,
Thanks for your advice and help. I will give this a try and get back. Thanks again! |

Hello Christian and Holger,
Hello Christian and Holger,
Thanks for your advice and help. I have followed the steps as below: (1) Added the code snippet in createFields.H file. volScalarField rho1gamma ( IOobject ( "rho1gamma", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), gamma*rho1, gamma.boundaryField().types() ); (2) Then made a rho1gamma.H file having the line dimensionedScalar totalMass = fvc::domainIntegrate(rho1gamma); (3) Added the following lines in interFoam.C file # include rho1gamma.H Info << "Mass of Fluid 1 = " << totalMass.value() << " kg" << endl; (4) recompiled interFoam Please correct me on the above steps. Upon testing the recompiled code, in the output I do see Mass of Fluid 1 = 3.2e-08 kg, but this value does not change with time after successive iterations? Pl. advice me if I need to make changes. Regards, A A Saha. |

Hi,
Your setup in the top-lHi,
Your setup in the top-level solver seems to be all right! Why your question? Should the overall fluid mass change with time in your case? regards, Holger |

Hi,
you could put the wholeHi,
you could put the whole code in one header File and include this into your solver, it is simplier but has nothing to do with your question. If your volume fraction should change in your simulation, you have to use an inlet with gamma = 1, right? Check your boundary conditions. Regards Christian |

Hello Holger and Christian,
Hello Holger and Christian,
The mass which is showing up is the initial fluid mass for gamma = 1 set with setFields at the inlet for capillary driven flow in a channel. As the interface moves I expect this value to increase with time for the transient solution. Please correct me if I am making a mistake. Is there a alternative, I have simulation for a number of old cases and wish to calculate liquid volume as the interface moves with time, because the new solver can be used for only new cases. Can paraview or tecplot be used? Kind regards, A A Saha |

Hi,
I admit that I have noHi,
I admit that I have not understood the geometric field completely yet, but volScalarField rho1gamma ( IOobject ( "rho1gamma", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), gamma*rho1, gamma.boundaryField().types() ); initializes rho1gamma with gamma*rho1, but it is not updated using this expression each time step, thus you need to add: rho1gamma = gamma*rho1; each time step before the integration - please correct me someone, if I am wrong. Best regards, Niels |

Hi Niels,
yes you are rightHi Niels,
yes you are right of course.... (so please ignore the second half of the first sentence in my previous post ;-)) ) This is why i put the whole code in one header file and include it at the and of each timestep. Then the update works... Kind regards Christian |

Hi Saha
I wonder if this wiHi Saha
I wonder if this will solve your purpose: dimensionedScalar totalLiquidVolume = sum(mesh.V()*gamma); Info << "Total Liquid Volume, Value: " << totalLiquidVolume.value() << ", Dimensions = " << totalLiquidVolume.dimensions() << endl; just include it into your main solver before runTime.write(); and recompile your solver. It will print the current volume at each iteration. Check it first on a single processor because you might need to change sum() with gSum(). Let me know if it works. Regards Jaswi |

Hello Jaswi,
Thank you veryHello Jaswi,
Thank you very much for your code snippet. The code is working. The liquid volume is getting upated with time at each iteration. Please advice me as, I also have simulation data for a number of old cases and wish to calculate liquid volume as the interface moves with time, because the new solver can be used for only new cases. Thanks again. Kind regards, A A Saha. |

Hi Saha
yes it can be done.Hi Saha
yes it can be done. just take a look at the utilities folder. in particular take a look at the postprocessing/velocityfield folder. There you will find a number of post processing utilities. you can adapt any one of those for your own purpose. just take the basic framework and modify it. i suggest magU. study it and then let me know if you have questions. Regards Jaswi |

Hello Jaswi,
I have followeHello Jaswi,
I have followed the thread http://www.cfd-online.com/cgi-bin/Op...how.cgi?1/7401 and got the required information to resolve my issue. I have a question regarding the max. and min. gamma values obtained during iterations. Sometimes I get the results something like given below: Liquid phase volume fraction = 0.130194 Min(gamma) = -7.81823e-47 Max(gamma) = 1.0004 The min. value is less than 0 and max. value is more than 1. As I understand gamma should be within 0 and 1 for boundedness. Pl. correct me if I may be missing something critical here. Is something wrong with the simulation results or the values obtained are acceptable for interFoam calculation. Pl. advise me on this. Best regards, A A Saha. |

Hi Saha
if one carefully taHi Saha
if one carefully takes a look at the min and max values for gamma then one can conclude that Min(gamma) = -7.81823e-47 implies gamma approximately equals 0 and regarding the Max(gamma) = 1.0004, as far as my understanding goes it can be because of several reasons: 1) set higher value for write precision in the controlDict to reduce rounding off error. 2)you are usng multigird for the pressure equation 3)this might be an intermediate iteration and when you let the solution converge you will get gamma=1.0 hope that helps and settle the doubt a bit :-) With Best Regards Jaswi |

Hello Jaswi,
Thanks for youHello Jaswi,
Thanks for your post. Yes the pressure equation uses multigrid. The log output for the converged solution is after each time step, so the solution may be converged. I will try to set higher value for write precision in the controlDict and see if this helps. Is there a specific documentation which clearly mentions how the interface capturing algorithm is implemented in interFoam. Pl. point me to these, if any. I have read HrvojeJasakPhD.pdf, OnnoUbbinkPhD.pdf, HenrikRuschePhD2002.pdf. I may be missing some other important documentation other than these. With best regards, A A Saha. |

Hi Saha
These are the textsHi Saha
These are the texts which I have referred as well. You can also google search with following combination 1) "multiphase flows" AND VOF filetype:pdf 2) "multiphase flows" AND "ishii" filetype:pdf and you will come across some PhD and Master's works . Some of these documents have the basic formulation. Also look into David Hill PhD work. It has the twoPhaseEulerFoam formulation explained. For a very detailed description you can also look into the book Computational Fluid Dynamics with Moving Boundaries by Wei Shyy, H. S. Udaykumar, und Madhukar M. Rao I will keep you posted if I find any more material With Best Regards Jaswi |

Hello Jaswi,
Thanks for theHello Jaswi,
Thanks for the information on documentation of interFoam. With best regards, A A Saha. |

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