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
persistent_tria.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 - 2026 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
13#include <deal.II/base/config.h>
14
19
22#include <deal.II/grid/tria.h>
23
24#include <Kokkos_Macros.hpp>
25
26#include <cstddef>
27#include <iostream>
28#include <typeinfo>
29#include <vector>
30
32
33
34template <int dim, int spacedim>
36
37template <int dim, int spacedim>
39
40
41template <int dim, int spacedim>
43 const Triangulation<dim, spacedim> &coarse_grid)
44 : coarse_grid(&coarse_grid, typeid(*this).name())
45{}
46
47
48
49template <int dim, int spacedim>
52 : // default initialize
53 // tria, i.e. it will be
54 // empty on first use
55 Triangulation<dim, spacedim>()
56 , coarse_grid(old_tria.coarse_grid)
57 , refine_flags(old_tria.refine_flags)
58 , coarsen_flags(old_tria.coarsen_flags)
59{
60 Assert(old_tria.n_levels() == 0, ExcTriaNotEmpty());
61}
62
63
64
65template <int dim, int spacedim>
66void
68{
69 // first save flags
70 refine_flags.emplace_back();
71 coarsen_flags.emplace_back();
72 this->save_refine_flags(refine_flags.back());
73 this->save_coarsen_flags(coarsen_flags.back());
74
75 // then refine triangulation. if
76 // this function throws an
77 // exception, that's fine since it
78 // is the last call here
80}
81
82
83
84template <int dim, int spacedim>
85void
87{
88 // for each of the previous
89 // refinement sweeps
90 for (unsigned int i = 0; i < refine_flags.size() + 1; ++i)
91 restore(i);
92}
93
94
95
96template <int dim, int spacedim>
97void
99{
100 if (step == 0)
101 // copy the old triangulation.
102 // this will yield an error if
103 // the underlying triangulation
104 // was not empty
106 else
107 // for each of the previous
108 // refinement sweeps
109 {
110 Assert(step < refine_flags.size() + 1,
111 ExcDimensionMismatch(step, refine_flags.size() + 1));
112
113 this->load_refine_flags(refine_flags[step - 1]);
114 this->load_coarsen_flags(coarsen_flags[step - 1]);
115
117 }
118}
119
120
121
122template <int dim, int spacedim>
123unsigned int
125{
126 return refine_flags.size();
127}
128
129
130
131template <int dim, int spacedim>
132void
134 const Triangulation<dim, spacedim> &old_grid)
135{
136 this->clear();
137 coarse_grid = &old_grid;
138 refine_flags.clear();
139 coarsen_flags.clear();
140}
141
142
143
144template <int dim, int spacedim>
145void
147 const std::vector<Point<spacedim>> &,
148 const std::vector<CellData<dim>> &,
149 const SubCellData &)
150{
151 Assert(false, ExcImpossibleInDim(dim));
152}
153
154
155
156template <int dim, int spacedim>
157void
165
166
167
168template <int dim, int spacedim>
169void
171{
172 const unsigned int n_flag_levels = refine_flags.size();
173
174 AssertThrow(out.fail() == false, ExcIO());
175
176 out << mn_persistent_tria_flags_begin << ' ' << n_flag_levels << std::endl;
177
178 for (unsigned int i = 0; i < n_flag_levels; ++i)
179 {
180 this->write_bool_vector(mn_tria_refine_flags_begin,
181 refine_flags[i],
183 out);
184 this->write_bool_vector(mn_tria_coarsen_flags_begin,
185 coarsen_flags[i],
187 out);
188 }
189
190 out << mn_persistent_tria_flags_end << std::endl;
191
192 AssertThrow(out.fail() == false, ExcIO());
193}
194
195
196
197template <int dim, int spacedim>
198void
200{
201 Assert(refine_flags.empty() && coarsen_flags.empty(), ExcFlagsNotCleared());
202 AssertThrow(in.fail() == false, ExcIO());
203
204 unsigned int magic_number;
205 in >> magic_number;
208
209 unsigned int n_flag_levels;
210 in >> n_flag_levels;
211 for (unsigned int i = 0; i < n_flag_levels; ++i)
212 {
213 refine_flags.emplace_back();
214 coarsen_flags.emplace_back();
215 this->read_bool_vector(mn_tria_refine_flags_begin,
216 refine_flags.back(),
218 in);
219 this->read_bool_vector(mn_tria_coarsen_flags_begin,
220 coarsen_flags.back(),
222 in);
223 }
224
225 in >> magic_number;
228
229 AssertThrow(in.fail() == false, ExcIO());
230}
231
232
233
234template <int dim, int spacedim>
235void
237{
238 refine_flags.clear();
239 coarsen_flags.clear();
240}
241
242
243
244template <int dim, int spacedim>
245std::size_t
253
254
255// explicit instantiations
256template class PersistentTriangulation<1>;
257template class PersistentTriangulation<2>;
258template class PersistentTriangulation<3>;
259template class PersistentTriangulation<1, 2>;
260template class PersistentTriangulation<2, 3>;
261
virtual void read_flags(std::istream &in)
virtual void write_flags(std::ostream &out) const
virtual std::size_t memory_consumption() const override
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata) override
virtual void copy_triangulation(const Triangulation< dim, spacedim > &tria) override
unsigned int n_refinement_steps() const
virtual void execute_coarsening_and_refinement() override
PersistentTriangulation(const Triangulation< dim, spacedim > &coarse_grid)
Definition point.h:111
virtual void clear()
virtual void copy_triangulation(const Triangulation< dim, spacedim > &other_tria)
unsigned int n_levels() const
virtual void execute_coarsening_and_refinement()
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define DEAL_II_ASSERT_UNREACHABLE()
static ::ExceptionBase & ExcIO()
#define Assert(cond, exc)
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcTriaNotEmpty()
#define AssertThrow(cond, exc)
const unsigned int mn_tria_refine_flags_end
const unsigned int mn_tria_coarsen_flags_end
const unsigned int mn_tria_refine_flags_begin
const unsigned int mn_persistent_tria_flags_begin
const unsigned int mn_persistent_tria_flags_end
const unsigned int mn_tria_coarsen_flags_begin
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)