How to create a MixedFunctionSpace with submesh

Dear all,
I am trying to use DolfinX to solve a problem with two different meshes.
I create the submesh from a cellmarker from gmsh.
The issue is when I try to create a function from the Mixed Function Space.
It says:

AttributeError: 'MixedFunctionSpace' object has no attribute '_cpp_object'

I cannot create a function from the space. Is this functionality not implemented in DolfinX or am I making some mistake.

Here is a MWE:

from dolfinx.fem import (Function, FunctionSpace, locate_dofs_geometrical)
from dolfinx.mesh import (create_unit_square, create_submesh,
                          locate_entities)
from ufl import (MixedFunctionSpace, FiniteElement)
from mpi4py import MPI

mesh = create_unit_square(MPI.COMM_WORLD, 10, 10)

def subdomain(x):
    return x[1] >= 0.5

cells_subdomain = locate_entities(mesh, mesh.topology.dim, subdomain)

submesh, vertex_map, geom_map = (mesh, mesh.topology.dim, cells_subdomain)

P1_mesh = FiniteElement("Lagrange", submesh.ufl_cell(), 1)
P1_submesh = FiniteElement("Lagrange", mesh.ufl_cell(), 1)

V_mesh = FunctionSpace(mesh, P1_mesh)
V_submesh = FunctionSpace(submesh, P1_submesh)
V = MixedFunctionSpace(V_mesh, V_submesh)

u = Function(V)

Than you so much for your help!
All the best

You may want to use GitHub - multiphenics/multiphenicsx: multiphenicsx - easy prototyping of multiphysics problems in FEniCSx (disclaimer: I am the author of that), or ping @jpdean if any of his branches are helpful for this case.

3 Likes

As Francesco mentioned, this is possible with the branches of FEniCSx I’ve been working on. If you are interested, please checkout GitHub - jpdean/mixed_domain_demos. However, this functionality is still a work in progress and has not yet been merged into main, so Multiphenicsx might be the better option for you.

Thanks,

Joe

3 Likes

Dear Francesco,
Thank you so much for your fast response!
I tried to study a bit multiphenicsx and also jpdean implementation of mixed element problems.
Unfortunately my background on applied math is not that vast.
Thus, I’d like to ask you some help.
On the MWE that I described on the post that I made, I was trying to create a Function Space that comprised both a variable defined on the whole domain, and a second one which was only defined on a subdomain. I was looking to implement on FEniCSx something that was closer to what was proposed on the latest development version of FEniCS and bumped on the fact that this is not available yet.
From what I understood, on your very nice tutorials of multiphenicsx, the proposed solution would be to create the subspaces and “bind” them through a mapping of the DOF’s. Then, create a newton solver object that could solve the problem.
Is that right?
Thank you so much!
All the best,
Murilo

Yeah. The technical description would be much more complicated, but basically if you look at multiphenicsx/tutorial_lagrange_multipliers_interface.ipynb at main · multiphenics/multiphenicsx · GitHub the key cell in that respect is

dofs_V1_Omega1 = dolfinx.fem.locate_dofs_topological(V1, subdomains.dim, cells_Omega1)
dofs_V2_Omega2 = dolfinx.fem.locate_dofs_topological(V2, subdomains.dim, cells_Omega2)
dofs_M_Gamma = dolfinx.fem.locate_dofs_topological(M, boundaries.dim, facets_Gamma)
restriction_V1_Omega1 = multiphenicsx.fem.DofMapRestriction(V1.dofmap, dofs_V1_Omega1)
restriction_V2_Omega2 = multiphenicsx.fem.DofMapRestriction(V2.dofmap, dofs_V2_Omega2)
restriction_M_Gamma = multiphenicsx.fem.DofMapRestriction(M.dofmap, dofs_M_Gamma)
restriction = [restriction_V1_Omega1, restriction_V2_Omega2, restriction_M_Gamma]

which enables multiphenicsx to determine which dofs are part of subdomain 1, subdomain 2 and interface, respectively.

1 Like

Hello Francescon,

I took a look at this page in your tutorial (tutorial_block_poisson) and this one (tutorial_navier_stokes). It looks you developed a package based on fenicsx to solve a coupled system of equations. Is this one application of your package? I am looking for a way to impose two coupled equation and solve the nonlinear system simultaneously in fenicsx. It looks your package is exactly what I am looking for and your tutorial contains a lot of resouces including the implementation by just using fenicsx and also by using your package. Am I correct? Thanks!

Yes, that is correct. I imagine that your equations involve restricting unknowns to some subdomain: in that case, please have a look at the third tutorial too.

Right! Thank you very much!