Reference documentation for deal.II version 9.2.0
\(\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 
49 template <class Object>
50 class MGLevelObject : public Subscriptor
51 {
52 public:
72  MGLevelObject(const unsigned int minlevel = 0,
73  const unsigned int maxlevel = 0);
74 
78  Object &operator[](const unsigned int level);
79 
86  const Object &operator[](const unsigned int level) const;
87 
99  void
100  resize(const unsigned int new_minlevel, const unsigned int new_maxlevel);
101 
109  operator=(const double d);
110 
119  void
120  clear_elements();
121 
125  unsigned int
126  min_level() const;
127 
131  unsigned int
132  max_level() const;
133 
144  template <typename ActionFunctionObjectType>
145  void
146  apply(ActionFunctionObjectType action);
147 
151  std::size_t
152  memory_consumption() const;
153 
154 private:
158  unsigned int minlevel;
159 
163  std::vector<std::shared_ptr<Object>> objects;
164 };
165 
166 
167 /* ------------------------------------------------------------------- */
168 
169 
170 template <class Object>
172  const unsigned int max)
173  : minlevel(0)
174 {
175  resize(min, max);
176 }
177 
178 
179 template <class Object>
180 Object &MGLevelObject<Object>::operator[](const unsigned int i)
181 {
182  Assert((i >= minlevel) && (i < minlevel + objects.size()),
183  ExcIndexRange(i, minlevel, minlevel + objects.size()));
184  return *objects[i - minlevel];
185 }
186 
187 
188 template <class Object>
189 const Object &MGLevelObject<Object>::operator[](const unsigned int i) const
190 {
191  Assert((i >= minlevel) && (i < minlevel + objects.size()),
192  ExcIndexRange(i, minlevel, minlevel + objects.size()));
193  return *objects[i - minlevel];
194 }
195 
196 
197 template <class Object>
198 void
199 MGLevelObject<Object>::resize(const unsigned int new_minlevel,
200  const unsigned int new_maxlevel)
201 {
202  Assert(new_minlevel <= new_maxlevel, ExcInternalError());
203  // note that on clear(), the
204  // shared_ptr class takes care of
205  // deleting the object it points to
206  // by itself
207  objects.clear();
208 
209  minlevel = new_minlevel;
210  for (unsigned int i = 0; i < new_maxlevel - new_minlevel + 1; ++i)
211  objects.push_back(std::make_shared<Object>());
212 }
213 
214 
215 template <class Object>
218 {
219  typename std::vector<std::shared_ptr<Object>>::iterator v;
220  for (v = objects.begin(); v != objects.end(); ++v)
221  **v = d;
222  return *this;
223 }
224 
225 
226 template <class Object>
227 void
229 {
230  typename std::vector<std::shared_ptr<Object>>::iterator v;
231  for (v = objects.begin(); v != objects.end(); ++v)
232  (*v)->clear();
233 }
234 
235 
236 template <class Object>
237 unsigned int
239 {
240  return minlevel;
241 }
242 
243 
244 template <class Object>
245 unsigned int
247 {
248  return minlevel + objects.size() - 1;
249 }
250 
251 template <class Object>
252 template <typename ActionFunctionObjectType>
253 void
254 MGLevelObject<Object>::apply(ActionFunctionObjectType action)
255 {
256  for (unsigned int lvl = min_level(); lvl <= max_level(); ++lvl)
257  {
258  action(lvl, (*this)[lvl]);
259  }
260 }
261 
262 
263 template <class Object>
264 std::size_t
266 {
267  std::size_t result = sizeof(*this);
268  using Iter = typename std::vector<std::shared_ptr<Object>>::const_iterator;
269  const Iter end = objects.end();
270  for (Iter o = objects.begin(); o != end; ++o)
271  result += (*o)->memory_consumption();
272 
273  return result;
274 }
275 
277 
278 #endif
MGLevelObject::operator=
MGLevelObject< Object > & operator=(const double d)
Definition: mg_level_object.h:217
MGLevelObject::max_level
unsigned int max_level() const
Definition: mg_level_object.h:246
MGLevelObject::min_level
unsigned int min_level() const
Definition: mg_level_object.h:238
VectorizedArray::max
VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &x, const ::VectorizedArray< Number, width > &y)
Definition: vectorization.h:5466
VectorizedArray::min
VectorizedArray< Number, width > min(const ::VectorizedArray< Number, width > &x, const ::VectorizedArray< Number, width > &y)
Definition: vectorization.h:5483
MGLevelObject::objects
std::vector< std::shared_ptr< Object > > objects
Definition: mg_level_object.h:163
MGLevelObject::MGLevelObject
MGLevelObject(const unsigned int minlevel=0, const unsigned int maxlevel=0)
Definition: mg_level_object.h:171
Physics::Elasticity::Kinematics::d
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
MGLevelObject::operator[]
Object & operator[](const unsigned int level)
Definition: mg_level_object.h:180
Subscriptor
Definition: subscriptor.h:62
level
unsigned int level
Definition: grid_out.cc:4355
StandardExceptions::ExcIndexRange
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
subscriptor.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
MGLevelObject::clear_elements
void clear_elements()
Definition: mg_level_object.h:228
TrilinosWrappers::internal::end
VectorType::value_type * end(VectorType &V)
Definition: trilinos_sparse_matrix.cc:65
StandardExceptions::ExcInternalError
static ::ExceptionBase & ExcInternalError()
MGLevelObject::resize
void resize(const unsigned int new_minlevel, const unsigned int new_maxlevel)
Definition: mg_level_object.h:199
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
MGLevelObject
Definition: mg_level_object.h:50
MGLevelObject::memory_consumption
std::size_t memory_consumption() const
Definition: mg_level_object.h:265
Utilities::MPI::min
T min(const T &t, const MPI_Comm &mpi_communicator)
config.h
MGLevelObject::minlevel
unsigned int minlevel
Definition: mg_level_object.h:158
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
MGLevelObject::apply
void apply(ActionFunctionObjectType action)
Definition: mg_level_object.h:254
Utilities::MPI::max
T max(const T &t, const MPI_Comm &mpi_communicator)