# Dirichlet boundary condition in heat equation

**URL:** <https://community.freefem.org/t/dirichlet-boundary-condition-in-heat-equation/2737>\
**Category:** General Discussion\
**Created:** [October 3, 2023, 1:27am UTC](https://community.freefem.org/t/dirichlet-boundary-condition-in-heat-equation/2737 "2023-10-03T01:27:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaMattoso](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ramattoso/32/499_2.png) [@RaMattoso](https://community.freefem.org/u/RaMattoso)\
**Post date:** [October 3, 2023, 1:27am UTC](https://community.freefem.org/t/dirichlet-boundary-condition-in-heat-equation/2737/1 "2023-10-03T01:27:01Z")

</div>

Hello fellows!

I’m trying to implement a simple bioheat problem, but I’m having trouble with the non homogeneous boundary condition.  
The mesh is constructed using buildmesh and the problem is solved using varf.

Mesh

```auto
real n = 200; // mesh generation parameter
    real nom = 200;
    real nbody = 160;
    real ndes = 80;
   
    border pml01(t=0, 0.5){x=-0.5+2*t; y=-0.5;label=1;}
    border pml02(t=0, 0.5){x=0.5; y=-0.5+2*t;label=1;}
    border pml03(t=0, 0.5){x=0.5-2*t; y=0.5;label=1;}
    border pml04(t=0, 0.5){x=-0.5; y=0.5-2*t;label=1;}
    border om01(t=0, 0.25){x=-0.25+2*t;y=-0.25;label=2;}
    border om02(t=0, 0.25){x=0.25;y=-0.25+2*t;label=2;}
    border om03(t=0, 0.25){x=0.25-2*t;y=0.25;label=2;}
    border om04(t=0, 0.25){x=-0.25;y=0.25-2*t;label=2;}

    border b(t=0, 2*pi){x=0.1*cos(t); y=0.1*sin(t); label=3;}
    border d(t=0, 2*pi){x=0.03+0.02*cos(t); y=0.03+0.02*sin(t); label=4;}
    Th = buildmesh(pml01(n)+pml02(n)+pml03(n)+pml04(n)+om04(n)+om03(n)+om02(n)+om01(n)+b(nbody)+d(ndes));

```

Problem

```auto
varf bioheat(T,nu) = int2d(Th)(cK*dx(T)*dx(nu)+ dy(T)*dy(nu) + cw*T*nu) + on(1,T=25);
matrix Ah = bioheat(Oh,Oh, tgv=1e43);
varf bioheatrhs(T,nu) = int2d(Th)(cw*thbb*nu);
fc[] = bioheatrhs(0,Oh);
T[] = Ah^-1 * fc[];

```

Note that I’m prescribing 25º in the boundary 1, but the result is 0º when I plot the solution using medit.

 ![initial](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/3/375fbdc744aa6972b7c4acffd22a18f89dddfc19.png)

Someone knows how can I solve this issue?  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [October 3, 2023, 3:30am UTC](https://community.freefem.org/t/dirichlet-boundary-condition-in-heat-equation/2737/2 "2023-10-03T03:30:09Z")

</div>

> Note that I’m prescribing 25º in the boundary 1

No, you are not prescribing anything on the RHS.

---

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [October 3, 2023, 8:02am UTC](https://community.freefem.org/t/dirichlet-boundary-condition-in-heat-equation/2737/3 "2023-10-03T08:02:48Z")

</div>

You could make a smaller mesh and dump matrix and rhs to see the problem.  
Why can’t you use the same varf for both? What did you expect the tgv to do?

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [October 3, 2023, 9:57am UTC](https://community.freefem.org/t/dirichlet-boundary-condition-in-heat-equation/2737/4 "2023-10-03T09:57:41Z")

</div>

> [@RaMattoso](#):
>
> `varf bioheatrhs(T,nu) = int2d(Th)(cw*thbb*nu);`  
> `fc[] = bioheatrhs(0,Oh);`

Change these lines to:

```auto
varf bioheatrhs(T,nu) = int2d(Th)(cw*thbb*nu) + on(1,T=25);
fc[] = bioheatrhs(0,Oh, tgv=1e43);

```

---

<div class="post-metadata">

**Author:** ![RaMattoso](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ramattoso/32/499_2.png) [@RaMattoso](https://community.freefem.org/u/RaMattoso)\
**Post date:** [October 3, 2023, 10:19am UTC](https://community.freefem.org/t/dirichlet-boundary-condition-in-heat-equation/2737/5 "2023-10-03T10:19:26Z")

</div>

Thanks!  
It worked perfectly fine.
