Hi everyone,

I’m trying to solve some 2D linear elasticity inverse problem and have encountered with an issue I haven’t been able to work around yet. I have a formulation that uses vectorial test functions, but what I’m trying to compute is a 1D function. However, I’m not sure how to set this with a non-linear solver so I can compute this unknown function.

The minimal code goes as follow:

```
comm = MPI.COMM_WORLD
domain = dolfinx.mesh.create_rectangle(comm,
points=((0.0, 0.0), (30, 20)), n=(150, 100),
cell_type=mesh.CellType.triangle)
# create function spaces
vector_cg1 = ufl.VectorElement("CG", domain.ufl_cell(), 1)
V = fem.FunctionSpace(domain, vector_cg1) # for test space
scalar_cg1 = ufl.FiniteElement("CG", domain.ufl_cell(), 1)
V_tilde = fem.FunctionSpace(domain, scalar_cg1)
v = ufl.TestFunction(V)
mu_fun = fem.Function(V_tilde)
# u_sol = some data function
# bc = some boundary condition for mu_fun
def epsilon(w):
return (ufl.nabla_grad(w) + ufl.nabla_grad(w).T)/2
F = mu_fun*(ufl.inner(epsilon(u_sol),epsilon(v)) + ufl.nabla_div(u_sol)*ufl.nabla_div(v))*ufl.dx
problem = fem.petsc.NonlinearProblem(F, mu_fun, bcs=[bc])
solver = dolfinx.nls.petsc.NewtonSolver(comm, problem=problem)
solver.rtol = 1e-6
solver.convergence_criterion = "incremental"
solver.solve(mu_fun)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-55-1eea49d55584> in <module>
----> 1 num_its, converged = solver.solve(mu_fun)
2 if converged:
3 print(f" converged in {num_its} iterations")
2 frames
/usr/local/lib/python3.8/dist-packages/dolfinx/fem/assemble.py in set_bc(b, bcs, x0, scale)
316
317 """
--> 318 _cpp.fem.set_bc(b, bcs, x0, scale)
RuntimeError: Size mismatch between b and x0 vectors.
```

I imagine this error comes from the dimension difference between the function spaces I’m using. Is this kind of formulation supported? Any hint or preexisting demo could be of great help.

Thanks in advance!