← Back to team overview

dolfin team mailing list archive

Re: Plot a constant Expression with different values in the x and y directions

 

Hi,

Anna Blechingberg wrote:
Hi,

I have difficulties with plotting a constant function in dolfin version
0.9.4. I can do it in version 0.9.3, but need it to work in 0.9.4 too.

The problem is that I have different values in the x and y directions, 0
and 9.82 respectively.

The code is as follows:

------------

mesh = Mesh("circle.xml.gz")

# Define function space
V = VectorFunctionSpace(mesh, "CG", 1)
W = FunctionSpace(mesh, "CG", 1)

# I have tried with two different definitions of the function, but don't
know which one is correct:

# Expression for acceleration force
class Acceleration(Expression):
    def eval(self, value, x):
        value[0] = 0.0
        value[1] = -9.82 # 1g acceleration downwards

f = Acceleration(V=W)

g = Constant(mesh,(0, 9.82)) # I can plot g in dolfin version 0.9.3 and
it works correctly there

-----------------------------------------

Do the Constant definition of g also work in dolfin version 0.9.4 even
if I can't plot it?

The function interface has changed a bit in 0.9.4, such that you don't define Constant function any longer with a mesh, you just pass in the desired value.

If you want to plot it, just used the mesh argument of the plot function, e.g.

c = Constant((0,1))
m = UnitSquare(3,3)
plot(c,mesh=m)

HTH,
Andre



References