'Variable Coefficient Matrix' Poisson Equation

Asked by Alex Evans

I am trying to solve the 2D Poisson equation: Div( k grad(p))=0 where k is a diagonal matrix.

I have tried the following attempt to modify existing code for a variable coefficient solver (after importing numpy and dolfin)

------------------
k=zeros(2,2)
k[0][0]=Expression("1")
k[1][1]=Expression("2")

a = inner(k*nabla_grad(u), nabla_grad(v))*dx
------------------

The error is generated once I have put these lines in as shown. (The solver works for a=inner(k*nabla_grad(u),nabla_grad(v)) as expected (where k is a scalar expression)).

The error given is that numpy arrays can't have expressions as arguments. How should I get around this? Or if there a very different way i should be approaching this problem?

Cheers

Question information

Language:
English Edit question
Status:
Solved
For:
FEniCS Project Edit question
Assignee:
No assignee Edit question
Solved by:
Felix Ospald
Solved:
Last query:
Last reply:
Revision history for this message
Best Felix Ospald (felix-ospald) said :
#1

I think you have to write

k = as_matrix(((Expression("1"), 0), (0, Expression("1"))))

or have a look at the undocumented/tensor-weigthed-poisson demo

Revision history for this message
Alex Evans (evansalex) said :
#2

Thats great - its at least fixed that step...could you send me the url for that demo by any chance? Can't seem to locate it.

Cheers

Revision history for this message
Felix Ospald (felix-ospald) said :
#3