How to access to the mass flow of a cross section?

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Luciano Garelli
Posts: 284
Joined: Fri Dec 04, 2015 1:42 pm

Re: How to access to the mass flow of a cross section?

Post by Luciano Garelli »

Hello,

Yes...you can access with ntcabs ; Current absolute time step number. In case of restart, this is equal to ntpabs + number of new iterations.

Regards,

Luciano
Jundi He
Posts: 106
Joined: Fri Jan 13, 2017 3:23 pm

Re: How to access to the mass flow of a cross section?

Post by Jundi He »

Many thanks!
Jundi He
Posts: 106
Joined: Fri Jan 13, 2017 3:23 pm

Re: How to access to the mass flow of a cross section?

Post by Jundi He »

Hi Code Saturne develop team:

In the script I access the mass flow rate of a certain layer of internal faces, and obtain the summation of the mass flows, then output the total mass flow to a file:

call field_get_key_int(ivarfl(ivar), kimasf, iflmas)
call field_get_val_s(iflmas, imasfl)

do ifac = 1, nfac
z_coord=cdgfac(3,ifac)
if(z_coord .gt. 0.00424 .and. z_coord .lt. 0.00426)then
totalmassflow = totalmassflow + imasfl(ifac)
endif
enddo

OPEN(2,FILE='output_massflow.txt',status='replace')
write(2,*)totalmassflow
close(2)

There is a problem, 8 processors are used in the simulation, every time only the mass flow information of a single processor is output to the file. What should I do if I need to calculate the mass flow of this cross section when the simulation is using 8 processors. Thanks for the time.

Regards!
Jundi
Luciano Garelli
Posts: 284
Joined: Fri Dec 04, 2015 1:42 pm

Re: How to access to the mass flow of a cross section?

Post by Luciano Garelli »

Hello,

If you have debug your script and it works in a serial run, the next step is to parallelize it. Each processor will have a set of cell, depending on the partition method used, wherewith each processor will compute a portion (local) of the total mass flow, then you have to do a parallel sum of this local values (parsom()). To do that you can check the following example scripts and documentation:

cs_user_extra_operations-global_efforts.f90
cs_user_extra_operations-parallel_operations.f90
https://www.code-saturne.org/doxygen/sr ... _8f90.html

Finally, if the processor rank=0 do the write operation

Regards,

Luciano
Jundi He
Posts: 106
Joined: Fri Jan 13, 2017 3:23 pm

Re: How to access to the mass flow of a cross section?

Post by Jundi He »

Luciano:

Thanks for the examples. It seems useful for me. I'll try if it works.

Regards!
Jundi
Jundi He
Posts: 106
Joined: Fri Jan 13, 2017 3:23 pm

Re: How to access to the mass flow of a cross section?

Post by Jundi He »

Luciano:

Should I obtain and output the total mass flow (of a cross section) like this:

call field_get_key_int(ivarfl(ivar), kimasf, iflmas)
call field_get_val_s(iflmas, imasfl)

do ifac = 1, nfac
z_coord=cdgfac(3,ifac)
if(z_coord .gt. 0.00424 .and. z_coord .lt. 0.00426)then
totalmassflow = totalmassflow + imasfl(ifac)
endif
enddo

if (irangp.ge.0) then
call parsom(totalmassflow)
endif

OPEN(2,FILE='output_massflow.txt',status='replace')
write(2,*)totalmassflow
close(2)


Thanks for the time.

Regards!
Jundi
Luciano Garelli
Posts: 284
Joined: Fri Dec 04, 2015 1:42 pm

Re: How to access to the mass flow of a cross section?

Post by Luciano Garelli »

Hello,

I think that yes, but you have to modify the write operation and initialize to zero totalmassflow variable. Try with this modifications.

Code: Select all

call field_get_key_int(ivarfl(ivar), kimasf, iflmas)
call field_get_val_s(iflmas, imasfl)

totalmassflow = 0.0

do ifac = 1, nfac
z_coord=cdgfac(3,ifac)
if(z_coord .gt. 0.00424 .and. z_coord .lt. 0.00426)then
totalmassflow = totalmassflow + imasfl(ifac)
endif
enddo

if (irangp.ge.0) then
call parsom(totalmassflow)
endif

if (irangp.le.0) then     ! Serial run irangp=-1, parallel run irangp=0 -> Master write
 OPEN(2,FILE='output_massflow.txt',status='replace')
 write(2,*) totalmassflow 
 close(2)
endif
Regards,

Luciano
Jundi He
Posts: 106
Joined: Fri Jan 13, 2017 3:23 pm

Re: How to access to the mass flow of a cross section?

Post by Jundi He »

Luciano:

Thanks for the help! Yes I should initialize the total mass flow rate at the begin, and then calculate the summation. Many thanks!

Regards!
Jundi
Post Reply