This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

I am getting this error when I run my code "Invalid ranks 1 and 1 in product."

+1 vote

from dolfin import *

if has_linear_algebra_backend("Epetra"):
parameters["linear_algebra_backend"] = "Epetra"

Create mesh and define function space

print("solving for mesh")

mesh = UnitSquareMesh(100, 100)
File("mesh.pvd") << mesh

Creating functionspace

V = FunctionSpace(mesh, "CG", 1)

Define boundary condition

S0 = Constant(8.3e-3)
bc = DirichletBC(V, S0, "x[0] < 0 || x[0] > 1 || x[1] < 0")

Define variational problem

D = Constant(0.5)
S = TrialFunction(V)
v = TestFunction(V)
Q = ('S(pow(C+S,-1)',1,4.0,S)
F = D
dot(grad(S)grad(v)dx) - dot(Qvdx)

Compute solution

solve(F == 0, S, bc, solver_parameters={"newton_solver":
{"relative_tolerance": 1e-10}})

Plot solution

plot(S, title="Concentration")
interactive()

Blockquote

asked Jun 30, 2017 by Hridyesh Raj Tewani FEniCS Novice (150 points)

1 Answer

0 votes

Please notice: It is way easier to find issues if you would use the code environment.

Your problem is probably caused by a synthax or typing error: It will disappear if you define your weak form as follows:

F = D*dot(grad(S),grad(v))*dx 

Further remark: Your solution line:

solve(F == 0, S, ...) won't work

Maybe have a look how the solve function works in FEniCS and think about something like:

l = Constant(0)*v*dx 
u = Function(V)
solve(F == l, u, ...)
answered Jun 30, 2017 by RR FEniCS User (3,330 points)

I tried running the code with the changes and it again showed me some errors. the major problem is the term 'Q" which depends on the trial function 'u' and is present in the variational form too!!!

Error:

ufl.log.UFLValueError: Invalid type conversion: ('u*(pow(C+u,-1)', 1, 4.0, Argument(FunctionSpace(Mesh(VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2), 21), FiniteElement('Lagrange', triangle, 1)), 1, None)) can not be converted to any UFL type.

from dolfin import *

if has_linear_algebra_backend("Epetra"):
    parameters["linear_algebra_backend"] = "Epetra"

# Create mesh and define function space
print("solving for mesh")

mesh = UnitSquareMesh(100, 100)
File("mesh.pvd") << mesh

#Creating functionspace
V = FunctionSpace(mesh, "CG", 1)

# Define boundary condition
S0 = Constant(8.3e-3)
bc = DirichletBC(V, S0, "x[0] < 0 || x[0] > 1  || x[1] < 0")

# Define variational problem
D = Constant(0.5)
u = TrialFunction(V)
v = TestFunction(V)
Q = ('u*(pow(C+u,-1)',1,4.0,u) #this variable has dependency on the trial function and is also there in the variational form

print("success")

F = D*dot(grad(u),grad(v))*dx - dot(Q,v)*dx
print("success2")

# Compute solution
l = Constant(0)*v*dx 
u = Function(V)
solve(F == l, u, bc, solver_parameters={"newton_solver":
                                        {"relative_tolerance": 1e-10}})

# Plot solution 
plot(S, title="Concentration")
interactive()
...