MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / create_subgeometry

Function create_subgeometry

cpp/dolfinx/mesh/utils.h:1331–1413  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1329/// degree-of-freedom to the coordinate degree-of-freedom in `geometry`.
1330template <std::floating_point T>
1331std::pair<Geometry<T>, std::vector<int32_t>>
1332create_subgeometry(const Mesh<T>& mesh, int dim,
1333 std::span<const std::int32_t> subentity_to_entity)
1334{
1335 const Geometry<T>& geometry = mesh.geometry();
1336
1337 // Get the geometry dofs in the sub-geometry based on the entities in
1338 // sub-geometry
1339 const fem::ElementDofLayout layout
1340 = geometry.cmaps().front().create_dof_layout();
1341
1342 const std::vector<std::int32_t> x_indices
1343 = entities_to_geometry(mesh, dim, subentity_to_entity, true).first;
1344
1345 std::vector<std::int32_t> sub_x_dofs = x_indices;
1346 std::ranges::sort(sub_x_dofs);
1347 auto [unique_end, range_end] = std::ranges::unique(sub_x_dofs);
1348 sub_x_dofs.erase(unique_end, range_end);
1349
1350 // Get the sub-geometry dofs owned by this process
1351 auto x_index_map = geometry.index_map();
1352 assert(x_index_map);
1353
1354 std::shared_ptr<common::IndexMap> sub_x_dof_index_map;
1355 std::vector<std::int32_t> subx_to_x_dofmap;
1356 {
1357 auto [map, new_to_old] = common::create_sub_index_map(
1358 *x_index_map, sub_x_dofs, common::IndexMapOrder::any, true);
1359 sub_x_dof_index_map = std::make_shared<common::IndexMap>(std::move(map));
1360 subx_to_x_dofmap = std::move(new_to_old);
1361 }
1362
1363 // Create sub-geometry coordinates
1364 std::span<const T> x = geometry.x();
1365 std::int32_t sub_num_x_dofs = subx_to_x_dofmap.size();
1366 std::vector<T> sub_x(3 * sub_num_x_dofs);
1367 for (std::int32_t i = 0; i < sub_num_x_dofs; ++i)
1368 {
1369 std::copy_n(std::next(x.begin(), 3 * subx_to_x_dofmap[i]), 3,
1370 std::next(sub_x.begin(), 3 * i));
1371 }
1372
1373 // Create geometry to sub-geometry map
1374 std::vector<std::int32_t> x_to_subx_dof_map(
1375 x_index_map->size_local() + x_index_map->num_ghosts(), -1);
1376 for (std::size_t i = 0; i < subx_to_x_dofmap.size(); ++i)
1377 x_to_subx_dof_map[subx_to_x_dofmap[i]] = i;
1378
1379 // Create sub-geometry dofmap
1380 std::vector<std::int32_t> sub_x_dofmap;
1381 sub_x_dofmap.reserve(x_indices.size());
1382 std::ranges::transform(x_indices, std::back_inserter(sub_x_dofmap),
1383 [&x_to_subx_dof_map](auto x_dof)
1384 {
1385 assert(x_to_subx_dof_map[x_dof] != -1);
1386 return x_to_subx_dof_map[x_dof];
1387 });
1388

Callers 1

create_submeshFunction · 0.85

Calls 15

transformFunction · 0.85
cell_entity_typeFunction · 0.85
geometryMethod · 0.80
cmapsMethod · 0.80
size_localMethod · 0.80
num_ghostsMethod · 0.80
cell_shapeMethod · 0.80
input_global_indicesMethod · 0.80
entities_to_geometryFunction · 0.70
GeometryClass · 0.70
create_dof_layoutMethod · 0.45
index_mapMethod · 0.45

Tested by

no test coverage detected