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 //                    Jonathan Hu       (jhu@sandia.gov)
00040 //                    Andrey Prokopenko (aprokop@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   template<class EpetraGlobalOrdinal>
00053   EpetraVectorT<EpetraGlobalOrdinal>::EpetraVectorT(const Teuchos::RCP<const Map<int,GlobalOrdinal> > &map, bool zeroOut) : EpetraMultiVectorT<GlobalOrdinal>(map,1,zeroOut) { }
00054 
00055   template<class EpetraGlobalOrdinal>
00056   void EpetraVectorT<EpetraGlobalOrdinal>::replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value) { XPETRA_MONITOR("EpetraVectorT::replaceGlobalValue"); this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->ReplaceGlobalValue(globalRow, 0, value); }
00057 
00058   template<class EpetraGlobalOrdinal>
00059   void EpetraVectorT<EpetraGlobalOrdinal>::sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value) { XPETRA_MONITOR("EpetraVectorT::sumIntoGlobalValue");this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->SumIntoGlobalValue(globalRow, 0, value); }
00060 
00061   template<class EpetraGlobalOrdinal>
00062   void EpetraVectorT<EpetraGlobalOrdinal>::replaceLocalValue(LocalOrdinal myRow, const Scalar &value) { XPETRA_MONITOR("EpetraVectorT::replaceLocalValue");this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->ReplaceMyValue(myRow, 0, value); }
00063 
00064   template<class EpetraGlobalOrdinal>
00065   void EpetraVectorT<EpetraGlobalOrdinal>::sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value) { XPETRA_MONITOR("EpetraVectorT::sumIntoLocalValue");this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->SumIntoMyValue(myRow, 0, value); }
00066 
00067   template<class EpetraGlobalOrdinal>
00068   double EpetraVectorT<EpetraGlobalOrdinal>::dot(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &a) const {
00069     XPETRA_MONITOR("EpetraVectorT::dot");
00070 
00071     XPETRA_DYNAMIC_CAST(const EpetraVectorT, a, tA, "This Xpetra::EpetraVectorT method only accept Xpetra::EpetraVectorT as input arguments.");
00072     //      return getEpetra_Vector()->Dot(*tA.getEpetra_Vector());
00073 
00074     // other way: use the MultiVector Dot instead of VectorDot:
00075     double r;
00076     this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->Epetra_MultiVector::Dot(*tA.getEpetra_MultiVector(), &r);
00077     return r;
00078   }
00079 
00080   template<class EpetraGlobalOrdinal>
00081   Teuchos::ScalarTraits<double>::magnitudeType EpetraVectorT<EpetraGlobalOrdinal>::norm1() const { XPETRA_MONITOR("EpetraVectorT::norm1"); double r; this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->Norm1(&r); return r; }
00082 
00083   template<class EpetraGlobalOrdinal>
00084   Teuchos::ScalarTraits<double>::magnitudeType EpetraVectorT<EpetraGlobalOrdinal>::norm2() const { XPETRA_MONITOR("EpetraVectorT::norm2"); double r; this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->Norm2(&r); return r; }
00085 
00086   template<class EpetraGlobalOrdinal>
00087   Teuchos::ScalarTraits<double>::magnitudeType EpetraVectorT<EpetraGlobalOrdinal>::normInf() const { XPETRA_MONITOR("EpetraVectorT::normInf"); double r; this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->NormInf(&r); return r; }
00088 
00089   template<class EpetraGlobalOrdinal>
00090   Teuchos::ScalarTraits<double>::magnitudeType
00091   EpetraVectorT<EpetraGlobalOrdinal>::normWeighted (const Vector<double,int,GlobalOrdinal, KokkosClassic::DefaultNode::DefaultNodeType>& weights) const
00092   {
00093     XPETRA_MONITOR("EpetraVectorT::normWeighted");
00094     XPETRA_DYNAMIC_CAST(const EpetraVectorT, weights, tWeights, "This Xpetra::EpetraVectorT method only accept Xpetra::EpetraVectorT as input arguments.");
00095     double r;
00096     this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->NormWeighted(*tWeights.getEpetra_MultiVector(), &r); return r;
00097   }
00098 
00099   template<class EpetraGlobalOrdinal>
00100   double EpetraVectorT<EpetraGlobalOrdinal>::meanValue() const {
00101     XPETRA_MONITOR("EpetraVectorT::meanValue");
00102     double r;
00103     this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->MeanValue(&r);
00104     return r;
00105   }
00106 
00107     template<class EpetraGlobalOrdinal>
00108     std::string EpetraVectorT<EpetraGlobalOrdinal>::description() const {
00109     XPETRA_MONITOR("EpetraVectorT::description");
00110     // This implementation come from Epetra_Vector_def.hpp (without modification)
00111     std::ostringstream oss;
00112     oss << Teuchos::Describable::description();
00113     oss << "{length="<<this->getGlobalLength()
00114         << "}";
00115     return oss.str();
00116   }
00117 
00118     template<class EpetraGlobalOrdinal>
00119     void EpetraVectorT<EpetraGlobalOrdinal>::describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const {
00120       XPETRA_MONITOR("EpetraVectorT::describe");
00121 
00122       if (verbLevel > Teuchos::VERB_NONE) {
00123         getEpetra_Vector()->Print (out);
00124       }
00125     }
00126 
00127   template<class EpetraGlobalOrdinal>
00128   EpetraVectorT<EpetraGlobalOrdinal>::EpetraVectorT(const RCP<Epetra_MultiVector> &mv, size_t j)
00129     : EpetraMultiVectorT<GlobalOrdinal>(rcp((*mv)(j), false)), // view of the vector number j. false == I do not own the data.
00130       internalRefToBaseMV_(mv)                 // keep an internal reference to the initial MultiVector to avoid desallocation of the view.
00131   {
00132     // The view of the internal data of 'mv' is only valid until the destruction of 'mv'.
00133     // The new vector hold an internal reference to 'mv' in order to keep the view valid after disappearance of 'mv' references in user code.
00134     // This implements the logic of subArray rcp (as required by the Tpetra interface).
00135   }
00136 
00137   // TODO: move that elsewhere
00138   template<class GlobalOrdinal>
00139   Epetra_Vector & toEpetra(Vector<double, int, GlobalOrdinal> &x) {
00140     XPETRA_DYNAMIC_CAST(      EpetraVectorT<GlobalOrdinal>, x, tX, "toEpetra");
00141     return *tX.getEpetra_Vector();
00142   }
00143 
00144   template<class GlobalOrdinal>
00145   const Epetra_Vector & toEpetra(const Vector<double, int, GlobalOrdinal> &x) {
00146     XPETRA_DYNAMIC_CAST(const EpetraVectorT<GlobalOrdinal>, x, tX, "toEpetra");
00147     return *tX.getEpetra_Vector();
00148   }
00149   //
00150 
00151 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
00152 template class EpetraVectorT<int>;
00153 template Epetra_Vector & toEpetra<int>(Vector<double, int, int> &);
00154 template const Epetra_Vector & toEpetra<int>(const Vector<double, int, int> &);
00155 #endif
00156 
00157 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
00158 template class EpetraVectorT<long long>;
00159 template Epetra_Vector & toEpetra<long long>(Vector<double, int, long long> &);
00160 template const Epetra_Vector & toEpetra<long long>(const Vector<double, int, long long> &);
00161 #endif
00162 
00163 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines