Reference documentation for deal.II version 9.2.0
\(\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 
26 template <int dim, int spacedim>
28 
29 template <int dim, int spacedim>
31 
32 
33 template <int dim, int spacedim>
35  const Triangulation<dim, spacedim> &coarse_grid)
36  : coarse_grid(&coarse_grid, typeid(*this).name())
37 {}
38 
39 
40 
41 template <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 
57 template <int dim, int spacedim>
58 void
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 
76 template <int dim, int spacedim>
77 void
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 
88 template <int dim, int spacedim>
89 void
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 
114 template <int dim, int spacedim>
115 unsigned int
117 {
118  return refine_flags.size();
119 }
120 
121 
122 
123 template <int dim, int spacedim>
124 void
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 
136 template <int dim, int spacedim>
137 void
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 
148 template <int dim, int spacedim>
149 void
152 {
153  (void)construction_data;
154 
155  Assert(false, ExcInternalError());
156 }
157 
158 
159 
160 template <int dim, int spacedim>
161 void
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 
172 template <int dim, int spacedim>
173 void
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 
201 template <int dim, int spacedim>
202 void
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 
239 template <int dim, int spacedim>
240 void
242 {
243  refine_flags.clear();
244  coarsen_flags.clear();
245 }
246 
247 
248 
249 template <int dim, int spacedim>
250 std::size_t
252 {
257 }
258 
259 
260 // explicit instantiations
261 template class PersistentTriangulation<1>;
262 template class PersistentTriangulation<2>;
263 template class PersistentTriangulation<3>;
264 template class PersistentTriangulation<1, 2>;
265 template class PersistentTriangulation<2, 3>;
266 
persistent_tria.h
PersistentTriangulation::restore
void restore()
Definition: persistent_tria.cc:78
StandardExceptions::ExcIO
static ::ExceptionBase & ExcIO()
PersistentTriangulation::clear_flags
virtual void clear_flags()
Definition: persistent_tria.cc:241
PersistentTriangulation::n_refinement_steps
unsigned int n_refinement_steps() const
Definition: persistent_tria.cc:116
mn_tria_refine_flags_end
const unsigned int mn_tria_refine_flags_end
Definition: magic_numbers.h:30
CellData
Definition: tria_description.h:67
Triangulation
Definition: tria.h:1109
PersistentTriangulation
Definition: persistent_tria.h:109
memory_consumption.h
PersistentTriangulation::create_triangulation
virtual void create_triangulation(const std::vector< Point< spacedim >> &vertices, const std::vector< CellData< dim >> &cells, const SubCellData &subcelldata) override
Definition: persistent_tria.cc:138
mn_persistent_tria_flags_end
const unsigned int mn_persistent_tria_flags_end
Definition: magic_numbers.h:40
PersistentTriangulation::memory_consumption
virtual std::size_t memory_consumption() const override
Definition: persistent_tria.cc:251
mn_tria_refine_flags_begin
const unsigned int mn_tria_refine_flags_begin
Definition: magic_numbers.h:29
magic_numbers.h
mn_tria_coarsen_flags_begin
const unsigned int mn_tria_coarsen_flags_begin
Definition: magic_numbers.h:31
Triangulation::execute_coarsening_and_refinement
virtual void execute_coarsening_and_refinement()
Definition: tria.cc:13385
mn_persistent_tria_flags_begin
const unsigned int mn_persistent_tria_flags_begin
Definition: magic_numbers.h:39
PersistentTriangulation::execute_coarsening_and_refinement
virtual void execute_coarsening_and_refinement() override
Definition: persistent_tria.cc:59
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
MemoryConsumption::memory_consumption
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
Definition: memory_consumption.h:268
PersistentTriangulation::copy_triangulation
virtual void copy_triangulation(const Triangulation< dim, spacedim > &tria) override
Definition: persistent_tria.cc:125
PersistentTriangulation::PersistentTriangulation
PersistentTriangulation(const Triangulation< dim, spacedim > &coarse_grid)
Definition: persistent_tria.cc:34
Triangulation::copy_triangulation
virtual void copy_triangulation(const Triangulation< dim, spacedim > &other_tria)
Definition: tria.cc:10438
PersistentTriangulation::ExcTriaNotEmpty
static ::ExceptionBase & ExcTriaNotEmpty()
PersistentTriangulation::create_triangulation_compatibility
virtual void create_triangulation_compatibility(const std::vector< Point< spacedim >> &vertices, const std::vector< CellData< dim >> &cells, const SubCellData &subcelldata) override
Definition: persistent_tria.cc:162
StandardExceptions::ExcInternalError
static ::ExceptionBase & ExcInternalError()
PersistentTriangulation::write_flags
virtual void write_flags(std::ostream &out) const
Definition: persistent_tria.cc:174
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
mn_tria_coarsen_flags_end
const unsigned int mn_tria_coarsen_flags_end
Definition: magic_numbers.h:32
StandardExceptions::ExcImpossibleInDim
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
StandardExceptions::ExcDimensionMismatch
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
Point< spacedim >
TriangulationDescription::Description
Definition: tria_description.h:347
SubCellData
Definition: tria_description.h:199
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
Triangulation< dim, dim >::n_levels
unsigned int n_levels() const
AssertThrow
#define AssertThrow(cond, exc)
Definition: exceptions.h:1531
Triangulation::clear
virtual void clear()
Definition: tria.cc:10209
PersistentTriangulation::read_flags
virtual void read_flags(std::istream &in)
Definition: persistent_tria.cc:203