MFEM  v3.4
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
blockvector.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010, Lawrence Livermore National Security, LLC. Produced at
2 // the Lawrence Livermore National Laboratory. LLNL-CODE-443211. All Rights
3 // reserved. See file COPYRIGHT for details.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability see http://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the GNU Lesser General Public License (as published by the Free
10 // Software Foundation) version 2.1 dated February 1999.
11 
12 #ifndef MFEM_BLOCKVECTOR
13 #define MFEM_BLOCKVECTOR
14 
15 #include "../config/config.hpp"
16 #include "../general/array.hpp"
17 #include "vector.hpp"
18 
19 namespace mfem
20 {
21 
22 //! @class BlockVector
23 /*
24  * \brief A class to handle Vectors in a block fashion
25  *
26  * All data is contained in Vector::data, while blockVector is just a viewer for this data
27  *
28  */
29 class BlockVector: public Vector
30 {
31 protected:
32 
33  //! Number of blocks in the blockVector
34  int numBlocks;
35  //! Offset for each block start. (length numBlocks+1)
36  /**
37  * blockOffsets[i+1] - blockOffsets[i] is the size of block i.
38  */
39  const int *blockOffsets;
40  //! array of Vector objects used to extract blocks without allocating memory.
42 
43  void SetBlocks();
44 
45 public:
46  //! empty constructor
47  BlockVector();
48 
49  //! Constructor
50  /**
51  * bOffsets is an array of integers (length nBlocks+1) that tells the offsets
52  * of each block start.
53  */
54  BlockVector(const Array<int> & bOffsets);
55 
56  //! Copy constructor
57  BlockVector(const BlockVector & block);
58 
59  //! View constructor
60  /*
61  * data is an array of double of length at least blockOffsets[numBlocks] that
62  * contain all the values of the monolithic vector. bOffsets is an array of
63  * integers (length nBlocks+1) that tells the offsets of each block start.
64  * nBlocks is the number of blocks.
65  */
66  BlockVector(double *data, const Array<int> & bOffsets);
67 
68  //! Assignment operator. this and original must have the same block structure.
69  BlockVector & operator=(const BlockVector & original);
70  //! Set each entry of this equal to val
71  BlockVector & operator=(double val);
72 
73  //! Destructor
74  ~BlockVector();
75 
76  //! Get the i-th vector in the block.
77  Vector & GetBlock(int i) { return blocks[i]; }
78  //! Get the i-th vector in the block (const version).
79  const Vector & GetBlock(int i) const { return blocks[i]; }
80 
81  //! Get the i-th vector in the block
82  void GetBlockView(int i, Vector & blockView);
83 
84  int BlockSize(int i) { return blockOffsets[i+1] - blockOffsets[i];}
85 
86  //! Update method
87  /**
88  * data is an array of double of length at least blockOffsets[numBlocks] that
89  * contain all the values of the monolithic vector. bOffsets is an array of
90  * integers (length nBlocks+1) that tells the offsets of each block start.
91  * nBlocks is the number of blocks.
92  */
93  void Update(double *data, const Array<int> & bOffsets);
94 
95  /// Update a BlockVector with new @a bOffsets and make sure it owns its data.
96  /** The block-vector will be re-allocated if either:
97  - the offsets @a bOffsets are different from the current offsets, or
98  - currently, the block-vector does not own its data. */
99  void Update(const Array<int> &bOffsets);
100 };
101 
102 }
103 
104 #endif /* MFEM_BLOCKVECTOR */
~BlockVector()
Destructor.
int BlockSize(int i)
Definition: blockvector.hpp:84
void GetBlockView(int i, Vector &blockView)
Get the i-th vector in the block.
BlockVector()
empty constructor
Definition: blockvector.cpp:28
const int * blockOffsets
Offset for each block start. (length numBlocks+1)
Definition: blockvector.hpp:39
void Update(double *data, const Array< int > &bOffsets)
Update method.
Definition: blockvector.cpp:67
const Vector & GetBlock(int i) const
Get the i-th vector in the block (const version).
Definition: blockvector.hpp:79
int numBlocks
Number of blocks in the blockVector.
Definition: blockvector.hpp:34
BlockVector & operator=(const BlockVector &original)
Assignment operator. this and original must have the same block structure.
Vector data type.
Definition: vector.hpp:48
double * data
Definition: vector.hpp:53
Vector * blocks
array of Vector objects used to extract blocks without allocating memory.
Definition: blockvector.hpp:41
Vector & GetBlock(int i)
Get the i-th vector in the block.
Definition: blockvector.hpp:77