Reference documentation for deal.II version Git 06d359936b 2020-09-19 18:16:22 -0400
\(\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\}}\)
mg_level_object.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 2020 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 #ifndef dealii_mg_level_object_h
17 #define dealii_mg_level_object_h
18 
19 #include <deal.II/base/config.h>
20 
22 
23 #include <memory>
24 #include <vector>
25 
27 
28 
48 template <class Object>
49 class MGLevelObject : public Subscriptor
50 {
51 public:
71  MGLevelObject(const unsigned int minlevel = 0,
72  const unsigned int maxlevel = 0);
73 
77  Object &operator[](const unsigned int level);
78 
85  const Object &operator[](const unsigned int level) const;
86 
98  void
99  resize(const unsigned int new_minlevel, const unsigned int new_maxlevel);
100 
108  operator=(const double d);
109 
118  void
119  clear_elements();
120 
124  unsigned int
125  min_level() const;
126 
130  unsigned int
131  max_level() const;
132 
143  template <typename ActionFunctionObjectType>
144  void
145  apply(ActionFunctionObjectType action);
146 
150  std::size_t
151  memory_consumption() const;
152 
153 private:
157  unsigned int minlevel;
158 
162  std::vector<std::shared_ptr<Object>> objects;
163 };
164 
165 
166 /* ------------------------------------------------------------------- */
167 
168 
169 template <class Object>
171  const unsigned int max)
172  : minlevel(0)
173 {
174  resize(min, max);
175 }
176 
177 
178 template <class Object>
179 Object &MGLevelObject<Object>::operator[](const unsigned int i)
180 {
181  Assert((i >= minlevel) && (i < minlevel + objects.size()),
182  ExcIndexRange(i, minlevel, minlevel + objects.size()));
183  return *objects[i - minlevel];
184 }
185 
186 
187 template <class Object>
188 const Object &MGLevelObject<Object>::operator[](const unsigned int i) const
189 {
190  Assert((i >= minlevel) && (i < minlevel + objects.size()),
191  ExcIndexRange(i, minlevel, minlevel + objects.size()));
192  return *objects[i - minlevel];
193 }
194 
195 
196 template <class Object>
197 void
198 MGLevelObject<Object>::resize(const unsigned int new_minlevel,
199  const unsigned int new_maxlevel)
200 {
201  Assert(new_minlevel <= new_maxlevel, ExcInternalError());
202  // note that on clear(), the
203  // shared_ptr class takes care of
204  // deleting the object it points to
205  // by itself
206  objects.clear();
207 
208  minlevel = new_minlevel;
209  for (unsigned int i = 0; i < new_maxlevel - new_minlevel + 1; ++i)
210  objects.push_back(std::make_shared<Object>());
211 }
212 
213 
214 template <class Object>
217 {
218  typename std::vector<std::shared_ptr<Object>>::iterator v;
219  for (v = objects.begin(); v != objects.end(); ++v)
220  **v = d;
221  return *this;
222 }
223 
224 
225 template <class Object>
226 void
228 {
229  typename std::vector<std::shared_ptr<Object>>::iterator v;
230  for (v = objects.begin(); v != objects.end(); ++v)
231  (*v)->clear();
232 }
233 
234 
235 template <class Object>
236 unsigned int
238 {
239  return minlevel;
240 }
241 
242 
243 template <class Object>
244 unsigned int
246 {
247  return minlevel + objects.size() - 1;
248 }
249 
250 template <class Object>
251 template <typename ActionFunctionObjectType>
252 void
253 MGLevelObject<Object>::apply(ActionFunctionObjectType action)
254 {
255  for (unsigned int lvl = min_level(); lvl <= max_level(); ++lvl)
256  {
257  action(lvl, (*this)[lvl]);
258  }
259 }
260 
261 
262 template <class Object>
263 std::size_t
265 {
266  std::size_t result = sizeof(*this);
267  using Iter = typename std::vector<std::shared_ptr<Object>>::const_iterator;
268  const Iter end = objects.end();
269  for (Iter o = objects.begin(); o != end; ++o)
270  result += (*o)->memory_consumption();
271 
272  return result;
273 }
274 
276 
277 #endif
unsigned int max_level() const
Object & operator[](const unsigned int level)
MGLevelObject(const unsigned int minlevel=0, const unsigned int maxlevel=0)
std::vector< std::shared_ptr< Object > > objects
void apply(ActionFunctionObjectType action)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
std::size_t memory_consumption() const
unsigned int min_level() const
#define Assert(cond, exc)
Definition: exceptions.h:1411
unsigned int minlevel
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:363
unsigned int level
Definition: grid_out.cc:4338
VectorType::value_type * end(VectorType &V)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
MGLevelObject< Object > & operator=(const double d)
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:362
T min(const T &t, const MPI_Comm &mpi_communicator)
void resize(const unsigned int new_minlevel, const unsigned int new_maxlevel)
T max(const T &t, const MPI_Comm &mpi_communicator)
static ::ExceptionBase & ExcInternalError()