All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
Xpetra_EpetraVector.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 //
00003 // ***********************************************************************
00004 //
00005 //             Xpetra: A linear algebra interface package
00006 //                  Copyright 2012 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
00039 //                    Jeremie Gaidamour (jngaida@sandia.gov)
00040 //                    Jonathan Hu       (jhu@sandia.gov)
00041 //                    Ray Tuminaro      (rstumin@sandia.gov)
00042 //
00043 // ***********************************************************************
00044 //
00045 // @HEADER
00046 #include "Xpetra_EpetraVector.hpp"
00047 
00048 //TODO: replace double -> Scalar etc.
00049 
00050 namespace Xpetra {
00051 
00052   EpetraVector::EpetraVector(const Teuchos::RCP<const Map<int,int> > &map, bool zeroOut) : EpetraMultiVector(map,1,zeroOut) { }
00053   
00054   void EpetraVector::replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value) { XPETRA_MONITOR("EpetraVector::replaceGlobalValue"); getEpetra_MultiVector()->ReplaceGlobalValue(globalRow, 0, value); }
00055 
00056   void EpetraVector::sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value) { XPETRA_MONITOR("EpetraVector::sumIntoGlobalValue");getEpetra_MultiVector()->SumIntoGlobalValue(globalRow, 0, value); }
00057 
00058   void EpetraVector::replaceLocalValue(LocalOrdinal myRow, const Scalar &value) { XPETRA_MONITOR("EpetraVector::replaceLocalValue");getEpetra_MultiVector()->ReplaceMyValue(myRow, 0, value); }
00059 
00060   void EpetraVector::sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value) { XPETRA_MONITOR("EpetraVector::sumIntoLocalValue");getEpetra_MultiVector()->SumIntoMyValue(myRow, 0, value); }
00061 
00062   double EpetraVector::dot(const Vector<double,int,int,Kokkos::DefaultNode::DefaultNodeType> &a) const { 
00063        XPETRA_MONITOR("EpetraVector::dot");
00064 
00065       XPETRA_DYNAMIC_CAST(const EpetraVector, a, tA, "This Xpetra::EpetraVector method only accept Xpetra::EpetraVector as input arguments.");
00066       //      return getEpetra_Vector()->Dot(*tA.getEpetra_Vector()); 
00067 
00068       // other way: use the MultiVector Dot instead of VectorDot:
00069       double r;
00070       getEpetra_MultiVector()->Epetra_MultiVector::Dot(*tA.getEpetra_MultiVector(), &r); 
00071       return r;
00072     }
00073 
00074     Teuchos::ScalarTraits<double>::magnitudeType EpetraVector::norm1() const { XPETRA_MONITOR("EpetraVector::norm1"); double r; getEpetra_MultiVector()->Norm1(&r); return r; }
00075 
00076     Teuchos::ScalarTraits<double>::magnitudeType EpetraVector::norm2() const { XPETRA_MONITOR("EpetraVector::norm2"); double r; getEpetra_MultiVector()->Norm2(&r); return r; }
00077 
00078     Teuchos::ScalarTraits<double>::magnitudeType EpetraVector::normInf() const { XPETRA_MONITOR("EpetraVector::normInf"); double r; getEpetra_MultiVector()->NormInf(&r); return r; }
00079 
00080   Teuchos::ScalarTraits<double>::magnitudeType EpetraVector::normWeighted(const Vector<double,int,int,Kokkos::DefaultNode::DefaultNodeType> &weights) const { 
00081       XPETRA_MONITOR("EpetraVector::normWeighted");
00082       XPETRA_DYNAMIC_CAST(const EpetraVector, weights, tWeights, "This Xpetra::EpetraVector method only accept Xpetra::EpetraVector as input arguments.");
00083       double r; 
00084       getEpetra_MultiVector()->NormWeighted(*tWeights.getEpetra_MultiVector(), &r); return r; 
00085     }
00086 
00087     double EpetraVector::meanValue() const { XPETRA_MONITOR("EpetraVector::meanValue"); double r; getEpetra_MultiVector()->MeanValue(&r); return r; }
00088 
00089     std::string EpetraVector::description() const { 
00090       XPETRA_MONITOR("EpetraVector::description");
00091       // This implementation come from Epetra_Vector_def.hpp (without modification)
00092       std::ostringstream oss;
00093       oss << Teuchos::Describable::description();
00094       oss << "{length="<<this->getGlobalLength()
00095       << "}";
00096       return oss.str();
00097     }
00098 
00099     void EpetraVector::describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const { 
00100       XPETRA_MONITOR("EpetraVector::describe");
00101       
00102       if (verbLevel > Teuchos::VERB_NONE)
00103         getEpetra_Vector()->Print(out);
00104 
00105 //       typedef Kokkos::MultiVector<double> KMV;
00106 //       typedef Kokkos::DefaultArithmetic<KMV>   MVT;
00107 
00108 //       // This implementation come from Tpetra_Vector_def.hpp (without modification)
00109 //       using std::endl;
00110 //       using std::setw;
00111 //       using Teuchos::VERB_DEFAULT;
00112 //       using Teuchos::VERB_NONE;
00113 //       using Teuchos::VERB_LOW;
00114 //       using Teuchos::VERB_MEDIUM;
00115 //       using Teuchos::VERB_HIGH;
00116 //       using Teuchos::VERB_EXTREME;
00117 //       Teuchos::EVerbosityLevel vl = verbLevel;
00118 
00119 //       TEUCHOS_TEST_FOR_EXCEPTION(1, Xpetra::Exceptions::NotImplemented, "TODO");
00120 
00121 //       if (vl == VERB_DEFAULT) vl = VERB_LOW;
00122 //       Teuchos::RCP<const Teuchos::Comm<int> > comm = this->getMap()->getComm();
00123 //       const int myImageID = comm->getRank(),
00124 //       numImages = comm->getSize();
00125 //       size_t width = 1;
00126 //       for (size_t dec=10; dec<this->getGlobalLength(); dec *= 10) {
00127 //         ++width;
00128 //       }
00129 //       Teuchos::OSTab tab(out);
00130 //       if (vl != VERB_NONE) {
00131 //         // VERB_LOW and higher prints description()
00132 //         if (myImageID == 0) out << this->description() << std::endl; 
00133 //         for (int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
00134 //           if (myImageID == imageCtr) {
00135 //             if (vl != VERB_LOW) {
00136 //               // VERB_MEDIUM and higher prints getLocalLength()
00137 //               out << "node " << setw(width) << myImageID << ": local length=" << this->getLocalLength() << endl;
00138 //               if (vl != VERB_MEDIUM) {
00139 //                 // VERB_HIGH and higher prints isConstantStride() and stride()
00140 //                 if (vl == VERB_EXTREME && this->getLocalLength() > 0) {
00141 //                   Teuchos::RCP<Node> node = this->lclMV_.getNode();
00142 //                   KOKKOS_NODE_TRACE("Vector::describe()")
00143 //                     Teuchos::ArrayRCP<const double> myview = node->template viewBuffer<double>(
00144 //                                                                                                this->getLocalLength(), 
00145 //                                                                                                MVT::getValues(this->lclMV_) );
00146 //                   // VERB_EXTREME prints values
00147 //                   for (size_t i=0; i<this->getLocalLength(); ++i) {
00148 //                     out << setw(width) << this->getMap()->getGlobalElement(i) 
00149 //                         << ": "
00150 //                         << myview[i] << endl;
00151 //                   }
00152 //                   myview = Teuchos::null;
00153 //                 }
00154 //               }
00155 //               else {
00156 //                 out << endl;
00157 //               }
00158 //             }
00159 //           }
00160 //         }
00161 //       }
00162     }
00163 
00164   // TODO: move that elsewhere
00165   Epetra_Vector & toEpetra(Vector<double, int, int> &x) {
00166     XPETRA_DYNAMIC_CAST(      EpetraVector, x, tX, "toEpetra");
00167     return *tX.getEpetra_Vector();
00168   }
00169   
00170   const Epetra_Vector & toEpetra(const Vector<double, int, int> &x) {
00171     XPETRA_DYNAMIC_CAST(const EpetraVector, x, tX, "toEpetra");
00172     return *tX.getEpetra_Vector();
00173   }
00174   //
00175 
00176 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines