00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef THYRA_VECTOR_SERIAL_BASE_HPP
00030 #define THYRA_VECTOR_SERIAL_BASE_HPP
00031
00032 #include "Thyra_SerialVectorBaseDecl.hpp"
00033 #include "Thyra_apply_op_helper.hpp"
00034 #include "Teuchos_Workspace.hpp"
00035 #include "Teuchos_TestForException.hpp"
00036
00037 namespace Thyra {
00038
00039 template<class Scalar>
00040 SerialVectorBase<Scalar>::SerialVectorBase()
00041 :in_applyOp_(false)
00042 {}
00043
00044
00045
00046 template<class Scalar>
00047 void SerialVectorBase<Scalar>::getData( const Scalar** values, Index* stride ) const
00048 {
00049 const_cast<SerialVectorBase<Scalar>*>(this)->getData(const_cast<Scalar**>(values),stride);
00050 }
00051
00052 template<class Scalar>
00053 void SerialVectorBase<Scalar>::freeData( const Scalar** values ) const
00054 {
00055 const_cast<SerialVectorBase<Scalar>*>(this)->commitData(const_cast<Scalar**>(values));
00056 }
00057
00058
00059
00060 template<class Scalar>
00061 void SerialVectorBase<Scalar>::applyOp(
00062 const RTOpPack::RTOpT<Scalar> &op
00063 ,const int num_vecs
00064 ,const VectorBase<Scalar>* vecs[]
00065 ,const int num_targ_vecs
00066 ,VectorBase<Scalar>* targ_vecs[]
00067 ,RTOpPack::ReductTarget *reduct_obj
00068 ,const Index first_ele
00069 ,const Index sub_dim
00070 ,const Index global_offset
00071 ) const
00072 {
00073 #ifdef _DEBUG
00074 TEST_FOR_EXCEPTION(
00075 in_applyOp_, std::logic_error
00076 ,"SerialVectorBase::applyOp(...): Error, something is not right here!" );
00077 Thyra::apply_op_validate_input(
00078 "SerialVectorBase<>::applyOp(...)",*this->space()
00079 ,op,num_vecs,vecs,num_targ_vecs,targ_vecs,reduct_obj,first_ele,sub_dim,global_offset
00080 );
00081 #endif
00082 in_applyOp_ = true;
00083 Thyra::apply_op_serial(
00084 *(this->space())
00085 ,op,num_vecs,vecs,num_targ_vecs,targ_vecs,reduct_obj
00086 ,first_ele,sub_dim,global_offset
00087 );
00088 in_applyOp_ = false;
00089 }
00090
00091 template<class Scalar>
00092 void SerialVectorBase<Scalar>::getSubVector( const Range1D& rng_in, RTOpPack::SubVectorT<Scalar>* sub_vec ) const
00093 {
00094 const Index this_dim = this->space()->dim();
00095 const Range1D rng = RangePack::full_range(rng_in,1,this_dim);
00096 #ifdef _DEBUG
00097 TEST_FOR_EXCEPTION(
00098 rng.ubound() > this_dim, std::out_of_range
00099 ,"SerialVectorBase<Scalar>::getSubVector(...) : Error, "
00100 "rng = ["<<rng.lbound()<<","<<rng.ubound()<<"] "
00101 "is not in the range [1,this->dim()] = [1," << this_dim << "]!" );
00102 #endif
00103 const Scalar *values = NULL; Index stride = 0;
00104 this->getData(&values,&stride);
00105 sub_vec->initialize(
00106 rng.lbound()-1
00107 ,rng.size()
00108 ,values+stride*(rng.lbound()-1)
00109 ,stride
00110 );
00111 }
00112
00113 template<class Scalar>
00114 void SerialVectorBase<Scalar>::freeSubVector( RTOpPack::SubVectorT<Scalar>* sub_vec ) const
00115 {
00116 sub_vec->set_uninitialized();
00117 }
00118
00119 template<class Scalar>
00120 void SerialVectorBase<Scalar>::getSubVector( const Range1D& rng_in, RTOpPack::MutableSubVectorT<Scalar>* sub_vec )
00121 {
00122 const Index this_dim = this->space()->dim();
00123 const Range1D rng = RangePack::full_range(rng_in,1,this_dim);
00124 #ifdef _DEBUG
00125 TEST_FOR_EXCEPTION(
00126 rng.ubound() > this_dim, std::out_of_range
00127 ,"SerialVectorBase<Scalar>::getSubVector(...) : Error, "
00128 "rng = ["<<rng.lbound()<<","<<rng.ubound()<<"] "
00129 "is not in the range [1,this->dim()] = [1," << this_dim << "]!" );
00130 #endif
00131 Scalar *values = NULL; Index stride = 0;
00132 this->getData(&values,&stride);
00133 sub_vec->initialize(
00134 rng.lbound()-1
00135 ,rng.size()
00136 ,values+stride*(rng.lbound()-1)
00137 ,stride
00138 );
00139 }
00140
00141 template<class Scalar>
00142 void SerialVectorBase<Scalar>::commitSubVector( RTOpPack::MutableSubVectorT<Scalar>* sub_vec )
00143 {
00144 sub_vec->set_uninitialized();
00145 }
00146
00147 template<class Scalar>
00148 void SerialVectorBase<Scalar>::setSubVector( const RTOpPack::SparseSubVectorT<Scalar>& sub_vec )
00149 {
00150 VectorBase<Scalar>::setSubVector(sub_vec);
00151 }
00152
00153 }
00154
00155 #endif // THYRA_VECTOR_SERIAL_BASE_HPP