Reference documentation for deal.II version GIT acb749f4f5 2024-02-21 16:10:02+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// Copyright (C) 1999 - 2023 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
18
22
25
26#include <deal.II/fe/fe.h>
27
29#include <deal.II/grid/tria.h>
32
33
35
36
37template <typename MeshType>
40 : source_grid(nullptr, typeid(*this).name())
41 , destination_grid(nullptr, typeid(*this).name())
42{}
43
44
45
46template <typename MeshType>
48void InterGridMap<MeshType>::make_mapping(const MeshType &source_grid,
49 const MeshType &destination_grid)
50{
51 // first delete all contents
52 clear();
53
54 // next store pointers to grids
55 this->source_grid = &source_grid;
56 this->destination_grid = &destination_grid;
57
58 // then set up the meshes from
59 // scratch and fill them with end-iterators
60 const unsigned int n_levels = source_grid.get_triangulation().n_levels();
61 mapping.resize(n_levels);
62 for (unsigned int level = 0; level < n_levels; ++level)
63 {
64 // first find out about the highest
65 // index used on this level. We could
66 // in principle ask the triangulation
67 // about this, but we would have to
68 // know the underlying data structure
69 // for this and we would like to
70 // avoid such knowledge here
71 unsigned int n_cells = 0;
72 cell_iterator cell = source_grid.begin(level),
73 endc = source_grid.end(level);
74 for (; cell != endc; ++cell)
75 if (static_cast<unsigned int>(cell->index()) > n_cells)
76 n_cells = cell->index();
77
78 // note: n_cells is now the largest
79 // zero-based index, but we need the
80 // number of cells, which is one larger
81 mapping[level].resize(n_cells + 1, destination_grid.end());
82 }
83
84 // now make up the mapping
85 // loop over all cells and set the user
86 // pointers as well as the contents of
87 // the two arrays. note that the function
88 // takes a *reference* to the int and
89 // this may change it
90 cell_iterator src_cell = source_grid.begin(0),
91 dst_cell = destination_grid.begin(0), endc = source_grid.end(0);
92 for (; src_cell != endc; ++src_cell, ++dst_cell)
93 set_mapping(src_cell, dst_cell);
94
95 // little assertion that the two grids
96 // are indeed related:
97 Assert(dst_cell == destination_grid.end(0), ExcIncompatibleGrids());
98}
99
100
101
102template <typename MeshType>
104void InterGridMap<MeshType>::set_mapping(const cell_iterator &src_cell,
105 const cell_iterator &dst_cell)
106{
107 // first set the map for this cell
108 mapping[src_cell->level()][src_cell->index()] = dst_cell;
109
110 // if both cells have children, we may
111 // recurse further into the hierarchy
112 if (src_cell->has_children() && dst_cell->has_children())
113 {
114 Assert(src_cell->n_children() ==
117 Assert(dst_cell->n_children() ==
120 Assert(src_cell->refinement_case() == dst_cell->refinement_case(),
122 for (unsigned int c = 0;
123 c < GeometryInfo<MeshType::dimension>::max_children_per_cell;
124 ++c)
125 set_mapping(src_cell->child(c), dst_cell->child(c));
126 }
127 else if (src_cell->has_children() && !dst_cell->has_children())
128 // src grid is more refined here.
129 // set entries for all children
130 // of this cell to the one
131 // dst_cell
132 for (unsigned int c = 0; c < src_cell->n_children(); ++c)
133 set_entries_to_cell(src_cell->child(c), dst_cell);
134 // else (no cell is refined or
135 // dst_cell is refined): no pointers
136 // to be set
137}
138
139
140
141template <typename MeshType>
143void InterGridMap<MeshType>::set_entries_to_cell(const cell_iterator &src_cell,
144 const cell_iterator &dst_cell)
145{
146 // first set the map for this cell
147 mapping[src_cell->level()][src_cell->index()] = dst_cell;
148
149 // then do so for the children as well
150 // if there are any
151 if (src_cell->has_children())
152 for (unsigned int c = 0; c < src_cell->n_children(); ++c)
153 set_entries_to_cell(src_cell->child(c), dst_cell);
154}
155
156
157template <typename MeshType>
161{
162 Assert(source_cell.state() == IteratorState::valid,
163 ExcInvalidKey(source_cell));
164 Assert(source_cell->level() <= static_cast<int>(mapping.size()),
165 ExcInvalidKey(source_cell));
166 Assert(source_cell->index() <=
167 static_cast<int>(mapping[source_cell->level()].size()),
168 ExcInvalidKey(source_cell));
169
170 return mapping[source_cell->level()][source_cell->index()];
171}
172
173
174
175template <typename MeshType>
177void InterGridMap<MeshType>::clear()
178{
179 mapping.clear();
180 source_grid = nullptr;
181 destination_grid = nullptr;
182}
183
184
185
186template <typename MeshType>
188const MeshType &InterGridMap<MeshType>::get_source_grid() const
189{
190 return *source_grid;
191}
192
193
194
195template <typename MeshType>
197const MeshType &InterGridMap<MeshType>::get_destination_grid() const
198{
199 return *destination_grid;
200}
201
202
203
204template <typename MeshType>
206std::size_t InterGridMap<MeshType>::memory_consumption() const
207{
210 MemoryConsumption::memory_consumption(destination_grid));
211}
212
213
214
215// explicit instantiations
216#include "intergrid_map.inst"
217
typename MeshType::cell_iterator cell_iterator
cell_iterator operator[](const cell_iterator &source_cell) const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:503
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:178
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:504
unsigned int level
Definition grid_out.cc:4617
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.