|
Thyra Package Browser (Single Doxygen Collection) Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Thyra: Interfaces and Support for Abstract Numerical Algorithms 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef THYRA_DETACHED_SPMD_VECTOR_VIEW_HPP 00030 #define THYRA_DETACHED_SPMD_VECTOR_VIEW_HPP 00031 00032 00033 #include "Thyra_SpmdVectorBase.hpp" 00034 #include "Teuchos_Assert.hpp" 00035 00036 00037 namespace Thyra { 00038 00039 00048 template<class Scalar> 00049 class ConstDetachedSpmdVectorView { 00050 public: 00052 ConstDetachedSpmdVectorView(const Teuchos::RCP<const VectorBase<Scalar> > &v) 00053 { 00054 using Teuchos::rcp_dynamic_cast; 00055 if (!is_null(v)) { 00056 const RCP<const SpmdVectorBase<Scalar> > spmd_v = 00057 rcp_dynamic_cast<const SpmdVectorBase<Scalar> >(v, true); 00058 v_ = spmd_v; 00059 sv_ = spmd_v->getLocalSubVector(); 00060 } 00061 else { 00062 v_ = Teuchos::null; 00063 sv_ = RTOpPack::ConstSubVectorView<Scalar>(); 00064 } 00065 } 00067 ~ConstDetachedSpmdVectorView() 00068 {} 00070 const RCP<const SpmdVectorSpaceBase<Scalar> > spmdSpace() const 00071 { if (!is_null(v_)) return v_->spmdSpace(); return Teuchos::null; } 00073 const RTOpPack::ConstSubVectorView<Scalar>& sv() const { return sv_; } 00075 Teuchos_Index globalOffset() const { return sv_.globalOffset(); } 00077 Teuchos_Index subDim() const { return sv_.subDim(); } 00079 const ArrayRCP<const Scalar> values() const { return sv_.values(); } 00081 ptrdiff_t stride() const { return sv_.stride(); } 00083 const Scalar& operator[](Teuchos_Index i) const { return sv_[i]; } 00085 const Scalar& operator()(Teuchos_Index i) const { return sv_(i); } 00086 private: 00087 Teuchos::RCP<const SpmdVectorBase<Scalar> > v_; 00088 RTOpPack::ConstSubVectorView<Scalar> sv_; 00089 // Not defined and not to be called 00090 ConstDetachedSpmdVectorView(); 00091 ConstDetachedSpmdVectorView(const ConstDetachedSpmdVectorView<Scalar>&); 00092 ConstDetachedSpmdVectorView<Scalar>& operator==( 00093 const ConstDetachedSpmdVectorView<Scalar>&); 00094 }; 00095 00096 00105 template<class Scalar> 00106 class DetachedSpmdVectorView { 00107 public: 00109 DetachedSpmdVectorView(const Teuchos::RCP<VectorBase<Scalar> > &v) 00110 { 00111 using Teuchos::rcp_dynamic_cast; 00112 if (!is_null(v)) { 00113 const RCP<SpmdVectorBase<Scalar> > spmd_v = 00114 rcp_dynamic_cast<SpmdVectorBase<Scalar> >(v, true); 00115 v_ = spmd_v; 00116 sv_ = spmd_v->getNonconstLocalSubVector(); 00117 } 00118 else { 00119 v_ = Teuchos::null; 00120 sv_ = RTOpPack::SubVectorView<Scalar>(); 00121 } 00122 } 00124 ~DetachedSpmdVectorView() 00125 {} 00127 const RCP<const SpmdVectorSpaceBase<Scalar> > spmdSpace() const 00128 { if (!is_null(v_)) return v_->spmdSpace(); return Teuchos::null; } 00130 const RTOpPack::SubVectorView<Scalar>& sv() const { return sv_; } 00132 Teuchos_Index globalOffset() const { return sv_.globalOffset(); } 00134 Teuchos_Index subDim() const { return sv_.subDim(); } 00136 const ArrayRCP<const Scalar> values() const { return sv_.values(); } 00138 ptrdiff_t stride() const { return sv_.stride(); } 00140 Scalar& operator[](Teuchos_Index i) const { return sv_[i]; } 00142 Scalar& operator()(Teuchos_Index i) const { return sv_(i); } 00143 private: 00144 Teuchos::RCP<SpmdVectorBase<Scalar> > v_; 00145 RTOpPack::SubVectorView<Scalar> sv_; 00146 // Not defined and not to be called 00147 DetachedSpmdVectorView(); 00148 DetachedSpmdVectorView(const DetachedSpmdVectorView<Scalar>&); 00149 DetachedSpmdVectorView<Scalar>& operator==( 00150 const DetachedSpmdVectorView<Scalar>&); 00151 }; 00152 00153 00154 } // namespace Thyra 00155 00156 00157 #endif // THYRA_DETACHED_SPMD_VECTOR_VIEW_HPP
1.7.4