8 class QuadraticBarrier :
public ipc::Barrier
11 QuadraticBarrier(
const double weight = 1) :
weight_(weight) {}
13 double operator()(
const double d,
const double dhat)
const override
18 return weight_ * (d - dhat) * (d - dhat);
20 double first_derivative(
const double d,
const double dhat)
const override
25 return 2 *
weight_ * (d - dhat);
27 double second_derivative(
const double d,
const double dhat)
const override
42 :
AdjointForm(variable_to_simulation), state_(state), dhat_(dhat), dmin_(dmin), barrier_potential_(dhat)
47 [
this](
const std::string &p) { return this->state_.resolve_input_path(p); },
86 if ((
V1 -
V0).lpNorm<Eigen::Infinity>() == 0.0)
89 bool is_valid = ipc::is_step_collision_free(
104 double max_step = ipc::compute_collision_free_stepsize(
117 static Eigen::MatrixXd cached_displaced_surface;
118 if (cached_displaced_surface.size() == displaced_surface.size() && cached_displaced_surface == displaced_surface)
123 cached_displaced_surface = displaced_surface;
128 Eigen::VectorXd X =
X_init;
134 :
AdjointForm(variable_to_simulation), state_(state), dhat_(dhat), barrier_potential_(dhat)
142 [
this](
const std::string &p) { return this->state_.resolve_input_path(p); },
211 static Eigen::MatrixXd cached_displaced_surface;
212 if (cached_displaced_surface.size() == displaced_surface.size() && cached_displaced_surface == displaced_surface)
217 cached_displaced_surface = displaced_surface;
222 Eigen::VectorXd X =
X_init;
229 const std::vector<int> &boundary_ids,
231 const bool use_log_barrier,
234 boundary_ids_(boundary_ids)
241 if (!use_log_barrier)
247 Eigen::MatrixXd node_positions;
248 Eigen::MatrixXi boundary_edges, boundary_triangles;
249 std::vector<Eigen::Triplet<double>> displacement_map_entries;
251 node_positions, boundary_edges, boundary_triangles, displacement_map_entries);
253 std::vector<bool> is_on_surface;
254 is_on_surface.resize(node_positions.rows(),
false);
257 Eigen::MatrixXd points, uv, normals;
258 Eigen::VectorXd weights;
259 Eigen::VectorXi global_primitive_ids;
262 const int e = lb.element_id();
272 for (
int i = 0; i < lb.size(); ++i)
274 const int primitive_global_id = lb.global_primitive_id(i);
276 const int boundary_id =
state_.
mesh->get_boundary_id(primitive_global_id);
281 for (
long n = 0; n < nodes.size(); ++n)
284 is_on_surface[v.
global[0].index] =
true;
285 assert(v.
global[0].index < node_positions.rows());
291 Eigen::SparseMatrix<double> displacement_map;
292 if (!displacement_map_entries.empty())
295 displacement_map.setFromTriplets(displacement_map_entries.begin(), displacement_map_entries.end());
299 Eigen::MatrixXi boundary_edges_alt(0, 2), boundary_triangles_alt(0, 3);
301 for (
int i = 0; i < boundary_edges.rows(); ++i)
303 bool on_surface =
true;
304 for (
int j = 0; j < boundary_edges.cols(); ++j)
305 on_surface &= is_on_surface[boundary_edges(i, j)];
308 boundary_edges_alt.conservativeResize(boundary_edges_alt.rows() + 1, 2);
309 boundary_edges_alt.row(boundary_edges_alt.rows() - 1) = boundary_edges.row(i);
315 for (
int i = 0; i < boundary_triangles.rows(); ++i)
317 bool on_surface =
true;
318 for (
int j = 0; j < boundary_triangles.cols(); ++j)
319 on_surface &= is_on_surface[boundary_triangles(i, j)];
322 boundary_triangles_alt.conservativeResize(boundary_triangles_alt.rows() + 1, 3);
323 boundary_triangles_alt.row(boundary_triangles_alt.rows() - 1) = boundary_triangles.row(i);
328 boundary_triangles_alt.resize(0, 0);
334 boundary_triangles_alt,
341 if (!is_on_surface[dof_idx_i])
346 if (!is_on_surface[dof_idx_j])
349 bool collision_allowed =
true;
352 collision_allowed =
false;
ElementAssemblyValues vals
main class that contains the polyfem solver and all its state
void get_vertices(Eigen::MatrixXd &vertices) const
int n_bases
number of bases
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.
Eigen::VectorXi in_node_to_node
Inpute nodes (including high-order) to polyfem nodes, only for isoparametric.
mesh::Obstacle obstacle
Obstacles used in collisions.
std::unique_ptr< mesh::Mesh > mesh
current mesh, it can be a Mesh2D or Mesh3D
json args
main input arguments containing all defaults
solver::DiffCache diff_cached
int n_geom_bases
number of geometric bases
std::vector< mesh::LocalBoundary > total_local_boundary
mapping from elements to nodes for all mesh
void build_collision_mesh()
extracts the boundary mesh for collision, called in build_basis
stores per local bases evaluations
std::vector< basis::Local2Global > global
stores per element basis values at given quadrature points and geometric mapping
Stores the basis functions for a given element in a mesh (facet in 2d, cell in 3d).
Eigen::VectorXi local_nodes_for_primitive(const int local_index, const mesh::Mesh &mesh) const
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
Eigen::VectorXd u(int step) const
A collection of VariableToSimulation.
void compute_state_variable(const ParameterType type, const State *state_ptr, const Eigen::VectorXd &x, Eigen::VectorXd &state_variable) const
Evaluate the variable to simulations and overwrite the state_variable based on x.
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.
static bool boundary_quadrature(const mesh::LocalBoundary &local_boundary, const int order, const mesh::Mesh &mesh, const bool skip_computation, Eigen::MatrixXd &uv, Eigen::MatrixXd &points, Eigen::MatrixXd &normals, Eigen::VectorXd &weights, Eigen::VectorXi &global_primitive_ids)
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)