Question about dolfin.cpp.la.Matrix

Hello, everyone
I am working on fenics 2019.1, I have some question about the class dolfin.cpp.la.Matrix

  1. Whether fenics supports basic matrix operations.(for example add,subract, multiply, divide, inv…)
  2. Whether fenics supports advanced matrix operations.For example, Creating a specified size fenics matrix and updating the value of the element. Calculating the fenics matrix eigenvalues and eigenvectors…
  3. If fenics can not complete some matrix operations. Maybe i need extra package(numpy and …). I can convert fenics matrix to numpy array using M01.array(), but this approach will fail when the size of matrix is very large (error: memory leak). Is there any package to recommend?

Thank you to anyone for your recovery!

See: Bitbucket for all functions associated with a matrix.

Note that if you use `as_backend_type(A).mat() you most likely get a petsc4py matrix and can use all their operations

Thank you for your reply!
I’m already learning PETSC basic the fenics 2019.1, but i am getting an error as follows:

import sys
import petsc4py
from fenics import *

petsc4py.init(sys.argv)
from petsc4py import PETSc

A = PETSc.Mat()
A.create(comm=PETSc.COMM_WORLD)
A.setSizes((5, 5))

A.setType(PETSc.Mat.Type.AIJ)

A[1, 1] = 999

A.assemblyBegin()
A.assemblyEnd()

print(A.getValues(1, 1))

error:
[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind
[0]PETSC ERROR: or try http://valgrind.org on GNU/linux and Apple Mac OS X to find memory corruption errors
[0]PETSC ERROR: configure using --with-debugging=yes, recompile, link, and run 
[0]PETSC ERROR: to get more information on the crash.
application called MPI_Abort(MPI_COMM_WORLD, 59) - process 0
[unset]: write_line error; fd=-1 buf=:cmd=abort exitcode=59
:
system msg for write_line failure : Bad file descriptor
Error in system call pthread_mutex_destroy: Device or resource busy
    src/mpi/init/initthread.c:284

When I run the same code in another python environment(no fenics), there is no error.

Your code is running correctly on my installation, and prints 999.0.

The issue is likely in your installation. Without any indication on how you installed dolfin it’s impossible to be of further help.

Thank you for reply!
I installed miniconda under linux system, then install fenics as follows

conda create -n fenicsproject -c conda-forge fenics

This is the version information
dolfin.version 2019.1.0

Did you add other libraries after creating the conda environment? If so, please create a further one and keep it clean of anything else, and confirm if the code works or not.

Thank you for your reply!
The code can work after i installed feics in a new conda environment. The above error may be caused by me installing some extra python package. Now I wonder what I should pay attention to when I install the extra package (eg gmsh, meshio, and etc …)

If you use conda, i would highly recommend to install all other required packages with conda. Mixing pip and conda can cause tons of issues