PolyFEM
Loading...
Searching...
No Matches
Stokes.cpp
Go to the documentation of this file.
1#include "Stokes.hpp"
2
3namespace polyfem::assembler
4{
6 : viscosity_("viscosity")
7 {
8 }
9 void StokesVelocity::add_multimaterial(const int index, const json &params, const Units &units)
10 {
11 assert(size() == 2 || size() == 3);
12
13 viscosity_.add_multimaterial(index, params, units.viscosity());
14 }
15
16 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 9, 1>
18 {
19 // (gradi : gradj) = <gradi, gradj> * Id
20
21 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 9, 1> res(size() * size());
22 res.setZero();
23
24 const Eigen::MatrixXd &gradi = data.vals.basis_values[data.i].grad_t_m;
25 const Eigen::MatrixXd &gradj = data.vals.basis_values[data.j].grad_t_m;
26 double dot = 0;
27 for (int k = 0; k < gradi.rows(); ++k)
28 {
29 dot += gradi.row(k).dot(gradj.row(k)) * data.da(k) * viscosity_(data.vals.val.row(k), data.t, data.vals.element_id);
30 }
31
32 for (int d = 0; d < size(); ++d)
33 res(d * size() + d) = dot;
34
35 return res;
36 }
37
39 {
40 assert(pt.size() == size());
41 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 3, 1> res(size());
42
43 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 3, 1> val(size());
44 for (int d = 0; d < size(); ++d)
45 val(d) = pt(d).getValue();
46
47 const auto nu = viscosity_(val, 0, 0);
48 for (int d = 0; d < size(); ++d)
49 {
50 res(d) = nu * pt(d).getHessian().trace();
51 }
52
53 return res;
54 }
55
56 std::map<std::string, Assembler::ParamFunc> StokesVelocity::parameters() const
57 {
58 std::map<std::string, ParamFunc> res;
59 const auto &nu = viscosity_;
60 res["viscosity"] = [&nu](const RowVectorNd &, const RowVectorNd &p, double t, int e) {
61 return nu(p, t, e);
62 };
63
64 return res;
65 }
66
67 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 3, 1>
69 {
70 // -(psii : div phij) = psii * gradphij
71
72 Eigen::Matrix<double, Eigen::Dynamic, 1, 0, 3, 1> res(rows() * cols());
73 res.setZero();
74
75 const Eigen::MatrixXd &psii = data.psi_vals.basis_values[data.i].val;
76 const Eigen::MatrixXd &gradphij = data.phi_vals.basis_values[data.j].grad_t_m;
77 assert(psii.size() == gradphij.rows());
78 assert(gradphij.cols() == rows());
79
80 for (int k = 0; k < gradphij.rows(); ++k)
81 {
82 res -= psii(k) * gradphij.row(k) * data.da(k);
83 }
84
85 return res;
86 }
87} // namespace polyfem::assembler
double val
Definition Assembler.cpp:86
std::string viscosity() const
Definition Units.hpp:32
void add_multimaterial(const int index, const json &params, const std::string &unit_type)
Definition MatParams.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
const QuadratureVector & da
contains both the quadrature weight and the change of metric in the integral
const ElementAssemblyValues & phi_vals
stores the evaluation for that element
const ElementAssemblyValues & psi_vals
stores the evaluation for that element
int rows() const override
Definition Stokes.hpp:47
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, 3, 1 > assemble(const MixedAssemblerData &data) const override
Definition Stokes.cpp:68
int cols() const override
Definition Stokes.hpp:48
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 Stokes.cpp:17
VectorNd compute_rhs(const AutodiffHessianPt &pt) const override
Definition Stokes.cpp:38
std::map< std::string, ParamFunc > parameters() const override
Definition Stokes.cpp:56
void add_multimaterial(const int index, const json &params, const Units &units) override
Definition Stokes.cpp:9
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