PolyFEM
|
#include <Remesher.hpp>
Classes | |
struct | GlobalProjectionCache |
Public Types | |
template<typename T > | |
using | EdgeMap = std::unordered_map< std::array< size_t, 2 >, T, polyfem::utils::HashUnorderedArray< size_t, 2 >, polyfem::utils::EqualUnorderedArray< size_t, 2 > > |
Map from a (sorted) edge to an integer (ID) | |
template<typename T > | |
using | FaceMap = std::unordered_map< std::array< size_t, 3 >, T, polyfem::utils::HashUnorderedArray< size_t, 3 >, polyfem::utils::EqualUnorderedArray< size_t, 3 > > |
Map from a (sorted) edge to an integer (ID) | |
template<typename T > | |
using | TetMap = std::unordered_map< std::array< size_t, 4 >, T, polyfem::utils::HashUnorderedArray< size_t, 4 >, polyfem::utils::EqualUnorderedArray< size_t, 4 > > |
template<typename T > | |
using | BoundaryMap = std::variant< EdgeMap< T >, FaceMap< T > > |
Public Member Functions | |
Remesher (const State &state, const Eigen::MatrixXd &obstacle_displacements, const Eigen::MatrixXd &obstacle_quantities, const double current_time, const double starting_energy) | |
Construct a new Remesher object. | |
virtual | ~Remesher ()=default |
virtual void | init (const Eigen::MatrixXd &rest_positions, const Eigen::MatrixXd &positions, const Eigen::MatrixXi &elements, const Eigen::MatrixXd &projection_quantities, const BoundaryMap< int > &boundary_to_id, const std::vector< int > &body_ids, const EdgeMap< double > &elastic_energy, const EdgeMap< double > &contact_energy) |
Initialize the mesh. | |
virtual bool | execute ()=0 |
Execute the remeshing. | |
virtual int | dim () const =0 |
Dimension of the mesh. | |
virtual bool | is_volume () const |
Is the mesh a volumetric mesh. | |
virtual Eigen::MatrixXd | rest_positions () const =0 |
Exports rest positions of the stored mesh. | |
virtual Eigen::MatrixXd | displacements () const =0 |
Exports positions of the stored mesh. | |
virtual Eigen::MatrixXd | positions () const =0 |
Exports displacements of the stored mesh. | |
virtual Eigen::MatrixXi | edges () const =0 |
Exports edges of the stored mesh. | |
virtual Eigen::MatrixXi | elements () const =0 |
Exports elements of the stored mesh. | |
virtual Eigen::MatrixXi | boundary_edges () const =0 |
Exports boundary edges of the stored mesh. | |
virtual Eigen::MatrixXi | boundary_faces () const =0 |
Exports boundary faces of the stored mesh. | |
virtual Eigen::MatrixXd | projection_quantities () const =0 |
Exports projected quantities of the stored mesh. | |
virtual BoundaryMap< int > | boundary_ids () const =0 |
Exports boundary ids of the stored mesh. | |
virtual std::vector< int > | body_ids () const =0 |
Exports body ids of the stored mesh. | |
virtual std::vector< int > | boundary_nodes (const Eigen::VectorXi &vertex_to_basis) const =0 |
Get the boundary nodes of the stored mesh. | |
virtual int | n_quantities () const =0 |
Number of projection quantities (not including the position) | |
const Obstacle & | obstacle () const |
Get a reference to the collision obstacles. | |
const Eigen::MatrixXd & | obstacle_displacements () const |
Get a reference to the collision obstacles' displacements. | |
const Eigen::MatrixXd & | obstacle_quantities () const |
Get a reference to the collision obstacles' extra quantities. | |
virtual void | set_rest_positions (const Eigen::MatrixXd &positions)=0 |
Set rest positions of the stored mesh. | |
virtual void | set_positions (const Eigen::MatrixXd &positions)=0 |
Set deformed positions of the stored mesh. | |
virtual void | set_projection_quantities (const Eigen::MatrixXd &projection_quantities)=0 |
Set projected quantities of the stored mesh. | |
virtual void | set_fixed (const std::vector< bool > &fixed)=0 |
Set if a vertex is fixed. | |
virtual void | set_boundary_ids (const BoundaryMap< int > &boundary_to_id)=0 |
Set the boundary IDs of all edges. | |
virtual void | set_body_ids (const std::vector< int > &body_ids)=0 |
Set the body IDs of all elements. | |
void | write_mesh (const std::string &path) const |
Writes a VTU mesh file. | |
void | init_assembler (const std::vector< int > &body_ids) const |
Create an assembler object. | |
Static Public Member Functions | |
static Eigen::MatrixXd | combine_time_integrator_quantities (const std::shared_ptr< time_integrator::ImplicitTimeIntegrator > &time_integrator) |
Combine the quantities of a time integrator into a single matrix (one column per quantity) | |
static void | split_time_integrator_quantities (const Eigen::MatrixXd &quantities, const int dim, Eigen::MatrixXd &x_prevs, Eigen::MatrixXd &v_prevs, Eigen::MatrixXd &a_prevs) |
Split the quantities of a time integrator into separate vectors. | |
static int | build_bases (const Mesh &mesh, const std::string &assembler_formulation, std::vector< polyfem::basis::ElementBases > &bases, std::vector< LocalBoundary > &local_boundary, Eigen::VectorXi &vertex_to_basis) |
Build bases for a given mesh (V, F) | |
static void | log_timings () |
Public Attributes | |
const State & | state |
Reference to the simulation state. | |
int | max_op_attempts = 1 |
Static Public Attributes | |
static std::unordered_map< std::string, utils::Timing > | timings |
Timings for the remeshing operations. | |
static double | total_time = 0 |
static size_t | num_solves = 0 |
static size_t | total_ndofs = 0 |
Protected Member Functions | |
virtual void | init_attributes_and_connectivity (const size_t num_vertices, const Eigen::MatrixXi &elements)=0 |
Create an internal mesh representation and associate attributes. | |
void | project_quantities () |
Update the mesh positions and other projection quantities. | |
void | cache_before () |
Cache quantities before applying an operation. | |
Protected Attributes | |
GlobalProjectionCache | global_projection_cache |
const json | args |
Copy of remesh args. | |
const Eigen::MatrixXd | m_obstacle_displacements |
Collision obstacles' displacements. | |
Eigen::MatrixXd | m_obstacle_quantities |
Collision obstacles' extra quantities. | |
const double | current_time |
Current time. | |
const double | starting_energy |
Starting energy. | |
Definition at line 19 of file Remesher.hpp.
using polyfem::mesh::Remesher::BoundaryMap = std::variant<EdgeMap<T>, FaceMap<T> > |
Definition at line 42 of file Remesher.hpp.
using polyfem::mesh::Remesher::EdgeMap = std::unordered_map< std::array<size_t, 2>, T, polyfem::utils::HashUnorderedArray<size_t, 2>, polyfem::utils::EqualUnorderedArray<size_t, 2> > |
Map from a (sorted) edge to an integer (ID)
Definition at line 26 of file Remesher.hpp.
using polyfem::mesh::Remesher::FaceMap = std::unordered_map< std::array<size_t, 3>, T, polyfem::utils::HashUnorderedArray<size_t, 3>, polyfem::utils::EqualUnorderedArray<size_t, 3> > |
Map from a (sorted) edge to an integer (ID)
Definition at line 32 of file Remesher.hpp.
using polyfem::mesh::Remesher::TetMap = std::unordered_map< std::array<size_t, 4>, T, polyfem::utils::HashUnorderedArray<size_t, 4>, polyfem::utils::EqualUnorderedArray<size_t, 4> > |
Definition at line 37 of file Remesher.hpp.
polyfem::mesh::Remesher::Remesher | ( | const State & | state, |
const Eigen::MatrixXd & | obstacle_displacements, | ||
const Eigen::MatrixXd & | obstacle_quantities, | ||
const double | current_time, | ||
const double | starting_energy | ||
) |
Construct a new Remesher object.
state | Simulation current state |
Definition at line 21 of file Remesher.cpp.
|
virtualdefault |
|
pure virtual |
Exports body ids of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by init().
|
pure virtual |
Exports boundary edges of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by project_quantities().
|
pure virtual |
Exports boundary faces of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by project_quantities().
|
pure virtual |
Exports boundary ids of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
|
pure virtual |
Get the boundary nodes of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by project_quantities().
|
static |
Build bases for a given mesh (V, F)
V | Matrix of vertex (rest) positions |
F | Matrix of elements indices |
bases | Output element bases |
vertex_to_basis | Map from vertex to reordered nodes |
Definition at line 254 of file Remesher.cpp.
References polyfem::basis::LagrangeBasis2d::build_bases(), polyfem::basis::LagrangeBasis3d::build_bases(), polyfem::mesh::Mesh::dimension(), polyfem::mesh::Mesh::n_vertices(), and polyfem::mesh::Mesh::point().
Referenced by polyfem::mesh::LocalMesh< M >::build_bases(), polyfem::mesh::LocalRelaxationData< M >::init_bases(), and project_quantities().
|
protected |
Cache quantities before applying an operation.
Definition at line 87 of file Remesher.cpp.
References elements(), polyfem::mesh::Remesher::GlobalProjectionCache::elements, global_projection_cache, projection_quantities(), polyfem::mesh::Remesher::GlobalProjectionCache::projection_quantities, rest_positions(), and polyfem::mesh::Remesher::GlobalProjectionCache::rest_positions.
|
static |
Combine the quantities of a time integrator into a single matrix (one column per quantity)
Definition at line 375 of file Remesher.cpp.
References projection_quantities(), and x.
Referenced by polyfem::State::remesh().
|
pure virtual |
Dimension of the mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by is_volume(), project_quantities(), and write_mesh().
|
pure virtual |
Exports positions of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by write_mesh().
|
pure virtual |
Exports edges of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
|
pure virtual |
Exports elements of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by cache_before(), init(), project_quantities(), and write_mesh().
|
pure virtual |
Execute the remeshing.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
|
virtual |
Initialize the mesh.
rest_positions | Rest positions of the mesh (|V| × dim) |
positions | Current positions of the mesh (|V| × dim) |
elements | Elements of the mesh (|T| × (dim + 1)) |
projection_quantities | Quantities to be projected to the new mesh (dim rows per vertex and 1 column per quantity) |
edge_to_boundary_id | Map from edge to boundary id (of size |E|) |
body_ids | Body ids of the mesh (of size |T|) |
Reimplemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Definition at line 35 of file Remesher.cpp.
References body_ids(), elements(), init_attributes_and_connectivity(), positions(), projection_quantities(), rest_positions(), set_body_ids(), set_boundary_ids(), set_fixed(), set_positions(), set_projection_quantities(), and set_rest_positions().
Referenced by polyfem::mesh::WildRemesher< WMTKMesh >::init().
void polyfem::mesh::Remesher::init_assembler | ( | const std::vector< int > & | body_ids | ) | const |
Create an assembler object.
body_ids | One body ID per element. |
|
protectedpure virtual |
Create an internal mesh representation and associate attributes.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by init().
|
inlinevirtual |
Is the mesh a volumetric mesh.
Definition at line 102 of file Remesher.hpp.
References dim().
Referenced by project_quantities(), and polyfem::mesh::PhysicsRemesher< wmtk::TetMesh >::smooth_after().
|
static |
Definition at line 414 of file Remesher.cpp.
References polyfem::logger(), num_solves, timings, total_ndofs, and total_time.
|
pure virtual |
Number of projection quantities (not including the position)
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by project_quantities().
|
inline |
Get a reference to the collision obstacles.
Definition at line 131 of file Remesher.hpp.
References polyfem::State::obstacle, and state.
Referenced by project_quantities(), and write_mesh().
|
inline |
Get a reference to the collision obstacles' displacements.
Definition at line 133 of file Remesher.hpp.
References m_obstacle_displacements.
Referenced by write_mesh().
|
inline |
Get a reference to the collision obstacles' extra quantities.
Definition at line 135 of file Remesher.hpp.
References m_obstacle_quantities.
Referenced by project_quantities(), and write_mesh().
|
pure virtual |
Exports displacements of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by init().
|
protected |
Update the mesh positions and other projection quantities.
Definition at line 94 of file Remesher.cpp.
References polyfem::utils::append_rows(), polyfem::State::args, polyfem::assembler::Mass::assemble(), polyfem::assembler::MassMatrixAssembler::assemble_cross(), boundary_edges(), boundary_faces(), boundary_nodes(), build_bases(), cache, polyfem::mesh::constrained_L2_projection(), polyfem::solver::SolveData::contact_form, polyfem::mesh::Mesh::create(), dim(), elements(), polyfem::mesh::Remesher::GlobalProjectionCache::elements, polyfem::State::formulation(), global_projection_cache, is_volume(), polyfem::State::make_nl_solver(), polyfem::utils::map_index_matrix(), n_quantities(), polyfem::mesh::Obstacle::n_vertices(), polyfem::mesh::Obstacle::ndof(), obstacle(), obstacle_quantities(), POLYFEM_REMESHER_SCOPED_TIMER, projection_quantities(), polyfem::mesh::Remesher::GlobalProjectionCache::projection_quantities, polyfem::utils::reorder_matrix(), rest_positions(), polyfem::mesh::Remesher::GlobalProjectionCache::rest_positions, set_projection_quantities(), polyfem::State::solve_data, state, polyfem::mesh::unconstrained_L2_projection(), and polyfem::utils::unreorder_matrix().
|
pure virtual |
Exports projected quantities of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by cache_before(), combine_time_integrator_quantities(), init(), project_quantities(), and write_mesh().
|
pure virtual |
Exports rest positions of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by cache_before(), init(), project_quantities(), and write_mesh().
|
pure virtual |
Set the body IDs of all elements.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by init().
|
pure virtual |
Set the boundary IDs of all edges.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by init().
|
pure virtual |
Set if a vertex is fixed.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by init().
|
pure virtual |
Set deformed positions of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by init().
|
pure virtual |
Set projected quantities of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by init(), and project_quantities().
|
pure virtual |
Set rest positions of the stored mesh.
Implemented in polyfem::mesh::WildRemesher< WMTKMesh >, polyfem::mesh::WildRemesher< wmtk::TetMesh >, and polyfem::mesh::WildRemesher< wmtk::TriMesh >.
Referenced by init().
|
static |
Split the quantities of a time integrator into separate vectors.
Definition at line 396 of file Remesher.cpp.
Referenced by polyfem::mesh::LocalRelaxationData< M >::init_solve_data(), and polyfem::State::remesh().
void polyfem::mesh::Remesher::write_mesh | ( | const std::string & | path | ) | const |
Writes a VTU mesh file.
path | Output path |
Definition at line 314 of file Remesher.cpp.
References polyfem::utils::append_rows(), dim(), displacements(), polyfem::mesh::Obstacle::e(), elements(), polyfem::utils::StringUtils::endswith(), polyfem::mesh::Obstacle::f(), polyfem::mesh::Obstacle::n_edges(), obstacle(), obstacle_displacements(), obstacle_quantities(), projection_quantities(), rest_positions(), and polyfem::utils::unflatten().
|
protected |
Copy of remesh args.
Definition at line 213 of file Remesher.hpp.
Referenced by polyfem::mesh::PhysicsTriRemesher::swap_edge_before().
|
protected |
Current time.
Definition at line 219 of file Remesher.hpp.
|
protected |
Definition at line 210 of file Remesher.hpp.
Referenced by cache_before(), and project_quantities().
|
protected |
Collision obstacles' displacements.
Definition at line 215 of file Remesher.hpp.
Referenced by obstacle_displacements().
|
protected |
Collision obstacles' extra quantities.
Definition at line 217 of file Remesher.hpp.
Referenced by obstacle_quantities().
int polyfem::mesh::Remesher::max_op_attempts = 1 |
Definition at line 196 of file Remesher.hpp.
|
static |
Definition at line 231 of file Remesher.hpp.
Referenced by log_timings().
|
protected |
Starting energy.
Definition at line 221 of file Remesher.hpp.
const State& polyfem::mesh::Remesher::state |
Reference to the simulation state.
Definition at line 191 of file Remesher.hpp.
Referenced by obstacle(), project_quantities(), and polyfem::mesh::WildRemesher< wmtk::TetMesh >::smooth_vertices().
|
static |
Timings for the remeshing operations.
Definition at line 229 of file Remesher.hpp.
Referenced by log_timings().
|
static |
Definition at line 232 of file Remesher.hpp.
Referenced by log_timings().
|
static |
Definition at line 230 of file Remesher.hpp.
Referenced by log_timings().