# About MHD equations

**URL:** <https://community.freefem.org/t/about-mhd-equations/3103>\
**Category:** General Discussion\
**Created:** [April 17, 2024, 1:28pm UTC](https://community.freefem.org/t/about-mhd-equations/3103 "2024-04-17T13:28:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LXX](https://avatars.discourse-cdn.com/v4/letter/l/258eb7/32.png) [@LXX](https://community.freefem.org/u/LXX)\
**Post date:** [April 17, 2024, 1:28pm UTC](https://community.freefem.org/t/about-mhd-equations/3103/1 "2024-04-17T13:28:39Z")

</div>

Hello, everyone.

I want to solev MHD equations in freefem++, but I really can not deal with the boundary condition of magnetic B, especially the condition

```auto
B·n = 0

```

or

```auto
B·n = Be·n

```

Be is the analytic solution and n is the normal for boundary.  
The MHD equations as follows, where time J = [0,T],

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/a/ad0308f36ee1b08a8799903e521d0e355f82c826.png)

Another question: In three dimensions, I define the mesh

```auto
mesh3 Th = cube(N,N,N);

```

But when N \> 10, the output: out of memory. Are there somes methods to this?

---

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [April 17, 2024, 4:13pm UTC](https://community.freefem.org/t/about-mhd-equations/3103/2 "2024-04-17T16:13:55Z")

</div>

You can do as

 ![mhd](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/6/66b0de1d3e3a70e8a3d9e7ebe1bc3044759ef945.jpeg)  
The penalty formulation (3) will work if the boundary is made of flat pieces. Otherwise you have to lump it, see [Boundary condition - #6 by fb77](https://community.freefem.org/t/boundary-condition/2945/6)

---

<div class="post-metadata">

**Author:** ![LXX](https://avatars.discourse-cdn.com/v4/letter/l/258eb7/32.png) [@LXX](https://community.freefem.org/u/LXX)\
**Post date:** [April 18, 2024, 4:25am UTC](https://community.freefem.org/t/about-mhd-equations/3103/3 "2024-04-18T04:25:43Z")

</div>

For `B·n = Be·n` in boundary of three dimensions \Omega, is it okay for me to enter like this?

```auto
+ int2d(Th, 1, 2, 3, 4, 5, 6)(1e10*( Bx*N.x + By*N.y + Bz*N.z )*( wx*N.x + wy*N.y + wz*N.z ) )
- int2d(Th, 1, 2, 3, 4, 5, 6) (1.e10*( Bxe*N.x + Bye*N.y + Bze*N.z )*( wx*N.x + wy*N.y + wz*N.z ) )

```

Is there need any other statements for magnetics `B`, like

```auto
+ on(1, 2, 3, 4, 5, 6)(.......)

```

---

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [April 18, 2024, 9:40am UTC](https://community.freefem.org/t/about-mhd-equations/3103/4 "2024-04-18T09:40:50Z")

</div>

Yes it looks good (if your domain has flat boundaries as I said, like a cube for example). There is no need of anything else.

---

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [April 19, 2024, 1:12pm UTC](https://community.freefem.org/t/about-mhd-equations/3103/5 "2024-04-19T13:12:35Z")

</div>

For completeness I explain why the variational formulation corresponds to your required boundary condition.

 ![mhd2](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/5/541f631e9e5af46a6f817228341157977eda9489.jpeg)
