Sparsity pattern discrepancy when applying constraints using Affine constraints

62 views
Skip to first unread message

Vinayak Vijay

unread,
Jun 12, 2023, 4:35:50 AM6/12/23
to deal.II User Group
Hello,

I am trying to constrain one beam to another by using the Affine constraint class. However, I have observed a discrepancy in the sparsity pattern thus generated (with connectivity constraint - all dofs on boundary id 1 are connected with all dofs of boundary id 2) which I am not able to understand. Here's the code snippet that i use for connecting the beams:

std::vector<bool> component_select(dof_handler.get_fe().n_components(),true);
std::set<types::boundary_id> id_boundary1 = {1};
std::set<types::boundary_id> id_boundary2 = {2};

const IndexSet connected_dofs1 = DoFTools::extract_boundary_dofs(dof_handler,component_select,id_boundary1);
const IndexSet connected_dofs2 = DoFTools::extract_boundary_dofs(dof_handler,component_select,id_boundary2);

std::cout << "Dof of beam 1: ";
connected_dofs1.print(std::cout);
std::cout << "should be constrained with dofs of beam 2: ";
connected_dofs2.print(std::cout);

constraints.add_lines(connected_dofs1);
std::cout << "Constrained dof1: " << connected_dofs1.nth_index_in_set(0) << "constrained dof2: "
<<connected_dofs2.nth_index_in_set(0) << std::endl;
constraints.add_entry(connected_dofs1.nth_index_in_set(0),connected_dofs2.nth_index_in_set(0),-1);
constraints.add_entry(connected_dofs1.nth_index_in_set(1),connected_dofs2.nth_index_in_set(1),-1);
constraints.add_entry(connected_dofs1.nth_index_in_set(2),connected_dofs2.nth_index_in_set(2),-1);
constraints.add_entry(connected_dofs1.nth_index_in_set(3),connected_dofs2.nth_index_in_set(3),-1);
constraints.add_entry(connected_dofs1.nth_index_in_set(4),connected_dofs2.nth_index_in_set(4),-1);
constraints.add_entry(connected_dofs1.nth_index_in_set(5),connected_dofs2.nth_index_in_set(5),-1);

constraints.close();

DynamicSparsityPattern dsp(all_dofs, all_dofs);
DoFTools::make_sparsity_pattern(dof_handler, dsp,constraints);
sparsity_pattern.copy_from(dsp);
system_matrix_network.reinit(sparsity_pattern);

std::ostringstream oss;
oss <<"sparsity_pattern.svg";
std::string filename = oss.str();
std::ofstream output(filename.c_str());
sparsity_pattern.print_svg(output);

The output I get is as follows:

Constrained dof of beam 1: {[12,17]}
Constrained dof of beam 2: {[18,23]}
Constrained dof1: 12 constrained dof2: 18


I have attached the png files of the sparsity pattern generated with and without the above constraints. Image1.png is the sparsity pattern without the above constraint and Image2.png is the sparsity pattern with the above constraint. 

As per the output, I expect that columns 18-23 in rows 12-17 should be non-zero and vice versa. That is, the non-zero entries due to the above constraints should have been as highlighted in green in Image2.png. However, clearly, in Image2.png I see that this isn't the case. Columns 18-23 are non-zero in rows 6-11 (instead of rows 12-17) and vice versa (highlighted in blue).

I am not able to figure out this discrepancy. Can someone help?

Thanks 
Vinayak

Image1.png
Image2.png

Wolfgang Bangerth

unread,
Jun 22, 2023, 11:44:32 PM6/22/23
to dea...@googlegroups.com
On 6/12/23 02:35, Vinayak Vijay wrote:
>
> As per the output, I expect that columns 18-23 in rows 12-17 should be
> non-zero and vice versa. That is, the non-zero entries due to the above
> constraints should have been as highlighted in green in Image2.png. However,
> clearly, in Image2.png I see that this isn't the case. Columns 18-23 are
> non-zero in rows 6-11 (instead of rows 12-17) and vice versa (highlighted in
> blue).
>
> I am not able to figure out this discrepancy. Can someone help?

Not being able to see the program that you used, it's hard to tell. But can
you try and just output the constraints you get? AffineConstraints has a
print() function (perhaps named differently) that should help here.

Best
W.

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


Vinayak Vijay

unread,
Jun 24, 2023, 2:13:19 AM6/24/23
to deal.II User Group
Hello Prof. Bangerth,

Thank you for your response.  
The constraint matrix that I get from the above code is:
 
0 = 0
1 = 0
2 = 0
3 = 0
4 = 0
5 = 0
12 18: 1
13 19: 1
14 20: 1
15 21: 1
16 22: 1
17 23: 1
 
This includes the dirichlet bc on dofs 0-5. As you can see that the constraint matrix is according the to constraints i want to apply (refer the printed output of the code snippet in the previous message). But the sparsity pattern doesn't seem to be as per this. 

Thanks
Vinayak

Wolfgang Bangerth

unread,
Jun 29, 2023, 1:41:15 PM6/29/23
to dea...@googlegroups.com, Vinayak Vijay

Vijay:

> The constraint matrix that I get from the above code is:
> 0 = 0
> 1 = 0
> 2 = 0
> 3 = 0
> 4 = 0
> 5 = 0

OK, so these all set DoFs 0...6 to zero.

> 12 18: 1
> 13 19: 1
> 14 20: 1
> 15 21: 1
> 16 22: 1
> 17 23: 1

And these say x_12=x_18, x_13=x_19, etc.

Are these all of the constraints you have? The pictures you show add whole
blocks of entries to the sparsity pattern, but the constraints you show above
do not support this. Something does not match.
Reply all
Reply to author
Forward
0 new messages