Reference documentation for deal.II version 8.4.1
mg_level_object.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 2015 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__mg_level_object_h
17 #define dealii__mg_level_object_h
18 
19 #include <deal.II/base/subscriptor.h>
20 #include <vector>
21 
22 #include <deal.II/base/std_cxx11/shared_ptr.h>
23 
24 DEAL_II_NAMESPACE_OPEN
25 
26 
40 template<class Object>
41 class MGLevelObject : public Subscriptor
42 {
43 public:
48  MGLevelObject (const unsigned int minlevel = 0,
49  const unsigned int maxlevel = 0);
50 
54  Object &operator[] (const unsigned int level);
55 
59  const Object &operator[] (const unsigned int level) const;
60 
65  void resize (const unsigned int new_minlevel,
66  const unsigned int new_maxlevel);
67 
72  MGLevelObject<Object> &operator = (const double d);
73 
79  void clear();
80 
84  unsigned int min_level () const;
85 
89  unsigned int max_level () const;
90 
94  std::size_t memory_consumption () const;
95 
96 private:
100  unsigned int minlevel;
101 
105  std::vector<std_cxx11::shared_ptr<Object> > objects;
106 };
107 
108 
109 /* ------------------------------------------------------------------- */
110 
111 
112 template<class Object>
114  const unsigned int max)
115  :
116  minlevel(0)
117 {
118  resize (min, max);
119 }
120 
121 
122 template<class Object>
123 Object &
125 {
126  Assert((i>=minlevel) && (i<minlevel+objects.size()),
127  ExcIndexRange (i, minlevel, minlevel+objects.size()));
128  return *objects[i-minlevel];
129 }
130 
131 
132 template<class Object>
133 const Object &
134 MGLevelObject<Object>::operator[] (const unsigned int i) const
135 {
136  Assert((i>=minlevel) && (i<minlevel+objects.size()),
137  ExcIndexRange (i, minlevel, minlevel+objects.size()));
138  return *objects[i-minlevel];
139 }
140 
141 
142 template<class Object>
143 void
144 MGLevelObject<Object>::resize (const unsigned int new_minlevel,
145  const unsigned int new_maxlevel)
146 {
147  Assert (new_minlevel <= new_maxlevel, ExcInternalError());
148  // note that on clear(), the
149  // shared_ptr class takes care of
150  // deleting the object it points to
151  // by itself
152  objects.clear ();
153 
154  minlevel = new_minlevel;
155  for (unsigned int i=0; i<new_maxlevel-new_minlevel+1; ++i)
156  objects.push_back(std_cxx11::shared_ptr<Object> (new Object));
157 }
158 
159 
160 template<class Object>
163 {
164  typename std::vector<std_cxx11::shared_ptr<Object> >::iterator v;
165  for (v = objects.begin(); v != objects.end(); ++v)
166  **v=d;
167  return *this;
168 }
169 
170 
171 template<class Object>
172 void
174 {
175  typename std::vector<std_cxx11::shared_ptr<Object> >::iterator v;
176  for (v = objects.begin(); v != objects.end(); ++v)
177  (*v)->clear();
178 }
179 
180 
181 template<class Object>
182 unsigned int
184 {
185  return minlevel;
186 }
187 
188 
189 template<class Object>
190 unsigned int
192 {
193  return minlevel + objects.size() - 1;
194 }
195 
196 
197 template<class Object>
198 std::size_t
200 {
201  std::size_t result = sizeof(*this);
202  typedef typename std::vector<std_cxx11::shared_ptr<Object> >::const_iterator Iter;
203  const Iter end = objects.end();
204  for (Iter o=objects.begin(); o!=end; ++o)
205  result += (*o)->memory_consumption();
206 
207  return result;
208 }
209 
210 DEAL_II_NAMESPACE_CLOSE
211 
212 #endif
Object & operator[](const unsigned int level)
MGLevelObject(const unsigned int minlevel=0, const unsigned int maxlevel=0)
std::size_t memory_consumption() const
std::vector< std_cxx11::shared_ptr< Object > > objects
VectorizedArray< Number > min(const ::VectorizedArray< Number > &x, const ::VectorizedArray< Number > &y)
#define Assert(cond, exc)
Definition: exceptions.h:294
unsigned int max_level() const
unsigned int minlevel
MGLevelObject< Object > & operator=(const double d)
unsigned int min_level() const
void resize(const unsigned int new_minlevel, const unsigned int new_maxlevel)
VectorizedArray< Number > max(const ::VectorizedArray< Number > &x, const ::VectorizedArray< Number > &y)