Reference documentation for deal.II version 8.5.1
mg_level_object.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2003 - 2016 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 
47 template<class Object>
48 class MGLevelObject : public Subscriptor
49 {
50 public:
70  MGLevelObject (const unsigned int minlevel = 0,
71  const unsigned int maxlevel = 0);
72 
76  Object &operator[] (const unsigned int level);
77 
84  const Object &operator[] (const unsigned int level) const;
85 
97  void resize (const unsigned int new_minlevel,
98  const unsigned int new_maxlevel);
99 
106  MGLevelObject<Object> &operator = (const double d);
107 
118  void clear() DEAL_II_DEPRECATED;
119 
128  void clear_elements();
129 
133  unsigned int min_level () const;
134 
138  unsigned int max_level () const;
139 
143  std::size_t memory_consumption () const;
144 
145 private:
149  unsigned int minlevel;
150 
154  std::vector<std_cxx11::shared_ptr<Object> > objects;
155 };
156 
157 
158 /* ------------------------------------------------------------------- */
159 
160 
161 template<class Object>
163  const unsigned int max)
164  :
165  minlevel(0)
166 {
167  resize (min, max);
168 }
169 
170 
171 template<class Object>
172 Object &
174 {
175  Assert((i>=minlevel) && (i<minlevel+objects.size()),
176  ExcIndexRange (i, minlevel, minlevel+objects.size()));
177  return *objects[i-minlevel];
178 }
179 
180 
181 template<class Object>
182 const Object &
183 MGLevelObject<Object>::operator[] (const unsigned int i) const
184 {
185  Assert((i>=minlevel) && (i<minlevel+objects.size()),
186  ExcIndexRange (i, minlevel, minlevel+objects.size()));
187  return *objects[i-minlevel];
188 }
189 
190 
191 template<class Object>
192 void
193 MGLevelObject<Object>::resize (const unsigned int new_minlevel,
194  const unsigned int new_maxlevel)
195 {
196  Assert (new_minlevel <= new_maxlevel, ExcInternalError());
197  // note that on clear(), the
198  // shared_ptr class takes care of
199  // deleting the object it points to
200  // by itself
201  objects.clear ();
202 
203  minlevel = new_minlevel;
204  for (unsigned int i=0; i<new_maxlevel-new_minlevel+1; ++i)
205  objects.push_back(std_cxx11::shared_ptr<Object> (new Object));
206 }
207 
208 
209 template<class Object>
212 {
213  typename std::vector<std_cxx11::shared_ptr<Object> >::iterator v;
214  for (v = objects.begin(); v != objects.end(); ++v)
215  **v=d;
216  return *this;
217 }
218 
219 
220 template<class Object>
221 void
223 {
224  // Avoid code duplication in deprecated call by calling replacing function
225  clear_elements();
226 }
227 
228 
229 template<class Object>
230 void
232 {
233  typename std::vector<std_cxx11::shared_ptr<Object> >::iterator v;
234  for (v = objects.begin(); v != objects.end(); ++v)
235  (*v)->clear();
236 }
237 
238 
239 template<class Object>
240 unsigned int
242 {
243  return minlevel;
244 }
245 
246 
247 template<class Object>
248 unsigned int
250 {
251  return minlevel + objects.size() - 1;
252 }
253 
254 
255 template<class Object>
256 std::size_t
258 {
259  std::size_t result = sizeof(*this);
260  typedef typename std::vector<std_cxx11::shared_ptr<Object> >::const_iterator Iter;
261  const Iter end = objects.end();
262  for (Iter o=objects.begin(); o!=end; ++o)
263  result += (*o)->memory_consumption();
264 
265  return result;
266 }
267 
268 DEAL_II_NAMESPACE_CLOSE
269 
270 #endif
unsigned int max_level() const
Object & operator[](const unsigned int level)
MGLevelObject(const unsigned int minlevel=0, const unsigned int maxlevel=0)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
std::size_t memory_consumption() const
unsigned int min_level() 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:313
unsigned int minlevel
MGLevelObject< Object > & operator=(const double d)
void resize(const unsigned int new_minlevel, const unsigned int new_maxlevel)
VectorizedArray< Number > max(const ::VectorizedArray< Number > &x, const ::VectorizedArray< Number > &y)
static ::ExceptionBase & ExcInternalError()