Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Epetra_Vector.cpp
Go to the documentation of this file.
1 
2 //@HEADER
3 // ************************************************************************
4 //
5 // Epetra: Linear Algebra Services Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 
43 #include "Epetra_ConfigDefs.h"
44 #include "Epetra_Vector.h"
45 #include "Epetra_Map.h"
46 #include "Epetra_Comm.h"
47 //=============================================================================
49  : Epetra_MultiVector(map,1,zeroOut) // Vector is just special case of MultiVector
50 {
51  SetLabel("Epetra::Vector");
52 }
53 //=============================================================================
55  : Epetra_MultiVector(Source) // Vector is just special case of MultiVector
56 {
57 }
58 //=============================================================================
60  : Epetra_MultiVector(CV, map, V, map.NumMyPoints(), 1) // Vector is just special case of MultiVector
61 {
62  SetLabel("Epetra::Vector");
63 }
64 //=============================================================================
66  : Epetra_MultiVector(CV, Source, Index, 1) // Vector is just special case of MultiVector
67 {
68  SetLabel("Epetra::Vector");
69 }
70 //=========================================================================
72 
73 //=============================================================================
74 int Epetra_Vector::ExtractCopy(double *V) const {
75  return(Epetra_MultiVector::ExtractCopy(V, 1));
76 }
77 
78 //=============================================================================
79 int Epetra_Vector::ExtractView(double **V) const {
80  int junk;
81  return(Epetra_MultiVector::ExtractView(V, &junk));
82 }
83 
84 /*
85 //=========================================================================
86 double& Epetra_Vector::operator [] (int Index) {
87 
88  return(Values_[Index]);
89 }
90 
91 //=========================================================================
92 const double& Epetra_Vector::operator [] (int Index) const {
93 
94  return(Values_[Index]);
95 }
96 */
97 
98 //=========================================================================
99 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
100 int Epetra_Vector::ReplaceGlobalValues(int NumEntries, const double * values, const int * Indices) {
101  // Use the more general method below
102  EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, values, Indices, true, false));
103  return(0);
104 }
105 #endif
106 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
107 int Epetra_Vector::ReplaceGlobalValues(int NumEntries, const double * values, const long long * Indices) {
108  // Use the more general method below
109  EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, values, Indices, true, false));
110  return(0);
111 }
112 #endif
113 //=========================================================================
114 int Epetra_Vector::ReplaceMyValues(int NumEntries, const double * values, const int * Indices) {
115  // Use the more general method below
116  EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, values, Indices, false, false));
117  return(0);
118 }
119 //=========================================================================
120 int Epetra_Vector::SumIntoGlobalValues(int NumEntries, const double * values, const int * Indices) {
121  // Use the more general method below
122  EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, values, Indices, true, true));
123  return(0);
124 }
125 //=========================================================================
126 int Epetra_Vector::SumIntoMyValues(int NumEntries, const double * values, const int * Indices) {
127  // Use the more general method below
128  EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, values, Indices, false, true));
129  return(0);
130 }
131 //=========================================================================
132 int Epetra_Vector::ReplaceGlobalValues(int NumEntries, int BlockOffset, const double * values, const int * Indices) {
133  // Use the more general method below
134  EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, values, Indices, true, false));
135  return(0);
136 }
137 //=========================================================================
138 int Epetra_Vector::ReplaceMyValues(int NumEntries, int BlockOffset, const double * values, const int * Indices) {
139  // Use the more general method below
140  EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, values, Indices, false, false));
141  return(0);
142 }
143 //=========================================================================
144 int Epetra_Vector::SumIntoGlobalValues(int NumEntries, int BlockOffset, const double * values, const int * Indices) {
145  // Use the more general method below
146  EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, values, Indices, true, true));
147  return(0);
148 }
149 //=========================================================================
150 int Epetra_Vector::SumIntoMyValues(int NumEntries, int BlockOffset, const double * values, const int * Indices) {
151  // Use the more general method below
152  EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, values, Indices, false, true));
153  return(0);
154 }
155 //=========================================================================
156 template<typename int_type>
157 int Epetra_Vector::TChangeValues(int NumEntries, int BlockOffset, const double * values, const int_type * Indices,
158  bool IndicesGlobal, bool SumInto) {
159 
160  int_type cur_index;
161  int ierr = 0;
162  if (BlockOffset<0) EPETRA_CHK_ERR(-1); // Offset is out-of-range
163 
164  for (int i=0; i<NumEntries; i++) {
165  if (IndicesGlobal)
166  cur_index = Map().LID(Indices[i]);
167  else
168  cur_index = Indices[i];
169 
170  if (Map().MyLID((int) cur_index)) {
171  if (BlockOffset>=Map().ElementSize((int) cur_index)) EPETRA_CHK_ERR(-1); // Offset is out-of-range
172  int entry = Map().FirstPointInElement((int) cur_index);
173 
174  if (SumInto)
175  Values_[entry+BlockOffset] += values[i];
176  else
177  Values_[entry+BlockOffset] = values[i];
178  }
179  else ierr = 1;
180  }
181 
182  EPETRA_CHK_ERR(ierr);
183  return(0);
184 }
185 
186 int Epetra_Vector::ChangeValues(int NumEntries, int BlockOffset, const double * values, const int * Indices,
187  bool IndicesGlobal, bool SumInto) {
188  if(Map().GlobalIndicesInt())
189  return TChangeValues<int>(NumEntries, BlockOffset, values, Indices, IndicesGlobal, SumInto);
190  else
191  throw ReportError("Epetra_Vector::ChangeValues int version called for a vector that is not int.", -1);
192 }
193 
194 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
195 int Epetra_Vector::ChangeValues(int NumEntries, int BlockOffset, const double * values, const long long * Indices,
196  bool IndicesGlobal, bool SumInto) {
197  if(Map().GlobalIndicesLongLong())
198  return TChangeValues<long long>(NumEntries, BlockOffset, values, Indices, IndicesGlobal, SumInto);
199  else
200  throw ReportError("Epetra_Vector::ChangeValues long long version called for a vector that is not long long.", -1);
201 }
202 #endif
Epetra_MultiVector: A class for constructing and using dense multi-vectors, vectors and matrices in p...
int SumIntoGlobalValues(int NumEntries, const double *Values, const int *Indices)
Sum values into a vector with a given indexed list of values, indices are in global index space...
virtual ~Epetra_Vector()
Epetra_Vector destructor.
virtual void SetLabel(const char *const Label)
Epetra_Object Label definition using char *.
#define EPETRA_CHK_ERR(a)
Epetra_Vector: A class for constructing and using dense vectors on a parallel computer.
int ExtractCopy(double *A, int MyLDA) const
Put multi-vector values into user-provided two-dimensional array.
int ReplaceMyValues(int NumEntries, const double *Values, const int *Indices)
Replace values in a vector with a given indexed list of values, indices are in local index space...
int ChangeValues(int NumEntries, int BlockOffset, const double *Values, const int *Indices, bool IndicesGlobal, bool SumInto)
int ReplaceGlobalValues(int NumEntries, const double *Values, const int *Indices)
Replace values in a vector with a given indexed list of values, indices are in global index space...
int SumIntoMyValues(int NumEntries, const double *Values, const int *Indices)
Sum values into a vector with a given indexed list of values, indices are in local index space...
int FirstPointInElement(int LID) const
Returns the requested entry in the FirstPointInElementList; see FirstPointInElementList() for details...
int ExtractView(double **A, int *MyLDA) const
Set user-provided addresses of A and MyLDA.
Epetra_BlockMap: A class for partitioning block element vectors and matrices.
int LID(int GID) const
Returns local ID of global ID, return -1 if not found on this processor.
Epetra_Vector(const Epetra_BlockMap &Map, bool zeroOut=true)
Basic Epetra_Vector constuctor.
int ExtractCopy(double *V) const
Put vector values into user-provided array.
virtual int ReportError(const std::string Message, int ErrorCode) const
Error reporting method.
int TChangeValues(int NumEntries, int BlockOffset, const double *Values, const int_type *Indices, bool IndicesGlobal, bool SumInto)
Epetra_DataAccess
int ExtractView(double **V) const
Set user-provided address of V.
const Epetra_BlockMap & Map() const
Returns the address of the Epetra_BlockMap for this multi-vector.