← Back to team overview

dolfin team mailing list archive

Re: Visualizing basis functions

 

Anders Logg wrote:
On Sun, Aug 10, 2008 at 03:54:25PM +0200, Evan Lezar wrote:
Hi there

After some time away I have once again been able to try and get do grips with
dolfin.  By a bit of a round about way I was able to solve a magnetic-field
based eigenvalue problem giving me the cutoff wavenumbers for a square
waveguide structure - it is still, however, a work in progress.

One question I do have is regarding the visualization of the results I have
obtained.  To this end I have two questions - the first is simply the
visualization of the basis functions (vector Nedelec) themselves (see the
attached image taken from Finite Element Method for Electromagnetics by Volakis
et al) - how could this be achieved in dolfin?  Put another way - how can I set
the coefficient for a single basis function equal to 1 and zero the rest and
display the result?

Marie Rognes has code for doing just this (plotbases.py in the
bdm-2007 repository). I don't want to post it myself, but I imagine
she would be willing to post the code. Marie?


Of course! If it is still interesting, see the attached python script. It just extracts the values of the basis functions at a suitable set of points on a triangle and gives output for use with matlab plotting.

Try something like

    python plot_bases.py > plot_bases.m
and run plot_basis.m in matlab.
--
Marie E. Rognes
Ph.D Fellow, Centre of Mathematics for Applications, University of Oslo
http://folk.uio.no/meg

# Marie Rognes 2007-10-24

# Extract the values of the Nedelec 0 basis functions at certain
# points and output for easy matlab plotting.

from ffc.fem.finiteelement import *
from ffc.fem.vectorelement import *

element = FiniteElement("Nedelec", "triangle", 0)
spacedim = 3

# Number of points for plotting:
n = 8
h = 1.0/n
x = [ 1.0*h*i for i in range(n+1)]
y = [ 1.0*h*i for i in range(n+1)]

points = []
for i in range(n+1):
    for j in range(n+1-i):
        points += [[x[i], y[j]]]
                   
print "figure"
for num in range(spacedim):
    U = []
    V = []
    X = []
    Y = []
    for point in points:
        X += [point[0]]
        Y += [point[1]]
        values = element.tabulate(0, [point])
        numpyvalue = [values[i][0][(0,0)][num] for i in range(len(values))]
        U += [numpyvalue[0][0]]
        V += [numpyvalue[1][0]]
        
    print "X  =", X
    print "Y = ", Y
    print "U = ", U
    print "V = ", V
    print "subplot(1, %d, %d)" % (spacedim, num+1)
    print "quiver(X, Y, U, V)"
    print "axis square"
    print "grid on"
    print

Follow ups

References