Hi David,

I am working on fluid-fluid coupling. My goal is to create matrices that
correspond to the interface so that I can put them in 0,1 and 1,0 blocks of
the system matrix.

Here is what I am doing for one of these matrices:

BlockSparseMatrix<double>    system_matrix12;
BlockSparsityPattern  non_diag_sparsity_pattern12;
BlockSparseMatrix<double>    system_matrix;
BlockSparsityPattern  sparsity_pattern;

non_diag_sparsity_pattern12.reinit(2,2);
non_diag_sparsity_pattern12.block(0,0).reinit(dof_u,dof_u2,2*fe1.dofs_per_cell
+ 2*fe2.dofs_per_cell);
non_diag_sparsity_pattern12.block(0,1).reinit(dof_u,dof_p2,2*fe1.dofs_per_cell
+ 2*fe2.dofs_per_cell);
non_diag_sparsity_pattern12.block(1,0).reinit(dof_p,dof_u2,2*fe1.dofs_per_cell
+ 2*fe2.dofs_per_cell);
non_diag_sparsity_pattern12.block(1,1).reinit(dof_p,dof_p2,2*fe1.dofs_per_cell
+ 2*fe2.dofs_per_cell);     //max_per_row is chosen arbitrarily big since
I'll compress it later


// I iterate over the cells and their faces and in a way check to see if
cell1(face_no1) == cell2(face_no2), then    (meshes are matching from the
both side)

fe_face_values1.reinit (cell1, face_no1);
fe_face_values2.reinit (cell2, face_no2);

std::vector<types::global_dof_index> local_dof_indices1 (fe1.dofs_per_cell);
std::vector<types::global_dof_index> local_dof_indices2 (fe2.dofs_per_cell);
cell1->get_dof_indices (local_dof_indices1);
cell2->get_dof_indices (local_dof_indices2);

for (unsigned int i=0; i<fe1.dofs_per_cell; ++i)
   for (unsigned int j=0; j<fe2.dofs_per_cell; ++j)
   {
    if (local_dof_indices1[i] < dof_u && local_dof_indices2[j] < dof_u2)
        {

 
non_diag_sparsity_pattern12.block(0,0).add(local_dof_indices1[i],local_dof_indices2[j]);
     }
    else if(local_dof_indices1[i] < dof_u && local_dof_indices2[j] >=
dof_u2)
    {

non_diag_sparsity_pattern12.block(0,1).add(local_dof_indices1[i],local_dof_indices2[j]
- dof_u2);
     }
    else if(local_dof_indices1[i] >= dof_u && local_dof_indices2[j] <
dof_u2)
    {
        non_diag_sparsity_pattern12.block(1,0).add(local_dof_indices1[i] -
dof_u,local_dof_indices2[j]);
     }
    else
        {
        non_diag_sparsity_pattern12.block(1,1).add(local_dof_indices1[i] -
dof_u,local_dof_indices2[j] - dof_u2);
        }
   }

non_diag_sparsity_pattern12.compress();
sparsity_pattern.compress();

sparsity_pattern.block(0,2).copy_from(non_diag_sparsity_pattern12.block(0,0));
sparsity_pattern.block(0,3).copy_from(non_diag_sparsity_pattern12.block(0,1));
sparsity_pattern.block(1,2).copy_from(non_diag_sparsity_pattern12.block(1,0));
sparsity_pattern.block(1,3).copy_from(non_diag_sparsity_pattern12.block(1,1));
                          //Other blocks of the global sparsity pattern
were copied same way.

system_matrix.clear();
system_matrix12.clear();
system_matrix.reinit(sparsity_pattern);
system_matrix12.reinit(non_diag_sparsity_pattern12);


To check the problem:

    std::cout << system_matrix11.m() << std::endl;
    std::cout << system_matrix12.m() << std::endl;
    std::cout << system_matrix.m() << std::endl;
    std::cout <<
non_diag_sparsity_pattern12.block(0,0).max_entries_per_row() << std::endl;
    std::cout << sparsity_pattern.block(3,0).n_rows()<< std::endl;

Results:
   659     initialized with a pattern created by make_sparsity_pattern
code, so no problem at all
   0         initialized with manually added sparsity pattern
   0         same goes here
   31       manually added non-diag sparsity pattern looks non-empty
   81       manually added global sparsity pattern also looks non-empty

As their sparsity patterns look to be created correctly, system matrices
initialized with these sparsity patterns looks empty.

Thanks,

Mustafa.


On Sat, Dec 15, 2018 at 2:04 AM David Wells <[email protected]> wrote:

> Hi Mustafa,
>
> This does sound strange: BlockSparseMatrix::m() should return the number
> of rows of blocks (which is clearly 4 in your code).
>
> Would it be possible for you to post a more complete code fragment that
> shows the problem? I cannot figure out where the problem is with what you
> posted.
>
> Thanks,
> David Wells
>
> On Friday, December 14, 2018 at 8:41:10 AM UTC-5, Mustafa Aggul wrote:
>>
>> Hello,
>> I have created my own block sparsity pattern by adding non-zero entries
>> manually, and then compressed it. Upon some testings on this sparsity
>> pattern, I have realized that it is indeed created correctly, in terms of
>> dimension and number of elements it has. However, the system matrix that I
>> initialized with this sparsity pattern looks empty (system_matrix.m() = 0).
>> What would be the possible reason for this?
>> Thanks for any response in advance,
>>
>> sparsity_pattern.reinit(4,4);
>>
>> if(something happens)
>> sparsity_pattern.block(0,0).add(local_dof_indices1[i],local_dof_indices2[j]);
>> //these kind of operations
>> sparsity_pattern.compress();
>> system_matrix.reinit(sparsity_pattern);
>>
>> --
>> *Mustafa Ağgül*
>> *Department of Mathematics*
>> *Michigan Technological University*
>> *1400 Townsend Drive*
>> *Houghton, Michigan 49931-1295*
>> *Tel: 906-487-3135*
>>
> --
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
>


-- 
*Mustafa Ağgül*
*Department of Mathematics*
*Michigan Technological University*
*1400 Townsend Drive*
*Houghton, Michigan 49931-1295*
*Tel: 906-487-3135*

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to