FFC

big numpy arrays - out of memory

Asked by Melanie Jahny

I'm solving an optimal control problem concerning the Advection Diffusion Equation using FEniCS.
During the calculation I need the QR decomposition of a matrix with size (Number of BasisFunctions) x (Number of Triangles) and I need to invert and transpose matrices. (I'm using Raviart Thomas Finite Elements)
I tried this with the numpy functions and numpy arrays,
but because my matrices are very big, the functions causes "Out of memory" errors.

I wonder if there is an alternative in Fenics for the numpy functions, perhaps using the lapack routines, but I don't know how to use them.
Any advice how I can do this better would be useful.

Here is my Fenics Code:

import numpy as np
from numpy import*

x_max = 154.0 # maximum x-coordinate
y_max = 0.78 # maximum y-coordinate

# define rectangle mesh
mesh = Rectangle(0,0, x_max, y_max, 78, 154)
mesh.order()

U = FunctionSpace(mesh, "Raviart-Thomas", 1)
W = FunctionSpace(mesh, "DG", 0)

psi = TrialFunction(U)
phi = TestFunction(W)

int_psi = phi*div(psi)*dx
Cmat_tr = assemble(int_psi)
C_mat = Cmat_tr.array().T

Q_mat,R_mat = np.linalg.qr(self.C_mat)
Q_t = Q_mat.T
R_inv = np.linalg.inv(R_mat)

Question information

Language:
English Edit question
Status:
Solved
For:
FFC Edit question
Assignee:
No assignee Edit question
Solved by:
Garth Wells
Solved:
Last query:
Last reply:
Revision history for this message
Best Garth Wells (garth-wells) said :
#1

On 20 September 2011 10:15, Melanie Jahny
<email address hidden> wrote:
> New question #171750 on FFC:
> https://answers.launchpad.net/ffc/+question/171750
>
> I'm solving an optimal control problem concerning the Advection Diffusion Equation using FEniCS.
> During the calculation I need the QR decomposition of a matrix with size (Number of BasisFunctions) x (Number of Triangles) and I need to invert and transpose matrices. (I'm using Raviart Thomas Finite Elements)
> I tried this with the numpy functions and numpy arrays,
> but because my matrices are very big, the functions causes "Out of memory" errors.
>
> I wonder if there is an alternative in Fenics for the numpy functions, perhaps using the lapack routines, but I don't know how to use them.
> Any advice how I can do this better would be useful.
>

I think you'll find that numpy uses Lapack. The more likely problem is
that the numpy functions are for dense matrices.

We don't provide any explicit QR interfaces. Something could be
accessed from the C++ interface by working directly with the la
backends. We could also add an interface, but that won't happen too
quickly. Another work around would be to use PyTrilinos inside DOLFIN.

You should also avoid computing the inverse of R.

Garth

> Here is my Fenics Code:
>
> import numpy as np
> from numpy import*
>
> x_max = 154.0 # maximum x-coordinate
> y_max = 0.78  # maximum y-coordinate
>
> # define rectangle mesh
> mesh = Rectangle(0,0, x_max, y_max, 78, 154)
> mesh.order()
>
> U = FunctionSpace(mesh, "Raviart-Thomas", 1)
> W = FunctionSpace(mesh, "DG", 0)
>
> psi = TrialFunction(U)
> phi = TestFunction(W)
>
> int_psi = phi*div(psi)*dx
> Cmat_tr = assemble(int_psi)
> C_mat = Cmat_tr.array().T
>
> Q_mat,R_mat =  np.linalg.qr(self.C_mat)
> Q_t = Q_mat.T
> R_inv = np.linalg.inv(R_mat)
>
>
> --
> You received this question notification because you are a member of FFC
> Team, which is an answer contact for FFC.
>

Revision history for this message
Melanie Jahny (melanie-jahny) said :
#2

Thanks you Garth for the information and the quick answer.
Perhaps I'll try with C++ or PyTrilios.