Welcome to ask.woodem.org. You may post when you login through your GitHub account.

Add a relaxation step in my calculations

0 votes
31 views
asked Dec 11, 2018 by MaxWiebicke (500 points)

Hi,

is there a way to insert an additional step for relaxation purposes to the script we once wrote, Vaclav? Here is an MWE of the calculation procedure:

epsRate=1. # deformation rate (1/s)
# save the step we are in in the loop below
S.lab.step=-1
S.lab._setWritable('step')

S.engines=S.engines+[PyRunner(command='nextStep(S)',stepPeriod=0,label='nextStepEngine')]

S.lab.goals=[-0.006,-0.002]

def nextStep(S):
   if S.lab.step>=len(S.lab.goals): return
   if S.lab.step>=0:
     goal=S.lab.goals[S.lab.step]
     print('%s/%d: finished eps=%g (real %g)'%('oedo',S.lab.step,goal,S.cell.trsf[2,2]-1))
   S.lab.step+=1
   if S.lab.step>=len(S.lab.goals):
      print('Finished the simulation!')
      S.stop()
      return
   goal=S.lab.goals[S.lab.step]
   eps_zz=S.cell.trsf[2,2]-1

   S.cell.nextGradV=(-1 if eps_zz>goal else 1)*epsRate*Vector3(-.5,-.5,1).asDiagonal()
   t=abs(eps_zz-goal)/epsRate
   # print("time t", t)
   print('%s/%d: %g time to run (eps %g -> %g)'%('oedo',S.lab.step,t,eps_zz,goal))
   print('%s/%d: gradV = %s'%('oedo',S.lab.step,S.cell.nextGradV))
   S.lab.nextStepEngine.virtPeriod=t

nextStep(S)
S.run()

I would love to enter a step for relaxation after each loading is finished, but all my attempts failed so far, because I can't set a hard number of computation steps within the nextStep(S).

When the program is finished, however, I can just enter the following in the ipython terminal and it works like I intend it to:

S.cell.nextGradV=Vector3(0,0,0).asDiagonal()
S.run(20000)

Do you have any idea?

Thank you, Max

1 Answer

+1 vote
answered Dec 21, 2018 by eudoxos (49,070 points)
selected Jan 15 by MaxWiebicke
 
Best answer

Hi Max, you could (for instance) alter the call of nextStep, so that it first goes into relaxing state and does not move to the next goal until called next time. Like below. HTH, Vaclav

S.lab.relaxing=False
S.lab._setWritable('relaxing')

#...

def nextStep(S):
   # ...
   if S.lab.step>=0:
      if S.lab.relaxing: 
          S.lab.relaxing=True
          # call nextStep again in approx 2000 steps
          S.lab.nextStepEngine.virtPeriod=S.dt*2000 
          return
      S.lab.relaxing=False
      goal=S.lab.goals[S.lab.step]
      #...
   #...

 

commented Dec 21, 2018 by MaxWiebicke (500 points)

Great, thank you, Vaclav!
I'll try it asap.

Thank you for your help and have a nice christmas/holiday time,
Max

commented Jan 15 by MaxWiebicke (500 points)

Hi Vaclav, I finally got around to test your proposed solution.
I had to change the order to setting the true/false value of relaxing and to add a (0,0,0) velocity gradient, but know it works, see:

def nextStep(S):
# ....
   if S.lab.step>=0:
      if S.lab.relaxing:
         # call nextStep again in approx 2000 steps
         S.cell.nextGradV=Vector3(0,0,0).asDiagonal()
         S.lab.nextStepEngine.virtPeriod=S.dt*2000
         S.lab.relaxing=False
         return
      # ....

   S.lab.relaxing=True

Thank you for your help,
Max

...