# How to solve the following problem?

**URL:** <https://community.freefem.org/t/how-to-solve-the-following-problem/2979>\
**Category:** General Discussion\
**Created:** [February 20, 2024, 10:19am UTC](https://community.freefem.org/t/how-to-solve-the-following-problem/2979 "2024-02-20T10:19:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ksugahar](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ksugahar/32/2115_2.png) [@ksugahar](https://community.freefem.org/u/ksugahar)\
**Post date:** [February 20, 2024, 10:19am UTC](https://community.freefem.org/t/how-to-solve-the-following-problem/2979/1 "2024-02-20T10:19:55Z")

</div>

I want to solve the following problem with FreeFEM++.

{\rm given }{\bf \vec B}{\rm (}{\bf \vec r}){\rm :such }\vec \nabla \cdot {\bf \vec B} = 0 \\ {\rm find }F{\rm (}{\bf \vec r}),G{\rm (}{\bf \vec r}):{\rm such }\vec \nabla F \times \vec \nabla G = {\bf \vec B} \\ 

How can I derive the weak form of this equation to solve with FreeFEM++?

---

<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:** [February 20, 2024, 1:18pm UTC](https://community.freefem.org/t/how-to-solve-the-following-problem/2979/2 "2024-02-20T13:18:00Z")

</div>

This is a well-known problem on differential forms, which is difficult.  
There is no easy way of solving it globally. One can solve it by abstract differential geometry arguments in the neighboorhood of a point x where B(x) is nonzero.  
Solving it with FreeFem++ looks out of reach since it is nonlinear in the couple F,G.

An analogous 2d problem is: given a non-vanishing vector field B, find two scalar functions f,g such that f\*grad(g)=B.  
The formal solution is: consider the integral lines of B^\perp.  
Take g constant on each of these integral lines, the constant changing when changing the integral line. Then grad g is perpendicular to these integral lines, thus grad g is proportional to B. It follows the existence of f.

All this is related to the Frobenius Theorem

> **[Frobenius theorem (differential topology)](https://en.wikipedia.org/wiki/Frobenius_theorem_(differential_topology))**
>
> In mathematics, Frobenius' theorem gives necessary and sufficient conditions for finding a maximal set of independent solutions of an overdetermined system of first-order homogeneous linear partial differential equations. In modern geometric terms, given a family of vector fields, the theorem gives necessary and sufficient integrability conditions for the existence of a foliation by maximal integral manifolds whose tangent bundles are spanned by the given vector fields. The theorem generalizes t...

---

<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:** [February 20, 2024, 3:25pm UTC](https://community.freefem.org/t/how-to-solve-the-following-problem/2979/4 "2024-02-20T15:25:34Z")

</div>

Nevertheless I can propose you a solution, assuming that B\_3\>0 everywhere.

It is enough to satisfy  
B.\nabla F=0, (1)  
B.\nabla G=0, (2)  
and  
(\partial\_1 F)_(\partial\_2 G)-(\partial\_2 F)_(\partial\_1 G)=B\_3 on the plane x\_3=0. (3)

Then if you interpret x\_3 as a time, (1) and (2) are advection equations on F  
and G, that you can solve (divide by B\_3) using `convect`, see _FreeFEM-documentation.pdf p.61_, provided you give initial data  
F\_0, G\_0 on the plane x\_3=0.  
These initial data need to be chosen such that (3) holds.  
You can take for example G\_0=x\_2.  
Then (3) is just (\partial\_1 F\_0)=B\_3, which is easily solved to get some F\_0(x\_1,x\_2).  
Once you have F\_0,G\_0, you can solve the advection equations.  
Francois.
