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

Implementing Convection Diffusion PDE with BCs

+1 vote

Hello,

I am new to Fenics and gmsh and was trying to understand BC implementation. I am trying to produce a volcanic shaped mesh from convection diffusion equation using gmsh+fenics.

I was able to create a similar shape from Poisson's equation but I keep getting error in this one about the 'b' vector [20, 0]. The problem is noted below:

The mesh with it's boundaries

The PDE:

The intended output

The following is my code:

Dolfin_bcs_example

from dolfin import *

Create mesh and define function space

mesh = Mesh("abhi1.xml")
boundaries = MeshFunction("size_t", mesh, "abhi1_facet_region.xml")
V = FunctionSpace(mesh, "CG", 1)

Define variational problem

u = TrialFunction(V)
v = TestFunction(V)
f = Constant(1.0)
g = Constant(2.0)
b = [20, 0]
a = dot(b, nabla_grad(u))vdx+dot(nabla_grad(u), nabla_grad(v))dx+guvds
L = fvdx+gvds

Define boundary condition values

u1 = Constant(400.0)
u2 = Constant(0.0)
u3 = Constant(0.0)

Define boundary conditions

bc1 = DirichletBC(V, u1, boundaries, 0) - last argument must match with number (or label) of Physical Surface(0)

bc1 = DirichletBC(V, u1, boundaries, 14) #Physical Lines (Hole in the plate)
bc2 = DirichletBC(V, u2, boundaries, 13) #Physical Lines (Outer boundary of the plate)
bc3 = DirichletBC(V, u3, boundaries, 12) #Physical SUrface

Compute solution

u = Function(V)
solve(a == L, u, [bc1, bc2, bc3])

Write solution to file

File("u.pvd") << u

Plot solution

plot(u, interactive=True)

This is the error displayed:

Invalid type conversion: can not be converted to any UFL type.
The representation of the object is:
[20, 0]
Traceback (most recent call last):
File "abhi2.py", line 14, in
a = dot(b, nabla_grad(u))vdx+dot(nabla_grad(u), nabla_grad(v))dx
File "/usr/lib/python2.7/dist-packages/ufl/operators.py", line 142, in dot
a = as_ufl(a)
File "/usr/lib/python2.7/dist-packages/ufl/constantvalue.py", line 406, in as_ufl
"The representation of the object is:\n%r") % (type(expression), expression))
File "/usr/lib/python2.7/dist-packages/ufl/log.py", line 151, in error
raise self._exception_type(self._format_raw(
message))
ufl.log.UFLException: Invalid type conversion: can not be converted to any UFL type.
The representation of the object is:
[20, 0]

asked Jul 10, 2015 by Chaitanya_Raj_Goyal FEniCS User (4,150 points)
edited Jul 10, 2015 by Chaitanya_Raj_Goyal

You need to indent your code 4 spaces to get it rendering properly on this forum...

1 Answer

+2 votes
 
Best answer

Hi, the advection velocity should be defined as

b = Constant((20, 0))

I would like to remind you of one of the rules of the forum

Post complete, but minimal code examples.

answered Jul 11, 2015 by MiroK FEniCS Expert (80,920 points)
selected Jul 13, 2015 by Chaitanya_Raj_Goyal

Thank you. I' ll be careful next time about the rules.

...