Thank you for the prompt reply. The inverse of the matrix addition will be 
used to construct a preconditioner for the solution of the original system 
with FGMRES.

On Wednesday, July 26, 2017 at 3:15:51 PM UTC+9, Jean-Paul Pelteret wrote:
>
> Dear Anna,
>
> So it appears that you're hitting this assertion 
> <https://github.com/dealii/dealii/blob/master/include/deal.II/lac/sparse_matrix.templates.h#L364>,
>  
> which is not checking that the sparsity pattern looks the same but rather 
> that both blocks reference the same sparsity pattern object 
> <https://github.com/dealii/dealii/blob/master/include/deal.II/lac/sparse_matrix.h#L1596>.
>  
> Since you build up your system as a block system, even if your 
> discretisations for E_re and E_im are the same, the different blocks of the 
> block sparse matrix each reference a different sparsity pattern (as stored 
> in the blocks in dsp).
>
> Depending on what you're wanting to do here, the LinearOperator 
> <https://www.dealii.org/8.5.0/doxygen/deal.II/classLinearOperator.html> 
> class *might* offer a work-around for this issue. What are you ultimately 
> going to do with the result of the matrix addition?
>
> Regards,
> Jean-Paul
>
> On Wednesday, July 26, 2017 at 5:14:11 AM UTC+2, Anna Avdeeva wrote:
>>
>> Dear All,
>>
>> I need to subtract two blocks of a BlockSparseMatrix<double> 
>> system_matrix.
>> I am trying to achieve this by 
>> creating SpraseMatrix<double> tmp1, then 
>>   tmp1.copy_from(system_matrix.block(0,0));
>>   tmp1.add(-1.0, system_matrix.block(0,1));
>>
>> However, I am getting the following error message:
>> "When copying one sparse matrix into another, or when adding one sparse 
>> matrix to another, both matrices need to refer to the same sparsity 
>> pattern."
>>
>> Could you please help me to overcome this problem? 
>>
>> system_matrix has BlockSparsityPattern sparsity_pattern;
>>
>> which was obtained in the following way:
>>
>> BlockDynamicSparsityPattern dsp (2, 2);
>> dsp.block (0, 0).reinit (n_E_re, n_E_re);
>> dsp.block (1, 0).reinit (n_E_im, n_E_re);
>> dsp.block (0, 1).reinit (n_E_re, n_E_im);
>> dsp.block (1, 1).reinit (n_E_im, n_E_im);
>> dsp.collect_sizes ();
>> DoFTools::make_sparsity_pattern (dof_handler, dsp, constraints,
>>         false);
>> sparsity_pattern.copy_from (dsp);
>>
>>
>> I have tried various ways of declaring tmp1. Such as 
>> SparseMatrix<double> tmp1(system_matrix.block(0,0).get_sparsity_pattern())
>> or creating tmp1 as BlockSparseMatrix<double> tmp1(sparsity_pattern)
>>
>> Thank you in advance for your help. 
>>
>>
>>

-- 
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