Getting user values
When running user written routines it is often convenient to set values in the Graphical User Interface and pass these to the subroutine. This can be done by using the Card 9 - VARIABLE Variable Definition Card - Optional. For more information, see the Thermal Solver Reference Manual PDF.
A user written subroutine can access these values by calling the subroutine VARVAL
. For example, to get the value of NAME
the call is:
call varval("%NAME", value)
This reads the value from NAME
and assigns it to the variable
value. Notice the "%" character at the start of the variable name.
Variables can be defined using thermal solver generic entities using the format described below for the include file. A generic entity directly defines a line to be added to the input file.
Variables can also be set in an include file, in which case any name can be used. The syntax of the Card 9 - VARIABLE Variable Definition Card - Optional entry is:
VARIABLE %NAME value
where:
%NAME is the variable name preceded by a "%" character and value is the value to be
assigned. An include file must include all delimiters and so a complete include file
that sets variables AREA
and ALTITUD
looks like:
Include file for User1 Variables
-1
-1
-1
-1
-1
-1
-1
-1
VARIABLE %AREA 6.789
VARIABLE %ALTITUD 25000
-1
-1
The code to access these variables would then be:
real area, altitude
..
call varval('%AREA', area)
call varval('%ALTITUD', altitude)
Variable values can obviously have many uses, one of these is to switch features of a
user written subroutine on or off. The following code will execute the subroutine
APPLYHEAT
if the variable TMGVAR0
>
0
and the routine APPLYCONVECT
if the variable
TMGVAR2
> 0
:
logical doheat, doconvect
real tempvar
..
C
C Initialization code
C
call varval('%TMGVAR0',tempvar)
if (tempvar .gt. 0.0) then
doheat = .true.
else
doheat = .false.
end if
call varval('%TMGVAR1',tempvar)
if (tempvar .gt. 0.0) then
doconvect = .true.
else
doconvect = .false.
end if
..
C
C Implementation code
C
if(doheat)then
call applyheat(…
end if
if(doconvect)then
call applyconvect(…
end if
Note that, the default values, for all TMG variables, is zero. Therefore, in the above
example, the routines APPLYHEAT
and APPLYCONVECT
will
not run unless they are explicitly turned on. The advantage of using this control logic
is that the two routines can be combined into a single USER1
routine
and then selected independently. Without the control logic, the following three versions
of USER1
would be required:
- Contains calls to both routines
- Contains call to
APPLYHEAT
only - Contains call to
APPLYCONVECT
only
Selection of routines to be run using this multiple routine approach would be by selecting the appropriate include file.