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 if (!
mesh->is_simplicial())
635 args[
"space"][
"advanced"][
"count_flipped_els_continuous"] =
false;
636 args[
"output"][
"paraview"][
"options"][
"jacobian_validity"] =
false;
637 args[
"solver"][
"advanced"][
"check_inversion"] =
"Discrete";
639 else if (
args[
"solver"][
"advanced"][
"check_inversion"] !=
"Discrete")
641 args[
"space"][
"advanced"][
"use_corner_quadrature"] =
true;
644 Eigen::MatrixXi geom_disc_orders;
647 if (
mesh->orders().size() <= 0)
650 geom_disc_orders.setConstant(1);
653 geom_disc_orders =
mesh->orders();
658 if (
args[
"space"][
"use_p_ref"])
662 args[
"space"][
"advanced"][
"B"],
663 args[
"space"][
"advanced"][
"h1_formula"],
664 args[
"space"][
"discr_order"],
665 args[
"space"][
"advanced"][
"discr_order_max"],
672 int quadrature_order =
args[
"space"][
"advanced"][
"quadrature_order"].get<
int>();
673 const int mass_quadrature_order =
args[
"space"][
"advanced"][
"mass_quadrature_order"].get<
int>();
679 logger().error(
"p refinement not supported in mixed formulation!");
686 const bool use_continuous_gbasis =
true;
687 const bool use_corner_quadrature =
args[
"space"][
"advanced"][
"use_corner_quadrature"];
689 if (
mesh->is_volume())
692 if (
args[
"space"][
"basis_type"] ==
"Spline")
709 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, use_corner_quadrature,
geom_bases_,
local_boundary, poly_edge_to_data_geom,
geom_mesh_nodes);
711 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, use_corner_quadrature,
bases,
local_boundary,
poly_edge_to_data,
mesh_nodes);
717 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, use_corner_quadrature,
pressure_bases,
local_boundary, poly_edge_to_data_geom,
pressure_mesh_nodes);
723 if (
args[
"space"][
"basis_type"] ==
"Spline")
741 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, use_corner_quadrature,
geom_bases_,
local_boundary, poly_edge_to_data_geom,
geom_mesh_nodes);
743 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, use_corner_quadrature,
bases,
local_boundary,
poly_edge_to_data,
mesh_nodes);
749 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, use_corner_quadrature,
pressure_bases,
local_boundary, poly_edge_to_data_geom,
pressure_mesh_nodes);
759 bases[i].compute_quadrature(b_quad);
775 std::map<std::array<int, 2>,
double> pairs;
776 for (
int e = 0; e < gbases.size(); e++)
778 const auto &gbs = gbases[e].bases;
779 const auto &bs =
bases[e].bases;
781 Eigen::MatrixXd local_pts;
782 const int order = bs.front().order();
783 if (
mesh->is_volume())
785 if (
mesh->is_simplex(e))
792 if (
mesh->is_simplex(e))
801 for (
int i = 0; i < bs.size(); i++)
803 for (
int j = 0; j < gbs.size(); j++)
805 if (std::abs(
vals.basis_values[j].val(i)) > 1e-7)
807 std::array<int, 2> index = {{gbs[j].global()[0].index, bs[i].global()[0].index}};
808 pairs.insert({index,
vals.basis_values[j].val(i)});
814 const int dim =
mesh->dimension();
815 std::vector<Eigen::Triplet<double>> coeffs;
817 for (
const auto &iter : pairs)
818 for (
int d = 0; d < dim; d++)
819 coeffs.emplace_back(iter.first[0] * dim + d, iter.first[1] * dim + d, iter.second);
828 const int dim =
mesh->dimension();
829 const int problem_dim =
problem->is_scalar() ? 1 : dim;
835 json directions =
args[
"boundary_conditions"][
"periodic_boundary"][
"correspondence"];
836 Eigen::MatrixXd tile_offset = Eigen::MatrixXd::Identity(dim, dim);
838 if (directions.size() > 0)
841 for (
int d = 0; d < dim; d++)
844 if (tmp.size() != dim)
846 tile_offset.col(d) = tmp;
855 if (
args[
"space"][
"advanced"][
"count_flipped_els"])
858 const int prev_bases =
n_bases;
863 logger().debug(
"Building node mapping...");
869 logger().debug(
"Done (took {}s)", timer2.getElapsedTime());
872 logger().info(
"Building collision mesh...");
896 for (
const auto &bs :
bases)
898 for (
const auto &b : bs.bases)
900 for (
const auto &lg : b.global())
902 if (lg.index == n_id)
926 for (
const auto &bs :
bases)
928 for (
const auto &b : bs.bases)
930 for (
const auto &lg : b.global())
932 if (lg.index == n_id)
955 for (
int i = prev_bases; i <
n_bases; ++i)
957 for (
int d = 0; d < problem_dim; ++d)
969 std::vector<bool> isboundary(
n_bases,
false);
972 const int e = lb.element_id();
973 for (
int i = 0; i < lb.size(); ++i)
975 const auto nodes =
bases[e].local_nodes_for_primitive(lb.global_primitive_id(i), *
mesh);
978 isboundary[
bases[e].
bases[n].global()[0].index] =
true;
987 const int actual_dim =
problem->is_scalar() ? 1 :
mesh->dimension();
988 for (
int d = 0; d < actual_dim; d++)
992 logger().info(
"Fix solution at node {} to remove singularity due to periodic BC", i);
996 const int n_samples = 10;
1019 args[
"contact"][
"dhat"] = dhat;
1024 logger().info(
"dhat set to {}",
double(
args[
"contact"][
"dhat"]));
1045 if (
n_bases <=
args[
"solver"][
"advanced"][
"cache_size"])
1048 logger().info(
"Building cache...");
1054 logger().info(
" took {}s", timer.getElapsedTime());
1062 logger().warn(
"(Quasi-)Static problem without Dirichlet nodes, will fix solution at one node to find a unique solution!");
1072 logger().error(
"Load the mesh first!");
1086 logger().info(
"Computing polygonal basis...");
1097 if (
mesh->is_volume())
1099 if (
args[
"space"][
"poly_basis_type"] ==
"MeanValue" ||
args[
"space"][
"poly_basis_type"] ==
"Wachspress")
1100 logger().error(
"Barycentric bases not supported in 3D");
1104 args[
"space"][
"advanced"][
"n_harmonic_samples"],
1107 args[
"space"][
"advanced"][
"quadrature_order"],
1108 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1109 args[
"space"][
"advanced"][
"integral_constraints"],
1117 if (
args[
"space"][
"poly_basis_type"] ==
"MeanValue")
1124 args[
"space"][
"advanced"][
"quadrature_order"],
1125 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1128 else if (
args[
"space"][
"poly_basis_type"] ==
"Wachspress")
1135 args[
"space"][
"advanced"][
"quadrature_order"],
1136 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1144 args[
"space"][
"advanced"][
"n_harmonic_samples"],
1147 args[
"space"][
"advanced"][
"quadrature_order"],
1148 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1149 args[
"space"][
"advanced"][
"integral_constraints"],
1159 if (
mesh->is_volume())
1161 if (
args[
"space"][
"poly_basis_type"] ==
"MeanValue" ||
args[
"space"][
"poly_basis_type"] ==
"Wachspress")
1163 logger().error(
"Barycentric bases not supported in 3D");
1164 throw std::runtime_error(
"not implemented");
1171 args[
"space"][
"advanced"][
"n_harmonic_samples"],
1174 args[
"space"][
"advanced"][
"quadrature_order"],
1175 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1176 args[
"space"][
"advanced"][
"integral_constraints"],
1185 if (
args[
"space"][
"poly_basis_type"] ==
"MeanValue")
1191 n_bases,
args[
"space"][
"advanced"][
"quadrature_order"],
1192 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1195 else if (
args[
"space"][
"poly_basis_type"] ==
"Wachspress")
1201 n_bases,
args[
"space"][
"advanced"][
"quadrature_order"],
1202 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1210 args[
"space"][
"advanced"][
"n_harmonic_samples"],
1213 args[
"space"][
"advanced"][
"quadrature_order"],
1214 args[
"space"][
"advanced"][
"mass_quadrature_order"],
1215 args[
"space"][
"advanced"][
"integral_constraints"],
1233 assert(!
mesh->is_volume());
1234 const int dim =
mesh->dimension();
1235 const int n_tiles = 2;
1237 if (
mesh->dimension() != 2)
1241 for (
const auto &bs :
bases)
1242 for (
const auto &b : bs.bases)
1243 for (
const auto &g : b.global())
1244 V.row(g.index) = g.node;
1247 for (
int i = 0; i < E.size(); i++)
1250 Eigen::MatrixXd bbox(
V.cols(), 2);
1251 bbox.col(0) =
V.colwise().minCoeff();
1252 bbox.col(1) =
V.colwise().maxCoeff();
1256 std::vector<int> ind;
1257 for (
int i = 0; i < E.rows(); i++)
1263 E = E(ind, Eigen::all).eval();
1266 Eigen::MatrixXd Vtmp, Vnew;
1267 Eigen::MatrixXi Etmp, Enew;
1268 Vtmp.setZero(
V.rows() * n_tiles * n_tiles,
V.cols());
1269 Etmp.setZero(E.rows() * n_tiles * n_tiles, E.cols());
1271 Eigen::MatrixXd tile_offset =
periodic_bc->get_affine_matrix();
1273 for (
int i = 0, idx = 0; i < n_tiles; i++)
1275 for (
int j = 0; j < n_tiles; j++)
1277 Eigen::Vector2d block_id;
1280 Vtmp.middleRows(idx *
V.rows(),
V.rows()) =
V;
1283 for (
int vid = 0; vid <
V.rows(); vid++)
1284 Vtmp.block(idx *
V.rows() + vid, 0, 1, 2) += (tile_offset * block_id).transpose();
1286 Etmp.middleRows(idx * E.rows(), E.rows()) = E.array() + idx *
V.rows();
1292 Eigen::VectorXi indices;
1294 std::vector<int> tmp;
1295 for (
int i = 0; i <
V.rows(); i++)
1301 indices.resize(tmp.size() * n_tiles * n_tiles);
1302 for (
int i = 0; i < n_tiles * n_tiles; i++)
1304 indices.segment(i * tmp.size(), tmp.size()) = Eigen::Map<Eigen::VectorXi, Eigen::Unaligned>(tmp.data(), tmp.size());
1305 indices.segment(i * tmp.size(), tmp.size()).array() += i *
V.rows();
1309 Eigen::VectorXi potentially_duplicate_mask(Vtmp.rows());
1310 potentially_duplicate_mask.setZero();
1311 potentially_duplicate_mask(indices).array() = 1;
1313 Eigen::MatrixXd candidates = Vtmp(indices, Eigen::all);
1315 Eigen::VectorXi SVI;
1316 std::vector<int> SVJ;
1317 SVI.setConstant(Vtmp.rows(), -1);
1319 const double eps = (bbox.col(1) - bbox.col(0)).maxCoeff() *
args[
"boundary_conditions"][
"periodic_boundary"][
"tolerance"].get<
double>();
1320 for (
int i = 0; i < Vtmp.rows(); i++)
1326 if (potentially_duplicate_mask(i))
1328 Eigen::VectorXd diffs = (candidates.rowwise() - Vtmp.row(i)).rowwise().norm();
1329 for (
int j = 0; j < diffs.size(); j++)
1331 SVI[indices[j]] =
id;
1337 Vnew = Vtmp(SVJ, Eigen::all);
1339 Enew.resizeLike(Etmp);
1340 for (
int d = 0; d < Etmp.cols(); d++)
1341 Enew.col(d) = SVI(Etmp.col(d));
1343 std::vector<bool> is_on_surface = ipc::CollisionMesh::construct_is_on_surface(Vnew.rows(), Enew);
1345 Eigen::MatrixXi boundary_triangles;
1346 Eigen::SparseMatrix<double> displacement_map;
1356 for (
int i = 0; i <
V.rows(); i++)
1357 for (
int j = 0; j < n_tiles * n_tiles; j++)
1375 const std::vector<basis::ElementBases> &bases,
1376 const std::vector<basis::ElementBases> &geom_bases,
1377 const std::vector<mesh::LocalBoundary> &total_local_boundary,
1380 const std::function<std::string(
const std::string &)> &resolve_input_path,
1381 const Eigen::VectorXi &in_node_to_node,
1382 ipc::CollisionMesh &collision_mesh)
1384 Eigen::MatrixXd collision_vertices;
1385 Eigen::VectorXi collision_codim_vids;
1386 Eigen::MatrixXi collision_edges, collision_triangles;
1387 std::vector<Eigen::Triplet<double>> displacement_map_entries;
1389 if (
args.contains(
"/contact/collision_mesh"_json_pointer)
1390 &&
args.at(
"/contact/collision_mesh/enabled"_json_pointer).get<
bool>())
1392 const json collision_mesh_args =
args.at(
"/contact/collision_mesh"_json_pointer);
1393 if (collision_mesh_args.contains(
"linear_map"))
1395 assert(displacement_map_entries.empty());
1396 assert(collision_mesh_args.contains(
"mesh"));
1397 const std::string
root_path = utils::json_value<std::string>(
args,
"root_path",
"");
1403 in_node_to_node, transformation, collision_vertices, collision_codim_vids,
1404 collision_edges, collision_triangles, displacement_map_entries);
1408 assert(collision_mesh_args.contains(
"max_edge_length"));
1410 "Building collision proxy with max edge length={} ...",
1411 collision_mesh_args[
"max_edge_length"].get<double>());
1416 collision_mesh_args[
"max_edge_length"], collision_vertices,
1417 collision_triangles, displacement_map_entries,
1418 collision_mesh_args[
"tessellation_type"]);
1419 if (collision_triangles.size())
1420 igl::edges(collision_triangles, collision_edges);
1422 logger().debug(fmt::format(
1423 std::locale(
"en_US.UTF-8"),
1424 "Done (took {:g}s, {:L} vertices, {:L} triangles)",
1425 timer.getElapsedTime(),
1426 collision_vertices.rows(), collision_triangles.rows()));
1433 collision_vertices, collision_edges, collision_triangles, displacement_map_entries);
1438 const int num_fe_collision_vertices = collision_vertices.rows();
1439 assert(collision_edges.size() == 0 || collision_edges.maxCoeff() < num_fe_collision_vertices);
1440 assert(collision_triangles.size() == 0 || collision_triangles.maxCoeff() < num_fe_collision_vertices);
1450 if (!displacement_map_entries.empty())
1452 displacement_map_entries.reserve(displacement_map_entries.size() +
obstacle.
n_vertices());
1455 displacement_map_entries.emplace_back(num_fe_collision_vertices + i, num_fe_nodes + i, 1.0);
1460 std::vector<bool> is_on_surface = ipc::CollisionMesh::construct_is_on_surface(
1461 collision_vertices.rows(), collision_edges);
1462 for (
const int vid : collision_codim_vids)
1464 is_on_surface[vid] =
true;
1467 Eigen::SparseMatrix<double> displacement_map;
1468 if (!displacement_map_entries.empty())
1470 displacement_map.resize(collision_vertices.rows(),
n_bases);
1471 displacement_map.setFromTriplets(displacement_map_entries.begin(), displacement_map_entries.end());
1475 is_on_surface, collision_vertices, collision_edges, collision_triangles,
1480 return collision_mesh.to_full_vertex_id(vi) < num_fe_collision_vertices
1481 ||
collision_mesh.to_full_vertex_id(vj) < num_fe_collision_vertices;
1491 logger().error(
"Load the mesh first!");
1496 logger().error(
"Build the bases first!");
1499 if (
assembler->name() ==
"OperatorSplitting")
1506 if (!
problem->is_time_dependent())
1517 logger().info(
"Assembling mass mat...");
1524 std::vector<Eigen::Triplet<double>> mass_blocks;
1525 mass_blocks.reserve(velocity_mass.nonZeros());
1527 for (
int k = 0; k < velocity_mass.outerSize(); ++k)
1529 for (StiffnessMatrix::InnerIterator it(velocity_mass, k); it; ++it)
1531 mass_blocks.emplace_back(it.row(), it.col(), it.value());
1536 mass.setFromTriplets(mass_blocks.begin(), mass_blocks.end());
1537 mass.makeCompressed();
1544 assert(
mass.size() > 0);
1547 for (
int k = 0; k <
mass.outerSize(); ++k)
1550 for (StiffnessMatrix::InnerIterator it(
mass, k); it; ++it)
1552 assert(it.col() == k);
1560 if (
args[
"solver"][
"advanced"][
"lump_mass_matrix"])
1577 const std::vector<basis::ElementBases> &bases_,
1580 json rhs_solver_params =
args[
"solver"][
"linear"];
1581 if (!rhs_solver_params.contains(
"Pardiso"))
1582 rhs_solver_params[
"Pardiso"] = {};
1583 rhs_solver_params[
"Pardiso"][
"mtype"] = -2;
1585 const int size =
problem->is_scalar() ? 1 :
mesh->dimension();
1587 return std::make_shared<RhsAssembler>(
1592 args[
"space"][
"advanced"][
"bc_method"],
1598 const std::vector<basis::ElementBases> &bases_)
const
1600 const int size =
problem->is_scalar() ? 1 :
mesh->dimension();
1602 return std::make_shared<PressureAssembler>(
1615 logger().error(
"Load the mesh first!");
1620 logger().error(
"Build the bases first!");
1627 p_params[
"formulation"] =
assembler->name();
1631 mesh->bounding_box(min, max);
1632 delta = (max - min) / 2. + min;
1633 if (
mesh->is_volume())
1634 p_params[
"bbox_center"] = {delta(0), delta(1), delta(2)};
1636 p_params[
"bbox_center"] = {delta(0), delta(1)};
1638 problem->set_parameters(p_params);
1643 logger().info(
"Assigning rhs...");
1652 const int prev_size =
rhs.size();
1654 rhs.conservativeResize(prev_size + n_larger,
rhs.cols());
1655 if (
assembler->name() ==
"OperatorSplitting")
1663 rhs.block(prev_size, 0, n_larger,
rhs.cols()).setZero();
1674 rhs.block(prev_size, 0, n_larger,
rhs.cols()) = tmp;
1687 logger().error(
"Load the mesh first!");
1692 logger().error(
"Build the bases first!");
1712 if (
problem->is_time_dependent())
1714 const double t0 =
args[
"time"][
"t0"];
1715 const int time_steps =
args[
"time"][
"time_steps"];
1716 const double dt =
args[
"time"][
"dt"];
1719 if (
args[
"output"][
"advanced"][
"save_time_sequence"])
1721 logger().info(
"Time sequence of simulation will be written to: \"{}\"",
1725 if (
assembler->name() ==
"NavierStokes")
1727 else if (
assembler->name() ==
"OperatorSplitting")
1734 throw std::runtime_error(
"Nonlinear scalar problems are not supported yet!");
1740 if (
assembler->name() ==
"NavierStokes")
1752 throw std::runtime_error(
"Nonlinear scalar problems are not supported yet!");
1761 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, const bool use_corner_quadrature, 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, const bool use_corner_quadrature, 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