TAGGED: apdl-command, material, material-assignments, mechanical-apdl
-
-
August 28, 2021 at 8:16 pm
massey95
SubscriberHello,
I am a novice with APDL, but have tried to implement APDL command into ANSYS workbench mechanical in order to assign material properties based on coordinate position. I have attempted this using the APDL script below. I recieve no errors, but the procedure is not working. Any help is appreciated!
!Define constants *SET,sig_max,500 *SET,sig_min,200 *SET,H_max,500 *SET,H_min,200 *SET,L_1,100 !width of geometry in mm !Get number of elements !GET, Par, Entity, ENTNUM, Item1, IT1NUMÂ *GET,par_elemcount,ELEM,,COUNTÂ Â !Create arrays for each centroid positions !DIM, Par, Type, IMAX, JMAX *DIM,centarray,ARRAY,par_elemcount,2Â Â !Assign element IDs and Centroid positions to centarray !VGET Retrieves values and stores them into an array parameter. *VGET,centarray(1,1),ELEM,,ELISTÂ !Element IDs *VGET,centarray(1,2),ELEM,,CENT,XÂ !Loop through each element !defines do loop !*DO, Par, IVAL, FVAL, INC *DO,i,1,par_elemcount,1Â Â !test i value *SET,par_testi,i !Get x-coordinate of element centroid *SET,x_pos,centarray(i,2)Â !calc material prop for element H=((H_max-H_min)/L_1)*x_pos + H_min sig=((sig_max-sig_min)/L_1)*x_pos + sig_min !Assign material prop to element !TB,lab,MAT,NTEMP,NPTS,TBLPT,EOSPT,FuncName !TB,bilinear isometric hardening, matid=1, no. of temp pts=1, !no. of pts=n/a for biso, eq of state=n/a, funcname=n/a TB,BISO,1,1,,, !TBDATA,STLOC,C1,C2 !TBDATA, starting location, 1st const, 2nd const. TBDATA,3,sig,H MPCHG,1,i !only updating 1 ele at a time. inefficient *ENDDOÂ Â !end loop ```
I have inserted this as a command into under geometry which should then run in /prep7. Note: it would be a lot more efficient to assign all elements with same x-cord at same time, but couldn't figure out how to achieve this. But as a first step, getting the above working would be great!
Many Thanks!
September 6, 2021 at 2:20 pmmassey95
SubscriberUPDATE: I believe the issue is that the command is working, BUT, it sets material 2 to the final calculation of sig and H.. however, this material is associated with all pts. So all points end up being assigned the final material calculation. Hence: either I need to create a unique material ID for each pt (think this may not be possible due to ansys limits) or unique material ID for each column of nodes (may have to combine columns depending on how many material IDs ansys allows). Hopefully this makes sense! Any help appreciated!
September 7, 2021 at 11:39 amAshish Khemka
Forum Moderator
Try selecting the elements based on the position using the ESEL command.
Regards Ashish Khemka
September 7, 2021 at 12:17 pmmassey95
SubscriberThanks Ashish. I have managed to make the progress below, which should hopefully do what is required. Now i just need to verify it is working correctly. Do you know how I can plot the material properties in the solution section of workbench?
!Define constants
*SET,sig_max,0.0005
*SET,sig_min,0.0002
*SET,H_max,0.000575
*SET,H_min,0.000300
*SET,L_1,100 !width of geometry in mm
! select all elements you want to assign x-based materials to
esel,all
! Save element selection to a component
!CM, Cname, Entity!Groups geometry items into a component.
cm,remainingElem,elem
! Set initial material ID
matID = 1
! arbitray large number of iterations (1000000) based on how many groups of elements you think you'll have.
!We'll exit the loop early if we end up finishing the assignments though.
!*DO, Par, IVAL, FVAL, INC !defines do loop
*do,ee,1,1000000
! Get the element ID of the next lowest element that is still selected
! "elnext" is an alternative way to do *GET, nextElem, ELEM,0, nxth
nextElem=ELNEXT(0)
! Get element x-coordinate
*get,elemXposition,ELEM,nextElem,cent,x
! Select all elements at this centroid location
!ESEL, Type, Item, Comp, VMIN, VMAX, VINC, KABS !Selects a subset of elements.
!r-Reselect a set from the current set.
esel,r,cent,x,elemXposition
! Assign component name to these elements
cm,elementXgroup,elem
!Define material prop for this x position
*SET,x_pos,elemXposition + 50 !+50 due to coord sys
!calc material prop for element
H=((H_max-H_min)/L_1)*x_pos + H_min
sig=((sig_max-sig_min)/L_1)*x_pos + sig_min
!Assign material prop to element
!TB,lab,MAT,NTEMP,NPTS,TBLPT,EOSPT,FuncName
!TB,bilinear isometric hardening, matid=1, no. of temp pts=1 !no. of pts=n/a for biso, eq of state=n/a, funcname=n/a
TB,BISO,matID,1,,
!TBDATA,STLOC,C1,C2
!TBDATA, starting location, 1st const, 2nd const.
TBDATA,1,sig,H
MP,EX,matID,0.19, ! tonne s^-2 mm^-1
MP,NUXY,matID,0.28, !MP, Lab, MAT, C0, C1
! Change material properties for all these elements
! You'll have to combine with your code to set up the material properties though.
MPCHG,matID,all
!Get number of elements in a col
*GET,par_elemcountcol,ELEM,,COUNT
! Select the component "remainingElem", unselect the group of elements we just assigned properties to "elementXgroup" and redefine "remainingElem" so we never select those elements again in the do-loop
cmsel,s,remainingElem !S - Select a new set (default).
cmsel,u,elementXgroup !U - Unselect a set from the current set.
cm,remainingElem,elem
!Get number of elements
*GET,par_elemcount,ELEM,,COUNT
! If there are no element left, exit the do-loop
!*IF, VAL1, Oper1, VAL2, Base1, VAL3, Oper2, VAL4, Base2 !Conditionally causes commands to be read.
!eq: equal! exit: exit current do-loop
*if,par_elemcount,eq,par_elemcountcol,exit
! Increment matID by one so we don't overwrite it for the next iteration of the do-loop
matID=matID+1
*enddo
matID=matID+1
! Get the element ID of the next lowest element that is still selected
! "elnext" is an alternative way to do *GET, nextElem, ELEM,0, nxth
nextElem=ELNEXT(0)
! Get element x-coordinate
*get,elemXposition,ELEM,nextElem,cent,x
! Select all elements at this centroid location
!ESEL, Type, Item, Comp, VMIN, VMAX, VINC, KABS !Selects a subset of elements.
!r-Reselect a set from the current set.
esel,r,cent,x,elemXposition
! Assign component name to these elements
cm,elementXgroup,elem
!Define material prop for this x position
*SET,x_pos,elemXposition + 50 !+50 due to coord sys
!calc material prop for element
H=((H_max-H_min)/L_1)*x_pos + H_min
sig=((sig_max-sig_min)/L_1)*x_pos + sig_min
!Assign material prop to element
!TB,lab,MAT,NTEMP,NPTS,TBLPT,EOSPT,FuncName
!TB,bilinear isometric hardening, matid=1, no. of temp pts=1 !no. of pts=n/a for biso, eq of state=n/a, funcname=n/a
TB,BISO,matID,1,,
!TBDATA,STLOC,C1,C2
!TBDATA, starting location, 1st const, 2nd const.
TBDATA,1,sig,H
MP,EX,matID,0.19, ! tonne s^-2 mm^-1
MP,NUXY,matID,0.28, !MP, Lab, MAT, C0, C1
! Change material properties for all these elements
! You'll have to combine with your code to set up the material properties though.
MPCHG,matID,all
ALLSEL,ALL,ALL
September 7, 2021 at 4:02 pmAshish Khemka
Forum Moderator
You can issue following commands:
EPLOT
/PNUM,MAT,1
/REPLOT
Regards Ashish Khemka
September 21, 2021 at 11:56 ammassey95
SubscriberThanks for the response. With the help of a reddit forum I got the code working as intended. It can be found here (I'm sure it could be enhanced but does the job for now!) :https://github.com/rhamill95/Random/blob/a45b7f3dd699531534034051c6ad99d60bfbe772/apdl_vary_matprop
Viewing 5 reply threads- The topic ‘APDL to assign material parameter based on x-coordinate of element’ is closed to new replies.
Innovation SpaceTrending discussionsTop Contributors-
6535
-
1906
-
1463
-
1311
-
1022
Top Rated Tags© 2026 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.
-