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

How can I replicate Constant('triangle') in UFL to Constant('triangle') in Dolfin? works for ufl but not for Fenics.

0 votes

from dolfin import *

Discretization parameters

family = 'Lagrange'
shape = 'triangle'
vel_order = 2
pres_order = 1

eta = Constant(shape)

h_num = 32

mesh

mesh = UnitSquareMesh(h_num, h_num, "crossed")

Define function spaces

V = VectorFunctionSpace(mesh, family, vel_order)
Q = FunctionSpace(mesh, family, pres_order)
W = MixedFunctionSpace([V, Q])
T = FunctionSpace(mesh, family, vel_order)

Test and Trial functions

(u, p) = TrialFunctions(W)
(v, q) = TestFunctions(W)

Equation parameters

z = Function(T)

f = Function(V)

a = (etainner(grad(v), grad(u)) - div(v)p - qdiv(u) + zv[1]u[0] - zv[0]u[1])dx
L = inner(v, f)*dx

w = Function(W)
solve(a == L, w)

(u, p) = w.split()

plot(u)
plot(p)
plot(mesh)
interactive()

asked Dec 7, 2016 by crisperm FEniCS Novice (150 points)

1 Answer

+1 vote
 
Best answer

When instantiating the dolfin.Constant class you have to specify a value. So, in order to stay as close to your example as possible, you can use the constant class in dolfin as follows:

from dolfin import *

family = 'Lagrange'
shape  = 'triangle'
vel_order = 2
pres_order = 1
value = 0. 
eta = Constant(value, cell = shape)

The good thing is that the value of the Constant does not need to be known at compile time. As a result, the value of the Constant can be changed during a computation without requiring re-compilation of c++ code.

answered Dec 7, 2016 by jmmal FEniCS User (5,890 points)
selected Dec 7, 2016 by crisperm
...