Assemble_system gives error message

Hi. I’m using dolfin 2018.1.0 to solve an eigenvalue problem using finite elements. I want to assemble the matrix “a” given by “a = inner(u , grad(p * v) )*dx”, where u is the Trial Function, v the Test Function and p(x) an scalar function. But when I try run

a = inner(u , grad(p * v) )dx
dummy = v
dx
A = PETScMatrix()
l = PETScVector()

assemble_system(a, dummy, bcs, A_tensor=A, b_tensor=l) #bcs the Boundary Conditions

I receive the error message “Cannot determine geometric dimension from expression”. What is the correct way to perform the matrix inner(u , grad(p * v) )*dx?

Please supply a minimal working example that can reproduce the error. This means including definitions of your mesh, your function spaces etc.

Ok. The program is:

from dolfin import *
if not has_linear_algebra_backend("PETSc"):
    print("DOLFIN has not been configured with PETSc. Exiting.")
    exit()
if not has_slepc():
    print("DOLFIN has not been configured with SLEPc. Exiting.")
    exit()

from mshr import *
import numpy as np
import matplotlib.pyplot as mpl

mesh = IntervalMesh(300, 0, 5)
V = FunctionSpace(mesh, "CG", 2)

u0 = Constant(0) 
u1 = Constant(0)

def DirichletBoundary_0(x, on_boundary):
    tol = 1e-14
    return on_boundary and abs(x[0]-X0) < tol

def DirichletBoundary_1(x, on_boundary):
    tol = 1e-14
    return on_boundary and abs(x[0]-X1) < tol

bc_0 = DirichletBC(V, u0, DirichletBoundary_0)
bc_1 = DirichletBC(V, u1, DirichletBoundary_1)

bcs = [bc_0, bc_1]

p = Expression('x[0]*x[0]',degree=2)
q = Expression('l*(l+1) - 2*x[0]',degree=1, l=1)

u = TrialFunction(V)
v = TestFunction(V)

a = inner(grad(u), grad(p*v))*dx
b = q * inner(u,v)*dx
c = p * inner(u,v)*dx

dummy = v*dx
A = PETScMatrix()
B = PETScMatrix()
ll = PETScVector()

assemble_system(a+b, dummy, bcs, A_tensor=A, b_tensor=ll)
assemble_system(c, dummy, bcs, A_tensor=B, b_tensor=ll)

#solve now around
point = -0.25
eigensolver = SLEPcEigenSolver(A, B)
eigensolver.parameters["solver"] = "krylov-schur"
eigensolver.parameters["problem_type"] = "gen_hermitian"
eigensolver.parameters["spectrum"] = "target magnitude"
eigensolver.parameters["spectral_transform"] = "shift-and-invert"
eigensolver.parameters["spectral_shift"] = point
eigensolver.parameters["tolerance"] = 1.e-5
eigensolver.parameters["maximum_iterations"] = 200

PETScOptions.set("eps_view")

eigensolver.parameters["spectrum"] = 'smallest real'
neigs = 7
eigensolver.solve(neigs)
print(eigensolver.get_number_converged())
´´´

Please encapsulate the code with ``` and make sure that the code can be copy-pasted into an editor and executed without any changes in formatting.

at a glance it looks like some of your Expression objects haven’t been provided with a reference to your mesh. This means the ufl.grad operator cannot implicitly determine their geometric dimension. E.g. p = Expression("...", ..., domain=mesh) would rectify such an issue.

1 Like