Reference documentation for deal.II version 9.0.0
persistent_tria.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2017 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #include <deal.II/base/memory_consumption.h>
17 #include <deal.II/grid/persistent_tria.h>
18 #include <deal.II/grid/magic_numbers.h>
19 #include <iostream>
20 
21 DEAL_II_NAMESPACE_OPEN
22 
23 
24 template <int dim, int spacedim>
25 const unsigned int
27 
28 template <int dim, int spacedim>
29 const unsigned int
31 
32 
33 template <int dim, int spacedim>
36  :
37  coarse_grid (&coarse_grid, typeid(*this).name())
38 {}
39 
40 
41 
42 template <int dim, int spacedim>
45  :
46  // default initialize
47  // tria, i.e. it will be
48  // empty on first use
49  Triangulation<dim,spacedim> (),
50  coarse_grid (old_tria.coarse_grid),
51  refine_flags (old_tria.refine_flags),
52  coarsen_flags (old_tria.coarsen_flags)
53 {
54  Assert (old_tria.n_levels() == 0, ExcTriaNotEmpty ());
55 }
56 
57 
58 
59 template <int dim, int spacedim>
60 void
62 {
63  // first save flags
64  refine_flags.emplace_back ();
65  coarsen_flags.emplace_back ();
66  this->save_refine_flags (refine_flags.back());
67  this->save_coarsen_flags (coarsen_flags.back());
68 
69  // then refine triangulation. if
70  // this function throws an
71  // exception, that's fine since it
72  // is the last call here
74 }
75 
76 
77 
78 template <int dim, int spacedim>
79 void
81 {
82  // for each of the previous
83  // refinement sweeps
84  for (unsigned int i=0; i<refine_flags.size()+1; ++i)
85  restore(i);
86 }
87 
88 
89 
90 template <int dim, int spacedim>
91 void
93 {
94 
95  if (step==0)
96  // copy the old triangulation.
97  // this will yield an error if
98  // the underlying triangulation
99  // was not empty
101  else
102  // for each of the previous
103  // refinement sweeps
104  {
105  Assert(step<refine_flags.size()+1,
106  ExcDimensionMismatch(step, refine_flags.size()+1));
107 
108  this->load_refine_flags (refine_flags[@ref step_1 "step-1"]);
109  this->load_coarsen_flags (coarsen_flags[@ref step_1 "step-1"]);
110 
112  }
113 }
114 
115 
116 
117 template <int dim, int spacedim>
118 unsigned int
120 {
121  return refine_flags.size();
122 }
123 
124 
125 
126 template <int dim, int spacedim>
127 void
129 {
130  this->clear ();
131  coarse_grid = &old_grid;
132  refine_flags.clear ();
133  coarsen_flags.clear ();
134 }
135 
136 
137 
138 template <int dim, int spacedim>
139 void
141  const std::vector<CellData<dim> > &,
142  const SubCellData &)
143 {
144  Assert (false, ExcImpossibleInDim(dim));
145 }
146 
147 
148 
149 template <int dim, int spacedim>
150 void
152  const std::vector<Point<spacedim> > &,
153  const std::vector<CellData<dim> > &,
154  const SubCellData &)
155 {
156  Assert (false, ExcImpossibleInDim(dim));
157 }
158 
159 
160 
161 template <int dim, int spacedim>
162 void
164 {
165  const unsigned int n_flag_levels=refine_flags.size();
166 
167  AssertThrow (out, ExcIO());
168 
169  out << mn_persistent_tria_flags_begin << ' ' << n_flag_levels << std::endl;
170 
171  for (unsigned int i=0; i<n_flag_levels; ++i)
172  {
173  this->write_bool_vector (mn_tria_refine_flags_begin, refine_flags[i],
174  mn_tria_refine_flags_end, out);
175  this->write_bool_vector (mn_tria_coarsen_flags_begin, coarsen_flags[i],
176  mn_tria_coarsen_flags_end, out);
177  }
178 
179  out << mn_persistent_tria_flags_end << std::endl;
180 
181  AssertThrow (out, ExcIO());
182 }
183 
184 
185 
186 template <int dim, int spacedim>
187 void
189 {
190  Assert(refine_flags.size()==0 && coarsen_flags.size()==0,
191  ExcFlagsNotCleared());
192  AssertThrow (in, ExcIO());
193 
194  unsigned int magic_number;
195  in >> magic_number;
196  AssertThrow(magic_number==mn_persistent_tria_flags_begin,
198 
199  unsigned int n_flag_levels;
200  in >> n_flag_levels;
201  for (unsigned int i=0; i<n_flag_levels; ++i)
202  {
203  refine_flags.emplace_back ();
204  coarsen_flags.emplace_back ();
205  this->read_bool_vector (mn_tria_refine_flags_begin, refine_flags.back(),
206  mn_tria_refine_flags_end, in);
207  this->read_bool_vector (mn_tria_coarsen_flags_begin, coarsen_flags.back(),
208  mn_tria_coarsen_flags_end, in);
209  }
210 
211  in >> magic_number;
212  AssertThrow(magic_number==mn_persistent_tria_flags_end,
214 
215  AssertThrow (in, ExcIO());
216 }
217 
218 
219 
220 template <int dim, int spacedim>
221 void
223 {
224  refine_flags.clear();
225  coarsen_flags.clear();
226 }
227 
228 
229 
230 template <int dim, int spacedim>
231 std::size_t
233 {
237  MemoryConsumption::memory_consumption (coarsen_flags));
238 }
239 
240 
241 // explicit instantiations
242 template class PersistentTriangulation<1>;
243 template class PersistentTriangulation<2>;
244 template class PersistentTriangulation<3>;
245 template class PersistentTriangulation<1,2>;
246 template class PersistentTriangulation<2,3>;
247 
248 DEAL_II_NAMESPACE_CLOSE
virtual void copy_triangulation(const Triangulation< dim, spacedim > &other_tria)
Definition: tria.cc:9159
virtual void create_triangulation_compatibility(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
static ::ExceptionBase & ExcIO()
unsigned int n_refinement_steps() const
virtual void execute_coarsening_and_refinement()
virtual std::size_t memory_consumption() const
#define AssertThrow(cond, exc)
Definition: exceptions.h:1221
unsigned int n_levels() const
virtual void execute_coarsening_and_refinement()
Definition: tria.cc:11739
static ::ExceptionBase & ExcImpossibleInDim(int arg1)
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
#define Assert(cond, exc)
Definition: exceptions.h:1142
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
PersistentTriangulation(const Triangulation< dim, spacedim > &coarse_grid)
virtual void write_flags(std::ostream &out) const
static ::ExceptionBase & ExcTriaNotEmpty()
virtual void copy_triangulation(const Triangulation< dim, spacedim > &tria)
virtual void read_flags(std::istream &in)
virtual void clear()
Definition: tria.cc:8912
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)