RTOpPack: Extra C/C++ Code for Vector Reduction/Transformation Operators  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
RTOpPack_RTOpC.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 // ///////////////////////////////
43 // RTOpPack_RTOpC.hpp
44 
45 #ifndef RTOPPACK_RTOP_NEW_C_HPP
46 #define RTOPPACK_RTOP_NEW_C_HPP
47 
48 #include "RTOpPack_OldTypes.hpp"
49 #include "RTOpPack_RTOpT.hpp"
50 #include "RTOp.h"
51 #include "Teuchos_dyn_cast.hpp"
52 
53 namespace RTOpPack {
54 
59 class RTOpC : public RTOpT<RTOp_value_type> {
60 public:
61 
63  typedef RTOp_value_type Scalar;
65  RTOpC();
67  ~RTOpC();
69  RTOp_RTOp& op();
71  const RTOp_RTOp& op() const;
73  RTOp_ReductTarget& operator()(ReductTarget& reduct_obj) const;
75  const RTOp_ReductTarget& operator()(const ReductTarget& reduct_obj) const;
76 
79 
82  const Teuchos::Ptr<int> &num_values,
83  const Teuchos::Ptr<int> &num_indexes,
84  const Teuchos::Ptr<int> &num_chars
85  ) const;
90  const ReductTarget &in_reduct_obj,
91  const Teuchos::Ptr<ReductTarget> &inout_reduct_obj
92  ) const;
95  const Teuchos::Ptr<ReductTarget> &reduct_obj
96  ) const;
99  const ReductTarget &reduct_obj,
101  const Teuchos::ArrayView<index_type> &index_data,
102  const Teuchos::ArrayView<char_type> &char_data
103  ) const;
107  const Teuchos::ArrayView<const index_type> &index_data,
108  const Teuchos::ArrayView<const char_type> &char_data,
109  const Teuchos::Ptr<ReductTarget> &reduct_obj
110  ) const;
112  bool coord_invariant_impl() const;
114  std::string op_name_impl() const;
116  void apply_op_impl(
117  const Teuchos::ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
118  const Teuchos::ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
119  const Teuchos::Ptr<ReductTarget> &reduct_obj
120  ) const;
121 
123 
124 private:
125 
126  RTOp_RTOp op_;
127 
128 }; // class RTOpC
129 
132 class ReductTargetC : public ReductTarget {
133 public:
134  inline ReductTargetC( const RTOp_RTOp& op, RTOp_ReductTarget obj );
135  inline ~ReductTargetC();
136  inline RTOp_ReductTarget& obj();
137  inline const RTOp_ReductTarget& obj() const;
138 private:
139  const RTOp_RTOp &op_;
140  RTOp_ReductTarget obj_;
141  ReductTargetC(); // Not defined and not to be called
142 };
143 
144 // ///////////////////////////////
145 // Inline member functions
146 
147 // RTOpC
148 
149 inline
151 {
152  return op_;
153 }
154 
155 inline
156 const RTOp_RTOp& RTOpC::op() const
157 {
158  return op_;
159 }
160 
161 inline
162 RTOp_ReductTarget&
163 RTOpC::operator()(ReductTarget& reduct_obj) const
164 {
165  return Teuchos::dyn_cast<ReductTargetC>(reduct_obj).obj();
166 }
167 
168 inline
169 const RTOp_ReductTarget&
170 RTOpC::operator()(const ReductTarget& reduct_obj) const
171 {
172  return Teuchos::dyn_cast<const ReductTargetC>(reduct_obj).obj();
173 }
174 
175 // ReductTargetC
176 
177 inline
178 ReductTargetC::ReductTargetC( const RTOp_RTOp& op, RTOp_ReductTarget obj )
179  : op_(op), obj_(obj)
180 {}
181 
182 inline
183 ReductTargetC::~ReductTargetC()
184 {
185  if( obj() != RTOp_REDUCT_OBJ_NULL ) {
187  0!=RTOp_reduct_obj_free(&op_,&obj_)
188  ,UnknownError
189  ,"RTOpC::reduct_obj_free(...): Error, "
190  "RTOp_reduct_obj_free(...) returned != 0"
191  );
192  }
193 }
194 
195 inline
196 RTOp_ReductTarget& ReductTargetC::obj()
197 {
198  return obj_;
199 }
200 
201 inline
202 const RTOp_ReductTarget& ReductTargetC::obj() const
203 {
204  return obj_;
205 }
206 
207 } // namespace RTOpPack
208 
209 #endif // RTOPPACK_RTOP_NEW_C_HPP
Adapter subclass that uses a RTOp_RTOp object.
std::string op_name_impl() const
Teuchos::RCP< ReductTarget > reduct_obj_create_impl() const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void get_reduct_type_num_entries_impl(const Teuchos::Ptr< int > &num_values, const Teuchos::Ptr< int > &num_indexes, const Teuchos::Ptr< int > &num_chars) const
void extract_reduct_obj_state_impl(const ReductTarget &reduct_obj, const Teuchos::ArrayView< primitive_value_type > &value_data, const Teuchos::ArrayView< index_type > &index_data, const Teuchos::ArrayView< char_type > &char_data) const
T_To & dyn_cast(T_From &from)
void apply_op_impl(const Teuchos::ArrayView< const ConstSubVectorView< Scalar > > &sub_vecs, const Teuchos::ArrayView< const SubVectorView< Scalar > > &targ_sub_vecs, const Teuchos::Ptr< ReductTarget > &reduct_obj) const
RTOp_ReductTarget & operator()(ReductTarget &reduct_obj) const
bool coord_invariant_impl() const
int RTOp_reduct_obj_free(const struct RTOp_RTOp *op, RTOp_ReductTarget *reduct_obj)
Definition: RTOp.c:267
void reduce_reduct_objs_impl(const ReductTarget &in_reduct_obj, const Teuchos::Ptr< ReductTarget > &inout_reduct_obj) const
RTOp_RTOp & op()
RTOp_value_type Scalar
Adapter subclass for RTOp_ReductTarget
void reduct_obj_reinit_impl(const Teuchos::Ptr< ReductTarget > &reduct_obj) const
void load_reduct_obj_state_impl(const Teuchos::ArrayView< const primitive_value_type > &value_data, const Teuchos::ArrayView< const index_type > &index_data, const Teuchos::ArrayView< const char_type > &char_data, const Teuchos::Ptr< ReductTarget > &reduct_obj) const