PolyFEM
Loading...
Searching...
No Matches
RhsAssembler.hpp
Go to the documentation of this file.
1#pragma once
2
5
9
10namespace polyfem
11{
12 namespace assembler
13 {
14 // computes the rhs of a problem by \int \phi rho rhs
16 {
17 public:
18 // initialization with assembler factory mesh
19 // size of the problem, bases
20 // and solver used internally
22 const Assembler &assembler,
23 const mesh::Mesh &mesh,
24 const mesh::Obstacle *obstacle,
25 const std::vector<int> &dirichlet_nodes,
26 const std::vector<int> &neumann_nodes,
27 const std::vector<RowVectorNd> &dirichlet_nodes_position,
28 const std::vector<RowVectorNd> &neumann_nodes_position,
29 const int n_basis,
30 const int size,
31 const std::vector<basis::ElementBases> &bases,
32 const std::vector<basis::ElementBases> &gbases,
34 const Problem &problem,
35 const std::string bc_method,
36 const json &solver_params,
37 const int fe_space_id = -1);
38
39 // computes the rhs of a problem by \int \phi rho rhs
40 void assemble(const Density &density, Eigen::MatrixXd &rhs, const double t = 1) const;
41
42 // computes the initial soltion for time dependent, calls time_bc
43 void initial_solution(Eigen::MatrixXd &sol) const;
44 // computes the initial velocity for time dependent, calls time_bc
45 void initial_velocity(Eigen::MatrixXd &sol) const;
46 // computes the initial acceleration for time dependent, calls time_bc
47 void initial_acceleration(Eigen::MatrixXd &sol) const;
48
49 // sets boundary conditions to rhs, the boundary conditions are projected (Dirichlet) integrated (Neumann) at resolution
50 // local boundary stores the mapping from elemment to nodes for Dirichlet nodes
51 // local local_neumann_boundary stores the mapping from elemment to nodes for Neumann nodes
52 // calls set_bc
53 void set_bc(
54 const std::vector<mesh::LocalBoundary> &local_boundary,
55 const std::vector<int> &bounday_nodes,
56 const QuadratureOrders &resolution,
57 const std::vector<mesh::LocalBoundary> &local_neumann_boundary,
58 Eigen::MatrixXd &rhs,
59 const Eigen::MatrixXd &displacement = Eigen::MatrixXd(),
60 const double t = 1) const;
61
62 // compute body energy
63 double compute_energy(
64 const Eigen::MatrixXd &displacement,
65 const Eigen::MatrixXd &displacement_prev,
66 const std::vector<mesh::LocalBoundary> &local_neumann_boundary,
67 const Density &density,
68 const QuadratureOrders &resolution,
69 const double t) const;
70 // compute body energy gradient, hessian is zero, rhs is a linear function
72 const std::vector<mesh::LocalBoundary> &local_boundary,
73 const std::vector<int> &bounday_nodes,
74 const Density &density,
75 const QuadratureOrders &resolution,
76 const std::vector<mesh::LocalBoundary> &local_neumann_boundary,
77 const Eigen::MatrixXd &final_rhs,
78 const double t,
79 Eigen::MatrixXd &rhs) const;
80
81 // compute body hessian wrt to previous solution
82 void compute_energy_hess(const std::vector<int> &bounday_nodes,
83 const QuadratureOrders &resolution,
84 const std::vector<mesh::LocalBoundary> &local_neumann_boundary,
85 const Eigen::MatrixXd &displacement,
86 const double t,
87 const bool project_to_psd,
88 StiffnessMatrix &hess) const;
89
90 inline const Problem &problem() const { return problem_; }
91 inline const mesh::Mesh &mesh() const { return mesh_; }
92 inline const std::vector<basis::ElementBases> &bases() const { return bases_; }
93 inline const std::vector<basis::ElementBases> &gbases() const { return gbases_; }
94 inline const AssemblyValsCache &ass_vals_cache() const { return ass_vals_cache_; }
95 inline const Assembler &assembler() const { return assembler_; }
96
97 private:
98 // leastsquares fit bc
99 void lsq_bc(const std::function<void(const Eigen::MatrixXi &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &df,
100 const std::vector<mesh::LocalBoundary> &local_boundary,
101 const std::vector<int> &bounday_nodes,
102 const int resolution,
103 Eigen::MatrixXd &rhs) const;
104
105 // sample bc at nodes
106 void sample_bc(const std::function<void(const Eigen::MatrixXi &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &df,
107 const std::vector<mesh::LocalBoundary> &local_boundary,
108 const std::vector<int> &bounday_nodes,
109 Eigen::MatrixXd &rhs) const;
110
111 // set boundary condition
112 // the 2 lambdas are callback to dirichlet df and neumann nf
113 // diriclet boundary condition are projected on the FEM bases, it inverts a linear system
114 void set_bc(
115 const std::function<void(const Eigen::MatrixXi &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &df,
116 const std::function<void(const Eigen::MatrixXi &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &nf,
117 const std::vector<mesh::LocalBoundary> &local_boundary,
118 const std::vector<int> &bounday_nodes,
119 const QuadratureOrders &resolution,
120 const std::vector<mesh::LocalBoundary> &local_neumann_boundary,
121 const Eigen::MatrixXd &displacement,
122 const double t,
123 Eigen::MatrixXd &rhs) const;
124
125 // sets the time (initial) boundary condition
126 // the lambda depeneds if soltuion, velocity, or acceleration
127 // they are projected on the FEM bases, it inverts a linear system
128 void time_bc(const std::function<void(const mesh::Mesh &, const Eigen::MatrixXi &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &fun, Eigen::MatrixXd &sol) const;
129
133 const int n_basis_;
134 const int size_;
135 const std::vector<basis::ElementBases> &bases_;
136 const std::vector<basis::ElementBases> &gbases_;
139 const std::string bc_method_;
141 const int fe_space_id_;
142 const std::vector<int> &dirichlet_nodes_;
143 const std::vector<RowVectorNd> &dirichlet_nodes_position_;
144 const std::vector<int> &neumann_nodes_;
145 const std::vector<RowVectorNd> &neumann_nodes_position_;
146 };
147 } // namespace assembler
148} // namespace polyfem
Caches basis evaluation and geometric mapping at every element.
void time_bc(const std::function< void(const mesh::Mesh &, const Eigen::MatrixXi &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &fun, Eigen::MatrixXd &sol) const
void compute_energy_hess(const std::vector< int > &bounday_nodes, const QuadratureOrders &resolution, const std::vector< mesh::LocalBoundary > &local_neumann_boundary, const Eigen::MatrixXd &displacement, const double t, const bool project_to_psd, StiffnessMatrix &hess) const
const AssemblyValsCache & ass_vals_cache() const
void set_bc(const std::vector< mesh::LocalBoundary > &local_boundary, const std::vector< int > &bounday_nodes, const QuadratureOrders &resolution, const std::vector< mesh::LocalBoundary > &local_neumann_boundary, Eigen::MatrixXd &rhs, const Eigen::MatrixXd &displacement=Eigen::MatrixXd(), const double t=1) const
const mesh::Mesh & mesh() const
const std::vector< RowVectorNd > & neumann_nodes_position_
const std::vector< basis::ElementBases > & gbases_
basis functions associated with geometric mapping
const Problem & problem() const
const mesh::Obstacle * obstacle_
const int size_
dimension of problem
double compute_energy(const Eigen::MatrixXd &displacement, const Eigen::MatrixXd &displacement_prev, const std::vector< mesh::LocalBoundary > &local_neumann_boundary, const Density &density, const QuadratureOrders &resolution, const double t) const
const std::vector< int > & neumann_nodes_
const std::vector< RowVectorNd > & dirichlet_nodes_position_
const Assembler & assembler() const
const AssemblyValsCache & ass_vals_cache_
void initial_solution(Eigen::MatrixXd &sol) const
void lsq_bc(const std::function< void(const Eigen::MatrixXi &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &df, const std::vector< mesh::LocalBoundary > &local_boundary, const std::vector< int > &bounday_nodes, const int resolution, Eigen::MatrixXd &rhs) const
const std::vector< basis::ElementBases > & bases_
basis functions associated with solution
const std::vector< basis::ElementBases > & gbases() const
void compute_energy_grad(const std::vector< mesh::LocalBoundary > &local_boundary, const std::vector< int > &bounday_nodes, const Density &density, const QuadratureOrders &resolution, const std::vector< mesh::LocalBoundary > &local_neumann_boundary, const Eigen::MatrixXd &final_rhs, const double t, Eigen::MatrixXd &rhs) const
void set_bc(const std::function< void(const Eigen::MatrixXi &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &df, const std::function< void(const Eigen::MatrixXi &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &nf, const std::vector< mesh::LocalBoundary > &local_boundary, const std::vector< int > &bounday_nodes, const QuadratureOrders &resolution, const std::vector< mesh::LocalBoundary > &local_neumann_boundary, const Eigen::MatrixXd &displacement, const double t, Eigen::MatrixXd &rhs) const
void initial_acceleration(Eigen::MatrixXd &sol) const
void initial_velocity(Eigen::MatrixXd &sol) const
void assemble(const Density &density, Eigen::MatrixXd &rhs, const double t=1) const
const std::vector< int > & dirichlet_nodes_
const std::vector< basis::ElementBases > & bases() const
void sample_bc(const std::function< void(const Eigen::MatrixXi &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &df, const std::vector< mesh::LocalBoundary > &local_boundary, const std::vector< int > &bounday_nodes, Eigen::MatrixXd &rhs) const
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:41
std::array< int, 2 > QuadratureOrders
Definition Types.hpp:19
nlohmann::json json
Definition Common.hpp:9
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix
Definition Types.hpp:24