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 io::ResourceIO &resources,
36 const std::string bc_method,
37 const json &solver_params,
38 const int fe_space_id = -1);
39
40 // computes the rhs of a problem by \int \phi rho rhs
41 void assemble(const Density &density, Eigen::MatrixXd &rhs, const double t = 1) const;
42
43 // computes the initial soltion for time dependent, calls time_bc
44 void initial_solution(Eigen::MatrixXd &sol) const;
45 // computes the initial velocity for time dependent, calls time_bc
46 void initial_velocity(Eigen::MatrixXd &sol) const;
47 // computes the initial acceleration for time dependent, calls time_bc
48 void initial_acceleration(Eigen::MatrixXd &sol) const;
49
50 // sets boundary conditions to rhs, the boundary conditions are projected (Dirichlet) integrated (Neumann) at resolution
51 // local boundary stores the mapping from elemment to nodes for Dirichlet nodes
52 // local local_neumann_boundary stores the mapping from elemment to nodes for Neumann nodes
53 // calls set_bc
54 void set_bc(
55 const std::vector<mesh::LocalBoundary> &local_boundary,
56 const std::vector<int> &bounday_nodes,
57 const QuadratureOrders &resolution,
58 const std::vector<mesh::LocalBoundary> &local_neumann_boundary,
59 Eigen::MatrixXd &rhs,
60 const Eigen::MatrixXd &displacement = Eigen::MatrixXd(),
61 const double t = 1) const;
62
63 // compute body energy
64 double compute_energy(
65 const Eigen::MatrixXd &displacement,
66 const Eigen::MatrixXd &displacement_prev,
67 const std::vector<mesh::LocalBoundary> &local_neumann_boundary,
68 const Density &density,
69 const QuadratureOrders &resolution,
70 const double t) const;
71 // compute body energy gradient, hessian is zero, rhs is a linear function
73 const std::vector<mesh::LocalBoundary> &local_boundary,
74 const std::vector<int> &bounday_nodes,
75 const Density &density,
76 const QuadratureOrders &resolution,
77 const std::vector<mesh::LocalBoundary> &local_neumann_boundary,
78 const Eigen::MatrixXd &final_rhs,
79 const double t,
80 Eigen::MatrixXd &rhs) const;
81
82 // compute body hessian wrt to previous solution
83 void compute_energy_hess(const std::vector<int> &bounday_nodes,
84 const QuadratureOrders &resolution,
85 const std::vector<mesh::LocalBoundary> &local_neumann_boundary,
86 const Eigen::MatrixXd &displacement,
87 const double t,
88 const bool project_to_psd,
89 StiffnessMatrix &hess) const;
90
91 inline const Problem &problem() const { return problem_; }
92 inline const mesh::Mesh &mesh() const { return mesh_; }
93 inline const std::vector<basis::ElementBases> &bases() const { return bases_; }
94 inline const std::vector<basis::ElementBases> &gbases() const { return gbases_; }
95 inline const AssemblyValsCache &ass_vals_cache() const { return ass_vals_cache_; }
96 inline const Assembler &assembler() const { return assembler_; }
97
98 private:
99 // leastsquares fit bc
100 void lsq_bc(const std::function<void(const Eigen::MatrixXi &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &df,
101 const std::vector<mesh::LocalBoundary> &local_boundary,
102 const std::vector<int> &bounday_nodes,
103 const int resolution,
104 Eigen::MatrixXd &rhs) const;
105
106 // sample bc at nodes
107 void sample_bc(const std::function<void(const Eigen::MatrixXi &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &df,
108 const std::vector<mesh::LocalBoundary> &local_boundary,
109 const std::vector<int> &bounday_nodes,
110 Eigen::MatrixXd &rhs) const;
111
112 // set boundary condition
113 // the 2 lambdas are callback to dirichlet df and neumann nf
114 // diriclet boundary condition are projected on the FEM bases, it inverts a linear system
115 void set_bc(
116 const std::function<void(const Eigen::MatrixXi &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &df,
117 const std::function<void(const Eigen::MatrixXi &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &nf,
118 const std::vector<mesh::LocalBoundary> &local_boundary,
119 const std::vector<int> &bounday_nodes,
120 const QuadratureOrders &resolution,
121 const std::vector<mesh::LocalBoundary> &local_neumann_boundary,
122 const Eigen::MatrixXd &displacement,
123 const double t,
124 Eigen::MatrixXd &rhs) const;
125
126 // sets the time (initial) boundary condition
127 // the lambda depeneds if soltuion, velocity, or acceleration
128 // they are projected on the FEM bases, it inverts a linear system
129 void time_bc(const std::function<void(const mesh::Mesh &, const Eigen::MatrixXi &, const Eigen::MatrixXd &, Eigen::MatrixXd &)> &fun, Eigen::MatrixXd &sol) const;
130
134 const int n_basis_;
135 const int size_;
136 const std::vector<basis::ElementBases> &bases_;
137 const std::vector<basis::ElementBases> &gbases_;
141 const std::string bc_method_;
143 const int fe_space_id_;
144 const std::vector<int> &dirichlet_nodes_;
145 const std::vector<RowVectorNd> &dirichlet_nodes_position_;
146 const std::vector<int> &neumann_nodes_;
147 const std::vector<RowVectorNd> &neumann_nodes_position_;
148 };
149 } // namespace assembler
150} // 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
const io::ResourceIO & resources_
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
Read-only interface to a hierarchical collection of simulation resources.
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:50
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