# How to build a ring model？

**URL:** <https://fenicsproject.discourse.group/t/how-to-build-a-ring-model/11739>\
**Category:** General\
**Created:** [July 14, 2023, 11:01pm UTC](https://fenicsproject.discourse.group/t/how-to-build-a-ring-model/11739 "2023-07-14T23:01:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chen\_wang](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/chen_wang/32/5334_2.png) [@chen\_wang](https://fenicsproject.discourse.group/u/chen_wang)\
**Post date:** [July 14, 2023, 11:01pm UTC](https://fenicsproject.discourse.group/t/how-to-build-a-ring-model/11739/1 "2023-07-14T23:01:55Z")

</div>

Someone can tell me which command can be used to create a ring in FEniCS？ Thanks

---

<div class="post-metadata">

**Author:** ![violetus](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/violetus/32/5122_2.png) [@violetus](https://fenicsproject.discourse.group/u/violetus)\
**Post date:** [July 15, 2023, 2:56am UTC](https://fenicsproject.discourse.group/t/how-to-build-a-ring-model/11739/2 "2023-07-15T02:56:35Z")

</div>

Hi, if you meant how can we generate a mesh in the ring shape you can use -  
In 2d, using this code -

```auto
from dolfin import *
from mshr import *

domain= Circle(Point(0., 0.), 2) - Circle(Point(0., 0.), 1)  
mesh = generate_mesh(domain, 20)

plot(mesh);

```

like this -  
 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/7/7c964407976baa9207f98b7b09803e87813ddb00.png)

In 3d, using this code -

```auto
from dolfin import *
from mshr import *

cylinder1 = Cylinder(Point(0., 0., 0), Point(0., 0., 1), 10, 10)
cylinder2 = Cylinder(Point(0., 0., 0), Point(0., 0., 1), 5, 5)

domain = cylinder1 - cylinder2
mesh = generate_mesh(domain, 40)

File("ring_3d.pvd") << mesh
plot(mesh);

```

I used paraview to visualize the mesh in 3d like this -

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/3/3b9089b3bb43fd7f7e4c10688930ad8080a9f005.jpeg)

But there is a caveat here, the `mshr` library that I’m using is currently not maintained so consider using [Gmsh](https://gmsh.info/) for making the geometries. Here are some good tutorials to get you started - [Mesh generation and conversion with PYGMSH and Meshio](https://jsdokken.com/src/pygmsh_tutorial.html) and [Using the GMSH Python API to generate complex meshes](https://jsdokken.com/src/tutorial_gmsh.html).  
I hope this helps.

---

<div class="post-metadata">

**Author:** ![chen\_wang](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/chen_wang/32/5334_2.png) [@chen\_wang](https://fenicsproject.discourse.group/u/chen_wang)\
**Post date:** [July 15, 2023, 1:30pm UTC](https://fenicsproject.discourse.group/t/how-to-build-a-ring-model/11739/3 "2023-07-15T13:30:12Z")

</div>

Thank you so much!  
I want to create a ring in the rectangle. I have tried your command. But in the rectangle i can not see this ring.  
I show you a photo about this model.

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/0/09ae669e9e5d7e9b6d912b0ad4e0bfc8a72422a0.png)

---

<div class="post-metadata">

**Author:** ![violetus](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/violetus/32/5122_2.png) [@violetus](https://fenicsproject.discourse.group/u/violetus)\
**Post date:** [July 15, 2023, 1:33pm UTC](https://fenicsproject.discourse.group/t/how-to-build-a-ring-model/11739/4 "2023-07-15T13:33:46Z")

</div>

Is the orange space with red and green cross empty ?

---

<div class="post-metadata">

**Author:** ![chen\_wang](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/chen_wang/32/5334_2.png) [@chen\_wang](https://fenicsproject.discourse.group/u/chen_wang)\
**Post date:** [July 15, 2023, 1:37pm UTC](https://fenicsproject.discourse.group/t/how-to-build-a-ring-model/11739/5 "2023-07-15T13:37:18Z")

</div>

Actually these three parts are different materials, can you tell me how to define the boundary.

 ![11111](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/8/878166e96e1bbc14718a1ddd1d58d62eaa14f1ce.jpeg)

---

<div class="post-metadata">

**Author:** ![chen\_wang](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/chen_wang/32/5334_2.png) [@chen\_wang](https://fenicsproject.discourse.group/u/chen_wang)\
**Post date:** [July 15, 2023, 1:39pm UTC](https://fenicsproject.discourse.group/t/how-to-build-a-ring-model/11739/6 "2023-07-15T13:39:15Z")

</div>

No, its not empty. The orange part is a specific material

---

<div class="post-metadata">

**Author:** ![violetus](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/violetus/32/5122_2.png) [@violetus](https://fenicsproject.discourse.group/u/violetus)\
**Post date:** [July 15, 2023, 1:41pm UTC](https://fenicsproject.discourse.group/t/how-to-build-a-ring-model/11739/7 "2023-07-15T13:41:54Z")

</div>

Okay, I suggest you to kindly go through this post [How to use gmsh tags to assign material properties?](https://fenicsproject.discourse.group/t/how-to-use-gmsh-tags-to-assign-material-properties/9249) which is probably what you are looking for.

EDIT: You can also use boundary conditions to define different material properties like in this tutorial -  
[Defining subdomains for different materials](https://fenicsproject.org/pub/tutorial/html/._ftut1013.html).
