카테고리 없음

Calculate Average Temperature

오늘보다 나은 내일 2013. 12. 31. 10:20

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:

ARG1 is the Load Step number

  1. ARG2 is the Substep number
  2. 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


! 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
!
fini
/post1
!
*if,ARG1,eq,0,then
   *if,ARG3,eq,0,then
      set,LAST                       ! if nothing specified, use final value
      *MSG,WARN
      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.
   *else
      set,,,,,ARG3                   ! if ARG1=0 and ARG3<>0 use ARG3 time
   *endif
*else
   set,ARG1,ARG2
*endif
*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
   my_comp_test=0
   allsel
   set,last
   *MSG,ERROR
   Named Selection "Temp_Here" must be created on face(s) of interest.
   /EOF
   *return,-1
*endif
!
cmsel,s,Temp_Here                    ! select nodes on face(s)
my_comp_test=1
!
*stat
*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=0
*do,ii,1,n_nodes
   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
*enddo
*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
allsel
set,last
!