Reference documentation for deal.II version 9.5.0
\(\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\}}\)
Loading...
Searching...
No Matches
sparsity_pattern_base.cc
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2022 - 2023 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
18#include <boost/container/small_vector.hpp>
19
20#include <algorithm>
21#include <utility>
22
24
25void
27 const ArrayView<const std::pair<size_type, size_type>> &inputs)
28{
29 // We always want to sort so that we can use the optimized add_row_entries()
30 // function
31 boost::container::small_vector<std::pair<size_type, size_type>, 128> entries(
32 inputs.begin(), inputs.end());
33 std::sort(entries.begin(), entries.end());
34 boost::container::small_vector<size_type, 128> columns;
35
36 auto entry = entries.begin();
37 while (entry != entries.end())
38 {
39 const auto row = entry->first;
40 auto row_end = entry;
41 while (row_end != entries.end() && row_end->first == row)
42 ++row_end;
43
44 columns.resize(0);
45 columns.reserve(row_end - entry);
46 // Simultaneously transform and uniquify
47 columns.push_back(entry->second);
48 ++entry;
49 while (entry != row_end)
50 {
51 if (columns.back() != entry->second)
52 columns.push_back(entry->second);
53 ++entry;
54 }
55
57 make_array_view(columns.begin(), columns.end()),
58 true);
59 }
60}
61
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:704
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:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473