deal.II version GIT relicensing-6917-gb466a1809f 2026-10-16 06:30:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
intergrid_map.cc
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 1999 - 2025 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
15
19
22
23#include <deal.II/fe/fe.h>
24
26#include <deal.II/grid/tria.h>
29
30
32
33
34template <typename MeshType>
37 : source_grid(nullptr, typeid(*this).name())
38 , destination_grid(nullptr, typeid(*this).name())
39{}
40
41
42
43template <typename MeshType>
45void InterGridMap<MeshType>::make_mapping(const MeshType &source_grid,
46 const MeshType &destination_grid)
47{
48 // first delete all contents
49 clear();
50
51 // next store pointers to grids
52 this->source_grid = &source_grid;
53 this->destination_grid = &destination_grid;
54
55 // then set up the meshes from
56 // scratch and fill them with end-iterators
57 const unsigned int n_levels = source_grid.get_triangulation().n_levels();
58 mapping.resize(n_levels);
59 for (unsigned int level = 0; level < n_levels; ++level)
60 {
61 // first find out about the highest
62 // index used on this level. We could
63 // in principle ask the triangulation
64 // about this, but we would have to
65 // know the underlying data structure
66 // for this and we would like to
67 // avoid such knowledge here
68 unsigned int n_cells = 0;
69 cell_iterator cell = source_grid.begin(level),
70 endc = source_grid.end(level);
71 for (; cell != endc; ++cell)
72 if (static_cast<unsigned int>(cell->index()) > n_cells)
73 n_cells = cell->index();
74
75 // note: n_cells is now the largest
76 // zero-based index, but we need the
77 // number of cells, which is one larger
78 mapping[level].resize(n_cells + 1, destination_grid.end());
79 }
80
81 // now make up the mapping
82 // loop over all cells and set the user
83 // pointers as well as the contents of
84 // the two arrays. note that the function
85 // takes a *reference* to the int and
86 // this may change it
87 cell_iterator src_cell = source_grid.begin(0),
88 dst_cell = destination_grid.begin(0), endc = source_grid.end(0);
89 for (; src_cell != endc; ++src_cell, ++dst_cell)
90 set_mapping(src_cell, dst_cell);
91
92 // little assertion that the two grids
93 // are indeed related:
94 Assert(dst_cell == destination_grid.end(0), ExcIncompatibleGrids());
95}
96
97
98
99template <typename MeshType>
101void InterGridMap<MeshType>::set_mapping(const cell_iterator &src_cell,
102 const cell_iterator &dst_cell)
103{
104 // first set the map for this cell
105 mapping[src_cell->level()][src_cell->index()] = dst_cell;
106
107 // if both cells have children, we may
108 // recurse further into the hierarchy
109 if (src_cell->has_children() && dst_cell->has_children())
110 {
111 Assert(src_cell->n_children() ==
114 Assert(dst_cell->n_children() ==
117 Assert(src_cell->refinement_case() == dst_cell->refinement_case(),
119 for (unsigned int c = 0;
120 c < GeometryInfo<MeshType::dimension>::max_children_per_cell;
121 ++c)
122 set_mapping(src_cell->child(c), dst_cell->child(c));
123 }
124 else if (src_cell->has_children() && !dst_cell->has_children())
125 // src grid is more refined here.
126 // set entries for all children
127 // of this cell to the one
128 // dst_cell
129 for (unsigned int c = 0; c < src_cell->n_children(); ++c)
130 set_entries_to_cell(src_cell->child(c), dst_cell);
131 // else (no cell is refined or
132 // dst_cell is refined): no pointers
133 // to be set
134}
135
136
137
138template <typename MeshType>
140void InterGridMap<MeshType>::set_entries_to_cell(const cell_iterator &src_cell,
141 const cell_iterator &dst_cell)
142{
143 // first set the map for this cell
144 mapping[src_cell->level()][src_cell->index()] = dst_cell;
145
146 // then do so for the children as well
147 // if there are any
148 if (src_cell->has_children())
149 for (unsigned int c = 0; c < src_cell->n_children(); ++c)
150 set_entries_to_cell(src_cell->child(c), dst_cell);
151}
152
153
154template <typename MeshType>
158{
159 Assert(source_cell.state() == IteratorState::valid,
160 ExcInvalidKey(source_cell));
161 Assert(source_cell->level() <= static_cast<int>(mapping.size()),
162 ExcInvalidKey(source_cell));
163 Assert(source_cell->index() <=
164 static_cast<int>(mapping[source_cell->level()].size()),
165 ExcInvalidKey(source_cell));
166
167 return mapping[source_cell->level()][source_cell->index()];
168}
169
170
171
172template <typename MeshType>
174void InterGridMap<MeshType>::clear()
175{
176 mapping.clear();
177 source_grid = nullptr;
178 destination_grid = nullptr;
179}
180
181
182
183template <typename MeshType>
185const MeshType &InterGridMap<MeshType>::get_source_grid() const
186{
187 return *source_grid;
188}
189
190
191
192template <typename MeshType>
194const MeshType &InterGridMap<MeshType>::get_destination_grid() const
195{
196 return *destination_grid;
197}
198
199
200
201template <typename MeshType>
203std::size_t InterGridMap<MeshType>::memory_consumption() const
204{
207 MemoryConsumption::memory_consumption(destination_grid));
208}
209
210
211
212// explicit instantiations
213#include "grid/intergrid_map.inst"
214
typename MeshType::cell_iterator cell_iterator
cell_iterator operator[](const cell_iterator &source_cell) const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:249
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
unsigned int level
Definition grid_out.cc:4642
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
@ valid
Iterator points to a valid object.
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
STL namespace.