### Mesh Not updating in Adaptive refinement while solving coupled equations

Hi, I am trying to solve coupled differential equations with staggered approach, for that I have tried to solved with adaptive refinement. Equation 1 is solved and mesh updated but Equation 2 is still solving o the previous mesh. I have used adapt(mesh.leaf_node()) to update the mesh. How can I resolve this issue.**Updated:** Sorry I have not given full information (I thought full code will be lengthy).**Problem:** equation 1 solved on updated mesh but equation 2 still solved on previous mesh why ?Figure 1: solution of equation 1 Figure 2: solution of equation 2

Thanks in advance

```
from dolfin import *
mesh = UnitSquareMesh(5,5)
V = FunctionSpace(mesh,'CG',1)
W = VectorFunctionSpace(mesh,'CG',1)
p , q = TrialFunction(V), TestFunction(V)
u , v = TrialFunction(W), TestFunction(W)
l_fac = 2
Gc = 2.7
l_o = l_fac*mesh.hmin()
l_o = Expression('l_o', l_o=l_o)
lmbda = 121.15e3
mu = 85.77e3
def epsilon(v):
return sym(grad(v))
def sigma(u):
return 2.0*mu*epsilon(u) + lmbda*tr(epsilon(u))*Identity(2)
def en_dens(u):
str_ele = 0.5*(grad(u) + grad(u).T)
IC = tr(str_ele)
ICC = tr(str_ele * str_ele)
return (0.5*lmbda*IC**2) + mu*ICC
class top(SubDomain):
def inside(self,x,on_boundary):
tol = 1e-10
return abs(x[1]-1.0) < tol and on_boundary
class bottom(SubDomain):
def inside(self,x,on_boundary):
tol = 1e-10
return abs(x[1]+0.0) < tol and on_boundary
Top = top()
Bottom = bottom()
u_Lx = Expression("t",t = 0.0)
bclx= DirichletBC(W.sub(0), Constant(0.0), Bottom)
bcly = DirichletBC(W.sub(1), Constant(0.0), Bottom)
bctx = DirichletBC(W.sub(1), u_Lx, Top)
bc_u = [bcly,bclx, bctx ]
u_old,u_conv, unew = Function(W),Function(W), Function(W)
alpha_old,alpha_conv = Function(V),Function(V)
# equation 1
E_du = ((1 - alpha_old)**2 + 1e-6)*inner(grad(v),sigma(u))*dx
# equation 2
E_alpha = ( Gc*l_o*inner(grad(p),grad(q))+\
((Gc/l_o) + 2.*en_dens(unew))*inner(p,q)-\
2.*en_dens(unew)*q)*dx
u = Function(W)
p = Function(V)
ndim = mesh.geometry().dim()
zero_v=Constant((0.,)*ndim)
f=zero_v
L = inner(f, v)*dx
problem_disp = LinearVariationalProblem(E_du,L,u,bc_u)
# error indicator
MF = en_dens(u)*dx
solver_disp = AdaptiveLinearVariationalSolver(problem_disp, MF)
solver_disp.parameters["error_control"]["dual_variational_solver"]["linear_solver"] = "cg"
solver_disp.parameters["error_control"]["dual_variational_solver"]["symmetric"] = True
min_load = 0.0
max_load = 1.0
deltaT = 1e-3
t = deltaT
ut = 1
TOL = 1e-6
while t <= max_load:
u_Lx.t=t*ut
if t > 0.005:
deltaT = 1e-4
u_old.assign(u_conv)
alpha_old.assign(alpha_conv)
iter = 1
toll = 1e-4
err = 1
maxiter = 100
while err > toll:
solver_disp.solve(TOL)
unew.assign(u.leaf_node())
adapt(mesh.leaf_node())
adapt(V.leaf_node(),mesh.leaf_node())
plot(mesh, key = 'mesh', title = 'updated mesh')
hm = mesh.hmin()
l_o = l_fac*hm
solve(lhs(E_alpha)==rhs(E_alpha),p)
print u.leaf_node().vector().array()
err_u = errornorm(u.leaf_node(),u_old, norm_type = 'l2', mesh = None)
err_alpha = errornorm(p,alpha_old, norm_type = 'l2', mesh = None)
err = max(err_u,err_alpha)
u_old.assign(u.leaf_node())
alpha_old.assign(p)
iter = iter + 1
if err < toll:
u_conv.assign(u.leaf_node())
alpha_conv.assign(p)
ux,uy = split(u.leaf_node())
plot(ux,key = 'ux',title = 'u_dispx')
plot(uy,key ='uy',title = 'u_dispy')
plot(p.leaf_node(),range_min = 0.,range_max = 1.,key = 'alpha',title = 'alpha%.4f'%(t))
interactive()
t+=deltaT
```

### 1 Answer

However, maybe you need to adapt the problem for equation 2 with regard to the adapted mesh. Something like

```
adapt(Eu, mesh.leaf_node())
Eu = Eu.child()
```

Thanks for the help

`plot(mesh.leaf_node(), key = 'mesh', title = 'updated mesh')`

to be sure to plot the adapted mesh. However, I think it is less confusing to use

```
adapt(mesh)
mesh=mesh.child()
```

so you don't have to deal with the leaf_node stuff at all.

Also there is propably still a

```
adapt(E_alpha,mesh.leaf_node())
E_alpha = E_alpha.child()
```

missing.

I am getting Error: in method 'adapt', argument 1 of type 'dolfin::ErrorControl const &'

```
.
.
.
problem2 = LinearVariationalProblem(lhs(E_alpha),rhs(E_alpha),p)
solver2 = LinearVariationalSolver(problem2)
.
.
.
adapt(mesh.leaf_node())
problem2 = adapt(problem2,mesh.leaf_node())
solver2.solve()
.
.
.
```

```
cell_markers = MeshFunction('bool', mesh)
cell_markers.set_all(False)
for cell in cells(mesh):
pp = cell.midpoint()
if en_dens(pp) >= 10:
cell_markers.set(cell,True)
```

but getting error: Invalid type conversion: <class 'dolfin.cpp.mesh.Point'> can not be converted to any UFL type.