Fluctuating pressure boundary 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

Fluctuating pressure boundary condition for inlet and outlet

Post by Tsubasa »

Hello,

Now I am trying indoor room simulation by k-omega SST.
What I want to do is to impose time history of pressure at inlet and oulet.

Regarding to time history of pressure, I will extract it from outdoor simulation. I will put probe points near windows, which are inlet and outlet for indoor simulation, to get time history of pressure. Therefore, I will do CFD simulation totally two times for indoor and outdoor separately.

Probably, becasue there is synthetic turbulence method for LES, I guess we can impose time-history of velocity (pressure also) as a boundary condition.

Simply put, I have file(such as csv.file or something) in which time history of pressure value is saved. And can I impose time-history of pressure at inlet and outlet by using the file?

However, even though I looked for how to impose time history of variables, I cannot find it.
Could someone give me tips or documents about it?


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

Re: Fluctuating pressure boundary condition for inlet and outlet

Post by Yvan Fournier »

Hello,

There is no automated way to do this. The solution is to read your .csv or similar file with pressure values and parse it from inside cs_user_boundary_conditions.f90, and apply the conditions matching the given time step. It is also more efficient to read it only the first time and save the values in an array (you can declare is as static in Fortran to keep it from call to call).

I do not beleive I have an example at hand, but in any case, to test your reading of the .csv file from Fortran, it is probably a good idea to test this on a simple "standalone" Fortran program.

Best regards,

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

Re: Fluctuating pressure boundary condition for inlet and outlet

Post by Tsubasa »

Hello Yvan,

For next step, I will impose fluctuating presure for my pressure-driven flow simulation.

For example, as a test, I have csv file which has 100 values in 1 dimension. Then after reading the csv file as an array, I will chage the dirichlet pressure value (below 101325) to i th value on the array in each calling "cs_user_boundary_condition.f90".

As you know, cs_user_boundary_condition.f90 is

Code: Select all

call getfbr('inlet', nlelt, lstelt)
do ilelt = 1, nlelt
   ifac = lstelt(ilelt)
   itypfb(ifac) = ientre

!Dirichlet B.C for pressure:
   icodcl(ifac,ipr) = 1
   rcodcl(ifac,ipr,1) = 101325.633

!Neumann B.C for velocity:
   icodcl(ifac,iu)= 3
   icodcl(ifac,iv)= 3
   icodcl(ifac,iw)= 3
enddo
To read csv file, I wrrote this code allthough this code is not efficient becasue of reading csv file each time.

Code: Select all

program readSimpleCSV
  implicit none
  integer, parameter :: n = 100  !number of time step
  real pressure
  integer save :: i = 1 
  real :: nx(100)
  open (17, file='pressure_time_history.csv', status='old')
  read (17, '()') 
  do i = 1, n
    read (17, *) pressure
    nx(i) = pressure 
  end do
  close (17)
end program readSimpleCSV
To activate this program, what should I do?
Should I define this program as a subroutine in some header files?
Then, shuold I read the csv file when initialization to hold it as the array?

What do you think the easiest solution is for this?

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

Re: Fluctuating pressure boundary condition for inlet and outlet

Post by Yvan Fournier »

Hello,

I am not sure I understand correctly. Is the pressure value uniform across the inlet and only dependent on time, or also on space ?.

If it is dependent only on time, and you only have a few hundred (or even few thousand) values, the simplest solution is probably to read you csv file at the first call of the boundary conditions routine, and save it in an array you can allocate locally and keep across calls using a Fortran variable with the "save" attribute, or its somewhat equivalent "static" attribute in C.

You can check whether this is the first call either using the array's allocation status, or simply checking that (ntcabs == ntpabs + 1).

If the pressure field is also space dependent, than some location and mapping needs to be done first, so it is more complicated.

Best regards,

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

Re: Fluctuating pressure boundary condition for inlet and outlet

Post by Tsubasa »

Hello,

Yes, pressure value is uniform across inlet and outlet face.
I am considering fluctuating pressure at inlet and outlet only which is time dependent, not space.

Is it possible to write a code, which is used to read csv file, like for example in a program below? This is a just example, which does not work.

Code: Select all

call getfbr('inlet', nlelt, lstelt)
do ilelt = 1, nlelt
   ifac = lstelt(ilelt)
   itypfb(ifac) = ientre
   
   open (17, file='../pressure_time_history.csv', status='old')
   read (17, '()')       ! skip header
   read (17, *) pressure
   nx(i) = pressure   
   close (17)   

!Dirichlet B.C for pressure:
   icodcl(ifac,ipr) = 1
   rcodcl(ifac,ipr,1) = 101325.633

!Neumann B.C for velocity:
   icodcl(ifac,iu)= 3
   icodcl(ifac,iv)= 3
   icodcl(ifac,iw)= 3
enddo
Yes, I am going to use "save" or something, but what I don't know is that where I can write the code for this.
Can I add a code to read csv in the same file: "cs_user_boundary_conditions.f90" ?

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

Re: Fluctuating pressure boundary condition for inlet and outlet

Post by Yvan Fournier »

Hello,

Yes, you can add the code in cs_user_boundary_conditions.f90. Ideally as a function you add in the file and call from the user subroutine (for better readability).

Regards,

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

Re: Fluctuating pressure boundary condition for inlet and outlet

Post by Tsubasa »

Hello Yvan,

If I add a code to show "hello world" as a first example, an error happened in compilation.

Code: Select all

program hello
	print *, 'hello world'
end program hello

call getfbr('inlet', nlelt, lstelt)
do ilelt = 1, nlelt
   ifac = lstelt(ilelt)
   itypfb(ifac) = ientre

!Dirichlet B.C for pressure:
   icodcl(ifac,ipr) = 1
   rcodcl(ifac,ipr,1) = 101325.633

!Neumann B.C for velocity:
   icodcl(ifac,iu)= 3
   icodcl(ifac,iv)= 3
   icodcl(ifac,iw)= 3
enddo
Where should I write the code?

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

Re: Fluctuating pressure boundary condition for inlet and outlet

Post by Yvan Fournier »

Hello,

You cannot call your code "program", because that means it is the main program. You simply need to convert it to a subroutine (basically replacing "program" with"subroutine") and call that from the user subroutine.

Regards,

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

Re: Fluctuating pressure boundary condition for inlet and outlet

Post by Tsubasa »

Hello,

Oh. I misunderstood sorry.
You are right.

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

Re: Fluctuating pressure boundary condition for inlet and outlet

Post by Tsubasa »

Hello Yvan,

To read csv file and store the fluctuating pressure history, I wrote a code. (but I am completely new to Fortran, so I am not sure the accuracy.) Now I made random selections for variabes (such as current_nstep and total_nstep) at the moment, and I will change it.

Code: Select all

function readcsv(current_nstep,total_nstep) result(direchlet_pressure)
  implicit none
  integer i, n, current_nstep, total_nstep
  real(8) pressure, direchlet_pressure
  real(8), save :: narray(100)

  if(current_nstep==1)then
	open (17, file='pressure_time_history.csv', status='old')
	read (17, '()')       ! skip header
	do i = 1, total_nstep
		read (17, *) pressure
		narray(i) = pressure  
	end do
	close (17)
  else
  endif
  direchlet_pressure = narray(current_nstep)
return
end function readcsv
What I want to ask you is where I should put this function?
For example, inside the subroutine in cs_user_boundary_condition or outside of the subroutine?
I investigated it, but I cannot find an ansewers.

Also, to check whether time step is the first or not, should I just define "ntcabs" like

Code: Select all

integer ntcabs
and check whether ntcabs == 1 or not?

Best regards,
Tsubasa
Post Reply