Hello all,
I am following a finite element course (they use FEniCS) “High Performance Finite Element Modeling”. Some of the codes are out dated:
# FEM function spaces and functions
V = VectorFunctionSpace(mesh, "CG", 1);
Q = FunctionSpace(mesh, "CG", 1);
W = V * Q; # outdated part
h = CellSize(mesh);
(v, q) = TestFunctions(W);
w = Function(W);
(u, p) = (as_vector((w[0], w[1])), w[2]);
u0 = Function(V)
I wrote elements and function spaces in a different way, now I have another problem UFLException: Can't add expressions with different shapes.
It originates from elements or function spaces. I spent some time on it -i think it has a simple solution but couldn’t find something similar, and asked on course’s discussion board has no replies- so I couldn’t figure it out. I have the following code:
# Generate mesh
mresolution=30
mesh = generate_mesh(Rectangle(Point(G[0], G[2]), Point(G[1], G[3])) - Circle(Point(.5, .5), .1), mresolution)
# Elements
el = FiniteElement("CG", mesh.ufl_cell(), degree=1);
vel = VectorElement("CG", mesh.ufl_cell(), degree=1);
element = MixedElement([vel, el]);
# Function spaces
V = VectorFunctionSpace(mesh, vel, degree=1);
W = FunctionSpace(mesh, element);
h = 2*Circumradius(mesh);
(v, q) = TestFunctions(W);
w = Function(W);
(u, p) = (as_vector((w[0], w[1])), w[2]);
u0 = Function(V)
The rest is the same w/ the original example. At the end I have this error
--> 109 um = theta*u + (1.0-theta)*u0
UFLException: Can’t add expressions with different shapes.
Since theata = 0.5,
I think there is a problem with u and u0.
What I did and failed?
I thought since we have this
(u, p) = (as_vector((w[0], w[1])), w[2]);
u have (w[0], w[1]) . So the dimensions of u0 (degree of V is 1) should match with the dimension of u (which should be 2 since we have w[0] and w[1]) and I thought degree of V should be 2 instead of 1 but it didn’t work.
So I have 2 questions:
- How can I solve this problem?
- What is happening in
(u, p) = (as_vector((w[0], w[1])), w[2]);
Thanks for following along !
Note1: I don’t know much about FEniCS, so I wasn’t able to post a minimal working example from the existed code.
Note2: I am new to finite elements and coding so I might not be using the correct terminology.