PolyFEM
Loading...
Searching...
No Matches
polyfem::utils Namespace Reference

Namespaces

namespace  StringUtils
 

Classes

class  AutoFlipSVD
 
class  AxisPlaneSelection
 
class  BoundarySampler
 
class  BoxSelection
 
class  BoxSideSelection
 
class  CylinderSelection
 
class  DenseMatrixCache
 
class  EdgeSampler
 
struct  EqualUnorderedArray
 
class  ExpressionValue
 
class  FileSelection
 
class  GeogramUtils
 
struct  HashMatrix
 
struct  HashPair
 
struct  HashUnorderedArray
 Hash function for an array where the order does not matter. More...
 
struct  HashVector
 
class  InterpolatedFunction2d
 
class  Interpolation
 
class  LinearInterpolation
 
class  LinearRamp
 
class  MatrixCache
 abstract class used for caching More...
 
class  NoInterpolation
 
class  NThread
 
class  PeriodicBoundary
 
class  PiecewiseConstantInterpolation
 
class  PiecewiseCubicInterpolation
 
class  PiecewiseInterpolation
 
class  PiecewiseLinearInterpolation
 
class  PlaneSelection
 
class  PolygonClipping
 
class  RBFInterpolation
 
class  RefElementSampler
 
class  Selection
 
class  SparseMatrixCache
 
class  SpecifiedSelection
 
class  SphereSelection
 
class  TetrahedronClipping
 
class  Timer
 
struct  Timing
 
class  Tree
 
class  TriangleClipping
 
class  UniformSelection
 

Functions

double triangle_area_2D (const Eigen::Vector2d &a, const Eigen::Vector2d &b, const Eigen::Vector2d &c)
 Compute the signed area of a 2D triangle defined by three points.
 
double triangle_area_3D (const Eigen::Vector3d &a, const Eigen::Vector3d &b, const Eigen::Vector3d &c)
 Compute the area of a 3D triangle defined by three points.
 
double triangle_area (const Eigen::MatrixXd V)
 Compute the signed area of a triangle defined by three points.
 
double tetrahedron_volume (const Eigen::Vector3d &a, const Eigen::Vector3d &b, const Eigen::Vector3d &c, const Eigen::Vector3d &d)
 Compute the signed volume of a tetrahedron defined by four points.
 
double tetrahedron_volume (const Eigen::MatrixXd V)
 Compute the signed volume of a tetrahedron defined by four points.
 
Eigen::MatrixXd triangle_to_clockwise_order (const Eigen::MatrixXd &triangle)
 Reorder the vertices of a triangle so they are in clockwise order.
 
std::vector< Eigen::MatrixXd > triangle_fan (const Eigen::MatrixXd &convex_polygon)
 Convert a convex polygon to a list of triangles fanned around the first vertex.
 
Eigen::VectorXd barycentric_coordinates (const Eigen::VectorXd &p, const Eigen::MatrixXd &V)
 Compute barycentric coordinates for point p with respect to a simplex.
 
bool triangle_intersects_disk (const Eigen::Vector2d &t0, const Eigen::Vector2d &t1, const Eigen::Vector2d &t2, const Eigen::Vector2d &center, const double radius)
 Determine if a 2D triangle intersects a 2D disk.
 
bool tetrahedron_intersects_ball (const Eigen::Vector3d &t0, const Eigen::Vector3d &t1, const Eigen::Vector3d &t2, const Eigen::Vector3d &t3, const Eigen::Vector3d &center, const double radius)
 Determine if a 3D tetrahedron intersects a 3D ball.
 
bool are_edges_collinear (const VectorNd &ea0, const VectorNd &ea1, const VectorNd &eb0, const VectorNd &eb1, const double tol=1e-10)
 Determine if two edges are collinear.
 
bool are_triangles_coplanar (const Eigen::Vector3d &t00, const Eigen::Vector3d &t01, const Eigen::Vector3d &t02, const Eigen::Vector3d &t10, const Eigen::Vector3d &t11, const Eigen::Vector3d &t12, const double tol=1e-10)
 Determine if two triangles are coplanar.
 
bool are_aabbs_intersecting (const VectorNd &aabb0_min, const VectorNd &aabb0_max, const VectorNd &aabb1_min, const VectorNd &aabb1_max)
 Determine if two axis-aligned bounding boxes intersect.
 
void triangle_area_2D_gradient (double ax, double ay, double bx, double by, double cx, double cy, double g[6])
 Compute the gradient of the signed area of a 2D triangle defined by three points.
 
void triangle_area_2D_hessian (double ax, double ay, double bx, double by, double cx, double cy, double H[36])
 Compute the Hessian of the signed area of a 2D triangle defined by three points.
 
void tetrahedron_volume_gradient (double ax, double ay, double az, double bx, double by, double bz, double cx, double cy, double cz, double dx, double dy, double dz, double g[12])
 Compute the gradient of the signed volume of a tetrahedron defined by four points.
 
void tetrahedron_volume_hessian (double ax, double ay, double az, double bx, double by, double bz, double cx, double cy, double cz, double dx, double dy, double dz, double H[144])
 Compute the gradient of the signed area of a 2D triangle defined by three points.
 
 NLOHMANN_JSON_SERIALIZE_ENUM (PiecewiseInterpolation::Extend, {{PiecewiseInterpolation::Extend::CONSTANT, "constant"}, {PiecewiseInterpolation::Extend::EXTRAPOLATE, "extrapolate"}, {PiecewiseInterpolation::Extend::REPEAT, "repeat"}, {PiecewiseInterpolation::Extend::REPEAT_OFFSET, "repeat_offset"}})
 
Eigen::MatrixXd extract_nodes (const int dim, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const Eigen::VectorXd &u, int order, int n_elem)
 
Eigen::MatrixXd extract_nodes (const int dim, const basis::ElementBases &basis, const basis::ElementBases &gbasis, const Eigen::VectorXd &u, int order)
 
Eigen::VectorXd robust_evaluate_jacobian (const int order, const Eigen::MatrixXd &cp, const Eigen::MatrixXd &uv)
 
std::vector< int > count_invalid (const int dim, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const Eigen::VectorXd &u)
 
std::tuple< bool, int, Treeis_valid (const int dim, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const Eigen::VectorXd &u, const double threshold)
 
bool is_valid (const int dim, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const Eigen::VectorXd &u1, const Eigen::VectorXd &u2, const double threshold)
 
std::tuple< double, int, double, Treemax_time_step (const int dim, const std::vector< basis::ElementBases > &bases, const std::vector< basis::ElementBases > &gbases, const Eigen::VectorXd &u1, const Eigen::VectorXd &u2, double precision)
 
void apply_common_params (json &args)
 
Eigen::Matrix3d to_rotation_matrix (const json &jr, std::string mode)
 
bool is_param_valid (const json &params, const std::string &key)
 Determine if a key exists and is non-null in a json object.
 
template<typename T >
deg2rad (T deg)
 
template<typename T = json>
std::vector< T > json_as_array (const json &j)
 Return the value of a json object as an array.
 
template<typename T >
json_value (const json &params, const std::string &key, const T &default_value)
 Get a parameter from a json object or return a default value if the parameter invalid.
 
void show_matrix_stats (const Eigen::MatrixXd &M)
 
template<typename T >
matrix_inner_product (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &A, const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &B)
 
template<typename T , int rows, int cols, int option, int maxRow, int maxCol>
determinant (const Eigen::Matrix< T, rows, cols, option, maxRow, maxCol > &mat)
 
template<typename T >
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > inverse (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > &mat)
 
Eigen::SparseMatrix< double > sparse_identity (int rows, int cols)
 
Eigen::VectorXd flatten (const Eigen::MatrixXd &X)
 Flatten rowwises.
 
Eigen::MatrixXd unflatten (const Eigen::VectorXd &x, int dim)
 Unflatten rowwises, so every dim elements in x become a row.
 
void vector2matrix (const Eigen::VectorXd &vec, Eigen::MatrixXd &mat)
 
Eigen::SparseMatrix< double > lump_matrix (const Eigen::SparseMatrix< double > &M)
 Lump each row of a matrix into the diagonal.
 
void full_to_reduced_matrix (const int full_size, const int reduced_size, const std::vector< int > &removed_vars, const StiffnessMatrix &full, StiffnessMatrix &reduced)
 Map a full size matrix to a reduced one by dropping rows and columns.
 
Eigen::MatrixXd reorder_matrix (const Eigen::MatrixXd &in, const Eigen::VectorXi &in_to_out, int out_blocks=-1, const int block_size=1)
 Reorder row blocks in a matrix.
 
Eigen::MatrixXd unreorder_matrix (const Eigen::MatrixXd &out, const Eigen::VectorXi &in_to_out, int in_blocks=-1, const int block_size=1)
 Undo the reordering of row blocks in a matrix.
 
Eigen::MatrixXi map_index_matrix (const Eigen::MatrixXi &in, const Eigen::VectorXi &index_mapping)
 Map the entrys of an index matrix to new indices.
 
template<typename DstMat , typename SrcMat >
void append_rows (DstMat &dst, const SrcMat &src)
 
template<typename DstMat >
void append_rows_of_zeros (DstMat &dst, const size_t n_zero_rows)
 
void maybe_parallel_for (int size, const std::function< void(int, int, int)> &partial_for)
 
void maybe_parallel_for (int size, const std::function< void(int)> &body)
 
template<typename LocalStorage >
auto create_thread_storage (const LocalStorage &initial_local_storage)
 
template<typename Storages >
auto & get_local_thread_storage (Storages &storage, int thread_id)
 
void par_for (const int size, const std::function< void(int, int, int)> &func)
 
size_t get_n_threads ()
 
void regular_2d_grid (const int n, bool tri, Eigen::MatrixXd &V, Eigen::MatrixXi &F)
 Generate a canonical triangle/quad subdivided from a regular grid.
 
void regular_3d_grid (const int nn, bool tet, Eigen::MatrixXd &V, Eigen::MatrixXi &F, Eigen::MatrixXi &T)
 Generate a canonical tet/hex subdivided from a regular grid.
 
std::string resolve_path (const std::string &path, const std::string &input_file_path, const bool only_if_exists=false)
 
template<int dim>
Eigen::Vector< double, dim > singular_values (const Eigen::Matrix< double, dim, dim > &A)
 

Function Documentation

◆ append_rows()

template<typename DstMat , typename SrcMat >
void polyfem::utils::append_rows ( DstMat &  dst,
const SrcMat &  src 
)

Definition at line 149 of file MatrixUtils.hpp.

Referenced by polyfem::mesh::Mesh::append(), polyfem::State::build_collision_mesh(), polyfem::mesh::SizingFieldRemesher< WMTKMesh >::compute_contact_sizing_field(), polyfem::mesh::LocalMesh< M >::LocalMesh(), polyfem::mesh::Remesher::project_quantities(), and polyfem::mesh::Remesher::write_mesh().

Here is the caller graph for this function:

◆ append_rows_of_zeros()

template<typename DstMat >
void polyfem::utils::append_rows_of_zeros ( DstMat &  dst,
const size_t  n_zero_rows 
)

Definition at line 161 of file MatrixUtils.hpp.

Referenced by polyfem::io::OutGeometryData::save_volume().

Here is the caller graph for this function:

◆ apply_common_params()

void polyfem::utils::apply_common_params ( json args)

Definition at line 14 of file JSONUtils.cpp.

References apply_common_params(), polyfem::log_and_throw_error(), and resolve_path().

Referenced by apply_common_params(), and polyfem::State::init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ are_aabbs_intersecting()

bool polyfem::utils::are_aabbs_intersecting ( const VectorNd aabb0_min,
const VectorNd aabb0_max,
const VectorNd aabb1_min,
const VectorNd aabb1_max 
)

Determine if two axis-aligned bounding boxes intersect.

Parameters
aabb0_minMinimum corner of the first AABB.
aabb0_maxMaximum corner of the first AABB.
aabb1_minMinimum corner of the second AABB.
aabb1_maxMaximum corner of the second AABB.
Returns
True if the AABBs intersect, false otherwise.

Definition at line 196 of file GeometryUtils.cpp.

Referenced by polyfem::mesh::LocalMesh< M >::ball_selection().

Here is the caller graph for this function:

◆ are_edges_collinear()

bool polyfem::utils::are_edges_collinear ( const VectorNd ea0,
const VectorNd ea1,
const VectorNd eb0,
const VectorNd eb1,
const double  tol = 1e-10 
)

Determine if two edges are collinear.

Parameters
ea0First vertex of the first edge.
ea1Second vertex of the first edge.
eb0First vertex of the second edge.
eb1Second vertex of the second edge.
tolTolerance for collinearity.
Returns
True if the edges are collinear, false otherwise.

Definition at line 169 of file GeometryUtils.cpp.

◆ are_triangles_coplanar()

bool polyfem::utils::are_triangles_coplanar ( const Eigen::Vector3d &  t00,
const Eigen::Vector3d &  t01,
const Eigen::Vector3d &  t02,
const Eigen::Vector3d &  t10,
const Eigen::Vector3d &  t11,
const Eigen::Vector3d &  t12,
const double  tol = 1e-10 
)

Determine if two triangles are coplanar.

Parameters
t00First vertex of the first triangle.
t01Second vertex of the first triangle.
t02Third vertex of the first triangle.
t10First vertex of the second triangle.
t11Second vertex of the second triangle.
t12Third vertex of the second triangle.
tolTolerance for coplanarity.
Returns
True if the triangles are coplanar, false otherwise.

Definition at line 182 of file GeometryUtils.cpp.

References polyfem::assembler::cross().

Here is the call graph for this function:

◆ barycentric_coordinates()

Eigen::VectorXd polyfem::utils::barycentric_coordinates ( const Eigen::VectorXd &  p,
const Eigen::MatrixXd &  V 
)

Compute barycentric coordinates for point p with respect to a simplex.

Parameters
pQuery point.
VVerties of the simplex as rows of a matrix.
Returns
The barycentric coordinates for point p with respect to the simplex.

Definition at line 88 of file GeometryUtils.cpp.

References V.

Referenced by polyfem::assembler::MassMatrixAssembler::assemble_cross().

Here is the caller graph for this function:

◆ count_invalid()

std::vector< int > polyfem::utils::count_invalid ( const int  dim,
const std::vector< basis::ElementBases > &  bases,
const std::vector< basis::ElementBases > &  gbases,
const Eigen::VectorXd &  u 
)

Definition at line 173 of file Jacobian.cpp.

References extract_nodes(), polyfem::utils::NThread::get(), and polyfem::utils::NThread::num_threads().

Referenced by polyfem::io::Evaluator::mark_flipped_cells(), and polyfem::State::solve_tensor_nonlinear().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create_thread_storage()

◆ deg2rad()

template<typename T >
T polyfem::utils::deg2rad ( deg)
inline

Definition at line 18 of file JSONUtils.hpp.

References deg2rad().

Referenced by polyfem::mesh::construct_affine_transformation(), deg2rad(), and to_rotation_matrix().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ determinant()

template<typename T , int rows, int cols, int option, int maxRow, int maxCol>
T polyfem::utils::determinant ( const Eigen::Matrix< T, rows, cols, option, maxRow, maxCol > &  mat)

◆ extract_nodes() [1/2]

Eigen::MatrixXd polyfem::utils::extract_nodes ( const int  dim,
const basis::ElementBases basis,
const basis::ElementBases gbasis,
const Eigen::VectorXd &  u,
int  order 
)

Definition at line 104 of file Jacobian.cpp.

References polyfem::assembler::ElementAssemblyValues::basis_values, polyfem::assembler::ElementAssemblyValues::compute(), polyfem::basis::ElementBases::eval_geom_mapping(), polyfem::autogen::p_nodes_2d(), polyfem::autogen::p_nodes_3d(), and vals.

Here is the call graph for this function:

◆ extract_nodes() [2/2]

Eigen::MatrixXd polyfem::utils::extract_nodes ( const int  dim,
const std::vector< basis::ElementBases > &  bases,
const std::vector< basis::ElementBases > &  gbases,
const Eigen::VectorXd &  u,
int  order,
int  n_elem 
)

Definition at line 77 of file Jacobian.cpp.

References polyfem::assembler::ElementAssemblyValues::basis_values, polyfem::assembler::ElementAssemblyValues::compute(), polyfem::autogen::p_nodes_2d(), polyfem::autogen::p_nodes_3d(), and vals.

Referenced by count_invalid(), polyfem::assembler::ElementAssemblyValues::eval_deformed_jacobian_determinant(), is_valid(), is_valid(), and max_time_step().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ flatten()

Eigen::VectorXd polyfem::utils::flatten ( const Eigen::MatrixXd &  X)

Flatten rowwises.

Definition at line 34 of file MatrixUtils.cpp.

References x.

Referenced by polyfem::solver::AMIPSForm::AMIPSForm(), polyfem::solver::PeriodicMeshToMesh::apply_jacobian(), polyfem::solver::CollisionBarrierForm::CollisionBarrierForm(), polyfem::solver::BoundarySmoothingForm::compute_partial_gradient(), polyfem::solver::SpatialIntegralForm::compute_partial_gradient_step(), polyfem::assembler::NeoHookeanElasticity::compute_stiffness_value(), polyfem::solver::DeformedCollisionBarrierForm::DeformedCollisionBarrierForm(), polyfem::solver::BSplineParametrization1DTo2D::eval(), polyfem::solver::PeriodicContactForm::force_periodic_shape_derivative(), polyfem::solver::NLHomoProblem::full_to_reduced(), polyfem::io::Evaluator::generate_linear_field(), polyfem::solver::ElasticEnergyForm::get_integral_functional(), polyfem::solver::StressNormForm::get_integral_functional(), polyfem::solver::ComplianceForm::get_integral_functional(), polyfem::solver::StressForm::get_integral_functional(), polyfem::solver::ShapeVariableToSimulation::inverse_eval(), polyfem::solver::PeriodicShapeVariableToSimulation::inverse_eval(), polyfem::solver::BSplineParametrization1DTo2D::inverse_eval(), polyfem::solver::NLHomoProblem::macro_reduced_to_full(), polyfem::State::remesh(), polyfem::mesh::LocalRelaxationData< M >::sol(), polyfem::State::solve_homogenization_step(), and polyfem::solver::MacroStrainLagrangianForm::update_quantities().

Here is the caller graph for this function:

◆ full_to_reduced_matrix()

void polyfem::utils::full_to_reduced_matrix ( const int  full_size,
const int  reduced_size,
const std::vector< int > &  removed_vars,
const StiffnessMatrix full,
StiffnessMatrix reduced 
)

Map a full size matrix to a reduced one by dropping rows and columns.

Parameters
[in]full_sizeNumber of variables in the full system.
[in]reduced_sizeNumber of variables in the reduced system.
[in]removed_varsIndices of the variables (rows and columns of full) to remove.
[in]fullFull size matrix.
[out]reducedOutput reduced size matrix.

Definition at line 103 of file MatrixUtils.cpp.

References entries, and POLYFEM_SCOPED_TIMER.

Referenced by polyfem::solver::NLProblem::full_hessian_to_reduced_hessian().

Here is the caller graph for this function:

◆ get_local_thread_storage()

template<typename Storages >
auto & polyfem::utils::get_local_thread_storage ( Storages &  storage,
int  thread_id 
)
inline

◆ get_n_threads()

size_t polyfem::utils::get_n_threads ( )
inline

Definition at line 51 of file par_for.hpp.

References polyfem::utils::NThread::get(), and polyfem::utils::NThread::num_threads().

Referenced by par_for(), and polyfem::io::OutStatsData::save_json().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ inverse()

template<typename T >
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > polyfem::utils::inverse ( const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, 0, 3, 3 > &  mat)

Definition at line 38 of file MatrixUtils.hpp.

References determinant().

Referenced by polyfem::mesh::stitch_mesh().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_param_valid()

bool polyfem::utils::is_param_valid ( const json params,
const std::string &  key 
)

Determine if a key exists and is non-null in a json object.

Parameters
paramsJSON of parameters
keyKey to check
Returns
True if the key exists and is non-null, false otherwise.

Definition at line 131 of file JSONUtils.cpp.

Referenced by polyfem::assembler::MacroStrainValue::init(), polyfem::mesh::LocalRelaxationData< M >::init_assembler(), polyfem::State::init_time(), json_value(), polyfem::State::load_mesh(), polyfem::mesh::read_fem_mesh(), polyfem::mesh::read_obstacle_geometry(), polyfem::mesh::read_obstacle_mesh(), polyfem::OptState::root_path(), polyfem::State::root_path(), polyfem::State::set_materials(), polyfem::State::set_materials(), polyfem::assembler::GenericTensorProblem::set_parameters(), polyfem::assembler::GenericScalarProblem::set_parameters(), and polyfem::State::solve_homogenization().

Here is the caller graph for this function:

◆ is_valid() [1/2]

std::tuple< bool, int, Tree > polyfem::utils::is_valid ( const int  dim,
const std::vector< basis::ElementBases > &  bases,
const std::vector< basis::ElementBases > &  gbases,
const Eigen::VectorXd &  u,
const double  threshold 
)

Definition at line 241 of file Jacobian.cpp.

References extract_nodes(), polyfem::utils::NThread::get(), and polyfem::utils::NThread::num_threads().

Referenced by polyfem::solver::CollisionBarrierForm::is_step_collision_free(), polyfem::solver::ContactForm::is_step_collision_free(), polyfem::mesh::NCMesh2D::refine(), polyfem::mesh::NCMesh3D::refine(), and polyfem::mesh::NCMesh3D::refine_element().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_valid() [2/2]

bool polyfem::utils::is_valid ( const int  dim,
const std::vector< basis::ElementBases > &  bases,
const std::vector< basis::ElementBases > &  gbases,
const Eigen::VectorXd &  u1,
const Eigen::VectorXd &  u2,
const double  threshold 
)

Definition at line 298 of file Jacobian.cpp.

References extract_nodes(), polyfem::utils::NThread::get(), and polyfem::utils::NThread::num_threads().

Here is the call graph for this function:

◆ json_as_array()

template<typename T = json>
std::vector< T > polyfem::utils::json_as_array ( const json j)

Return the value of a json object as an array.

If the value is an array return it directly otherwise return a vector with the value.

Parameters
jJSON object
Returns
Array of values

Definition at line 38 of file JSONUtils.hpp.

Referenced by polyfem::assembler::GenericMatParams::add_multimaterial(), polyfem::State::boundary_conditions_ids(), polyfem::State::build_collision_mesh(), polyfem::solver::SolveData::init_forms(), polyfem::State::load_mesh(), polyfem::State::load_mesh(), polyfem::mesh::read_fem_geometry(), polyfem::mesh::read_obstacle_geometry(), and polyfem::problem::NodeProblem::set_parameters().

Here is the caller graph for this function:

◆ json_value()

template<typename T >
T polyfem::utils::json_value ( const json params,
const std::string &  key,
const T &  default_value 
)

Get a parameter from a json object or return a default value if the parameter invalid.

Similar to json::value() but return default value if the parameter is null.

Definition at line 56 of file JSONUtils.hpp.

References is_param_valid().

Here is the call graph for this function:

◆ lump_matrix()

Eigen::SparseMatrix< double > polyfem::utils::lump_matrix ( const Eigen::SparseMatrix< double > &  M)

Lump each row of a matrix into the diagonal.

Parameters
MMatrix to lump.
Returns
Lumped matrix.

Definition at line 84 of file MatrixUtils.cpp.

Referenced by polyfem::State::assemble_mass_mat(), and polyfem::solver::BCLagrangianForm::init_masked_lumped_mass().

Here is the caller graph for this function:

◆ map_index_matrix()

Eigen::MatrixXi polyfem::utils::map_index_matrix ( const Eigen::MatrixXi &  in,
const Eigen::VectorXi &  index_mapping 
)

Map the entrys of an index matrix to new indices.

Parameters
inInput index matrix.
index_mappingMapping from old to new indices.
Returns
Mapped index matrix.

Definition at line 223 of file MatrixUtils.cpp.

Referenced by polyfem::mesh::Remesher::project_quantities(), and polyfem::mesh::LocalMesh< M >::reorder_vertices().

Here is the caller graph for this function:

◆ matrix_inner_product()

template<typename T >
T polyfem::utils::matrix_inner_product ( const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &  A,
const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &  B 
)

Definition at line 16 of file MatrixUtils.hpp.

◆ max_time_step()

std::tuple< double, int, double, Tree > polyfem::utils::max_time_step ( const int  dim,
const std::vector< basis::ElementBases > &  bases,
const std::vector< basis::ElementBases > &  gbases,
const Eigen::VectorXd &  u1,
const Eigen::VectorXd &  u2,
double  precision 
)

Definition at line 345 of file Jacobian.cpp.

References extract_nodes(), polyfem::utils::NThread::get(), and polyfem::utils::NThread::num_threads().

Here is the call graph for this function:

◆ maybe_parallel_for() [1/2]

void polyfem::utils::maybe_parallel_for ( int  size,
const std::function< void(int)> &  body 
)
inline

◆ maybe_parallel_for() [2/2]

void polyfem::utils::maybe_parallel_for ( int  size,
const std::function< void(int, int, int)> &  partial_for 
)
inline

Referenced by polyfem::assembler::NLAssembler::assemble_energy(), polyfem::assembler::NLAssembler::assemble_energy_per_element(), polyfem::assembler::RhsAssembler::compute_energy(), polyfem::assembler::PressureAssembler::compute_grad_volume(), polyfem::assembler::PressureAssembler::compute_grad_volume_id(), polyfem::assembler::PressureAssembler::compute_hess_volume_2d(), polyfem::assembler::PressureAssembler::compute_hess_volume_3d(), polyfem::assembler::PressureAssembler::compute_volume(), polyfem::solver::InversionBarrierForm::first_derivative_unweighted(), polyfem::solver::InertiaForm::force_shape_derivative(), polyfem::solver::BodyForm::force_shape_derivative(), polyfem::assembler::AssemblyValsCache::init(), polyfem::solver::AdjointTools::integrate_objective(), polyfem::assembler::PressureAssembler::is_closed_or_boundary_fixed(), polyfem::utils::SparseMatrixCache::operator+(), polyfem::utils::SparseMatrixCache::operator+=(), polyfem::solver::InversionBarrierForm::second_derivative_unweighted(), polyfem::solver::SDFTargetForm::solution_changed_step(), polyfem::solver::MeshTargetForm::solution_changed_step(), polyfem::solver::AdjointNLProblem::solve_pde(), polyfem::solver::ContactForm::value_per_element_unweighted(), polyfem::solver::InversionBarrierForm::value_unweighted(), and polyfem::solver::MaxStressForm::value_unweighted_step().

Here is the caller graph for this function:

◆ NLOHMANN_JSON_SERIALIZE_ENUM()

◆ par_for()

void polyfem::utils::par_for ( const int  size,
const std::function< void(int, int, int)> &  func 
)

Definition at line 10 of file par_for.cpp.

References get_n_threads(), and x.

Here is the call graph for this function:

◆ regular_2d_grid()

void polyfem::utils::regular_2d_grid ( const int  n,
bool  tri,
Eigen::MatrixXd &  V,
Eigen::MatrixXi &  F 
)

Generate a canonical triangle/quad subdivided from a regular grid.

Parameters
[in]nn grid quads
[in]triis a tri or a quad
[out]VV x 2 output vertices positions
[out]FF x 3 output triangle indices

Definition at line 31 of file RefElementSampler.cpp.

References polyfem::F, and V.

Referenced by polyfem::utils::RefElementSampler::build().

Here is the caller graph for this function:

◆ regular_3d_grid()

void polyfem::utils::regular_3d_grid ( const int  nn,
bool  tet,
Eigen::MatrixXd &  V,
Eigen::MatrixXi &  F,
Eigen::MatrixXi &  T 
)

Generate a canonical tet/hex subdivided from a regular grid.

Parameters
[in]nn grid quads
[in]tetis a tet or a hex
[out]VV x 3 output vertices positions
[out]FF x 3 output triangle indices
[out]TF x 4 output tet indices

Definition at line 116 of file RefElementSampler.cpp.

References polyfem::F, and V.

Referenced by polyfem::utils::RefElementSampler::build().

Here is the caller graph for this function:

◆ reorder_matrix()

Eigen::MatrixXd polyfem::utils::reorder_matrix ( const Eigen::MatrixXd &  in,
const Eigen::VectorXi &  in_to_out,
int  out_blocks = -1,
const int  block_size = 1 
)

Reorder row blocks in a matrix.

Parameters
inInput matrix.
in_to_outMapping from input blocks to output blocks.
out_blocksNumber of blocks in the output matrix.
block_sizeSize of each block.
Returns
Reordered matrix.

Definition at line 162 of file MatrixUtils.cpp.

Referenced by polyfem::mesh::Remesher::project_quantities(), polyfem::State::remesh(), and polyfem::mesh::LocalMesh< M >::reorder_vertices().

Here is the caller graph for this function:

◆ resolve_path()

std::string polyfem::utils::resolve_path ( const std::string &  path,
const std::string &  input_file_path,
const bool  only_if_exists = false 
)

◆ robust_evaluate_jacobian()

Eigen::VectorXd polyfem::utils::robust_evaluate_jacobian ( const int  order,
const Eigen::MatrixXd &  cp,
const Eigen::MatrixXd &  uv 
)

Definition at line 124 of file Jacobian.cpp.

Referenced by polyfem::assembler::ElementAssemblyValues::eval_deformed_jacobian_determinant().

Here is the caller graph for this function:

◆ show_matrix_stats()

void polyfem::utils::show_matrix_stats ( const Eigen::MatrixXd &  M)

Definition at line 8 of file MatrixUtils.cpp.

References polyfem::logger().

Referenced by polyfem::basis::RBFWithQuadraticLagrange::compute_constraints_matrix_2d_old(), and polyfem::basis::RBFWithQuadraticLagrange::compute_constraints_matrix_3d().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ singular_values()

template<int dim>
Eigen::Vector< double, dim > polyfem::utils::singular_values ( const Eigen::Matrix< double, dim, dim > &  A)

Definition at line 358 of file svd.hpp.

References polyfem::utils::AutoFlipSVD< MatrixType >::singularValues().

Referenced by polyfem::utils::AutoFlipSVD< MatrixType >::fastComputeSingularValues3d(), and polyfem::utils::AutoFlipSVD< MatrixType >::fastSVD3d().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sparse_identity()

Eigen::SparseMatrix< double > polyfem::utils::sparse_identity ( int  rows,
int  cols 
)
inline

Definition at line 83 of file MatrixUtils.hpp.

Referenced by polyfem::solver::BCLagrangianForm::init_masked_lumped_mass().

Here is the caller graph for this function:

◆ tetrahedron_intersects_ball()

bool polyfem::utils::tetrahedron_intersects_ball ( const Eigen::Vector3d &  t0,
const Eigen::Vector3d &  t1,
const Eigen::Vector3d &  t2,
const Eigen::Vector3d &  t3,
const Eigen::Vector3d &  center,
const double  radius 
)

Determine if a 3D tetrahedron intersects a 3D ball.

Parameters
t0Tetrahedron first vertex.
t1Tetrahedron second vertex.
t2Tetrahedron third vertex.
t3Tetrahedron fourth vertex.
centerCenter of the ball.
radiusRadius of the ball.
Returns
True if the tetrahedron intersects the ball, false otherwise.

Definition at line 137 of file GeometryUtils.cpp.

Referenced by polyfem::mesh::LocalMesh< M >::ball_selection().

Here is the caller graph for this function:

◆ tetrahedron_volume() [1/2]

double polyfem::utils::tetrahedron_volume ( const Eigen::MatrixXd  V)

Compute the signed volume of a tetrahedron defined by four points.

Parameters
VThe vertices of the terahedron as rows of a matrix.
Returns
The signed volume of the tetrahedron.

Definition at line 52 of file GeometryUtils.cpp.

References tetrahedron_volume(), and V.

Here is the call graph for this function:

◆ tetrahedron_volume() [2/2]

double polyfem::utils::tetrahedron_volume ( const Eigen::Vector3d &  a,
const Eigen::Vector3d &  b,
const Eigen::Vector3d &  c,
const Eigen::Vector3d &  d 
)

Compute the signed volume of a tetrahedron defined by four points.

Parameters
aFirst point of the tetrahedron.
bSecond point of the tetrahedron.
cThird point of the tetrahedron.
dFourth point of the tetrahedron.
Returns
The signed volume of the tetrahedron.

Definition at line 43 of file GeometryUtils.cpp.

Referenced by polyfem::assembler::MassMatrixAssembler::assemble_cross(), polyfem::utils::TetrahedronClipping::clip(), polyfem::solver::InversionBarrierForm::element_volume(), and tetrahedron_volume().

Here is the caller graph for this function:

◆ tetrahedron_volume_gradient()

void polyfem::utils::tetrahedron_volume_gradient ( double  ax,
double  ay,
double  az,
double  bx,
double  by,
double  bz,
double  cx,
double  cy,
double  cz,
double  dx,
double  dy,
double  dz,
double  g[12] 
)

Compute the gradient of the signed volume of a tetrahedron defined by four points.

Parameters
axFirst point's x coordinate.
ayFirst point's y coordinate.
ayFirst point's z coordinate.
bxSecond point's x coordinate.
bySecond point's y coordinate.
bySecond point's z coordinate.
cxThird point's x coordinate.
cyThird point's y coordinate.
cyThird point's z coordinate.
dxFourth point's x coordinate.
dyFourth point's y coordinate.
dyFourth point's z coordinate.
gOutput gradient with respect to the four points.

Definition at line 261 of file GeometryUtils.cpp.

Referenced by polyfem::solver::InversionBarrierForm::element_volume_gradient().

Here is the caller graph for this function:

◆ tetrahedron_volume_hessian()

void polyfem::utils::tetrahedron_volume_hessian ( double  ax,
double  ay,
double  az,
double  bx,
double  by,
double  bz,
double  cx,
double  cy,
double  cz,
double  dx,
double  dy,
double  dz,
double  H[144] 
)

Compute the gradient of the signed area of a 2D triangle defined by three points.

Parameters
axFirst point's x coordinate.
ayFirst point's y coordinate.
ayFirst point's z coordinate.
bxSecond point's x coordinate.
bySecond point's y coordinate.
bySecond point's z coordinate.
cxThird point's x coordinate.
cyThird point's y coordinate.
cyThird point's z coordinate.
dxFourth point's x coordinate.
dyFourth point's y coordinate.
dyFourth point's z coordinate.
gOutput flattened Hessian with respect to the four points.

Definition at line 295 of file GeometryUtils.cpp.

Referenced by polyfem::solver::InversionBarrierForm::element_volume_hessian().

Here is the caller graph for this function:

◆ to_rotation_matrix()

Eigen::Matrix3d polyfem::utils::to_rotation_matrix ( const json jr,
std::string  mode 
)

Definition at line 61 of file JSONUtils.cpp.

References deg2rad().

Referenced by polyfem::mesh::construct_affine_transformation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ triangle_area()

double polyfem::utils::triangle_area ( const Eigen::MatrixXd  V)

Compute the signed area of a triangle defined by three points.

Parameters
VThe vertices of the triangle as rows of a matrix.
Returns
The signed area of the triangle.

Definition at line 30 of file GeometryUtils.cpp.

References triangle_area_2D(), triangle_area_3D(), and V.

Referenced by polyfem::assembler::MassMatrixAssembler::assemble_cross(), polyfem::solver::InversionBarrierForm::element_volume(), polyfem::mesh::irregular_triangle(), and triangle_to_clockwise_order().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ triangle_area_2D()

double polyfem::utils::triangle_area_2D ( const Eigen::Vector2d &  a,
const Eigen::Vector2d &  b,
const Eigen::Vector2d &  c 
)

Compute the signed area of a 2D triangle defined by three points.

Parameters
aFirst point of the triangle.
bSecond point of the triangle.
cThird point of the triangle.
Returns
The signed area of the triangle.

Definition at line 14 of file GeometryUtils.cpp.

Referenced by polyfem::mesh::WildRemesher< WMTKMesh >::swap_edge_before(), and triangle_area().

Here is the caller graph for this function:

◆ triangle_area_2D_gradient()

void polyfem::utils::triangle_area_2D_gradient ( double  ax,
double  ay,
double  bx,
double  by,
double  cx,
double  cy,
double  g[6] 
)

Compute the gradient of the signed area of a 2D triangle defined by three points.

Parameters
axFirst point's x coordinate.
ayFirst point's y coordinate.
bxSecond point's x coordinate.
bySecond point's y coordinate.
cxThird point's x coordinate.
cyThird point's y coordinate.
gOutput gradient with respect to the three points.

Definition at line 209 of file GeometryUtils.cpp.

Referenced by polyfem::solver::InversionBarrierForm::element_volume_gradient().

Here is the caller graph for this function:

◆ triangle_area_2D_hessian()

void polyfem::utils::triangle_area_2D_hessian ( double  ax,
double  ay,
double  bx,
double  by,
double  cx,
double  cy,
double  H[36] 
)

Compute the Hessian of the signed area of a 2D triangle defined by three points.

Parameters
axFirst point's x coordinate.
ayFirst point's y coordinate.
bxSecond point's x coordinate.
bySecond point's y coordinate.
cxThird point's x coordinate.
cyThird point's y coordinate.
gOutput flattened Hessian with respect to the three points.

Definition at line 221 of file GeometryUtils.cpp.

Referenced by polyfem::solver::InversionBarrierForm::element_volume_hessian().

Here is the caller graph for this function:

◆ triangle_area_3D()

double polyfem::utils::triangle_area_3D ( const Eigen::Vector3d &  a,
const Eigen::Vector3d &  b,
const Eigen::Vector3d &  c 
)

Compute the area of a 3D triangle defined by three points.

Parameters
aFirst point of the triangle.
bSecond point of the triangle.
cThird point of the triangle.
Returns
The signed area of the triangle.

Definition at line 22 of file GeometryUtils.cpp.

Referenced by triangle_area().

Here is the caller graph for this function:

◆ triangle_fan()

std::vector< Eigen::MatrixXd > polyfem::utils::triangle_fan ( const Eigen::MatrixXd &  convex_polygon)

Convert a convex polygon to a list of triangles fanned around the first vertex.

Parameters
convex_polygonThe vertices of the convex polygon as rows of a matrix.
Returns
The list of triangles as matrices of rows.

Definition at line 74 of file GeometryUtils.cpp.

Referenced by polyfem::utils::TriangleClipping::clip().

Here is the caller graph for this function:

◆ triangle_intersects_disk()

bool polyfem::utils::triangle_intersects_disk ( const Eigen::Vector2d &  t0,
const Eigen::Vector2d &  t1,
const Eigen::Vector2d &  t2,
const Eigen::Vector2d &  center,
const double  radius 
)

Determine if a 2D triangle intersects a 2D disk.

Parameters
t0Triangle first vertex.
t1Triangle second vertex.
t2Triangle third vertex.
centerCenter of the disk.
radiusRadius of the disk.
Returns
True if the triangle intersects the disk, false otherwise.

Definition at line 107 of file GeometryUtils.cpp.

Referenced by polyfem::mesh::LocalMesh< M >::ball_selection().

Here is the caller graph for this function:

◆ triangle_to_clockwise_order()

Eigen::MatrixXd polyfem::utils::triangle_to_clockwise_order ( const Eigen::MatrixXd &  triangle)

Reorder the vertices of a triangle so they are in clockwise order.

Parameters
triangleThe vertices of the triangle as rows of a matrix.
Returns
The vertices of the triangle in clockwise order as rows of a matrix.

Definition at line 58 of file GeometryUtils.cpp.

References triangle_area().

Referenced by polyfem::utils::TriangleClipping::clip().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unflatten()

Eigen::MatrixXd polyfem::utils::unflatten ( const Eigen::VectorXd &  x,
int  dim 
)

Unflatten rowwises, so every dim elements in x become a row.

Definition at line 53 of file MatrixUtils.cpp.

References x.

Referenced by polyfem::solver::PeriodicMeshToMesh::apply_jacobian(), polyfem::solver::ProxyContactForceForm::compute_adjoint_rhs_step(), polyfem::solver::ContactForm::compute_displaced_surface(), polyfem::State::compute_force_jacobian_prev(), polyfem::solver::CollisionBarrierForm::compute_partial_gradient(), polyfem::solver::DeformedCollisionBarrierForm::compute_partial_gradient(), polyfem::solver::SpatialIntegralForm::compute_partial_gradient_step(), polyfem::solver::ProxyContactForceForm::compute_partial_gradient_step(), polyfem::solver::FrictionForm::compute_surface_velocities(), polyfem::mesh::constrained_L2_projection(), polyfem::solver::PeriodicMeshToMesh::eval(), polyfem::solver::BSplineParametrization1DTo2D::eval(), polyfem::io::OutGeometryData::export_data(), polyfem::solver::InversionBarrierForm::first_derivative_unweighted(), polyfem::solver::PeriodicContactForm::force_periodic_shape_derivative(), polyfem::solver::FrictionForm::force_shape_derivative(), polyfem::solver::ElasticEnergyForm::get_integral_functional(), polyfem::utils::PiecewiseCubicInterpolation::init(), polyfem::State::init_nonlinear_tensor_solve(), polyfem::solver::PeriodicMeshToMesh::inverse_eval(), polyfem::solver::BSplineParametrization1DTo2D::inverse_eval(), polyfem::solver::BoundedBiharmonicWeights2Dto3D::inverse_eval(), polyfem::solver::CollisionBarrierForm::is_step_collision_free(), polyfem::solver::AMIPSForm::is_step_valid(), polyfem::solver::InversionBarrierForm::is_step_valid(), polyfem::solver::AdjointNLProblem::is_step_valid(), polyfem::solver::CollisionBarrierForm::max_step_size(), polyfem::solver::NLHomoProblem::reduced_to_disp_grad(), polyfem::solver::NLHomoProblem::reduced_to_full(), polyfem::State::remesh(), polyfem::io::OutGeometryData::save_contact_surface(), polyfem::io::OutGeometryData::save_volume(), polyfem::io::OutGeometryData::save_volume_vector_field(), polyfem::solver::InversionBarrierForm::second_derivative_unweighted(), polyfem::solver::CollisionBarrierForm::solution_changed(), polyfem::solver::DeformedCollisionBarrierForm::solution_changed(), polyfem::State::solve_homogenization(), polyfem::State::solve_homogenization_step(), polyfem::solver::PeriodicShapeVariableToSimulation::update(), polyfem::solver::CollisionBarrierForm::value_unweighted(), polyfem::solver::DeformedCollisionBarrierForm::value_unweighted(), polyfem::solver::InversionBarrierForm::value_unweighted(), polyfem::solver::ProxyContactForceForm::value_unweighted_step(), vector2matrix(), polyfem::mesh::Remesher::write_mesh(), and polyfem::mesh::LocalMesh< M >::write_mesh().

Here is the caller graph for this function:

◆ unreorder_matrix()

Eigen::MatrixXd polyfem::utils::unreorder_matrix ( const Eigen::MatrixXd &  out,
const Eigen::VectorXi &  in_to_out,
int  in_blocks = -1,
const int  block_size = 1 
)

Undo the reordering of row blocks in a matrix.

Parameters
outReordered matrix.
in_to_outMapping from input blocks to output blocks.
in_blocksNumber of blocks in the input matrix.
block_sizeSize of each block.
Returns
Unreordered matrix.

Definition at line 193 of file MatrixUtils.cpp.

Referenced by polyfem::mesh::Remesher::project_quantities().

Here is the caller graph for this function:

◆ vector2matrix()

void polyfem::utils::vector2matrix ( const Eigen::VectorXd &  vec,
Eigen::MatrixXd &  mat 
)

Definition at line 69 of file MatrixUtils.cpp.

References unflatten(), and vec.

Referenced by polyfem::solver::ComplianceForm::compute_partial_gradient_step(), polyfem::solver::AdjointTools::compute_shape_derivative_functional_term(), polyfem::solver::StressNormForm::get_integral_functional(), polyfem::solver::ComplianceForm::get_integral_functional(), and polyfem::solver::StressForm::get_integral_functional().

Here is the call graph for this function:
Here is the caller graph for this function: