|
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 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 // /////////////////////////////// 00043 // RTOpPack_RTOpC.hpp 00044 00045 #ifndef RTOPPACK_RTOP_NEW_C_HPP 00046 #define RTOPPACK_RTOP_NEW_C_HPP 00047 00048 #include "RTOpPack_OldTypes.hpp" 00049 #include "RTOpPack_RTOpT.hpp" 00050 #include "RTOp.h" 00051 #include "Teuchos_dyn_cast.hpp" 00052 00053 namespace RTOpPack { 00054 00059 class RTOpC : public RTOpT<RTOp_value_type> { 00060 public: 00061 00063 typedef RTOp_value_type Scalar; 00065 RTOpC(); 00067 ~RTOpC(); 00069 RTOp_RTOp& op(); 00071 const RTOp_RTOp& op() const; 00073 RTOp_ReductTarget& operator()(ReductTarget& reduct_obj) const; 00075 const RTOp_ReductTarget& operator()(const ReductTarget& reduct_obj) const; 00076 00079 00081 void get_reduct_type_num_entries_impl( 00082 const Teuchos::Ptr<int> &num_values, 00083 const Teuchos::Ptr<int> &num_indexes, 00084 const Teuchos::Ptr<int> &num_chars 00085 ) const; 00087 Teuchos::RCP<ReductTarget> reduct_obj_create_impl() const; 00089 void reduce_reduct_objs_impl( 00090 const ReductTarget &in_reduct_obj, 00091 const Teuchos::Ptr<ReductTarget> &inout_reduct_obj 00092 ) const; 00094 void reduct_obj_reinit_impl( 00095 const Teuchos::Ptr<ReductTarget> &reduct_obj 00096 ) const; 00098 void extract_reduct_obj_state_impl( 00099 const ReductTarget &reduct_obj, 00100 const Teuchos::ArrayView<primitive_value_type> &value_data, 00101 const Teuchos::ArrayView<index_type> &index_data, 00102 const Teuchos::ArrayView<char_type> &char_data 00103 ) const; 00105 void load_reduct_obj_state_impl( 00106 const Teuchos::ArrayView<const primitive_value_type> &value_data, 00107 const Teuchos::ArrayView<const index_type> &index_data, 00108 const Teuchos::ArrayView<const char_type> &char_data, 00109 const Teuchos::Ptr<ReductTarget> &reduct_obj 00110 ) const; 00112 bool coord_invariant_impl() const; 00114 std::string op_name_impl() const; 00116 void apply_op_impl( 00117 const Teuchos::ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs, 00118 const Teuchos::ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs, 00119 const Teuchos::Ptr<ReductTarget> &reduct_obj 00120 ) const; 00121 00123 00124 private: 00125 00126 RTOp_RTOp op_; 00127 00128 }; // class RTOpC 00129 00132 class ReductTargetC : public ReductTarget { 00133 public: 00134 inline ReductTargetC( const RTOp_RTOp& op, RTOp_ReductTarget obj ); 00135 inline ~ReductTargetC(); 00136 inline RTOp_ReductTarget& obj(); 00137 inline const RTOp_ReductTarget& obj() const; 00138 private: 00139 const RTOp_RTOp &op_; 00140 RTOp_ReductTarget obj_; 00141 ReductTargetC(); // Not defined and not to be called 00142 }; 00143 00144 // /////////////////////////////// 00145 // Inline member functions 00146 00147 // RTOpC 00148 00149 inline 00150 RTOp_RTOp& RTOpC::op() 00151 { 00152 return op_; 00153 } 00154 00155 inline 00156 const RTOp_RTOp& RTOpC::op() const 00157 { 00158 return op_; 00159 } 00160 00161 inline 00162 RTOp_ReductTarget& 00163 RTOpC::operator()(ReductTarget& reduct_obj) const 00164 { 00165 return Teuchos::dyn_cast<ReductTargetC>(reduct_obj).obj(); 00166 } 00167 00168 inline 00169 const RTOp_ReductTarget& 00170 RTOpC::operator()(const ReductTarget& reduct_obj) const 00171 { 00172 return Teuchos::dyn_cast<const ReductTargetC>(reduct_obj).obj(); 00173 } 00174 00175 // ReductTargetC 00176 00177 inline 00178 ReductTargetC::ReductTargetC( const RTOp_RTOp& op, RTOp_ReductTarget obj ) 00179 : op_(op), obj_(obj) 00180 {} 00181 00182 inline 00183 ReductTargetC::~ReductTargetC() 00184 { 00185 if( obj() != RTOp_REDUCT_OBJ_NULL ) { 00186 TEUCHOS_TEST_FOR_EXCEPTION( 00187 0!=RTOp_reduct_obj_free(&op_,&obj_) 00188 ,UnknownError 00189 ,"RTOpC::reduct_obj_free(...): Error, " 00190 "RTOp_reduct_obj_free(...) returned != 0" 00191 ); 00192 } 00193 } 00194 00195 inline 00196 RTOp_ReductTarget& ReductTargetC::obj() 00197 { 00198 return obj_; 00199 } 00200 00201 inline 00202 const RTOp_ReductTarget& ReductTargetC::obj() const 00203 { 00204 return obj_; 00205 } 00206 00207 } // namespace RTOpPack 00208 00209 #endif // RTOPPACK_RTOP_NEW_C_HPP
1.7.6.1