Currently, I am solving a scalar linear PDE using first-order basis functions. I need to compute element-wise 2nd order derivatives to generate the hessian of the solution. To this end, I currently project the solution to 2nd order basis functions and then would like to compute the derivates. The projection problem that I solve is given by:
#msh represents the mesh and using fenicsx.
wh = fem.FunctionSpace(msh, ("Lagrange", 2)) # higher order function space
bcp = fem.dirichletbc(value=ScalarType(0.0), dofs=dofs, V=wh) #boundary condition of the problem
up = ufl.TrialFunction(wh)
vp = ufl.TestFunction(wh)
ap = inner(up,vp) * dx #L2 projection bilinear form
Lp = uh* vp * ufl.dx # load vector computed using first-order solution uh
proj_problem = fem.petsc.LinearProblem(ap, Lp, bcs=[bcp], petsc_options={"ksp_type": "preonly", "pc_type": "lu"})
up = proj_problem.solve()
#computing the hessian
ux1p = ufl.diff(up,x1)
ux1x1p = ufl.diff(ux1p,x1)
ux2p = ufl.diff(up,x2)
ux2x2p = ufl.diff(ux2p,x2)
ux1x2p = ufl.diff(ux1p,x2)
#to compute ux1x1
W = fem.FunctionSpace(msh, (“DG”, 0))
vdg = ufl.TestFunction(W)
ap = inner(ux1p,vdg) * dx
Mp = fem.form(ap)
dx1x1 = fem.petsc.assemble_vector(Mp) # I plan to divide this by the volume of the element as
# element wise hessian will be constant.
but when I run this exactly at ap = inner(ux1p,vdg) * dx
I get the following error:
This integral is missing an integration domain.
ERROR:UFL:This integral is missing an integration domain.
Traceback (most recent call last):
File “/Users/ankit/Desktop/fenicscodes/Exponential-integrators/conv_diff_steady_state/conv_diff_clean.py”, line 287, in
fenics_solver(filename,connect,coord)
File “/Users/ankit/Desktop/fenicscodes/Exponential-integrators/conv_diff_steady_state/conv_diff_clean.py”, line 255, in fenics_solver
ap = inner(ux1p,vdg) * dx
File “/opt/anaconda3/envs/fenicsx-env/lib/python3.10/site-packages/ufl/measure.py”, line 432, in rmul
error(“This integral is missing an integration domain.”)
File “/opt/anaconda3/envs/fenicsx-env/lib/python3.10/site-packages/ufl/log.py”, line 158, in error
raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: This integral is missing an integration domain.
can someone kindly tell me how to compute spatial derivatives of a solution and its projection to a richer space?
Regards
Ankit