41 axpy(coeff, lap, u, b);
50 axpy(coeff, lap, u, b);
59 axpy(coeff, lap, u, b);
76 std::vector<idx> rows, cols;
77 std::vector<real> vals;
81 for (
int i = 0; i < N; ++i) {
82 for (
int j = 0; j < N; ++j) {
89 cols.push_back((i - 1) * N + j);
94 cols.push_back((i + 1) * N + j);
99 cols.push_back(i * N + (j - 1));
104 cols.push_back(i * N + (j + 1));
114 std::vector<idx> rows, cols;
115 std::vector<real> vals;
119 for (
int i = 0; i < N; ++i) {
120 for (
int j = 0; j < N; ++j) {
124 vals.push_back(1.0 + 4.0 * coeff);
127 cols.push_back((i - 1) * N + j);
128 vals.push_back(-coeff);
132 cols.push_back((i + 1) * N + j);
133 vals.push_back(-coeff);
137 cols.push_back(i * N + (j - 1));
138 vals.push_back(-coeff);
142 cols.push_back(i * N + (j + 1));
143 vals.push_back(-coeff);
Conjugate gradient solvers.
constexpr idx size() const noexcept
Sparse matrix in Compressed Sparse Row (CSR) format.
static SparseMatrix from_triplets(idx n_rows, idx n_cols, const std::vector< idx > &rows, const std::vector< idx > &cols, const std::vector< real > &vals)
Build from coordinate (COO / triplet) lists.
void symmetric_operator_tag
idx rows() const noexcept
idx cols() const noexcept
const SparseMatrix & matrix() const noexcept
void apply(const Vector &x, Vector &y) const
BackwardEulerOperator2D(int N, double coeff)
Backend enum and default backend selection.
2D uniform interior grid: geometry only, no field data.
Universal linear solver callable type.
SPDOp< Op > assume_spd(Op op)
SparseMatrix laplacian_sparse_2d(int N)
void diffusion_step_2d_4th_dirichlet(Vector &u, int N, double coeff, Backend b=best_backend)
void diffusion_step_2d_dirichlet(Vector &u, int N, double coeff, Backend b=best_backend)
void diffusion_step_2d(Vector &u, int N, double coeff, Backend b=best_backend)
BackwardEulerOperator2D backward_euler_operator(int N, double coeff)
SparseMatrix backward_euler_matrix(int N, double coeff)
LinearSolver make_cg_solver(const SparseMatrix &A, real tol=1e-6)
void laplacian_stencil_2d(const BasicVector< T > &x, BasicVector< T > &y, int N)
std::function< SolverResult(const Vector &rhs, Vector &x)> LinearSolver
Callable that solves .
constexpr Backend best_backend
void laplacian_stencil_2d_4th(const BasicVector< T > &x, BasicVector< T > &y, int N)
Fourth-order 2D Laplacian cross stencil.
void sparse_matvec(const SparseMatrix &A, const Vector &x, Vector &y)
y = A * x
void laplacian_stencil_2d_periodic(const BasicVector< T > &x, BasicVector< T > &y, int N)
Periodic second-order 2D Laplacian stencil.
void axpy(real alpha, const Vector &x, Vector &y, Backend b=default_backend)
Compute .
SolverResult cg(const Matrix &A, const Vector &b, Vector &x, real tol=1e-10, idx max_iter=1000, Backend backend=default_backend)
Declared mathematical properties for linear operators.
Compressed Sparse Row (CSR) matrix and operations.
SparseMatrix adapter for the operator protocol.
Higher-order stencil and grid-sweep utilities.
int N
interior nodes per side
Adapt a SparseMatrix to the operator protocol.
Dense vector storage and operations.