DOLFINx 0.9.0
DOLFINx C++ interface
Loading...
Searching...
No Matches
refine.h
1// Copyright (C) 2010-2024 Garth N. Wells and Paul T. Kühner
2//
3// This file is part of DOLFINx (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9#include "dolfinx/graph/AdjacencyList.h"
10#include "dolfinx/mesh/Mesh.h"
11#include "dolfinx/mesh/Topology.h"
12#include "dolfinx/mesh/cell_types.h"
13#include "dolfinx/mesh/utils.h"
14#include "interval.h"
15#include "plaza.h"
16#include <algorithm>
17#include <concepts>
18#include <optional>
19#include <spdlog/spdlog.h>
20#include <utility>
21
22namespace dolfinx::refinement
23{
54template <std::floating_point T>
55std::tuple<mesh::Mesh<T>, std::optional<std::vector<std::int32_t>>,
56 std::optional<std::vector<std::int8_t>>>
58 std::optional<std::span<const std::int32_t>> edges,
59 const mesh::CellPartitionFunction& partitioner
60 = mesh::create_cell_partitioner(mesh::GhostMode::none),
61 Option option = Option::none)
62{
63 auto topology = mesh.topology();
64 assert(topology);
65 if (!mesh::is_simplex(topology->cell_type()))
66 throw std::runtime_error("Refinement only defined for simplices");
67
68 auto [cell_adj, new_vertex_coords, xshape, parent_cell, parent_facet]
69 = (topology->cell_type() == mesh::CellType::interval)
70 ? interval::compute_refinement_data(mesh, edges, option)
71 : plaza::compute_refinement_data(mesh, edges, option);
72
74 mesh.comm(), mesh.comm(), cell_adj.array(), mesh.geometry().cmap(),
75 mesh.comm(), new_vertex_coords, xshape, partitioner);
76
77 // Report the number of refined cells
78 const int D = topology->dim();
79 const std::int64_t n0 = topology->index_map(D)->size_global();
80 const std::int64_t n1 = mesh1.topology()->index_map(D)->size_global();
81 spdlog::info(
82 "Number of cells increased from {} to {} ({}% increase).", n0, n1,
83 100.0 * (static_cast<double>(n1) / static_cast<double>(n0) - 1.0));
84
85 return {std::move(mesh1), std::move(parent_cell), std::move(parent_facet)};
86}
87} // namespace dolfinx::refinement
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition Mesh.h:23
std::shared_ptr< Topology > topology()
Get mesh topology.
Definition Mesh.h:64
Functions supporting mesh operations.
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:783
bool is_simplex(CellType type)
Definition cell_types.cpp:145
std::function< graph::AdjacencyList< std::int32_t >( MPI_Comm comm, int nparts, const std::vector< CellType > &cell_types, const std::vector< std::span< const std::int64_t > > &cells)> CellPartitionFunction
Signature for the cell partitioning function. The function should compute the destination rank for ce...
Definition utils.h:185
CellPartitionFunction create_cell_partitioner(mesh::GhostMode ghost_mode=mesh::GhostMode::none, const graph::partition_fn &partfn=&graph::partition_graph)
Definition utils.cpp:85
std::tuple< graph::AdjacencyList< std::int64_t >, std::vector< T >, std::array< std::size_t, 2 >, std::optional< std::vector< std::int32_t > >, std::optional< std::vector< std::int8_t > > > compute_refinement_data(const mesh::Mesh< T > &mesh, std::optional< std::span< const std::int32_t > > edges, Option option)
Definition plaza.h:463
Mesh refinement algorithms.
Definition dolfinx_refinement.h:8
std::tuple< mesh::Mesh< T >, std::optional< std::vector< std::int32_t > >, std::optional< std::vector< std::int8_t > > > refine(const mesh::Mesh< T > &mesh, std::optional< std::span< const std::int32_t > > edges, const mesh::CellPartitionFunction &partitioner=mesh::create_cell_partitioner(mesh::GhostMode::none), Option option=Option::none)
Refine a mesh with markers.
Definition refine.h:57
Option
Options for data to compute during mesh refinement.
Definition option.h:16