Export pressure field on surface

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
Alexandre
Posts: 12
Joined: Wed Mar 21, 2012 2:43 pm

Export pressure field on surface

Post by Alexandre »

Hi all,

I would like to export a pressure field of a surface.

My export file is like this : X , Y , Z , Pressure.

I have no problem with on processor but I have problems with multiple processors.
call getfbr('DEFLECT', nlelt, lstelt)
!==========
OPEN(FILE='pressure_field.csv',UNIT=11,ACCESS='APPEND')

! loop over the boundary faces
DO ILELT = 1, NLELT
IFAC = LSTELT(ILELT)
iel = ifabor(ifac)

Xgrav = cdgfbo(1,IFAC)
Ygrav = cdgfbo(2,IFAC)
Zgrav = cdgfbo(3,IFAC)
Psurf=rtp(iel,ipr)
!
WRITE(11,'(4(E12.5,1X))') &
Xgrav,Ygrav,Zgrav,Psurf
ENDDO
I know I have to do a sum to take into account all the processors but I don't know where.

I tried an alternative solution with arrays of ncelet elements for my variables with a sum with PARRSM before write file but it doesn't work.

Thanks for any help.
Yohann Eude
Posts: 19
Joined: Mon Aug 12, 2013 9:36 am

Re: Export pressure field on surface

Post by Yohann Eude »

Hello Alexandre

The easiest way to do that is that each processor writes in different files. So put a condition on the rank of the processor for the "open file part" of your code and for the written part. Then do a fuse of the files created.

Or

You can write a piece of code to initialise a table(size equal to the maximum of iel for your case) at 0.d0. Then each processor filling the table(iel) by the pressure then you can do a sum with PARRSM just before to open and write the result (where the table(...) /=0.d0) from the processor 0.
Alexandre
Posts: 12
Joined: Wed Mar 21, 2012 2:43 pm

Re: Export pressure field on surface

Post by Alexandre »

Hello thank you for the answer,

I chose the second solution to only have to write a single file, but I still have problems with multiprocessor.
call getfbr('DEFLECT', nlelt, lstelt)
nbrface = nlelt
if (irangp.ge.0) then
call parcmx(nbrface)
endif

allocate (Xgrav(nbrface))
allocate (Ygrav(nbrface))
allocate (Zgrav(nbrface))
allocate (Psurf(nbrface))

DO ILELT = 1, NLELT
IFAC = LSTELT(ILELT)
iel = ifabor(ifac)
Xgrav(ILELT) = cdgfbo(1,IFAC)
Ygrav(ILELT) = cdgfbo(2,IFAC)
Zgrav(ILELT) = cdgfbo(3,IFAC)
Psurf(ILELT)=rtp(iel,ipr)
ENDDO

IF(IRANGP.GE.0) THEN
CALL PARRSM(nbrface,Psurf)
CALL PARRSM(nbrface,Xgrav)
CALL PARRSM(nbrface,Ygrav)
CALL PARRSM(nbrface,Zgrav)
ENDIF
if (irangp.le.0) then
OPEN(FILE='pressure_field.csv',UNIT=11,ACCESS='APPEND')
Do ii=1, NLELT
if (Xgrav(ii) /= 0.d0) then
WRITE(11,*) &
Xgrav(ii),';',Ygrav(ii),';',Zgrav(ii),';',Psurf(ii)
endif
Enddo
CLOSE(UNIT=11)
endif
I do not know how much sums with multiprocessor.
Thanks for any help
Yohann Eude
Posts: 19
Joined: Mon Aug 12, 2013 9:36 am

Re: Export pressure field on surface

Post by Yohann Eude »

Try with theses modifications:


call getfbr('DEFLECT', nlelt, lstelt)
nbrface = nlelt
if (irangp.ge.0) then
call parcmx(nbrface)
endif

allocate (Xgrav(nbrface))
allocate (Ygrav(nbrface))
allocate (Zgrav(nbrface))
allocate (Psurf(nbrface))

Here -> Xgrav(:) = 0.d0, Ygrav(:) = 0.d0, Zgrav(:) = 0.d0, Psurf(:) = 0.d0

DO ILELT = 1, NLELT
IFAC = LSTELT(ILELT)
iel = ifabor(ifac)

Xgrav(ILELT) = cdgfbo(1,IFAC)
Ygrav(ILELT) = cdgfbo(2,IFAC)
Zgrav(ILELT) = cdgfbo(3,IFAC)
Psurf(ILELT)=rtp(iel,ipr)

!if you use ILELT which go from 1 to NLELT when you will do the sum on all the processors you will have a huge pressure
!so if iel and IFAC are well inferior to nbrface do:
Xgrav(IFAC) = cdgfbo(1,IFAC)
Ygrav(IFAC) = cdgfbo(2,IFAC)
Zgrav(IFAC) = cdgfbo(3,IFAC)
Psurf(iel)=rtp(iel,ipr)

(with this, each processor will fill the arrays one times because iel and ifac are generic to the entire domain)

(I'm not sure if the numbering of iel of ifac start from 1 in code_satune, you need to check that)


ENDDO


!change that
IF(IRANGP.GE.0) THEN
CALL PARRSM(nbrface,Psurf)
CALL PARRSM(nbrface,Xgrav)
CALL PARRSM(nbrface,Ygrav)
CALL PARRSM(nbrface,Zgrav)
ENDIF
!by (for all processors)
CALL PARSOM(Psurf)
CALL PARSOM(Xgrav)
CALL PARSOM(Ygrav)
CALL PARSOM(Zgrav)
(all the tables Psurf,etc have the true values and 0.d0 on all the processors.
All the values will be exchanged between the processors by the sum.
For example if the processor 1 knows the pressure at iel = 10 and not iel =11 and the processor 2 knows the pressure at iel = 11 and not iel =10
you will have before the parsom!
on the proc1
Psurf(10)=1000Pa
Psurf(11)=0.d0
on the proc2
Psurf(10)=0.d0
Psurf(11)=999Pa
after the "call parsom" you will have on all the processors:
Psurf(10)=1000+0=1000Pa
Psurf(11)=0+999=999Pa


if (irangp.le.0) then
OPEN(FILE='pressure_field.csv',UNIT=11,ACCESS='APPEND')

! here you need to change the loop on NLELT and do the loop on value of Psurs(i)=j or j /=0.d0
Do ii=1, NLELT
if (Xgrav(ii) /= 0.d0) then
WRITE(11,*) &
Xgrav(ii),';',Ygrav(ii),';',Zgrav(ii),';',Psurf(ii)
endif
Enddo
CLOSE(UNIT=11)
endif
Alexandre
Posts: 12
Joined: Wed Mar 21, 2012 2:43 pm

Re: Export pressure field on surface

Post by Alexandre »

Thanks Yohann for your help,

I still have problems with multiprocessor, for the moment I redo a restart with 1 processor, it's silly but my model computation times are acceptable.

I will look later.
Thanks again

Alexandre
Post Reply