Contents - Index


$Constant

 

The $CONSTANT directive allows the specification of a constant.  A constant is similar in some respects to an EES variable in that it has a value and units, but its value cannot be changed.  In addition, it is a global (rather than a local) variable in the respect that all EES functions, procedures, subprograms, modules, as well as the main program have access to constants.  A constant is recognized by EES by the last character in its name which must be the # character.  A string constant can also be defined.  All string variables end with the $ character.  A string constant must have #$ as the last two characters.  

 

Constants are normally specified in the Constants.txt file that is read in when EES is started.  These constants are permanent constants that are available to all EES files.  The difference between a constant that is defined in the Constants.txt file and one that is defined with the $CONSTANT directive is that the latter is only available to the EES file that it is defined within.  It is, in this sense, a temporary constant.  The $CONSTANT directive in no way changes the Constants.txt file. 

 

The format of the $CONSTANT directive is:

 

$CONSTANT Name# = ValueSI [UnitsSI]  ValueEng [UnitsEng]   {for a numerical constant}

 

or

 

$CONSTANT Name#$ = 'Character string'   {for a string constant}

 

Name# is the name of the constant.  The $CONSTANT directive will allow a constant that has been previously defined in the Constants.txt file to be redefined, but you generally do not want to do this.

 

ValueSI is a numerical value that will be the value of this constant when EES is configured to operate in SI units.  ValueSI must be a numerical value or a simple expression (with no spaces) using the +, -, *, or / operators.   Note that the simple expression can refer to previously defined constants, e.g., $CONSTANT N1#=N#-1 where N# is previously defined.  EES variables cannot be used to designate the value.

 

UnitsSI is the units for the constant that will be used when EES is configured in SI units.  Note that the units must be enclosed in square braces.  The units specification is optional.

 

ValueEng is a numerical value that will be the value of this constant when EES is configured to operate in English units.  ValueEng must be a numerical value or a simple expression (with no spaces) using the +, -, *, or / operators.  If  ValueEng is not provided, it is assumed that the constant has the same value in either unit system.  Note:  If  ValueEng is provided, its value should be the same as the product of ValueSI and the conversion factor relating the SI and Eng units.  

 

UnitsEng is the units for the constant that will be used when EES is configured in English units.  Note that the units must be enclosed in square braces.  The units specification is optional.

 

Multiple constants can be defined, but each requires a separate $CONSTANT directive.  The $CONSTANT directive should appear before the constant is used, preferably at the very top of the EES file.

 

One application of the $CONSTANT directive is to specify the value of a global variable.   As shown in the following program, a constant specified with the $CONSTANT directive can be used to specify the size of arrays that passed to functions using array range notation or the limits of a duplicate loop

 

 

$Constant N#=4

 

function fixthis(x[1..N#,1..N#])

  i:=0

  sum:=0;

  repeat

    i=i+1

sum=sum+x[i,i]

  until (i>=N#)

  fixthis:=sum

end

 

duplicate j=1,N#

duplicate i=1,N#

   x[i,j]=i+j

end

END

 

s=fixthis(x[1..N#,1..N#])

 

 

The $Constant directive may also be the most convenient way to specify a refrigerant name that is used throughout an EES program, as in the following example.

 

$Constant R#$='R134a'

$unitSystem SI K kPa kJ

 

function h(T,P)

   h=enthalpy(R#$,T=T,P=P)

end

 

h_1=h(300 [K],100 [kPa])

 

 

Also see:  Constants menu command and Directives