On 05/24/2017 06:02 AM, Juan Carlos Araujo Cabarcas wrote:
I managed to do it by looking at: *PETScWrappers::MatrixBase*, but my solution is extremely ugly!

|
doublemax_coup_dofs =dof_handler.max_couplings_between_dofs();
PETScWrappers::SparseMatrixlocal_M;
   local_M.reinit (par.dofs,par.dofs,max_coup_dofs);

MatSetOption(local_M,MAT_NEW_NONZERO_ALLOCATION_ERR,PETSC_FALSE);

{// reading and parsing from (Mat M_read) into PETScWrappers::SparseMatrix local_M;
PetscIntbegin,end;
constintierr =MatGetOwnershipRange(static_cast<constMat&>(M_read),&begin,&end);

std::pair<PETScWrappers::MatrixBase::size_type,PETScWrappers::MatrixBase::size_type>
                             loc_range =std::make_pair (begin,end);

PetscIntncols;
constPetscInt*colnums;
constPetscScalar*values;

PETScWrappers::MatrixBase::size_type row;
for(row =loc_range.first;row <loc_range.second;++row){
intierr =MatGetRow(M_read,row,&ncols,&colnums,&values);
(void)ierr;
AssertThrow(ierr ==0,PETScWrappers::MatrixBase::ExcPETScError(ierr));

for(PetscIntcol =0;col <ncols;++col){
// cout << "(" << row << "," << colnums[col] << ") " << values[col] << 
std::endl;
local_M.set(row,colnums[col],values[col]);
}

ierr =MatRestoreRow(M_read,row,&ncols,&colnums,&values);
AssertThrow(ierr ==0,PETScWrappers::MatrixBase::ExcPETScError(ierr));
}
//AssertThrow (out, ExcIO());
}

   local_M.compress (VectorOperation::add);

This would work. What bothers you about it?

Code like this could of course also be put into the library if you felt like writing a patch! :-)


By the way, I noticed also the definition:
|
MatrixBase::operatorMat()const
{
returnmatrix;
}
|
By I was unable to use it!

You are using it:
  MatSetOption( local_M, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
Using `local_M` in the first argument implicitly calls the conversion operator.

Best
 W.


--
------------------------------------------------------------------------
Wolfgang Bangerth          email:                 bange...@colostate.edu
                           www: http://www.math.colostate.edu/~bangerth/

--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to dealii+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to