PolyFEM
Loading...
Searching...
No Matches
Problem.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/Units.hpp>
4
9
10namespace polyfem
11{
12 namespace assembler
13 {
14 class Problem
15 {
16 public:
17 Problem(const std::string &name);
18 virtual void set_units(const assembler::Assembler &assembler, const Units &units) {}
19
20 virtual ~Problem() {}
21
22 virtual void init(const mesh::Mesh &mesh) {}
23 inline const std::string &name() const { return name_; }
24
25 virtual bool is_scalar() const = 0;
26
27 virtual void rhs(const assembler::Assembler &assembler, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const = 0;
28 virtual bool is_rhs_zero() const = 0;
29
30 virtual void dirichlet_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const = 0;
31 virtual void neumann_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &normals, const double t, Eigen::MatrixXd &val) const {}
32 virtual void pressure_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &normals, const double t, Eigen::MatrixXd &val) const {}
33 virtual double pressure_cavity_bc(const int boundary_id, const double t) const { return 0; }
34
35 virtual bool is_boundary_pressure(const int boundary_id) const { return std::find(pressure_boundary_ids_.begin(), pressure_boundary_ids_.end(), boundary_id) != pressure_boundary_ids_.end(); }
36
37 virtual void dirichlet_nodal_value(const mesh::Mesh &mesh, const int node_id, const RowVectorNd &pt, const double t, Eigen::MatrixXd &val) const {}
38 virtual void neumann_nodal_value(const mesh::Mesh &mesh, const int node_id, const RowVectorNd &pt, const Eigen::MatrixXd &normal, const double t, Eigen::MatrixXd &val) const {}
39 virtual bool is_nodal_dirichlet_boundary(const int n_id, const int tag) { return false; }
40 virtual bool is_nodal_neumann_boundary(const int n_id, const int tag) { return false; }
41 virtual bool has_nodal_dirichlet() { return false; }
42 virtual bool has_nodal_neumann() { return false; }
43
44 virtual bool has_exact_sol() const = 0;
45 virtual void exact(const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const {};
46 virtual void exact_grad(const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const {};
47
48 virtual void clear() {}
49
50 virtual bool is_time_dependent() const { return false; }
51 virtual bool is_constant_in_time() const { return true; }
52
53 virtual void initial_solution(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val) const {}
54 virtual void initial_velocity(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val) const {}
55 virtual void initial_acceleration(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val) const {}
56 virtual void initial_density(const Eigen::MatrixXd &pts, Eigen::MatrixXd &val) const {}
57
58 virtual void set_parameters(const json &params) {}
59
60 virtual bool might_have_no_dirichlet() { return false; }
61 virtual bool is_dimension_dirichet(const int tag, const int dim) const { return true; }
62 virtual bool is_nodal_dimension_dirichlet(const int n_id, const int tag, const int dim) const { return true; }
63
64 virtual bool all_dimensions_dirichlet() const { return true; } // here for efficiency reasons
65
66 void setup_bc(const mesh::Mesh &mesh,
67 const int n_bases, const std::vector<basis::ElementBases> &bases, const std::vector<basis::ElementBases> &geom_bases, const std::vector<basis::ElementBases> &pressure_bases,
68 std::vector<mesh::LocalBoundary> &local_boundary, std::vector<int> &boundary_nodes,
69 std::vector<mesh::LocalBoundary> &local_neumann_boundary,
70 std::vector<mesh::LocalBoundary> &local_pressure_boundary,
71 std::unordered_map<int, std::vector<mesh::LocalBoundary>> &local_pressure_cavity,
72 std::vector<int> &pressure_boundary_nodes,
73 std::vector<int> &dirichlet_nodes, std::vector<int> &neumann_nodes);
74
75 virtual void update_nodes(const Eigen::VectorXi &in_node_to_node) {}
76
77 protected:
78 std::vector<int> boundary_ids_;
79 std::vector<int> neumann_boundary_ids_;
81 std::vector<int> pressure_boundary_ids_;
82 std::vector<int> pressure_cavity_ids_;
84
85 private:
86 std::string name_;
87 };
88 } // namespace assembler
89} // namespace polyfem
double val
Definition Assembler.cpp:86
virtual void neumann_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &normals, const double t, Eigen::MatrixXd &val) const
Definition Problem.hpp:31
void setup_bc(const mesh::Mesh &mesh, const int n_bases, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &geom_bases, const std::vector< basis::ElementBases > &pressure_bases, std::vector< mesh::LocalBoundary > &local_boundary, std::vector< int > &boundary_nodes, std::vector< mesh::LocalBoundary > &local_neumann_boundary, std::vector< mesh::LocalBoundary > &local_pressure_boundary, std::unordered_map< int, std::vector< mesh::LocalBoundary > > &local_pressure_cavity, std::vector< int > &pressure_boundary_nodes, std::vector< int > &dirichlet_nodes, std::vector< int > &neumann_nodes)
Definition Problem.cpp:16
virtual void set_parameters(const json &params)
Definition Problem.hpp:58
virtual bool has_nodal_neumann()
Definition Problem.hpp:42
virtual void pressure_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const Eigen::MatrixXd &normals, const double t, Eigen::MatrixXd &val) const
Definition Problem.hpp:32
virtual bool is_rhs_zero() const =0
const std::string & name() const
Definition Problem.hpp:23
std::vector< int > normal_aligned_neumann_boundary_ids_
Definition Problem.hpp:80
virtual void neumann_nodal_value(const mesh::Mesh &mesh, const int node_id, const RowVectorNd &pt, const Eigen::MatrixXd &normal, const double t, Eigen::MatrixXd &val) const
Definition Problem.hpp:38
virtual bool is_dimension_dirichet(const int tag, const int dim) const
Definition Problem.hpp:61
virtual bool all_dimensions_dirichlet() const
Definition Problem.hpp:64
virtual void exact_grad(const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const
Definition Problem.hpp:46
virtual void initial_density(const Eigen::MatrixXd &pts, Eigen::MatrixXd &val) const
Definition Problem.hpp:56
virtual double pressure_cavity_bc(const int boundary_id, const double t) const
Definition Problem.hpp:33
virtual void initial_acceleration(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val) const
Definition Problem.hpp:55
virtual bool is_scalar() const =0
virtual void set_units(const assembler::Assembler &assembler, const Units &units)
Definition Problem.hpp:18
virtual void update_nodes(const Eigen::VectorXi &in_node_to_node)
Definition Problem.hpp:75
std::vector< int > pressure_boundary_ids_
Definition Problem.hpp:81
virtual bool has_exact_sol() const =0
virtual void rhs(const assembler::Assembler &assembler, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const =0
virtual bool is_nodal_neumann_boundary(const int n_id, const int tag)
Definition Problem.hpp:40
virtual bool might_have_no_dirichlet()
Definition Problem.hpp:60
virtual void dirichlet_nodal_value(const mesh::Mesh &mesh, const int node_id, const RowVectorNd &pt, const double t, Eigen::MatrixXd &val) const
Definition Problem.hpp:37
std::vector< int > splitting_pressure_boundary_ids_
Definition Problem.hpp:83
virtual void initial_velocity(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val) const
Definition Problem.hpp:54
std::vector< int > boundary_ids_
Definition Problem.hpp:78
virtual bool is_constant_in_time() const
Definition Problem.hpp:51
virtual void exact(const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const
Definition Problem.hpp:45
virtual bool is_nodal_dirichlet_boundary(const int n_id, const int tag)
Definition Problem.hpp:39
virtual bool is_nodal_dimension_dirichlet(const int n_id, const int tag, const int dim) const
Definition Problem.hpp:62
virtual bool is_boundary_pressure(const int boundary_id) const
Definition Problem.hpp:35
virtual bool is_time_dependent() const
Definition Problem.hpp:50
virtual void initial_solution(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &pts, Eigen::MatrixXd &val) const
Definition Problem.hpp:53
virtual void dirichlet_bc(const mesh::Mesh &mesh, const Eigen::MatrixXi &global_ids, const Eigen::MatrixXd &uv, const Eigen::MatrixXd &pts, const double t, Eigen::MatrixXd &val) const =0
virtual void init(const mesh::Mesh &mesh)
Definition Problem.hpp:22
std::vector< int > neumann_boundary_ids_
Definition Problem.hpp:79
std::vector< int > pressure_cavity_ids_
Definition Problem.hpp:82
virtual bool has_nodal_dirichlet()
Definition Problem.hpp:41
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
Definition Mesh.hpp:39
nlohmann::json json
Definition Common.hpp:9
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13