Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
persistent_tria.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2018 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 
16 #include <deal.II/base/memory_consumption.h>
17 
18 #include <deal.II/grid/magic_numbers.h>
19 #include <deal.II/grid/persistent_tria.h>
20 
21 #include <iostream>
22 
23 DEAL_II_NAMESPACE_OPEN
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
151  const std::vector<Point<spacedim>> &,
152  const std::vector<CellData<dim>> &,
153  const SubCellData &)
154 {
155  Assert(false, ExcImpossibleInDim(dim));
156 }
157 
158 
159 
160 template <int dim, int spacedim>
161 void
163 {
164  const unsigned int n_flag_levels = refine_flags.size();
165 
166  AssertThrow(out, ExcIO());
167 
168  out << mn_persistent_tria_flags_begin << ' ' << n_flag_levels << std::endl;
169 
170  for (unsigned int i = 0; i < n_flag_levels; ++i)
171  {
172  this->write_bool_vector(mn_tria_refine_flags_begin,
173  refine_flags[i],
174  mn_tria_refine_flags_end,
175  out);
176  this->write_bool_vector(mn_tria_coarsen_flags_begin,
177  coarsen_flags[i],
178  mn_tria_coarsen_flags_end,
179  out);
180  }
181 
182  out << mn_persistent_tria_flags_end << std::endl;
183 
184  AssertThrow(out, ExcIO());
185 }
186 
187 
188 
189 template <int dim, int spacedim>
190 void
192 {
193  Assert(refine_flags.size() == 0 && coarsen_flags.size() == 0,
194  ExcFlagsNotCleared());
195  AssertThrow(in, ExcIO());
196 
197  unsigned int magic_number;
198  in >> magic_number;
199  AssertThrow(magic_number == mn_persistent_tria_flags_begin,
201 
202  unsigned int n_flag_levels;
203  in >> n_flag_levels;
204  for (unsigned int i = 0; i < n_flag_levels; ++i)
205  {
206  refine_flags.emplace_back();
207  coarsen_flags.emplace_back();
208  this->read_bool_vector(mn_tria_refine_flags_begin,
209  refine_flags.back(),
210  mn_tria_refine_flags_end,
211  in);
212  this->read_bool_vector(mn_tria_coarsen_flags_begin,
213  coarsen_flags.back(),
214  mn_tria_coarsen_flags_end,
215  in);
216  }
217 
218  in >> magic_number;
219  AssertThrow(magic_number == mn_persistent_tria_flags_end,
221 
222  AssertThrow(in, ExcIO());
223 }
224 
225 
226 
227 template <int dim, int spacedim>
228 void
230 {
231  refine_flags.clear();
232  coarsen_flags.clear();
233 }
234 
235 
236 
237 template <int dim, int spacedim>
238 std::size_t
240 {
245 }
246 
247 
248 // explicit instantiations
249 template class PersistentTriangulation<1>;
250 template class PersistentTriangulation<2>;
251 template class PersistentTriangulation<3>;
252 template class PersistentTriangulation<1, 2>;
253 template class PersistentTriangulation<2, 3>;
254 
255 DEAL_II_NAMESPACE_CLOSE
virtual void copy_triangulation(const Triangulation< dim, spacedim > &other_tria)
Definition: tria.cc:10421
static ::ExceptionBase & ExcIO()
unsigned int n_refinement_steps() const
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:1519
virtual void execute_coarsening_and_refinement() override
unsigned int n_levels() const
virtual std::size_t memory_consumption() const override
virtual void execute_coarsening_and_refinement()
Definition: tria.cc:13267
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
#define Assert(cond, exc)
Definition: exceptions.h:1407
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
PersistentTriangulation(const Triangulation< dim, spacedim > &coarse_grid)
virtual void write_flags(std::ostream &out) const
static ::ExceptionBase & ExcTriaNotEmpty()
virtual void read_flags(std::istream &in)
virtual void clear()
Definition: tria.cc:10180
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)