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 2001 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_Vector.h"
00044 #include "Epetra_Map.h"
00045 #include "Epetra_Comm.h"
00046 //=============================================================================
00047 Epetra_Vector::Epetra_Vector(const Epetra_BlockMap& Map, bool zeroOut)
00048   : Epetra_MultiVector(Map,1,zeroOut) // Vector is just special case of MultiVector
00049 {
00050   SetLabel("Epetra::Vector");
00051 }
00052 //=============================================================================
00053 Epetra_Vector::Epetra_Vector(const Epetra_Vector& Source)
00054   : Epetra_MultiVector(Source) // Vector is just special case of MultiVector
00055 {
00056 }
00057 //=============================================================================
00058 Epetra_Vector::Epetra_Vector(Epetra_DataAccess CV, const Epetra_BlockMap& Map, double *V)
00059   : Epetra_MultiVector(CV, Map, V, Map.NumMyPoints(), 1) // Vector is just special case of MultiVector
00060 {
00061   SetLabel("Epetra::Vector");
00062 }
00063 //=============================================================================
00064 Epetra_Vector::Epetra_Vector(Epetra_DataAccess CV, const Epetra_MultiVector& Source, int Index)
00065   : Epetra_MultiVector(CV, Source, Index, 1) // Vector is just special case of MultiVector
00066 {
00067   SetLabel("Epetra::Vector");
00068 }
00069 //=========================================================================
00070 Epetra_Vector::~Epetra_Vector(){}
00071 
00072 //=============================================================================
00073 int Epetra_Vector::ExtractCopy(double *V) const {
00074   return(Epetra_MultiVector::ExtractCopy(V, 1));
00075 }
00076 
00077 //=============================================================================
00078 int Epetra_Vector::ExtractView(double **V) const {
00079   int junk;
00080   return(Epetra_MultiVector::ExtractView(V, &junk));
00081 }
00082 
00083 /*
00084 //=========================================================================
00085 double& Epetra_Vector::operator [] (int Index)  {
00086 
00087    return(Values_[Index]);
00088 }
00089 
00090 //=========================================================================
00091 const double& Epetra_Vector::operator [] (int Index) const  {
00092 
00093    return(Values_[Index]);
00094 }
00095 */
00096 
00097 //=========================================================================
00098 int Epetra_Vector::ReplaceGlobalValues(int NumEntries, const double * Values, const int * Indices) {
00099   // Use the more general method below
00100   EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, Values, Indices, true, false));
00101   return(0);
00102 }
00103 //=========================================================================
00104 int Epetra_Vector::ReplaceMyValues(int NumEntries, const double * Values, const int * Indices) {
00105   // Use the more general method below
00106   EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, Values, Indices, false, false));
00107   return(0);
00108 }
00109 //=========================================================================
00110 int Epetra_Vector::SumIntoGlobalValues(int NumEntries, const double * Values, const int * Indices) {
00111   // Use the more general method below
00112   EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, Values, Indices, true, true));
00113   return(0);
00114 }
00115 //=========================================================================
00116 int Epetra_Vector::SumIntoMyValues(int NumEntries, const double * Values, const int * Indices) {
00117   // Use the more general method below
00118   EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, Values, Indices, false, true));
00119   return(0);
00120 }
00121 //=========================================================================
00122 int Epetra_Vector::ReplaceGlobalValues(int NumEntries, int BlockOffset, const double * Values, const int * Indices) {
00123   // Use the more general method below
00124   EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, Values, Indices, true, false));
00125   return(0);
00126 }
00127 //=========================================================================
00128 int Epetra_Vector::ReplaceMyValues(int NumEntries, int BlockOffset, const double * Values, const int * Indices) {
00129   // Use the more general method below
00130   EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, Values, Indices, false, false));
00131   return(0);
00132 }
00133 //=========================================================================
00134 int Epetra_Vector::SumIntoGlobalValues(int NumEntries, int BlockOffset, const double * Values, const int * Indices) {
00135   // Use the more general method below
00136   EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, Values, Indices, true, true));
00137   return(0);
00138 }
00139 //=========================================================================
00140 int Epetra_Vector::SumIntoMyValues(int NumEntries, int BlockOffset, const double * Values, const int * Indices) {
00141   // Use the more general method below
00142   EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, Values, Indices, false, true));
00143   return(0);
00144 }
00145 //=========================================================================
00146 int Epetra_Vector::ChangeValues(int NumEntries, int BlockOffset, const double * Values, const int * Indices,
00147         bool IndicesGlobal, bool SumInto) {
00148 
00149   int cur_index;
00150   int ierr = 0;
00151   if (BlockOffset<0) EPETRA_CHK_ERR(-1); // Offset is out-of-range
00152 
00153   for (int i=0; i<NumEntries; i++) {
00154     if (IndicesGlobal) 
00155       cur_index = Map().LID(Indices[i]);
00156     else
00157       cur_index = Indices[i];
00158     
00159     if (Map().MyLID(cur_index)) {
00160       if (BlockOffset>=Map().ElementSize(cur_index)) EPETRA_CHK_ERR(-1); // Offset is out-of-range
00161       int entry = Map().FirstPointInElement(cur_index);
00162 
00163       if (SumInto)
00164   Values_[entry+BlockOffset] += Values[i];
00165       else
00166   Values_[entry+BlockOffset] = Values[i];
00167     }
00168     else ierr = 1;
00169   }
00170 
00171   EPETRA_CHK_ERR(ierr);
00172   return(0);
00173 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines