Reference documentation for deal.II version 8.1.0
mg_level_object.h
1 // ---------------------------------------------------------------------
2 // @f$Id: mg_level_object.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2003 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__mg_level_object_h
18 #define __deal2__mg_level_object_h
19 
20 #include <deal.II/base/subscriptor.h>
21 #include <vector>
22 
23 #include <deal.II/base/std_cxx1x/shared_ptr.h>
24 
26 
27 
42 template<class Object>
43 class MGLevelObject : public Subscriptor
44 {
45 public:
52  MGLevelObject (const unsigned int minlevel = 0,
53  const unsigned int maxlevel = 0);
54 
58  Object &operator[] (const unsigned int level);
59 
64  const Object &operator[] (const unsigned int level) const;
65 
73  void resize (const unsigned int new_minlevel,
74  const unsigned int new_maxlevel);
75 
83  MGLevelObject<Object> &operator = (const double d);
84 
93  void clear();
94 
98  unsigned int min_level () const;
99 
103  unsigned int max_level () const;
104 
108  unsigned int get_minlevel () const DEAL_II_DEPRECATED;
109 
113  unsigned int get_maxlevel () const DEAL_II_DEPRECATED;
114 
118  std::size_t memory_consumption () const;
119 
120 private:
124  unsigned int minlevel;
125 
129  std::vector<std_cxx1x::shared_ptr<Object> > objects;
130 };
131 
132 
133 /* ------------------------------------------------------------------- */
134 
135 
136 template<class Object>
137 MGLevelObject<Object>::MGLevelObject(const unsigned int min,
138  const unsigned int max)
139  :
140  minlevel(0)
141 {
142  resize (min, max);
143 }
144 
145 
146 template<class Object>
147 Object &
149 {
150  Assert((i>=minlevel) && (i<minlevel+objects.size()),
151  ExcIndexRange (i, minlevel, minlevel+objects.size()));
152  return *objects[i-minlevel];
153 }
154 
155 
156 template<class Object>
157 const Object &
158 MGLevelObject<Object>::operator[] (const unsigned int i) const
159 {
160  Assert((i>=minlevel) && (i<minlevel+objects.size()),
161  ExcIndexRange (i, minlevel, minlevel+objects.size()));
162  return *objects[i-minlevel];
163 }
164 
165 
166 template<class Object>
167 void
168 MGLevelObject<Object>::resize (const unsigned int new_minlevel,
169  const unsigned int new_maxlevel)
170 {
171  Assert (new_minlevel <= new_maxlevel, ExcInternalError());
172  // note that on clear(), the
173  // shared_ptr class takes care of
174  // deleting the object it points to
175  // by itself
176  objects.clear ();
177 
178  minlevel = new_minlevel;
179  for (unsigned int i=0; i<new_maxlevel-new_minlevel+1; ++i)
180  objects.push_back(std_cxx1x::shared_ptr<Object> (new Object));
181 }
182 
183 
184 template<class Object>
187 {
188  typename std::vector<std_cxx1x::shared_ptr<Object> >::iterator v;
189  for (v = objects.begin(); v != objects.end(); ++v)
190  **v=d;
191  return *this;
192 }
193 
194 
195 template<class Object>
196 void
198 {
199  typename std::vector<std_cxx1x::shared_ptr<Object> >::iterator v;
200  for (v = objects.begin(); v != objects.end(); ++v)
201  (*v)->clear();
202 }
203 
204 
205 template<class Object>
206 unsigned int
208 {
209  return minlevel;
210 }
211 
212 
213 template<class Object>
214 unsigned int
216 {
217  return minlevel + objects.size() - 1;
218 }
219 
220 
221 template<class Object>
222 unsigned int
224 {
225  return minlevel;
226 }
227 
228 
229 template<class Object>
230 unsigned int
232 {
233  return minlevel + objects.size() - 1;
234 }
235 
236 
237 template<class Object>
238 std::size_t
240 {
241  std::size_t result = sizeof(*this);
242  typedef typename std::vector<std_cxx1x::shared_ptr<Object> >::const_iterator Iter;
243  const Iter end = objects.end();
244  for (Iter o=objects.begin(); o!=end; ++o)
245  result += (*o)->memory_consumption();
246 
247  return result;
248 }
249 
250 DEAL_II_NAMESPACE_CLOSE
251 
252 #endif
Object & operator[](const unsigned int level)
std::vector< std_cxx1x::shared_ptr< Object > > objects
MGLevelObject(const unsigned int minlevel=0, const unsigned int maxlevel=0)
std::size_t memory_consumption() const
STL namespace.
#define Assert(cond, exc)
Definition: exceptions.h:299
unsigned int max_level() const
unsigned int minlevel
::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
BlockCompressedSparsityPattern CompressedBlockSparsityPattern DEAL_II_DEPRECATED
MGLevelObject< Object > & operator=(const double d)
unsigned int min_level() const
unsigned int get_minlevel() const DEAL_II_DEPRECATED
void resize(const unsigned int new_minlevel, const unsigned int new_maxlevel)
unsigned int get_maxlevel() const DEAL_II_DEPRECATED
::ExceptionBase & ExcInternalError()