114 std::unordered_map<size_t, std::tuple<double, double, int>> edge_to_fields;
117 const double current_edge_energy = edge_elastic_energy(e);
118 edge_to_fields[e.eid(*
this)] = std::make_tuple(current_edge_energy, 0, 0);
121 auto queue = executor.serial_queue();
124 bool energies_match =
true;
126 for (
int i = 1; !queue.empty(); ++i)
128 std::tuple<double, std::string, Tuple, size_t> tmp;
129 bool pop_success = queue.try_pop(tmp);
131 const auto &[energy, op, t, _] = tmp;
134 if (!t.is_valid(*
this))
143 const double recomputed_energy = edge_elastic_energy(t);
144 const double diff = energy - recomputed_energy;
145 if (abs(diff) >= tol)
148 "Energy mismatch: {} vs {}; diff={:g}",
149 energy, recomputed_energy, diff);
150 energies_match =
false;
154 assert(current_edge_energy - energy >= -tol);
157 edge_to_fields[t.eid(*
this)] = std::make_tuple(energy, abs(diff), i);
159 assert(energies_match);
161 const std::vector<Tuple> edges = WMTKMesh::get_edges();
164 const int n_vertices = 2 * edges.size();
166 std::vector<std::vector<int>> elements(edges.size(), std::vector<int>(2));
167 Eigen::MatrixXd rest_positions(n_vertices, this->dim());
168 Eigen::MatrixXd displacements(n_vertices, this->dim());
169 Eigen::VectorXd edge_energies(n_vertices);
170 Eigen::VectorXd edge_energy_diffs(n_vertices);
171 Eigen::VectorXd edge_orders(n_vertices);
173 for (
int ei = 0; ei < edges.size(); ei++)
175 const std::array<size_t, 2> vids = {{
176 edges[ei].vid(*
this),
177 edges[ei].switch_vertex(*this).vid(*
this),
180 double edge_energy, edge_energy_diff, edge_order;
181 const auto &itr = edge_to_fields.find(edges[ei].eid(*
this));
182 if (itr != edge_to_fields.end())
183 std::tie(edge_energy, edge_energy_diff, edge_order) = itr->second;
185 edge_energy = edge_energy_diff = edge_order = NaN;
187 for (
int vi = 0; vi < vids.size(); ++vi)
189 elements[ei][vi] = 2 * ei + vi;
190 rest_positions.row(elements[ei][vi]) = vertex_attrs[vids[vi]].rest_position;
191 displacements.row(elements[ei][vi]) = vertex_attrs[vids[vi]].displacement();
192 edge_energies(elements[ei][vi]) = edge_energy;
193 edge_energy_diffs(elements[ei][vi]) = edge_energy_diff;
194 edge_orders(elements[ei][vi]) = edge_order;
198 paraviewo::VTUWriter writer;
199 writer.add_field(
"displacement", displacements);
200 writer.add_field(
"edge_energy", edge_energies);
201 writer.add_field(
"edge_energy_diff", edge_energy_diffs);
202 writer.add_field(
"operation_order", edge_orders);
203 writer.write_mesh(path, rest_positions, elements,
true,
false);