PolyFEM
Loading...
Searching...
No Matches
Helmholtz.cpp
Go to the documentation of this file.
1#include "Helmholtz.hpp"
3
4namespace polyfem::assembler
5{
7 : k_("k")
8 {
9 }
10
11 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 9, 1>
13 {
14 const Eigen::MatrixXd &gradi = data.vals.basis_values[data.i].grad_t_m;
15 const Eigen::MatrixXd &gradj = data.vals.basis_values[data.j].grad_t_m;
16
17 double res = 0;
18 for (int k = 0; k < gradi.rows(); ++k)
19 {
20 res += gradi.row(k).dot(gradj.row(k)) * data.da(k);
21 }
22
23 for (int k = 0; k < gradi.rows(); ++k)
24 {
25 const double tmp = k_(data.vals.val.row(k), data.t, data.vals.element_id);
26 res -= data.vals.basis_values[data.i].val(k) * data.vals.basis_values[data.j].val(k) * data.da[k] * tmp * tmp;
27 }
28
29 return Eigen::Matrix<double, 1, 1>::Constant(res);
30 }
31
33 {
34 Eigen::Matrix<double, 1, 1> result;
35 assert(pt.size() == 1);
36 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 3, 1> val(size());
37 for (int d = 0; d < size(); ++d)
38 val(d) = 0;
39
40 const double tmp = k_(val, 0, 0);
41 result(0) = pt(0).getHessian().trace() + tmp * tmp * pt(0).getValue();
42 return result;
43 }
44
45 void Helmholtz::add_multimaterial(const int index, const json &params, const Units &units)
46 {
47 k_.add_multimaterial(index, params, "");
48 }
49
50 Eigen::Matrix<AutodiffScalarGrad, Eigen::Dynamic, 1, 0, 3, 1> Helmholtz::kernel(const int dim, const AutodiffGradPt &rvect, const AutodiffScalarGrad &r) const
51 {
52 Eigen::Matrix<AutodiffScalarGrad, Eigen::Dynamic, 1, 0, 3, 1> res(1);
53
54 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 3, 1> val(size());
55 val.setZero();
56 const double tmp = k_(val, 0, 0);
57
58 if (dim == 2)
59 res(0) = -0.25 * utils::bessy0(tmp * r);
60 else if (dim == 3)
61 res(0) = 0.25 * cos(tmp * r) / (M_PI * r);
62 else
63 assert(false);
64
65 return res;
66 }
67
68 std::map<std::string, Assembler::ParamFunc> Helmholtz::parameters() const
69 {
70 std::map<std::string, ParamFunc> res;
71 res["k"] = [this](const RowVectorNd &, const RowVectorNd &p, double t, int e) {
72 return this->k_(p, t, e);
73 };
74
75 return res;
76 }
77} // namespace polyfem::assembler
double val
Definition Assembler.cpp:86
void add_multimaterial(const int index, const json &params, const std::string &unit_type)
Definition MatParams.cpp:28
void add_multimaterial(const int index, const json &params, const Units &units) override
Definition Helmholtz.cpp:45
VectorNd compute_rhs(const AutodiffHessianPt &pt) const override
Definition Helmholtz.cpp:32
GenericMatParam k() const
Definition Helmholtz.hpp:27
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, 9, 1 > assemble(const LinearAssemblerData &data) const override
local assembly function that defines the bilinear form (LHS) computes and returns a single local stif...
Definition Helmholtz.cpp:12
Eigen::Matrix< AutodiffScalarGrad, Eigen::Dynamic, 1, 0, 3, 1 > kernel(const int dim, const AutodiffGradPt &rvect, const AutodiffScalarGrad &r) const override
Definition Helmholtz.cpp:50
std::map< std::string, ParamFunc > parameters() const override
Definition Helmholtz.cpp:68
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< double, Eigen::Dynamic, 1, 0, 3, 1 > VectorNd
Definition Types.hpp:11
nlohmann::json json
Definition Common.hpp:9
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13
Eigen::Matrix< AutodiffScalarGrad, Eigen::Dynamic, 1, 0, 3, 1 > AutodiffGradPt
Automatic differentiation scalar with first-order derivatives.
Definition autodiff.h:112