Problem with Adaptive LinearVariationalSolver

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

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!

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

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 for examples of how minimal code examples should look like.

1 Like