Reference documentation for deal.II version GIT 29f9da0a34 2023-12-07 10:00:01+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\}}\)
persistent_tria.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2022 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 {
164  const unsigned int n_flag_levels = refine_flags.size();
165 
166  AssertThrow(out.fail() == false, 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],
175  out);
176  this->write_bool_vector(mn_tria_coarsen_flags_begin,
177  coarsen_flags[i],
179  out);
180  }
181 
182  out << mn_persistent_tria_flags_end << std::endl;
183 
184  AssertThrow(out.fail() == false, ExcIO());
185 }
186 
187 
188 
189 template <int dim, int spacedim>
190 void
192 {
193  Assert(refine_flags.empty() && coarsen_flags.empty(), ExcFlagsNotCleared());
194  AssertThrow(in.fail() == false, ExcIO());
195 
196  unsigned int magic_number;
197  in >> magic_number;
200 
201  unsigned int n_flag_levels;
202  in >> n_flag_levels;
203  for (unsigned int i = 0; i < n_flag_levels; ++i)
204  {
205  refine_flags.emplace_back();
206  coarsen_flags.emplace_back();
207  this->read_bool_vector(mn_tria_refine_flags_begin,
208  refine_flags.back(),
210  in);
211  this->read_bool_vector(mn_tria_coarsen_flags_begin,
212  coarsen_flags.back(),
214  in);
215  }
216 
217  in >> magic_number;
220 
221  AssertThrow(in.fail() == false, ExcIO());
222 }
223 
224 
225 
226 template <int dim, int spacedim>
227 void
229 {
230  refine_flags.clear();
231  coarsen_flags.clear();
232 }
233 
234 
235 
236 template <int dim, int spacedim>
237 std::size_t
239 {
244 }
245 
246 
247 // explicit instantiations
248 template class PersistentTriangulation<1>;
249 template class PersistentTriangulation<2>;
250 template class PersistentTriangulation<3>;
251 template class PersistentTriangulation<1, 2>;
252 template class PersistentTriangulation<2, 3>;
253 
virtual void read_flags(std::istream &in)
virtual void create_triangulation(const std::vector< Point< spacedim >> &vertices, const std::vector< CellData< dim >> &cells, const SubCellData &subcelldata) override
virtual void write_flags(std::ostream &out) const
virtual std::size_t memory_consumption() const 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:477
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
#define Assert(cond, exc)
Definition: exceptions.h:1631
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
static ::ExceptionBase & ExcTriaNotEmpty()
static ::ExceptionBase & ExcIO()
#define AssertThrow(cond, exc)
Definition: exceptions.h:1732
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_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)