• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

MOR_EpetraSamplingOperator.cpp

Go to the documentation of this file.
00001 //*****************************************************************//
00002 //    Albany 2.0:  Copyright 2012 Sandia Corporation               //
00003 //    This Software is released under the BSD license detailed     //
00004 //    in the file "license.txt" in the top-level Albany directory  //
00005 //*****************************************************************//
00006 #include "MOR_EpetraSamplingOperator.hpp"
00007 
00008 #include "MOR_EpetraUtils.hpp"
00009 
00010 #include "Epetra_MultiVector.h"
00011 #include "Epetra_Comm.h"
00012 
00013 #include "Teuchos_Assert.hpp"
00014 #include "Teuchos_TypeNameTraits.hpp"
00015 
00016 #include <string>
00017 #include <algorithm>
00018 
00019 namespace MOR {
00020 
00021 using ::Teuchos::Array;
00022 using ::Teuchos::ArrayView;
00023 
00024 EpetraSamplingOperator::EpetraSamplingOperator(
00025     const Epetra_Map &map,
00026     const ArrayView<const GlobalIndex> &sampleLIDs) :
00027   map_(map),
00028   sampleLIDs_(sampleLIDs)
00029 {
00030   std::sort(sampleLIDs_.begin(), sampleLIDs_.end());
00031 }
00032 
00033 EpetraSamplingOperator::EpetraSamplingOperator(
00034     const Epetra_Map &map,
00035     FromGIDsTag,
00036     const Teuchos::ArrayView<const EpetraSamplingOperator::GlobalIndex> &sampleGIDs) :
00037   map_(map),
00038   sampleLIDs_(getMyLIDs(map, sampleGIDs))
00039 {
00040   std::sort(sampleLIDs_.begin(), sampleLIDs_.end());
00041 }
00042 
00043 const char *EpetraSamplingOperator::Label() const
00044 {
00045   static const std::string label = Teuchos::TypeNameTraits<EpetraSamplingOperator>::name();
00046   return label.c_str();
00047 }
00048 
00049 const Epetra_Map &EpetraSamplingOperator::OperatorDomainMap() const
00050 {
00051   return map_;
00052 }
00053 
00054 const Epetra_Map &EpetraSamplingOperator::OperatorRangeMap() const
00055 {
00056   return map_;
00057 }
00058 
00059 const Epetra_Comm &EpetraSamplingOperator::Comm() const
00060 {
00061   return map_.Comm();
00062 }
00063 
00064 int EpetraSamplingOperator::SetUseTranspose(bool UseTranspose)
00065 {
00066   useTranspose_ = UseTranspose;
00067   return 0;
00068 }
00069 
00070 bool EpetraSamplingOperator::UseTranspose() const
00071 {
00072   return useTranspose_;
00073 }
00074 
00075 int EpetraSamplingOperator::Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
00076 {
00077   TEUCHOS_ASSERT(map_.PointSameAs(X.Map()) && map_.PointSameAs(Y.Map()));
00078   TEUCHOS_ASSERT(X.NumVectors() == Y.NumVectors());
00079 
00080   Y.PutScalar(0.0);
00081 
00082   for (int iVec = 0; iVec < X.NumVectors(); ++iVec) {
00083     const ArrayView<const double> sourceVec(X[iVec], X.MyLength());
00084     const ArrayView<double> targetVec(Y[iVec], Y.MyLength());
00085     for (Array<GlobalIndex>::const_iterator it = sampleLIDs_.begin(), it_end = sampleLIDs_.end(); it != it_end; ++it) {
00086        targetVec[*it] = sourceVec[*it];
00087     }
00088   }
00089 
00090   return 0;
00091 }
00092 
00093 int EpetraSamplingOperator::ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
00094 {
00095   // Not supported (rank-deficient operator)
00096   return -1;
00097 }
00098 
00099 bool EpetraSamplingOperator::HasNormInf() const
00100 {
00101   return true;
00102 }
00103 
00104 double EpetraSamplingOperator::NormInf() const
00105 {
00106   // Using long because of Epetra_Comm::SumAll (should be Array<GlobalIndex>::size_type)
00107   long mySampleCount = sampleLIDs_.size(); // Nonconst because of Epetra_Comm::SumAll
00108   long sampleCount;
00109   this->Comm().SumAll(&mySampleCount, &sampleCount, 1);
00110   return sampleCount != 0l ? 1.0 : 0.0;
00111 }
00112 
00113 } // namespace MOR

Generated on Wed Mar 26 2014 18:36:40 for Albany: a Trilinos-based PDE code by  doxygen 1.7.1