# Finite element space on an edge

**URL:** <https://community.freefem.org/t/finite-element-space-on-an-edge/2774>\
**Category:** General Discussion\
**Created:** [November 3, 2023, 1:47pm UTC](https://community.freefem.org/t/finite-element-space-on-an-edge/2774 "2023-11-03T13:47:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AArnoult](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@AArnoult](https://community.freefem.org/u/AArnoult)\
**Post date:** [November 3, 2023, 1:47pm UTC](https://community.freefem.org/t/finite-element-space-on-an-edge/2774/1 "2023-11-03T13:47:04Z")

</div>

Dear FreeFem++ community,

For domain decomposition, I need to solve a 2d problem with a given function g on a boundary (thus 1d) obtained with an iterative finite element calculation. g can be, for example, the restriction of a finite element function on a boundary.

In the example below, g is defined in the whole finite element space, I would like to define it only on the top interface. Perhaps with 1d meshL ?

```auto

border top(t=0,1){x=t;y=1;}

border right(t=0,1){x=1;y=1-t;}

border bottom(t=0,1){x=1-t;y=0;}

border left(t=0,1){x=0;y=t;}

mesh Th=buildmesh(top(-5)+right(-5)+bottom(-5)+left(-5));

fespace Vh(Th,P1);

Vh g = x*y;

Vh u,v;

solve Prob(u,v)

= int2d(Th)(dx(u)*dx(v) + dy(u)*dy(v))

+ on(right, bottom, left, u=0)

+ on(top, u=g);

plot(u, wait=1, value=1);

```

---

<div class="post-metadata">

**Author:** ![jbl](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jbl](https://community.freefem.org/u/jbl)\
**Post date:** [November 3, 2023, 2:22pm UTC](https://community.freefem.org/t/finite-element-space-on-an-edge/2774/2 "2023-11-03T14:22:17Z")

</div>

Hello,

To impose a Dirichlet BC (Boundary condition) in Freefem++, you need to call the label of your boundary in the on function.  
For example, if you use the square function to build your mesh, the default labels are 1 for bottom, 2 for right, 3 for top and 4 for left.

In your example, you build your mesh from the top, so the top label is 1, the right label is 2, the bot label is 3 and the left label is 4.

Once you know your labels you write

```auto
on(border label, u= value)

```

in your case :

```auto
border top(t=0,1){x=t;y=1;}
border right(t=0,1){x=1;y=1-t;}
border bottom(t=0,1){x=1-t;y=0;}
border left(t=0,1){x=0;y=t;}

mesh Th=buildmesh(top(-5)+right(-5)+bottom(-5)+left(-5));

fespace Vh(Th,P1);

Vh g = x*y;

Vh u,v;

solve Prob(u,v)

= int2d(Th)(dx(u)*dx(v) + dy(u)*dy(v))

+ on(2, 3, 4, u=0)

+ on(1, u=g);

plot(u, wait=1, value=1);

```

To be sure of the label, you can also give one while you’re creating your border.  
example:

```auto
border top(t=0,1){x=t;y=1;label = 10;}
border right(t=0,1){x=1;y=1-t; label = 20;}
border bottom(t=0,1){x=1-t;y=0;label = 30;}
border left(t=0,1){x=0;y=t; label = 40;}

```

Let me know if this answers your question.

---

<div class="post-metadata">

**Author:** ![AArnoult](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@AArnoult](https://community.freefem.org/u/AArnoult)\
**Post date:** [November 3, 2023, 4:09pm UTC](https://community.freefem.org/t/finite-element-space-on-an-edge/2774/3 "2023-11-03T16:09:41Z")

</div>

Thanks for your answer.

I may not have been clear in my question : I indeed want Dirichlet BC on the top (ie on label=10), but I want the function g to be defined only on the top mesh (in 1d), not on the whole finite element space Vh.  
Actually, this is indeed works, but it too slow for my purpose (I exchange g between processors).

---

<div class="post-metadata">

**Author:** ![jbl](https://avatars.discourse-cdn.com/v4/letter/j/e47c2d/32.png) [@jbl](https://community.freefem.org/u/jbl)\
**Post date:** [November 9, 2023, 11:31am UTC](https://community.freefem.org/t/finite-element-space-on-an-edge/2774/4 "2023-11-09T11:31:29Z")

</div>

Hi, have you found a solution to your problem?
