deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+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: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2003 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_mg_level_object_h
14#define dealii_mg_level_object_h
15
16#include <deal.II/base/config.h>
17
19
20#include <memory>
21#include <vector>
22
24
25
45template <class Object>
47{
48public:
70 template <class... Args>
71 MGLevelObject(const unsigned int minlevel,
72 const unsigned int maxlevel,
73 Args &&...args);
74
79 MGLevelObject(const unsigned int minlevel = 0,
80 const unsigned int maxlevel = 0);
81
85 Object &
86 operator[](const unsigned int level);
87
94 const Object &
95 operator[](const unsigned int level) const;
96
100 const Object &
101 back() const;
102
116 template <class... Args>
117 void
118 resize(const unsigned int new_minlevel,
119 const unsigned int new_maxlevel,
120 Args &&...args);
121
129 operator=(const double d);
130
135 void
137
146 void
148
152 unsigned int
153 min_level() const;
154
158 unsigned int
159 max_level() const;
160
164 unsigned int
165 n_levels() const;
166
177 template <typename ActionFunctionObjectType>
178 void
179 apply(ActionFunctionObjectType action);
180
184 std::size_t
186
187private:
191 unsigned int minlevel;
192
196 std::vector<std::shared_ptr<Object>> objects;
197};
198
199
200/* ------------------------------------------------------------------- */
201
202
203template <class Object>
204template <class... Args>
206 const unsigned int max,
207 Args &&...args)
208 : minlevel(0)
209{
210 resize(min, max, std::forward<Args>(args)...);
211}
212
213
214template <class Object>
216 const unsigned int max)
217 : minlevel(0)
218{
219 resize(min, max);
220}
221
222
223template <class Object>
224Object &
226{
227 Assert((i >= minlevel) && (i < minlevel + objects.size()),
228 ExcIndexRange(i, minlevel, minlevel + objects.size()));
229 return *objects[i - minlevel];
230}
231
232
233template <class Object>
234const Object &
235MGLevelObject<Object>::operator[](const unsigned int i) const
236{
237 Assert((i >= minlevel) && (i < minlevel + objects.size()),
238 ExcIndexRange(i, minlevel, minlevel + objects.size()));
239 return *objects[i - minlevel];
240}
241
242
243template <class Object>
244const Object &
246{
247 return this->operator[](this->max_level());
248}
249
250
251template <class Object>
252template <class... Args>
253void
254MGLevelObject<Object>::resize(const unsigned int new_minlevel,
255 const unsigned int new_maxlevel,
256 Args &&...args)
257{
258 Assert(new_minlevel <= new_maxlevel, ExcInternalError());
259 // note that on clear(), the
260 // shared_ptr class takes care of
261 // deleting the object it points to
262 // by itself
263 objects.clear();
264
265 minlevel = new_minlevel;
266 for (unsigned int i = 0; i < new_maxlevel - new_minlevel + 1; ++i)
267 objects.push_back(std::make_shared<Object>(std::forward<Args>(args)...));
268}
269
270
271template <class Object>
274{
275 typename std::vector<std::shared_ptr<Object>>::iterator v;
276 for (v = objects.begin(); v != objects.end(); ++v)
277 **v = d;
278 return *this;
279}
280
281
282template <class Object>
283void
285{
286 minlevel = 0;
287 objects.clear();
288}
289
290
291template <class Object>
292void
294{
295 typename std::vector<std::shared_ptr<Object>>::iterator v;
296 for (v = objects.begin(); v != objects.end(); ++v)
297 (*v)->clear();
298}
299
300
301template <class Object>
302unsigned int
304{
305 return minlevel;
306}
307
308
309template <class Object>
310unsigned int
312{
313 return minlevel + objects.size() - 1;
314}
315
316
317template <class Object>
318unsigned int
320{
321 return objects.size();
322}
323
324template <class Object>
325template <typename ActionFunctionObjectType>
326void
327MGLevelObject<Object>::apply(ActionFunctionObjectType action)
328{
329 for (unsigned int lvl = min_level(); lvl <= max_level(); ++lvl)
330 {
331 action(lvl, (*this)[lvl]);
332 }
333}
334
335
336template <class Object>
337std::size_t
339{
340 std::size_t result = sizeof(*this);
341 using Iter = typename std::vector<std::shared_ptr<Object>>::const_iterator;
342 const Iter end = objects.end();
343 for (Iter o = objects.begin(); o != end; ++o)
344 result += (*o)->memory_consumption();
345
346 return result;
347}
348
350
351#endif
*  iterator end()
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:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
unsigned int level
Definition grid_out.cc:4642
#define Assert(cond, exc)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcIndexRange(std::size_t arg1, std::size_t arg2, std::size_t arg3)