Menu

ngsolve.la.BaseVector and ngsolve.la.BaseMatrix as vector and matrix in NumPy/SciPy

Help
2016-01-15
2016-03-05
  • Gerhard Unger

    Gerhard Unger - 2016-01-15

    I use NGSolve - Python and I want to use gridfunctions(related ngsolve.BaseVector) and
    bilinearforms (related ngsolve.BaseMatrix) as vectors and as matrices in SciPy. Is there a direct
    and easy way to use them as vectors and matrices in SciPy?
    I could not find any reference to this topic.

     
  • Christopher Lackner

    BaseVector -> NumPy Vector:
    bv[:].NumPy()
    get a NgSolve vector by bv[:] from the baseVector and the vector class has a .NumPy() function.

    Matrix is a bit more work because of the SparseMatrix format, but you can use a.mat.COO() to get the COOrdinate format of the matrix and build a scipy sparse.sparse.coo_matrix out of that information.

    BaseVector should be without any hard copying, with the matrix im not entirely sure...

     

Log in to post a comment.