I am trying to use FreeFem++ to solve the heat geodesics algorithm.
The algorithm is:
- solve $\dot u = \Delta u$ at a specific time $t$.
- compute $X = \frac{\nabla u_t}{|\nabla u_t|}$
- solve $\Delta\phi = \nabla \cdot X$
I am having a hard time doing step 2. The documentation does talk about gradients, but it seems to use them in the context of solving linear systems?
This is my current snippet that tries to solve the heat part of the Varadahn equation.
// Parameters
func u0 = 0; // initial condition: u is zero everywhere
real T = 1.0; // final time
real dt = 0.01; // time step
// Define mesh boundary
border C(t=-pi, -pi + 0.3){x=cos(t) -1/(1 + 4 * t * t); y=sin(t);}
border B(t=-pi + 0.3, pi){x=cos(t) -1/(1 + 4 * t * t); y=sin(t);}
// The triangulated domain Th is on the left side of its boundary
mesh pmesh = buildmesh(C(500) + B(500));
// Fespace
fespace Vh(pmesh, P1);
Vh u, v, uold;
real S;
// Problem
problem heatFlow(u,v) =
int2d(pmesh)( u*v/dt + ( dx(u)*dx(v) + dy(u)*dy(v) ) )
- int2d(pmesh)(- uold*v/dt)
+ on(C, u=1) + on(B, u=0); // Dirichlet B.C.: on Curve C the field variable u is zero.
// apply the initial condition:
u = u0;
// Time iterations
ofstream ff("sol.dat");
for(real t = 0; t < T; t += dt)
{
uold = u; //equivalent to u^{n-1} = u^n
S = t;
heatFlow;
plot(u, fill=true);
}