Is there any function similar to FunctionAssigner that works with different meshes?

Hello everyone,

I am trying to assign a function defined on a mesh (e.g. a unit square mesh) to another function defined on another mesh (half of the unit squaremesh with the same mesh resolution and same type and order of the element as the previous function).
I try using the FunctionAssigner but this only work with functions defined on the same mesh. So, I would like to ask if there is any other functionalities that extend the FunctionAssigner ability to make the assignment possible with function defined on different meshes?

ps. I would like to preserve the connection between the assigning function and the receiving function as I get from the FunctionAssigner accordingt to the below code and picture.

from fenics import *
from fenics_adjoint import *
import time

mesh = UnitSquareMesh(256, 256)
V = FunctionSpace(mesh, "CG", 1)
VV = VectorFunctionSpace(mesh, "CG", 1)

# Define function
vv = Function(VV)
u0 = Function(V)
u1 = Function(V)

# Assign mixed function from two scalar functions using FunctionAssigner
assigner = FunctionAssigner(VV, [V, V])
t0 = time.time()
assigner.assign(vv, [u0, u1])
ta1 = time.time() - t0

tape = get_working_tape()
tape.visualise()

function_connection
Thank you very much
Phuris

There is no functionality with dolfin-adjoint for cross mesh assignment. Hopefully, in the future this might supported, with the MeshView functionality recently added to dolfin. However this is not on anyone’s list of priorities.

What you could do is to use the full mesh for both problems, using A.ident_zeros() on the assembled matrix to make sure the matrix is invertible if only consisting of parts of the mesh.
This method is for instance used to project facet-normals (How to plot normal unit vector of faces in a 2D mesh?) and compute mesh curvature (How to compute curvature of a boundary)

Thank a lot for your help.

Regarding to your reply,

Does this mean the dolfin-adjoint now support the mixed dimensional assembler?

No, it does not.
What i meant is that since this feature is in dolfin, it would be natural to extend dolfin-adjoint. However, this requires an effort, and Im not sure who has the time for this as of now.

Also, I would like to clarify a bit more on this,

So, with this, it would be possible to solve a variational problem on part of the full mesh right?

This means that you can solve problems on a sub space og your mesh, with the full function space, for instance, solving an eq on half of the mesh. Note that this is only properly supported for the same co dimension, as an interface gradient in 2D and 3D differs.

1 Like

thank you again for your help. I think this is what I am looking for.

Dear Dokken,

Is it also possible to directly apply the ident_zeros() with nonlinear variational problem (with mixed-element)? I think in this case, the nonlinear problem needs to be solved using the lower level solver (e.g. Picard iteration or Newton method at algebraic equation, ref), but I am not sure if there is easier way to do this.

I am then quite certain you need to create your own custom newton solver, see for instance: Custom Newton Solver problem with Dirichlet conditions

1 Like

Thanks again for your help.