Bug in createAIJ function ?


44
views
-1
25 days ago by
Name  
Hi,

I have a problem with setValuesCSR with a big model. The filling of the matrix is very very long whereas with numpy it is instantaneous. Therefore, i use the createAIJ function in order to filling my matrix. However i have a problem with this function. When i test these lines:
A1=PETScMatrix()
A1.mat().createAIJ(size=(size_mat+size_groups, size_mat+size_groups), nnz=size_mat+size_groups*2 ,csr=(row_i,AValues[1],AValues[2]))
print A1.mat().getValuesCSR()

A1=PETScMatrix().mat().createAIJ(size=(size_mat+size_groups, size_mat+size_groups), nnz=size_mat+size_groups*2 ,csr=(row_i,AValues[1],AValues[2]))
print A1.getValuesCSR()


Results:
(array([0], dtype=int32), array([], dtype=int32), array([], dtype=float64))

(array([     0,      9,     18, ..., 578061, 578061, 578061], dtype=int32), array([    0,   264,   351, ..., 27828, 27829, 27830], dtype=int32), array([  8.65384615,  -1.92307692,  -6.73076923, ...,  -2.55443313,
        -2.72414887,  13.38645699]))


The first solution gives a bad result while the second gives good results. I would like to use the first solution so that I can use the basic functions of fenics (solve, ...). Could you help me ?

Thank you !
Best regards,
Arnaud





Community: FEniCS Project
The questions should have an MWE. Read https://www.allanswered.com/post/emre/read-before-posting-how-do-i-get-by-my-question-answered/

Omit boilerplate like Hi and Regards, it is useless in QA forum.
written 25 days ago by Jan Blechta  

2 Answers


2
25 days ago by
The first case is not supposed to work. You're using the petsc4py API wrong. It does not modify (already initialized!) matrix in place - rather it creates new.

For your use case. Create petsc4py matrix and then initialize DOLFIN PETScMatrix using existing the existing petsc4py object.
1
25 days ago by
Name  
thank you for your help! It works
A2=PETScMatrix().mat().createAIJ(size=(size_mat+size_groups, size_mat+size_groups),nnz=size_mat+size_groups*2 ,csr=(row_i,AValues[1],AValues[2]))
A1=PETScMatrix(A2)
print A1.mat().getValuesCSR()
​
Please login to add an answer/comment or follow this question.

Similar posts:
Search »