# Robin boundary condition for 2D problem

**URL:** <https://fenicsproject.discourse.group/t/robin-boundary-condition-for-2d-problem/16403>\
**Category:** General\
**Tags:** boundary-conditions\
**Created:** [November 27, 2024, 8:06pm UTC](https://fenicsproject.discourse.group/t/robin-boundary-condition-for-2d-problem/16403 "2024-11-27T20:06:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![viveksingh](https://avatars.discourse-cdn.com/v4/letter/v/c77e96/32.png) [@viveksingh](https://fenicsproject.discourse.group/u/viveksingh)\
**Post date:** [November 27, 2024, 8:06pm UTC](https://fenicsproject.discourse.group/t/robin-boundary-condition-for-2d-problem/16403/1 "2024-11-27T20:06:26Z")

</div>

Hello everyone,  
I am trying to implement Robin boundary condition in 2D problem. The schematic for the problem is given below. In the problem `𝜎_12= 𝛼_1 𝑢_1` and `𝜎_22= 𝛼_2 𝑢_2` where `𝑢_1` and `𝑢_2` are components of the vector displacement field **u** to be solved. Any suggestions or help on how to add the stress terms in the variational form ?

 ![schem_robin](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/8/8831c78beadfa69767c4b06dae2a82188da18790.png)

---

<div class="post-metadata">

**Author:** ![francesco-ballarin](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@francesco-ballarin](https://fenicsproject.discourse.group/u/francesco-ballarin)\
**Post date:** [November 28, 2024, 8:12am UTC](https://fenicsproject.discourse.group/t/robin-boundary-condition-for-2d-problem/16403/2 "2024-11-28T08:12:15Z")

</div>

Have you written down the weak form on paper?

Do you know how that would work for the case of a Neumann boundary condition? Can you start from there and see what is the difference in your case?

This is a forum about FEniCS specific support, we are not supposed to answer in detail about all possible background you may be missing on the finite element method.

---

<div class="post-metadata">

**Author:** ![viveksingh](https://avatars.discourse-cdn.com/v4/letter/v/c77e96/32.png) [@viveksingh](https://fenicsproject.discourse.group/u/viveksingh)\
**Post date:** [November 29, 2024, 10:15am UTC](https://fenicsproject.discourse.group/t/robin-boundary-condition-for-2d-problem/16403/3 "2024-11-29T10:15:49Z")

</div>

Hello Francesco,

I have the weak form written down as  
 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/3/344ce707d34cc0ad5a2cfc87e2880eedf298a3bb.png)  
The term on the right side can be written as  
 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/8/8950d7b49d22724ffb410ff17d7b93484eddb3b8.png)  
I know how to implement Neumann boundary condition. So implement this in FEniCSx, I tried the following code:

```auto
Coeff = ufl.as_tensor([[alpha1, 0], [0, alpha_2]])
u = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
Tr_top = ufl.dot(Coeff, u)

a = ufl.inner(sigma(u), epsilon(v))*ufl.dx - ufl.dot(Tr_top, v) *ufl.ds

```

Is this the correct way to implement 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:** [November 29, 2024, 11:46am UTC](https://fenicsproject.discourse.group/t/robin-boundary-condition-for-2d-problem/16403/4 "2024-11-29T11:46:58Z")

</div>

It follows the same logic as when you write the problem on paper.  
So yes, you would include the term

> [@viveksingh](#):
>
> ` ufl.dot(Tr_top, v) *ufl.ds`

in your variational form.

Please note that since you are using `a` as a variable name, I am assuming that you are trying to set up a linear system (a(u,v)=L(v)).

Then you should either write everything in a residual form, such as

```auto
F = ufl.inner(sigma(u), epsilon(v))*ufl.dx - ufl.dot(Tr_top, v) *ufl.ds

```

and use

```auto
a, L = ufl.system(F)

```

to get the bi-linear and linear form, or just write them out by hand:

```auto
a = ufl.inner(sigma(u), epsilon(v))*ufl.dx 
L = ufl.dot(Tr_top, v) *ufl.ds

```

---

<div class="post-metadata">

**Author:** ![Stein](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/stein/32/8751_2.png) [@Stein](https://fenicsproject.discourse.group/u/Stein)\
**Post date:** [November 29, 2024, 2:11pm UTC](https://fenicsproject.discourse.group/t/robin-boundary-condition-for-2d-problem/16403/5 "2024-11-29T14:11:22Z")

</div>

@viveksingh What you have written down is not a Robin condition though. Are you sure that is what you need?

In your context, a Neumann condition would be:  
\sigma\cdot n = T\_{top} \,\, on \,\,\partial\Omega\_{top}  
That condition is _substituted_ into the boundary integral that shows up in working out the weak formulation and then moved to the right hand side. And @dokken has provided you the code with how to implement that in FEniCS.

A Robin condition, though, would look like:  
\sigma\cdot n + \alpha u = T\_{top} \,\, on \,\,\partial\Omega\_{top}  
Substituting that into the boundary integral gives you an additional term in your left hand side.

Augmenting Dokken’s earlier code snippet:

```auto
a = ufl.inner(sigma(u), epsilon(v))*ufl.dx + ufl.dot(alpha * u, v) *ufl.ds
L = ufl.dot(Tr_top, v) *ufl.ds

```
