DOLFINx 0.8.0
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_type() != mesh::CellType::triangle
31 and topology->cell_type() != mesh::CellType::tetrahedron)
32 {
33 throw std::runtime_error("Refinement only defined for simplices");
34 }
35
36 auto [refined_mesh, parent_cell, parent_facet]
37 = plaza::refine(mesh, redistribute, plaza::Option::none);
38
39 // Report the number of refined cells
40 const int D = topology->dim();
41 const std::int64_t n0 = topology->index_map(D)->size_global();
42 const std::int64_t n1 = refined_mesh.topology()->index_map(D)->size_global();
43 LOG(INFO) << "Number of cells increased from " << n0 << " to " << n1 << " ("
44 << 100.0 * (static_cast<double>(n1) / static_cast<double>(n0) - 1.0)
45 << "%% increase).";
46
47 return refined_mesh;
48}
49
60template <std::floating_point T>
62 std::span<const std::int32_t> edges,
63 bool redistribute = true)
64{
65 auto topology = mesh.topology();
66 assert(topology);
67 if (topology->cell_type() != mesh::CellType::triangle
68 and topology->cell_type() != mesh::CellType::tetrahedron)
69 {
70 throw std::runtime_error("Refinement only defined for simplices");
71 }
72
73 auto [refined_mesh, parent_cell, parent_facet]
74 = plaza::refine(mesh, edges, redistribute, plaza::Option::none);
75
76 // Report the number of refined cells
77 const int D = topology->dim();
78 const std::int64_t n0 = topology->index_map(D)->size_global();
79 const std::int64_t n1 = refined_mesh.topology()->index_map(D)->size_global();
80 LOG(INFO) << "Number of cells increased from " << n0 << " to " << n1 << " ("
81 << 100.0 * (static_cast<double>(n1) / static_cast<double>(n0) - 1.0)
82 << "%% increase).";
83
84 return refined_mesh;
85}
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::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
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