Hey Pai Liu,

At some point in my research I had to do something similar to what you want 
to do. In the application of the so-called Dirichlet-to-Neumann maps for 
Helmholtz problems, one has to assemble a dense block corresponding to the 
boundary degrees of freedom, so I had to include extra entries in my FE 
matrices. This is what I did (omitting some non-related details):

PETScWrappers::SparseMatrix                       Q;

std::vector<unsigned int> map_dofs_boundary;
DoFTools::map_dof_to_boundary_indices (    dof_handler,
                                                                            
    map_dofs_boundary    );

std::vector<unsigned int> dofs_boundary_lenghts ( map_dofs_boundary.size() 
);

Q.reinit (par.dofs, par.dofs, dofs_boundary_lenghts);
MatSetOption(Q, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);

FE assembly routine ...

in a loop i, j ...
    Q.set ( boundary_idx[i], boundary_idx[j], my_value (i,j) );

Q.compress (VectorOperation::add);

and that works for me.

I hope this may be of help to you.

Juan Carlos Araújo Cabarcas
Doctor candidate in Computational Science with emphasis in mathematics,
Umeå Universitet


El miércoles, 3 de abril de 2019, 0:47:09 (UTC+2), Pai Liu escribió:
>
> Hi Wolfgang,
>  
>
>> I would start by asking where the nonzero entries are going to lie. What 
>> kind of operator do you plan on implementing for which you don't know 
>> where the nonzeros are? 
>>
>
> I want to multiply this matrix with a PETSc vector (which is also stored 
> in parallel).
> When I initialize the PETSc sparsity matrix, I don't know where the 
> nonzeros are.
> Then I loop over the locally owned cells on each processor, and guadually 
> know for each row of the matrix the locations and values of the nonzeros. 
> Do you mean that I can't directly use the PETSc_sparsity_matrix.add() 
> function to insert nonzero values into the matrix without telling the 
> sparsity pattern the nonzeros locations?
>
> *If I have to tell the sparsity pattern where the nonzeros are manually, 
> what are the necessary procedures and functions I should follow and use 
> (since the matrix is not a system matrix, I can't use the 
> DoFTools::make_sparsity_pattern function with an dofhandler as input)?*
>
> *For example, for row 0, how can I tell the sparsity pattern the elements 
> at (0,3) and (0,5) arenonzeros? I search the documentation, and find maybe 
> I should use dynamic_spasity_pattern? I am so confused.*
>

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