Reference documentation for deal.II version 8.1.0
vector_view.h
1 // ---------------------------------------------------------------------
2 // @f$Id: vector_view.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2009 - 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 __dealii__vector_view_h
18 #define __dealii__vector_view_h
19 
20 
21 #include <deal.II/base/config.h>
23 #include <deal.II/base/subscriptor.h>
24 #include <deal.II/lac/vector.h>
25 
26 #include <cstdio>
27 
29 
30 
136 template<typename Number>
137 class VectorView : public Vector<Number>
138 {
139 public:
140 
145 
153  VectorView(const size_type new_size, Number *ptr);
154 
168  VectorView(const size_type new_size, const Number *ptr);
169 
175  ~VectorView();
176 
235  virtual void reinit (const size_type N,
236  const bool fast=false);
237 
243  void reinit(const size_type N, Number *ptr);
244 
252  void reinit(const size_type N, const Number *ptr);
253 
259  virtual void swap (Vector<Number> &v);
260 };
261 
262 
263 
265 /*----------------------- Inline functions ----------------------------------*/
266 
267 #ifndef DOXYGEN
268 
269 template<typename Number>
270 inline
271 VectorView<Number>::VectorView(const size_type new_size, Number *ptr)
272 {
273  this->vec_size = new_size;
274  this->max_vec_size = new_size;
275  this->val = ptr;
276 }
277 
278 
279 
280 template<typename Number>
281 inline
282 VectorView<Number>::VectorView(const size_type new_size, const Number *ptr)
283 {
284  this->vec_size = new_size;
285  this->max_vec_size = new_size;
286  this->val = const_cast<Number *>(ptr);
287 }
288 
289 
290 
291 template<typename Number>
292 inline
294 {
295  // avoid that the base class releases
296  // memory it doesn't own
297  this->vec_size = 0;
298  this->max_vec_size = 0;
299  this->val = 0;
300 }
301 
302 
303 template<typename Number>
304 inline
305 void VectorView<Number>::reinit(const size_type N, const bool fast)
306 {
307  this->vec_size = N;
308  this->max_vec_size = N;
309  if (fast == false)
310  Vector<Number>::operator=(static_cast<Number>(0));
311 }
312 
313 
314 template<typename Number>
315 inline
316 void VectorView<Number>::reinit(const size_type new_size, Number *ptr)
317 {
318  this->vec_size = new_size;
319  this->max_vec_size = new_size;
320  this->val = ptr;
321 }
322 
323 
324 template<typename Number>
325 inline
326 void VectorView<Number>::reinit(const size_type new_size, const Number *ptr)
327 {
328  this->vec_size = new_size;
329  this->max_vec_size = new_size;
330  this->val = const_cast<Number *>(ptr);
331 }
332 
333 
334 template<typename Number>
335 inline
337 {
338  AssertThrow(false, ExcMessage("Cant' swap a VectorView with a Vector!"));
339 }
340 
341 #endif
342 
343 DEAL_II_NAMESPACE_CLOSE
344 
345 #endif
::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
Definition: exceptions.h:362
Vector< Number > & operator=(const Number s)
unsigned int global_dof_index
Definition: types.h:100
virtual void reinit(const size_type N, const bool fast=false)
types::global_dof_index size_type
Definition: vector_view.h:144
VectorView(const size_type new_size, Number *ptr)
virtual void swap(Vector< Number > &v)