Users can employ APDL commands to map stresses from one Ansys Mechanical APDL model to another, when the two models occupy the same geometry. There are also ways to do this in the Ansys Workbench environment, using the External Data system. This article illustrates how to map stresses in APDL, providing example APDL code to carry out the mapping. Note that the *MOPER and /INISTATE commands are essential in carrying out the mapping efficiently.
Users sometimes want to map stresses from one model into another. There are tools to do this in both Ansys Mechanical APDL, as well as using External Data in Ansys Workbench Mechanical. This document explores using APDL commands.
An array of node locations and an array of stress components can be created for corner nodes in an Ansys FEA result. There is an APDL command called *MOPER that can be used to map those stresses to the locations of another set of coordinates that fit inside and on the boundary of the original set of nodes. This facility can be used to map stresses from one model to another, when the receiving model fits the same geometry.
To proceed with the original model, *VGET commands will quickly retrieve node locations and stresses, placing them in arrays. The command *VWRITE can write the coordinate and stress data to ASCII text files for later use.
The following set of APDL commands builds and solves the example model seen in the left image in Figure 1, above, and moves its corner node locations and stresses into data array columns:
! Create a block. Mesh with hex elements. Fix the left side, place pressure on top and Solve.
! Use at your own risk. . .
VSEL, , , , 1
! Plot equivalent stress
/efacet,2 ! more detail
! SAVE A COPY TO LOOK AT LATER
! reselect nodes at corners only. No stresses at midside nodes
! Create arrays to hold node coordinates and stress components
*get,maxnode,node,,num,max ! highest node number
*get,numnodes,node,,count ! number of selected nodes
*dim,nc,array,maxnode,3 ! node coordinates x,y,z
*dim,ns,array,maxnode,6 ! node stress components
! Create a node masking array for further array work in case
! node numbering is not continuous, or nodes are not selected.
*vget,mymask(1),node,1,nsel ! fill with status values
! *VGET coordinates of the nodes
! *VGET stress components of the nodes
! Compress out the midside node zeros…
! Want ns2 array to contain stress components at locations in nc2 array
*dim,nc2,array,numnodes,3 ! compressed file of coordinates
*dim,ns2,array,numnodes,6 ! compressed file of stresses
*do,ii,1,3 ! compress 3 coordinates
*do,ii,1,6 ! compress 6 stresses
A second receiving model as in the right hand image of Figure 1 can have the stresses mapped in as initial conditions using its own node coordinates. The node locations of the receiving model can be loaded into an array with *VGET commands. The *MOPER command can map stress values of the original model into the node locations of the receiving model, using the arrays. Finally the INISTATE command can place the resulting stress values at the nodes of the receiving model.
The following APDL commands re-mesh the above geometry with an alternative mesh, move node locations to array columns, map stresses from the original model with *MOPER, and move the stresses to the new mesh with INITATE commands. The nodes are constrained in all degrees of freedom, the model is solved, and the mapped stresses are displayed. Note that there is not displacement in the receiving model result since all nodes are constrained:
! Now, remesh with tet mesh, and map stresses to nodes using *MOPER to map,
! and INISTATE to place stresses in the undeformed mesh
! Stresses applied to midside nodes will be ignored in Solve
vclear,1 ! clear the mesh
dadele,all,all ! remove constraint
sfadele,all,all,all ! remove pressure
VSEL, , , , 1
VMESH,_Y1 ! mesh with tetrahedrons
! Create array of node locations in tet elements, and array for mapped stresses.
*get,maxnode3,node,,num,max ! highest node number
*dim,nc3,array,maxnode3,3 ! node coordinates x,y,z of new mesh
*dim,ns3,array,maxnode3,6 ! node stress components of new mesh
! *VGET coordinates of the new nodes
*MOPER,ns3(1,1),nc3(1,1),MAP,ns2(1,1),nc2(1,1),3 ! Map data from first mesh compressed data
x3=maxnode3 ! highest node number, shorter name
inistate,set,NODE,1 ! node-based initial state
! Use implied looping for speed.
! Impose the 6 stress components with INISTATE on nodes 1 through x3
d,all,all ! constrain all degrees of freedom
/efacet,2 ! more detail
plnsol,s,eqv ! how do the stresses look?
! Save a copy to look at later
See the working directory to compare the four plots
In the event that the node coordinates and stresses from the first model need to be written to an external file, the following commands illustrate how it can be done. Numerical data here has been written with 14 digit accuracy:
! Write compressed coordinate and stress arrays to exterior files.
! The format used writes 14 digits for each numerical entry
! Open the file to be written, then *VWRITE the coordinate columns
! Open the file to be written, then *VWRITE the stress component columns
To read the coordinate and stress data into arrays in a second model, the following commands illustrate a method:
! To read coordinate and stress array data from files created above…
! Delete the arrays if they exist
*del,nc_in,,nopr ! hold coordinates
*del,ns_in,,nopr ! hold stress components at the coordinates
! How many rows in one of these files? Dimension arrays accordingly.
*dim,nc_in,array,numlines,3 ! coordinate data array
*dim,ns_in,array,numlines,6 ! 6 stress components array
! *VREAD data from the coordinate and stress component files
As shown in the first APDL example, to check the mapped stress values in the receiving model, a user can constrain all degrees of freedom in the receiving model, remove any other loads, and solve. If the material properties are linear, the mapped stress values should be available to list and plot as results over the model.
If only the constraints of the original model are applied to a receiving model that differs only in the mesh, then when solved, and equal but opposite deflection should be seen, within the accuracy that might be expected from the meshes that have been used.
Note the important APDL commands that we have employed above:
These commands can be studied in detail in the Commands Manual in the Ansys Help system.
Users can adapt the methods illustrated here to map various quantities between models that fit the same geometry. Users should check for correctness and accuracy of the methods employed.