Reference documentation for deal.II version 9.6.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// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2022 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
16
17#include <boost/container/small_vector.hpp>
18
19#include <algorithm>
20#include <utility>
21
23
24void
26 const ArrayView<const std::pair<size_type, size_type>> &inputs)
27{
28 // We always want to sort so that we can use the optimized add_row_entries()
29 // function
30 boost::container::small_vector<std::pair<size_type, size_type>, 128> entries(
31 inputs.begin(), inputs.end());
32 std::sort(entries.begin(), entries.end());
33 boost::container::small_vector<size_type, 128> columns;
34
35 auto entry = entries.begin();
36 while (entry != entries.end())
37 {
38 const auto row = entry->first;
39 auto row_end = entry;
40 while (row_end != entries.end() && row_end->first == row)
41 ++row_end;
42
43 columns.resize(0);
44 columns.reserve(row_end - entry);
45 // Simultaneously transform and uniquify
46 columns.push_back(entry->second);
47 ++entry;
48 while (entry != row_end)
49 {
50 if (columns.back() != entry->second)
51 columns.push_back(entry->second);
52 ++entry;
53 }
54
56 make_array_view(columns.begin(), columns.end()),
57 true);
58 }
59}
60
ArrayView< std::remove_reference_t< typename std::iterator_traits< Iterator >::reference >, MemorySpaceType > make_array_view(const Iterator begin, const Iterator end)
Definition array_view.h:949
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:503
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504