|
Collection of Concrete Vector Reduction/Transformation Operator Implementations
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // RTOp: Interfaces and Support Software for Vector Reduction Transformation 00005 // Operations 00006 // Copyright (2006) Sandia Corporation 00007 // 00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00009 // license for use of this work by or on behalf of the U.S. Government. 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 Roscoe A. Bartlett (rabartl@sandia.gov) 00039 // 00040 // *********************************************************************** 00041 // @HEADER 00042 00043 #ifndef RTOPPACK_ROP_GET_SUB_VECTOR_DEF_HPP 00044 #define RTOPPACK_ROP_GET_SUB_VECTOR_DEF_HPP 00045 00046 00047 #include "RTOpPack_ROpGetSubVector_decl.hpp" 00048 00049 00050 namespace RTOpPack { 00051 00052 00053 template<class Scalar> 00054 ROpGetSubVector<Scalar>::ROpGetSubVector( const index_type l, 00055 const index_type u 00056 ) 00057 :RTOpT<Scalar>("ROpGetSubVector"), l_(l), u_(u) 00058 {} 00059 00060 00061 template<class Scalar> 00062 void ROpGetSubVector<Scalar>::set_range( const index_type l, 00063 const index_type u 00064 ) 00065 { 00066 l_ = l; 00067 u_ = u; 00068 } 00069 00070 00071 template<class Scalar> 00072 const ConstSubVectorView<Scalar> 00073 ROpGetSubVector<Scalar>::operator()( const ReductTarget& reduct_obj ) const 00074 { 00075 using Teuchos::dyn_cast; 00076 return dyn_cast<const DefaultReductTarget<SubVectorView< Scalar> > >(reduct_obj).get(); 00077 } 00078 00079 00080 // Overridden from RTOpT 00081 00082 00083 template<class Scalar> 00084 void ROpGetSubVector<Scalar>::get_reduct_type_num_entries_impl( 00085 const Ptr<int> &num_values, 00086 const Ptr<int> &num_indexes, 00087 const Ptr<int> &num_chars 00088 ) const 00089 { 00090 typedef PrimitiveTypeTraits<Scalar,Scalar> PTT; 00091 const int num_prim_objs_per_scalar = PTT::numPrimitiveObjs(); 00092 *num_values = (u_-l_+1)*num_prim_objs_per_scalar; 00093 *num_indexes = 0; 00094 *num_chars = 0; 00095 } 00096 00097 00098 template<class Scalar> 00099 Teuchos::RCP<ReductTarget> 00100 ROpGetSubVector<Scalar>::reduct_obj_create_impl() const 00101 { 00102 const index_type subDim = u_ - l_ + 1; 00103 const ArrayRCP<Scalar> values = Teuchos::arcp<Scalar>(subDim); 00104 std::fill(values.begin(), values.end(), ScalarTraits<Scalar>::zero()); 00105 return defaultReductTarget( 00106 SubVectorView<Scalar>( l_, subDim, values, 1 ) 00107 ); 00108 } 00109 00110 00111 template<class Scalar> 00112 void ROpGetSubVector<Scalar>::reduce_reduct_objs_impl( 00113 const ReductTarget &in_reduct_obj, const Ptr<ReductTarget> &inout_reduct_obj 00114 ) const 00115 { 00116 00117 using Teuchos::dyn_cast; 00118 typedef DefaultReductTarget<SubVectorView<Scalar> > DRTSVV; 00119 00120 DRTSVV &drtsvv_inout_reduct_obj = dyn_cast<DRTSVV>(*inout_reduct_obj); 00121 00122 const ConstSubVectorView<Scalar> sub_vec_in = 00123 dyn_cast<const DRTSVV>(in_reduct_obj).get(); 00124 SubVectorView<Scalar> sub_vec_inout = drtsvv_inout_reduct_obj.get(); 00125 00126 #ifdef TEUCHOS_DEBUG 00127 TEUCHOS_TEST_FOR_EXCEPT( 00128 sub_vec_in.subDim()!=sub_vec_inout.subDim() 00129 || sub_vec_in.globalOffset()!=sub_vec_inout.globalOffset() 00130 || is_null(sub_vec_in.values()) 00131 || is_null(sub_vec_inout.values()) 00132 || sub_vec_in.stride()!=1 00133 || sub_vec_inout.stride()!=1 00134 ); 00135 #endif // TEUCHOS_DEBUG 00136 00137 typedef typename ArrayRCP<const Scalar>::const_iterator const_iter_t; 00138 typedef typename ArrayRCP<Scalar>::iterator iter_t; 00139 00140 const_iter_t in_iter = sub_vec_in.values().begin(); 00141 iter_t inout_iter = sub_vec_inout.values().begin(); 00142 00143 for( int k = 0; k < sub_vec_in.subDim(); ++k ) { 00144 *inout_iter++ += *in_iter++; 00145 } 00146 00147 drtsvv_inout_reduct_obj.set(sub_vec_inout); 00148 00149 } 00150 00151 00152 template<class Scalar> 00153 void ROpGetSubVector<Scalar>::reduct_obj_reinit_impl( 00154 const Ptr<ReductTarget> &reduct_obj ) const 00155 { 00156 using Teuchos::dyn_cast; 00157 typedef DefaultReductTarget<SubVectorView<Scalar> > DRTSVV; 00158 DRTSVV &drtsvv_inout_reduct_obj = dyn_cast<DRTSVV>(*reduct_obj); 00159 SubVectorView<Scalar> sub_vec = drtsvv_inout_reduct_obj.get(); 00160 std::fill( sub_vec.values().begin(), sub_vec.values().end(), 00161 ScalarTraits<Scalar>::zero() ); 00162 } 00163 00164 00165 template<class Scalar> 00166 void ROpGetSubVector<Scalar>::extract_reduct_obj_state_impl( 00167 const ReductTarget &reduct_obj, 00168 const ArrayView<primitive_value_type> &value_data, 00169 const ArrayView<index_type> &index_data, 00170 const ArrayView<char_type> &char_data 00171 ) const 00172 { 00173 using Teuchos::null; 00174 using Teuchos::dyn_cast; 00175 typedef PrimitiveTypeTraits<Scalar,Scalar> PTT; 00176 const int num_prim_objs_per_scalar = PTT::numPrimitiveObjs(); 00177 const ConstSubVectorView<Scalar> sub_vec = 00178 dyn_cast<const DefaultReductTarget<SubVectorView<Scalar> > >(reduct_obj).get(); 00179 int value_data_off = 0; 00180 for( 00181 int k = 0; 00182 k < sub_vec.subDim(); 00183 ++k, value_data_off += num_prim_objs_per_scalar 00184 ) 00185 { 00186 PTT::extractPrimitiveObjs( sub_vec[k], 00187 value_data(value_data_off, num_prim_objs_per_scalar), 00188 null, null ); 00189 } 00190 } 00191 00192 00193 template<class Scalar> 00194 void ROpGetSubVector<Scalar>::load_reduct_obj_state_impl( 00195 const ArrayView<const primitive_value_type> &value_data, 00196 const ArrayView<const index_type> &index_data, 00197 const ArrayView<const char_type> &char_data, 00198 const Ptr<ReductTarget> &reduct_obj 00199 ) const 00200 { 00201 using Teuchos::null; 00202 using Teuchos::outArg; 00203 using Teuchos::dyn_cast; 00204 using Teuchos::arcp_const_cast; 00205 typedef PrimitiveTypeTraits<Scalar,Scalar> PTT; 00206 typedef DefaultReductTarget<SubVectorView<Scalar> > DRTSVV; 00207 const int num_prim_objs_per_scalar = PTT::numPrimitiveObjs(); 00208 DRTSVV &drtsvv_reduct_obj = dyn_cast<DRTSVV>(*reduct_obj); 00209 const ConstSubVectorView<Scalar> const_sub_vec = drtsvv_reduct_obj.get(); 00210 const ArrayRCP<Scalar> sv_values = 00211 arcp_const_cast<Scalar>(const_sub_vec.values()); 00212 int value_data_off = 0; 00213 for( 00214 int k = 0; 00215 k < const_sub_vec.subDim(); 00216 ++k, value_data_off += num_prim_objs_per_scalar 00217 ) 00218 { 00219 PTT::loadPrimitiveObjs( 00220 value_data(value_data_off, num_prim_objs_per_scalar), null, null, 00221 outArg(sv_values[k]) ); 00222 } 00223 } 00224 00225 00226 template<class Scalar> 00227 bool ROpGetSubVector<Scalar>::coord_invariant_impl() const 00228 { 00229 return false; 00230 } 00231 00232 00233 template<class Scalar> 00234 void ROpGetSubVector<Scalar>::apply_op_impl( 00235 const ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs, 00236 const ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs, 00237 const Ptr<ReductTarget> &reduct_obj 00238 ) const 00239 { 00240 00241 using Teuchos::dyn_cast; 00242 typedef DefaultReductTarget<SubVectorView<Scalar> > DRTSVV; 00243 00244 validate_apply_op( *this, 1, 0, true, 00245 sub_vecs, targ_sub_vecs, reduct_obj.getConst() ); 00246 00247 typedef typename Teuchos::ArrayRCP<const Scalar>::iterator const_iter_t; 00248 const index_type subDim = sub_vecs[0].subDim(); 00249 const index_type globalOffset = sub_vecs[0].globalOffset(); 00250 TEUCHOS_TEST_FOR_EXCEPT(globalOffset<0); 00251 const_iter_t v0_val = sub_vecs[0].values().begin(); 00252 const ptrdiff_t v0_s = sub_vecs[0].stride(); 00253 00254 if( u_ < globalOffset || globalOffset + subDim - 1 < l_ ) { 00255 // None of the sub-vector elements that we are looking for is in this 00256 // vector chunk! 00257 return; 00258 } 00259 00260 index_type 00261 i_l = ( l_ <= globalOffset ? 0 : l_ - globalOffset ), 00262 i_u = ( u_ >= globalOffset+subDim-1 ? subDim-1 : u_ - globalOffset ); 00263 00264 DRTSVV &drtsvv_reduct_obj = dyn_cast<DRTSVV>(*reduct_obj); 00265 SubVectorView<Scalar> sub_vec_targ = drtsvv_reduct_obj.get(); 00266 00267 const ArrayRCP<Scalar> svt_values = sub_vec_targ.values(); 00268 00269 for( index_type i = i_l; i <= i_u; ++i ) { 00270 svt_values[i+(globalOffset-l_)] = v0_val[i*v0_s]; 00271 } 00272 00273 drtsvv_reduct_obj.set(sub_vec_targ); 00274 00275 } 00276 00277 00278 } // namespace RTOpPack 00279 00280 00281 #endif // RTOPPACK_ROP_GET_SUB_VECTOR_DEF_HPP
1.7.6.1