9#include <unsupported/Eigen/KroneckerProduct>
19template <
class EleType>
40 return static_cast<size_t>((2 / h) - 1);
56 Eigen::SparseMatrix<EleType> D(n, n);
59 size_t n_diagonals = 3;
60 D.reserve(Eigen::VectorXi::Constant(n, n_diagonals));
61 for (
int i = 0; i < n; ++i) {
62 D.insert(i, i) = -2.0;
64 D.insert(i, i - 1) = 1.0;
67 D.insert(i, i + 1) = 1.0;
88 static Eigen::SparseMatrix<EleType>
laplacian(
size_t n) {
91 Eigen::SparseMatrix<EleType> spidentity(n, n);
92 spidentity.setIdentity();
94 Eigen::SparseMatrix<EleType> A = Eigen::kroneckerProduct(spidentity, D) +
95 Eigen::kroneckerProduct(D, spidentity);
108 static Eigen::Matrix<EleType, -1, 1>
rhs(
110 std::function<EleType(EleType, EleType)> f = [](EleType x, EleType y) {
111 return 5 * exp(-10 * (x * x + y * y));
116 EleType left_bound = -1.0;
117 EleType right_bound = 1.0;
118 Eigen::Matrix<EleType, -1, 1> domain_1D =
119 Eigen::DenseBase<Eigen::Matrix<EleType, -1, 1>>::LinSpaced(
120 n_points_in_direction, left_bound, right_bound);
123 size_t ndofs = n * n;
124 Eigen::Matrix<EleType, -1, 1> b(ndofs);
128 EleType xj, xi, feval;
129 for (
size_t j = 1; j <= n; ++j) {
131 for (
size_t i = 1; i <= n; ++i) {
Static functions for constructing A and b, the components of a linear system Au = b.
Definition grid.hpp:20
static Eigen::SparseMatrix< EleType > second_order_central_difference(size_t n)
Return second order central difference as linear operator on 1D function.
Definition grid.hpp:50
static Eigen::Matrix< EleType, -1, 1 > rhs(size_t n, std::function< EleType(EleType, EleType)> f=[](EleType x, EleType y) { return 5 *exp(-10 *(x *x+y *y));})
Return right hand side vector b by evaluating f on a mesh grid in [-1, 1]^2.
Definition grid.hpp:108
static size_t points_n_from_grid_spacing_h(EleType h=1./50)
Compute the number of points in a direction given gridspacing h.
Definition grid.hpp:39
static const size_t n_boundary_points
Definition grid.hpp:22
static EleType grid_spacing_h(size_t n)
Compute the gridspacing h of a domain given n points in a direction.
Definition grid.hpp:31
static Eigen::SparseMatrix< EleType > laplacian(size_t n)
Return coefficients matrix A for laplacian as linear operator on u(x,y) assuming homogenous dirichlet...
Definition grid.hpp:88