Xpetra_EpetraVector.cpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #include "Xpetra_EpetraVector.hpp"
47 
48 //TODO: replace double -> Scalar etc.
49 
50 namespace Xpetra {
51 
52  template<class EpetraGlobalOrdinal>
53  EpetraVectorT<EpetraGlobalOrdinal>::EpetraVectorT(const Teuchos::RCP<const Map<int,GlobalOrdinal> > &map, bool zeroOut) : EpetraMultiVectorT<GlobalOrdinal>(map,1,zeroOut) { }
54 
55  template<class EpetraGlobalOrdinal>
56  void EpetraVectorT<EpetraGlobalOrdinal>::replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value) { XPETRA_MONITOR("EpetraVectorT::replaceGlobalValue"); this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->ReplaceGlobalValue(globalRow, 0, value); }
57 
58  template<class EpetraGlobalOrdinal>
59  void EpetraVectorT<EpetraGlobalOrdinal>::sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value) { XPETRA_MONITOR("EpetraVectorT::sumIntoGlobalValue");this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->SumIntoGlobalValue(globalRow, 0, value); }
60 
61  template<class EpetraGlobalOrdinal>
62  void EpetraVectorT<EpetraGlobalOrdinal>::replaceLocalValue(LocalOrdinal myRow, const Scalar &value) { XPETRA_MONITOR("EpetraVectorT::replaceLocalValue");this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->ReplaceMyValue(myRow, 0, value); }
63 
64  template<class EpetraGlobalOrdinal>
65  void EpetraVectorT<EpetraGlobalOrdinal>::sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value) { XPETRA_MONITOR("EpetraVectorT::sumIntoLocalValue");this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->SumIntoMyValue(myRow, 0, value); }
66 
67  template<class EpetraGlobalOrdinal>
69  XPETRA_MONITOR("EpetraVectorT::dot");
70 
71  XPETRA_DYNAMIC_CAST(const EpetraVectorT, a, tA, "This Xpetra::EpetraVectorT method only accept Xpetra::EpetraVectorT as input arguments.");
72  // return getEpetra_Vector()->Dot(*tA.getEpetra_Vector());
73 
74  // other way: use the MultiVector Dot instead of VectorDot:
75  double r;
76  this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->Epetra_MultiVector::Dot(*tA.getEpetra_MultiVector(), &r);
77  return r;
78  }
79 
80  template<class EpetraGlobalOrdinal>
82 
83  template<class EpetraGlobalOrdinal>
85 
86  template<class EpetraGlobalOrdinal>
88 
89  template<class EpetraGlobalOrdinal>
92  {
93  XPETRA_MONITOR("EpetraVectorT::normWeighted");
94  XPETRA_DYNAMIC_CAST(const EpetraVectorT, weights, tWeights, "This Xpetra::EpetraVectorT method only accept Xpetra::EpetraVectorT as input arguments.");
95  double r[1];
96  this->EpetraMultiVectorT<GlobalOrdinal>::getEpetra_MultiVector()->NormWeighted(*tWeights.getEpetra_MultiVector(), r);
97  return r[0];
98  }
99 
100  template<class EpetraGlobalOrdinal>
102  XPETRA_MONITOR("EpetraVectorT::meanValue");
103  double r;
105  return r;
106  }
107 
108  template<class EpetraGlobalOrdinal>
110  XPETRA_MONITOR("EpetraVectorT::description");
111  // This implementation come from Epetra_Vector_def.hpp (without modification)
112  std::ostringstream oss;
114  oss << "{length="<<this->getGlobalLength()
115  << "}";
116  return oss.str();
117  }
118 
119  template<class EpetraGlobalOrdinal>
121  XPETRA_MONITOR("EpetraVectorT::describe");
122 
123  if (verbLevel > Teuchos::VERB_NONE) {
124  getEpetra_Vector()->Print (out);
125  }
126  }
127 
128  template<class EpetraGlobalOrdinal>
130  : EpetraMultiVectorT<GlobalOrdinal>(rcp((*mv)(j), false)), // view of the vector number j. false == I do not own the data.
131  internalRefToBaseMV_(mv) // keep an internal reference to the initial MultiVector to avoid desallocation of the view.
132  {
133  // The view of the internal data of 'mv' is only valid until the destruction of 'mv'.
134  // The new vector hold an internal reference to 'mv' in order to keep the view valid after disappearance of 'mv' references in user code.
135  // This implements the logic of subArray rcp (as required by the Tpetra interface).
136  }
137 
138  // TODO: move that elsewhere
139  template<class GlobalOrdinal>
142  return *tX.getEpetra_Vector();
143  }
144 
145  template<class GlobalOrdinal>
146  const Epetra_Vector & toEpetra(const Vector<double, int, GlobalOrdinal> &x) {
147  XPETRA_DYNAMIC_CAST(const EpetraVectorT<GlobalOrdinal>, x, tX, "toEpetra");
148  return *tX.getEpetra_Vector();
149  }
150  //
151 
152 #ifndef XPETRA_EPETRA_NO_32BIT_GLOBAL_INDICES
153 template class EpetraVectorT<int>;
154 template Epetra_Vector & toEpetra<int>(Vector<double, int, int> &);
155 template const Epetra_Vector & toEpetra<int>(const Vector<double, int, int> &);
156 #endif
157 
158 #ifndef XPETRA_EPETRA_NO_64BIT_GLOBAL_INDICES
159 template class EpetraVectorT<long long>;
160 template Epetra_Vector & toEpetra<long long>(Vector<double, int, long long> &);
161 template const Epetra_Vector & toEpetra<long long>(const Vector<double, int, long long> &);
162 #endif
163 
164 }
template const Epetra_CrsGraph & toEpetra< long long >(const RCP< const CrsGraph< int, long long > > &graph)
void sumIntoGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Adds specified value to existing value at the specified location.
Scalar dot(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &a) const
Computes dot product of this Vector against input Vector x.
const Epetra_CrsGraph & toEpetra(const RCP< const CrsGraph< int, GlobalOrdinal > > &graph)
Teuchos::ScalarTraits< Scalar >::magnitudeType normWeighted(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &weights) const
Compute Weighted 2-norm (RMS Norm) of this Vector.
void replaceLocalValue(LocalOrdinal myRow, const Scalar &value)
Replace current value at the specified location with specified values.
Xpetra namespace
void sumIntoLocalValue(LocalOrdinal myRow, const Scalar &value)
Adds specified value to existing value at the specified location.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm2() const
Compute 2-norm of this Vector.
template const Epetra_CrsGraph & toEpetra< int >(const RCP< const CrsGraph< int, int > > &graph)
EpetraVectorT(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, bool zeroOut=true)
Sets all vector entries to zero.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual std::string description() const
Teuchos::ScalarTraits< Scalar >::magnitudeType norm1() const
Return 1-norm of this Vector.
std::string description() const
Return a simple one-line description of this object.
Scalar meanValue() const
Compute mean (average) value of this Vector.
#define XPETRA_DYNAMIC_CAST(type, obj, newObj, exceptionMsg)
void replaceGlobalValue(GlobalOrdinal globalRow, const Scalar &value)
Replace current value at the specified location with specified value.
#define XPETRA_MONITOR(funcName)
RCP< Epetra_MultiVector > getEpetra_MultiVector() const
Get the underlying Epetra multivector.
Teuchos::ScalarTraits< Scalar >::magnitudeType normInf() const
Compute Inf-norm of this Vector.