# Lagrange Multipliers and Adaptive Meshing

Hi all,

I am confused as to how to implement adaptive meshing for a lagrange multiplier problem. The code example for the lagrange multiplier is here https://doc.freefem.org/examples/finite-element.html#examplelagrangemultipliers

Most examples, and in the documentation it describes how to use adaptmesh using a loop.

``````// Adaptmesh loop
for (int i = 0; i < 4; i++){
Problem;
error = error/2;
}
``````

Where the “Problem” is defined earlier, like the poisson problem https://doc.freefem.org/examples/mesh-generation.html#mesh-adaptation-for-the-poisson-s-problem

But for the Lagrange multiplier examples, there is not a problem variable that we set. How would I go about using the block matrices we make the lagrange example work with this?

Best,
Kevin

Example Lagrange Code

``````// Parameters
func f = 1 + x - y;

// Mesh
mesh Th = square(10, 10);

// Fespace
fespace Vh(Th, P1);
int n = Vh.ndof;
int n1 = n+1;
Vh uh, vh;

// Problem
varf va (uh, vh)
= int2d(Th)(
dx(uh)*dx(vh)
+ dy(uh)*dy(vh)
)
;

varf vL (uh, vh) = int2d(Th)(f*vh);
varf vb (uh, vh) = int2d(Th)(1.*vh);

matrix A = va(Vh, Vh);
real[int] b = vL(0, Vh);
real[int] B = vb(0, Vh);
// Block matrix
matrix AA = [ [ A, B ], [ B', 0 ] ];
set(AA, solver=sparsesolver);

real[int] bb(n+1), xx(n+1), b1(1), l(1);
b1 = 0;
// Builds the right hand side block
bb = [b, b1];

// Solve
xx = AA^-1 * bb;

// Set values
[uh[],l] = xx;

// Display
cout << " l = " << l(0) << " , b(u, 1) =" << B'*uh[] << endl;

// Plot
plot(uh);``````

The equivalent of `problem` here is in matrix construction+the execution `xx = AA^-1 * bb;`
So I guess you should do the mesh adaptation after this line.
I guess you start the loop before first matrix construction: `matrix A = va(Vh, Vh)`.
Indeed we can suppose the number of elements change after the mesh adaptation, I think the matrices have to be re-allocated …

check this Laplace-lagrange-mult.edp (1.3 KB)