Reference documentation for deal.II version GIT 6bdf9a4b6c 2022-08-12 19:20: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 
142  void
144 
148  unsigned int
149  min_level() const;
150 
154  unsigned int
155  max_level() const;
156 
160  unsigned int
161  n_levels() const;
162 
173  template <typename ActionFunctionObjectType>
174  void
175  apply(ActionFunctionObjectType action);
176 
180  std::size_t
182 
183 private:
187  unsigned int minlevel;
188 
192  std::vector<std::shared_ptr<Object>> objects;
193 };
194 
195 
196 /* ------------------------------------------------------------------- */
197 
198 
199 template <class Object>
200 template <class... Args>
202  const unsigned int max,
203  Args &&...args)
204  : minlevel(0)
205 {
206  resize(min, max, std::forward<Args>(args)...);
207 }
208 
209 
210 template <class Object>
212  const unsigned int max)
213  : minlevel(0)
214 {
215  resize(min, max);
216 }
217 
218 
219 template <class Object>
220 Object &
222 {
223  Assert((i >= minlevel) && (i < minlevel + objects.size()),
224  ExcIndexRange(i, minlevel, minlevel + objects.size()));
225  return *objects[i - minlevel];
226 }
227 
228 
229 template <class Object>
230 const Object &
231 MGLevelObject<Object>::operator[](const unsigned int i) const
232 {
233  Assert((i >= minlevel) && (i < minlevel + objects.size()),
234  ExcIndexRange(i, minlevel, minlevel + objects.size()));
235  return *objects[i - minlevel];
236 }
237 
238 
239 template <class Object>
240 const Object &
242 {
243  return this->operator[](this->max_level());
244 }
245 
246 
247 template <class Object>
248 template <class... Args>
249 void
250 MGLevelObject<Object>::resize(const unsigned int new_minlevel,
251  const unsigned int new_maxlevel,
252  Args &&...args)
253 {
254  Assert(new_minlevel <= new_maxlevel, ExcInternalError());
255  // note that on clear(), the
256  // shared_ptr class takes care of
257  // deleting the object it points to
258  // by itself
259  objects.clear();
260 
261  minlevel = new_minlevel;
262  for (unsigned int i = 0; i < new_maxlevel - new_minlevel + 1; ++i)
263  objects.push_back(std::make_shared<Object>(std::forward<Args>(args)...));
264 }
265 
266 
267 template <class Object>
270 {
271  typename std::vector<std::shared_ptr<Object>>::iterator v;
272  for (v = objects.begin(); v != objects.end(); ++v)
273  **v = d;
274  return *this;
275 }
276 
277 
278 template <class Object>
279 void
281 {
282  typename std::vector<std::shared_ptr<Object>>::iterator v;
283  for (v = objects.begin(); v != objects.end(); ++v)
284  (*v)->clear();
285 }
286 
287 
288 template <class Object>
289 unsigned int
291 {
292  return minlevel;
293 }
294 
295 
296 template <class Object>
297 unsigned int
299 {
300  return minlevel + objects.size() - 1;
301 }
302 
303 
304 template <class Object>
305 unsigned int
307 {
308  return objects.size();
309 }
310 
311 template <class Object>
312 template <typename ActionFunctionObjectType>
313 void
314 MGLevelObject<Object>::apply(ActionFunctionObjectType action)
315 {
316  for (unsigned int lvl = min_level(); lvl <= max_level(); ++lvl)
317  {
318  action(lvl, (*this)[lvl]);
319  }
320 }
321 
322 
323 template <class Object>
324 std::size_t
326 {
327  std::size_t result = sizeof(*this);
328  using Iter = typename std::vector<std::shared_ptr<Object>>::const_iterator;
329  const Iter end = objects.end();
330  for (Iter o = objects.begin(); o != end; ++o)
331  result += (*o)->memory_consumption();
332 
333  return result;
334 }
335 
337 
338 #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:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
unsigned int level
Definition: grid_out.cc:4607
static ::ExceptionBase & ExcInternalError()
#define Assert(cond, exc)
Definition: exceptions.h:1473
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)