Combining discontinuous vectors in a coefficient matrix

Asked by Alex Evans

Hi,

To give a rough outline of what i am trying to do: I am trying to combine the methods given in http://fenicsproject.org/documentation/tutorial/materials.html#working-with-two-subdomains and http://bazaar.launchpad.net/~dolfin-core/dolfin/trunk/view/head:/demo/undocumented/tensor-weighted-poisson/python/demo_tensor-weighted-poisson.py to solve a tensor weighted poisson problem where the values in the tensor vary across the domain.

I have reached the stage of trying to create said tensor as shown:

for cell_no in range(len(subdomains.array())):
        subdomain_no = subdomains.array()[cell_no]
        kx.vector()[cell_no] = kx_values[subdomain_no]
        ky.vector()[cell_no] = ky_values[subdomain_no]

K = as_matrix(((Expression("k1", k1=1.0), 0), (0, Expression("k2",k2=1.0))))
K[0][0].k1 = kx.vector()
K[1][1].k2 = ky.vector()

u = TrialFunction(V)
v = TestFunction(V)

a = inner(K*nabla_grad(u), nabla_grad(v))*dx
L = f*v*dx
u = Function(V)

solve(a == L, u, [bc, bc2])

(this is a snippet of the code but when defining the kx and ky vectors I have used the method from the first link above, these are the vectors that vary across the domain)

Now, I realise of course that I am trying for put vectors into a scalar space in the matrix but this gives an idea of what I would ideally like to do, ie. to arrive at a matrix which is both usable by dolfin and where the coefficients of the elements of grad(u) are multiplied by the two sets of varying coefficients. Any hints would be much appreciated.

Cheers
Alex

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Marie Rognes
Solved:
Last query:
Last reply:
Revision history for this message
Best Marie Rognes (meg-simula) said :
#1

Assuming that kx and ky are members of dolfin.Function: try this instead:

  K = as_matrix(((kx, 0), (0, ky)))

For later reference, please include a minimal, runnable example when asking a question (yours is not runnable) -- that makes it much easier to help.

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

Thanks Marie Rognes, that solved my question.

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

Thanks Marie, annoying that, as always I haven't spotted the obvious solution. Noted on the format for asking questions

Alex