Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/dolfinx/v0.9.0/cpp/doxygen/da/dbc/refine_8h_source.html
DOLFINx 0.7.3
DOLFINx C++ interface
Loading...
Searching...
No Matches
refine.h
1// Copyright (C) 2010-2023 Garth N. Wells
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 "plaza.h"
10#include "refine.h"
11#include <dolfinx/common/IndexMap.h>
12#include <dolfinx/common/log.h>
13#include <dolfinx/mesh/Mesh.h>
14#include <dolfinx/mesh/Topology.h>
15
16namespace dolfinx::refinement
17{
24template <std::floating_point T>
25mesh::Mesh<T> refine(const mesh::Mesh<T>& mesh, bool redistribute = true)
26{
27 auto topology = mesh.topology();
28 assert(topology);
29
30 if (topology->cell_types().size() > 1)
31 throw std::runtime_error("Mixed topology not supported");
32
33 if (topology->cell_types()[0] != mesh::CellType::triangle
34 and topology->cell_types()[0] != mesh::CellType::tetrahedron)
35 {
36 throw std::runtime_error("Refinement only defined for simplices");
37 }
38
39 auto [refined_mesh, parent_cell, parent_facet]
40 = plaza::refine(mesh, redistribute, plaza::Option::none);
41
42 // Report the number of refined cells
43 const int D = topology->dim();
44 const std::int64_t n0 = topology->index_map(D)->size_global();
45 const std::int64_t n1 = refined_mesh.topology()->index_map(D)->size_global();
46 LOG(INFO) << "Number of cells increased from " << n0 << " to " << n1 << " ("
47 << 100.0 * (static_cast<double>(n1) / static_cast<double>(n0) - 1.0)
48 << "%% increase).";
49
50 return refined_mesh;
51}
52
63template <std::floating_point T>
65 std::span<const std::int32_t> edges,
66 bool redistribute = true)
67{
68 auto topology = mesh.topology();
69 assert(topology);
70
71 if (topology->cell_types().size() > 1)
72 throw std::runtime_error("Mixed topology not supported");
73 if (topology->cell_types()[0] != mesh::CellType::triangle
74 and topology->cell_types()[0] != mesh::CellType::tetrahedron)
75 {
76 throw std::runtime_error("Refinement only defined for simplices");
77 }
78
79 auto [refined_mesh, parent_cell, parent_facet]
80 = plaza::refine(mesh, edges, redistribute, plaza::Option::none);
81
82 // Report the number of refined cells
83 const int D = topology->dim();
84 const std::int64_t n0 = topology->index_map(D)->size_global();
85 const std::int64_t n1 = refined_mesh.topology()->index_map(D)->size_global();
86 LOG(INFO) << "Number of cells increased from " << n0 << " to " << n1 << " ("
87 << 100.0 * (static_cast<double>(n1) / static_cast<double>(n0) - 1.0)
88 << "%% increase).";
89
90 return refined_mesh;
91}
92
93} // 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
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:427
Mesh refinement algorithms.
Definition dolfinx_refinement.h:8
mesh::Mesh< T > refine(const mesh::Mesh< T > &mesh, bool redistribute=true)
Create a uniformly refined mesh.
Definition refine.h:25