### Error in adapting non-linear variational problem while using AdaptiveNonlinearVariationalSolver

154

views

0

I am trying to solve a coupled set of equations where I solve the first equation using AdaptiveNonlinearVariationalSolver and the second using NonlinearVariationalSolver. after each solution I update the problem by adapting it to new mesh. The code causing the error could be found here:

```
# Define the non-linear variational problems for phase field and displacement
problem_u = NonlinearVariationalProblem(R_u, uh, BC_u, J_u)
problem_d = NonlinearVariationalProblem(R_d, dh, BC_d, J_d)
# Define the solvers for the non-linear variational problems
solver_u = NonlinearVariationalSolver(problem_u)
M = dh*dx()
tol_M = 1.0e-6
solver_d = AdaptiveNonlinearVariationalSolver(problem_d,M)
# Integrate in time
while step < max_steps:
mh = MeshHierarchy(mesh)
if step < 51:
dirichlet_val_u_2.t_y = 1.0e-4*step
else:
dirichlet_val_u_2.t_y = 5.0e-3+1.0e-5*(step-50)
it = 0
# Iterate while solution is converged
while True:
# Solve phase field
solver_d.solve(tol_M)
# dh_lb.assign( dh )
check = True
if check:
print('in check')
#mh = mh.refine(cell_markers)
# adapt to the refined mesh
dx = Measure("dx",domain = mh.finest())
ds = Measure("ds",domain = mh.finest())
adapt(uh,mh.finest())
adapt(uh_prev,mh.finest())
adapt(problem_u, mh.finest())
uh_prev = uh_prev.child()
uh = uh.child()
problem_u = problem_u.child()
solver_u = NonlinearVariationalSolver(problem_u.leaf_node())
adapt(dh,mh.finest())
adapt(dh_prev,mh.finest())
adapt(problem_d, mh.finest())
dh_prev = dh_prev.child()
dh = dh.child()
M = dh*dx()
problem_d = problem_d.child()
solver_d = AdaptiveNonlinearVariationalSolver(problem_d.leaf_node(),M)
#adapt(mesh,cell_markers)
mesh = mesh.child()
print('out of check')
diff_d = norm( dh.vector() - dh_prev.vector() )/norm( dh.vector())
# Solve variational problem
solver_u.solve()
diff_u = norm( uh.vector() - uh_prev.vector() )/norm( uh.vector())
diff = diff_d + diff_u
print ('Difference in fields: %.2e (d: %.2e, u: %.2e )' +\
'Step: %i Iteration: %i Eta: %.2e' ) % (diff,diff_d,diff_u,step,it,eta)
uh_prev.assign( uh )
dh_prev.assign( dh )
uh.rename('displacement','displacement')
dh.rename('phase_field','phase_field')
```

When I try to adapt the solver I get the following error:```
File "adaptive_non_linear_solver.py", line 347, in <module>
solver_d = AdaptiveNonlinearVariationalSolver(problem_d.leaf_node(),M)
.
.
.
.
*** Error: Unable to generate forms required for error control.
*** Reason: Unknown problem type ("<dolfin.cpp.fem.NonlinearVariationalProblem; proxy of <Swig Object of type 'std::shared_ptr< dolfin::NonlinearVariationalProblem > *' at 0x7fc5702661b0> >").
```

Any suggestions as to how should we update the problem?
Community: FEniCS Project

### 1 Answer

0

You're using a MixedFunctionSpace (coupled equations), so try M = dh[0]*dx() (cf. https://www.allanswered.com/post/nvrm/adaptive-solver-with-multiple-unknowns/)

Please login to add an answer/comment or follow this question.