Hello,
In FreeFem, when you set init=1, it reuses the previously constructed matrix, which indeed saves the reconstruction cost. However, as you pointed out, if the matrix depends on a parameter that needs to change, you need to update the matrix accordingly. Remeshing the domain is one way to force the update, but it’s inefficient.
To address your problem without remeshing, you can modify the parameter that affects the matrix and manually reconstruct the matrix by resetting init. One approach is to redefine the problem when the parameter changes. Here’s how you can do it:
mesh Th = square(10,10);
fespace Vh(Th, P2);
Vh w, u=1.0;
real dl=1., dr=1.;
// Define a function to set up and solve the problem
func problemSetup(real dl, real dr) {
problem pbU (u, w, init=0, solver=LU)
= int2d(Th)(
(dx(u)*dx(w) + dy(u)*dy(w)) * dl)
- int2d(Th)(1 * w * dr)
+ on(1, 2, 3, 4, u=0);
pbU;
plot(u, wait=0, fill=1, value=1, aspectratio=0);
}
// Initial solve
problemSetup(dl, dr);
// Change parameter dr and solve again
dr = 10.;
problemSetup(dl, dr);
// Change parameter dl and solve again
dl = 10.;
problemSetup(dl, dr);
// Optionally remesh and solve again if needed
Th = square(10,10);
problemSetup(dl, dr);
In this code, we define a function problemSetup that constructs and solves the problem with the current values of dl and dr. When you need to change these parameters, you call problemSetup with the new values, ensuring that the matrix is reconstructed correctly each time. Also check this : Out of Bound problem after refining a 3D meshlooker
This approach avoids remeshing and efficiently updates the matrix according to the changed parameters.
I hope this helps!