Reference documentation for deal.II version 9.3.3
\(\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\}}\)
persistent_tria.cc
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 1999 - 2020 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
17
20
21#include <iostream>
22
24
25
26template <int dim, int spacedim>
28
29template <int dim, int spacedim>
31
32
33template <int dim, int spacedim>
35 const Triangulation<dim, spacedim> &coarse_grid)
36 : coarse_grid(&coarse_grid, typeid(*this).name())
37{}
38
39
40
41template <int dim, int spacedim>
44 : // default initialize
45 // tria, i.e. it will be
46 // empty on first use
47 Triangulation<dim, spacedim>()
48 , coarse_grid(old_tria.coarse_grid)
49 , refine_flags(old_tria.refine_flags)
50 , coarsen_flags(old_tria.coarsen_flags)
51{
52 Assert(old_tria.n_levels() == 0, ExcTriaNotEmpty());
53}
54
55
56
57template <int dim, int spacedim>
58void
60{
61 // first save flags
62 refine_flags.emplace_back();
63 coarsen_flags.emplace_back();
64 this->save_refine_flags(refine_flags.back());
65 this->save_coarsen_flags(coarsen_flags.back());
66
67 // then refine triangulation. if
68 // this function throws an
69 // exception, that's fine since it
70 // is the last call here
72}
73
74
75
76template <int dim, int spacedim>
77void
79{
80 // for each of the previous
81 // refinement sweeps
82 for (unsigned int i = 0; i < refine_flags.size() + 1; ++i)
83 restore(i);
84}
85
86
87
88template <int dim, int spacedim>
89void
91{
92 if (step == 0)
93 // copy the old triangulation.
94 // this will yield an error if
95 // the underlying triangulation
96 // was not empty
98 else
99 // for each of the previous
100 // refinement sweeps
101 {
102 Assert(step < refine_flags.size() + 1,
103 ExcDimensionMismatch(step, refine_flags.size() + 1));
104
105 this->load_refine_flags(refine_flags[step - 1]);
106 this->load_coarsen_flags(coarsen_flags[step - 1]);
107
109 }
110}
111
112
113
114template <int dim, int spacedim>
115unsigned int
117{
118 return refine_flags.size();
119}
120
121
122
123template <int dim, int spacedim>
124void
126 const Triangulation<dim, spacedim> &old_grid)
127{
128 this->clear();
129 coarse_grid = &old_grid;
130 refine_flags.clear();
131 coarsen_flags.clear();
132}
133
134
135
136template <int dim, int spacedim>
137void
139 const std::vector<Point<spacedim>> &,
140 const std::vector<CellData<dim>> &,
141 const SubCellData &)
142{
143 Assert(false, ExcImpossibleInDim(dim));
144}
145
146
147
148template <int dim, int spacedim>
149void
152{
153 (void)construction_data;
154
155 Assert(false, ExcInternalError());
156}
157
158
159
160template <int dim, int spacedim>
161void
163 const std::vector<Point<spacedim>> &,
164 const std::vector<CellData<dim>> &,
165 const SubCellData &)
166{
167 Assert(false, ExcImpossibleInDim(dim));
168}
169
170
171
172template <int dim, int spacedim>
173void
175{
176 const unsigned int n_flag_levels = refine_flags.size();
177
178 AssertThrow(out, ExcIO());
179
180 out << mn_persistent_tria_flags_begin << ' ' << n_flag_levels << std::endl;
181
182 for (unsigned int i = 0; i < n_flag_levels; ++i)
183 {
184 this->write_bool_vector(mn_tria_refine_flags_begin,
185 refine_flags[i],
187 out);
188 this->write_bool_vector(mn_tria_coarsen_flags_begin,
189 coarsen_flags[i],
191 out);
192 }
193
194 out << mn_persistent_tria_flags_end << std::endl;
195
196 AssertThrow(out, ExcIO());
197}
198
199
200
201template <int dim, int spacedim>
202void
204{
205 Assert(refine_flags.size() == 0 && coarsen_flags.size() == 0,
206 ExcFlagsNotCleared());
207 AssertThrow(in, ExcIO());
208
209 unsigned int magic_number;
210 in >> magic_number;
213
214 unsigned int n_flag_levels;
215 in >> n_flag_levels;
216 for (unsigned int i = 0; i < n_flag_levels; ++i)
217 {
218 refine_flags.emplace_back();
219 coarsen_flags.emplace_back();
220 this->read_bool_vector(mn_tria_refine_flags_begin,
221 refine_flags.back(),
223 in);
224 this->read_bool_vector(mn_tria_coarsen_flags_begin,
225 coarsen_flags.back(),
227 in);
228 }
229
230 in >> magic_number;
233
234 AssertThrow(in, ExcIO());
235}
236
237
238
239template <int dim, int spacedim>
240void
242{
243 refine_flags.clear();
244 coarsen_flags.clear();
245}
246
247
248
249template <int dim, int spacedim>
250std::size_t
252{
257}
258
259
260// explicit instantiations
261template class PersistentTriangulation<1>;
262template class PersistentTriangulation<2>;
263template class PersistentTriangulation<3>;
264template class PersistentTriangulation<1, 2>;
265template class PersistentTriangulation<2, 3>;
266
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 create_triangulation_compatibility(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)
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:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
static ::ExceptionBase & ExcIO()
#define Assert(cond, exc)
Definition: exceptions.h:1465
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
static ::ExceptionBase & ExcTriaNotEmpty()
#define AssertThrow(cond, exc)
Definition: exceptions.h:1575
const unsigned int mn_tria_refine_flags_end
Definition: magic_numbers.h:30
const unsigned int mn_tria_coarsen_flags_end
Definition: magic_numbers.h:32
const unsigned int mn_tria_refine_flags_begin
Definition: magic_numbers.h:29
const unsigned int mn_persistent_tria_flags_begin
Definition: magic_numbers.h:39
const unsigned int mn_persistent_tria_flags_end
Definition: magic_numbers.h:40
const unsigned int mn_tria_coarsen_flags_begin
Definition: magic_numbers.h:31
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)