(Deleted) Multiply Function Spaces


89
views
-3
4 months ago by
Mesh:

L = 1
H = 0.2
W = 0.2
mesh = BoxMesh(Point(0, 0, 0), Point(L, H, W), 22, 4, 4)

Create function space A:

A = FunctionSpace(mesh, "CG", 1)

Initialise two functions:

X0 = interpolate(Expression('1 + 20*x[2]',degree=1), A)
X1 = interpolate(Expression('1 + 20*x[2]',degree=1), A)

Multiply both functions together:

X2 = X0 * X1

Project X2 onto function space A:

X2 = project(X2, A)

I don't get the numbers I expect, for example:

X0.vector().get_local()[0] = 5
X1.vector().get_local()[0] = 5

So X0.vector().get_local()[0] * X1.vector().get_local()[0] should equal 25.

However X2.vector().get_local()[0] = 24.91070019

Why does this occur?
Also how can I multiply functions together without numerical error and without accessing the local arrays through '.vector().get_local()'?

Thanks!
Community: FEniCS Project
1
I would recommend to provide a MWE, see https://www.allanswered.com/post/emre/read-before-posting-how-do-i-get-by-my-question-answered.
written 4 months ago by Jan Blechta  

1 Answer


1
4 months ago by
Some comments on your question:
1.  If you multiply two linear polynomials, you need to increase the degree of the function space to 2 so that it is polynomial 2nd order accurate
2.  vector.get_local() returns a vector of dofs, whose mapping to grid points may not be obvious, but can be obtained from "vertex_to_dof_map" in general (if this is of interest to you)
3.  By "multiply functions together" besides needing 1. above, do you want to evaluate the product at specific points, or use the product elsewhere?  There are differences between "interpolate" vs.  "project" which you can search on this forum.  Interpolating the product X2 into a 2nd order polynomial space will allow you to call the eval() method on the function to grab the value of the product at any x in your domain (perhaps project will work for this also) if that is what you want to do.

For additional information on a related issue concerning mapping to higher-order function spaces (and that is very well written in the Fenics tutorial), see:
https://fenicsproject.org/pub/tutorial/html/._ftut1020.html#ch:poisson0:convrates
Please login to add an answer/comment or follow this question.
The thread is closed. No new answer/comment may be added.

Similar posts:
Search »
  • Nothing matches yet.