The example project may be downloaded by right clicking this link: spatially_varying_modulus_via_do_looop.wbpz
Open up Model in the Project Schematic to bring up the Mechanical window.
Under Coordinate Systems, create your own local coordinate system. The screenshot below results in the coordinate system's origin at the middle of the top face of the cube for our example project.
Create your own Named Selection with the following properties.
Under Static Structural, insert a Commands option
Copy paste the following text into the Commands window (also attached is a screenshot from the example project):
! Commands inserted into this file will be executed just prior to the ANSYS SOLVE command.
! These commands may supersede command settings set by Workbench.
! Active UNIT system in Workbench when this object was created: Metric (mm, kg, N, s, mV, mA)
! 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.
mat_ref = maxmp
E0 = 2e+05 ! Youngs modulus at surface
Einf = 1.5*E0 ! Youngs modulus at infiniti
beta = 1 ! Rate of exponential decay
csys,100 ! Set active coordinate system to 100 to match the manual numbered coordinate system in the object tree under Coordinate Systems
! If you change the coordinate system, you must clear the results and rerun
*GET, depth, ELEM, i, cent, y, ! Calculate element centroid in active coordinate system
value = Einf-(Einf-E0)*exp(-beta*depth) ! Calculated youngs modulus at given location
mat_ref = mat_ref+1
MP,EX,mat_ref,value ! Defining the new material
emodif,i,mat,mat_ref ! Assign the new material to the current element