Need help understand the varf command

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.1
2.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;

Your variational form must be linear with respect to u and to v. Here u*dx(u) is not linear.

fb77 is right: udx(u) makes the form nonlinear, so it cannot be assembled into a matrix. Use the commented-out version instead, but write the coefficient explicitly: varf massAxis(u,v) = int2d(Th)(2pixuv); — as typed, “2pix” is not going to be read as 2pix. That is the standard axisymmetric mass form, the r-weight coming from 2pirdrdz. Also, your printing loops only reach nrnz, while P1 on square(nr,nz) has (nr+1)*(nz+1) unknowns, so index up to M.n and M.m.