PolyFEM
Loading...
Searching...
No Matches
Laplacian.cpp
Go to the documentation of this file.
1#include "Laplacian.hpp"
2
3namespace polyfem::assembler
4{
5 namespace
6 {
7 bool delta(int i, int j)
8 {
9 return (i == j) ? true : false;
10 }
11 } // namespace
12
13 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 9, 1> Laplacian::assemble(const LinearAssemblerData &data) const
14 {
15 const Eigen::MatrixXd &gradi = data.vals.basis_values[data.i].grad_t_m;
16 const Eigen::MatrixXd &gradj = data.vals.basis_values[data.j].grad_t_m;
17 // return ((gradi.array() * gradj.array()).rowwise().sum().array() * da.array()).colwise().sum();
18 double res = 0;
19 assert(gradi.rows() == data.da.size());
20 for (int k = 0; k < gradi.rows(); ++k)
21 {
22 // compute grad(phi_i) dot grad(phi_j) weighted by quadrature weights
23 res += gradi.row(k).dot(gradj.row(k)) * data.da(k);
24 }
25 return Eigen::Matrix<double, 1, 1>::Constant(res);
26 }
27
28 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 3, 1> Laplacian::compute_rhs(const AutodiffHessianPt &pt) const
29 {
30 Eigen::Matrix<double, 1, 1> result;
31 assert(pt.size() == 1);
32 result(0) = pt(0).getHessian().trace();
33 return result;
34 }
35
36 Eigen::Matrix<AutodiffScalarGrad, Eigen::Dynamic, 1, 0, 3, 1> Laplacian::kernel(const int dim, const AutodiffGradPt &rvect, const AutodiffScalarGrad &r) const
37 {
38 Eigen::Matrix<AutodiffScalarGrad, Eigen::Dynamic, 1, 0, 3, 1> res(1);
39
40 if (dim == 2)
41 res(0) = -1. / (2 * M_PI) * log(r);
42 else if (dim == 3)
43 res(0) = 1. / (4 * M_PI * r);
44 else
45 assert(false);
46
47 return res;
48 }
49
51 const Eigen::MatrixXd &mat,
52 Eigen::MatrixXd &stress,
53 Eigen::MatrixXd &result) const
54 {
55 stress = data.grad_u_i;
56 result = mat;
57 }
58
61 const Eigen::MatrixXd &local_pts,
62 const Eigen::MatrixXd &displacement,
63 Eigen::MatrixXd &tensor) const
64 {
65 const int dim = local_pts.cols();
66 tensor.resize(local_pts.rows(), dim * dim);
67 assert(displacement.cols() == 1);
68
69 for (long p = 0; p < local_pts.rows(); ++p)
70 {
71 for (int i = 0, idx = 0; i < dim; i++)
72 for (int j = 0; j < dim; j++)
73 {
74 tensor(p, idx) = delta(i, j);
75 idx++;
76 }
77 }
78 }
79} // namespace polyfem::assembler
ElementAssemblyValues vals
Definition Assembler.cpp:22
stores per element basis values at given quadrature points and geometric mapping
Eigen::Matrix< AutodiffScalarGrad, Eigen::Dynamic, 1, 0, 3, 1 > kernel(const int dim, const AutodiffGradPt &rvect, const AutodiffScalarGrad &r) const override
kernel of the pde, used in kernel problem
Definition Laplacian.cpp:36
void compute_stress_grad_multiply_mat(const OptAssemblerData &data, const Eigen::MatrixXd &mat, Eigen::MatrixXd &stress, Eigen::MatrixXd &result) const override
Definition Laplacian.cpp:50
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, 9, 1 > assemble(const LinearAssemblerData &data) const override
computes local stiffness matrix (1x1) for bases i,j where i,j is passed in through data ie integral o...
Definition Laplacian.cpp:13
void compute_stiffness_value(const double t, const assembler::ElementAssemblyValues &vals, const Eigen::MatrixXd &local_pts, const Eigen::MatrixXd &displacement, Eigen::MatrixXd &tensor) const override
Definition Laplacian.cpp:59
VectorNd compute_rhs(const AutodiffHessianPt &pt) const override
uses autodiff to compute the rhs for a fabricated solution in this case it just return pt....
Definition Laplacian.cpp:28
const ElementAssemblyValues & vals
stores the evaluation for that element
const QuadratureVector & da
contains both the quadrature weight and the change of metric in the integral
Used for test only.
Eigen::Matrix< AutodiffScalarHessian, Eigen::Dynamic, 1, 0, 3, 1 > AutodiffHessianPt
Eigen::Matrix< AutodiffScalarGrad, Eigen::Dynamic, 1, 0, 3, 1 > AutodiffGradPt
Automatic differentiation scalar with first-order derivatives.
Definition autodiff.h:112