Reference documentation for deal.II version GIT 7b2de2f2f9 2023-09-24 11:00:02+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\}}\)
mg_level_object.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 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 
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:
73  template <class... Args>
74  MGLevelObject(const unsigned int minlevel,
75  const unsigned int maxlevel,
76  Args &&...args);
77 
82  MGLevelObject(const unsigned int minlevel = 0,
83  const unsigned int maxlevel = 0);
84 
88  Object &
89  operator[](const unsigned int level);
90 
97  const Object &
98  operator[](const unsigned int level) const;
99 
103  const Object &
104  back() const;
105 
119  template <class... Args>
120  void
121  resize(const unsigned int new_minlevel,
122  const unsigned int new_maxlevel,
123  Args &&...args);
124 
132  operator=(const double d);
133 
138  void
139  clear();
140 
149  void
151 
155  unsigned int
156  min_level() const;
157 
161  unsigned int
162  max_level() const;
163 
167  unsigned int
168  n_levels() const;
169 
180  template <typename ActionFunctionObjectType>
181  void
182  apply(ActionFunctionObjectType action);
183 
187  std::size_t
189 
190 private:
194  unsigned int minlevel;
195 
199  std::vector<std::shared_ptr<Object>> objects;
200 };
201 
202 
203 /* ------------------------------------------------------------------- */
204 
205 
206 template <class Object>
207 template <class... Args>
209  const unsigned int max,
210  Args &&...args)
211  : minlevel(0)
212 {
213  resize(min, max, std::forward<Args>(args)...);
214 }
215 
216 
217 template <class Object>
219  const unsigned int max)
220  : minlevel(0)
221 {
222  resize(min, max);
223 }
224 
225 
226 template <class Object>
227 Object &
229 {
230  Assert((i >= minlevel) && (i < minlevel + objects.size()),
231  ExcIndexRange(i, minlevel, minlevel + objects.size()));
232  return *objects[i - minlevel];
233 }
234 
235 
236 template <class Object>
237 const Object &
238 MGLevelObject<Object>::operator[](const unsigned int i) const
239 {
240  Assert((i >= minlevel) && (i < minlevel + objects.size()),
241  ExcIndexRange(i, minlevel, minlevel + objects.size()));
242  return *objects[i - minlevel];
243 }
244 
245 
246 template <class Object>
247 const Object &
249 {
250  return this->operator[](this->max_level());
251 }
252 
253 
254 template <class Object>
255 template <class... Args>
256 void
257 MGLevelObject<Object>::resize(const unsigned int new_minlevel,
258  const unsigned int new_maxlevel,
259  Args &&...args)
260 {
261  Assert(new_minlevel <= new_maxlevel, ExcInternalError());
262  // note that on clear(), the
263  // shared_ptr class takes care of
264  // deleting the object it points to
265  // by itself
266  objects.clear();
267 
268  minlevel = new_minlevel;
269  for (unsigned int i = 0; i < new_maxlevel - new_minlevel + 1; ++i)
270  objects.push_back(std::make_shared<Object>(std::forward<Args>(args)...));
271 }
272 
273 
274 template <class Object>
277 {
278  typename std::vector<std::shared_ptr<Object>>::iterator v;
279  for (v = objects.begin(); v != objects.end(); ++v)
280  **v = d;
281  return *this;
282 }
283 
284 
285 template <class Object>
286 void
288 {
289  minlevel = 0;
290  objects.clear();
291 }
292 
293 
294 template <class Object>
295 void
297 {
298  typename std::vector<std::shared_ptr<Object>>::iterator v;
299  for (v = objects.begin(); v != objects.end(); ++v)
300  (*v)->clear();
301 }
302 
303 
304 template <class Object>
305 unsigned int
307 {
308  return minlevel;
309 }
310 
311 
312 template <class Object>
313 unsigned int
315 {
316  return minlevel + objects.size() - 1;
317 }
318 
319 
320 template <class Object>
321 unsigned int
323 {
324  return objects.size();
325 }
326 
327 template <class Object>
328 template <typename ActionFunctionObjectType>
329 void
330 MGLevelObject<Object>::apply(ActionFunctionObjectType action)
331 {
332  for (unsigned int lvl = min_level(); lvl <= max_level(); ++lvl)
333  {
334  action(lvl, (*this)[lvl]);
335  }
336 }
337 
338 
339 template <class Object>
340 std::size_t
342 {
343  std::size_t result = sizeof(*this);
344  using Iter = typename std::vector<std::shared_ptr<Object>>::const_iterator;
345  const Iter end = objects.end();
346  for (Iter o = objects.begin(); o != end; ++o)
347  result += (*o)->memory_consumption();
348 
349  return result;
350 }
351 
353 
354 #endif
std::vector< std::shared_ptr< Object > > objects
Object & operator[](const unsigned int level)
MGLevelObject< Object > & operator=(const double d)
MGLevelObject(const unsigned int minlevel, const unsigned int maxlevel, Args &&...args)
unsigned int minlevel
MGLevelObject(const unsigned int minlevel=0, const unsigned int maxlevel=0)
const Object & operator[](const unsigned int level) const
void resize(const unsigned int new_minlevel, const unsigned int new_maxlevel, Args &&...args)
std::size_t memory_consumption() const
unsigned int max_level() const
unsigned int min_level() const
const Object & back() const
unsigned int n_levels() const
void apply(ActionFunctionObjectType action)
VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &x, const ::VectorizedArray< Number, width > &y)
VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &x, const ::VectorizedArray< Number, width > &y)
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:477
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:478
unsigned int level
Definition: grid_out.cc:4617
static ::ExceptionBase & ExcInternalError()
#define Assert(cond, exc)
Definition: exceptions.h:1616
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
VectorType::value_type * end(VectorType &V)