MFEM  v3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
blockvector.cpp
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.googlecode.com.
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 #include "../general/array.hpp"
13 #include "vector.hpp"
14 #include "blockvector.hpp"
15 
16 namespace mfem
17 {
18 
20  Vector(),
21  numBlocks(0),
22  blockOffsets(NULL),
23  tmp_block(0)
24 {
25 
26 }
27 
30  Vector(bOffsets.Last()),
31  numBlocks(bOffsets.Size()-1),
32  blockOffsets(bOffsets.GetData()),
33  tmp_block(numBlocks)
34 {
35  for (int i = 0; i < numBlocks; ++i)
37 }
38 
41  Vector(v),
42  numBlocks(v.numBlocks),
43  blockOffsets(v.blockOffsets),
44  tmp_block(numBlocks)
45 {
46  for (int i = 0; i < numBlocks; ++i)
48 }
49 
51 BlockVector::BlockVector(double *data, const Array<int> & bOffsets):
52  Vector(data, bOffsets.Last()),
53  numBlocks(bOffsets.Size()-1),
54  blockOffsets(bOffsets.GetData()),
55  tmp_block(numBlocks)
56 {
57  for (int i = 0; i < numBlocks; ++i)
58  tmp_block[i] = new Vector(data+blockOffsets[i], blockOffsets[i+1]-blockOffsets[i]);
59 }
60 
61 void BlockVector::Update(double *data, const Array<int> & bOffsets)
62 {
63  NewDataAndSize(data, bOffsets.Last());
64  blockOffsets = bOffsets.GetData();
65  numBlocks = bOffsets.Size()-1;
66 
67  int oldNumBlocks = tmp_block.Size();
68  for (int i = numBlocks; i < oldNumBlocks; ++i)
69  delete tmp_block[i];
70 
71  tmp_block.SetSize(numBlocks);
72  for (int i = oldNumBlocks; i < numBlocks; ++i)
73  tmp_block[i] = new Vector(data+blockOffsets[i], blockOffsets[i+1]-blockOffsets[i]);
74 }
75 
77 {
78  if(numBlocks!=original.numBlocks)
79  mfem_error("Number of Blocks don't match in BlockVector::operator=");
80 
81  for (int i(0); i <= numBlocks; ++i)
82  if(blockOffsets[i]!=original.blockOffsets[i])
83  mfem_error("Size of Blocks don't match in BlockVector::operator=");
84 
85  for (int i = 0; i < original.size; i++)
86  data[i] = original.data[i];
87 
88  return *this;
89 }
90 
92 {
93  Vector::operator=(val);
94  return *this;
95 }
96 
99 {
100  for (int i = 0; i < tmp_block.Size(); ++i)
101  delete tmp_block[i];
102 }
103 
105 {
106  tmp_block[i]->NewDataAndSize(data+blockOffsets[i], blockOffsets[i+1]-blockOffsets[i]);
107  return *(tmp_block[i]);
108 }
109 
110 const Vector & BlockVector::GetBlock(int i) const
111 {
112  tmp_block[i]->NewDataAndSize(data+blockOffsets[i], blockOffsets[i+1]-blockOffsets[i]);
113  return *(tmp_block[i]);
114 }
115 
116 void BlockVector::GetBlockView(int i, Vector & blockView)
117 {
119 }
120 
121 }
~BlockVector()
Destructor.
Definition: blockvector.cpp:98
int Size() const
Logical size of the array.
Definition: array.hpp:108
Vector()
Default constructor for Vector. Sets size = 0 and data = NULL.
Definition: vector.hpp:39
void NewDataAndSize(double *d, int s)
Definition: vector.hpp:67
void GetBlockView(int i, Vector &blockView)
Get the i-th vector in the block.
BlockVector()
empty constructor
Definition: blockvector.cpp:19
const int * blockOffsets
Offset for each block start. (length numBlocks+1)
Definition: blockvector.hpp:39
T * GetData()
Returns the data.
Definition: array.hpp:90
void Update(double *data, const Array< int > &bOffsets)
Update method.
Definition: blockvector.cpp:61
Vector & operator=(const double *v)
Definition: vector.cpp:100
Array< Vector * > tmp_block
array of Vector objects used to extract blocks without allocating memory.
Definition: blockvector.hpp:41
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.
Definition: blockvector.cpp:76
void mfem_error(const char *msg)
Definition: error.cpp:23
T & Last()
Return the last element in the array.
Definition: array.hpp:361
Vector data type.
Definition: vector.hpp:29
double * data
Definition: vector.hpp:34
Vector & GetBlock(int i)
Get the i-th vector in the block.