# Updating function with its largest time history value at every material point

I want to update the value of Hold variable with its largest time history value at every material point. However the output of the code below seems to take not the largest but the last value of the Hold in the time history.

``````V = FunctionSpace(mesh, 'CG', 1)
W = VectorFunctionSpace(mesh, 'CG', 1)
WW = FunctionSpace(mesh, 'DG', 0)

unew, uold = Function(W), Function(W)
pnew, pold, Hold, Holdtr = Function(V), Function(V), Function(V), Function(V)

def psi(u):
return 0.5*(lmbda+mu)*(0.5*(tr(epsilon(u))+abs(tr(epsilon(u)))))**2+\
mu*inner(dev(epsilon(u)),dev(epsilon(u)))
def H(Holdtr,Hold):
return conditional(lt(Hold,Holdtr),Holdtr,Hold)

Hold.assign(project(psi(uold), WW))
Holdtr.assign(project(psi(uold), WW))

while err_u >= toll:
iter_u += 1
solver_disp.solve()
err_u = errornorm(unew,uold,norm_type = 'l2',mesh = None)
uold.assign(unew)

Holdtr.assign(project(psi(unew), WW))
if conditional(gt(Holdtr,Hold),1,0):
Hold.assign(project(psi(unew), WW))
``````

What I need to do to impose this condition?

You can more simply use

``````from ufl import Max
Hold.assign(project(Max(psi(uold), Hold), WW))
``````
1 Like