# '\<' not supported between instances of 'Mesh' and 'Mesh'

**URL:** <https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187>\
**Category:** mesh\
**Created:** [September 28, 2020, 2:38am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187 "2020-09-28T02:38:30Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Orangewang](https://avatars.discourse-cdn.com/v4/letter/o/eada6e/32.png) [@Orangewang](https://fenicsproject.discourse.group/u/Orangewang)\
**Post date:** [September 28, 2020, 2:38am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/1 "2020-09-28T02:38:30Z")

</div>

Hello,  
i’am studying the tourial example:[https://fenicsproject.org/pub/tutorial/python/vol1/ft08\_navier\_stokes\_cylinder.py](https://fenicsproject.org/pub/tutorial/python/vol1/ft08_navier_stokes_cylinder.py)  
and i want to achieve the vibration of the cylinder experiencing the in-folw,

```python
class Structure(SubDomain):
    def inside(self, x, on_boundary):
        return (x[0] - 0.2) **2 + (x[1] - 0.2)** 2 < 0.01 + DOLFIN_EPS

    # Create mesh

mesh = RectangleMesh(Point(0, 0), Point(2.2, 0.41), 600, 200)

# Create sub domain markers and mark everaything as 0
sub_domains = MeshFunction("size_t", mesh, mesh.topology().dim())
sub_domains.set_all(0)

# Mark structure(cylinder) domain as 1
structure = Structure()
structure.mark(sub_domains, 1)

# Extract sub meshes
fluid_mesh = SubMesh(mesh, sub_domains, 0)
structure_mesh = SubMesh(mesh, sub_domains, 1)

```

and i just reuse the function space and here the errors accurs:

```python
Traceback (most recent call last):
  File "/mnt/c/Users/wangc/Desktop/pythonProject/moving_rec.py", line 112, in <module>
    - dot(f, v) * dx
  File "/usr/lib/python3/dist-packages/ufl/measure.py", line 437, in __rmul__
    domains = extract_domains(integrand)
  File "/usr/lib/python3/dist-packages/ufl/domain.py", line 355, in extract_domains
    return sorted(join_domains(domainlist))
TypeError: '<' not supported between instances of 'Mesh' and 'Mesh'

```

please help me

---

<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:** [September 28, 2020, 6:41am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/2 "2020-09-28T06:41:40Z")

</div>

As you are not interested in the deformation of you object, I would really recommend to use a mesh Which only contains the fluid domain. You can use Gmsh to create such a mesh, see for instance the tutorial I have created at my [homepage](https://jsdokken.com/converted_files/tutorial_pygmsh.html) . To load this mesh into dolfin, see for instance [Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio](https://fenicsproject.discourse.group/t/transitioning-from-mesh-xml-to-mesh-xdmf-from-dolfin-convert-to-meshio/412/79) or [Converter from GMSH to XDMF (with physical groups)](https://fenicsproject.discourse.group/t/converter-from-gmsh-to-xdmf-with-physical-groups/2779).

Also, please supply minimal working code examples that reproce your error message, as described in [Read before posting: How do I get my question answered?](https://fenicsproject.discourse.group/t/read-before-posting-how-do-i-get-my-question-answered/21)

---

<div class="post-metadata">

**Author:** ![Orangewang](https://avatars.discourse-cdn.com/v4/letter/o/eada6e/32.png) [@Orangewang](https://fenicsproject.discourse.group/u/Orangewang)\
**Post date:** [September 28, 2020, 7:09am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/3 "2020-09-28T07:09:22Z")

</div>

Thank you for your reply, I am just new to the fenics software, and there are still many things I don’t understand. Thanks again for your reply, but I want to know why the flow field mesh does not change in the following code:

```python
from __future__ import print_function
from fenics import *
from mshr import *
import numpy as np
import matplotlib.pyplot as plt

T = 0.02 # final time
num_steps = 100 # number of time steps
dt = T / num_steps # time step size
mu = 0.001 # dynamic viscosity
rho = 1 # density

# Structure sub domain
class Structure(SubDomain):
    def inside(self, x, on_boundary):
        return (x[0] - 0.2) **2 + (x[1] - 0.2)** 2 < 0.01 + DOLFIN_EPS

mesh = RectangleMesh(Point(0, 0), Point(2.2, 0.41), 100, 200)

# Create sub domain markers and mark everaything as 0
sub_domains = MeshFunction("size_t", mesh, mesh.topology().dim())
sub_domains.set_all(0)

# Mark structure(cylinder) domain as 1
structure = Structure()
structure.mark(sub_domains, 1)

# Extract sub meshes
fluid_mesh = SubMesh(mesh, sub_domains, 0)
structure_mesh = SubMesh(mesh, sub_domains, 1)

# Define function spaces

V = VectorFunctionSpace(mesh, 'P', 2)
Q = FunctionSpace(mesh, 'P', 1)

# Define boundaries
inflow = 'near(x[0], 0)'
outflow = 'near(x[0], 2.2)'
walls = 'near(x[1], 0) || near(x[1], 0.41)'
cylinder = Structure()

# Define inflow profile
inflow_profile = ('4.0*1.5*x[1]*(0.41 - x[1]) / pow(0.41, 2)', '0')

# Define boundary conditions
bcu_inflow = DirichletBC(V, Expression(inflow_profile, degree=2), inflow)
bcu_walls = DirichletBC(V, Constant((0, 0)), walls)
bcu_cylinder = DirichletBC(V, Constant((0, 0)), cylinder)
bcp_outflow = DirichletBC(Q, Constant(0), outflow)
bcu = [bcu_inflow, bcu_walls, bcu_cylinder]
bcp = [bcp_outflow]

# Define trial and test functions
u = TrialFunction(V)
v = TestFunction(V)
print(type(v))
p = TrialFunction(Q)
q = TestFunction(Q)

# Define functions for solutions at previous and current time steps
u_n = Function(V)
u_ = Function(V)
p_n = Function(Q)
p_ = Function(Q)

# Define expressions used in variational forms
U = 0.5 * (u_n + u)
n = FacetNormal(mesh)
f = Constant((0, 0))
k = Constant(dt)
mu = Constant(mu)
rho = Constant(rho)

# Define symmetric gradient
def epsilon(u):
    return sym(nabla_grad(u))

# Define stress tensor
def sigma(u, p):
    return 2 * mu * epsilon(u) - p * Identity(len(u))

# Define variational problem for step 1
F1 = rho * dot((u - u_n) / k, v) * dx \
     + rho * dot(dot(u_n, nabla_grad(u_n)), v) * dx \
     + inner(sigma(U, p_n), epsilon(v)) * dx \
     + dot(p_n * n, v) * ds - dot(mu * nabla_grad(U) * n, v) * ds \
     - dot(f, v) * dx
a1 = lhs(F1)
L1 = rhs(F1)

# Define variational problem for step 2
a2 = dot(nabla_grad(p), nabla_grad(q)) * dx
L2 = dot(nabla_grad(p_n), nabla_grad(q)) * dx - (1 / k) * div(u_) * q * dx

# Define variational problem for step 3
a3 = dot(u, v) * dx
L3 = dot(u_, v) * dx - k * dot(nabla_grad(p_ - p_n), v) * dx

# Assemble matrices
A1 = assemble(a1)
A2 = assemble(a2)
A3 = assemble(a3)

# Apply boundary conditions to matrices
[bc.apply(A1) for bc in bcu]
[bc.apply(A2) for bc in bcp]

# Create XDMF files for visualization output
xdmffile_u = XDMFFile('moving_rec/velocity.xdmf')
xdmffile_p = XDMFFile('moving_rec/pressure.xdmf')

# Create time series (for use in reaction_system.py)
timeseries_u = TimeSeries('moving_rec/velocity_series')
timeseries_p = TimeSeries('moving_rec/pressure_series')

t = 0
for n in range(num_steps):
    # Update current time
    t += dt

    # Step 1: Tentative velocity step
    b1 = assemble(L1)
    [bc.apply(b1) for bc in bcu]
    solve(A1, u_.vector(), b1, 'bicgstab', 'hypre_amg')

    # Step 2: Pressure correction step
    b2 = assemble(L2)
    [bc.apply(b2) for bc in bcp]
    solve(A2, p_.vector(), b2, 'bicgstab', 'hypre_amg')

    # Step 3: Velocity correction step
    b3 = assemble(L3)
    solve(A3, u_.vector(), b3, 'cg', 'sor')

    xdmffile_u.write(u_, t)
    xdmffile_p.write(p_, t)

    # Save nodal values to file
    timeseries_u.store(u_.vector(), t)
    timeseries_p.store(p_.vector(), t)

    # Plot solution
    plot(u_, title='Velocity')
    # plt.show()
    plot(p_, title='Pressure')

    for x in structure_mesh.coordinates():
        x[1] += 0.1 * sin(100 * dt)

    # Move fluid mesh according to structure mesh
    ALE.move(fluid_mesh, structure_mesh)
    fluid_mesh.smooth()

    plot(fluid_mesh, title="Fluid")
    plt.show()

    # Update previous solution
    u_n.assign(u_)
    p_n.assign(p_)

    print('u max:', u_.vector().max())
    print(t)

```

thank you for your reply!

---

<div class="post-metadata">

**Author:** ![Orangewang](https://avatars.discourse-cdn.com/v4/letter/o/eada6e/32.png) [@Orangewang](https://fenicsproject.discourse.group/u/Orangewang)\
**Post date:** [September 28, 2020, 7:12am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/4 "2020-09-28T07:12:10Z")

</div>

and how can I calculate the pressure at the “structure\_mesh” boundary, I should use some mark function or others to achieves this. thank you for your reply!

---

<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:** [September 28, 2020, 7:24am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/5 "2020-09-28T07:24:04Z")

</div>

I already pointed this out in [Vortex induced vibration (cylinder vibration)](https://fenicsproject.discourse.group/t/vortex-induced-vibration-cylinder-vibration/4181/7)

---

<div class="post-metadata">

**Author:** ![Orangewang](https://avatars.discourse-cdn.com/v4/letter/o/eada6e/32.png) [@Orangewang](https://fenicsproject.discourse.group/u/Orangewang)\
**Post date:** [September 28, 2020, 7:36am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/6 "2020-09-28T07:36:08Z")

</div>

Hi， Thank you very much for the reply. But I still have confused that in this expression:“assemble(p\*n[1]\*ds(cylindermarker)” , I know the p represents the pressure and the ds represents the edge of the cylinder. But I don’t known how can I get the n[1] and the ds, what shoud I use some certain functions to achieve this!  
Thank you very much for your reply yesterday and you take some time to answer my questions!

---

<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:** [September 28, 2020, 7:39am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/7 "2020-09-28T07:39:04Z")

</div>

n[1] can be gotten by using the `n = FacetNormal(mesh)` command.  
The `ds` can be defined as `ds=Measure("ds", subdomain_data=facet_function)`,  
where facet\_function is a `MeshFunction containing the tagged entities of the boundaries,  
In the post above, I have shown how to create a mesh and corresponding facet tags, as well as linking you to how to load these tags into dolfin.

---

<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:** [September 28, 2020, 7:44am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/8 "2020-09-28T07:44:27Z")

</div>

The reason that the code you posted above does not work, is that you are not applying the correct boundary conditions for the pressure correction step. As for instance explained is this paper: [https://www.sciencedirect.com/science/article/pii/S0045782520303145](https://www.sciencedirect.com/science/article/pii/S0045782520303145)  
when you have Dirichlet conditions for the velocity in the original equation, you need a homogeneous Neumann condition at this boundary in the pressure correction step. This is not applied in your code, as the boundary of the obstacle is not a boundary of the mesh.

---

<div class="post-metadata">

**Author:** ![Orangewang](https://avatars.discourse-cdn.com/v4/letter/o/eada6e/32.png) [@Orangewang](https://fenicsproject.discourse.group/u/Orangewang)\
**Post date:** [September 29, 2020, 1:06am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/9 "2020-09-29T01:06:53Z")

</div>

Hello，Professor Dokken.  
I have run the demo “navier-stokes-multimesh-zenodo”, but the program run with errors:

```python
Traceback (most recent call last):
  File "/mnt/c/Users/wangc/Desktop/try_1/test.py", line 47, in <module>
    geo_filename="mesh.geo", msh_filename="mesh.msh", verbose=False)
  File "/usr/local/lib/python3.6/dist-packages/pygmsh/helpers.py", line 134, in generate_mesh
    p.returncode
AssertionError: Gmsh exited with error (return code 1).

```

I cannot figure out what’s wrong with it,thank you for your reply!

---

<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:** [September 29, 2020, 7:32am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/10 "2020-09-29T07:32:36Z")

</div>

For me to be able to help, please tell me which file you are running.

---

<div class="post-metadata">

**Author:** ![Orangewang](https://avatars.discourse-cdn.com/v4/letter/o/eada6e/32.png) [@Orangewang](https://fenicsproject.discourse.group/u/Orangewang)\
**Post date:** [September 29, 2020, 7:56am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/11 "2020-09-29T07:56:19Z")

</div>

Thank you for your reply,Professor Dokken.  
In this morning, I found a example in [https://github.com/camilobayonaroa/FenicsFSI-NCMM](https://github.com/camilobayonaroa/FenicsFSI-NCMM). I am reading the code and find out what kind method I will use. If there are any further questions, I will ask for advice, thank you very much for your reply. Thank you !

---

<div class="post-metadata">

**Author:** ![Orangewang](https://avatars.discourse-cdn.com/v4/letter/o/eada6e/32.png) [@Orangewang](https://fenicsproject.discourse.group/u/Orangewang)\
**Post date:** [September 30, 2020, 9:09am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/12 "2020-09-30T09:09:37Z")

</div>

Hello,Professor Dokken. When I run the file “turek\_benchmark \creat\_meshes.py” in [https://zenodo.org/record/3564206#.X3GyK5rTVo9](https://zenodo.org/record/3564206#.X3GyK5rTVo9), the program run with errors:

```python
/usr/local/lib/python3.6/dist-packages/pygmsh/built_in/geometry.py:209: UserWarning: add_physical_line() is deprecated. use add_physical() instead.
  warnings.warn("add_physical_line() is deprecated. use add_physical() instead.")
/usr/local/lib/python3.6/dist-packages/pygmsh/built_in/geometry.py:215: UserWarning: add_physical_surface() is deprecated. use add_physical() instead.
  "add_physical_surface() is deprecated. use add_physical() instead."
Traceback (most recent call last):
  File "/usr/local/bin/gmsh", line 6, in <module>
    import gmsh
ModuleNotFoundError: No module named 'gmsh'
Traceback (most recent call last):
  File "/mnt/c/Users/wangc/Desktop/RL/navier-stokes-multimesh-zenodo/navier-stokes-multimesh-2018-dokken-zenodo/optimal_layout/create_meshes.py", line 104, in <module>
    obstacle_mesh(res)
  File "/mnt/c/Users/wangc/Desktop/RL/navier-stokes-multimesh-zenodo/navier-stokes-multimesh-2018-dokken-zenodo/optimal_layout/create_meshes.py", line 92, in obstacle_mesh
    geo_filename="mesh_1.geo")
  File "/usr/local/lib/python3.6/dist-packages/pygmsh/helpers.py", line 134, in generate_mesh
    p.returncode
AssertionError: Gmsh exited with error (return code 1).

```

could you help me! thank you so much!

---

<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:** [September 30, 2020, 9:13am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/13 "2020-09-30T09:13:07Z")

</div>

You need to install gmsh to be able to create the meshes.  
In the `README.md` in the zip, you find instructions on how to get the correct dependencies using docker:

```auto
# Navier-Stokes with the multimesh finite element method.

This repository consists of the examples published in the paper:
*A multimesh finite element method for the Navier-Stokes equations based on projection methods* by J.S. Dokken, A. Johansson, A. Massing and S. W. Funke.

## Installation

To get a dolfin image, using the MultiMesh uflacs implementation, there is a docker image [available](https://hub.docker.com/r/dokken92/multimesh-uflacs/dockerfile).
To download it, run `docker pull dokken92/multimesh-uflacs`.

```

---

<div class="post-metadata">

**Author:** ![xliu24](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/xliu24/32/2053_2.png) [@xliu24](https://fenicsproject.discourse.group/u/xliu24)\
**Post date:** [January 27, 2022, 3:12am UTC](https://fenicsproject.discourse.group/t/not-supported-between-instances-of-mesh-and-mesh/4187/14 "2022-01-27T03:12:41Z")

</div>

Hi there, did you solve the problem in tutorial code?  
I have the same issue at this line `- dot(f, v)*dx`

```auto
  File "/fenics2018/lib/python3.6/site-packages/ufl/measure.py", line 437, in __rmul__
    domains = extract_domains(integrand)
  File "/fenics2018/lib/python3.6/site-packages/ufl/domain.py", line 351, in extract_domains
    return sorted(join_domains(domainlist))
TypeError: '<' not supported between instances of 'Mesh' and 'Mesh'

```

If you’ve debugged, could you share the solution? Thanks vey much!
