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