I am trying to use the varf command to generate a mass matrix for a cylinder, for an axisymmetric problem.
I have been very successful in creating error messages, but not a working mass matrix.
Could you please help identify what it is that I am doing wrong?
Thank you,
Here is the code:
real R = 4.752.54/100; // radius
real L = 0.12.54/100; // length
int nr = 5, nz = 10; // mesh resolution
// Mesh in (r,z) plane
mesh Th = square(nr, nz, [Rx, Ly]);
// Finite element space
fespace Vh(Th, P1);
Vh u, v;
Vh uu, vv;
Vh rr, zz;
rr = x; // radial coordinates
zz = y; // axial coordinates
// Axisymmetric mass matrix assembly
//varf massAxis(u, v) = int2d(Th)( 2pix * u * v );
varf massAxis(u, v) = int2d(Th)(u*dx(u)*dy(v));
// Build the matrix
matrix M = massAxis(Vh, Vh);
// Optional: check size and a sample entry
// cout << "Mass matrix size: " << M.n << " x " << M.m << endl;
for(int jj=0; jj < nr; jj++) {
for(int kk=0; kk < nz; kk++) {
cout << "for jj = " << jj << " and kk = " << kk << " M(jj,kk) = " << M(jj,kk) << endl;
}
}
real MassSum = 0.0;
for(int jj=0; jj < nr; jj++) {
for(int kk=0; kk < nz; kk++) {
MassSum = MassSum + M(jj,kk);
}
}
cout << "summation mass matrix " << MassSum << endl;