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 terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00026 // 
00027 // ************************************************************************
00028 //@HEADER
00029 
00030 #include "Epetra_Vector.h"
00031 #include "Epetra_Map.h"
00032 #include "Epetra_Comm.h"
00033 //=============================================================================
00034 Epetra_Vector::Epetra_Vector(const Epetra_BlockMap& Map, bool zeroOut)
00035   : Epetra_MultiVector(Map,1,zeroOut) // Vector is just special case of MultiVector
00036 {
00037   SetLabel("Epetra::Vector");
00038 }
00039 //=============================================================================
00040 Epetra_Vector::Epetra_Vector(const Epetra_Vector& Source)
00041   : Epetra_MultiVector(Source) // Vector is just special case of MultiVector
00042 {
00043 }
00044 //=============================================================================
00045 Epetra_Vector::Epetra_Vector(Epetra_DataAccess CV, const Epetra_BlockMap& Map, double *V)
00046   : Epetra_MultiVector(CV, Map, V, Map.NumMyPoints(), 1) // Vector is just special case of MultiVector
00047 {
00048   SetLabel("Epetra::Vector");
00049 }
00050 //=============================================================================
00051 Epetra_Vector::Epetra_Vector(Epetra_DataAccess CV, const Epetra_MultiVector& Source, int Index)
00052   : Epetra_MultiVector(CV, Source, Index, 1) // Vector is just special case of MultiVector
00053 {
00054   SetLabel("Epetra::Vector");
00055 }
00056 //=========================================================================
00057 Epetra_Vector::~Epetra_Vector(){}
00058 
00059 //=============================================================================
00060 int Epetra_Vector::ExtractCopy(double *V) const {
00061   return(Epetra_MultiVector::ExtractCopy(V, 1));
00062 }
00063 
00064 //=============================================================================
00065 int Epetra_Vector::ExtractView(double **V) const {
00066   int junk;
00067   return(Epetra_MultiVector::ExtractView(V, &junk));
00068 }
00069 
00070 /*
00071 //=========================================================================
00072 double& Epetra_Vector::operator [] (int Index)  {
00073 
00074    return(Values_[Index]);
00075 }
00076 
00077 //=========================================================================
00078 const double& Epetra_Vector::operator [] (int Index) const  {
00079 
00080    return(Values_[Index]);
00081 }
00082 */
00083 
00084 //=========================================================================
00085 int Epetra_Vector::ReplaceGlobalValues(int NumEntries, double * Values, int * Indices) {
00086   // Use the more general method below
00087   EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, Values, Indices, true, false));
00088   return(0);
00089 }
00090 //=========================================================================
00091 int Epetra_Vector::ReplaceMyValues(int NumEntries, double * Values, int * Indices) {
00092   // Use the more general method below
00093   EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, Values, Indices, false, false));
00094   return(0);
00095 }
00096 //=========================================================================
00097 int Epetra_Vector::SumIntoGlobalValues(int NumEntries, double * Values, int * Indices) {
00098   // Use the more general method below
00099   EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, Values, Indices, true, true));
00100   return(0);
00101 }
00102 //=========================================================================
00103 int Epetra_Vector::SumIntoMyValues(int NumEntries, double * Values, int * Indices) {
00104   // Use the more general method below
00105   EPETRA_CHK_ERR(ChangeValues(NumEntries, 0, Values, Indices, false, true));
00106   return(0);
00107 }
00108 //=========================================================================
00109 int Epetra_Vector::ReplaceGlobalValues(int NumEntries, int BlockOffset, double * Values, int * Indices) {
00110   // Use the more general method below
00111   EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, Values, Indices, true, false));
00112   return(0);
00113 }
00114 //=========================================================================
00115 int Epetra_Vector::ReplaceMyValues(int NumEntries, int BlockOffset, double * Values, int * Indices) {
00116   // Use the more general method below
00117   EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, Values, Indices, false, false));
00118   return(0);
00119 }
00120 //=========================================================================
00121 int Epetra_Vector::SumIntoGlobalValues(int NumEntries, int BlockOffset, double * Values, int * Indices) {
00122   // Use the more general method below
00123   EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, Values, Indices, true, true));
00124   return(0);
00125 }
00126 //=========================================================================
00127 int Epetra_Vector::SumIntoMyValues(int NumEntries, int BlockOffset, double * Values, int * Indices) {
00128   // Use the more general method below
00129   EPETRA_CHK_ERR(ChangeValues(NumEntries, BlockOffset, Values, Indices, false, true));
00130   return(0);
00131 }
00132 //=========================================================================
00133 int Epetra_Vector::ChangeValues(int NumEntries, int BlockOffset, double * Values, int * Indices,
00134         bool IndicesGlobal, bool SumInto) {
00135 
00136   int cur_index;
00137   int ierr = 0;
00138   if (BlockOffset<0) EPETRA_CHK_ERR(-1); // Offset is out-of-range
00139 
00140   for (int i=0; i<NumEntries; i++) {
00141     if (IndicesGlobal) 
00142       cur_index = Map().LID(Indices[i]);
00143     else
00144       cur_index = Indices[i];
00145     
00146     if (Map().MyLID(cur_index)) {
00147       if (BlockOffset>=Map().ElementSize(cur_index)) EPETRA_CHK_ERR(-1); // Offset is out-of-range
00148       int entry = Map().FirstPointInElement(cur_index);
00149 
00150       if (SumInto)
00151   Values_[entry+BlockOffset] += Values[i];
00152       else
00153   Values_[entry+BlockOffset] = Values[i];
00154     }
00155     else ierr = 1;
00156   }
00157 
00158   EPETRA_CHK_ERR(ierr);
00159   return(0);
00160 }

Generated on Wed May 12 21:41:05 2010 for Epetra Package Browser (Single Doxygen Collection) by  doxygen 1.4.7