# Mixed Neumann-Dirichlet boundary conditions in 3d

**URL:** <https://community.freefem.org/t/mixed-neumann-dirichlet-boundary-conditions-in-3d/457>\
**Category:** General Discussion\
**Created:** [June 8, 2020, 3:32pm UTC](https://community.freefem.org/t/mixed-neumann-dirichlet-boundary-conditions-in-3d/457 "2020-06-08T15:32:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathias-Fuchs](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/mathias-fuchs/32/175_2.png) [@Mathias-Fuchs](https://community.freefem.org/u/Mathias-Fuchs)\
**Post date:** [June 8, 2020, 3:32pm UTC](https://community.freefem.org/t/mixed-neumann-dirichlet-boundary-conditions-in-3d/457/1 "2020-06-08T15:32:46Z")

</div>

Hello FF!  
I’m trying to distill from the example Laplace3d.edp the simplest example for applying mixed Neumann-Dirichlet boundary conditions to a general tetrahedral mesh, and to solve \Delta u = 0 in the interior (steady heat equation). There are regions 1, 5 for Dirichlet boundary conditions, and 2, 3, 4 for Neumann boundary conditions (it describes a beam whose temperatures at the ends are fixed). To make things simple, I set the function ue of the example Laplace3d.edp to 0 for the Neumann boundary part, basically dictating zero flow through the Neumann boundary. (I also checked with nonzero ue, it made the solution more regular but still wrong so I concluded that setting ue=0 does not seem to be the mistake). If it is of interest, the surface mesh used in the following script is [here](https://mathiasfuchs.de/mainS.msh).

> load “msh3”  
> load “gmsh”  
> load “tetgen”  
> meshS ThS = gmshloadS(“mainS.msh”); // a surface mesh file in msh file format  
> func newregion = 1 + (y \> -500.0) + (y \> -10.0) + (y \> 10.0) + (y \> 500.0); // define regions  
> ThS = change(ThS, fregion=newregion);  
> mesh3 Th=tetg(ThS,switch=“paAAQYY”);  
> fespace Vh(Th, P2);  
> Vh u, v;  
> macro Grad(u) [dx(u), dy(u), dz(u)] // EOM  
> problem Laplace(u, v, solver=CG)  
> = int3d(Th)(Grad(u)’ \* Grad(v))  
> +int2d(Th, 2)(u \* v)  
> +int2d(Th, 3)(u \* v)  
> +int2d(Th, 4)(u \* v)  
> + on(1, u=20.0)  
> + on(5, u=-13.1);  
> Laplace;  
> but the solution is incorrect, it seems the zero Neumann boundary conditions are not applied correctly:
> 
> ![xx](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/afca9e32672b5e0230c85387d159aef36bba9ef9.png)  
> Help appreciated!

---

<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:** [June 9, 2020, 9:30am UTC](https://community.freefem.org/t/mixed-neumann-dirichlet-boundary-conditions-in-3d/457/2 "2020-06-09T09:30:33Z")

</div>

Natural boundary conditions vanish in your variational formulation. The following works as expected.

```auto
problem Laplace(u, v, solver=CG)
= int3d(Th)(Grad(u)' * Grad(v))
+ on(1, u=20.0)
+ on(5, u=-13.1);

```

 ![Screenshot 2020-06-09 at 11.29.30 AM](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/c409d72f2a8c5aee33885b3795c23c6fc546e735.png)

---

<div class="post-metadata">

**Author:** ![Mathias-Fuchs](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/mathias-fuchs/32/175_2.png) [@Mathias-Fuchs](https://community.freefem.org/u/Mathias-Fuchs)\
**Post date:** [February 9, 2021, 11:51am UTC](https://community.freefem.org/t/mixed-neumann-dirichlet-boundary-conditions-in-3d/457/3 "2021-02-09T11:51:59Z")

</div>

Thanks for the answer (and sorry for late reply).
