Example for Dam breaking

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
hsnu1137
Posts: 7
Joined: Fri May 28, 2021 4:22 pm

Example for Dam breaking

Post by hsnu1137 »

Hi, I am sort of new to Code Saturne, though I have finished some simple simulation of non-Newtonian simulation in axisymmetric tube by modifying the SRC.

I have wandered for several days on the internet in the search for possible tutorial/information/example of Dam Breaking or material slumping with Code_Saturne. However I am still very confused about where to start.

For case of Dam Breaking in OpenFoam, https://cfd.direct/openfoam/user-guide/v7-dambreak/ it is possible to assign the phase fraction (alpha) in space directly. I am not sure how to achieve it in CS. Does it have something to do with "Interior to boundary faces(boundary insertion)" and the setting of the "porosity" of specific volume? Should I assign the ALE Free Surface at the internal boundary together with the Homogeneous Eulerian VoF model?

Or, should I define the phase fraction in any subroutine?

Maybe the question is sort of simple or even silly, but it is really quite frustrated finding no relevant resources. If it can be done easily I can upload some example for the future tutorial. Otherwise I would have to go to another hell of OpenFoam :?

Thank you very much.

PoChun Tseng
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Example for Dam breaking

Post by Yvan Fournier »

Hello,

Did you search for VoF posts in this forum ? I seem to remember there were a few questions on this subject some months ago.

I am not familar with the use of VoF in code_saturne, so I can only suggest ways of searching, and if you really find nothing useful, I can try to remind some people who have worked on this to check your post.

In any case, VoF has no relation to boundary insertion (which is a mesh prepossessing operation). I am not sure about the reltion to "porosity", but porosity can be used in many applications outside of VoF in any case.
Also VoF and ALE are alternative and independent approaches, so I do not believe you need to assign an ALE Free Surface.

Best regards,

Yvan
hsnu1137
Posts: 7
Joined: Fri May 28, 2021 4:22 pm

Re: Example for Dam breaking

Post by hsnu1137 »

Dear Yvan,

Thank you for the rapid reply. I found the clue to go on after a more detailed search of the recent post.
I have found the key info from a post in 2019. viewtopic.php?p=13658
In the post, Luciano pointed out that
To activate VOF you have to set the variable ivofmt = 0 using the cs_user_parameters.f90 routine and the void fraction is store in the ivolf2 array.
The remaining questions are:
If I selected the VoF model in gui, should I still set the variable ivofmt = 0 in cs_user_parameters.f90?
Besides, I tried to specify the ivolf2 in different volume zones cs_user_initialization.f90. However, the SRC failed at call getcel(’2’, nlelt, lstelt) in the early stage and a syntax error was reported. Could you please help me figure it out?

I am using CS 6.0.6 in Ubuntu. The result is attached for reference.
Thank you very much.

Sincerely,

Po-Chun
Attachments
20210529-2315.zip
(4.53 KiB) Downloaded 100 times
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Example for Dam breaking

Post by Yvan Fournier »

Hello,

you need to add :

use cs_c_bindings

in the "Module files" section of the file to avoid the syntax error.

If you set it using the GUI, you should not need to set ivofmt (looking at the sources, it seems it is set by the GUI). In any case, user subroutines have priority over the GUI (they are called after so can overwrite/complete settings).

Best regards,

Yvan
hsnu1137
Posts: 7
Joined: Fri May 28, 2021 4:22 pm

Re: Example for Dam breaking

Post by hsnu1137 »

Hello,

Thank you again for the reply. The SRC still failed with a Syntax error in argument list after adding use cs_c_bindings in the Module files section.
use cs_c_bindings

integer nvar , nscal
integer nlelt , iel, iel2nd
double precision dt(ncelet)

integer, allocatable, dimension(:) :: lstelt
double precision, dimension(:), pointer :: cvar_voidf

allocate(lstelt(ncel)) ! temporary array for cells selection

call getcel(’2’, nlelt, lstelt)
1
Error: Syntax error in argument list at (1)
Should I attach other files or information to aid in the troubleshooting?

Thank you very much.

PoChun
Attachments
20210530-1032.zip
(4.54 KiB) Downloaded 107 times
Luciano Garelli
Posts: 280
Joined: Fri Dec 04, 2015 1:42 pm

Re: Example for Dam breaking

Post by Luciano Garelli »

Hello,

May be I am wrong, but I think that you should use single quotes '...' for string criteria and not single closing quotes ’..’.

Regards,
Luciano
hsnu1137
Posts: 7
Joined: Fri May 28, 2021 4:22 pm

Re: Example for Dam breaking

Post by hsnu1137 »

Thank you Luciano for pointing out my mistake.
Your answer indeed solved the problem. I am quite excited now :D

I reproduced the mistake because I copied the getcel example directly from the PDF practical user's guide (3.9.4 Using selection criteria in user subroutines) without through checking.

Anyway, later I will post more details about how to use VoF for newbies like me.

Sincerely,

PoChun
Last edited by hsnu1137 on Sun May 30, 2021 10:19 am, edited 1 time in total.
hsnu1137
Posts: 7
Joined: Fri May 28, 2021 4:22 pm

Re: Example for Dam breaking

Post by hsnu1137 »

For those interested in the Homogeneous Eulerian VoF/Volume of fluid method,
I may share some simple steps here.

First in GUI:
  • Select Homogeneous Eulerian VoF in Claculation features
  • Assign Gravity in Body forces
  • Assign Density&Viscosity of the two fluids (fully filled with μ1 means: void fraction=0)
Then the void fraction (μ1-to-μ2 ratio in each cell) should be assigned with cs_user_initialization.f90
example code:
implicit none

! Arguments

integer nvar , nscal
integer nlelt , iel, iel2nd
double precision dt(ncelet)

! Local variables

! INSERT_VARIABLE_DEFINITIONS_HERE

integer, allocatable, dimension(:) :: lstelt
double precision, dimension(:), pointer :: cvar_voidf

!===============================================================================
! Initialization
!===============================================================================

allocate(lstelt(ncel)) ! temporary array for cells selection

! INSERT_MAIN_CODE_HERE

!--------
! Formats
!--------
! getcel('1 or 2', nlelt, lstelt) select cells
call getcel('box[0.01, 0.01, 0, 0.03, 0.03, 0.02]', nlelt, lstelt)
call field_get_val_s(ivarfl(ivolf2), cvar_voidf)

! Assign void to the whole volume first
do iel = 1, ncel
cvar_voidf(iel) = 1
enddo

! Assign non-void to the selected volume then
do iel = 1, nlelt
iel2nd = lstelt(iel)
cvar_voidf(iel2nd) = 0
enddo
With the code we may initialize specific volume zone filled with the first fluid with getcel.

The first argument of getcel may be the selection criteria in Volume zones
i.e. the 'volume group' created by Salome-Mesh, or something direct like 'box[0.01, 0.01, 0, 0.03, 0.03, 0.02]' as the link below
https://www.code-saturne.org/cms/sites/ ... ect_c.html

Best,

PoChun
Last edited by hsnu1137 on Sun May 30, 2021 11:11 am, edited 1 time in total.
hsnu1137
Posts: 7
Joined: Fri May 28, 2021 4:22 pm

Re: Example for Dam breaking

Post by hsnu1137 »

By the way,
I encountered the same problem as the post viewtopic.php?p=15275 while adding an inlet.
@ At least one boundary face declared as inlet (or
@ outlet) with prescribed velocity with an entering
@ flow for which the value of void_fraction has not been
@ specified (Dirichlet condition).
@ The calculation will not be run.
Should I use getfbr to assign the void_fraction to the boundary face of inlet?
The concept is quite strange because I thought the array ivolf2 applies to the cell only...

Best regards,

PoChun
Luciano Garelli
Posts: 280
Joined: Fri Dec 04, 2015 1:42 pm

Re: Example for Dam breaking

Post by Luciano Garelli »

Hello,

But you are solving the dam break problem, you don't need an inlet boundary condition.

Check this post(viewtopic.php?f=2&t=2830) where I set the void fraction to an inlet boundary condition.

Regards,
Luciano
Post Reply