-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16079 from bangerth/view
Add a function to take a view of an index set with regard to an index set mask.
- Loading branch information
Showing
9 changed files
with
408 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
New: The function IndexSet::get_view() now has an overload that | ||
computes the view with regard to an arbitrary mask. | ||
<br> | ||
(Wolfgang Bangerth, 2023/10/02) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// --------------------------------------------------------------------- | ||
// | ||
// Copyright (C) 2010 - 2018 by the deal.II authors | ||
// | ||
// This file is part of the deal.II library. | ||
// | ||
// The deal.II library is free software; you can use it, redistribute | ||
// it, and/or modify it under the terms of the GNU Lesser General | ||
// Public License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// The full text of the license can be found in the file LICENSE.md at | ||
// the top level directory of deal.II. | ||
// | ||
// --------------------------------------------------------------------- | ||
|
||
|
||
// test IndexSet::get_view(IndexSet) with a mask that is identical to | ||
// the one used in the _18 test just that it is given as an IndexSet | ||
// rather than a single range. | ||
|
||
#include <deal.II/base/index_set.h> | ||
|
||
#include <stdlib.h> | ||
|
||
#include "../tests.h" | ||
|
||
|
||
void | ||
test() | ||
{ | ||
IndexSet is1(100); | ||
|
||
// randomly add 90 elements to each | ||
// set, some of which may be | ||
// repetitions of previous ones | ||
for (unsigned int i = 0; i < 9 * is1.size() / 10; ++i) | ||
is1.add_index(Testing::rand() % is1.size()); | ||
|
||
is1.compress(); | ||
|
||
IndexSet mask(100); | ||
mask.add_range(20, 50); | ||
|
||
const IndexSet is2 = is1.get_view(mask); | ||
Assert(is2.size() == mask.n_elements(), ExcInternalError()); | ||
|
||
deallog << "Original index set: " << std::endl; | ||
is1.print(deallog); | ||
deallog << "View of index set between 20 and 50: " << std::endl; | ||
is2.print(deallog); | ||
|
||
deallog << "OK" << std::endl; | ||
} | ||
|
||
|
||
|
||
int | ||
main() | ||
{ | ||
initlog(); | ||
|
||
test(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
DEAL::Original index set: | ||
DEAL::{[2,3], 5, 8, 11, [13,15], 19, [21,27], [29,30], [34,37], 40, [42,43], [45,46], [49,51], 54, [56,59], [62,64], [67,70], [72,73], [76,78], [80,84], [86,88], [90,93], [95,96], [98,99]} | ||
DEAL::View of index set between 20 and 50: | ||
DEAL::{[1,7], [9,10], [14,17], 20, [22,23], [25,26], 29} | ||
DEAL::OK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// --------------------------------------------------------------------- | ||
// | ||
// Copyright (C) 2010 - 2018 by the deal.II authors | ||
// | ||
// This file is part of the deal.II library. | ||
// | ||
// The deal.II library is free software; you can use it, redistribute | ||
// it, and/or modify it under the terms of the GNU Lesser General | ||
// Public License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// The full text of the license can be found in the file LICENSE.md at | ||
// the top level directory of deal.II. | ||
// | ||
// --------------------------------------------------------------------- | ||
|
||
|
||
// test IndexSet::get_view(IndexSet) with a mask that is not just a | ||
// single range. | ||
|
||
#include <deal.II/base/index_set.h> | ||
|
||
#include <stdlib.h> | ||
|
||
#include "../tests.h" | ||
|
||
|
||
void | ||
test() | ||
{ | ||
IndexSet is1(100); | ||
|
||
// randomly add 90 elements to each | ||
// set, some of which may be | ||
// repetitions of previous ones | ||
for (unsigned int i = 0; i < 9 * is1.size() / 10; ++i) | ||
is1.add_index(Testing::rand() % is1.size()); | ||
|
||
IndexSet mask(100); | ||
mask.add_range(20, 40); | ||
mask.add_range(60, 80); | ||
mask.compress(); | ||
|
||
const IndexSet is2 = is1.get_view(mask); | ||
Assert(is2.size() == mask.n_elements(), ExcInternalError()); | ||
|
||
deallog << "Original index set: " << std::endl; | ||
is1.print(deallog); | ||
deallog << "Mask: " << std::endl; | ||
mask.print(deallog); | ||
deallog << "View of index set between 20-40 and 60-80: " << std::endl; | ||
is2.print(deallog); | ||
|
||
deallog << "OK" << std::endl; | ||
} | ||
|
||
|
||
|
||
int | ||
main() | ||
{ | ||
initlog(); | ||
|
||
test(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
DEAL::Original index set: | ||
DEAL::{[2,3], 5, 8, 11, [13,15], 19, [21,27], [29,30], [34,37], 40, [42,43], [45,46], [49,51], 54, [56,59], [62,64], [67,70], [72,73], [76,78], [80,84], [86,88], [90,93], [95,96], [98,99]} | ||
DEAL::Mask: | ||
DEAL::{[20,39], [60,79]} | ||
DEAL::View of index set between 20-40 and 60-80: | ||
DEAL::{[1,7], [9,10], [14,17], [22,24], [27,30], [32,33], [36,38]} | ||
DEAL::OK |
Oops, something went wrong.