Hi,
I’m pretty new to Fenics and have run into this error for the first time.
Exception has occurred: UFLException
Can’t add expressions with different shapes.
File “/home/ucarsten/Desktop/PG_0_1_5_G.py”, line 126, in
rhoJ= ((2*rho_2 )/ epsi)- dot(E,grad(grad(rho_2)))
As this seems to be an error that should be quiet common I seem to have been lucky till now.
As this is for an university assignment I wont post the full code (besides it being quiet long at the moment). But what I have been trying to do is calculate some related Differential equations over a 2D mesh. The formula I got problems with is the Jacobian of this
aC = (dot((rho_2**2) / epsi, u) - dot(dot(E, grad(rho_2)), u))*dx
which I’m trying to feed into a non-linear solver
epsi=Constant(1)
V = VectorFunctionSpace(mesh, ‘P’, 1)
Q = FunctionSpace(mesh, ‘Lagrange’, 1)E = Function(V)
E.assign(project(grad(phi), V))
phi being the result of a previous Differential equation over the same meshrho_2=TrialFunction(Q)
u=TestFunction(Q)
rho_2=Function(Q)aC = (dot((rho_2**2) / epsi, u) - dot(dot(E, grad(rho_2)), u))*dx
rhoJ=((2*rho_2 )/ epsi)- dot(E,grad(grad(rho_2)))
rhoproblem = NonlinearVariationalProblem(aC, rho_2, bcd,rhoJ)
rhosolver = NonlinearVariationalSolver(rhoproblem)
So since the normal solve function can work with aC
just not calculate it the problem itself seems to be a dimension mismatch in the jacobian rhoJ
and the error underlines the /
or the epsi
depending if there is a space or between them or not. If this were Matlab I would take a look of the dimensions of the variables and have a play around with that but in Fenics if I print them I get these
(2*rho_2 )/epsi =
2 * f_62 / f_0
dot(E,grad(grad(rho_2))) =
(f_43) . (grad(grad(f_62)))
and to be honest that doesn’t tell me much
I think the problem is either that it isn’t sure how to divide the Trialfunction rho_2 through a Constant or it cant subtract a function x function from a function
but after searching the documentation and googling a lot I don’t think I have gotten any closer to the solution…
any ideas?