Error: Cannot determine geometric dimension from expression

I am sorry for asking this but I am very new to this. Grad doe snot work.
The error is

Cannot determine geometric dimension from expression.

mesh = UnitSquareMesh(10,10)
RT1 = FiniteElement("RT", mesh.ufl_cell(), 1)
CG1 = FiniteElement("CG", mesh.ufl_cell(), 1)
mixed_B = MixedElement([RT1, CG1])
W_B = FunctionSpace(mesh, mixed_B)
uinitial = Expression(" exp(x[1] + x[0] - t)", t = 0, degree = 2)
q0 = project(grad(uinitial), W_B.sub(0).collapse(), t = 0)

Use spatial coordinates:

from dolfin import * 
mesh = UnitSquareMesh(10,10) 
RT1 = FiniteElement("RT", mesh.ufl_cell(), 1) 
CG1 = FiniteElement("CG", mesh.ufl_cell(), 1) 
mixed_B = MixedElement([RT1, CG1]) 
W_B = FunctionSpace(mesh, mixed_B) 
x = SpatialCoordinate(mesh) 
t= Constant(0) 
uinitial = exp(x[1] + x[0] -t) 
q0 = project(grad(uinitial), W_B.sub(0).collapse())  

and use

t.assign(value)

to update t.

2 Likes

or just provide the spatial domain to the expression:

uinitial = Expression(" exp(x[1] + x[0] - t)", t=0, degree=2, domain=mesh)
1 Like

Thanks . but it was not working … may be i missed something.

thank you very much… it worked