Open
Description
Hello, everyone.
I want to use the smallest refined solution as a Reference solution to calculate the error. But the program reported an error(Whether running in parallel or on a single core).
Here is my code:
from firedrake import *
import math
Test_Type = "Temporal_Convergence"
FinalTime = 0.5
num_refs = 4
u_solution = []
for idx in range(num_refs):
Lx = 2*math.pi;
Ly = 2*math.pi
if Test_Type == "Spatial_Convergence":
Nx = 4*2**(idx)
N_step = 1024
elif Test_Type == "Temporal_Convergence":
Nx = 64
N_step = 2**(idx)
Ny = Nx
Hx = Lx/Nx
dt = FinalTime / N_step
dtc = Constant(dt)
t = 0
tc = Constant(t)
mesh = PeriodicRectangleMesh(Nx, Ny, Lx, Ly)
x, y = SpatialCoordinate(mesh)
V = FunctionSpace(mesh, "Lagrange", 1)
u_trial = TrialFunction(V)
v_test = TestFunction(V)
u_exact = sin(x)*sin(y)*exp(-2*tc)
u = Function(V).interpolate(u_exact)
LHS = (
inner(u_trial, v_test)*dx
-0.5*dtc* inner(grad(u_trial), grad(v_test)) * dx
)
RHS = (
inner(u, v_test)*dx
+0.5*dtc* inner(grad(u), grad(v_test)) * dx
)
Solution_space = Function(V)
solver_parameters={
"ksp_type": "preonly",
"pc_type": "lu",
"pc_factor_mat_solver_type": "mumps",
}
problem = LinearVariationalProblem(LHS, RHS, Solution_space)
solver = LinearVariationalSolver(problem, solver_parameters= solver_parameters)
Step = 0
for Step in range(N_step):
t += dt
tc.assign(t)
solver.solve()
u.assign(Solution_space)
u_solution.append(u)
# Use the smallest refined solution as a Reference solution to calculate the error
u_e_ref_L2 = []
for i, u in enumerate(u_solution[:-1]):
u_e_ref_L2.append(norm(u - u_solution[-1]), "L2")
PETSc.Sys.Print("u_e_ref_L2={:}",u_e_ref_L2)
Here is the report:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[21], line 72
67 u_e_ref_L2 = []
68 for i, u in enumerate(u_solution[:-1]):
69 # u_ref = u_solution[i+1]
70 # u_inter = project(u, u_ref.function_space())
71 # error = errornorm(u_ref, u_inter)
---> 72 u_e_ref_L2.append(norm(u - u_solution[-1]), "L2")
73 PETSc.Sys.Print("u_e_ref_L2={:}",u_e_ref_L2)
File petsc4py/PETSc/Log.pyx:115, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func()
File petsc4py/PETSc/Log.pyx:116, in petsc4py.PETSc.Log.EventDecorator.decorator.wrapped_func()
File /home/firedrake/firedrake/src/firedrake/firedrake/norms.py:80, in norm(v, norm_type, mesh)
77 else:
78 raise RuntimeError("Unknown norm type '%s'" % norm_type)
---> 80 return assemble((expr**(p/2))*dx)**(1/p)
File /home/firedrake/firedrake/src/ufl/ufl/measure.py:408, in Measure.__rmul__(self, integrand)
406 domain = self.ufl_domain()
407 if domain is None:
--> 408 domains = extract_domains(integrand)
409 if len(domains) == 1:
410 domain, = domains
File /home/firedrake/firedrake/src/ufl/ufl/domain.py:340, in extract_domains(expr)
338 for t in traverse_unique_terminals(expr):
339 domainlist.extend(t.ufl_domains())
--> 340 return sorted(join_domains(domainlist))
TypeError: '<' not supported between instances of 'MeshGeometry' and 'MeshGeometry'