|
RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00005 // Copyright (2003) 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 Roscoe A. Bartlett (rabartl@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 // /////////////////////////////// 00030 // RTOpPack_RTOpC.hpp 00031 00032 #ifndef RTOPPACK_RTOP_NEW_C_HPP 00033 #define RTOPPACK_RTOP_NEW_C_HPP 00034 00035 #include "RTOpPack_OldTypes.hpp" 00036 #include "RTOpPack_RTOpT.hpp" 00037 #include "RTOp.h" 00038 #include "Teuchos_dyn_cast.hpp" 00039 00040 namespace RTOpPack { 00041 00046 class RTOpC : public RTOpT<RTOp_value_type> { 00047 public: 00048 00050 typedef RTOp_value_type Scalar; 00052 RTOpC(); 00054 ~RTOpC(); 00056 RTOp_RTOp& op(); 00058 const RTOp_RTOp& op() const; 00060 RTOp_ReductTarget& operator()(ReductTarget& reduct_obj) const; 00062 const RTOp_ReductTarget& operator()(const ReductTarget& reduct_obj) const; 00063 00066 00068 void get_reduct_type_num_entries_impl( 00069 const Teuchos::Ptr<int> &num_values, 00070 const Teuchos::Ptr<int> &num_indexes, 00071 const Teuchos::Ptr<int> &num_chars 00072 ) const; 00074 Teuchos::RCP<ReductTarget> reduct_obj_create_impl() const; 00076 void reduce_reduct_objs_impl( 00077 const ReductTarget &in_reduct_obj, 00078 const Teuchos::Ptr<ReductTarget> &inout_reduct_obj 00079 ) const; 00081 void reduct_obj_reinit_impl( 00082 const Teuchos::Ptr<ReductTarget> &reduct_obj 00083 ) const; 00085 void extract_reduct_obj_state_impl( 00086 const ReductTarget &reduct_obj, 00087 const Teuchos::ArrayView<primitive_value_type> &value_data, 00088 const Teuchos::ArrayView<index_type> &index_data, 00089 const Teuchos::ArrayView<char_type> &char_data 00090 ) const; 00092 void load_reduct_obj_state_impl( 00093 const Teuchos::ArrayView<const primitive_value_type> &value_data, 00094 const Teuchos::ArrayView<const index_type> &index_data, 00095 const Teuchos::ArrayView<const char_type> &char_data, 00096 const Teuchos::Ptr<ReductTarget> &reduct_obj 00097 ) const; 00099 bool coord_invariant_impl() const; 00101 std::string op_name_impl() const; 00103 void apply_op_impl( 00104 const Teuchos::ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs, 00105 const Teuchos::ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs, 00106 const Teuchos::Ptr<ReductTarget> &reduct_obj 00107 ) const; 00108 00110 00111 private: 00112 00113 RTOp_RTOp op_; 00114 00115 }; // class RTOpC 00116 00119 class ReductTargetC : public ReductTarget { 00120 public: 00121 inline ReductTargetC( const RTOp_RTOp& op, RTOp_ReductTarget obj ); 00122 inline ~ReductTargetC(); 00123 inline RTOp_ReductTarget& obj(); 00124 inline const RTOp_ReductTarget& obj() const; 00125 private: 00126 const RTOp_RTOp &op_; 00127 RTOp_ReductTarget obj_; 00128 ReductTargetC(); // Not defined and not to be called 00129 }; 00130 00131 // /////////////////////////////// 00132 // Inline member functions 00133 00134 // RTOpC 00135 00136 inline 00137 RTOp_RTOp& RTOpC::op() 00138 { 00139 return op_; 00140 } 00141 00142 inline 00143 const RTOp_RTOp& RTOpC::op() const 00144 { 00145 return op_; 00146 } 00147 00148 inline 00149 RTOp_ReductTarget& 00150 RTOpC::operator()(ReductTarget& reduct_obj) const 00151 { 00152 return Teuchos::dyn_cast<ReductTargetC>(reduct_obj).obj(); 00153 } 00154 00155 inline 00156 const RTOp_ReductTarget& 00157 RTOpC::operator()(const ReductTarget& reduct_obj) const 00158 { 00159 return Teuchos::dyn_cast<const ReductTargetC>(reduct_obj).obj(); 00160 } 00161 00162 // ReductTargetC 00163 00164 inline 00165 ReductTargetC::ReductTargetC( const RTOp_RTOp& op, RTOp_ReductTarget obj ) 00166 : op_(op), obj_(obj) 00167 {} 00168 00169 inline 00170 ReductTargetC::~ReductTargetC() 00171 { 00172 if( obj() != RTOp_REDUCT_OBJ_NULL ) { 00173 TEST_FOR_EXCEPTION( 00174 0!=RTOp_reduct_obj_free(&op_,&obj_) 00175 ,UnknownError 00176 ,"RTOpC::reduct_obj_free(...): Error, " 00177 "RTOp_reduct_obj_free(...) returned != 0" 00178 ); 00179 } 00180 } 00181 00182 inline 00183 RTOp_ReductTarget& ReductTargetC::obj() 00184 { 00185 return obj_; 00186 } 00187 00188 inline 00189 const RTOp_ReductTarget& ReductTargetC::obj() const 00190 { 00191 return obj_; 00192 } 00193 00194 } // namespace RTOpPack 00195 00196 #endif // RTOPPACK_RTOP_NEW_C_HPP
1.7.4