Reference documentation for deal.II version GIT relicensing-249-g48dc7357c7 2024-03-29 12:30: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
persistent_tria.cc
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 1999 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
16
19
20#include <iostream>
21
23
24
25template <int dim, int spacedim>
27
28template <int dim, int spacedim>
30
31
32template <int dim, int spacedim>
34 const Triangulation<dim, spacedim> &coarse_grid)
35 : coarse_grid(&coarse_grid, typeid(*this).name())
36{}
37
38
39
40template <int dim, int spacedim>
43 : // default initialize
44 // tria, i.e. it will be
45 // empty on first use
46 Triangulation<dim, spacedim>()
47 , coarse_grid(old_tria.coarse_grid)
48 , refine_flags(old_tria.refine_flags)
49 , coarsen_flags(old_tria.coarsen_flags)
50{
51 Assert(old_tria.n_levels() == 0, ExcTriaNotEmpty());
52}
53
54
55
56template <int dim, int spacedim>
57void
59{
60 // first save flags
61 refine_flags.emplace_back();
62 coarsen_flags.emplace_back();
63 this->save_refine_flags(refine_flags.back());
64 this->save_coarsen_flags(coarsen_flags.back());
65
66 // then refine triangulation. if
67 // this function throws an
68 // exception, that's fine since it
69 // is the last call here
71}
72
73
74
75template <int dim, int spacedim>
76void
78{
79 // for each of the previous
80 // refinement sweeps
81 for (unsigned int i = 0; i < refine_flags.size() + 1; ++i)
82 restore(i);
83}
84
85
86
87template <int dim, int spacedim>
88void
90{
91 if (step == 0)
92 // copy the old triangulation.
93 // this will yield an error if
94 // the underlying triangulation
95 // was not empty
97 else
98 // for each of the previous
99 // refinement sweeps
100 {
101 Assert(step < refine_flags.size() + 1,
102 ExcDimensionMismatch(step, refine_flags.size() + 1));
103
104 this->load_refine_flags(refine_flags[step - 1]);
105 this->load_coarsen_flags(coarsen_flags[step - 1]);
106
108 }
109}
110
111
112
113template <int dim, int spacedim>
114unsigned int
116{
117 return refine_flags.size();
118}
119
120
121
122template <int dim, int spacedim>
123void
125 const Triangulation<dim, spacedim> &old_grid)
126{
127 this->clear();
128 coarse_grid = &old_grid;
129 refine_flags.clear();
130 coarsen_flags.clear();
131}
132
133
134
135template <int dim, int spacedim>
136void
138 const std::vector<Point<spacedim>> &,
139 const std::vector<CellData<dim>> &,
140 const SubCellData &)
141{
142 Assert(false, ExcImpossibleInDim(dim));
143}
144
145
146
147template <int dim, int spacedim>
148void
156
157
158
159template <int dim, int spacedim>
160void
162{
163 const unsigned int n_flag_levels = refine_flags.size();
164
165 AssertThrow(out.fail() == false, ExcIO());
166
167 out << mn_persistent_tria_flags_begin << ' ' << n_flag_levels << std::endl;
168
169 for (unsigned int i = 0; i < n_flag_levels; ++i)
170 {
171 this->write_bool_vector(mn_tria_refine_flags_begin,
172 refine_flags[i],
174 out);
175 this->write_bool_vector(mn_tria_coarsen_flags_begin,
176 coarsen_flags[i],
178 out);
179 }
180
181 out << mn_persistent_tria_flags_end << std::endl;
182
183 AssertThrow(out.fail() == false, ExcIO());
184}
185
186
187
188template <int dim, int spacedim>
189void
191{
192 Assert(refine_flags.empty() && coarsen_flags.empty(), ExcFlagsNotCleared());
193 AssertThrow(in.fail() == false, ExcIO());
194
195 unsigned int magic_number;
196 in >> magic_number;
199
200 unsigned int n_flag_levels;
201 in >> n_flag_levels;
202 for (unsigned int i = 0; i < n_flag_levels; ++i)
203 {
204 refine_flags.emplace_back();
205 coarsen_flags.emplace_back();
206 this->read_bool_vector(mn_tria_refine_flags_begin,
207 refine_flags.back(),
209 in);
210 this->read_bool_vector(mn_tria_coarsen_flags_begin,
211 coarsen_flags.back(),
213 in);
214 }
215
216 in >> magic_number;
219
220 AssertThrow(in.fail() == false, ExcIO());
221}
222
223
224
225template <int dim, int spacedim>
226void
228{
229 refine_flags.clear();
230 coarsen_flags.clear();
231}
232
233
234
235template <int dim, int spacedim>
236std::size_t
244
245
246// explicit instantiations
247template class PersistentTriangulation<1>;
248template class PersistentTriangulation<2>;
249template class PersistentTriangulation<3>;
250template class PersistentTriangulation<1, 2>;
251template class PersistentTriangulation<2, 3>;
252
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:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
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)
#define DEAL_II_ASSERT_UNREACHABLE()
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)