On Wed, 19 Jan 2011, Andre Smit wrote:
Robert - I'm trying to change the displacement (disp) in the traction function when the force stabilizes but for some reason the scope of disp within traction() appears different to that within calc_force(), even though disp is defined as global. Any ideas?
old_force = 0 def calc_force(pb, ts, state): ��� global disp,old_force ��� d = state() ��� pb.remove_bcs() ��� f = pb.evaluator.eval_residual(d) ��� pb.time_update() ��� f.shape = (pb.domain.mesh.n_nod, 3) ��� p = [] ��� for n in pb.domain.regions['Top'].vertices[0]: ������� p.append(f[n][2]) ��� p = nm.array(p) ��� if abs(old_force-p.sum()) < fvar: ������� my_output(disp,",",p.sum()) ������� disp -= ddisp ��� old_force=p.sum()
def traction(ts, coors, bc=None): ��� global disp ��� #disp = -(ts.dt*(ts.step+1)) ��� print "traction disp: ", disp ��� val = nm.empty_like(coors[:,0]) ��� val.fill(disp) ��� return val
I would use brute force:
globals()['disp'] = ...
You cannot really change value of a global that is immutable (IMHO)... A common idiom is to use list instead, like:
disp = [0]
def traction(ts, coors, bc=None): disp[0] = ...
What is the meaning of 'smix' stiffness, for strain rate zero?
I'm not sure.
That might be the problem causing the oscillations...
r.