PolyFEM
Loading...
Searching...
No Matches
Execute.cpp
Go to the documentation of this file.
2
4
5#include <wmtk/utils/ExecutorUtils.hpp>
6#include <wmtk/utils/TupleUtils.hpp>
7
8// #define SAVE_OPS
9
10namespace polyfem::mesh
11{
12 template <class WMTKMesh>
14 {
15 const auto &reset_edge_attrs = [&](const Tuple &e) {
16 edge_attr(e.eid(*this)).op_attempts = 0;
17 edge_attr(e.eid(*this)).op_depth = 0;
18 };
19
20 utils::Timer timer(total_time);
21 timer.start();
22
23 const bool split = args["split"]["enabled"];
24 const bool collapse = args["collapse"]["enabled"];
25 const bool swap = args["swap"]["enabled"];
26 const bool smooth = args["smooth"]["enabled"];
27
28 wmtk::logger().set_level(logger().level());
29
30 // if (NUM_THREADS > 0)
31 // {
32 // executor.lock_vertices = [&](WildRemesher &m, const Tuple &e, int task_id) -> bool {
33 // return m.try_set_edge_mutex_n_ring(e, task_id, n_ring_size);
34 // };
35 // executor.num_threads = NUM_THREADS;
36 // }
37
38 executor.renew_neighbor_tuples = [&](const WildRemesher &m, std::string op, const std::vector<Tuple> &tris) -> Operations {
39 return m.renew_neighbor_tuples(op, tris);
40 };
41
42 static int aggregate_split_cnt_success = 0;
43 static int aggregate_split_cnt_fail = 0;
44 static int aggregate_collapse_cnt_success = 0;
45 static int aggregate_collapse_cnt_fail = 0;
46 static int aggregate_swap_cnt_success = 0;
47 static int aggregate_swap_cnt_fail = 0;
48 static int aggregate_smooth_cnt_success = 0;
49 static int aggregate_smooth_cnt_fail = 0;
50
51#ifdef SAVE_OPS
52 static int frame_count = 0;
53 if (frame_count == 0)
54 write_mesh(state.resolve_output_path(fmt::format("op{:d}.vtu", frame_count++)));
55#endif
56
57 int cnt_success = 0;
58
59 cache_before();
60
61 if (split)
62 {
63 logger().info("Splitting");
64 split_edges();
65 cnt_success += executor.cnt_success();
66 aggregate_split_cnt_success += executor.cnt_success();
67 aggregate_split_cnt_fail += executor.cnt_fail();
68#ifdef SAVE_OPS
69 write_mesh(state.resolve_output_path(fmt::format("op{:d}.vtu", frame_count++)));
70#endif
71 }
72
73 // Reset operation attempts and depth counters
74 WMTKMesh::for_each_edge(reset_edge_attrs);
75
76 bool projection_needed = false;
77
78 if (collapse)
79 {
80 logger().info("Collapsing");
81 executor.m_cnt_success = 0;
82 executor.m_cnt_fail = 0;
83 collapse_edges();
84 cnt_success += executor.cnt_success();
85 aggregate_collapse_cnt_success += executor.cnt_success();
86 aggregate_collapse_cnt_fail += executor.cnt_fail();
87 projection_needed |= executor.cnt_success() > 0;
88#ifdef SAVE_OPS
89 write_mesh(state.resolve_output_path(fmt::format("op{:d}.vtu", frame_count++)));
90#endif
91 }
92
93 // Reset operation attempts and depth counters
94 WMTKMesh::for_each_edge(reset_edge_attrs);
95
96 if (swap)
97 {
98 assert(DIM == 2);
99 logger().info("Swapping");
100 executor.m_cnt_success = 0;
101 executor.m_cnt_fail = 0;
102 swap_edges();
103 cnt_success += executor.cnt_success();
104 aggregate_swap_cnt_success += executor.cnt_success();
105 aggregate_swap_cnt_fail += executor.cnt_fail();
106 projection_needed |= executor.cnt_success() > 0;
107#ifdef SAVE_OPS
108 write_mesh(state.resolve_output_path(fmt::format("op{:d}.vtu", frame_count++)));
109#endif
110 }
111
112 if (smooth)
113 {
114 assert(DIM == 2);
115 logger().info("Smoothing");
116 executor.m_cnt_success = 0;
117 executor.m_cnt_fail = 0;
118 smooth_vertices();
119 cnt_success += executor.cnt_success();
120 aggregate_smooth_cnt_success += executor.cnt_success();
121 aggregate_smooth_cnt_fail += executor.cnt_fail();
122 projection_needed |= executor.cnt_success() > 0;
123#ifdef SAVE_OPS
124 write_mesh(state.resolve_output_path(fmt::format("op{:d}.vtu", frame_count++)));
125#endif
126 }
127
128 logger().info("[split] aggregate_cnt_success {} aggregate_cnt_fail {}", aggregate_split_cnt_success, aggregate_split_cnt_fail);
129 logger().info("[collapse] aggregate_cnt_success {} aggregate_cnt_fail {}", aggregate_collapse_cnt_success, aggregate_collapse_cnt_fail);
130 logger().info("[swap] aggregate_cnt_success {} aggregate_cnt_fail {}", aggregate_swap_cnt_success, aggregate_swap_cnt_fail);
131 logger().info("[smooth] aggregate_cnt_success {} aggregate_cnt_fail {}", aggregate_smooth_cnt_success, aggregate_smooth_cnt_fail);
132
133 if (projection_needed)
134 project_quantities();
135#ifdef SAVE_OPS
136 write_mesh(state.resolve_output_path(fmt::format("op{:d}.vtu", frame_count++)));
137#endif
138
139 // Remove unused vertices
140 WMTKMesh::consolidate_mesh();
141
142 timer.stop();
143 log_timings();
144
145 return cnt_success > 0;
146 }
147
148 // ------------------------------------------------------------------------
149 // Template specializations
150 template class WildRemesher<wmtk::TriMesh>;
151 template class WildRemesher<wmtk::TetMesh>;
152
153} // namespace polyfem::mesh
virtual Operations renew_neighbor_tuples(const std::string &op, const std::vector< Tuple > &tris) const
std::vector< std::pair< std::string, Tuple > > Operations
typename WMTKMesh::Tuple Tuple
bool execute() override
Execute the remeshing.
Definition Execute.cpp:13
spdlog::logger & logger()
Retrieves the current logger.
Definition Logger.cpp:42