Mean temperature calculation

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
Axel Cablé

Mean temperature calculation

Post by Axel Cablé »

Hi,
I would like to calculate the mean temperature in a part of my calculation domain.
I used the usproj.f routine, however when I'm trying to write the Temperature using the WRITE command I don't know where to get it (it doesn't seem to appear in "listing" for example). What would be the correct command to get the computed mean temperature in a .hst file for example?
Here is what I typed:
*********CALCUL DE LA TEMPERATURE INTERIEURE MOYENNE TIM********* c NX,NY,NZ nombre d'intervales suivant X,Y,Z pour un capteur tous les 10cm c Initialisation       TIM = 0.D0       NBTERMES = 0 c Somme de toutes les temperatures       DO NX = 1, 39       DO NY = 1, 11       DO NZ = 1, 24                 CALL GETCEL('X=NX*0.1 and Y=NY*0.1 and Z=NZ*0.1',NLELT,LSTELT)       DO IEL = 1, NLELT       TIM = TIM + RTP(IEL,ISCA(ISCALT(IPHAS)))       NBTERMES = NBTERMES + 1       ENDDO             ENDDO       ENDDO       ENDDO c Calcul de la température interieure moyenne       TIM = TIM / NBTERMES c Ecriture de la valeur renvoyee       WRITE(NFECRA,5500)TIM  5500 FORMAT(' USPROJ: Temperature moyenne =',E14.5)
Many thanks,
Axel
 
Alexandre Douce

Re: Mean temperature calculation

Post by Alexandre Douce »

Hi
same answer as here: https://code-saturne.info/products/code-saturne/forums/general-usage/26440820/503535256
'X=NX*0.1 and Y=NY*0.1 and Z=NZ*0.1' is not a correct location, because GETCEL does not evaluate arithmetical expression. See §2.9 in the user guide for more information. :)
In the following suggested correction, I add the weighting of the volume of cells, useful for irregular mesh.
*********CALCUL DE LA TEMPERATURE INTERIEURE MOYENNE TIM*********
c
Initialisation
      TIM = 0.D0
      VOL= 0.D0
c Somme de toutes les temperatures
      CALL GETCEL('X<=3.9 and Y<=1.1 and Z<=2.4',NLELT,LSTELT)
C for the complete mesh:
C      CALL GETCEL('all[]',NLELT,LSTELT)

      DO IEL = 1, NLELT
        TIM = TIM + RTP(IEL,ISCA(ISCALT(IPHAS))) * VOLUME(IEL)
        VOL= VOL + VOLUME(IEL)
      ENDDO

c Calcul de la température interieure moyenne
TIM = TIM / VOL
c Ecriture de la valeur renvoyee
     
WRITE(NFECRA,5500)TIM
5500 FORMAT(' USPROJ: Temperature moyenne =',E14.5)
 
 
Axel Cablé

Re: Mean temperature calculation

Post by Axel Cablé »

Thanks for the answer, the weighting of the volume of cells being particularly useful.
As for the writing of the calculated mean temperature in a .hst file (instead of writing the result in the listing file, someone kindly advised me to try the following command, which works:
c Ecriture de la valeur renvoyee       OPEN(unit = 10, file = 'Tinterieur.hst', status = 'unknown',      &   position = 'append')       WRITE(10,5500) TIM  5500 FORMAT(' USPROJ: Temperature moyenne =',E14.5) c Si on est a la derniere iteration, fermer l'unite logique du fichier de temperature       IF (NTCABS.EQ.NTMABS) CLOSE(10)
David Monfort

Re: Mean temperature calculation

Post by David Monfort »

Hello,
I will add a small advice for parallel runs ;)
You need to add the following calls to sum the temperature and volume over the domains (across processors)
call parsom(tim)
call parsom(vol)
tim = tim/vol
You should also only write from the first processor, with something like
if (irangp.le.0) then
  if (ntcabs.eq.1) open(...)     ! or "ntcabs.eq.ntpabs+1" for restart calculation.
  write(...) tim
  if (ntcabs.eq.ntmabs) close(...)
endif
David
Post Reply