#
# A CFD-Post session file for creating Resultant Temperature and
# Mean Radiant Temperature variables
# Reference: CIBSE Guide A, CIBSE, UK, 1999.
#
#
# Macro GUI begin
#
# macro name = Comfort Factors
# macro subroutine = comfortFactors
#
# macro parameter = separator
#  type = Separator
#
# macro parameter = comment
#  type = Comment
#  default = This macro calculates <b>Resultant Temperature</b> and <b>Mean Radiant Temperature</b> variables.<br>If the Radiation Model Transfer Mode is 'Surface to Surface', it requires Wall Irradiation Flux to be present in the results file, otherwise Radiation Intensity must be present.
#
# macro parameter = Radiation Transfer
#  type = Combo
#  list = Surface to Surface, Participating Media
#  default = Surface to Surface 
#
# Macro GUI end

! no warnings 'redefine';

! sub comfortFactors {
! ($radMode) = @_;

# First, make sure all essential dependent variables exist
!
! if( $radMode eq "Surface to Surface" ) {
!   if( getValue("Wall Irradiation Flux", "User Level") eq "" ) {
!     reportError( "'Comfort Factors' macro failed.\nVariable 'Wall Irradiation Flux' does not exist." );
!     return;
!  }
! } else {
!   if( getValue("Radiation Intensity", "User Level") eq "" ) {
!     reportError( "'Comfort Factors' macro failed.\nVariable 'Radiation Intensity' does not exist." );
!     return;
!   }
! }
! if( getValue("Velocity", "User Level") eq "" ) {
!   reportError( "'Comfort Factors' macro failed.\nVariable 'Velocity' does not exist." );
!   return;
! }
! if( getValue("Temperature", "User Level") eq "" ) {
!   reportError( "'Comfort Factors' macro failed.\nVariable 'Temperature' does not exist." );
!   return;
! }
!
!


  # Calculate Resultant Temperature & Mean Radiant Temperature
  LIBRARY:
   CEL:
    EXPRESSIONS:
     Tzero = 273.15 [K]
     factor1 = sqrt( 10 [s m^-1] * Velocity )
! if( $radMode eq "Surface to Surface" ) {
     meanirrad = max( pi * 1e-10 [W m^-2], abs( Wall Irradiation Flux ) )
     meanTemp = ( meanirrad / stefan )^0.25
! } else {
     meanint = max( 1e-10 [W m^-2 sr^-1], abs( Radiation Intensity ) )
     meanTemp = ( pi * meanint * 1[sr] / stefan )^0.25
! }
     resultTemp = ( meanTemp - Tzero  + factor1 * ( Temperature - Tzero )  ) / ( 1 + factor1 ) + Tzero
    END
   END
  END

  USER SCALAR VARIABLE: Resultant Temperature
   Recipe = Expression
   Expression = resultTemp
   Calculate Global Range = false
  END

  USER SCALAR VARIABLE: Mean Radiant Temperature
   Recipe = Expression
   Expression = meanTemp
   Calculate Global Range = false
  END

! reportWarning( "Created variables: \"Resultant Temperature\"\n and \"Mean Radiant Temperature\"" );

!}
