### How to use a source function f that is stored in a matrix?

144

views

0

Suppose I want to solve the PDE that appears in the ft01_poisson.py tutorial file:

-Laplace(u) = f in the unit square

u = u_D on the boundary

u_D = 1 + x^2 + 2y^2

However, suppose also that my source function function f does not have a nice closed form expression and must be computed numerically. To be concrete, suppose my f is a piecewise constant function whose values I have precomputed and stored in a matrix A, and to get the value of f(x,y), I need to read off the corresponding entry in my matrix A.

How do I proceed in solving this PDE? My understanding is that Expression requires code that is compatible with C

-Laplace(u) = f in the unit square

u = u_D on the boundary

u_D = 1 + x^2 + 2y^2

However, suppose also that my source function function f does not have a nice closed form expression and must be computed numerically. To be concrete, suppose my f is a piecewise constant function whose values I have precomputed and stored in a matrix A, and to get the value of f(x,y), I need to read off the corresponding entry in my matrix A.

How do I proceed in solving this PDE? My understanding is that Expression requires code that is compatible with C

Community: FEniCS Project

### 1 Answer

3

You can create a Python subclass of

`Expression`

. See http://fenics.readthedocs.io/projects/dolfin/en/latest/demos/biharmonic/python/demo_biharmonic.py.html for an example.
Please login to add an answer/comment or follow this question.