Epetra Package Browser (Single Doxygen Collection) Development
Epetra_Vector.cpp
Go to the documentation of this file.
00001 
00002 //@HEADER
00003 // ************************************************************************
00004 // 
00005 //               Epetra: Linear Algebra Services Package 
00006 //                 Copyright 2011 Sandia Corporation
00007 // 
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00039 // 
00040 // ************************************************************************
00041 //@HEADER
00042 
00043 #include "Epetra_ConfigDefs.h"
00044 #include "Epetra_Vector.h"
00045 #include "Epetra_Map.h"
00046 #include "Epetra_Comm.h"
00047 //=============================================================================
00048 Epetra_Vector::Epetra_Vector(const Epetra_BlockMap& map, bool zeroOut)
00049   : Epetra_MultiVector(map,1,zeroOut) // Vector is just special case of MultiVector
00050 {
00051   SetLabel("Epetra::Vector");
00052 }
00053 //=============================================================================
00054 Epetra_Vector::Epetra_Vector(const Epetra_Vector& Source)
00055   : Epetra_MultiVector(Source) // Vector is just special case of MultiVector
00056 {
00057 }
00058 //=============================================================================
00059 Epetra_Vector::Epetra_Vector(Epetra_DataAccess CV, const Epetra_BlockMap& map, double *V)
00060   : Epetra_MultiVector(CV, map, V, map.NumMyPoints(), 1) // Vector is just special case of MultiVector
00061 {
00062   SetLabel("Epetra::Vector");
00063 }
00064 //=============================================================================
00065 Epetra_Vector::Epetra_Vector(Epetra_DataAccess CV, const Epetra_MultiVector& Source, int Index)
00066   : Epetra_MultiVector(CV, Source, Index, 1) // Vector is just special case of MultiVector
00067 {
00068   SetLabel("Epetra::Vector");
00069 }
00070 //=========================================================================
00071 Epetra_Vector::~Epetra_Vector(){}
00072 
00073 //=============================================================================
00074 int Epetra_Vector::ExtractCopy(double *V) const {
00075   return(Epetra_MultiVector::ExtractCopy(V, 1));
00076 }
00077 
00078 //=============================================================================
00079 int Epetra_Vector::ExtractView(double **V) const {
00080   int junk;
00081   return(Epetra_MultiVector::ExtractView(V, &junk));
00082 }
00083 
00084 /*
00085 //=========================================================================
00086 double& Epetra_Vector::operator [] (int Index)  {
00087 
00088    return(Values_[Index]);
00089 }
00090 
00091 //=========================================================================
00092 const double& Epetra_Vector::operator [] (int Index) const  {
00093 
00094    return(Values_[Index]);
00095 }
00096 */
00097 
00098 //=========================================================================
00099 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00100 int Epetra_Vector::ReplaceGlobalValues(int NumEntries, const double * values, const int * Indices) {
00101   // Use the more general method below
00102   EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, values, Indices, true, false));
00103   return(0);
00104 }
00105 #endif
00106 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00107 int Epetra_Vector::ReplaceGlobalValues(int NumEntries, const double * values, const long long * Indices) {
00108   // Use the more general method below
00109   EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, values, Indices, true, false));
00110   return(0);
00111 }
00112 #endif
00113 //=========================================================================
00114 int Epetra_Vector::ReplaceMyValues(int NumEntries, const double * values, const int * Indices) {
00115   // Use the more general method below
00116   EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, values, Indices, false, false));
00117   return(0);
00118 }
00119 //=========================================================================
00120 int Epetra_Vector::SumIntoGlobalValues(int NumEntries, const double * values, const int * Indices) {
00121   // Use the more general method below
00122   EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, values, Indices, true, true));
00123   return(0);
00124 }
00125 //=========================================================================
00126 int Epetra_Vector::SumIntoMyValues(int NumEntries, const double * values, const int * Indices) {
00127   // Use the more general method below
00128   EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, values, Indices, false, true));
00129   return(0);
00130 }
00131 //=========================================================================
00132 int Epetra_Vector::ReplaceGlobalValues(int NumEntries, int BlockOffset, const double * values, const int * Indices) {
00133   // Use the more general method below
00134   EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, values, Indices, true, false));
00135   return(0);
00136 }
00137 //=========================================================================
00138 int Epetra_Vector::ReplaceMyValues(int NumEntries, int BlockOffset, const double * values, const int * Indices) {
00139   // Use the more general method below
00140   EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, values, Indices, false, false));
00141   return(0);
00142 }
00143 //=========================================================================
00144 int Epetra_Vector::SumIntoGlobalValues(int NumEntries, int BlockOffset, const double * values, const int * Indices) {
00145   // Use the more general method below
00146   EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, values, Indices, true, true));
00147   return(0);
00148 }
00149 //=========================================================================
00150 int Epetra_Vector::SumIntoMyValues(int NumEntries, int BlockOffset, const double * values, const int * Indices) {
00151   // Use the more general method below
00152   EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, values, Indices, false, true));
00153   return(0);
00154 }
00155 //=========================================================================
00156 template<typename int_type>
00157 int Epetra_Vector::TChangeValues(int NumEntries, int BlockOffset, const double * values, const int_type * Indices,
00158         bool IndicesGlobal, bool SumInto) {
00159 
00160   int_type cur_index;
00161   int ierr = 0;
00162   if (BlockOffset<0) EPETRA_CHK_ERR(-1); // Offset is out-of-range
00163 
00164   for (int i=0; i<NumEntries; i++) {
00165     if (IndicesGlobal) 
00166       cur_index = Map().LID(Indices[i]);
00167     else
00168       cur_index = Indices[i];
00169     
00170     if (Map().MyLID((int) cur_index)) {
00171       if (BlockOffset>=Map().ElementSize((int) cur_index)) EPETRA_CHK_ERR(-1); // Offset is out-of-range
00172       int entry = Map().FirstPointInElement((int) cur_index);
00173 
00174       if (SumInto)
00175   Values_[entry+BlockOffset] += values[i];
00176       else
00177   Values_[entry+BlockOffset] = values[i];
00178     }
00179     else ierr = 1;
00180   }
00181 
00182   EPETRA_CHK_ERR(ierr);
00183   return(0);
00184 }
00185 
00186 int Epetra_Vector::ChangeValues(int NumEntries, int BlockOffset, const double * values, const int * Indices,
00187         bool IndicesGlobal, bool SumInto) {
00188   if(Map().GlobalIndicesInt())
00189     return TChangeValues<int>(NumEntries, BlockOffset, values, Indices, IndicesGlobal, SumInto);
00190   else
00191     throw ReportError("Epetra_Vector::ChangeValues int version called for a vector that is not int.", -1);
00192 }
00193 
00194 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00195 int Epetra_Vector::ChangeValues(int NumEntries, int BlockOffset, const double * values, const long long * Indices,
00196         bool IndicesGlobal, bool SumInto) {
00197   if(Map().GlobalIndicesLongLong())
00198     return TChangeValues<long long>(NumEntries, BlockOffset, values, Indices, IndicesGlobal, SumInto);
00199   else
00200     throw ReportError("Epetra_Vector::ChangeValues long long version called for a vector that is not long long.", -1);
00201 }
00202 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines