Reference documentation for deal.II version 8.5.1
persistent_tria.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1999 - 2014 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>
61 {}
62 
63 
64 
65 template <int dim, int spacedim>
66 void
68 {
69  // first save flags
70  refine_flags.push_back (std::vector<bool>());
71  coarsen_flags.push_back (std::vector<bool>());
72  this->save_refine_flags (refine_flags.back());
73  this->save_coarsen_flags (coarsen_flags.back());
74 
75  // then refine triangulation. if
76  // this function throws an
77  // exception, that's fine since it
78  // is the last call here
80 }
81 
82 
83 
84 template <int dim, int spacedim>
85 void
87 {
88  // for each of the previous
89  // refinement sweeps
90  for (unsigned int i=0; i<refine_flags.size()+1; ++i)
91  restore(i);
92 }
93 
94 
95 
96 template <int dim, int spacedim>
97 void
99 {
100 
101  if (step==0)
102  // copy the old triangulation.
103  // this will yield an error if
104  // the underlying triangulation
105  // was not empty
107  else
108  // for each of the previous
109  // refinement sweeps
110  {
111  Assert(step<refine_flags.size()+1,
112  ExcDimensionMismatch(step, refine_flags.size()+1));
113 
114  this->load_refine_flags (refine_flags[@ref step_1 "step-1"]);
115  this->load_coarsen_flags (coarsen_flags[@ref step_1 "step-1"]);
116 
118  }
119 }
120 
121 
122 
123 template <int dim, int spacedim>
124 unsigned int
126 {
127  return refine_flags.size();
128 }
129 
130 
131 
132 template <int dim, int spacedim>
133 void
135 {
136  this->clear ();
137  coarse_grid = &old_grid;
138  refine_flags.clear ();
139  coarsen_flags.clear ();
140 }
141 
142 
143 
144 template <int dim, int spacedim>
145 void
147  const std::vector<CellData<dim> > &,
148  const SubCellData &)
149 {
150  Assert (false, ExcImpossibleInDim(dim));
151 }
152 
153 
154 
155 template <int dim, int spacedim>
156 void
158  const std::vector<Point<spacedim> > &,
159  const std::vector<CellData<dim> > &,
160  const SubCellData &)
161 {
162  Assert (false, ExcImpossibleInDim(dim));
163 }
164 
165 
166 
167 template <int dim, int spacedim>
168 void
170 {
171  const unsigned int n_flag_levels=refine_flags.size();
172 
173  AssertThrow (out, ExcIO());
174 
175  out << mn_persistent_tria_flags_begin << ' ' << n_flag_levels << std::endl;
176 
177  for (unsigned int i=0; i<n_flag_levels; ++i)
178  {
179  this->write_bool_vector (mn_tria_refine_flags_begin, refine_flags[i],
180  mn_tria_refine_flags_end, out);
181  this->write_bool_vector (mn_tria_coarsen_flags_begin, coarsen_flags[i],
182  mn_tria_coarsen_flags_end, out);
183  }
184 
185  out << mn_persistent_tria_flags_end << std::endl;
186 
187  AssertThrow (out, ExcIO());
188 }
189 
190 
191 
192 template <int dim, int spacedim>
193 void
195 {
196  Assert(refine_flags.size()==0 && coarsen_flags.size()==0,
197  ExcFlagsNotCleared());
198  AssertThrow (in, ExcIO());
199 
200  unsigned int magic_number;
201  in >> magic_number;
202  AssertThrow(magic_number==mn_persistent_tria_flags_begin,
204 
205  unsigned int n_flag_levels;
206  in >> n_flag_levels;
207  for (unsigned int i=0; i<n_flag_levels; ++i)
208  {
209  refine_flags.push_back (std::vector<bool>());
210  coarsen_flags.push_back (std::vector<bool>());
211  this->read_bool_vector (mn_tria_refine_flags_begin, refine_flags.back(),
212  mn_tria_refine_flags_end, in);
213  this->read_bool_vector (mn_tria_coarsen_flags_begin, coarsen_flags.back(),
214  mn_tria_coarsen_flags_end, in);
215  }
216 
217  in >> magic_number;
218  AssertThrow(magic_number==mn_persistent_tria_flags_end,
220 
221  AssertThrow (in, 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 {
243  MemoryConsumption::memory_consumption (coarsen_flags));
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 
254 DEAL_II_NAMESPACE_CLOSE
255 
virtual void copy_triangulation(const Triangulation< dim, spacedim > &other_tria)
Definition: tria.cc:9315
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:369
unsigned int n_levels() const
virtual void execute_coarsening_and_refinement()
Definition: tria.cc:11899
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:313
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
std_cxx11::enable_if< std_cxx11::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)
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:9080