int main( int argc, char *argv[] ) { gdouble max_area = 0.0001; gdouble min_angle = RADIANS(15.0); guint niter = 10; Polygon *p = polygon_create_box( 0.0, 0.0, 1.0, 1.0 ); /* Polygon *p = polygon_create_island(); */ /* Polygon *p = polygon_create_A(); */ /* ELEMENT QUALITY SMOOTHING */ Mesh * mesh = mesh_triangulate_polygon( p ); mesh_make_cdt_by_edge_flipping( mesh ); polygon_free( p ); mesh_refine( mesh, RUPPERT_REFINEMENT, max_area, min_angle ); mesh_relax( mesh ); mesh_smooth( mesh, ELEMENT_QUALITY_SMOOTHING, niter, max_area ); mesh_relax( mesh ); mesh_smooth( mesh, ELEMENT_QUALITY_SMOOTHING, niter, max_area ); mesh_save_to_eps( "mesh.eps", mesh ); mesh_save_to_obj( "mesh.obj", mesh ); mesh_free( mesh ); return EXIT_SUCCESS; }
void EquationSystems::init () { const unsigned int n_sys = this->n_systems(); libmesh_assert_not_equal_to (n_sys, 0); // Distribute the mesh if possible if (this->n_processors() > 1) _mesh.delete_remote_elements(); // Tell all the \p DofObject entities how many systems // there are. { MeshBase::node_iterator node_it = _mesh.nodes_begin(); const MeshBase::node_iterator node_end = _mesh.nodes_end(); for ( ; node_it != node_end; ++node_it) (*node_it)->set_n_systems(n_sys); MeshBase::element_iterator elem_it = _mesh.elements_begin(); const MeshBase::element_iterator elem_end = _mesh.elements_end(); for ( ; elem_it != elem_end; ++elem_it) (*elem_it)->set_n_systems(n_sys); } for (unsigned int i=0; i != this->n_systems(); ++i) this->get_system(i).init(); #ifdef LIBMESH_ENABLE_AMR MeshRefinement mesh_refine(_mesh); mesh_refine.clean_refinement_flags(); #endif }
int test_refine( int argc, char *argv[] ) { /* Polygon *p = polygon_create_box( 0.0, 0.0, 1.0, 1.0 ); */ Polygon *p = polygon_create_island(); Mesh *mesh = mesh_triangulate_polygon( p ); mesh_save_to_eps( "test_refine_1.eps", mesh ); polygon_free( p ); mesh_make_cdt_by_edge_flipping( mesh ); mesh_save_to_eps( "test_refine_2.eps", mesh ); mesh_refine( mesh, RUPPERT_REFINEMENT, 0.0007, RADIANS(30) ); mesh_save_to_eps( "test_refine_3.eps", mesh ); mesh_save_to_ply( "test_refine_3.ply", mesh ); mesh_save_to_poly( "test_refine_3.poly", mesh ); mesh_save_to_obj( "test_refine_3.obj", mesh ); mesh_save_to_off( "test_refine_3.off", mesh ); mesh_free( mesh ); return EXIT_SUCCESS; }
void mesh_refine_all(mesh* m) { mflag* f = mflag_new_all(m, mesh_elem(m)); mesh_refine(m, f); mflag_free(f); }
void EquationSystems::reinit () { parallel_object_only(); const unsigned int n_sys = this->n_systems(); libmesh_assert_not_equal_to (n_sys, 0); // We may have added new systems since our last // EquationSystems::(re)init call bool _added_new_systems = false; for (unsigned int i=0; i != n_sys; ++i) if (!this->get_system(i).is_initialized()) _added_new_systems = true; if (_added_new_systems) { // Our DofObjects will need space for the additional systems MeshBase::node_iterator node_it = _mesh.nodes_begin(); const MeshBase::node_iterator node_end = _mesh.nodes_end(); for ( ; node_it != node_end; ++node_it) (*node_it)->set_n_systems(n_sys); MeshBase::element_iterator elem_it = _mesh.elements_begin(); const MeshBase::element_iterator elem_end = _mesh.elements_end(); for ( ; elem_it != elem_end; ++elem_it) (*elem_it)->set_n_systems(n_sys); // And any new systems will need initialization for (unsigned int i=0; i != n_sys; ++i) if (!this->get_system(i).is_initialized()) this->get_system(i).init(); } #ifdef DEBUG // Make sure all the \p DofObject entities know how many systems // there are. { // All the nodes MeshBase::node_iterator node_it = _mesh.nodes_begin(); const MeshBase::node_iterator node_end = _mesh.nodes_end(); for ( ; node_it != node_end; ++node_it) { Node *node = *node_it; libmesh_assert_equal_to (node->n_systems(), this->n_systems()); } // All the elements MeshBase::element_iterator elem_it = _mesh.elements_begin(); const MeshBase::element_iterator elem_end = _mesh.elements_end(); for ( ; elem_it != elem_end; ++elem_it) { Elem *elem = *elem_it; libmesh_assert_equal_to (elem->n_systems(), this->n_systems()); } } #endif // Localize each system's vectors for (unsigned int i=0; i != this->n_systems(); ++i) this->get_system(i).re_update(); #ifdef LIBMESH_ENABLE_AMR bool dof_constraints_created = false; bool mesh_changed = false; // FIXME: For backwards compatibility, assume // refine_and_coarsen_elements or refine_uniformly have already // been called { for (unsigned int i=0; i != this->n_systems(); ++i) { System &sys = this->get_system(i); // Even if the system doesn't have any variables in it we want // consistent behavior; e.g. distribute_dofs should have the // opportunity to count up zero dofs on each processor. // // Who's been adding zero-var systems anyway, outside of my // unit tests? - RHS // if(!sys.n_vars()) // continue; sys.get_dof_map().distribute_dofs(_mesh); // Recreate any user or internal constraints sys.reinit_constraints(); sys.prolong_vectors(); } mesh_changed = true; dof_constraints_created = true; } // FIXME: Where should the user set maintain_level_one now?? // Don't override previous settings, for now MeshRefinement mesh_refine(_mesh); mesh_refine.face_level_mismatch_limit() = false; // Try to coarsen the mesh, then restrict each system's vectors // if necessary if (mesh_refine.coarsen_elements()) { for (unsigned int i=0; i != this->n_systems(); ++i) { System &sys = this->get_system(i); if (!dof_constraints_created) { sys.get_dof_map().distribute_dofs(_mesh); sys.reinit_constraints(); } sys.restrict_vectors(); } mesh_changed = true; dof_constraints_created = true; } // Once vectors are all restricted, we can delete // children of coarsened elements if (mesh_changed) this->get_mesh().contract(); // Try to refine the mesh, then prolong each system's vectors // if necessary if (mesh_refine.refine_elements()) { for (unsigned int i=0; i != this->n_systems(); ++i) { System &sys = this->get_system(i); if (!dof_constraints_created) { sys.get_dof_map().distribute_dofs(_mesh); sys.reinit_constraints(); } sys.prolong_vectors(); } mesh_changed = true; // dof_constraints_created = true; } // If the mesh has changed, systems will need to create new dof // constraints and update their global solution vectors if (mesh_changed) { for (unsigned int i=0; i != this->n_systems(); ++i) this->get_system(i).reinit(); } #endif // #ifdef LIBMESH_ENABLE_AMR }