PolyFEM
Loading...
Searching...
No Matches
PhysicsRemesher.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <polyfem/State.hpp>
7
8namespace polyfem::mesh
9{
10 template <class WMTKMesh>
11 class PhysicsRemesher : public WildRemesher<WMTKMesh>
12 {
13 private:
16
17 protected:
18 using Super::args;
19 using Super::executor;
20 using Super::state;
21
22 public:
24 using Tuple = typename Super::Tuple;
25 using Operations = typename Super::Operations;
26 using VectorNd = typename Super::VectorNd;
27
29 const State &state,
30 const Eigen::MatrixXd &obstacle_displacements,
31 const Eigen::MatrixXd &obstacle_vals,
32 const double current_time,
33 const double starting_energy)
35 {
36 }
37
38 virtual ~PhysicsRemesher(){};
39
40 // Edge splitting
41 void split_edges() override;
42 bool split_edge_before(const Tuple &t) override;
43 bool split_edge_after(const Tuple &t) override;
44
45 // Edge collapse
46 void collapse_edges() override;
47 bool collapse_edge_before(const Tuple &t) override;
48 bool collapse_edge_after(const Tuple &t) override;
49
50 // Smooth vertex
51 bool smooth_before(const Tuple &t) override;
52 bool smooth_after(const Tuple &t) override;
53
54 protected:
60 const std::string &op, const std::vector<Tuple> &tris) const override;
61
65 bool local_relaxation(const Tuple &t, const double acceptance_tolerance)
66 {
67 return local_relaxation(local_mesh_tuples(t), acceptance_tolerance);
68 }
69
73 bool local_relaxation(const VectorNd &center, const double acceptance_tolerance)
74 {
75 return local_relaxation(local_mesh_tuples(center), acceptance_tolerance);
76 }
77
83 const std::vector<Tuple> &local_mesh_tuples,
84 const double acceptance_tolerance);
85
89 std::vector<Tuple> local_mesh_tuples(const VectorNd &center) const;
90
94 std::vector<Tuple> local_mesh_tuples(const Tuple &v) const
95 {
96 return local_mesh_tuples(this->vertex_attrs[v.vid(*this)].rest_position);
97 }
98
102 double local_mesh_energy(const VectorNd &local_mesh_center) const;
103
105 double local_energy_before() const { return this->op_cache->local_energy; }
106
108 double edge_elastic_energy(const Tuple &e) const;
109
112 void write_priority_queue_mesh(const std::string &path, const Tuple &e) const;
113 };
114
115 class PhysicsTriRemesher : public PhysicsRemesher<wmtk::TriMesh>
116 {
117 private:
119
120 public:
121 using Tuple = typename Super::Tuple;
122
124 const State &state,
125 const Eigen::MatrixXd &obstacle_displacements,
126 const Eigen::MatrixXd &obstacle_vals,
127 const double current_time,
128 const double starting_energy)
130 {
131 }
132
133 protected:
134 // Edge swap
135 void swap_edges() override;
136 bool swap_edge_before(const Tuple &t) override;
137 bool swap_edge_after(const Tuple &t) override;
138 };
139
140 class PhysicsTetRemesher : public PhysicsRemesher<wmtk::TetMesh>
141 {
142 private:
144
145 public:
146 using Tuple = typename Super::Tuple;
147
149 const State &state,
150 const Eigen::MatrixXd &obstacle_displacements,
151 const Eigen::MatrixXd &obstacle_vals,
152 const double current_time,
153 const double starting_energy)
155 {
156 }
157
158 protected:
159 // 4-4 Edge swap
160 // bool swap_edge_44_before(const Tuple &t) override;
161 // bool swap_edge_44_after(const Tuple &t) override;
162
163 // 2-3 Face swap
164 // bool swap_face_before(const Tuple &t) override;
165 // bool swap_face_after(const Tuple &t) override;
166
167 // 3-2 Edge swap
168 // bool swap_edge_before(const Tuple &t) override;
169 // bool swap_edge_after(const Tuple &t) override;
170 };
171
172} // namespace polyfem::mesh
main class that contains the polyfem solver and all its state
Definition State.hpp:79
double local_mesh_energy(const VectorNd &local_mesh_center) const
Compute the energy of a local n-ring around a vertex.
void write_priority_queue_mesh(const std::string &path, const Tuple &e) const
Write a visualization mesh of the priority queue.
typename Super::Operations Operations
typename Super::VectorNd VectorNd
void split_edges() override
Definition Split.cpp:169
PhysicsRemesher< WMTKMesh > This
bool local_relaxation(const Tuple &t, const double acceptance_tolerance)
Relax a local n-ring around a vertex.
bool collapse_edge_after(const Tuple &t) override
Definition Collapse.cpp:205
wmtk::AttributeCollection< VertexAttributes > vertex_attrs
bool smooth_before(const Tuple &t) override
Definition Smooth.cpp:171
bool split_edge_after(const Tuple &t) override
Definition Split.cpp:127
bool smooth_after(const Tuple &t) override
Definition Smooth.cpp:280
double edge_elastic_energy(const Tuple &e) const
Compute the average elastic energy of the faces containing an edge.
bool collapse_edge_before(const Tuple &t) override
Definition Collapse.cpp:75
std::vector< Tuple > local_mesh_tuples(const Tuple &v) const
Get the local n-ring around a vertex.
double local_energy_before() const
Get the energy of the local n-ring around a vertex.
Operations renew_neighbor_tuples(const std::string &op, const std::vector< Tuple > &tris) const override
Renew the neighbor tuples of an operation.
bool local_relaxation(const VectorNd &center, const double acceptance_tolerance)
Relax a local n-ring around a vertex.
PhysicsRemesher(const State &state, const Eigen::MatrixXd &obstacle_displacements, const Eigen::MatrixXd &obstacle_vals, const double current_time, const double starting_energy)
bool split_edge_before(const Tuple &t) override
Definition Split.cpp:37
std::vector< Tuple > local_mesh_tuples(const VectorNd &center) const
Get the local n-ring around a vertex.
PhysicsTetRemesher(const State &state, const Eigen::MatrixXd &obstacle_displacements, const Eigen::MatrixXd &obstacle_vals, const double current_time, const double starting_energy)
bool swap_edge_after(const Tuple &t) override
Definition Swap.cpp:161
bool swap_edge_before(const Tuple &t) override
Definition Swap.cpp:64
PhysicsTriRemesher(const State &state, const Eigen::MatrixXd &obstacle_displacements, const Eigen::MatrixXd &obstacle_vals, const double current_time, const double starting_energy)
const Eigen::MatrixXd & obstacle_displacements() const
Get a reference to the collision obstacles' displacements.
Definition Remesher.hpp:133
const double current_time
Current time.
Definition Remesher.hpp:219
const double starting_energy
Starting energy.
Definition Remesher.hpp:221
const State & state
Reference to the simulation state.
Definition Remesher.hpp:191
const json args
Copy of remesh args.
Definition Remesher.hpp:213
std::conditional< std::is_same< WMTKMesh, wmtk::TriMesh >::value, std::shared_ptr< TriOperationCache >, std::shared_ptr< TetOperationCache > >::type op_cache
std::vector< std::pair< std::string, Tuple > > Operations
wmtk::ExecutePass< WildRemesher, EXECUTION_POLICY > executor
typename WMTKMesh::Tuple Tuple
wmtk::AttributeCollection< VertexAttributes > vertex_attrs
Eigen::Matrix< double, DIM, 1 > VectorNd
WildTetRemesher::Tuple Tuple
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, 3, 1 > VectorNd
Definition Types.hpp:11