I'm a bit confused then. The following tests three get_view() with 
IndexSets : your example (slightly modified), the example from the doc of 
get_view(), and then a slight modification of it. Your example returns 
0-based indices, but the one from the doc returns 11 as first index, which 
is 1-based. The last example throws an error. Is it a bug or am I missing 
something obvious?
My output is :

A :{[1,2], 5}
B :{[0,1], [4,9]}
View :{1, 3}
A :{[20,39]}
B :{1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 
39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 
77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99}
View B:{[11,20]}
C :{22, 26}

--------------------------------------------------------
An error occurred in line <1816> of file 
</home/bawina/Code/dealii/include/deal.II/base/index_set.h> in function
    void dealii::IndexSet::add_range(size_type, size_type)
The violated condition was: 
    (begin < index_space_size) || ((begin == index_space_size) && (end == 
index_space_size))
Additional information: 
    Index 22 is not in the half-open range [0,2).

Stacktrace:
-----------
#0  ./indexset: dealii::IndexSet::add_range(unsigned int, unsigned int)
#1  /usr/local/lib/libdeal_II.g.so.9.7.0-pre: 
dealii::IndexSet::get_view(dealii::IndexSet const&) const
#2  ./indexset: main
--------------------------------------------------------

(Edit: I accidentally replied to W. Bangerth only, not to the list.)

Thanks, 
Arthur 

    { 
        IndexSet A(10); 
        A.add_index(1); 
        A.add_index(2); 
        A.add_index(5); 
        std::cout << "A :"; 
        A.print(std::cout); 

        IndexSet B(10); 
        B.add_index(0); 
        B.add_index(1); 
        B.add_index(4); 
        B.add_index(5); 
        B.add_index(6); 
        B.add_index(7); 
        B.add_index(8); 
        B.add_index(9); 
        std::cout << "B :"; 
        B.print(std::cout); 

        IndexSet view = A.get_view(B); 
        std::cout << "View :"; 
        view.print(std::cout); 
      } 

      { 
        const unsigned int N = 100; 

        IndexSet A(N); 
        A.add_range(20, 40); 
        std::cout << "A :"; 
        A.print(std::cout); 

        // Odd numbers in [0,N) 
        IndexSet B(N); 
        for (unsigned int i = 1; i < N; i += 2) 
          B.add_index(i); 
        std::cout << "B :"; 
        B.print(std::cout); 

        { 
          IndexSet view = A.get_view(B); 
          std::cout << "View B:"; 
          view.print(std::cout); 
        } 

        IndexSet C(N); 
        C.add_index(22); 
        C.add_index(26); 
        std::cout << "C :"; 
        C.print(std::cout); 

        { 
          IndexSet view = A.get_view(C); 
          std::cout << "View C :"; 
          view.print(std::cout); 
        } 
      } 

Le mercredi 19 novembre 2025 à 17:06:58 UTC-5, Wolfgang Bangerth a écrit :

>
> On 11/19/25 14:05, Arthur Bawin wrote:
> > 
> > Then I try to re-create the constraints using get_view() and merge() as 
> > indicated in affine_constraints.h :
>
> You don't show the whole code, so it's difficult to say. But get_view() 
> doesn't just remove constraints outside the "viewed" subset, but it 
> re-enumerates. For example, if you have 10 DoFs and your 
> AffineConstraint stores constraints for indices 1, 2, 5. Then let's say 
> you call get_view() with an index (sub)set 4...8 inclusive, then the 
> result is not an AffineConstraint of size 10 that stores a constraint 
> for index 5. Rather, it is an AffineConstraint of size 5 that stores a 
> constraint for index 1 (the second index within the range 4...8).
>
> Does that make sense as perhaps the cause for your issue?
>
> Best
> W.
>

-- 
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].
To view this discussion visit 
https://groups.google.com/d/msgid/dealii/939b699a-a380-48fe-a553-5132dbc6fa18n%40googlegroups.com.

Reply via email to