chombo-discharge
Loading...
Searching...
No Matches
CD_PetscStencil.H
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2021-2026 SINTEF Energy Research
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
12
13#ifdef CH_USE_PETSC
14
15#ifndef CD_PETSCSTENCIL_H
16#define CD_PETSCSTENCIL_H
17
18// Std includes
19#include <utility>
20#include <vector>
21
22// Petsc includes
23#include "petsc.h"
24
25// Our includes
26#include <CD_NamespaceHeader.H>
27
43{
44public:
48 PetscStencil() = default;
49
53 ~PetscStencil() = default;
54
58 void
59 clear();
60
65 int
66 size() const noexcept;
67
73 PetscInt
74 row(const int a_entry) const noexcept;
75
81 PetscScalar
82 weight(const int a_entry) const noexcept;
83
90 void
91 add(const PetscInt& a_row, const PetscScalar& a_weight) noexcept;
92
100 operator+=(const PetscStencil& a_otherStencil) noexcept;
101
107 void
108 compress() noexcept;
109
116 operator*=(const PetscScalar& a_scalingFactor) noexcept;
117
118protected:
122 std::vector<std::pair<PetscInt, PetscScalar>> m_entries;
123};
124
125#include <CD_NamespaceFooter.H>
126
127#endif
128
129#endif
PetscScalar weight(const int a_entry) const noexcept
Get the weight of a stencil entry.
Definition CD_PetscStencil.cpp:46
void add(const PetscInt &a_row, const PetscScalar &a_weight) noexcept
Append an entry to this stencil.
Definition CD_PetscStencil.cpp:54
void compress() noexcept
Sort the entries by row and merge entries with the same row by summing their weights.
Definition CD_PetscStencil.cpp:68
~PetscStencil()=default
Destructor.
void clear()
Remove all entries from the stencil.
Definition CD_PetscStencil.cpp:26
PetscStencil()=default
Default constructor. Creates an empty stencil.
std::vector< std::pair< PetscInt, PetscScalar > > m_entries
Stencil entries as (global PETSc row, weight). Rows are unique and ascending only after compress().
Definition CD_PetscStencil.H:122
PetscInt row(const int a_entry) const noexcept
Get the PETSc row of a stencil entry.
Definition CD_PetscStencil.cpp:38
int size() const noexcept
Get the number of entries in the stencil.
Definition CD_PetscStencil.cpp:32