# Circular mesh looks not okay

**URL:** <https://fenicsproject.discourse.group/t/circular-mesh-looks-not-okay/8794>\
**Category:** mesh\
**Created:** [July 16, 2022, 12:18pm UTC](https://fenicsproject.discourse.group/t/circular-mesh-looks-not-okay/8794 "2022-07-16T12:18:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonardo](https://avatars.discourse-cdn.com/v4/letter/l/e56c9b/32.png) [@leonardo](https://fenicsproject.discourse.group/u/leonardo)\
**Post date:** [July 16, 2022, 12:18pm UTC](https://fenicsproject.discourse.group/t/circular-mesh-looks-not-okay/8794/1 "2022-07-16T12:18:43Z")

</div>

I am trying to generate a circular mesh with `pygmsh`. This is the code:

```python
import pygmsh
import gmsh
import meshio

path = "/home/sphere/"

resolution = .0125

# An empty geometry
geometry = pygmsh.geo.Geometry()
# Create a model to add data to
model = geometry. __enter__ ()

# A circle centered at the origin and radius 1
circle = model.add_circle([0.0, 0.0, 0.0], 1.0, mesh_size=5*resolution) # meshes are always 3D, I will suppress the third component in case

# Sinchronize, before adding physical entities
model.synchronize()

# Tagging
model.add_physical(circle.curve_loop.curves, "circle")

# Generate the mesh
geometry.generate_mesh(dim=1)
gmsh.write(path+"circle_mesh.msh")
gmsh.clear()
geometry. __exit__ ()

def create_mesh(mesh, cell_type, prune_z = False):
    cells = mesh.get_cells_type(cell_type) # get the cells of some type: it will change!
    cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
    points = mesh.points[:,:2] if prune_z else mesh.points
    out_mesh = meshio.Mesh(points=points, cells={cell_type: cells}, cell_data={"name_to_read":[cell_data]})
    return out_mesh

# Using the above function, create line and "plane" mesh
mesh_from_file = meshio.read(path+"circle_mesh.msh")
line_mesh = create_mesh(mesh_from_file, "line", prune_z=True)
meshio.write(path+"circle_mesh.xdmf", line_mesh)

```

What Fenics sees is then:

![Schermata da 2022-07-16 14-14-46](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/4/4818b290b761431fc0831d309976fb8b2692d6e9.png)

What ParaView sees is:

![Schermata da 2022-07-16 14-16-39](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/d/d5b9c9bfb1ee87085128e5c364d83464cb725e6a.png)

How can I get rid of the “inner triangle” and have just a regular circle like Paraview displays it?

---

<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:** [July 16, 2022, 12:33pm UTC](https://fenicsproject.discourse.group/t/circular-mesh-looks-not-okay/8794/2 "2022-07-16T12:33:41Z")

</div>

What do you mean by

> [@leonardo](#):
>
> What Fenics sees is then:

Do you mean that if you call `plot(mesh)` you get this plot?  
How does a solution on the geometry look like when exported to Paraview as xdmf or pvd file?

---

<div class="post-metadata">

**Author:** ![leonardo](https://avatars.discourse-cdn.com/v4/letter/l/e56c9b/32.png) [@leonardo](https://fenicsproject.discourse.group/u/leonardo)\
**Post date:** [July 16, 2022, 1:04pm UTC](https://fenicsproject.discourse.group/t/circular-mesh-looks-not-okay/8794/3 "2022-07-16T13:04:25Z")

</div>

Yes, I used `plot(mesh_circle)`.

Here is an image of a constantly one function, using paraview, including the mesh too:

 ![Schermata da 2022-07-16 15-02-12](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/6/610b66db395ffcc96618dcd102adea07efa1a9cb.png)

It comes from the code:

```python

mesh_path = ...

mesh_circle = Mesh()
with XDMFFile(mesh_path + "circle_mesh.xdmf") as infile:
    infile.read(mesh_circle)

L1_S = FiniteElement("Lagrange", mesh_circle.ufl_cell(), 1)
V_S = FunctionSpace(mesh_circle, L1_S)

u = Function(V_S)
u.vector()[:]=1

vtkfile = File("u.pvd")

vtkfile << u

```

---

<div class="post-metadata">

**Author:** ![leonardo](https://avatars.discourse-cdn.com/v4/letter/l/e56c9b/32.png) [@leonardo](https://fenicsproject.discourse.group/u/leonardo)\
**Post date:** [July 16, 2022, 1:50pm UTC](https://fenicsproject.discourse.group/t/circular-mesh-looks-not-okay/8794/4 "2022-07-16T13:50:56Z")

</div>

As a follow up, here is a coarser version of the mesh:

![Schermata da 2022-07-16 15-50-02](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/1/15f322ea7b99e525ad46c43670f92327180c8f1c.png)

---

<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:** [July 16, 2022, 2:19pm UTC](https://fenicsproject.discourse.group/t/circular-mesh-looks-not-okay/8794/5 "2022-07-16T14:19:25Z")

</div>

I think this is simply a bug in plotting the mesh, as both the integration area (circumference) and the function `u` is correctly projected with the following code:

```python
from pickletools import uint2
import pygmsh
import gmsh
import meshio

path = "./"

resolution = .0125

# An empty geometry
geometry = pygmsh.geo.Geometry()
# Create a model to add data to
model = geometry. __enter__ ()

# A circle centered at the origin and radius 1
circle = model.add_circle([0.0, 0.0, 0.0], 1.0, mesh_size=5*resolution) # meshes are always 3D, I will suppress the third component in case

# Sinchronize, before adding physical entities
model.synchronize()

# Tagging
model.add_physical(circle.curve_loop.curves, "circle")

# Generate the mesh
geometry.generate_mesh(dim=1)
gmsh.write(path+"circle_mesh.msh")
gmsh.clear()
geometry. __exit__ ()

def create_mesh(mesh, cell_type, prune_z = False):
    cells = mesh.get_cells_type(cell_type) # get the cells of some type: it will change!
    cell_data = mesh.get_cell_data("gmsh:physical", cell_type)
    points = mesh.points[:,:2] if prune_z else mesh.points
    out_mesh = meshio.Mesh(points=points, cells={cell_type: cells}, cell_data={"name_to_read":[cell_data]})
    return out_mesh

# Using the above function, create line and "plane" mesh
mesh_from_file = meshio.read(path+"circle_mesh.msh")
line_mesh = create_mesh(mesh_from_file, "line", prune_z=True)
meshio.write(path+"circle_mesh.xdmf", line_mesh)

from dolfin import *

mesh = Mesh()
with XDMFFile("circle_mesh.xdmf") as xdmf:
    xdmf.read(mesh)

x, y = SpatialCoordinate(mesh)
V = FunctionSpace(mesh, "CG", 1)
u =project(x+y, V)
File("u.pvd")<< u
import matplotlib.pyplot as plt
plt.savefig("mesh.png")
print(assemble(1*dx(domain=mesh)))

```
