Average Temperature on One or More Faces of Bodies in Ansys Mechanical

Temperature Monitoring and Perioperative Thermo-regulation

Computing Average Temperature on One or More Faces of Bodies in Mechanical Workbench

A Probe in Ansys Mechanical Workbench can return a maximum or minimum result on associated geometry, however it does not produce an average value of the result. Users sometimes wish to measure an average value of a result on selected geometry. If this is returned as an output parameter, it can be used in design studies.

To return an average temperature on the face of a body is not just a matter of finding a simple average over a number of nodes—the node temperature values need to be weighted by the amount of element face area associated with each node. Fortunately, the ARNODE function in Ansys can find the area on element faces associated with each node, and a weighted average can be formed.


This article illustrates an APDL Commands Object for Workbench Mechanical that can output the average temperature over a selected face or set of faces in a thermal model.

Using a Commands Object for Average Value on a Face

In order for a Workbench Mechanical Commands Object to find a portion of a model that is of interest to a user, a Named Selection can be used since it is turned into a Component in the Ansys APDL analysis. In the following macro, the Named Selection “Temp_Here” (not case sensitive) is used to indicate the nodes on one or more faces that are to be used to form an average. The named selection must exist and represent a set of faces on Bodies in the user’s Workbench Mechanical thermal model.

Arguments can be passed to a Commands Object in its Input details. The macro is written to accept three Input arguments to indicate Load Step, Substep, or Time for the result to be formed. If the Input arguments are all blank, then SET,LAST is used to read the final result. The arguments are:

  1. ARG1 is the Load Step number
  2. ARG2 is the Substep number
  3. ARG3 is the Time of interest

The macro is written to apply the following logic to loading a result:

  • If ARG1 and ARG3 are zero, the SET,LAST command is used to get the result at the end of the analysis results file.
  • If ARG1 is nonzero, then ARG3 for time will be ignored.
  • If ARG1 is nonzero and ARG2 is zero, the SET command reads the last substep of the Load Step number in ARG1.

The Commands Object creates three Output parameters that report:

  1. Average temperature value calculated
  2. Time of the result that was loaded by the SET command as a result of the Input arguments
  3. The result of an error check on the Named Selection, where “1” means OK

There are limited error checks programmed into the macro. When it runs, the Commands Object does not pop up an error message in the Workbench interface, so a user should check output to see that there is a valid result for the average temperature calculation. Check Details of the Commands Object to see the Output parameters to read the average temperature that was calculated.

Creating a Temperature-Based Node Component in Ansys APDL

This Commands Object could also serve as a macro in the APDL interface to Ansys. A user must create a node component “Temp_Here” that corresponds to nodes on the exterior surface of interest. A user must select all nodes on an element face, according to the description of the ARNODE function in Ansys, in order to include the contributing area of any attached element faces.

SOLVE must be executed to form the average, so users must plan ahead, placing the Commands Object in the postprocessing section of the Workbench Mechanical Outline, creating the Named Selection “Temp_Here”, and entering Input arguments to the Commands Object that indicate Load Step/Substep or Time of interest, prior to solving.

Modifying a Macro to Calculate Temp Averages for Load Steps

Users could modify the macro to calculate temperature averages for all load steps and substeps in a results file, such as listing them in the Output text that is generated during the run, or turning extreme values and their times into output parameters—an “exercise for the student”.

Here is the content of the Commands Object (or macro) that does the work:

! Use at your own risk–only limited testing has been done
! Calculate Average Temperature on Face(s) in Named Selection “Temp_Here”
! Report average as parameter “my_temp_avg” in Details>Results
! The ARNODE function returns the area on solid element faces associated with
! a node on the surface. All nodes on the surface must be selected, so if we
! select only nodes on a surface of interest, only the element faces on that
! surface will contribute to the area estimate.
! ARG1=load step desired
! ARG2=substep desired, if blank, last substep of ARG1 load step is loaded
! ARG3=time desired, used only if ARG1=0
set,LAST ! if nothing specified, use final value
No Load Step or Time was provided to temperature average macro. %/&
SET,LAST will be used for final Load Step. See my_time Output in Details.
set,,,,,ARG3 ! if ARG1=0 and ARG3<>0 use ARG3 time
*get,my_time,ACTIVE,,SET,TIME ! time of result in database
*get,comptype,COMP,Temp_Here,TYPE ! what type of component
*if,comptype,ne,1,then ! is it a node component
Named Selection “Temp_Here” must be created on face(s) of interest.
cmsel,s,Temp_Here ! select nodes on face(s)
*get,n_nodes,node,,count ! how many nodes in component
*dim,node_arnode,array,n_nodes ! associated elements surface area each node
*dim,node_t_a,array,n_nodes ! product of temperature*area at each node
node_next=NDNEXT(node_next) ! work through all the nodes
node_arnode(ii)=ARNODE(node_next) ! associated area on element faces
node_t_a(ii)=ARNODE(node_next)*TEMP(node_next) ! product
*vscfun,sum_node_t_a,SUM,node_t_a(1) ! sum of temperature*area products
*vscfun,sum_area,SUM,node_arnode(1) ! sum of areas
my_temp_avg=sum_node_t_a/sum_area ! the average temperature on the surface
! my_temp_avg is reported in Results

The Average Temperature result will be in the units employed during the Solve, according to settings in Workbench. Users should check the reported average temperature value in Details>Results for the Commands Object as listed for the parameter “my_temp_avg”.

Conclusion | Average Temperature on Selection of Body Faces

An APDL Commands Object can be used in the Outline of Workbench mechanical to calculate the average temperature on a selection of body faces indicated by a Named Selection. Calculating a weighted average of the temperatures of nodes on those body faces will return an averaged value that is independent of variation in element face shapes and sizes.  For offsetting a temperature to degrees absolute, click HERE.

The user can use Input Arguments to Details of the Commands Object to indicate the result of interest, and read Results to find the value of the average. The calculated average can be promoted to a Workbench parameter if design studies are to be initiated.

The macro that has been illustrated could be modified to produce other averaged values that are suitable over a surface.  In addition, that can be retrieved at each node of interest with a GET Function or *GET command.  Including, average displacement, heat flux, stress, or other choice, controlling for direction with a results coordinate system choice.

ETABLE and SMULT Commands in Ansys Mechanical

This Commands Object has formed an average of values at nodes over a face or faces on the exterior surfaces of bodies. Averaged values of a selection of elements would usually be generated using ETABLE commands—one for the averaged value inside individual selected elements.  And, one for the volume of the elements, followed by an SMULT command to form the (value*volume) products element-by-element, an SSUM to get the summation values, two *GET commands to find the summation values of the preceding SSUM command, and finally a one-line calculation of the weighted average.

A Named Selection for a set of Bodies in the Geometry would indicate the element component to be used in the ETABLE commands. Checks and APDL programming to be employed would be similar to that in the above Commands Object macro.  For more examples of operational engineering, please follow the corresponding link.

Most Recent Tips & Tricks