LifeV
BlockEpetra_MultiVector.cpp
Go to the documentation of this file.
1 /*
2  * BlockEpetra_MultiVector.cpp
3  *
4  * Created on: Aug 14, 2011
5  * Author: uvilla
6  */
7 
8 #include <lifev/core/linear_algebra/BlockEpetra_MultiVector.hpp>
9 
10 namespace LifeV
11 {
12 BlockEpetra_MultiVector::BlockEpetra_MultiVector(const BlockEpetra_Map& map, int numVectors, bool zeroOut):
15  M_blockMap(map),
18 {
20 }
21 
24  M_nBlocks(source.M_nBlocks),
27  M_blocks(source.M_blocks)
28 {
30 }
31 
32 BlockEpetra_MultiVector::BlockEpetra_MultiVector(Epetra_DataAccess CV, const vector_Type & source, const BlockEpetra_Map& map):
35  M_blockMap(map),
38 {
40 }
41 
42 
44 {
45  ASSERT_PRE(iblock < M_nBlocks, "Asking a block out of range!");
46 
47  double ** arrayOfPointers;
48  ExtractView(&arrayOfPointers);
49  double ** arrayOfShiftedPointers = new double*[NumVectors()];
50 
51  for(Int iVect(0); iVect < NumVectors(); ++iVect)
52  arrayOfShiftedPointers[iVect] = arrayOfPointers[iVect] + M_myLocalOffsets[iblock];
53 
54  M_blocks[iblock]->ResetView(arrayOfShiftedPointers);
55 
56  delete[] arrayOfShiftedPointers;
57 
58  return *(M_blocks[iblock]);
59 }
60 
62 {
63  ASSERT_PRE(iblock < M_nBlocks, "Asking a block out of range!");
64 
65  double ** arrayOfPointers;
66  ExtractView(&arrayOfPointers);
67  double ** arrayOfShiftedPointers = new double*[NumVectors()];
68 
69  for(Int iVect(0); iVect < NumVectors(); ++iVect)
70  arrayOfShiftedPointers[iVect] = arrayOfPointers[iVect] + M_myLocalOffsets[iblock];
71 
72  M_blocks[iblock]->ResetView(arrayOfShiftedPointers);
73 
74  delete[] arrayOfShiftedPointers;
75 
76  return *(M_blocks[iblock]);
77 }
78 
80 {
81  return M_blockMap;
82 }
83 
84 //-----------------------------------------------------/
86 {
87  double ** arrayOfPointers;
88  ExtractView(&arrayOfPointers);
89  double ** arrayOfShiftedPointers = new double*[NumVectors()];
90  for(UInt iblock(0); iblock < M_nBlocks; ++iblock)
91  {
92  for(Int iVect(0); iVect < NumVectors(); ++iVect)
93  arrayOfShiftedPointers[iVect] = arrayOfPointers[iVect] + M_myLocalOffsets[iblock];
94  M_blocks[iblock].reset(
95  new Epetra_MultiVector(View, *(M_blockMap.blockMap(iblock)), arrayOfShiftedPointers, NumVectors())
96  );
97  }
98  delete[] arrayOfShiftedPointers;
99 }
100 
101 //------------------------------------------------------/
102 // Generate a BlockEpetra_MultiVector from a list of Epetra_MultiVector.
103 BlockEpetra_MultiVector * stride(std::vector<const BlockEpetra_MultiVector::vector_Type *> vectors)
104 {
105  //Step 0: Check input
106  const UInt nBlocks(vectors.size());
107  const UInt numVectors(vectors[0]->NumVectors());
108 
109  for(UInt i(0); i<nBlocks; ++i)
110  ASSERT_PRE( numVectors == static_cast<UInt>(vectors[i]->NumVectors()), "error in BlockEpetra_MultiVector * stride\n");
111 
112  //Step 1: Create the block map
113  BlockEpetra_Map blockMap;
114 
115  BlockEpetra_Map::mapPtrContainer_Type mapPtrContainer(nBlocks);
116  for(UInt i(0); i < nBlocks; ++i)
117  mapPtrContainer[i].reset( blockMap2Map(&(vectors[i]->Map())) );
118 
119  blockMap.setUp(mapPtrContainer);
120 
121  //Step 2: Allocate the BlockEpetra_MultiVector
122  BlockEpetra_MultiVector * stridedVector;
123  stridedVector = new BlockEpetra_MultiVector(blockMap, numVectors, false);
124 
125  stridedVector->PutScalar(404.3142713);
126 
127  //Step 3: Copy the contents of the vectors
128  for(UInt i(0); i < nBlocks; ++i)
129  stridedVector->block(i) = *(vectors[i]);
130 
131  //Step 4: return the stridedVector
132  return stridedVector;
133 }
134 
135 // Generate a BlockEpetra_MultiVector from two Epetra_MultiVectors
138 {
139  std::vector<const BlockEpetra_MultiVector::vector_Type *> vectors(2);
140  vectors[0] = &v1;
141  vectors[1] = &v2;
142  return stride(vectors);
143 }
144 
145 //! Generate a BlockEpetra_MultiVector from three Epetra_MultiVectors
149 {
150  std::vector<const BlockEpetra_MultiVector::vector_Type *> vectors(3);
151  vectors[0] = &v1;
152  vectors[1] = &v2;
153  vectors[2] = &v3;
154  return stride(vectors);
155 }
156 
157 //! Generate a BlockEpetra_MultiVector from three Epetra_MultiVectors
162 {
163  std::vector<const BlockEpetra_MultiVector::vector_Type *> vectors(4);
164  vectors[0] = &v1;
165  vectors[1] = &v2;
166  vectors[2] = &v3;
167  vectors[3] = &v4;
168  return stride(vectors);
169 }
170 
171 //! Generate a BlockEpetra_MultiVector from a Epetra_MultiVector and a BlockEpetra_Map
173 {
175  bMV = new BlockEpetra_MultiVector(View, source, map);
176  return bMV;
177 }
178 
179 
180 
181 } /* end namespace */
This class handles block access to parallel monolithic Vectors with an underling block structure...
BlockEpetra_MultiVector * createBlockView(const BlockEpetra_MultiVector::vector_Type &source, const BlockEpetra_Map &map)
Generate a BlockEpetra_MultiVector from a Epetra_MultiVector and a BlockEpetra_Map.
void setUp(const mapPtrContainer_Type &mapPtrContainer)
general setup for arbitrary number of blocks. The maps of the block to stride are collected in a mapP...
Epetra_MultiVector & block(UInt iblock)
Return a Epetra_MultiVector (view) object for block iblock.
BlockEpetra_MultiVector(const BlockEpetra_Map &map, int numVectors, bool zeroOut=true)
Generate a BlockEpetra_MultiVector from a BlockEpetra_Map.
const BlockEpetra_Map & blockEpetraMap() const
retrieve the BlockEpetra_Map
BlockEpetra_MultiVector * stride(const BlockEpetra_MultiVector::vector_Type &v1, const BlockEpetra_MultiVector::vector_Type &v2, const BlockEpetra_MultiVector::vector_Type &v3, const BlockEpetra_MultiVector::vector_Type &v4)
Generate a BlockEpetra_MultiVector from three Epetra_MultiVectors.
void updateInverseJacobian(const UInt &iQuadPt)
#define ASSERT_PRE(X, A)
Definition: LifeAssert.hpp:96
std::vector< mapPtr_Type > mapPtrContainer_Type
BlockEpetra_MultiVector(const BlockEpetra_MultiVector &Source)
Copy Constructor.
BlockEpetra_MultiVector(Epetra_DataAccess CV, const vector_Type &source, const BlockEpetra_Map &map)
Overlay a block structure to a source.
A derived class from Epetra_MultiVector specialized to handle parallel block structured Vectors...
BlockEpetra_MultiVector * stride(const BlockEpetra_MultiVector::vector_Type &v1, const BlockEpetra_MultiVector::vector_Type &v2)
Generate a BlockEpetra_MultiVector from two Epetra_MultiVectors.
UInt nBlocks() const
get the number of blocks
const Epetra_MultiVector & block(UInt iblock) const
const version
BlockEpetra_MultiVector * stride(const BlockEpetra_MultiVector::vector_Type &v1, const BlockEpetra_MultiVector::vector_Type &v2, const BlockEpetra_MultiVector::vector_Type &v3)
Generate a BlockEpetra_MultiVector from three Epetra_MultiVectors.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
BlockEpetra_MultiVector * stride(std::vector< const BlockEpetra_MultiVector::vector_Type *> vectors)
Generate a BlockEpetra_MultiVector from a list of Epetra_MultiVector.