19 void scaled_jacobian(
const Eigen::MatrixXd &
V,
const Eigen::MatrixXi &
F, Eigen::VectorXd &quality)
21 const int dim =
F.cols() - 1;
23 quality.setZero(
F.rows());
26 for (
int i = 0; i <
F.rows(); i++)
28 Eigen::RowVector3d e0;
30 e0.head(2) =
V.row(
F(i, 2)) -
V.row(
F(i, 1));
31 Eigen::RowVector3d e1;
33 e1.head(2) =
V.row(
F(i, 0)) -
V.row(
F(i, 2));
34 Eigen::RowVector3d e2;
36 e2.head(2) =
V.row(
F(i, 1)) -
V.row(
F(i, 0));
38 double l0 = e0.norm();
39 double l1 = e1.norm();
40 double l2 = e2.norm();
42 double A = 0.5 * (e0.cross(e1)).
norm();
43 double Lmax = std::max(l0 * l1, std::max(l1 * l2, l0 * l2));
45 quality(i) = 2 * A * (2 / sqrt(3)) / Lmax;
50 for (
int i = 0; i <
F.rows(); i++)
52 Eigen::RowVector3d e0 =
V.row(
F(i, 1)) -
V.row(
F(i, 0));
53 Eigen::RowVector3d e1 =
V.row(
F(i, 2)) -
V.row(
F(i, 1));
54 Eigen::RowVector3d e2 =
V.row(
F(i, 0)) -
V.row(
F(i, 2));
55 Eigen::RowVector3d e3 =
V.row(
F(i, 3)) -
V.row(
F(i, 0));
56 Eigen::RowVector3d e4 =
V.row(
F(i, 3)) -
V.row(
F(i, 1));
57 Eigen::RowVector3d e5 =
V.row(
F(i, 3)) -
V.row(
F(i, 2));
59 double l0 = e0.norm();
60 double l1 = e1.norm();
61 double l2 = e2.norm();
62 double l3 = e3.norm();
63 double l4 = e4.norm();
64 double l5 = e5.norm();
66 double J = std::abs((e0.cross(e3)).dot(e2));
68 double a1 = l0 * l2 * l3;
69 double a2 = l0 * l1 * l4;
70 double a3 = l1 * l2 * l5;
71 double a4 = l3 * l4 * l5;
73 double a = std::max({a1, a2, a3, a4, J});
74 quality(i) = J * sqrt(2) / a;
82 const bool is_volume =
state_.
mesh->is_volume();
83 double min_jacs = std::numeric_limits<double>::max();
90 const int n_local_bases = int(gbasis.bases.size());
93 gbasis.compute_quadrature(quad);
95 std::vector<assembler::AssemblyValues> tmp;
97 Eigen::MatrixXd dx = Eigen::MatrixXd::Zero(quad.
points.rows(), quad.
points.cols());
98 Eigen::MatrixXd dy = Eigen::MatrixXd::Zero(quad.
points.rows(), quad.
points.cols());
101 dz = Eigen::MatrixXd::Zero(quad.
points.rows(), quad.
points.cols());
103 gbasis.evaluate_grads(quad.
points, tmp);
105 for (
int j = 0; j < n_local_bases; ++j)
109 for (std::size_t ii = 0; ii < b.global().size(); ++ii)
111 dx += tmp[j].grad.col(0) * b.global()[ii].node * b.global()[ii].val;
112 dy += tmp[j].grad.col(1) * b.global()[ii].node * b.global()[ii].val;
114 dz += tmp[j].grad.col(2) * b.global()[ii].node * b.global()[ii].val;
118 for (
long i = 0; i < dx.rows(); ++i)
123 tmp << dx.row(i), dy.row(i), dz.row(i);
124 min_jacs = std::min(min_jacs, tmp.determinant());
129 tmp << dx.row(i), dy.row(i);
130 min_jacs = std::min(min_jacs, tmp.determinant());
150 json transform_params = {};
151 transform_params[
"canonical_transformation"] = json::array();
152 if (!state.
mesh->is_volume())
154 Eigen::MatrixXd regular_tri(3, 3);
155 regular_tri << 0, 0, 1,
157 1. / 2., std::sqrt(3) / 2., 1;
158 regular_tri.transposeInPlace();
159 Eigen::MatrixXd regular_tri_inv = regular_tri.inverse();
162 for (
int e = 0; e < state.
mesh->n_elements(); e++)
164 Eigen::MatrixXd transform;
166 transform_params[
"canonical_transformation"].push_back(
json({
180 Eigen::MatrixXd regular_tet(4, 4);
181 regular_tet << 0, 0, 0, 1,
183 1. / 2., std::sqrt(3) / 2., 0, 1,
184 1. / 2., 1. / 2. / std::sqrt(3), std::sqrt(3) / 2., 1;
185 regular_tet.transposeInPlace();
186 Eigen::MatrixXd regular_tet_inv = regular_tet.inverse();
189 for (
int e = 0; e < state.
mesh->n_elements(); e++)
191 Eigen::MatrixXd transform;
193 transform_params[
"canonical_transformation"].push_back(
json({
212 transform_params[
"solve_displacement"] =
true;
233 Eigen::MatrixXd grad;
234 amips_energy_->assemble_gradient(
state_.
mesh->is_volume(),
state_.
n_geom_bases,
init_geom_bases_,
init_geom_bases_,
init_ass_vals_cache_, 0, 0,
AdjointTools::map_primitive_to_node_order(
state_, X -
X_rest), Eigen::VectorXd(), grad);
main class that contains the polyfem solver and all its state
void get_vertices(Eigen::MatrixXd &vertices) const
const std::vector< basis::ElementBases > & geom_bases() const
Get a constant reference to the geometry mapping bases.
std::unique_ptr< mesh::Mesh > mesh
current mesh, it can be a Mesh2D or Mesh3D
void get_elements(Eigen::MatrixXi &elements) const
int n_geom_bases
number of geometric bases
static std::shared_ptr< Assembler > make_assembler(const std::string &formulation)
Represents one basis function and its gradient.
void compute_face_jacobian(const int el_id, const Eigen::MatrixXd &reference_map, Eigen::MatrixXd &jacobian) const
void compute_cell_jacobian(const int el_id, const Eigen::MatrixXd &reference_map, Eigen::MatrixXd &jacobian) const
A collection of VariableToSimulation.
virtual Eigen::VectorXd apply_parametrization_jacobian(const ParameterType type, const State *state_ptr, const Eigen::VectorXd &x, const std::function< Eigen::VectorXd()> &grad) const
Maps the partial gradient wrt.
bool scaled_jacobian(Mesh3DStorage &hmi, Mesh_Quality &mq)
bool is_flipped(const Eigen::MatrixXd &V, const Eigen::MatrixXi &F)
Determine if any simplex is inverted or collapses.
Eigen::MatrixXd unflatten(const Eigen::VectorXd &x, int dim)
Unflatten rowwises, so every dim elements in x become a row.
Eigen::VectorXd flatten(const Eigen::MatrixXd &X)
Flatten rowwises.
spdlog::logger & adjoint_logger()
Retrieves the current logger for adjoint.
void log_and_throw_adjoint_error(const std::string &msg)