# Determining whether Mixed Element or Mixed Function

**URL:** <https://fenicsproject.discourse.group/t/determining-whether-mixed-element-or-mixed-function/17620>\
**Category:** General\
**Created:** [May 16, 2025, 4:49pm UTC](https://fenicsproject.discourse.group/t/determining-whether-mixed-element-or-mixed-function/17620 "2025-05-16T16:49:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![EDE](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EDE](https://fenicsproject.discourse.group/u/EDE)\
**Post date:** [May 16, 2025, 4:49pm UTC](https://fenicsproject.discourse.group/t/determining-whether-mixed-element-or-mixed-function/17620/1 "2025-05-16T16:49:53Z")

</div>

Hello,

I am working on vibroacoustic simulation where elastic plate and air domain are coupled. After doing some research, I’ve noticed that there are two ways to define test functions and trial functions for each domain: one is by using mixed element, and the other one is by using mixed function.

I have tried to find some information regarding how to decide which approach to take, but I couldn’t, and I am wondering if anyone could clarify which approach is suitable or advantageous for which case.

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 16, 2025, 5:17pm UTC](https://fenicsproject.discourse.group/t/determining-whether-mixed-element-or-mixed-function/17620/2 "2025-05-16T17:17:13Z")

</div>

The mixedelement will merge everything into a single dofmap, making the access to do efficient block preconditioning harder.

If you use the `ufl.MixedFunctionSpace` you can get ufl to set up a block structured problem that one can exploit the structure (see for instance:  
[SNES solver interface for standard, block and nest systems by jorgensd · Pull Request #3648 · FEniCS/dolfinx · GitHub](https://github.com/FEniCS/dolfinx/pull/3648)) or the tests that have changed in that PR.

MixedFunctionSpace is also very useful when you have function spaces living on different meshes (a mesh and submesh of entities of the original mesh).

---

<div class="post-metadata">

**Author:** ![EDE](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EDE](https://fenicsproject.discourse.group/u/EDE)\
**Post date:** [May 17, 2025, 11:06am UTC](https://fenicsproject.discourse.group/t/determining-whether-mixed-element-or-mixed-function/17620/3 "2025-05-17T11:06:04Z")

</div>

Thank you, dokken!!

It seems like I should probably use mixed functionspace since it’s easier to access each block, and also I am dealing with different meshes.

Now, my current understanding is that mixed functionspace is simpy superior to mixedelement, but is there cases where mixedelement is actually advantageous, such as, for instance, the performance for less complicated models on a single mesh?

Thank you in advance for your advice!!

---

<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 17, 2025, 7:33pm UTC](https://fenicsproject.discourse.group/t/determining-whether-mixed-element-or-mixed-function/17620/4 "2025-05-17T19:33:27Z")

</div>

> [@EDE](#):
>
> Now, my current understanding is that mixed functionspace is simpy superior to mixedelement, but is there cases where mixedelement is actually advantageous, such as, for instance, the performance for less complicated models on a single mesh?

The current API, pre the aforementioned pull request (and a similar one for LinearProblem) is easier for mixedelement than for mixedfunctionspace.

It will hopefully change soon and then I think for most cases I would use mixedfunctionspace.

There might be a few problems (with direct solvers on small grids) where the data locality in the mixed map might result in a speedup

---

<div class="post-metadata">

**Author:** ![EDE](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EDE](https://fenicsproject.discourse.group/u/EDE)\
**Post date:** [May 20, 2025, 4:16pm UTC](https://fenicsproject.discourse.group/t/determining-whether-mixed-element-or-mixed-function/17620/5 "2025-05-20T16:16:44Z")

</div>

Dear dokken,

Thank you for the very insightful answer to my question.  
I will pay some attention in choosing which one to use for the time being, and I am looking forward to the future updates as well.

Thank you as always!!

---

<div class="post-metadata">

**Author:** ![EDE](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EDE](https://fenicsproject.discourse.group/u/EDE)\
**Post date:** [June 16, 2025, 3:26pm UTC](https://fenicsproject.discourse.group/t/determining-whether-mixed-element-or-mixed-function/17620/6 "2025-06-16T15:26:08Z")

</div>

@dokken  
Dear dokken,

I have a follow-up question regarding the use of Mixed Element and Mixed Function.  
I am modifying the below code using Mixed Function instead of Mixed Element.

> **[Reissner-Mindlin plates — Computational Mechanics Numerical Tours with FEniCSx](https://bleyerj.github.io/comet-fenicsx/intro/plates/plates.html)**

Upon calling fem.form, this error rises: ArityMismatch: Adding expressions with non-matching form arguments

Below is the simplified snippet of the code where Mixed Function is defined and error rises.

```python
deg=2
elw = basix.ufl.element("Lagrange", domain.topology.cell_name(), deg)
Vw = fem.functionspace(domain, elw)
elt = basix.ufl.element("Lagrange", domain.topology.cell_name(), deg, shape=(2,))
Vpt = fem.functionspace(domain, elt)
V=ufl.MixedFunctionSpace(Vw,Vpt)
w,u=ufl.TrialFunctions(V)
w_,u_=ufl.TestFunctions(V)

m_form = ufl.inner(w,w_)*dx + ufl.inner(u[0],u_[0])*dx
fem.form(m_form)

```

Would this be a case where only Mixed Element is allowed, or is there a way to do with Mixed Function?

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:** [June 16, 2025, 4:04pm UTC](https://fenicsproject.discourse.group/t/determining-whether-mixed-element-or-mixed-function/17620/7 "2025-06-16T16:04:15Z")

</div>

> [@EDE](#):
>
> ```auto
> V=ufl.MixedFunctionSpace(Vw,Vpt)
> w,u=ufl.TrialFunctions(V)
> w_,u_=ufl.TestFunctions(V)
> 
> m_form = ufl.inner(w,w_)*dx + ufl.inner(u[0],u_[0])*dx
> fem.form(m_form)
> 
> ```

You have to use `ufl.extract_block(m_form)` prior to calling `fem.form(…)`

---

<div class="post-metadata">

**Author:** ![EDE](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EDE](https://fenicsproject.discourse.group/u/EDE)\
**Post date:** [June 16, 2025, 4:19pm UTC](https://fenicsproject.discourse.group/t/determining-whether-mixed-element-or-mixed-function/17620/8 "2025-06-16T16:19:42Z")

</div>

Thank you very much–`ufl.extract_blocks` worked perfect!!
