Appreciate for your patience!
Now I want to use projection to transport data (Maybe from P2 to P1) ,so that I can complete the follow-up calculation of the weak formulation below:
Im confused about how to do the projection work.Here is my code:
#read mesh
checkpoint_file = Path("function_checkpoint.bp")
msh = adios4dolfinx.read_mesh(MPI.COMM_WORLD, checkpoint_file, engine='BP4', ghost_mode=dolfinx.mesh.GhostMode.shared_facet)
#read u
P2 = element("Lagrange", msh.basix_cell(), 2, shape=(msh.geometry.dim,))
U = functionspace(msh, P2)
u = Function(U)
adios4dolfinx.read_function(u, checkpoint_file, engine="BP4")
P1 = element("Lagrange", msh.basix_cell(), 1)
V = functionspace(msh, P1)
#projection
u_projected = ufl.TrialFunction(V)
v = ufl.TestFunction(V)
a_proj = inner(u_projected, v) * dx
L_proj = inner(u, v) * dx
A_proj = assemble_matrix(a_proj)
A_proj.assemble()
b_proj = assemble_vector(L_proj)
solver_proj = PETSc.KSP().create(msh.comm)
solver_proj.setOperators(A_proj)
solver_proj.solve(b_proj, u_projected.vector)
u_projected.x.scatter_forward()
And it failed with:
Traceback (most recent call last):
File "/home/fenics/work/phase.py", line 33, in <module>
L_proj = inner(u, v) * dx
File "/usr/local/lib/python3.10/dist-packages/ufl/operators.py", line 167, in inner
return Inner(a, b)
File "/usr/local/lib/python3.10/dist-packages/ufl/tensoralgebra.py", line 162, in __new__
raise ValueError(f"Shapes do not match: {ufl_err_str(a)} and {ufl_err_str(b)}")
ValueError: Shapes do not match: <Coefficient id=140108284108736> and <Argument id=140108318196832>
It seems that there is a shape mismatch between the operands in the inner
function …? How should I modify the code ?
And I alse referred to L2 projection of fine mesh solution to a coarse mesh ,maybe I should interpolate the function u first? If so ,how should I interpolate the function?