Reference documentation for deal.II version 9.3.3
\(\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
48template <class Object>
50{
51public:
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 &operator[](const unsigned int level);
89
96 const Object &operator[](const unsigned int level) const;
97
111 template <class... Args>
112 void
113 resize(const unsigned int new_minlevel,
114 const unsigned int new_maxlevel,
115 Args &&... args);
116
124 operator=(const double d);
125
134 void
136
140 unsigned int
141 min_level() const;
142
146 unsigned int
147 max_level() const;
148
159 template <typename ActionFunctionObjectType>
160 void
161 apply(ActionFunctionObjectType action);
162
166 std::size_t
168
169private:
173 unsigned int minlevel;
174
178 std::vector<std::shared_ptr<Object>> objects;
179};
180
181
182/* ------------------------------------------------------------------- */
183
184
185template <class Object>
186template <class... Args>
188 const unsigned int max,
189 Args &&... args)
190 : minlevel(0)
191{
192 resize(min, max, std::forward<Args>(args)...);
193}
194
195
196template <class Object>
198 const unsigned int max)
199 : minlevel(0)
200{
201 resize(min, max);
202}
203
204
205template <class Object>
206Object &MGLevelObject<Object>::operator[](const unsigned int i)
207{
208 Assert((i >= minlevel) && (i < minlevel + objects.size()),
209 ExcIndexRange(i, minlevel, minlevel + objects.size()));
210 return *objects[i - minlevel];
211}
212
213
214template <class Object>
215const Object &MGLevelObject<Object>::operator[](const unsigned int i) const
216{
217 Assert((i >= minlevel) && (i < minlevel + objects.size()),
218 ExcIndexRange(i, minlevel, minlevel + objects.size()));
219 return *objects[i - minlevel];
220}
221
222
223template <class Object>
224template <class... Args>
225void
226MGLevelObject<Object>::resize(const unsigned int new_minlevel,
227 const unsigned int new_maxlevel,
228 Args &&... args)
229{
230 Assert(new_minlevel <= new_maxlevel, ExcInternalError());
231 // note that on clear(), the
232 // shared_ptr class takes care of
233 // deleting the object it points to
234 // by itself
235 objects.clear();
236
237 minlevel = new_minlevel;
238 for (unsigned int i = 0; i < new_maxlevel - new_minlevel + 1; ++i)
239 objects.push_back(std::make_shared<Object>(std::forward<Args>(args)...));
240}
241
242
243template <class Object>
246{
247 typename std::vector<std::shared_ptr<Object>>::iterator v;
248 for (v = objects.begin(); v != objects.end(); ++v)
249 **v = d;
250 return *this;
251}
252
253
254template <class Object>
255void
257{
258 typename std::vector<std::shared_ptr<Object>>::iterator v;
259 for (v = objects.begin(); v != objects.end(); ++v)
260 (*v)->clear();
261}
262
263
264template <class Object>
265unsigned int
267{
268 return minlevel;
269}
270
271
272template <class Object>
273unsigned int
275{
276 return minlevel + objects.size() - 1;
277}
278
279template <class Object>
280template <typename ActionFunctionObjectType>
281void
282MGLevelObject<Object>::apply(ActionFunctionObjectType action)
283{
284 for (unsigned int lvl = min_level(); lvl <= max_level(); ++lvl)
285 {
286 action(lvl, (*this)[lvl]);
287 }
288}
289
290
291template <class Object>
292std::size_t
294{
295 std::size_t result = sizeof(*this);
296 using Iter = typename std::vector<std::shared_ptr<Object>>::const_iterator;
297 const Iter end = objects.end();
298 for (Iter o = objects.begin(); o != end; ++o)
299 result += (*o)->memory_consumption();
300
301 return result;
302}
303
305
306#endif
std::vector< std::shared_ptr< Object > > objects
Object & operator[](const unsigned int level)
MGLevelObject< Object > & operator=(const double d)
void resize(const unsigned int new_minlevel, const unsigned int new_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
std::size_t memory_consumption() const
unsigned int max_level() const
unsigned int min_level() const
void apply(ActionFunctionObjectType action)
MGLevelObject(const unsigned int minlevel, const unsigned int maxlevel, Args &&... args)
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:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
unsigned int level
Definition: grid_out.cc:4590
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
#define Assert(cond, exc)
Definition: exceptions.h:1465
static ::ExceptionBase & ExcInternalError()
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
VectorType::value_type * end(VectorType &V)