# Problem with Adaptive LinearVariationalSolver

**URL:** <https://fenicsproject.discourse.group/t/problem-with-adaptive-linearvariationalsolver/5831>\
**Category:** Errors\
**Created:** [May 19, 2021, 2:22pm UTC](https://fenicsproject.discourse.group/t/problem-with-adaptive-linearvariationalsolver/5831 "2021-05-19T14:22:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Chikitkin](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/alexander_chikitkin/32/2532_2.png) [@Alexander\_Chikitkin](https://fenicsproject.discourse.group/u/Alexander_Chikitkin)\
**Post date:** [May 19, 2021, 2:22pm UTC](https://fenicsproject.discourse.group/t/problem-with-adaptive-linearvariationalsolver/5831/1 "2021-05-19T14:22:06Z")

</div>

Hi, everyone!  
I am trying to use adaptive mesh refinement. I started with example  
[https://fenicsproject.org/olddocs/dolfin/1.3.0/python/demo/documented/auto-adaptive-poisson/python/documentation.html](https://fenicsproject.org/olddocs/dolfin/1.3.0/python/demo/documented/auto-adaptive-poisson/python/documentation.html)

it works.  
In my case I use combined functional space and may be for this reason I get **Replacement expressions must have the same shape as what they replace.**  
error in AdaptiveLinearVariationalSolver.  
Here the main part of the code

UE0 = FiniteElement(“N2curl”, tetrahedron, 1)  
UE1 = FiniteElement(“N2curl”, tetrahedron, 1)

U\_nh1 = FunctionSpace(mesh, UE0 \* UE1)

U = TrialFunction(U\_nh1)  
(U\_re, U\_im) = split(U)

V = TestFunction(U\_nh1)  
(V\_re, V\_im) = split(V)

Dr\_bc0 = DirichletBC(U\_nh1.sub(0), E\_zer, boundaries, 1)  
Dr\_bc1 = DirichletBC(U\_nh1.sub(1), E\_zer, boundaries, 1)

n = FacetNormal(mesh)  
dx = Measure(“dx”, domain = mesh)  
ds = Measure(“ds”, domain = mesh, subdomain\_data = boundaries)

A\_C\_form = inner(curl(U\_re), curl(V\_re))\*dx + inner(curl(U\_im), curl(V\_im))\*dx  
A\_L\_form = inner(U\_re, V\_re)\*dx + inner(U\_im, V\_im)\*dx  
A\_Z\_form = inner(cross(n,U\_re), cross(n,V\_im))\*ds(2) + inner(cross(n,U\_re), cross(n,V\_im))\*ds(3) -  
inner(cross(n,U\_im), cross(n,V\_re))\*ds(2) - inner(cross(n,U\_im), cross(n,V\_re))\*ds(3)

import time

Freq = []  
S11\_dB = []  
S21\_dB = []  
times\_direct = []

for fr in [2050]:  
print(‘Start computation for frequency {0:5.2e} GHz’.format(1e-3 \* fr))

```
start = time.time()
k0 = 2*pi*fr*1E+6*sqrt(e0*m0)
A_form = A_C_form - k0*k0*A_L_form + k0 * A_Z_form

b_E_form = inner(E_cxl, V_im)*ds(2)

b_form = 2 * k0 * b_E_form
X = Function(U_nh1)
(X_re, X_im) = split(X)

goal = inner(X, X)*dx

problem = LinearVariationalProblem(A_form, b_form, X, [Dr_bc0, Dr_bc1])
solver = AdaptiveLinearVariationalSolver(problem, goal)
solver.parameters["linear_solver"] = 'mumps'
solver.parameters["error_control"]["dual_variational_solver"]["linear_solver"] = "mumps"
solver.solve(tol = 1e-3)
solver.summary()
end = time.time()
times_direct.append(end - start)
print('Time = {0:5.2e} s'.format(times_direct[-1]))

```

The main lines: definition of the goal functional and the function call itself. Without refinement, e.g. with **LinearVariationalSolver** , the code works, so everything except these lines should be correct.  
Could anyone indicate the problem with **goal**?  
Thank you in advance!

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [May 19, 2021, 2:48pm UTC](https://fenicsproject.discourse.group/t/problem-with-adaptive-linearvariationalsolver/5831/2 "2021-05-19T14:48:21Z")

</div>

First note that you are using a very old documentation of the demo (v 1.3.0). The newest version can be found here: [Auto adaptive Poisson equation — DOLFIN documentation](https://fenicsproject.org/olddocs/dolfin/latest/python/demos/auto-adaptive-poisson/demo_auto-adaptive-poisson.py.html)

Please also format your code such that it is readable, i.e. using 3x` encapsulation.  
Also note that you need to produce a minimal code example, this implies that the code should be executable on any system using fenics, without having to add extra code. See [Read before posting: How do I get my question answered? - #4 by nate](https://fenicsproject.discourse.group/t/read-before-posting-how-do-i-get-my-question-answered/21/4) for examples of how minimal code examples should look like.
