Reference documentation for deal.II version Git ac8d010384 2020-11-27 19:49:05 +0100
\(\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  {
185  refine_flags[i],
187  out);
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,
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();
221  refine_flags.back(),
223  in);
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 
virtual void copy_triangulation(const Triangulation< dim, spacedim > &other_tria)
Definition: tria.cc:9762
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
static ::ExceptionBase & ExcIO()
unsigned int n_refinement_steps() const
static void read_bool_vector(const unsigned int magic_number1, std::vector< bool > &v, const unsigned int magic_number2, std::istream &in)
Definition: tria.cc:14508
const unsigned int mn_persistent_tria_flags_begin
Definition: magic_numbers.h:39
virtual void create_triangulation(const std::vector< Point< spacedim >> &vertices, const std::vector< CellData< dim >> &cells, const SubCellData &subcelldata) override
#define AssertThrow(cond, exc)
Definition: exceptions.h:1576
virtual void execute_coarsening_and_refinement() override
static ::ExceptionBase & ExcFlagsNotCleared()
SmartPointer< const Triangulation< dim, spacedim >, PersistentTriangulation< dim, spacedim > > coarse_grid
unsigned int n_levels() const
virtual std::size_t memory_consumption() const override
void load_coarsen_flags(std::istream &out)
Definition: tria.cc:10331
std::vector< std::vector< bool > > refine_flags
virtual void execute_coarsening_and_refinement()
Definition: tria.cc:12703
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
static void write_bool_vector(const unsigned int magic_number1, const std::vector< bool > &v, const unsigned int magic_number2, std::ostream &out)
Definition: tria.cc:14473
#define Assert(cond, exc)
Definition: exceptions.h:1466
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
virtual void copy_triangulation(const Triangulation< dim, spacedim > &tria) override
virtual void create_triangulation_compatibility(const std::vector< Point< spacedim >> &vertices, const std::vector< CellData< dim >> &cells, const SubCellData &subcelldata) override
void save_coarsen_flags(std::ostream &out) const
Definition: tria.cc:10317
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:372
void save_refine_flags(std::ostream &out) const
Definition: tria.cc:10248
PersistentTriangulation(const Triangulation< dim, spacedim > &coarse_grid)
const unsigned int mn_tria_refine_flags_begin
Definition: magic_numbers.h:29
virtual void write_flags(std::ostream &out) const
const unsigned int mn_tria_coarsen_flags_begin
Definition: magic_numbers.h:31
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:371
static ::ExceptionBase & ExcTriaNotEmpty()
virtual void read_flags(std::istream &in)
const unsigned int mn_persistent_tria_flags_end
Definition: magic_numbers.h:40
std::vector< std::vector< bool > > coarsen_flags
virtual void clear()
Definition: tria.cc:9543
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
void load_refine_flags(std::istream &in)
Definition: tria.cc:10262
static ::ExceptionBase & ExcInternalError()