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

AttributeError: 'VectorElement' object has no attribute 'mesh'

0 votes

Currently, I am doing steady state forced convection flow. I use mixed element to define the function space:

from future import print_function
from fenics import *

set parameter values

rho = 997.1 #density water
mu = 1 #0.890*10^-3 #dynamic viscosity water
sigma = 0.05501 #electrical conductivity water
C = 4179 #heat capacitance water
c = 0.591 #thermal conductivity water
B_0 = 0

create mesh

mesh = UnitSquareMesh(8,8)

define function space

V = VectorElement('P', mesh.ufl_cell() , 2)
Q = FiniteElement('P', mesh.ufl_cell(), 2)
element = MixedElement([Q, V, Q])
W = FunctionSpace(mesh, element)

However, there is error:

File "steady.py", line 43, in
bcu_walls = DirichletBC(V, Constant(0), walls)
File "/usr/lib/python2.7/dist-packages/dolfin/fem/bcs.py", line 90, in init
mpi_comm = args[0].mesh().mpi_comm()
AttributeError: 'VectorElement' object has no attribute 'mesh'
Aborted (core dumped)

I dont know how to solve this problem. Thank you for your help.

asked May 24, 2017 by Raihan FEniCS Novice (220 points)

1 Answer

0 votes

DirichletBCs need to be defined on a FunctionSpace not a FiniteElement. Furthermore, V here is a VectorElement and the spatial dimension of your boundary function must match the dimension of the spatial dimension of the functions in the function space.

Try:

bcu_walls = DirichletBC(W.sub(1), Constant((0, 0)), walls)

And in the future please take care to correctly format the code in your questions.

answered May 24, 2017 by nate FEniCS Expert (17,050 points)

I stuck on the boundary condition. I still cant run the program. I am working on the forced convection at vertical plate.

My boundary condition is:

u=v=o, T=T_w, at y=0

u=u_e, T--> iuniform temperature when y-->infinity

where u_e is potential velocity

my coding is:

from __future__ import print_function
from fenics import *

#set parameter values
rho = 997.1 #density water
mu = 1 #0.890*10^-3 #dynamic viscosity water
sigma = 0.05501 #electrical conductivity water
C = 4179 #heat capacitance water
c = 0.591 #thermal conductivity water
B_0 = 0

#create mesh
mesh = UnitSquareMesh(8,8)

#define function space
V = VectorElement('P', mesh.ufl_cell() , 2)
Q = FiniteElement('P', mesh.ufl_cell(), 2)
element = MixedElement([Q, V, Q])
W = FunctionSpace(mesh, element)


#define boundaries
outflow = 'near(x[1],1)'
walls = 'near(x[1],0)'

#define boundary condition

#walls
bcu_walls = DirichletBC(W.sub(1), Constant((0,0)), walls)
bcT_walls = DirichletBC(W.sub(2), Constant(), walls) #T_w
bcp_walls = DirichletBC(W.sub(2), Constant(0), walls) #pressure

#outflow
bcu_outflow = DirichletBC(W.sub(1), Constant(1), outflow) #u_e=1
bcT_outflow = DirichletBC(W.sub(2), Constant(295), outflow) #uniform temperature
bcp_outflow = DirichletBC(W.sub(2), Constant(1), outflow)

bcu = [bcu_walls, bcu_outflow]
bcT = [bcT_walls, bcT_outflow]
bcp = [bcp_walls, bcp_outflow]

Thank you for your help. I dont know how to code my boundary conditions.

why does the Constant on this line:

bcT_walls = DirichletBC(W.sub(2), Constant(), walls) #T_w

have no argument?

Sorry for the mistake.

from __future__ import print_function
from fenics import *

#set parameter values
rho = 997.1 #density water
mu = 1 #0.890*10^-3 #dynamic viscosity water
sigma = 0.05501 #electrical conductivity water
C = 4179 #heat capacitance water
c = 0.591 #thermal conductivity water
B_0 = 0

#create mesh
mesh = UnitSquareMesh(8,8)

#define function space
V = VectorElement('P', mesh.ufl_cell() , 2)
Q = FiniteElement('P', mesh.ufl_cell(), 2)
element = MixedElement([Q, V, Q])
W = FunctionSpace(mesh, element)

#define boundaries
outflow = 'near(x[1],1)'
walls = 'near(x[1],0)'

#define boundary condition

#walls
bcu_walls = DirichletBC(W.sub(1), Constant((0,0)), walls)
bcT_walls = DirichletBC(W.sub(2), Constant(290), walls) #T_w #cooled surface
bcp_walls = DirichletBC(W.sub(2), Constant(0), walls) #pressure

#outflow
bcu_outflow = DirichletBC(W.sub(1), Constant(1), outflow) #u_e=1
bcT_outflow = DirichletBC(W.sub(2), Constant(295), outflow) #uniform temperature
bcp_outflow = DirichletBC(W.sub(2), Constant(1), outflow)

bcu = [bcu_walls, bcu_outflow]
bcT = [bcT_walls, bcT_outflow]
bcp = [bcp_walls, bcp_outflow]

Can you help me? Thank you.

There is error when i run the coding:

File "steady.py", line 46, in
bcu_outflow = DirichletBC(W.sub(1), Constant(1), outflow) #u_e=1 File "/usr/lib/python2.7/dist-packages/dolfin/fem/bcs.py", line 136,
in init
cpp.DirichletBC.init(self, args) File "/usr/lib/python2.7/dist-packages/dolfin/cpp/fem.py", line 1487, in
init
_fem.DirichletBC_swiginit(self, _fem.new_DirichletBC(
args)) RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at


*** fenics-support@googlegroups.com


*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.


*** -------------------------------------------------------------------------
*** Error: Unable to create Dirichlet boundary condition.
*** Reason: Expecting a vector-valued boundary value but given function is scalar.
*** Where: This error was encountered inside DirichletBC.cpp.
*** Process: 0


*** DOLFIN version: 2016.2.0
*** Git changeset: unknown
*** -------------------------------------------------------------------------

Aborted (core dumped)

Thanks in advance.

...