Skip to main content

ANSYS qu from new user: help me write a "for" loop please!

Submitted by bumblebee on

Hi: I am a new ANSYS user and would really appreciate help writing a "for"-type loop to go with an example found here:

http://www.mece.ualberta.ca/tutorials/ansys/CL/CAT/BirthDeath/Print.html

 At the end of the example is the paragraph below.  I want to know how to do this!  Can anyone modify the code for me?  I don't even know where to start.  I would be very grateful!  

 This procedure can be programmed in a loop, using command line code, to more accurately model element death over time. Rather than running the analysis for a time of 60 and killing any elements above melting temperature at the end, a check can be done after each substep to see if any elements are above the specified temperature and be killed at that point. That way, the prescribed convection can then act on the elements below those killed, more accurately modelling the heating process. 

Look at the help on the *do command.  The syntax is something like

*do, <index>, <start_idx>, <incr>, <end_index>

*enddo

You will have to break your solution loadstep up into a number of substeps.  Each substep will have its own solve command.

For example 

/solu

total_time = 1

time_steps = 100 

time_inc = total_time/time_steps 

*do, step_no, 1, num_step

    time, step_no*time_inc

    nsub, 1

    outres, all, all

    ... any stuff about boundary conditions ...

    solve

    finish

    /post1

    set, last

    etable,melty,temp, ! Create an element table

    esel,s,etab,melty,273 ! Select all elements from table above 273

    finish

    /solu ! Re-enter solution phase

    antype,,rest ! Restart analysis

    ekill,all ! Kill all selected elements

    esel,all

*enddo

etc.

Mon, 10/20/2008 - 04:13 Permalink

Hi Biswajit:

Thanks a lot for your help.  I tried your suggestion and have a couple of  questions if you have time.  Sorry--I know that this is probably really simple stuff, but I'm trying to learn!

 I got a couple of error messages (all of my code is below, with the part I got and modified from you in bold blue): First, after entering the code I got from you, I got "No DO trips needed, enter *ENDDO".  Second, after entering the postprocesser, I got: "The current database is not from a previous solution. No restart is possible with this database"; then " Cumulative iteration 1 may have been solved using different model or boundary condition data than currently stored. POST1 results may be erroneous unless you RESUME from a Jobname.DB file for this substep.

 If you have any idea what this stuff means and how to fix it, I would really appreciate hearing it!  My code is below.  

 

/title, Transient melting by element death (conduction)

/prep7                         ! Enter the preprocessor



                        ! define geometry



BLC4,0,0,20,15                     ! Create rectangle

BLC4,0,0,10,4                     ! Create smaller rectangle (magma)

ASBA,1,2                    ! Boolean Subtraction (subtracts area 2 (small) from area 1 (big))



ET,1,Plane55                     ! Element type



MP,Dens,1,2262e9                 ! Define density

mp,c,1,0.001604                 ! Define specific heat

mp,kxx,1,0.001                    ! Define heat transfer coefficient

                   

SMRT,6                    ! Mesh size 

CM,_Y,AREA 

ASEL, , , , 3

CM,_Y1,AREA

CHKMSH,'AREA'  

CMSEL,S,_Y 

 

AMESH,_Y1                   ! Mesh area                       

CMDEL,_Y                    ! Refine mesh

CMDEL,_Y1  

CMDEL,_Y2  

FLST,5,6,2,ORDE,4  

FITEM,5,6  

FITEM,5,22 

FITEM,5,-25

FITEM,5,44 

CM,_Y,ELEM 

ESEL, , , ,P51X

CM,_Y1,ELEM

CMSEL,S,_Y 

CMDEL,_Y

EREF,_Y1, , ,3,0,1,1

CMDEL,_Y1  

finish

/solu                         ! Enter solution phase

antype,4                     ! Transient analysis

nropt,full                     ! Newton Raphson - full

SOLCONTROL,ON,0

total_t = 3.1536e13

t_steps = 100 

t_inc = total_t/t_steps



*do, step_no, 1, num_step

    time, step_no*t_inc

    nsub, 1

    outres, all, all

                            !... any stuff about boundary conditions ...

TUNIF,200, 

TREF,200,

IC,all,temp,200                     ! Initial conditions, temp = 200

PRED,-1

FLST,2,628,1,ORDE,2

FITEM,2,1  

FITEM,2,-628

IC,P51X,TEMP,200,  

FLST,2,2,4,ORDE,2  

FITEM,2,6  

FITEM,2,-7 

/GO



DL,P51X, ,TEMP,1200,1            ! BC  

FLST,2,2,4,ORDE,2  

FITEM,2,2  

FITEM,2,-3 

/GO

 

DL,P51X, ,TEMP,200,1



/STAT,SOLU 

    solve

    finish

    /post1

    set, last

    etable,melty,temp,     ! Create an element table

    esel,s,etab,melty,600     ! Select all elements from table above 600 C

    finish

    /solu     ! Re-enter solution phase

    antype,,rest     ! Restart analysis

    ekill,all     ! Kill all selected elements

    esel,all

*enddo



/post1                    ! Enter postprocesser



set, first

etable,melty,temp,                 ! Create an element table

esel,s,etab,melty,600                ! Select all elements from table                                             ! above 600

finish



/solu                         ! Re-enter solution phase

antype,,rest                     ! Restart analysis

ekill,all                         ! Kill all selected elements

esel,all                         ! Re-select all elements



finish



/post1                         ! Re-enter postprocessor

set,first                        ! Read in last subset of data

esel,s,live                     ! Select all live elements

plnsol,temp                     ! Plot the temp contour of the live elements



!/CONT,1,10,200,100,1200

!PLNS,TEMP, 

!/REPLOT



*DO, i,1,10,1

set,i

etable,delete

etable,melty,temp,                 ! Create an element table

esel,s,etab,melty,600                ! Select all elements from table                                             ! above 600

finish



/solu                         ! Re-enter solution phase

antype,,rest                     ! Restart analysis

ekill,all                         ! Kill all selected elements

esel,all                         ! Re-select all elements



finish



/post1                         ! Re-enter postprocessor

set,i                        ! Read in last subset of data

esel,s,live                     ! Select all live elements

plnsol,temp

 /CONT,1,10,200,100,1200

PLNS,TEMP,             

/replot



*ENDDO



ANTIME,100,0.5, ,0,2,0,0.31536E+14

 

Mon, 10/20/2008 - 14:34 Permalink

I just noticed that I'd written num_step instead of t_steps in the do loop.  You'll have to correct that before you proceed.

If you want an amination, you'll have to save the results at the end of each step.  I'm not sure exactly how to proceed after that.

Please let us know when you figure out the right way of getting waht you want.

-- Biswajit 

Mon, 10/20/2008 - 22:25 Permalink

I just want to clarify that I still can't animate progressive element death (i.e., elements disappearing as temp evolves).  At what point (in the "DO" loop or after it) and how do I put the results from /solu into the postporcessor for animation?  Major thanks...

Mon, 10/20/2008 - 18:51 Permalink

OK, I'm stumped on how to make an animation for this example.  Thanks a lot Biswajit; your suggestion was really helpful.  The commands are posted below, not including the animation step.  I'm going to put up a new post to ask about the animation.  

 

/title, Convection Example   

/prep7                ! Enter the preprocessor



! define geometry



k,1,0,0                ! Define keypoints

k,2,0.03,0

k,3,0.03,0.03

k,4,0,0.03

a,1,2,3,4            ! Connect the keypoints to form area





! mesh 2D areas



ET,1,Plane55            ! Element type



MP,Dens,1,2262e9         ! Define density

mp,c,1,0.001604         ! Define specific heat

mp,kxx,1,1.8            ! Define heat transfer coefficient



esize,0.0025            ! Mesh size

amesh,all            ! Mesh area



finish





/solu                ! Enter solution phase



antype,4            ! Transient analysis



tot_time = 1e6

t_steps = 50

time_inc = tot_time/t_steps



time,1e6            ! Time at end of analysis



nropt,full            ! Newton Raphson - full

lumpm,0            ! Lumped mass off

nsubst,20            ! Number of substeps, 20

neqit,10                ! Max no. of iterations

autots,off            ! Auto time search off

lnsrch,on            ! Line search on





TUNIF,200,

IC,all,temp,200            ! Initial conditions, temp = 200



*do, i,1 ,t_steps, 1

/solu

    time=i*time_inc

    nsub, 1

outres,all,all            ! Output data for all substeps



                    !... any stuff about boundary conditions ...



                ! fixed temp BC's

nsel,s,ext            ! Node select all exterior nodes

sf,all,conv,1,600

NSEL,ALL            ! Reselect all nodes

kbc,1                ! Load applied in steps, not ramped

/gst,off                ! Turn off graphical convergence monitor



    solve

    finish



    /post1

    set, last

    etable,melty,temp, ! Create an element table

    esel,s,etab,melty,900 ! Select all elements from table above 500

    finish

    /solu ! Re-enter solution phase

    antype,,rest ! Restart analysis

    ekill,all ! Kill all selected elements

    esel,all



finish

*enddo

 

Tue, 10/21/2008 - 16:31 Permalink

Hi, I tried the code you posted, but it could not work correct. The problem happens here:

 
    etable,melty,temp, ! Create an element table

    esel,s,etab,melty,900 ! Select all elements from table above 500

    finish

    /solu ! Re-enter solution phase

    antype,,rest ! Restart analysis

    ekill,all ! Kill all selected elements

 It seems that the 'esel' is not valid after  'antype,,rest ', thus all the elements have been killed....

Could you please tell me how to deal with this? Thanks. 

Fri, 08/14/2009 - 16:41 Permalink