How to calculate effective stress/strain in a homogenization model

Thank you so much dr. @dokken for your response. I have written MWE for 2D case,
I have two more questions on this,

  1. how would I know which contribution is coming from which cell. Is there any correspondence between indices of int_f and cells.
  2. let us suppose I have a solution vector u with 16 degrees of freedom for which I want to calculate avg. value over each cell, would there be any issue while defining dolfinx.fem.form(u*v*dx) as u and v have different dofs.
msh = create_unit_square(MPI.COMM_WORLD,2,2)
x = ufl.SpatialCoordinate(msh)
f = x[0] + x[1]

V = dolfinx.fem.functionspace(msh, ("DG", 0))
# f_vl = fem.Function(V)
# f_exp = dolfinx.fem.Expression(f,V.element.interpolation_points())
# f_vl.interpolate(f_exp)

v = ufl.TestFunction(V)
int_f = dolfinx.fem.assemble_vector(dolfinx.fem.form(1/ufl.CellVolume(msh)*f*v*ufl.dx))
print(int_f.array)

I hope I am not bothering if I sound trivial.