Reference documentation for deal.II version GIT relicensing-136-gb80d0be4af 2024-03-18 08: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\}}\)
Loading...
Searching...
No Matches
mg_level_object.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2003 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_mg_level_object_h
16#define dealii_mg_level_object_h
17
18#include <deal.II/base/config.h>
19
21
22#include <memory>
23#include <vector>
24
26
27
47template <class Object>
49{
50public:
72 template <class... Args>
73 MGLevelObject(const unsigned int minlevel,
74 const unsigned int maxlevel,
75 Args &&...args);
76
81 MGLevelObject(const unsigned int minlevel = 0,
82 const unsigned int maxlevel = 0);
83
87 Object &
88 operator[](const unsigned int level);
89
96 const Object &
97 operator[](const unsigned int level) const;
98
102 const Object &
103 back() const;
104
118 template <class... Args>
119 void
120 resize(const unsigned int new_minlevel,
121 const unsigned int new_maxlevel,
122 Args &&...args);
123
131 operator=(const double d);
132
137 void
139
148 void
150
154 unsigned int
155 min_level() const;
156
160 unsigned int
161 max_level() const;
162
166 unsigned int
167 n_levels() const;
168
179 template <typename ActionFunctionObjectType>
180 void
181 apply(ActionFunctionObjectType action);
182
186 std::size_t
188
189private:
193 unsigned int minlevel;
194
198 std::vector<std::shared_ptr<Object>> objects;
199};
200
201
202/* ------------------------------------------------------------------- */
203
204
205template <class Object>
206template <class... Args>
208 const unsigned int max,
209 Args &&...args)
210 : minlevel(0)
211{
212 resize(min, max, std::forward<Args>(args)...);
213}
214
215
216template <class Object>
218 const unsigned int max)
219 : minlevel(0)
220{
221 resize(min, max);
222}
223
224
225template <class Object>
226Object &
228{
229 Assert((i >= minlevel) && (i < minlevel + objects.size()),
230 ExcIndexRange(i, minlevel, minlevel + objects.size()));
231 return *objects[i - minlevel];
232}
233
234
235template <class Object>
236const Object &
237MGLevelObject<Object>::operator[](const unsigned int i) const
238{
239 Assert((i >= minlevel) && (i < minlevel + objects.size()),
240 ExcIndexRange(i, minlevel, minlevel + objects.size()));
241 return *objects[i - minlevel];
242}
243
244
245template <class Object>
246const Object &
248{
249 return this->operator[](this->max_level());
250}
251
252
253template <class Object>
254template <class... Args>
255void
256MGLevelObject<Object>::resize(const unsigned int new_minlevel,
257 const unsigned int new_maxlevel,
258 Args &&...args)
259{
260 Assert(new_minlevel <= new_maxlevel, ExcInternalError());
261 // note that on clear(), the
262 // shared_ptr class takes care of
263 // deleting the object it points to
264 // by itself
265 objects.clear();
266
267 minlevel = new_minlevel;
268 for (unsigned int i = 0; i < new_maxlevel - new_minlevel + 1; ++i)
269 objects.push_back(std::make_shared<Object>(std::forward<Args>(args)...));
270}
271
272
273template <class Object>
276{
277 typename std::vector<std::shared_ptr<Object>>::iterator v;
278 for (v = objects.begin(); v != objects.end(); ++v)
279 **v = d;
280 return *this;
281}
282
283
284template <class Object>
285void
287{
288 minlevel = 0;
289 objects.clear();
290}
291
292
293template <class Object>
294void
296{
297 typename std::vector<std::shared_ptr<Object>>::iterator v;
298 for (v = objects.begin(); v != objects.end(); ++v)
299 (*v)->clear();
300}
301
302
303template <class Object>
304unsigned int
306{
307 return minlevel;
308}
309
310
311template <class Object>
312unsigned int
314{
315 return minlevel + objects.size() - 1;
316}
317
318
319template <class Object>
320unsigned int
322{
323 return objects.size();
324}
325
326template <class Object>
327template <typename ActionFunctionObjectType>
328void
329MGLevelObject<Object>::apply(ActionFunctionObjectType action)
330{
331 for (unsigned int lvl = min_level(); lvl <= max_level(); ++lvl)
332 {
333 action(lvl, (*this)[lvl]);
334 }
335}
336
337
338template <class Object>
339std::size_t
341{
342 std::size_t result = sizeof(*this);
343 using Iter = typename std::vector<std::shared_ptr<Object>>::const_iterator;
344 const Iter end = objects.end();
345 for (Iter o = objects.begin(); o != end; ++o)
346 result += (*o)->memory_consumption();
347
348 return result;
349}
350
352
353#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)
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
unsigned int level
Definition grid_out.cc:4616
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)