Hi,
I am new to FreeFem and PETSc and need some help. I want to solve a time dependent stokes equation, where the righthandside is updated with the old velocity uold in each iteration step. Until the time loop everything works fine but then I get the error "Error line number 63, in file petsc-stokes.edp, before token ". So something is wrong with the rhs in the loop. Do I need to set the value of the rhs in the loop in a different way? Does anybody has an idea how to fix this problem/script?
petsc-stokes.edp (1.7 KB)
// run with MPI: ff-mpirun -np 4 script.edp
load “PETSc” // PETSc plugin
macro dimension()2// EOM // 2D or 3D
include “macro_ddm.idp” // additional DDM functions
macro def(i)[i, i#B, i#C]// EOM // vector field definition
macro init(i)[i, i, i]// EOM // vector field initialization
macro grad(u)[dx(u), dy(u)]// EOM // two-dimensional gradientmacro div(u) (dx(u) + dy(u#B)) //EOM
func Pk = [P2, P2, P1]; // finite element space//Parameters
real dt = 0.1;
real tau = 1/dt;
real T = 1.;
real mu = 0.1;
int n = 10;mesh Th = square(getARGV(“-global”,n),getARGV(“-global”,n));
Mat A;
macro ThRefinementFactor()getARGV(“-split”, 0)//
MatCreate(Th, A, Pk);//Fespace
fespace Wh(Th, Pk);//variational formultation
varf vPbA([u, uB, p], [v, vB, q]) = int2d(Th)(
tau*(uv+uBvB) + mu*(dx(u)*dx(v) + dy(u)dy(v) + dx(uB)dx(vB) + dy(uB)dy(vB) )- pq1.e-6- qdiv(u)
)+ on(1, 2, 4, u=0, uB=0)+ on(3, u=1, uB=0)
;//variational formualtion for the righthandside
varf vPbf([uold, uoldB, p], [v, vB, q]) = int2d(Th)(
tau*(uoldv+uoldBvB)
)+ on(1, 2, 4, uold=0, uoldB=0)+ on(3, uold=1, uoldB=0)
;
real[int] rhs = vPbf(0,Wh);set(A, sparams = “-pc_type lu”);
Wh def(u);A = vPbA(Wh, Wh);
u = A^-1 * rhs;macro def2(u)[u, u#B] //EOM
macro def1(u)u //EOM
plotMPI(Th, def2(u), [P2,P2], def2, real, cmm = “Global velocity”);// Time loop
int M = T/dt;
for(int m = 0; m < M; m++){rhs = vPbf(def(u),Wh);
set(A, sparams = “-pc_type lu”);
Wh def(u);A = vPbA(Wh, Wh);
u = A^-1 * rhs;plotMPI(Th, def2(u), [P2,P2], def2, real, cmm = “Global velocity”);
}