Reference documentation for deal.II version GIT c545eda070 2023-01-27 00:25:02+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
sparsity_pattern_base.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2022 - 2022 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
17 
19 #include <boost/container/small_vector.hpp>
21 
22 #include <algorithm>
23 #include <utility>
24 
26 
27 void
29  const ArrayView<const std::pair<size_type, size_type>> &inputs)
30 {
31  // We always want to sort so that we can use the optimized add_row_entries()
32  // function
33  boost::container::small_vector<std::pair<size_type, size_type>, 128> entries(
34  inputs.begin(), inputs.end());
35  std::sort(entries.begin(), entries.end());
36  boost::container::small_vector<size_type, 128> columns;
37 
38  auto entry = entries.begin();
39  while (entry != entries.end())
40  {
41  const auto row = entry->first;
42  auto row_end = entry;
43  while (row_end != entries.end() && row_end->first == row)
44  ++row_end;
45 
46  columns.resize(0);
47  columns.reserve(row_end - entry);
48  // Simultaneously transform and uniquify
49  columns.push_back(entry->second);
50  ++entry;
51  while (entry != row_end)
52  {
53  if (columns.back() != entry->second)
54  columns.push_back(entry->second);
55  ++entry;
56  }
57 
58  add_row_entries(row,
59  make_array_view(columns.begin(), columns.end()),
60  true);
61  }
62 }
63 
ArrayView< typename std::remove_reference< typename std::iterator_traits< Iterator >::reference >::type, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
Definition: array_view.h:685
virtual void add_entries(const ArrayView< const std::pair< size_type, size_type >> &entries)
virtual void add_row_entries(const size_type &row, const ArrayView< const size_type > &columns, const bool indices_are_sorted=false)=0
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:458
#define DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
Definition: config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:459
#define DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
Definition: config.h:513