diff --git a/cpp/Contact.cpp b/cpp/Contact.cpp index 9ad25b92..5e6d8cd4 100644 --- a/cpp/Contact.cpp +++ b/cpp/Contact.cpp @@ -459,17 +459,16 @@ Contact::generate_kernel(Kernel type, //---------------------------------------------------------------------------- void Contact::create_q_phys(int origin_meshtag) { - // Get information depending on surface - - std::vector submesh_facets + std::vector facets = _submesh.get_submesh_tuples(_cell_facet_pairs.links(origin_meshtag)); - auto mesh_sub = _submesh.mesh(); - std::size_t gdim = mesh_sub->geometry().dim(); + + auto mesh = _submesh.mesh(); + std::size_t gdim = mesh->geometry().dim(); const std::vector& qp_offsets = _quadrature_rule.offset(); _qp_phys[origin_meshtag].resize((qp_offsets[1] - qp_offsets[0]) - * (submesh_facets.size() / 2) * gdim); + * (facets.size() / 2) * gdim); compute_physical_points( - *mesh_sub, submesh_facets, qp_offsets, + *mesh, facets, qp_offsets, mdspan_t(_reference_basis.data(), _reference_shape), _qp_phys[origin_meshtag]); } diff --git a/cpp/SubMesh.cpp b/cpp/SubMesh.cpp index 5e9a3cc0..c0f97d0b 100644 --- a/cpp/SubMesh.cpp +++ b/cpp/SubMesh.cpp @@ -13,30 +13,24 @@ using namespace dolfinx_contact; SubMesh::SubMesh(const dolfinx::mesh::Mesh& mesh, std::span cell_facet_pairs) { - const int tdim = mesh.topology()->dim(); + int tdim = mesh.topology()->dim(); - // Copy cell indices + // Build list in unique cell indices std::vector cells(cell_facet_pairs.size() / 2); for (std::size_t f = 0; f < cell_facet_pairs.size() / 2; ++f) cells[f] = cell_facet_pairs[2 * f]; - - // sort cells and remove duplicates dolfinx::radix_sort(std::span(cells.data(), cells.size())); cells.erase(std::unique(cells.begin(), cells.end()), cells.end()); - // save sorted cell vector as _parent_cells - - // call dolfinx::mesh::create_submesh and save ouput to member - // variables + // Create sub-mesh of cells auto [submesh, cell_map, vertex_map, x_dof_map] = dolfinx::mesh::create_submesh(mesh, tdim, cells); - _parent_cells = cell_map; - _mesh = std::make_shared>(submesh); + _parent_cells = cell_map; _submesh_to_mesh_vertex_map = vertex_map; _submesh_to_mesh_x_dof_map = x_dof_map; - // create/retrieve connectivities on submesh + // Create/retrieve connectivities on submesh _mesh->topology_mutable()->create_connectivity(tdim - 1, tdim); std::shared_ptr> f_to_c = _mesh->topology()->connectivity(tdim - 1, tdim); @@ -51,12 +45,12 @@ SubMesh::SubMesh(const dolfinx::mesh::Mesh& mesh, // in adjacency list if it is contained, it has exactly one link, the // submesh cell index - // get number of cells on process + // Get number of cells on this rank in parent mesh std::shared_ptr map_c = mesh.topology()->index_map(tdim); const std::int32_t num_cells = map_c->size_local() + map_c->num_ghosts(); - // mark which cells are in cells, i.e. which cells are in the submesh + // Mark cells in parent mesh that are in the submesh std::vector marked_cells(num_cells, 0); for (auto cell : cells) marked_cells[cell] = 1; @@ -69,7 +63,7 @@ SubMesh::SubMesh(const dolfinx::mesh::Mesh& mesh, // fill data array std::vector data(offsets.back()); for (std::size_t c = 0; c < cells.size(); ++c) - data[offsets[cells[c]]] = (std::int32_t)c; + data[offsets[cells[c]]] = c; // create adjacency list _mesh_to_submesh_cell_map @@ -80,10 +74,10 @@ SubMesh::SubMesh(const dolfinx::mesh::Mesh& mesh, // Create facet to (cell, local_facet) map for exterior facet from the // original input { - // Retrieve number of facets on process + // Get number of facets on this rank std::shared_ptr map_f = _mesh->topology()->index_map(tdim - 1); - int num_facets = map_f->size_local() + map_f->num_ghosts(); + std::int32_t num_facets = map_f->size_local() + map_f->num_ghosts(); // mark which facets are in any of the facet lists @@ -131,15 +125,15 @@ SubMesh::SubMesh(const dolfinx::mesh::Mesh& mesh, } //---------------------------------------------------------------------------- dolfinx::fem::FunctionSpace SubMesh::create_functionspace( - const dolfinx::fem::FunctionSpace& V_parent) const + const dolfinx::fem::FunctionSpace& V) const { // get element and element_dof_layout from parent mesh std::shared_ptr> element - = V_parent.element(); + = V.element(); const dolfinx::fem::ElementDofLayout& element_dof_layout - = V_parent.dofmap()->element_dof_layout(); + = V.dofmap()->element_dof_layout(); - // use parent mesh data and submesh comm/topology to create new dofmap + // Use parent mesh data and submesh comm/topology to create new dofmap std::function, std::uint32_t)> unpermute_dofs; if (element->needs_dof_permutations()) unpermute_dofs = element->dof_permutation_fn(true, true); @@ -148,8 +142,8 @@ dolfinx::fem::FunctionSpace SubMesh::create_functionspace( dolfinx::fem::create_dofmap(_mesh->comm(), element_dof_layout, *_mesh->topology(), unpermute_dofs, nullptr)); - // create and return function space - std::span vs = V_parent.value_shape(); + // Create and return function space + std::span vs = V.value_shape(); std::vector _value_shape(vs.data(), vs.data() + vs.size()); return dolfinx::fem::FunctionSpace(_mesh, element, dofmap, _value_shape); diff --git a/cpp/SubMesh.h b/cpp/SubMesh.h index 8c02fd2a..92f00faa 100644 --- a/cpp/SubMesh.h +++ b/cpp/SubMesh.h @@ -61,18 +61,14 @@ class SubMesh /// Return parent cells: parent_cells()[i] is the cell in the parent /// mesh for ith cell in submesh - std::span parent_cells() const - { - return std::span(_parent_cells.data(), - _parent_cells.size()); - } + std::span parent_cells() const { return _parent_cells; } /// Create FunctionSpace on submesh that is identical with a given /// FunctionSpace on the parent mesh but restricted to submesh - /// @param[in] V_parent the function space on the the parent mesh + /// @param[in] V the function space on the the parent mesh /// @return the function space on the submesh - dolfinx::fem::FunctionSpace create_functionspace( - const dolfinx::fem::FunctionSpace& V_parent) const; + dolfinx::fem::FunctionSpace + create_functionspace(const dolfinx::fem::FunctionSpace& V) const; /// Copy of a function on the parent mesh/ in the parent function /// space to submesh/ function space on submesh