IndexSet
get_view(const size_type begin, const size_type end) const;
+ /**
+ * Split the set indices represented by this object into blocks
+ * given by the @p dofs_per_block structure.
+ */
+ std::vector<IndexSet>
+ split_by_block(
+ const std::vector<types::global_dof_index> &dofs_per_block) const;
+
/**
* Remove all elements contained in @p other from this set. In other words,
* if $x$ is the current object and $o$ the argument, then we compute $x
return result;
}
+std::vector<IndexSet>
+IndexSet::split_by_block(
+ const std::vector<types::global_dof_index> &dofs_per_block) const
+{
+ std::vector<IndexSet> partitioned;
+ const unsigned int n_block_dofs = dofs_per_block.size();
+ partitioned.reserve(n_block_dofs);
+ types::global_dof_index start = 0;
+ types::global_dof_index sum = 0;
+ for (const auto n_block_dofs : dofs_per_block)
+ {
+ partitioned.push_back(this->get_view(start, start + n_block_dofs));
+ start += n_block_dofs;
+ sum += partitioned.back().size();
+ }
+ AssertDimension(sum, this->size());
+ return partitioned;
+}
void
IndexSet::subtract_set(const IndexSet &other)
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2020 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::split_by_block ()
+
+#include <deal.II/base/index_set.h>
+
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/dofs/dof_renumbering.h>
+#include <deal.II/dofs/dof_tools.h>
+
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/fe/fe_system.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+
+#include "../tests.h"
+
+template <int dim>
+void
+test()
+{
+ Triangulation<dim> triangulation;
+ GridGenerator::hyper_cube(triangulation);
+ triangulation.refine_global(1);
+
+ FESystem<dim> fe(FE_Q<dim>(2), dim, FE_Q<dim>(1), 1);
+ DoFHandler<dim> dof_handler(triangulation);
+ dof_handler.distribute_dofs(fe);
+
+ std::vector<unsigned int> block_component(dim + 1, 0);
+ block_component[dim] = 1;
+ DoFRenumbering::component_wise(dof_handler, block_component);
+
+ const std::vector<types::global_dof_index> dofs_per_block =
+ DoFTools::count_dofs_per_fe_block(dof_handler, block_component);
+
+ const std::vector<IndexSet> partition =
+ dof_handler.locally_owned_dofs().split_by_block(dofs_per_block);
+ for (unsigned int i = 0; i < 2; ++i)
+ {
+ partition[i].print(deallog);
+ }
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+int
+main()
+{
+ initlog();
+
+ test<2>();
+ test<3>();
+}