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

Custom function space

+2 votes

Is it possible to add a custom function space, e.g. Fourier-like series of sinusoids? Can I use an existing space with limited coefficients e.g. polynomials of arbitrary order (high) with arbitrary coefficients. It would be a subspace of existing CG or DG spaces.

asked Nov 30, 2015 by bp FEniCS Novice (520 points)

1 Answer

+5 votes
 
Best answer

The R space is convenient for global functions like Fourier series etc. Consider
the following:

from fenics import *

n = 16
mesh = UnitIntervalMesh(n)

dim = 4
R = VectorFunctionSpace(mesh, "R", 0, dim=dim)
x = SpatialCoordinate(mesh)

omega = Constant(2.0*pi)

sinbasis = [sin((i+1)(omegax[0])) for i in range(dim)]

udofs = TrialFunction(R)
vdofs = TestFunction(R)
ubasis = [udofi * sini for udofi, sini in zip(udofs, sinbasis)]
vbasis = [vdofi * sini for vdofi, sini in zip(vdofs, sinbasis)]
u = sum(ubasis)
v = sum(vbasis)

a = inner(grad(u), grad(v))*dx(degree=4)
A = assemble(a)

print A.array()

answered Nov 30, 2015 by Kent-Andre Mardal FEniCS Expert (14,380 points)
selected Dec 2, 2015 by bp

Thank You for a quick response,

It's like a "chain rule", only coefficients in the series are subject to variation.
I'm not sure how to express the solution in terms of ubasis and vbasis. Does it belong to "R" space?

I don't know what you mean by "chain rule".
Your solution will now be expressed in terms of the Fourier series.

...