Dirichlet boudary condition for inlet and outlet

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Tsubasa
Posts: 175
Joined: Fri Nov 20, 2020 4:09 am

Re: Dirichlet boudary condition for inlet and outlet

Post by Tsubasa »

Hello,

Although | don't think this code is correct, I tried it below anyway,

Code: Select all

subroutine cs_f_user_boundary_conditions &
 ( nvar   , nscal  ,                                              &
   icodcl , itrifb , itypfb , izfppp ,                            &
   dt     ,                                                       &
   rcodcl )

!===============================================================================

!===============================================================================
! Module files
!===============================================================================

use paramx
use numvar
use optcal
use cstphy
use cstnum
use entsor
use parall
use period
use ihmpre
use ppppar
use ppthch
use coincl
use cpincl
use ppincl
use ppcpfu
use atincl
use atsoil
use ctincl
use cs_fuel_incl
use mesh
use field
use turbomachinery
use iso_c_binding
use cs_c_bindings

!===============================================================================

implicit none

! Arguments

integer          nvar   , nscal

integer          icodcl(nfabor,nvar)
integer          itrifb(nfabor), itypfb(nfabor)
integer          izfppp(nfabor)

double precision dt(ncelet)
double precision rcodcl(nfabor,nvar,3)

! Local variables

!< [loc_var_dec]
integer          ifac, iel, ii
integer          ilelt, nlelt
double precision uref2
double precision rhomoy, xdh
double precision xitur

integer, allocatable, dimension(:) :: lstelt
double precision, dimension(:), pointer :: bfpro_rom
!< [loc_var_dec]

! INSERT_VARIABLE_DEFINITIONS_HERE

!===============================================================================


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

allocate(lstelt(nfabor))  ! temporary array for boundary faces selection

! INSERT_ADDITIONAL_INITIALIZATION_CODE_HERE

!===============================================================================
! Assign boundary conditions to boundary faces here

! For each subset:
! - use selection criteria to filter boundary faces of a given subset
! - loop on faces from a subset
!   - set the boundary condition for each face
!===============================================================================

! INSERT_MAIN_CODE_HERE
call getfbr('Inlet', nlelt, lstelt)
do ilelt = 1, nlelt
   ifac = lstelt(ilelt)
   itypfb(ifac) = 77! Custom number (better to be a big number should not be equal to another boundary)

!Dirichlet B.C for inlet pressure:
    icodcl(ifac,ipr) = 1
    rcodcl(ifac,ipr,1) =  100050 !pressure value
enddo

call getfbr('Outlet', nlelt, lstelt)
do ilelt = 2, nlelt
   ifac = lstelt(ilelt)
   itypfb(ifac) = 77! Custom number (better to be a big number should not be equal to another boundary)
   
!Dirichlet B.C for outlet pressure:
    icodcl(ifac,ipr) = 1
    rcodcl(ifac,ipr,1) =  100010 !pressure value
enddo
!--------
! Formats
!--------

!----
! End
!----

deallocate(lstelt)  ! temporary array for boundary faces selection

return
end subroutine cs_f_user_boundary_conditions

!> \section examples Examples
!>   Several examples are provided
!>   \ref cs_user_boundary_conditions_examples "here".

Could you tell me how to modify this?
In paticular, what should I write for such as "Local variables" and "Arguments"? I just copied example case to above code at the moment.
(In my case, I want to impose only Pressure value for both inlet and outlet, and I don't want to impose velocity values. (Now I use laminar flow instead of turbulence model.))

Also, to activate user subroutine, do I just have to put "cs_user_boundary_conditions.f90"(in which above code is written) in "SRC"? After that, I just run simulaiton with GUI, right? Even though I run simualtion by GUI, user subroutine is a top priority if subroutine file exists in "SRC", isn't it?
If yes, I wonder why above user subroutine was not activate in my case.

Sorry for bothering you.
I hope someone help me.

Best regards,
Hamada
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Dirichlet boudary condition for inlet and outlet

Post by Yvan Fournier »

Hello,

Your code seems mostly correct (at least reading it rapidly), though I would comment the lines with itypfb, and leave the natural values set by the GUI. Or better, try both ways, with and without them.

Yes, the file should have priority over the GUI f it is in SRC. Does it compile correctly (using "code_saturne compile -t" in the SRC folder from a terminal, or running the case) ?

What system and install are you running on ? Could you post the "run_solver" file which may appear temporarily in the RESU/<run_id> folder ? There are som known cases where user functions are ignored on Ubuntu with pre-packaged code_saturne. Otherwise it should work.

Regards,

Yvan
Tsubasa
Posts: 175
Joined: Fri Nov 20, 2020 4:09 am

Re: Dirichlet boudary condition for inlet and outlet

Post by Tsubasa »

Hello,

Thank you for your help.

Sorry I didn't understand your post below:
--though I would comment the lines with itypfb--
What do you mean by this?

Oh, I forgot to compile the source file. (Sorry I never tried compiler language so far...)
So, to activate user subroutine, do I have to compile source file? After that, I have to put exe.file in SRC, right?

Now, I am using Ubunts18 on VirtualBox.
This is "run_solver.log".
run_solver.log
(1.92 MiB) Downloaded 131 times
Maybe the problem is becasue I didn't compile, isn't it?

Sorry for bothering you by biginner questions.
Yvan Fournier
Posts: 4070
Joined: Mon Feb 20, 2012 3:25 pm

Re: Dirichlet boudary condition for inlet and outlet

Post by Yvan Fournier »

Hello,

You do not need to compile the source file if you place it under SRC (it is done automatically when you run the case), but compiling it first helps you check you have no syntax error.

Could you start the code checking the "initialize only" box in the advanced run parameters, and post the "run_solver" file ?

By "commenting" a line I meant removing it or placing a comment character (! in Fortran) at the beginning of the line, to check the behavior without this line.

Regards,

Yvan
Tsubasa
Posts: 175
Joined: Fri Nov 20, 2020 4:09 am

Re: Dirichlet boudary condition for inlet and outlet

Post by Tsubasa »

Hello,

As you said, computation worked after removing "itypfb(ifac) = 39" by commneting out as follow;

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!===============================================================================
! Assign boundary conditions to boundary faces here

! For each subset:
! - use selection criteria to filter boundary faces of a given subset
! - loop on faces from a subset
! - set the boundary condition for each face
!===============================================================================
call getfbr('inlet', nlelt, lstelt)
do ilelt = 1, nlelt
ifac = lstelt(ilelt)
! itypfb(ifac) = 39

icodcl(ifac,ipr) = 1
rcodcl(ifac,ipr,1) = 100050
enddo

call getfbr('outlet', nlelt, lstelt)
do ilelt = 2, nlelt
ifac = lstelt(ilelt)
! itypfb(ifac) = 39

icodcl(ifac,ipr) = 1
rcodcl(ifac,ipr,1) = 100010
enddo
!--------
! Formats
!--------

!----
! End
!----
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

However, looking at the result
pressure.png
there is an unexpected result.
Why is pressure velue around [6.3-1300] in the picture, even though I set them as 100050Pa and 100010Pa in subroutine?
Mohammad
Posts: 114
Joined: Thu Oct 25, 2018 12:18 pm

Re: Dirichlet boudary condition for inlet and outlet

Post by Mohammad »

Hello,

The value set in your codes is total pressure while you are looking at relative pressure in the picture.

Regards,
Mohammad
Tsubasa
Posts: 175
Joined: Fri Nov 20, 2020 4:09 am

Re: Dirichlet boudary condition for inlet and outlet

Post by Tsubasa »

Hello Mohammad,

In code saturne, is relative pressure calculated by following?
relative pressure = reference pressure - static pressure? or static pressure - reference pressure?
Would you teach me this if you know? Because there are many kind of pressures (static, dynamic, total, relative .etc), I am littile bit comfused by them.

Best regards,
Hamada
Mohammad
Posts: 114
Joined: Thu Oct 25, 2018 12:18 pm

Re: Dirichlet boudary condition for inlet and outlet

Post by Mohammad »

Hello,

There is another field in postprocessing files named total_pressure you can check its value in paraview.
The reference pressure is 1.01325xE5 Pascals by default and you can also set its value in cs_user_parameters file.

I think the [relative]pressure is: static pressure + dynamic pressure - reference pressure

And total pressure is: static pressure + dynamic pressure

Regards,
Mohammad
Tsubasa
Posts: 175
Joined: Fri Nov 20, 2020 4:09 am

Re: Dirichlet boudary condition for inlet and outlet

Post by Tsubasa »

Hello,

Now, I am trying 2-dimensional channel flow(x=2m, y=0.1m, z=0.005m(1layer)). For z direction, Symmetry condition is applied. The geometory can be seen in the below picture.
channel_flow.png
When imposing velicty inlet condition (u=0.01m/s) at the inlet and normal outlet condition (which can be set by GUI) at the outlet, I got the above result, and I got the0.06Pa pressure difference between inlet and outlet in the below picture.
laminar_pipe_pressure.png


Therefore, what I want to do next is that I want to get the same velocity profile as can be seen above picture by imposing pressure differece 0.06Pa between inlet and outlet.
However, although I was supposed to give a correct subroutine code below
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
call getfbr('inlet', nlelt, lstelt)
do ilelt = 1, nlelt
ifac = lstelt(ilelt)
icodcl(ifac,ipr) = 1
rcodcl(ifac,ipr,1) = 0.06
enddo

call getfbr('outlet', nlelt, lstelt)
do ilelt = 1, nlelt
ifac = lstelt(ilelt)
icodcl(ifac,ipr) = 1
rcodcl(ifac,ipr,1) = 0
enddo
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I cannot get the result, which I want.

Looking at the result,
for the velocity, velocity magnitude is very large (around 0.8-1.0m/s, idealy this should be around 0.01m/s) like this.
velo.png
For the total pressure (which can be set by subroutine code), non-physical profile was appered.


Could someone give me tips how to get good result?
If there are mistakes in subroutine code, could you teach me?

Best regards,
Tsubasa
Tsubasa
Posts: 175
Joined: Fri Nov 20, 2020 4:09 am

Re: Dirichlet boudary condition for inlet and outlet

Post by Tsubasa »

For the total pressure,
the result is like this.
pre.png
This is non-physical.

Best
Tsubasa
Post Reply