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;
Th = adaptmesh(Th, function_to_adapt_by, err=error);
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);