Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/dolfinx/v0.9.0/cpp/doxygen/d6/db4/plaza_8h_source.html
DOLFINx 0.8.0
DOLFINx C++ interface
Loading...
Searching...
No Matches
plaza.h
1// Copyright (C) 2014-2018 Chris Richardson
2//
3// This file is part of DOLFINx (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#include "utils.h"
8#include <cstdint>
9#include <dolfinx/common/MPI.h>
10#include <dolfinx/graph/AdjacencyList.h>
11#include <dolfinx/mesh/Geometry.h>
12#include <dolfinx/mesh/Mesh.h>
13#include <dolfinx/mesh/Topology.h>
14#include <dolfinx/mesh/utils.h>
15#include <span>
16#include <tuple>
17#include <utility>
18#include <vector>
19
20#pragma once
21
28{
29
31enum class Option : int
32{
33 none = 0,
35 = 1,
37 = 2,
40};
41
42namespace impl
43{
47template <int tdim>
48std::vector<std::int8_t>
49compute_parent_facets(std::span<const std::int32_t> simplex_set)
50{
51 {
52 assert(simplex_set.size() % (tdim + 1) == 0);
53 std::vector<std::int8_t> parent_facet(simplex_set.size(), -1);
54
55 // Index lookups in 'indices' for the child vertices that occur on
56 // each parent facet in 2D and 3D. In 2D each edge has 3 child
57 // vertices, and in 3D each triangular facet has six child vertices.
58 constexpr std::array<std::array<int, 3>, 3> facet_table_2d{
59 {{1, 2, 3}, {0, 2, 4}, {0, 1, 5}}};
60
61 constexpr std::array<std::array<int, 6>, 4> facet_table_3d{
62 {{1, 2, 3, 4, 5, 6},
63 {0, 2, 3, 4, 7, 8},
64 {0, 1, 3, 5, 7, 9},
65 {0, 1, 2, 6, 8, 9}}};
66
67 const int ncells = simplex_set.size() / (tdim + 1);
68 for (int fpi = 0; fpi < (tdim + 1); ++fpi)
69 {
70 // For each child cell, consider all facets
71 for (int cc = 0; cc < ncells; ++cc)
72 {
73 for (int fci = 0; fci < (tdim + 1); ++fci)
74 {
75 // Indices of all vertices on child facet, sorted
76 std::array<int, tdim> cf, set_output;
77
78 int num_common_vertices;
79 if constexpr (tdim == 2)
80 {
81 for (int j = 0; j < tdim; ++j)
82 cf[j] = simplex_set[cc * 3 + facet_table_2d[fci][j]];
83 std::sort(cf.begin(), cf.end());
84 auto it = std::set_intersection(
85 facet_table_2d[fpi].begin(), facet_table_2d[fpi].end(),
86 cf.begin(), cf.end(), set_output.begin());
87 num_common_vertices = std::distance(set_output.begin(), it);
88 }
89 else
90 {
91 for (int j = 0; j < tdim; ++j)
92 cf[j] = simplex_set[cc * 4 + facet_table_3d[fci][j]];
93 std::sort(cf.begin(), cf.end());
94 auto it = std::set_intersection(
95 facet_table_3d[fpi].begin(), facet_table_3d[fpi].end(),
96 cf.begin(), cf.end(), set_output.begin());
97 num_common_vertices = std::distance(set_output.begin(), it);
98 }
99
100 if (num_common_vertices == tdim)
101 {
102 assert(parent_facet[cc * (tdim + 1) + fci] == -1);
103 // Child facet "fci" of cell cc, lies on parent facet "fpi"
104 parent_facet[cc * (tdim + 1) + fci] = fpi;
105 }
106 }
107 }
108 }
109
110 return parent_facet;
111 }
112}
113
130std::vector<std::int32_t>
131get_simplices(std::span<const std::int64_t> indices,
132 std::span<const std::int32_t> longest_edge, int tdim,
133 bool uniform);
134
137void enforce_rules(MPI_Comm comm, const graph::AdjacencyList<int>& shared_edges,
138 std::vector<std::int8_t>& marked_edges,
139 const mesh::Topology& topology,
140 std::span<const std::int32_t> long_edge);
141
151template <std::floating_point T>
152std::pair<std::vector<std::int32_t>, std::vector<std::int8_t>>
153face_long_edge(const mesh::Mesh<T>& mesh)
154{
155 const int tdim = mesh.topology()->dim();
156 // FIXME: cleanup these calls? Some of the happen internally again.
157 mesh.topology_mutable()->create_entities(1);
158 mesh.topology_mutable()->create_entities(2);
159 mesh.topology_mutable()->create_connectivity(2, 1);
160 mesh.topology_mutable()->create_connectivity(1, tdim);
161 mesh.topology_mutable()->create_connectivity(tdim, 2);
162
163 std::int64_t num_faces = mesh.topology()->index_map(2)->size_local()
164 + mesh.topology()->index_map(2)->num_ghosts();
165
166 // Storage for face-local index of longest edge
167 std::vector<std::int32_t> long_edge(num_faces);
168 std::vector<std::int8_t> edge_ratio_ok;
169
170 // Check mesh face quality (may be used in 2D to switch to "uniform"
171 // refinement)
172 const T min_ratio = sqrt(2.0) / 2.0;
173 if (tdim == 2)
174 edge_ratio_ok.resize(num_faces);
175
176 auto x_dofmap = mesh.geometry().dofmap();
177
178 auto c_to_v = mesh.topology()->connectivity(tdim, 0);
179 assert(c_to_v);
180 auto e_to_c = mesh.topology()->connectivity(1, tdim);
181 assert(e_to_c);
182 auto e_to_v = mesh.topology()->connectivity(1, 0);
183 assert(e_to_v);
184
185 // Store all edge lengths in Mesh to save recalculating for each Face
186 auto map_e = mesh.topology()->index_map(1);
187 assert(map_e);
188 std::vector<T> edge_length(map_e->size_local() + map_e->num_ghosts());
189 for (std::size_t e = 0; e < edge_length.size(); ++e)
190 {
191 // Get first attached cell
192 auto cells = e_to_c->links(e);
193 assert(!cells.empty());
194 auto cell_vertices = c_to_v->links(cells.front());
195 auto edge_vertices = e_to_v->links(e);
196
197 // Find local index of edge vertices in the cell geometry map
198 auto it0 = std::find(cell_vertices.begin(), cell_vertices.end(),
199 edge_vertices[0]);
200 assert(it0 != cell_vertices.end());
201 const std::size_t local0 = std::distance(cell_vertices.begin(), it0);
202 auto it1 = std::find(cell_vertices.begin(), cell_vertices.end(),
203 edge_vertices[1]);
204 assert(it1 != cell_vertices.end());
205 const std::size_t local1 = std::distance(cell_vertices.begin(), it1);
206
207 auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
208 x_dofmap, cells.front(), MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
209 std::span<const T, 3> x0(mesh.geometry().x().data() + 3 * x_dofs[local0],
210 3);
211 std::span<const T, 3> x1(mesh.geometry().x().data() + 3 * x_dofs[local1],
212 3);
213
214 // Compute length of edge between vertex x0 and x1
215 edge_length[e] = std::sqrt(std::transform_reduce(
216 x0.begin(), x0.end(), x1.begin(), 0.0, std::plus<>(),
217 [](auto x0, auto x1) { return (x0 - x1) * (x0 - x1); }));
218 }
219
220 // Get longest edge of each face
221 auto f_to_v = mesh.topology()->connectivity(2, 0);
222 assert(f_to_v);
223 auto f_to_e = mesh.topology()->connectivity(2, 1);
224 assert(f_to_e);
225 const std::vector global_indices
226 = mesh.topology()->index_map(0)->global_indices();
227 for (int f = 0; f < f_to_v->num_nodes(); ++f)
228 {
229 auto face_edges = f_to_e->links(f);
230
231 std::int32_t imax = 0;
232 T max_len = 0.0;
233 T min_len = std::numeric_limits<T>::max();
234
235 for (int i = 0; i < 3; ++i)
236 {
237 const T e_len = edge_length[face_edges[i]];
238 min_len = std::min(e_len, min_len);
239 if (e_len > max_len)
240 {
241 max_len = e_len;
242 imax = i;
243 }
244 else if (tdim == 3 and e_len == max_len)
245 {
246 // If edges are the same length, compare global index of
247 // opposite vertex. Only important so that tetrahedral faces
248 // have a matching refinement pattern across processes.
249 auto vertices = f_to_v->links(f);
250 const int vmax = vertices[imax];
251 const int vi = vertices[i];
252 if (global_indices[vi] > global_indices[vmax])
253 imax = i;
254 }
255 }
256
257 // Only save edge ratio in 2D
258 if (tdim == 2)
259 edge_ratio_ok[f] = (min_len / max_len >= min_ratio);
260
261 long_edge[f] = face_edges[imax];
262 }
263
264 return std::pair(std::move(long_edge), std::move(edge_ratio_ok));
265}
266
291template <std::floating_point T>
292std::tuple<graph::AdjacencyList<std::int64_t>, std::vector<T>,
293 std::array<std::size_t, 2>, std::vector<std::int32_t>,
294 std::vector<std::int8_t>>
295compute_refinement(MPI_Comm neighbor_comm,
296 const std::vector<std::int8_t>& marked_edges,
297 const graph::AdjacencyList<int>& shared_edges,
298 const mesh::Mesh<T>& mesh,
299 const std::vector<std::int32_t>& long_edge,
300 const std::vector<std::int8_t>& edge_ratio_ok,
301 plaza::Option option)
302{
303 int tdim = mesh.topology()->dim();
304 int num_cell_edges = tdim * 3 - 3;
305 int num_cell_vertices = tdim + 1;
306 bool compute_facets = (option == plaza::Option::parent_facet
308 bool compute_parent_cell
309 = (option == plaza::Option::parent_cell
311
312 // Make new vertices in parallel
313 const auto [new_vertex_map, new_vertex_coords, xshape]
314 = create_new_vertices(neighbor_comm, shared_edges, mesh, marked_edges);
315
316 std::vector<std::int32_t> parent_cell;
317 std::vector<std::int8_t> parent_facet;
318 std::vector<std::int64_t> indices(num_cell_vertices + num_cell_edges);
319 std::vector<std::int32_t> simplex_set;
320
321 auto map_c = mesh.topology()->index_map(tdim);
322 assert(map_c);
323 auto c_to_v = mesh.topology()->connectivity(tdim, 0);
324 assert(c_to_v);
325 auto c_to_e = mesh.topology()->connectivity(tdim, 1);
326 assert(c_to_e);
327 auto c_to_f = mesh.topology()->connectivity(tdim, 2);
328 assert(c_to_f);
329
330 std::int32_t num_new_vertices_local = std::count(
331 marked_edges.begin(),
332 marked_edges.begin() + mesh.topology()->index_map(1)->size_local(), true);
333
334 std::vector<std::int64_t> global_indices
335 = adjust_indices(*mesh.topology()->index_map(0), num_new_vertices_local);
336
337 const int num_cells = map_c->size_local();
338
339 // Iterate over all cells, and refine if cell has a marked edge
340 std::vector<std::int64_t> cell_topology;
341 for (int c = 0; c < num_cells; ++c)
342 {
343 // Create vector of indices in the order [vertices][edges], 3+3 in
344 // 2D, 4+6 in 3D
345
346 // Copy vertices
347 auto vertices = c_to_v->links(c);
348 for (std::size_t v = 0; v < vertices.size(); ++v)
349 indices[v] = global_indices[vertices[v]];
350
351 // Get cell-local indices of marked edges
352 auto edges = c_to_e->links(c);
353 bool no_edge_marked = true;
354 for (std::size_t ei = 0; ei < edges.size(); ++ei)
355 {
356 if (marked_edges[edges[ei]])
357 {
358 no_edge_marked = false;
359 auto it = new_vertex_map.find(edges[ei]);
360 assert(it != new_vertex_map.end());
361 indices[num_cell_vertices + ei] = it->second;
362 }
363 else
364 indices[num_cell_vertices + ei] = -1;
365 }
366
367 if (no_edge_marked)
368 {
369 // Copy over existing cell to new topology
370 for (auto v : vertices)
371 cell_topology.push_back(global_indices[v]);
372
373 if (compute_parent_cell)
374 parent_cell.push_back(c);
375
376 if (compute_facets)
377 {
378 if (tdim == 3)
379 parent_facet.insert(parent_facet.end(), {0, 1, 2, 3});
380 else
381 parent_facet.insert(parent_facet.end(), {0, 1, 2});
382 }
383 }
384 else
385 {
386 // Need longest edges of each face in cell local indexing. NB in
387 // 2D the face is the cell itself, and there is just one entry.
388 std::vector<std::int32_t> longest_edge;
389 for (auto f : c_to_f->links(c))
390 longest_edge.push_back(long_edge[f]);
391
392 // Convert to cell local index
393 for (std::int32_t& p : longest_edge)
394 {
395 for (std::size_t ej = 0; ej < edges.size(); ++ej)
396 {
397 if (p == edges[ej])
398 {
399 p = ej;
400 break;
401 }
402 }
403 }
404
405 const bool uniform = (tdim == 2) ? edge_ratio_ok[c] : false;
406
407 // FIXME: this has an expensive dynamic memory allocation
408 simplex_set = get_simplices(indices, longest_edge, tdim, uniform);
409
410 // Save parent index
411 const std::int32_t ncells = simplex_set.size() / num_cell_vertices;
412
413 if (compute_parent_cell)
414 {
415 for (std::int32_t i = 0; i < ncells; ++i)
416 parent_cell.push_back(c);
417 }
418
419 if (compute_facets)
420 {
421 std::vector<std::int8_t> npf;
422 if (tdim == 3)
423 npf = compute_parent_facets<3>(simplex_set);
424 else
425 npf = compute_parent_facets<2>(simplex_set);
426 parent_facet.insert(parent_facet.end(), npf.begin(), npf.end());
427 }
428
429 // Convert from cell local index to mesh index and add to cells
430 for (std::int32_t v : simplex_set)
431 cell_topology.push_back(indices[v]);
432 }
433 }
434
435 assert(cell_topology.size() % num_cell_vertices == 0);
436 std::vector<std::int32_t> offsets(
437 cell_topology.size() / num_cell_vertices + 1, 0);
438 for (std::size_t i = 0; i < offsets.size() - 1; ++i)
439 offsets[i + 1] = offsets[i] + num_cell_vertices;
440 graph::AdjacencyList cell_adj(std::move(cell_topology), std::move(offsets));
441
442 return {std::move(cell_adj), std::move(new_vertex_coords), xshape,
443 std::move(parent_cell), std::move(parent_facet)};
444}
445} // namespace impl
446
457template <std::floating_point T>
458std::tuple<mesh::Mesh<T>, std::vector<std::int32_t>, std::vector<std::int8_t>>
459refine(const mesh::Mesh<T>& mesh, bool redistribute, Option option)
460{
461 auto [cell_adj, new_coords, xshape, parent_cell, parent_facet]
462 = compute_refinement_data(mesh, option);
463
464 if (dolfinx::MPI::size(mesh.comm()) == 1)
465 {
466 return {mesh::create_mesh(mesh.comm(), cell_adj.array(),
467 mesh.geometry().cmap(), new_coords, xshape,
468 mesh::GhostMode::none),
469 std::move(parent_cell), std::move(parent_facet)};
470 }
471 else
472 {
473 std::shared_ptr<const common::IndexMap> map_c
474 = mesh.topology()->index_map(mesh.topology()->dim());
475 const int num_ghost_cells = map_c->num_ghosts();
476 // Check if mesh has ghost cells on any rank
477 // FIXME: this is not a robust test. Should be user option.
478 int max_ghost_cells = 0;
479 MPI_Allreduce(&num_ghost_cells, &max_ghost_cells, 1, MPI_INT, MPI_MAX,
480 mesh.comm());
481
482 // Build mesh
483 const mesh::GhostMode ghost_mode = max_ghost_cells == 0
484 ? mesh::GhostMode::none
485 : mesh::GhostMode::shared_facet;
486 return {partition<T>(mesh, cell_adj, std::span(new_coords), xshape,
487 redistribute, ghost_mode),
488 std::move(parent_cell), std::move(parent_facet)};
489 }
490}
491
503template <std::floating_point T>
504std::tuple<mesh::Mesh<T>, std::vector<std::int32_t>, std::vector<std::int8_t>>
505refine(const mesh::Mesh<T>& mesh, std::span<const std::int32_t> edges,
506 bool redistribute, Option option)
507{
508 auto [cell_adj, new_vertex_coords, xshape, parent_cell, parent_facet]
509 = compute_refinement_data(mesh, edges, option);
510
511 if (dolfinx::MPI::size(mesh.comm()) == 1)
512 {
513 return {mesh::create_mesh(mesh.comm(), cell_adj.array(),
514 mesh.geometry().cmap(), new_vertex_coords, xshape,
515 mesh::GhostMode::none),
516 std::move(parent_cell), std::move(parent_facet)};
517 }
518 else
519 {
520 std::shared_ptr<const common::IndexMap> map_c
521 = mesh.topology()->index_map(mesh.topology()->dim());
522 const int num_ghost_cells = map_c->num_ghosts();
523 // Check if mesh has ghost cells on any rank
524 // FIXME: this is not a robust test. Should be user option.
525 int max_ghost_cells = 0;
526 MPI_Allreduce(&num_ghost_cells, &max_ghost_cells, 1, MPI_INT, MPI_MAX,
527 mesh.comm());
528
529 // Build mesh
530 const mesh::GhostMode ghost_mode = max_ghost_cells == 0
531 ? mesh::GhostMode::none
532 : mesh::GhostMode::shared_facet;
533
534 return {partition<T>(mesh, cell_adj, new_vertex_coords, xshape,
535 redistribute, ghost_mode),
536 std::move(parent_cell), std::move(parent_facet)};
537 }
538}
539
548template <std::floating_point T>
549std::tuple<graph::AdjacencyList<std::int64_t>, std::vector<T>,
550 std::array<std::size_t, 2>, std::vector<std::int32_t>,
551 std::vector<std::int8_t>>
553{
554 common::Timer t0("PLAZA: refine");
555 auto topology = mesh.topology();
556 assert(topology);
557
558 if (topology->cell_type() != mesh::CellType::triangle
559 and topology->cell_type() != mesh::CellType::tetrahedron)
560 {
561 throw std::runtime_error("Cell type not supported");
562 }
563
564 auto map_e = topology->index_map(1);
565 if (!map_e)
566 throw std::runtime_error("Edges must be initialised");
567
568 // Get sharing ranks for each edge
569 graph::AdjacencyList<int> edge_ranks = map_e->index_to_dest_ranks();
570
571 // Create unique list of ranks that share edges (owners of ghosts
572 // plus ranks that ghost owned indices)
573 std::vector<int> ranks(edge_ranks.array().begin(), edge_ranks.array().end());
574 std::sort(ranks.begin(), ranks.end());
575 ranks.erase(std::unique(ranks.begin(), ranks.end()), ranks.end());
576
577 // Convert edge_ranks from global rank to to neighbourhood ranks
578 std::transform(edge_ranks.array().begin(), edge_ranks.array().end(),
579 edge_ranks.array().begin(),
580 [&ranks](auto r)
581 {
582 auto it = std::lower_bound(ranks.begin(), ranks.end(), r);
583 assert(it != ranks.end() and *it == r);
584 return std::distance(ranks.begin(), it);
585 });
586
587 MPI_Comm comm;
588 MPI_Dist_graph_create_adjacent(mesh.comm(), ranks.size(), ranks.data(),
589 MPI_UNWEIGHTED, ranks.size(), ranks.data(),
590 MPI_UNWEIGHTED, MPI_INFO_NULL, false, &comm);
591
592 const auto [long_edge, edge_ratio_ok] = impl::face_long_edge(mesh);
593 auto [cell_adj, new_vertex_coords, xshape, parent_cell, parent_facet]
594 = impl::compute_refinement(
595 comm,
596 std::vector<std::int8_t>(map_e->size_local() + map_e->num_ghosts(),
597 true),
598 edge_ranks, mesh, long_edge, edge_ratio_ok, option);
599 MPI_Comm_free(&comm);
600
601 return {std::move(cell_adj), std::move(new_vertex_coords), xshape,
602 std::move(parent_cell), std::move(parent_facet)};
603}
604
614template <std::floating_point T>
615std::tuple<graph::AdjacencyList<std::int64_t>, std::vector<T>,
616 std::array<std::size_t, 2>, std::vector<std::int32_t>,
617 std::vector<std::int8_t>>
619 std::span<const std::int32_t> edges, Option option)
620{
621 common::Timer t0("PLAZA: refine");
622 auto topology = mesh.topology();
623 assert(topology);
624
625 if (topology->cell_type() != mesh::CellType::triangle
626 and topology->cell_type() != mesh::CellType::tetrahedron)
627 {
628 throw std::runtime_error("Cell type not supported");
629 }
630
631 auto map_e = topology->index_map(1);
632 if (!map_e)
633 throw std::runtime_error("Edges must be initialised");
634
635 // Get sharing ranks for each edge
636 graph::AdjacencyList<int> edge_ranks = map_e->index_to_dest_ranks();
637
638 // Create unique list of ranks that share edges (owners of ghosts plus
639 // ranks that ghost owned indices)
640 std::vector<int> ranks(edge_ranks.array().begin(), edge_ranks.array().end());
641 std::sort(ranks.begin(), ranks.end());
642 ranks.erase(std::unique(ranks.begin(), ranks.end()), ranks.end());
643
644 // Convert edge_ranks from global rank to to neighbourhood ranks
645 std::transform(edge_ranks.array().begin(), edge_ranks.array().end(),
646 edge_ranks.array().begin(),
647 [&ranks](auto r)
648 {
649 auto it = std::lower_bound(ranks.begin(), ranks.end(), r);
650 assert(it != ranks.end() and *it == r);
651 return std::distance(ranks.begin(), it);
652 });
653
654 // Get number of neighbors
655 std::vector<std::int8_t> marked_edges(
656 map_e->size_local() + map_e->num_ghosts(), false);
657 std::vector<std::vector<std::int32_t>> marked_for_update(ranks.size());
658 for (auto edge : edges)
659 {
660 if (!marked_edges[edge])
661 {
662 marked_edges[edge] = true;
663
664 // If it is a shared edge, add all sharing neighbors to update set
665 for (int rank : edge_ranks.links(edge))
666 marked_for_update[rank].push_back(edge);
667 }
668 }
669
670 MPI_Comm comm;
671 MPI_Dist_graph_create_adjacent(mesh.comm(), ranks.size(), ranks.data(),
672 MPI_UNWEIGHTED, ranks.size(), ranks.data(),
673 MPI_UNWEIGHTED, MPI_INFO_NULL, false, &comm);
674
675 // Communicate any shared edges
676 update_logical_edgefunction(comm, marked_for_update, marked_edges, *map_e);
677
678 // Enforce rules about refinement (i.e. if any edge is marked in a
679 // triangle, then the longest edge must also be marked).
680 const auto [long_edge, edge_ratio_ok] = impl::face_long_edge(mesh);
681 impl::enforce_rules(comm, edge_ranks, marked_edges, *topology, long_edge);
682
683 auto [cell_adj, new_vertex_coords, xshape, parent_cell, parent_facet]
684 = impl::compute_refinement(comm, marked_edges, edge_ranks, mesh,
685 long_edge, edge_ratio_ok, option);
686 MPI_Comm_free(&comm);
687
688 return {std::move(cell_adj), std::move(new_vertex_coords), xshape,
689 std::move(parent_cell), std::move(parent_facet)};
690}
691
692} // namespace dolfinx::refinement::plaza
Definition Timer.h:31
Definition AdjacencyList.h:28
std::span< T > links(std::size_t node)
Definition AdjacencyList.h:112
const std::vector< T > & array() const
Return contiguous array of links for all nodes (const version)
Definition AdjacencyList.h:129
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition Mesh.h:23
Functions supporting mesh operations.
int size(MPI_Comm comm)
Definition MPI.cpp:72
void cells(la::SparsityPattern &pattern, std::array< std::span< const std::int32_t >, 2 > cells, std::array< std::reference_wrapper< const DofMap >, 2 > dofmaps)
Iterate over cells and insert entries into sparsity pattern.
Definition sparsitybuild.cpp:15
GhostMode
Enum for different partitioning ghost modes.
Definition utils.h:35
Mesh< typename std::remove_reference_t< typename U::value_type > > create_mesh(MPI_Comm comm, MPI_Comm commt, std::span< const std::int64_t > cells, const fem::CoordinateElement< typename std::remove_reference_t< typename U::value_type > > &element, MPI_Comm commg, const U &x, std::array< std::size_t, 2 > xshape, const CellPartitionFunction &partitioner)
Create a distributed mesh from mesh data using a provided graph partitioning function for determining...
Definition utils.h:785
int num_cell_vertices(CellType type)
Definition cell_types.cpp:147
Plaza mesh refinement.
Definition plaza.h:28
std::tuple< graph::AdjacencyList< std::int64_t >, std::vector< T >, std::array< std::size_t, 2 >, std::vector< std::int32_t >, std::vector< std::int8_t > > compute_refinement_data(const mesh::Mesh< T > &mesh, Option option)
Refine mesh returning new mesh data.
Definition plaza.h:552
Option
Options for data to compute during mesh refinement.
Definition plaza.h:32
std::tuple< mesh::Mesh< T >, std::vector< std::int32_t >, std::vector< std::int8_t > > refine(const mesh::Mesh< T > &mesh, bool redistribute, Option option)
Uniform refine, optionally redistributing and optionally calculating the parent-child relationships`.
Definition plaza.h:459
void update_logical_edgefunction(MPI_Comm comm, const std::vector< std::vector< std::int32_t > > &marked_for_update, std::vector< std::int8_t > &marked_edges, const common::IndexMap &map)
Communicate edge markers between processes that share edges.
Definition utils.cpp:46
std::tuple< std::map< std::int32_t, std::int64_t >, std::vector< T >, std::array< std::size_t, 2 > > create_new_vertices(MPI_Comm comm, const graph::AdjacencyList< int > &shared_edges, const mesh::Mesh< T > &mesh, std::span< const std::int8_t > marked_edges)
Add new vertex for each marked edge, and create new_vertex_coordinates and global_edge->new_vertex ma...
Definition utils.h:152
std::vector< std::int64_t > adjust_indices(const common::IndexMap &map, std::int32_t n)
Given an index map, add "n" extra indices at the end of local range.
Definition utils.cpp:102