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