Using a Snippet to Extract Ansys Workbench Results to a Text File with vmask and vget

Commonly, we need to save results from an Ansys Workbench study as a text file for post-processing in another program, such as Excel.  One can right-click on a desired result and use Export, but that can be tedious if there a lot of results to save.  With a snippet one inserts a Commands (APDL) object in the solution and writes APDL code to perform the desired  functions.

Below we use a simple example of an L-shaped bracket.  In this static structural example, there are three time steps as we change the forces on the bracket.  One could also use this in a thermal, modal, or transient structural with a few changes needed.

L bracket geom

We begin by creating a Named Selection to define the regions of the model where we are interested in results.

insert named selection

 

 

Here we have chosen to use a single face as the named selection.  One could use a set of faces or edges, vertices, or volumes.

named selection face

Then, we must make sure to set the output to save an mapdl db file to yes.  

output save db file

Next, we insert a Commands (APDL) object into the Solution

insert commands object in solu

 

Below is the command snippet that we use to export the data.  For a structural system in which I am interested in deformations, I typically like to a file format of “X  Y  Z  UX  UY  UZ” where X, Y, Z are the coordinate locations and UX,UY,UZ are the deformations at each node in the named selection.  I typically do not use a file header but one could insert that if desired.

The general method below is to load the results from the db file using RESUME.  Then, calculate the total number of results sets in the study.  We use a DO-loop to cycle through all results.  Then, we select the nodal named selection.  Alternatively to using a named selection, we could select nodes of interest using the available selection commands such as NSEL and ESEL.  The desired information (coordinate locations and displacements) for the full model are put into an array using *VGET.  Using the node numbers of the named selection in combination with the *VMASK command, we create a compressed array of the desired information only at the nodes of interest.  Finally, using *VWRITE we write that array into a text file.

! Commands inserted into this file will be executed immediately after the ANSYS /POST1 command.
! Active UNIT system in Workbench when this object was created: Metric (m, kg, N, s, V, A)
! NOTE: Any data that requires units (such as mass) is assumed to be in the consistent solver unit system.
! See Solving Units in the help system for more information.
!
RESUME     !this is necessary to read the db file which was saved earlier
!
alls     !this selects everything, good place to start
!
*GET,numb_sets,ACTIVE,0,SET,NSET !get number of results sets
set,first
!
CMSEL,s,face_of_interest  !select the named selection
!
*get,nummax,NODE,,num,max !Max Node id in selected nodes
*get,numnode,NODE,,count !Number of selected nodes
*dim,mask,array,nummax
*vget,mask(1),NODE,,NSEL !mask for selected nodes
*dim,nodal_data_full,array,nummax,6 !array for pressures of all 1-to-nummax nodes
*dim,nodal_data_comp,array,numnode,6 !array for pressures of ONLY selected nodes
*dim,nodeid_full,array,nummax !array for containing NODE ID
*dim,nodeid_comp,array,numnode !array for containing NODE ID for ONLY selected nodes
*vfill,nodeid_full,ramp,1,1 !array from 1-to-nummnode (1,2,3,....)
!
*do,i_set,1,numb_sets,1
*GET,current_time,ACTIVE,0,SET,TIME
!Retrieving DATA
*vmask,mask(1)
*vget,nodal_data_full(1,1),node,,LOC,X
*vmask,mask(1)
*vget,nodal_data_full(1,2),node,,LOC,Y
*vmask,mask(1)
*vget,nodal_data_full(1,3),node,,LOC,Z
*vmask,mask(1)
*vget,nodal_data_full(1,4),node,,U,X !*VGET,ParR,Entity,ENTNUM,Item1,IT1NUM,Item2,IT2NUM,KLOOP
*vmask,mask(1)
*vget,nodal_data_full(1,5),node,,U,Y
*vmask,mask(1)
*vget,nodal_data_full(1,6),node,,U,Z
!
!COMPRESSING ARRAYS TO ONLY SELECTED NODES for the coordinate locations and displacements:
*vmask,mask(1)
*vfun,nodal_data_comp(1,1),COMP,nodal_data_full(1,1)
*vmask,mask(1)
*vfun,nodal_data_comp(1,2),COMP,nodal_data_full(1,2)
*vmask,mask(1)
*vfun,nodal_data_comp(1,3),COMP,nodal_data_full(1,3)
*vmask,mask(1)
*vfun,nodal_data_comp(1,4),COMP,nodal_data_full(1,4)
*vmask,mask(1)
*vfun,nodal_data_comp(1,5),COMP,nodal_data_full(1,5)
*vmask,mask(1)
*vfun,nodal_data_comp(1,6),COMP,nodal_data_full(1,6)
!
!GETTING THE SELECTED NODE ID LIST !only necessary if you also want to keep the node numbers
*vmask,mask(1)
*vfun,nodeid_comp(1),COMP,nodeid_full(1)
!
!WRITING TO A FILE: !set the file name as desired.  includes the time step in the file name as a variable
*cfopen,named_deformation_data_time_%current_time%,DAT
*vwrite,nodal_data_comp(1,1),nodal_data_comp(1,2),nodal_data_comp(1,3),nodal_data_comp(1,4), nodal_data_comp(1,5), nodal_data_comp(1,6)
%F %F %F %E %E %E   !formats for each column
*cfclos
!
set,next !read next set
*ENDDO !end loop
!
!DELETING USED VARIABLES
*del,nodal_data_full,nopr
*del,nodeid_full,nopr
*del,nodal_data_comp,nopr
*del,nodeid_comp,nopr
*del,mask,nopr
*del,nummax,nopr
*del,numnode,nopr
ALLS

One thought on “Using a Snippet to Extract Ansys Workbench Results to a Text File with vmask and vget”

  1. Dear Justin

    Thank you for your nice post. It helped me a lot.

    I am running a transient analysis,and I would like to extract some nodal information over the time, as you have extracted. The problem in my case is, some nodal information are written and some are not written. So, if I would like to extract nodal information of 10 nodes, 10 files are created therefore and half of them write the nodal information and other half not. The files which are not writing the nodal information are created correctly with right dimensions, but write only zeros. The code is as follows:

    !———————————————————————-
    /Post1
    FILE,STT,rst

    *GET,numb_sets,ACTIVE,0,SET,NSET

    *do,i,100,110 ! from node number 100 to 110
    *dim,data_%i%,,numb_sets,7
    set,first
    *do,j,1,numb_sets
    *vget,data_%i%(j,1),node,i,s,x
    *vget,data_%i%(j,2),node,i,s,y
    *vget,data_%i%(j,3),node,i,s,z
    *vget,data_%i%(j,4),node,i,s,1
    *vget,data_%i%(j,5),node,i,s,2
    *vget,data_%i%(j,6),node,i,s,3
    *vget,data_%i%(j,7),node,i,s,eqv
    set,next
    *enddo
    *cfopen,result_%i%,txt
    *vwrite,data_%i%(1,1,1),data_%i%(1,2,1),data_%i%(1,3,1),data_%i%(1,4,1),data_%i%(1,5,1),data_%i%(1,6,1),data_%i%(1,7,1)
    (F8.2,’ ‘,F8.2,’ ‘F8.2,’ ‘,F8.2,’ ‘,F8.2,’ ‘,F8.2,’ ‘,F8.2)
    *cfclos
    *enddo
    !—————————————————————–

    Can you please let me know, if there is anything wrong in this code?
    Thank you again.

Comments are closed.