45#include <polysolve/linear/FEMSolver.hpp>
66 using namespace assembler;
69 using namespace utils;
74 void build_in_node_to_in_primitive(
const Mesh &mesh,
const MeshNodes &mesh_nodes,
75 Eigen::VectorXi &in_node_to_in_primitive,
76 Eigen::VectorXi &in_node_offset)
78 const int num_vertex_nodes = mesh_nodes.num_vertex_nodes();
79 const int num_edge_nodes = mesh_nodes.num_edge_nodes();
80 const int num_face_nodes = mesh_nodes.num_face_nodes();
81 const int num_cell_nodes = mesh_nodes.num_cell_nodes();
83 const int num_nodes = num_vertex_nodes + num_edge_nodes + num_face_nodes + num_cell_nodes;
85 const long n_vertices = num_vertex_nodes;
86 const int num_in_primitives = n_vertices + mesh.n_edges() + mesh.n_faces() + mesh.n_cells();
87 const int num_primitives = mesh.n_vertices() + mesh.n_edges() + mesh.n_faces() + mesh.n_cells();
89 in_node_to_in_primitive.resize(num_nodes);
90 in_node_offset.resize(num_nodes);
93 in_node_to_in_primitive.head(num_vertex_nodes).setLinSpaced(num_vertex_nodes, 0, num_vertex_nodes - 1);
94 in_node_offset.head(num_vertex_nodes).setZero();
96 int prim_offset = n_vertices;
97 int node_offset = num_vertex_nodes;
98 auto foo = [&](
const int num_prims,
const int num_prim_nodes) {
99 if (num_prims <= 0 || num_prim_nodes <= 0)
101 const Eigen::VectorXi range = Eigen::VectorXi::LinSpaced(num_prim_nodes, 0, num_prim_nodes - 1);
103 const int node_per_prim = num_prim_nodes / num_prims;
105 in_node_to_in_primitive.segment(node_offset, num_prim_nodes) =
106 range.array() / node_per_prim + prim_offset;
108 in_node_offset.segment(node_offset, num_prim_nodes) =
109 range.unaryExpr([&](
const int x) {
return x % node_per_prim; });
111 prim_offset += num_prims;
112 node_offset += num_prim_nodes;
115 foo(mesh.n_edges(), num_edge_nodes);
116 foo(mesh.n_faces(), num_face_nodes);
117 foo(mesh.n_cells(), num_cell_nodes);
120 bool build_in_primitive_to_primitive(
121 const Mesh &mesh,
const MeshNodes &mesh_nodes,
122 const Eigen::VectorXi &in_ordered_vertices,
123 const Eigen::MatrixXi &in_ordered_edges,
124 const Eigen::MatrixXi &in_ordered_faces,
125 Eigen::VectorXi &in_primitive_to_primitive)
128 const int num_vertex_nodes = mesh_nodes.num_vertex_nodes();
129 const int num_edge_nodes = mesh_nodes.num_edge_nodes();
130 const int num_face_nodes = mesh_nodes.num_face_nodes();
131 const int num_cell_nodes = mesh_nodes.num_cell_nodes();
132 const int num_nodes = num_vertex_nodes + num_edge_nodes + num_face_nodes + num_cell_nodes;
134 const long n_vertices = num_vertex_nodes;
135 const int num_in_primitives = n_vertices + mesh.n_edges() + mesh.n_faces() + mesh.n_cells();
136 const int num_primitives = mesh.n_vertices() + mesh.n_edges() + mesh.n_faces() + mesh.n_cells();
138 in_primitive_to_primitive.setLinSpaced(num_in_primitives, 0, num_in_primitives - 1);
146 if (in_ordered_vertices.rows() != n_vertices)
148 logger().warn(
"Node ordering disabled, in_ordered_vertices != n_vertices, {} != {}", in_ordered_vertices.rows(), n_vertices);
152 in_primitive_to_primitive.head(n_vertices) = in_ordered_vertices;
154 int in_offset = n_vertices;
155 int offset = mesh.n_vertices();
161 logger().trace(
"Building Mesh edges to IDs...");
163 const auto edges_to_ids = mesh.edges_to_ids();
164 if (in_ordered_edges.rows() != edges_to_ids.size())
166 logger().warn(
"Node ordering disabled, in_ordered_edges != edges_to_ids, {} != {}", in_ordered_edges.rows(), edges_to_ids.size());
170 logger().trace(
"Done (took {}s)", timer.getElapsedTime());
172 logger().trace(
"Building in-edge to edge mapping...");
174 for (
int in_ei = 0; in_ei < in_ordered_edges.rows(); in_ei++)
176 const std::pair<int, int> in_edge(
177 in_ordered_edges.row(in_ei).minCoeff(),
178 in_ordered_edges.row(in_ei).maxCoeff());
179 in_primitive_to_primitive[in_offset + in_ei] =
180 offset + edges_to_ids.at(in_edge);
183 logger().trace(
"Done (took {}s)", timer.getElapsedTime());
185 in_offset += mesh.n_edges();
186 offset += mesh.n_edges();
192 if (mesh.is_volume())
194 logger().trace(
"Building Mesh faces to IDs...");
196 const auto faces_to_ids = mesh.faces_to_ids();
197 if (in_ordered_faces.rows() != faces_to_ids.size())
199 logger().warn(
"Node ordering disabled, in_ordered_faces != faces_to_ids, {} != {}", in_ordered_faces.rows(), faces_to_ids.size());
203 logger().trace(
"Done (took {}s)", timer.getElapsedTime());
205 logger().trace(
"Building in-face to face mapping...");
207 for (
int in_fi = 0; in_fi < in_ordered_faces.rows(); in_fi++)
209 std::vector<int> in_face(in_ordered_faces.cols());
210 for (
int i = 0; i < in_face.size(); i++)
211 in_face[i] = in_ordered_faces(in_fi, i);
212 std::sort(in_face.begin(), in_face.end());
214 in_primitive_to_primitive[in_offset + in_fi] =
215 offset + faces_to_ids.at(in_face);
218 logger().trace(
"Done (took {}s)", timer.getElapsedTime());
220 in_offset += mesh.n_faces();
221 offset += mesh.n_faces();
231 indices.resize(
mesh->n_vertices());
238 std::vector<int> indices;
240 for (
int i = 0; i < p2n.size(); i++)
247 if (
args[
"space"][
"basis_type"] ==
"Spline")
249 logger().warn(
"Node ordering disabled, it dosent work for splines!");
255 logger().warn(
"Node ordering disabled, it works only for p < 4 and uniform order!");
259 if (!
mesh->is_conforming())
261 logger().warn(
"Node ordering disabled, not supported for non-conforming meshes!");
265 if (
mesh->has_poly())
267 logger().warn(
"Node ordering disabled, not supported for polygonal meshes!");
271 if (
mesh->in_ordered_vertices().size() <= 0 ||
mesh->in_ordered_edges().size() <= 0 || (
mesh->is_volume() &&
mesh->in_ordered_faces().size() <= 0))
273 logger().warn(
"Node ordering disabled, input vertices/edges/faces not computed!");
277 const int num_vertex_nodes =
mesh_nodes->num_vertex_nodes();
278 const int num_edge_nodes =
mesh_nodes->num_edge_nodes();
279 const int num_face_nodes =
mesh_nodes->num_face_nodes();
280 const int num_cell_nodes =
mesh_nodes->num_cell_nodes();
282 const int num_nodes = num_vertex_nodes + num_edge_nodes + num_face_nodes + num_cell_nodes;
284 const long n_vertices = num_vertex_nodes;
285 const int num_in_primitives = n_vertices +
mesh->n_edges() +
mesh->n_faces() +
mesh->n_cells();
286 const int num_primitives =
mesh->n_vertices() +
mesh->n_edges() +
mesh->n_faces() +
mesh->n_cells();
290 logger().trace(
"Building in-node to in-primitive mapping...");
292 Eigen::VectorXi in_node_to_in_primitive;
293 Eigen::VectorXi in_node_offset;
294 build_in_node_to_in_primitive(*
mesh, *
mesh_nodes, in_node_to_in_primitive, in_node_offset);
296 logger().trace(
"Done (took {}s)", timer.getElapsedTime());
298 logger().trace(
"Building in-primitive to primitive mapping...");
300 bool ok = build_in_primitive_to_primitive(
302 mesh->in_ordered_vertices(),
303 mesh->in_ordered_edges(),
304 mesh->in_ordered_faces(),
307 logger().trace(
"Done (took {}s)", timer.getElapsedTime());
315 const auto &tmp =
mesh_nodes->in_ordered_vertices();
318 max_tmp = std::max(max_tmp, v);
321 for (
int i = 0; i < tmp.size(); ++i)
330 if (
args[
"materials"].is_null())
332 logger().error(
"specify some 'materials'");
333 assert(!
args[
"materials"].is_null());
334 throw std::runtime_error(
"invalid input");
337 if (
args[
"materials"].is_array())
339 std::string current =
"";
340 for (
const auto &m :
args[
"materials"])
342 const std::string tmp = m[
"type"];
345 else if (current != tmp)
347 if (current ==
"LinearElasticity"
348 || current ==
"NeoHookean"
349 || current ==
"SaintVenant"
350 || current ==
"HookeLinearElasticity"
351 || current ==
"MooneyRivlin"
352 || current ==
"MooneyRivlin3Param"
353 || current ==
"UnconstrainedOgden"
354 || current ==
"IncompressibleOgden"
355 || current ==
"MultiModels")
357 if (tmp ==
"LinearElasticity"
358 || tmp ==
"NeoHookean"
359 || tmp ==
"SaintVenant"
360 || tmp ==
"HookeLinearElasticity"
361 || tmp ==
"MooneyRivlin"
362 || current ==
"MooneyRivlin3Param"
363 || tmp ==
"UnconstrainedOgden"
364 || tmp ==
"IncompressibleOgden")
365 current =
"MultiModels";
368 logger().error(
"Current material is {}, new material is {}, multimaterial supported only for LinearElasticity and NeoHookean", current, tmp);
369 throw std::runtime_error(
"invalid input");
374 logger().error(
"Current material is {}, new material is {}, multimaterial supported only for LinearElasticity and NeoHookean", current, tmp);
375 throw std::runtime_error(
"invalid input");
383 return args[
"materials"][
"type"];
390 logger().error(
"No pressure bases defined!");
395 Eigen::MatrixXd tmp = sol;
407 const std::vector<basis::ElementBases> &bases,
408 const std::vector<basis::ElementBases> &gbases,
409 Eigen::MatrixXd &basis_integrals)
413 logger().error(
"Works only on volumetric meshes!");
418 basis_integrals.resize(n_bases, 9);
419 basis_integrals.setZero();
420 Eigen::MatrixXd rhs(n_bases, 9);
424 for (
int e = 0; e < n_elements; ++e)
436 for (
int j = 0; j < n_local_bases; ++j)
453 for (
size_t ii = 0; ii < v.
global.size(); ++ii)
455 basis_integrals(v.
global[ii].index, 0) += integral_100 * v.
global[ii].val;
456 basis_integrals(v.
global[ii].index, 1) += integral_010 * v.
global[ii].val;
457 basis_integrals(v.
global[ii].index, 2) += integral_001 * v.
global[ii].val;
459 basis_integrals(v.
global[ii].index, 3) += integral_110 * v.
global[ii].val;
460 basis_integrals(v.
global[ii].index, 4) += integral_011 * v.
global[ii].val;
461 basis_integrals(v.
global[ii].index, 5) += integral_101 * v.
global[ii].val;
463 basis_integrals(v.
global[ii].index, 6) += integral_200 * v.
global[ii].val;
464 basis_integrals(v.
global[ii].index, 7) += integral_020 * v.
global[ii].val;
465 basis_integrals(v.
global[ii].index, 8) += integral_002 * v.
global[ii].val;
467 rhs(v.
global[ii].index, 6) += -2.0 * area * v.
global[ii].val;
468 rhs(v.
global[ii].index, 7) += -2.0 * area * v.
global[ii].val;
469 rhs(v.
global[ii].index, 8) += -2.0 * area * v.
global[ii].val;
474 basis_integrals -= rhs;
479 if (
mesh->has_poly())
482 if (
args[
"space"][
"basis_type"] ==
"Spline")
485 if (
mesh->is_rational())
488 if (
args[
"space"][
"use_p_ref"])
497 if (
mesh->orders().size() <= 0)
499 if (
args[
"space"][
"discr_order"] == 1)
502 return args[
"space"][
"advanced"][
"isoparametric"];
505 if (
mesh->orders().minCoeff() !=
mesh->orders().maxCoeff())
508 if (
args[
"space"][
"discr_order"] ==
mesh->orders().minCoeff())
515 return args[
"space"][
"advanced"][
"isoparametric"];
522 logger().error(
"Load the mesh first!");
526 mesh->prepare_mesh();
546 assert(
args[
"materials"].is_array());
548 std::vector<std::string> materials(
mesh->n_elements());
550 std::map<int, std::string> mats;
552 for (
const auto &m :
args[
"materials"])
553 mats[m[
"id"].get<int>()] = m[
"type"];
555 for (
int i = 0; i < materials.size(); ++i)
556 materials[i] = mats.at(
mesh->get_body_id(i));
558 mm->init_multimodels(materials);
570 logger().info(
"Building {} basis...", (
iso_parametric() ?
"isoparametric" :
"not isoparametric"));
571 const bool has_polys =
mesh->has_poly();
577 std::map<int, basis::InterfaceData> poly_edge_to_data_geom;
579 const auto &tmp_json =
args[
"space"][
"discr_order"];
580 if (tmp_json.is_number_integer())
584 else if (tmp_json.is_string())
586 const std::string discr_orders_path = tmp_json;
590 assert(tmp.cols() == 1);
593 else if (tmp_json.is_array())
595 const auto b_discr_orders = tmp_json;
597 std::map<int, int> b_orders;
598 for (
size_t i = 0; i < b_discr_orders.size(); ++i)
600 assert(b_discr_orders[i][
"id"].is_array() || b_discr_orders[i][
"id"].is_number_integer());
602 const int order = b_discr_orders[i][
"order"];
603 for (
const int id : json_as_array<int>(b_discr_orders[i][
"id"]))
605 b_orders[id] = order;
606 logger().trace(
"bid {}, discr {}",
id, order);
610 for (
int e = 0; e <
mesh->n_elements(); ++e)
612 const int bid =
mesh->get_body_id(e);
613 const auto order = b_orders.find(bid);
614 if (order == b_orders.end())
616 logger().debug(
"Missing discretization order for body {}; using 1", bid);
628 logger().error(
"space/discr_order must be either a number a path or an array");
629 throw std::runtime_error(
"invalid json");
633 Eigen::MatrixXi geom_disc_orders;
636 if (
mesh->orders().size() <= 0)
639 geom_disc_orders.setConstant(1);
642 geom_disc_orders =
mesh->orders();
647 if (
args[
"space"][
"use_p_ref"])
651 args[
"space"][
"advanced"][
"B"],
652 args[
"space"][
"advanced"][
"h1_formula"],
653 args[
"space"][
"discr_order"],
654 args[
"space"][
"advanced"][
"discr_order_max"],
661 int quadrature_order =
args[
"space"][
"advanced"][
"quadrature_order"].get<
int>();
662 const int mass_quadrature_order =
args[
"space"][
"advanced"][
"mass_quadrature_order"].get<
int>();
668 logger().error(
"p refinement not supported in mixed formulation!");
675 const bool use_continuous_gbasis =
true;
677 if (
mesh->is_volume())
680 if (
args[
"space"][
"basis_type"] ==
"Spline")
697 n_geom_bases =
basis::LagrangeBasis3d::build_bases(tmp_mesh,
assembler->name(), quadrature_order, mass_quadrature_order, geom_disc_orders,
false, has_polys, !use_continuous_gbasis,
geom_bases_,
local_boundary, poly_edge_to_data_geom,
geom_mesh_nodes);
699 n_bases =
basis::LagrangeBasis3d::build_bases(tmp_mesh,
assembler->name(), quadrature_order, mass_quadrature_order,
disc_orders,
args[
"space"][
"basis_type"] ==
"Serendipity", has_polys,
false,
bases,
local_boundary,
poly_edge_to_data,
mesh_nodes);
705 n_pressure_bases =
basis::LagrangeBasis3d::build_bases(tmp_mesh,
assembler->name(), quadrature_order, mass_quadrature_order,
int(
args[
"space"][
"pressure_discr_order"]),
false, has_polys,
false,
pressure_bases,
local_boundary, poly_edge_to_data_geom,
pressure_mesh_nodes);
711 if (
args[
"space"][
"basis_type"] ==
"Spline")
729 n_geom_bases =
basis::LagrangeBasis2d::build_bases(tmp_mesh,
assembler->name(), quadrature_order, mass_quadrature_order, geom_disc_orders,
false, has_polys, !use_continuous_gbasis,
geom_bases_,
local_boundary, poly_edge_to_data_geom,
geom_mesh_nodes);
731 n_bases =
basis::LagrangeBasis2d::build_bases(tmp_mesh,
assembler->name(), quadrature_order, mass_quadrature_order,
disc_orders,
args[
"space"][
"basis_type"] ==
"Serendipity", has_polys,
false,
bases,
local_boundary,
poly_edge_to_data,
mesh_nodes);
737 n_pressure_bases =
basis::LagrangeBasis2d::build_bases(tmp_mesh,
assembler->name(), quadrature_order, mass_quadrature_order,
int(
args[
"space"][
"pressure_discr_order"]),
false, has_polys,
false,
pressure_bases,
local_boundary, poly_edge_to_data_geom,
pressure_mesh_nodes);
747 bases[i].compute_quadrature(b_quad);
763 std::map<std::array<int, 2>,
double> pairs;
764 for (
int e = 0; e < gbases.size(); e++)
766 const auto &gbs = gbases[e].bases;
767 const auto &bs =
bases[e].bases;
769 Eigen::MatrixXd local_pts;
770 const int order = bs.front().order();
771 if (
mesh->is_volume())
773 if (
mesh->is_simplex(e))
780 if (
mesh->is_simplex(e))
789 for (
int i = 0; i < bs.size(); i++)
791 for (
int j = 0; j < gbs.size(); j++)
793 if (std::abs(
vals.basis_values[j].val(i)) > 1e-7)
795 std::array<int, 2> index = {{gbs[j].global()[0].index, bs[i].global()[0].index}};
796 pairs.insert({index,
vals.basis_values[j].val(i)});
802 const int dim =
mesh->dimension();
803 std::vector<Eigen::Triplet<double>> coeffs;
805 for (
const auto &iter : pairs)
806 for (
int d = 0; d < dim; d++)
807 coeffs.emplace_back(iter.first[0] * dim + d, iter.first[1] * dim + d, iter.second);
816 const int dim =
mesh->dimension();
817 const int problem_dim =
problem->is_scalar() ? 1 : dim;
823 json directions =
args[
"boundary_conditions"][
"periodic_boundary"][
"correspondence"];
824 Eigen::MatrixXd tile_offset = Eigen::MatrixXd::Identity(dim, dim);
826 if (directions.size() > 0)
829 for (
int d = 0; d < dim; d++)
832 if (tmp.size() != dim)
834 tile_offset.col(d) = tmp;
843 if (
args[
"space"][
"advanced"][
"count_flipped_els"])
846 const int prev_bases =
n_bases;
851 logger().debug(
"Building node mapping...");
857 logger().debug(
"Done (took {}s)", timer2.getElapsedTime());
860 logger().info(
"Building collision mesh...");
884 for (
const auto &bs :
bases)
886 for (
const auto &b : bs.bases)
888 for (
const auto &lg : b.global())
890 if (lg.index == n_id)
914 for (
const auto &bs :
bases)
916 for (
const auto &b : bs.bases)
918 for (
const auto &lg : b.global())
920 if (lg.index == n_id)
943 for (
int i = prev_bases; i <
n_bases; ++i)
945 for (
int d = 0; d < problem_dim; ++d)
957 std::vector<bool> isboundary(
n_bases,
false);
960 const int e = lb.element_id();
961 for (
int i = 0; i < lb.size(); ++i)
963 const auto nodes =
bases[e].local_nodes_for_primitive(lb.global_primitive_id(i), *
mesh);
966 isboundary[
bases[e].
bases[n].global()[0].index] =
true;
975 const int actual_dim =
problem->is_scalar() ? 1 :
mesh->dimension();
976 for (
int d = 0; d < actual_dim; d++)
980 logger().info(
"Fix solution at node {} to remove singularity due to periodic BC", i);
984 const int n_samples = 10;
1007 args[
"contact"][
"dhat"] = dhat;
1012 logger().info(
"dhat set to {}",
double(
args[
"contact"][
"dhat"]));
1033 if (
n_bases <=
args[
"solver"][
"advanced"][
"cache_size"])
1036 logger().info(
"Building cache...");
1042 logger().info(
" took {}s", timer.getElapsedTime());
1050 logger().warn(
"(Quasi-)Static problem without Dirichlet nodes, will fix solution at one node to find a unique solution!");
1060 logger().error(
"Load the mesh first!");
1074 logger().info(
"Computing polygonal basis...");
1085 if (
mesh->is_volume())
1087 if (
args[
"space"][
"poly_basis_type"] ==
"MeanValue" ||
args[
"space"][
"poly_basis_type"] ==
"Wachspress")
1088 logger().error(
"Barycentric bases not supported in 3D");
1092 args[
"space"][
"advanced"][
"n_harmonic_samples"],
1095 args[
"space"][
"advanced"][
"quadrature_order"],
1096 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1097 args[
"space"][
"advanced"][
"integral_constraints"],
1105 if (
args[
"space"][
"poly_basis_type"] ==
"MeanValue")
1112 args[
"space"][
"advanced"][
"quadrature_order"],
1113 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1116 else if (
args[
"space"][
"poly_basis_type"] ==
"Wachspress")
1123 args[
"space"][
"advanced"][
"quadrature_order"],
1124 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1132 args[
"space"][
"advanced"][
"n_harmonic_samples"],
1135 args[
"space"][
"advanced"][
"quadrature_order"],
1136 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1137 args[
"space"][
"advanced"][
"integral_constraints"],
1147 if (
mesh->is_volume())
1149 if (
args[
"space"][
"poly_basis_type"] ==
"MeanValue" ||
args[
"space"][
"poly_basis_type"] ==
"Wachspress")
1151 logger().error(
"Barycentric bases not supported in 3D");
1152 throw std::runtime_error(
"not implemented");
1159 args[
"space"][
"advanced"][
"n_harmonic_samples"],
1162 args[
"space"][
"advanced"][
"quadrature_order"],
1163 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1164 args[
"space"][
"advanced"][
"integral_constraints"],
1173 if (
args[
"space"][
"poly_basis_type"] ==
"MeanValue")
1179 n_bases,
args[
"space"][
"advanced"][
"quadrature_order"],
1180 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1183 else if (
args[
"space"][
"poly_basis_type"] ==
"Wachspress")
1189 n_bases,
args[
"space"][
"advanced"][
"quadrature_order"],
1190 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1198 args[
"space"][
"advanced"][
"n_harmonic_samples"],
1201 args[
"space"][
"advanced"][
"quadrature_order"],
1202 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1203 args[
"space"][
"advanced"][
"integral_constraints"],
1221 assert(!
mesh->is_volume());
1222 const int dim =
mesh->dimension();
1223 const int n_tiles = 2;
1225 if (
mesh->dimension() != 2)
1229 for (
const auto &bs :
bases)
1230 for (
const auto &b : bs.bases)
1231 for (
const auto &g : b.global())
1232 V.row(g.index) = g.node;
1235 for (
int i = 0; i < E.size(); i++)
1238 Eigen::MatrixXd bbox(
V.cols(), 2);
1239 bbox.col(0) =
V.colwise().minCoeff();
1240 bbox.col(1) =
V.colwise().maxCoeff();
1244 std::vector<int> ind;
1245 for (
int i = 0; i < E.rows(); i++)
1251 E = E(ind, Eigen::all).eval();
1254 Eigen::MatrixXd Vtmp, Vnew;
1255 Eigen::MatrixXi Etmp, Enew;
1256 Vtmp.setZero(
V.rows() * n_tiles * n_tiles,
V.cols());
1257 Etmp.setZero(E.rows() * n_tiles * n_tiles, E.cols());
1259 Eigen::MatrixXd tile_offset =
periodic_bc->get_affine_matrix();
1261 for (
int i = 0, idx = 0; i < n_tiles; i++)
1263 for (
int j = 0; j < n_tiles; j++)
1265 Eigen::Vector2d block_id;
1268 Vtmp.middleRows(idx *
V.rows(),
V.rows()) =
V;
1271 for (
int vid = 0; vid <
V.rows(); vid++)
1272 Vtmp.block(idx *
V.rows() + vid, 0, 1, 2) += (tile_offset * block_id).transpose();
1274 Etmp.middleRows(idx * E.rows(), E.rows()) = E.array() + idx *
V.rows();
1280 Eigen::VectorXi indices;
1282 std::vector<int> tmp;
1283 for (
int i = 0; i <
V.rows(); i++)
1289 indices.resize(tmp.size() * n_tiles * n_tiles);
1290 for (
int i = 0; i < n_tiles * n_tiles; i++)
1292 indices.segment(i * tmp.size(), tmp.size()) = Eigen::Map<Eigen::VectorXi, Eigen::Unaligned>(tmp.data(), tmp.size());
1293 indices.segment(i * tmp.size(), tmp.size()).array() += i *
V.rows();
1297 Eigen::VectorXi potentially_duplicate_mask(Vtmp.rows());
1298 potentially_duplicate_mask.setZero();
1299 potentially_duplicate_mask(indices).array() = 1;
1301 Eigen::MatrixXd candidates = Vtmp(indices, Eigen::all);
1303 Eigen::VectorXi SVI;
1304 std::vector<int> SVJ;
1305 SVI.setConstant(Vtmp.rows(), -1);
1307 const double eps = (bbox.col(1) - bbox.col(0)).maxCoeff() *
args[
"boundary_conditions"][
"periodic_boundary"][
"tolerance"].get<
double>();
1308 for (
int i = 0; i < Vtmp.rows(); i++)
1314 if (potentially_duplicate_mask(i))
1316 Eigen::VectorXd diffs = (candidates.rowwise() - Vtmp.row(i)).rowwise().norm();
1317 for (
int j = 0; j < diffs.size(); j++)
1319 SVI[indices[j]] =
id;
1325 Vnew = Vtmp(SVJ, Eigen::all);
1327 Enew.resizeLike(Etmp);
1328 for (
int d = 0; d < Etmp.cols(); d++)
1329 Enew.col(d) = SVI(Etmp.col(d));
1331 std::vector<bool> is_on_surface = ipc::CollisionMesh::construct_is_on_surface(Vnew.rows(), Enew);
1333 Eigen::MatrixXi boundary_triangles;
1334 Eigen::SparseMatrix<double> displacement_map;
1344 for (
int i = 0; i <
V.rows(); i++)
1345 for (
int j = 0; j < n_tiles * n_tiles; j++)
1363 const std::vector<basis::ElementBases> &bases,
1364 const std::vector<basis::ElementBases> &geom_bases,
1365 const std::vector<mesh::LocalBoundary> &total_local_boundary,
1368 const std::function<std::string(
const std::string &)> &resolve_input_path,
1369 const Eigen::VectorXi &in_node_to_node,
1370 ipc::CollisionMesh &collision_mesh)
1372 Eigen::MatrixXd collision_vertices;
1373 Eigen::VectorXi collision_codim_vids;
1374 Eigen::MatrixXi collision_edges, collision_triangles;
1375 std::vector<Eigen::Triplet<double>> displacement_map_entries;
1377 if (
args.contains(
"/contact/collision_mesh"_json_pointer)
1378 &&
args.at(
"/contact/collision_mesh/enabled"_json_pointer).get<
bool>())
1380 const json collision_mesh_args =
args.at(
"/contact/collision_mesh"_json_pointer);
1381 if (collision_mesh_args.contains(
"linear_map"))
1383 assert(displacement_map_entries.empty());
1384 assert(collision_mesh_args.contains(
"mesh"));
1385 const std::string
root_path = utils::json_value<std::string>(
args,
"root_path",
"");
1391 in_node_to_node, transformation, collision_vertices, collision_codim_vids,
1392 collision_edges, collision_triangles, displacement_map_entries);
1396 assert(collision_mesh_args.contains(
"max_edge_length"));
1398 "Building collision proxy with max edge length={} ...",
1399 collision_mesh_args[
"max_edge_length"].get<double>());
1404 collision_mesh_args[
"max_edge_length"], collision_vertices,
1405 collision_triangles, displacement_map_entries,
1406 collision_mesh_args[
"tessellation_type"]);
1407 if (collision_triangles.size())
1408 igl::edges(collision_triangles, collision_edges);
1410 logger().debug(fmt::format(
1411 std::locale(
"en_US.UTF-8"),
1412 "Done (took {:g}s, {:L} vertices, {:L} triangles)",
1413 timer.getElapsedTime(),
1414 collision_vertices.rows(), collision_triangles.rows()));
1421 collision_vertices, collision_edges, collision_triangles, displacement_map_entries);
1426 const int num_fe_collision_vertices = collision_vertices.rows();
1427 assert(collision_edges.size() == 0 || collision_edges.maxCoeff() < num_fe_collision_vertices);
1428 assert(collision_triangles.size() == 0 || collision_triangles.maxCoeff() < num_fe_collision_vertices);
1438 if (!displacement_map_entries.empty())
1440 displacement_map_entries.reserve(displacement_map_entries.size() +
obstacle.
n_vertices());
1443 displacement_map_entries.emplace_back(num_fe_collision_vertices + i, num_fe_nodes + i, 1.0);
1448 std::vector<bool> is_on_surface = ipc::CollisionMesh::construct_is_on_surface(
1449 collision_vertices.rows(), collision_edges);
1450 for (
const int vid : collision_codim_vids)
1452 is_on_surface[vid] =
true;
1455 Eigen::SparseMatrix<double> displacement_map;
1456 if (!displacement_map_entries.empty())
1458 displacement_map.resize(collision_vertices.rows(),
n_bases);
1459 displacement_map.setFromTriplets(displacement_map_entries.begin(), displacement_map_entries.end());
1463 is_on_surface, collision_vertices, collision_edges, collision_triangles,
1468 return collision_mesh.to_full_vertex_id(vi) < num_fe_collision_vertices
1469 ||
collision_mesh.to_full_vertex_id(vj) < num_fe_collision_vertices;
1479 logger().error(
"Load the mesh first!");
1484 logger().error(
"Build the bases first!");
1487 if (
assembler->name() ==
"OperatorSplitting")
1494 if (!
problem->is_time_dependent())
1505 logger().info(
"Assembling mass mat...");
1512 std::vector<Eigen::Triplet<double>> mass_blocks;
1513 mass_blocks.reserve(velocity_mass.nonZeros());
1515 for (
int k = 0; k < velocity_mass.outerSize(); ++k)
1517 for (StiffnessMatrix::InnerIterator it(velocity_mass, k); it; ++it)
1519 mass_blocks.emplace_back(it.row(), it.col(), it.value());
1524 mass.setFromTriplets(mass_blocks.begin(), mass_blocks.end());
1525 mass.makeCompressed();
1532 assert(
mass.size() > 0);
1535 for (
int k = 0; k <
mass.outerSize(); ++k)
1538 for (StiffnessMatrix::InnerIterator it(
mass, k); it; ++it)
1540 assert(it.col() == k);
1548 if (
args[
"solver"][
"advanced"][
"lump_mass_matrix"])
1565 const std::vector<basis::ElementBases> &bases_,
1568 json rhs_solver_params =
args[
"solver"][
"linear"];
1569 if (!rhs_solver_params.contains(
"Pardiso"))
1570 rhs_solver_params[
"Pardiso"] = {};
1571 rhs_solver_params[
"Pardiso"][
"mtype"] = -2;
1573 const int size =
problem->is_scalar() ? 1 :
mesh->dimension();
1575 return std::make_shared<RhsAssembler>(
1580 args[
"space"][
"advanced"][
"bc_method"],
1586 const std::vector<basis::ElementBases> &bases_)
const
1588 const int size =
problem->is_scalar() ? 1 :
mesh->dimension();
1590 return std::make_shared<PressureAssembler>(
1603 logger().error(
"Load the mesh first!");
1608 logger().error(
"Build the bases first!");
1615 p_params[
"formulation"] =
assembler->name();
1619 mesh->bounding_box(min, max);
1620 delta = (max - min) / 2. + min;
1621 if (
mesh->is_volume())
1622 p_params[
"bbox_center"] = {delta(0), delta(1), delta(2)};
1624 p_params[
"bbox_center"] = {delta(0), delta(1)};
1626 problem->set_parameters(p_params);
1631 logger().info(
"Assigning rhs...");
1640 const int prev_size =
rhs.size();
1642 rhs.conservativeResize(prev_size + n_larger,
rhs.cols());
1643 if (
assembler->name() ==
"OperatorSplitting")
1651 rhs.block(prev_size, 0, n_larger,
rhs.cols()).setZero();
1662 rhs.block(prev_size, 0, n_larger,
rhs.cols()) = tmp;
1675 logger().error(
"Load the mesh first!");
1680 logger().error(
"Build the bases first!");
1700 if (
problem->is_time_dependent())
1702 const double t0 =
args[
"time"][
"t0"];
1703 const int time_steps =
args[
"time"][
"time_steps"];
1704 const double dt =
args[
"time"][
"dt"];
1707 if (
args[
"output"][
"advanced"][
"save_time_sequence"])
1709 logger().info(
"Time sequence of simulation will be written to: \"{}\"",
1713 if (
assembler->name() ==
"NavierStokes")
1715 else if (
assembler->name() ==
"OperatorSplitting")
1722 throw std::runtime_error(
"Nonlinear scalar problems are not supported yet!");
1728 if (
assembler->name() ==
"NavierStokes")
1740 throw std::runtime_error(
"Nonlinear scalar problems are not supported yet!");
1749 if (!state_path.empty())
ElementAssemblyValues vals
DECLARE_DIFFSCALAR_BASE()
io::OutRuntimeData timings
runtime statistics
assembler::MacroStrainValue macro_strain_constraint
std::shared_ptr< utils::PeriodicBoundary > periodic_bc
periodic BC and periodic mesh utils
int n_bases
number of bases
void cache_transient_adjoint_quantities(const int current_step, const Eigen::MatrixXd &sol, const Eigen::MatrixXd &disp_grad)
int n_pressure_bases
number of pressure bases
std::string formulation() const
return the formulation (checks if the problem is scalar or not and deals with multiphysics)
assembler::AssemblyValsCache ass_vals_cache
used to store assembly values for small problems
int n_boundary_samples() const
quadrature used for projecting boundary conditions
const std::vector< basis::ElementBases > & geom_bases() const
Get a constant reference to the geometry mapping bases.
double starting_max_edge_length
std::vector< mesh::LocalBoundary > local_pressure_boundary
mapping from elements to nodes for pressure boundary conditions
void sol_to_pressure(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
splits the solution in solution and pressure for mixed problems
std::string root_path() const
Get the root path for the state (e.g., args["root_path"] or ".")
void assemble_mass_mat()
assemble mass, step 4 of solve build mass matrix based on defined basis modifies mass (and maybe more...
Eigen::VectorXi in_node_to_node
Inpute nodes (including high-order) to polyfem nodes, only for isoparametric.
void build_polygonal_basis()
builds bases for polygons, called inside build_basis
mesh::Obstacle obstacle
Obstacles used in collisions.
std::shared_ptr< assembler::Assembler > assembler
assemblers
ipc::CollisionMesh periodic_collision_mesh
IPC collision mesh under periodic BC.
void build_periodic_collision_mesh()
io::OutGeometryData out_geom
visualization stuff
bool use_avg_pressure
use average pressure for stokes problem to fix the additional dofs, true by default if false,...
std::string resolve_output_path(const std::string &path) const
Resolve output path relative to output_dir if the path is not absolute.
std::vector< int > neumann_nodes
per node neumann
ipc::CollisionMesh collision_mesh
IPC collision mesh.
std::vector< basis::ElementBases > geom_bases_
Geometric mapping bases, if the elements are isoparametric, this list is empty.
solver::CacheLevel optimization_enabled
Eigen::VectorXi in_primitive_to_primitive
maps in vertices/edges/faces/cells to polyfem vertices/edges/faces/cells
std::map< int, basis::InterfaceData > poly_edge_to_data
nodes on the boundary of polygonal elements, used for harmonic bases
std::vector< int > pressure_boundary_nodes
list of neumann boundary nodes
std::vector< basis::ElementBases > pressure_bases
FE pressure bases for mixed elements, the size is #elements.
bool is_homogenization() const
void solve_transient_tensor_nonlinear(const int time_steps, const double t0, const double dt, Eigen::MatrixXd &sol)
solves transient tensor nonlinear problem
double starting_min_edge_length
std::shared_ptr< assembler::Mass > mass_matrix_assembler
void build_node_mapping()
build the mapping from input nodes to polyfem nodes
std::vector< int > primitive_to_node() const
bool has_dhat
stores if input json contains dhat
std::shared_ptr< polyfem::mesh::MeshNodes > pressure_mesh_nodes
std::unique_ptr< mesh::Mesh > mesh
current mesh, it can be a Mesh2D or Mesh3D
std::shared_ptr< polyfem::mesh::MeshNodes > mesh_nodes
Mapping from input nodes to FE nodes.
StiffnessMatrix mass
Mass matrix, it is computed only for time dependent problems.
void solve_homogenization(const int time_steps, const double t0, const double dt, Eigen::MatrixXd &sol)
std::vector< int > dirichlet_nodes
per node dirichlet
bool has_periodic_bc() const
void solve_problem(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
solves the problems
void build_basis()
builds the bases step 2 of solve modifies bases, pressure_bases, geom_bases_, boundary_nodes,...
void solve_navier_stokes(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
solves a navier stokes
std::shared_ptr< assembler::Problem > problem
current problem, it contains rhs and bc
std::vector< RowVectorNd > dirichlet_nodes_position
std::map< int, std::pair< Eigen::MatrixXd, Eigen::MatrixXi > > polys_3d
polyhedra, used since poly have no geom mapping
std::vector< int > node_to_primitive() const
json args
main input arguments containing all defaults
io::OutStatsData stats
Other statistics.
std::vector< RowVectorNd > neumann_nodes_position
void assemble_rhs()
compute rhs, step 3 of solve build rhs vector based on defined basis and given rhs of the problem mod...
double min_boundary_edge_length
Eigen::VectorXi periodic_collision_mesh_to_basis
index mapping from periodic 2x2 collision mesh to FE periodic mesh
std::vector< basis::ElementBases > bases
FE bases, the size is #elements.
void solve_transient_navier_stokes_split(const int time_steps, const double dt, Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
solves transient navier stokes with operator splitting
int n_geom_bases
number of geometric bases
assembler::AssemblyValsCache pressure_ass_vals_cache
used to store assembly values for pressure for small problems
std::vector< mesh::LocalBoundary > local_boundary
mapping from elements to nodes for dirichlet boundary conditions
double avg_mass
average system mass, used for contact with IPC
bool iso_parametric() const
check if using iso parametric bases
std::shared_ptr< assembler::RhsAssembler > build_rhs_assembler() const
build a RhsAssembler for the problem
std::vector< mesh::LocalBoundary > total_local_boundary
mapping from elements to nodes for all mesh
void solve_transient_navier_stokes(const int time_steps, const double t0, const double dt, Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
solves transient navier stokes with FEM
void init_solve(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
initialize solver
void init_linear_solve(Eigen::MatrixXd &sol, const double t=1.0)
initialize the linear solve
assembler::AssemblyValsCache mass_ass_vals_cache
void solve_tensor_nonlinear(Eigen::MatrixXd &sol, const int t=0, const bool init_lagging=true)
solves nonlinear problems
std::string resolve_input_path(const std::string &path, const bool only_if_exists=false) const
Resolve input path relative to root_path() if the path is not absolute.
std::vector< int > boundary_nodes
list of boundary nodes
solver::SolveData solve_data
timedependent stuff cached
std::shared_ptr< polyfem::mesh::MeshNodes > geom_mesh_nodes
void solve_linear(Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
solves a linear problem
void init_nonlinear_tensor_solve(Eigen::MatrixXd &sol, const double t=1.0, const bool init_time_integrator=true)
initialize the nonlinear solver
bool is_contact_enabled() const
does the simulation has contact
void build_collision_mesh()
extracts the boundary mesh for collision, called in build_basis
Eigen::VectorXi disc_orders
vector of discretization orders, used when not all elements have the same degree, one per element
std::vector< mesh::LocalBoundary > local_neumann_boundary
mapping from elements to nodes for neumann boundary conditions
std::shared_ptr< assembler::PressureAssembler > build_pressure_assembler() const
void solve_transient_linear(const int time_steps, const double t0, const double dt, Eigen::MatrixXd &sol, Eigen::MatrixXd &pressure)
solves transient linear problem
bool is_problem_linear() const
Returns whether the system is linear. Collisions and pressure add nonlinearity to the problem.
std::shared_ptr< assembler::MixedAssembler > mixed_assembler
std::map< int, Eigen::MatrixXd > polys
polygons, used since poly have no geom mapping
Eigen::MatrixXd rhs
System right-hand side.
std::unordered_map< int, std::vector< mesh::LocalBoundary > > local_pressure_cavity
mapping from elements to nodes for pressure boundary conditions
StiffnessMatrix basis_nodes_to_gbasis_nodes
std::string velocity() const
static double convert(const json &val, const std::string &unit_type)
const std::string & length() const
Caches basis evaluation and geometric mapping at every element.
void init(const bool is_volume, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const bool is_mass=false)
computes the basis evaluation and geometric mapping for each of the given ElementBases in bases initi...
stores per local bases evaluations
std::vector< basis::Local2Global > global
stores per element basis values at given quadrature points and geometric mapping
std::vector< AssemblyValues > basis_values
void compute(const int el_index, const bool is_volume, const Eigen::MatrixXd &pts, const basis::ElementBases &basis, const basis::ElementBases &gbasis)
computes the per element values at the local (ref el) points (pts) sets basis_values,...
quadrature::Quadrature quadrature
assemble matrix based on the local assembler local assembler is eg Laplace, LinearElasticity etc
void init(const int dim, const json ¶m)
static int build_bases(const mesh::Mesh2D &mesh, const std::string &assembler, const int quadrature_order, const int mass_quadrature_order, const int discr_order, const bool serendipity, const bool has_polys, const bool is_geom_bases, std::vector< ElementBases > &bases, std::vector< mesh::LocalBoundary > &local_boundary, std::map< int, InterfaceData > &poly_edge_to_data, std::shared_ptr< mesh::MeshNodes > &mesh_nodes)
Builds FE basis functions over the entire mesh (P1, P2 over triangles, Q1, Q2 over quads).
static int build_bases(const mesh::Mesh3D &mesh, const std::string &assembler, const int quadrature_order, const int mass_quadrature_order, const int discr_order, const bool serendipity, const bool has_polys, const bool is_geom_bases, std::vector< ElementBases > &bases, std::vector< mesh::LocalBoundary > &local_boundary, std::map< int, InterfaceData > &poly_face_to_data, std::shared_ptr< mesh::MeshNodes > &mesh_nodes)
Builds FE basis functions over the entire mesh (P1, P2 over tets, Q1, Q2 over hes).
static int build_bases(const std::string &assembler_name, const int dim, const mesh::Mesh2D &mesh, const int n_bases, const int quadrature_order, const int mass_quadrature_order, std::vector< ElementBases > &bases, std::vector< mesh::LocalBoundary > &local_boundary, std::map< int, Eigen::MatrixXd > &mapped_boundary)
static int build_bases(const assembler::LinearAssembler &assembler, const int n_samples_per_edge, const mesh::Mesh2D &mesh, const int n_bases, const int quadrature_order, const int mass_quadrature_order, const int integral_constraints, std::vector< ElementBases > &bases, const std::vector< ElementBases > &gbases, const std::map< int, InterfaceData > &poly_edge_to_data, std::map< int, Eigen::MatrixXd > &mapped_boundary)
Build bases over the remaining polygons of a mesh.
static int build_bases(const assembler::LinearAssembler &assembler, const int n_samples_per_edge, const mesh::Mesh3D &mesh, const int n_bases, const int quadrature_order, const int mass_quadrature_order, const int integral_constraints, std::vector< ElementBases > &bases, const std::vector< ElementBases > &gbases, const std::map< int, InterfaceData > &poly_face_to_data, std::map< int, std::pair< Eigen::MatrixXd, Eigen::MatrixXi > > &mapped_boundary)
Build bases over the remaining polygons of a mesh.
static int build_bases(const mesh::Mesh2D &mesh, const std::string &assembler, const int quadrature_order, const int mass_quadrature_order, std::vector< ElementBases > &bases, std::vector< mesh::LocalBoundary > &local_boundary, std::map< int, InterfaceData > &poly_edge_to_data)
static int build_bases(const mesh::Mesh3D &mesh, const std::string &assembler, const int quadrature_order, const int mass_quadrature_order, std::vector< ElementBases > &bases, std::vector< mesh::LocalBoundary > &local_boundary, std::map< int, InterfaceData > &poly_face_to_data)
static int build_bases(const std::string &assembler_name, const int dim, const mesh::Mesh2D &mesh, const int n_bases, const int quadrature_order, const int mass_quadrature_order, std::vector< ElementBases > &bases, std::vector< mesh::LocalBoundary > &local_boundary, std::map< int, Eigen::MatrixXd > &mapped_boundary)
void build_grid(const polyfem::mesh::Mesh &mesh, const double spacing)
builds the grid to export the solution
static void extract_boundary_mesh(const mesh::Mesh &mesh, const int n_bases, const std::vector< basis::ElementBases > &bases, const std::vector< mesh::LocalBoundary > &total_local_boundary, Eigen::MatrixXd &node_positions, Eigen::MatrixXi &boundary_edges, Eigen::MatrixXi &boundary_triangles, std::vector< Eigen::Triplet< double > > &displacement_map_entries)
extracts the boundary mesh
double assembling_stiffness_mat_time
time to assembly
double assigning_rhs_time
time to computing the rhs
double assembling_mass_mat_time
time to assembly mass
double building_basis_time
time to construct the basis
double solving_time
time to solve
double computing_poly_basis_time
time to build the polygonal/polyhedral bases
int n_flipped
number of flipped elements, compute only when using count_flipped_els (false by default)
Eigen::Vector4d spectrum
spectrum of the stiffness matrix, enable only if POLYSOLVE_WITH_SPECTRA is ON (off by default)
void count_flipped_elements(const polyfem::mesh::Mesh &mesh, const std::vector< polyfem::basis::ElementBases > &gbases)
counts the number of flipped elements
void compute_mesh_size(const polyfem::mesh::Mesh &mesh_in, const std::vector< polyfem::basis::ElementBases > &bases_in, const int n_samples, const bool use_curved_mesh_size)
computes the mesh size, it samples every edges n_samples times uses curved_mesh_size (false by defaul...
long long nn_zero
non zeros and sytem matrix size num dof is the total dof in the system
double mesh_size
max edge lenght
void reset()
clears all stats
double min_edge_length
min edge lenght
bool is_volume() const override
checks if mesh is volume
Abstract mesh class to capture 2d/3d conforming and non-conforming meshes.
int n_elements() const
utitlity to return the number of elements, cells or faces in 3d and 2d
const Eigen::MatrixXi & e() const
const Eigen::MatrixXi & f() const
const Eigen::MatrixXd & v() const
const Eigen::VectorXi & codim_v() const
static void p_refine(const mesh::Mesh &mesh, const double B, const bool h1_formula, const int base_p, const int discr_order_max, io::OutStatsData &stats, Eigen::VectorXi &disc_orders)
compute a priori prefinement
std::shared_ptr< assembler::RhsAssembler > rhs_assembler
void q_nodes_2d(const int q, Eigen::MatrixXd &val)
void p_nodes_2d(const int p, Eigen::MatrixXd &val)
void p_nodes_3d(const int p, Eigen::MatrixXd &val)
void q_nodes_3d(const int q, Eigen::MatrixXd &val)
bool read_matrix(const std::string &path, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &mat)
Reads a matrix from a file. Determines the file format based on the path's extension.
bool write_matrix(const std::string &path, const Mat &mat)
Writes a matrix to a file. Determines the file format based on the path's extension.
void load_collision_proxy(const std::string &mesh_filename, const std::string &weights_filename, const Eigen::VectorXi &in_node_to_node, const json &transformation, Eigen::MatrixXd &vertices, Eigen::VectorXi &codim_vertices, Eigen::MatrixXi &edges, Eigen::MatrixXi &faces, std::vector< Eigen::Triplet< double > > &displacement_map_entries)
Load a collision proxy mesh and displacement map from files.
void build_collision_proxy(const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &geom_bases, const std::vector< LocalBoundary > &total_local_boundary, const int n_bases, const int dim, const double max_edge_length, Eigen::MatrixXd &proxy_vertices, Eigen::MatrixXi &proxy_faces, std::vector< Eigen::Triplet< double > > &displacement_map_entries, const CollisionProxyTessellation tessellation)
Eigen::SparseMatrix< double > lump_matrix(const Eigen::SparseMatrix< double > &M)
Lump each row of a matrix into the diagonal.
std::string resolve_path(const std::string &path, const std::string &input_file_path, const bool only_if_exists=false)
std::vector< T > json_as_array(const json &j)
Return the value of a json object as an array.
void append_rows(DstMat &dst, const SrcMat &src)
spdlog::logger & logger()
Retrieves the current logger.
void compute_integral_constraints(const Mesh3D &mesh, const int n_bases, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, Eigen::MatrixXd &basis_integrals)
Eigen::Matrix< double, Eigen::Dynamic, 1, 0, 3, 1 > VectorNd
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
void log_and_throw_error(const std::string &msg)
Eigen::SparseMatrix< double, Eigen::ColMajor > StiffnessMatrix