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

Variational fomulation for energy equation

0 votes

Hello, I am currently working on forced convective flow. However, I have problem in running the code for my variational formulation at energy equation.

This is my energy equation:

rhoC(u.grad(T))=c*div(grad(T)

This is my coding:

#define test functions
(v, q, s) = TestFunctions(W)

#define functions
u = Function(W)
p = Function(W)
T = Function(W)

#split functions
w =Function(W)
(u, p, T) = w.split()

#define expression used in variational forms
n = FacetNormal(mesh)
mu = Constant(mu)
rho = Constant(rho)
sigma = Constant(sigma)
C = Constant(C)
c = Constant(c)
B_0 = Constant(B_0)

#define variational problem
F=nabla_grad(u)*q*dx \
+rho*dot(dot(u,nabla_grad(u)),v)*dx+dot(p,nabla_grad(v))*dx- dot(n*p,v)*ds \
+dot(mu*nabla_grad(u),nabla_grad(v))*dx \
-dot(n*nabla_grad(u),v)*ds+dot(sigma*pow(B_0,2)*u,v)*dx \ 
+rho*C*dot(u,nabla_grad(T))*s*dx-c*div(nabla_grad(T))*s*dx #energy equation

There is error while running the code:

Invalid ranks 1 and 1 in product. Traceback (most recent call last):
File "steady.py", line 79, in
+rhoCdot(u,nabla_grad(T))sdx-cdiv(nabla_grad(T))sdx File "/usr/lib/python2.7/dist-packages/ufl/exproperators.py", line 190, in
_mul
return _mult(self, o) File "/usr/lib/python2.7/dist-packages/ufl/exproperators.py", line 165, in
_mult
error("Invalid ranks {0} and {1} in product.".format(r1, r2)) File "/usr/lib/python2.7/dist-packages/ufl/log.py", line 171, in error
raise self._exception_type(self._format_raw(
message)) ufl.log.UFLException: Invalid ranks 1 and 1 in product. Aborted (core
dumped)

Could you help me? Thanks in advance.

asked Jun 1, 2017 by Raihan FEniCS Novice (220 points)

1 Answer

+1 vote

Hey Raihan,
I am not really sure, but I think you may have a problem due to the fact of working with a scalar and vector field as the error message says about the ranks of the tensors.
Keep in mind that the velocity is a vector field while the temperature is a scalar one.
I don't know how you defined the space W but maybe you could define different spaces.
There is an example in the following link for the navier-stokes equation.

https://fenicsproject.org/pub/tutorial/html/._ftut1009.html

I think that there you can find some interesting insights and a better explanation than the one I tried to give you.

All the best, Murilo.

answered Jun 1, 2017 by MuriloMoreira FEniCS Novice (490 points)
...