Reference documentation for deal.II version 9.1.0-pre
tria_levels.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2006 - 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/tria_levels.h>
19 
20 DEAL_II_NAMESPACE_OPEN
21 
22 
23 namespace internal
24 {
25  namespace TriangulationImplementation
26  {
27  template <int dim>
28  void
29  TriaLevel<dim>::reserve_space(const unsigned int total_cells,
30  const unsigned int dimension,
31  const unsigned int space_dimension)
32  {
33  // we need space for total_cells cells. Maybe we have more already
34  // with those cells which are unused, so only allocate new space if
35  // needed.
36  //
37  // note that all arrays should have equal sizes (checked by
38  // @p{monitor_memory}
39  if (total_cells > refine_flags.size())
40  {
41  refine_flags.reserve(total_cells);
42  refine_flags.insert(refine_flags.end(),
43  total_cells - refine_flags.size(),
45 
46  coarsen_flags.reserve(total_cells);
47  coarsen_flags.insert(coarsen_flags.end(),
48  total_cells - coarsen_flags.size(),
49  false);
50 
51  active_cell_indices.reserve(total_cells);
52  active_cell_indices.insert(active_cell_indices.end(),
53  total_cells - active_cell_indices.size(),
55 
56  subdomain_ids.reserve(total_cells);
57  subdomain_ids.insert(subdomain_ids.end(),
58  total_cells - subdomain_ids.size(),
59  0);
60 
61  level_subdomain_ids.reserve(total_cells);
62  level_subdomain_ids.insert(level_subdomain_ids.end(),
63  total_cells - level_subdomain_ids.size(),
64  0);
65 
66  if (dimension < space_dimension)
67  {
68  direction_flags.reserve(total_cells);
69  direction_flags.insert(direction_flags.end(),
70  total_cells - direction_flags.size(),
71  true);
72  }
73  else
74  direction_flags.clear();
75 
76  parents.reserve((int)(total_cells + 1) / 2);
77  parents.insert(parents.end(),
78  (total_cells + 1) / 2 - parents.size(),
79  -1);
80 
81  neighbors.reserve(total_cells * (2 * dimension));
82  neighbors.insert(neighbors.end(),
83  total_cells * (2 * dimension) - neighbors.size(),
84  std::make_pair(-1, -1));
85  };
86  }
87 
88 
89  template <int dim>
90  void
91  TriaLevel<dim>::monitor_memory(const unsigned int true_dimension) const
92  {
93  (void)true_dimension;
94  Assert(2 * true_dimension * refine_flags.size() == neighbors.size(),
95  ExcMemoryInexact(refine_flags.size(), neighbors.size()));
96  Assert(2 * true_dimension * coarsen_flags.size() == neighbors.size(),
97  ExcMemoryInexact(coarsen_flags.size(), neighbors.size()));
98  }
99 
100 
101  template <int dim>
102  std::size_t
104  {
105  return (MemoryConsumption::memory_consumption(refine_flags) +
107  MemoryConsumption::memory_consumption(active_cell_indices) +
110  MemoryConsumption::memory_consumption(level_subdomain_ids) +
112  MemoryConsumption::memory_consumption(direction_flags) +
114  }
115 
116  // This specialization should be only temporary, until the TriaObjects
117  // classes are straightened out.
118 
119  void
120  TriaLevel<3>::reserve_space(const unsigned int total_cells,
121  const unsigned int dimension,
122  const unsigned int space_dimension)
123  {
124  // we need space for total_cells
125  // cells. Maybe we have more already
126  // with those cells which are unused,
127  // so only allocate new space if needed.
128  //
129  // note that all arrays should have equal
130  // sizes (checked by @p{monitor_memory}
131  if (total_cells > refine_flags.size())
132  {
133  refine_flags.reserve(total_cells);
134  refine_flags.insert(refine_flags.end(),
135  total_cells - refine_flags.size(),
137 
138  coarsen_flags.reserve(total_cells);
139  coarsen_flags.insert(coarsen_flags.end(),
140  total_cells - coarsen_flags.size(),
141  false);
142 
143  active_cell_indices.reserve(total_cells);
145  total_cells - active_cell_indices.size(),
147 
148  subdomain_ids.reserve(total_cells);
149  subdomain_ids.insert(subdomain_ids.end(),
150  total_cells - subdomain_ids.size(),
151  0);
152 
153  level_subdomain_ids.reserve(total_cells);
155  total_cells - level_subdomain_ids.size(),
156  0);
157 
158  if (dimension < space_dimension)
159  {
160  direction_flags.reserve(total_cells);
161  direction_flags.insert(direction_flags.end(),
162  total_cells - direction_flags.size(),
163  true);
164  }
165  else
166  direction_flags.clear();
167 
168  parents.reserve((int)(total_cells + 1) / 2);
169  parents.insert(parents.end(),
170  (total_cells + 1) / 2 - parents.size(),
171  -1);
172 
173  neighbors.reserve(total_cells * (2 * dimension));
174  neighbors.insert(neighbors.end(),
175  total_cells * (2 * dimension) - neighbors.size(),
176  std::make_pair(-1, -1));
177  };
178  }
179 
180 
181  void
182  TriaLevel<3>::monitor_memory(const unsigned int true_dimension) const
183  {
184  (void)true_dimension;
185  Assert(2 * true_dimension * refine_flags.size() == neighbors.size(),
186  ExcMemoryInexact(refine_flags.size(), neighbors.size()));
187  Assert(2 * true_dimension * coarsen_flags.size() == neighbors.size(),
188  ExcMemoryInexact(coarsen_flags.size(), neighbors.size()));
189  }
190 
191 
192  std::size_t
194  {
203  }
204  } // namespace TriangulationImplementation
205 } // namespace internal
206 
207 
210 
211 DEAL_II_NAMESPACE_CLOSE
TriaObjects< TriaObject< dim > > cells
Definition: tria_levels.h:156
static const unsigned int invalid_unsigned_int
Definition: types.h:173
std::vector< std::pair< int, int > > neighbors
Definition: tria_levels.h:118
std::vector< types::subdomain_id > level_subdomain_ids
Definition: tria_levels.h:131
void reserve_space(const unsigned int total_cells, const unsigned int dimension, const unsigned int space_dimension)
Definition: tria_levels.cc:29
std::vector< std::uint8_t > refine_flags
Definition: tria_levels.h:69
std::vector< unsigned int > active_cell_indices
Definition: tria_levels.h:83
std::vector< types::subdomain_id > subdomain_ids
Definition: tria_levels.h:126
#define Assert(cond, exc)
Definition: exceptions.h:1227
static::ExceptionBase & ExcMemoryInexact(int arg1, int arg2)
void monitor_memory(const unsigned int true_dimension) const
Definition: tria_levels.cc:91
std::enable_if< std::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)