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

Plot function on IntervalMesh causes Segmentation Fault

+1 vote

I'm having some difficulty plotting a function on an IntervalMesh. The result produces a Segmentation Fault. I am using dolfin version 1.5.

import dolfin as df
mesh = df.IntervalMesh(100, -20, 20)
fs = df.VectorFunctionSpace(mesh, “CG”, 1, 3)
f = df.Function(fs)
f.assign(df.Constant([0, 0, 1]))
df.plot(f)

Thanks in advance,
-- Mark Vousden

asked May 20, 2015 by MVousden FEniCS Novice (260 points)

1 Answer

0 votes

Hi,

I think plot(f) can't work because f is a vector valued function, you should also give the index of f you want to plot e.g f[2], which will return the constant function equal to 1 on the interval:

import dolfin as df
mesh = df.IntervalMesh(100, -20, 20)
fs = df.VectorFunctionSpace(mesh, 'CG', 1, 3)
f = df.Function(fs)
f.assign(df.Constant([0, 0, 1]))
df.plot(f[2])

Is that what you wanted?

answered May 20, 2015 by MathieuFV FEniCS User (1,490 points)

Perhaps I should elaborate - I would like the plot to show vectors, similar to what would happen if you used

mesh = df.RectangleMesh(-10, -10, 10, 10, 10, 10)

in place of the IntervalMesh. I realise I could combine three seperate plots of each component, but I'm looking for the vector display in this case. Thanks for your response though!

Unfortunately, I'm facing the same problem as yours. The plot command can display vector valued functions thanks to the mode="glyphs" but it seems that it doesn't work on interval meshes. Using the glyphs mode works fine on a square mesh though but something lacks with unidimensional domains...

import dolfin as df
mesh1 = df.UnitSquareMesh(10,10)
mesh2 = df.UnitIntervalMesh(10)
fs1 = df.VectorFunctionSpace(mesh1, 'CG', 1, 3)
fs2 = df.VectorFunctionSpace(mesh2, 'CG', 1, 3)
f1 = df.Function(fs1)
f2 = df.Function(fs2)
f1.assign(df.Constant([0, 0, 1]))
f2.assign(df.Constant([0, 0, 1]))
df.plot(f1,mode="glyphs") #Works
df.plot(f2,mode="glyphs") #Crashes
...