# How to create test and trial functions for MixedFunctionSpace?

**URL:** <https://fenicsproject.discourse.group/t/how-to-create-test-and-trial-functions-for-mixedfunctionspace/3349>\
**Category:** variational formulation\
**Created:** [May 28, 2020, 1:49pm UTC](https://fenicsproject.discourse.group/t/how-to-create-test-and-trial-functions-for-mixedfunctionspace/3349 "2020-05-28T13:49:36Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![cdaversin](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/cdaversin/32/44_2.png) [@cdaversin](https://fenicsproject.discourse.group/u/cdaversin)\
**Post date:** [May 29, 2020, 8:22am UTC](https://fenicsproject.discourse.group/t/how-to-create-test-and-trial-functions-for-mixedfunctionspace/3349/5 "2020-05-29T08:22:16Z")

</div>

Hi,

First of all, you mention using various methods and getting various errors without more details. That might be helpful for people trying to reproduce the issue.

To answer the main question, the way you define test and trial functions from a `MixedFunctionSpace` is correct.

Some comments on your code :  
1- I recommend using MeshView instead of SubMesh, using directly the cell `MeshFunction` regions :

```auto
submeshfluid = MeshView.create(regions, 1)
submeshsolid = MeshView.create(regions, 2)

```

2- I don’t see why do you define `fluid_regions` and `solid_regions`. Since these `MeshFunction`s are both set to zero, it doesn’t make sense in the `Measure`s `dxf` and `dxs` you define later. Plus note that this way of define the `Measure` is deprecated (you should get a warning saying exactly that). If you want to define the `Measure`s corresponding to these submeshes, you should use :

```auto
dxf = Measure("dx", domain=submeshfluid)
dxs = Measure("dx", domain=submeshsolid)

```

Same remark for the `ds` measures for the submeshes boundaries :

```auto
dsf = Measure("ds", domain=submeshfluid, subdomain_data = fluid_boundaries)
dss = Measure("ds", domain=submeshsolid, subdomain_data = solid_boundaries)

```

3- The Jacobian has to be defined by blocks. Note that it can be automatically computed by the `solve` function using `solve(F == 0, w, bcs)`, but if you want to define it manually then I suggest you have a look to this [recent post](https://fenicsproject.discourse.group/t/mixed-dimensional-branch-problem-with-mixed-nonlinear-variational-solver/3324).

---

_[View the full topic](https://fenicsproject.discourse.group/t/how-to-create-test-and-trial-functions-for-mixedfunctionspace/3349)._
