hp-FEM
Adaptive hp-FEM suite for nano-optics
Loading...
Searching...
No Matches
sparse_assembler.hpp
Go to the documentation of this file.
1#pragma once
5
6#include <cstddef>
7#include <span>
8#include <vector>
9
10#include <Eigen/SparseCore>
11
12#include "hpfem/core/types.hpp"
13
14namespace hpfem::assembly {
15
20 public:
22
23 [[nodiscard]] Index rows() const noexcept { return rows_; }
24 [[nodiscard]] Index cols() const noexcept { return cols_; }
25 [[nodiscard]] std::size_t num_triplets() const noexcept { return triplets_.size(); }
26 void reserve(std::size_t triplets) { triplets_.reserve(triplets); }
27
29 void add(std::span<const Index> rows, std::span<const Index> cols, const Matrix& local);
31 void add(Index row, Index col, Complex value);
33 void append(const SparseAssembler& other);
34
36 [[nodiscard]] SparseMatrix finalize() const;
37
38 private:
39 Index rows_;
40 Index cols_;
41 std::vector<Eigen::Triplet<Complex, Index>> triplets_;
42};
43
45void scatter(Vector& global, std::span<const Index> dofs, const Vector& local);
46
48[[nodiscard]] Vector gather(const Vector& global, std::span<const Index> dofs);
49
50} // namespace hpfem::assembly
Definition sparse_assembler.hpp:19
void reserve(std::size_t triplets)
Definition sparse_assembler.hpp:26
Index cols() const noexcept
Definition sparse_assembler.hpp:24
SparseAssembler(Index rows, Index cols)
Index rows() const noexcept
Definition sparse_assembler.hpp:23
void append(const SparseAssembler &other)
Appends the triplets of another assembler of the same size (per-thread buffers).
void add(Index row, Index col, Complex value)
Adds one entry.
void add(std::span< const Index > rows, std::span< const Index > cols, const Matrix &local)
Adds local(i, j) to the global entry (rows[i], cols[j]); sizes must match.
SparseMatrix finalize() const
Compressed matrix with all contributions summed.
std::size_t num_triplets() const noexcept
Definition sparse_assembler.hpp:25
Definition axisymmetric_forms.hpp:30
Vector gather(const Vector &global, std::span< const Index > dofs)
Gathers global at the positions dofs into a dense vector.
void scatter(Vector &global, std::span< const Index > dofs, const Vector &local)
Adds the element vector local to global at the positions dofs.
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic > Matrix
Definition types.hpp:22
Eigen::SparseMatrix< Complex, Eigen::RowMajor, Index > SparseMatrix
Definition types.hpp:24
std::int64_t Index
global indices (DoFs, entities)
Definition types.hpp:17
Eigen::Matrix< Complex, Eigen::Dynamic, 1 > Vector
Definition types.hpp:20
std::complex< double > Complex
Definition types.hpp:16