MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RTOpPack_RTOpC.cpp
Go to the documentation of this file.
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.cpp
44 
45 #include "RTOpPack_RTOpC.hpp"
46 #include "Teuchos_Workspace.hpp"
47 
48 
49 namespace RTOpPack {
50 
51 
53  :RTOpT<RTOp_value_type>("RTOpC") // Should be unused since op_name() if overridden here!
54 {
55  op_.vtbl = NULL;
56  op_.obj_data = NULL;
57 }
58 
59 
61 {
62  if(op_.obj_data)
63  RTOp_free_op( &op_ );
64 }
65 
66 
67 // Overridden from RTOpT
68 
69 
71  const Teuchos::Ptr<int> &num_values,
72  const Teuchos::Ptr<int> &num_indexes,
73  const Teuchos::Ptr<int> &num_chars
74  ) const
75 {
77  0!=RTOp_get_reduct_type_num_entries(&op_,&*num_values,&*num_indexes,&*num_chars)
78  ,UnknownError
79  ,"RTOpC::get_reduct_type_num_entries(...): Error, "
80  "RTOp_get_reduct_type_num_entries(...) returned != 0"
81  );
82 }
83 
84 
87 {
88  RTOp_ReductTarget reduct_obj_raw = RTOp_REDUCT_OBJ_NULL;
90  0!=RTOp_reduct_obj_create(&op_,&reduct_obj_raw)
91  ,UnknownError
92  ,"RTOpC::reduct_obj_create(...): Error, "
93  "RTOp_reduct_obj_create(...) returned != 0"
94  );
95  return Teuchos::rcp(new ReductTargetC(op_,reduct_obj_raw));
96 }
97 
98 
100  const ReductTarget &in_reduct_obj,
101  const Teuchos::Ptr<ReductTarget> &inout_reduct_obj
102  ) const
103 {
105  0!=RTOp_reduce_reduct_objs( &op_, (*this)(in_reduct_obj), (*this)(*inout_reduct_obj) )
106  ,UnknownError
107  ,"RTOpC::reduce_reduct_objs(...): Error, "
108  "RTOp_reduce_reduct_objs(...) returned != 0"
109  );
110 }
111 
112 
114  const Teuchos::Ptr<ReductTarget> &reduct_obj ) const
115 {
117  0!=RTOp_reduct_obj_reinit( &op_, (*this)(*reduct_obj) )
118  ,UnknownError
119  ,"RTOpC::reduct_obj_reinit(...): Error, "
120  "RTOp_reduct_obj_reinit(...) returned != 0"
121  );
122 }
123 
124 
126  const ReductTarget &reduct_obj,
128  const Teuchos::ArrayView<index_type> &index_data,
129  const Teuchos::ArrayView<char_type> &char_data
130  ) const
131 {
134  &op_, (*this)(reduct_obj),
135  value_data.size(), value_data.getRawPtr(),
136  index_data.size(), index_data.getRawPtr(),
137  char_data.size(), char_data.getRawPtr()
138  ),
139  UnknownError,
140  "RTOpC::extract_reduct_obj_state(...): Error, "
141  "RTOp_extract_reduct_obj_state(...) returned != 0"
142  );
143 }
144 
145 
148  const Teuchos::ArrayView<const index_type> &index_data,
149  const Teuchos::ArrayView<const char_type> &char_data,
150  const Teuchos::Ptr<ReductTarget> &reduct_obj
151  ) const
152 {
155  &op_,
156  value_data.size(), value_data.getRawPtr(),
157  index_data.size(), index_data.getRawPtr(),
158  char_data.size(), char_data.getRawPtr(),
159  (*this)(*reduct_obj)
160  ),
161  UnknownError,
162  "RTOpC::load_reduct_obj_state(...): Error, "
163  "RTOp_load_reduct_obj_state(...) returned != 0"
164  );
165 }
166 
167 
169 {
170  return false; // We have to assume this to be safe!
171 }
172 
173 
174 std::string RTOpC::op_name_impl() const
175 {
176  const char* op_name = NULL;
178  0!=RTOp_get_op_name(&op_,&op_name)
179  ,UnknownError
180  ,"RTOpC::get_op_name(...): Error, "
181  "RTOp_op_name(...) returned != 0"
182  );
183  return op_name;
184 }
185 
186 
188  const Teuchos::ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
189  const Teuchos::ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
190  const Teuchos::Ptr<ReductTarget> &_reduct_obj
191  ) const
192 {
193 
194  using Teuchos::Workspace;
197 
198  const int num_vecs = sub_vecs.size();
199  const int num_targ_vecs = targ_sub_vecs.size();
200 
202  if(!is_null(_reduct_obj))
203  reduct_obj = (*this)(*_reduct_obj);
204 
205  int k;
206  Workspace<RTOp_SubVector> c_sub_vecs(wss,num_vecs,false);
207  for( k = 0; k < num_vecs; ++k ) {
208  const SubVector& v = sub_vecs[k];
209  RTOp_sub_vector(v.globalOffset(),v.subDim(),v.values(),v.stride(),&c_sub_vecs[k]);
210  }
211  Workspace<RTOp_MutableSubVector> c_targ_sub_vecs(wss,num_targ_vecs,false);
212  for( k = 0; k < num_targ_vecs; ++k ) {
213  const MutableSubVector& v = targ_sub_vecs[k];
214  RTOp_mutable_sub_vector(v.globalOffset(),v.subDim(),v.values(),v.stride(),&c_targ_sub_vecs[k]);
215  }
216 
217  const int err = RTOp_apply_op(
218  &op_
219  ,num_vecs, num_vecs ? &c_sub_vecs[0] : (RTOp_SubVector*)NULL
220  ,num_targ_vecs, num_targ_vecs ? &c_targ_sub_vecs[0] : (RTOp_MutableSubVector*)NULL
221  ,reduct_obj
222  );
224  err==RTOp_ERR_INVALID_NUM_VECS, InvalidNumVecs
225  ,"RTOpC::apply_op(...): Error, "
226  "RTOp_apply_op(...) returned RTOp_ERR_INVALID_NUM_VECS" );
228  err==RTOp_ERR_INVALID_NUM_TARG_VECS, InvalidNumTargVecs
229  ,"RTOpC::apply_op(...): Error, "
230  "RTOp_apply_op(...) returned RTOp_ERR_INVALID_NUM_TARG_VECS" );
232  err!=0, UnknownError
233  ,"RTOpC::apply_op(...): Error, "
234  "RTOp_apply_op(...) returned != 0 with unknown meaning" );
235 
236 }
237 
238 
239 } // namespace RTOpPack
int RTOp_get_reduct_type_num_entries(const struct RTOp_RTOp *op, int *num_values, int *num_indexes, int *num_chars)
Definition: RTOp.c:209
double RTOp_value_type
Definition: RTOp.h:69
bool is_null(const boost::shared_ptr< T > &p)
ptrdiff_t stride() const
void * RTOp_ReductTarget
Definition: RTOp.h:191
int RTOp_load_reduct_obj_state(const struct RTOp_RTOp *op, int num_values, const RTOp_value_type value_data[], int num_indexes, const RTOp_index_type index_data[], int num_chars, const RTOp_char_type char_data[], RTOp_ReductTarget reduct_obj)
Definition: RTOp.c:307
std::string op_name_impl() const
Teuchos::RCP< ReductTarget > reduct_obj_create_impl() const
int RTOp_reduct_obj_create(const struct RTOp_RTOp *op, RTOp_ReductTarget *reduct_obj)
Definition: RTOp.c:230
void RTOp_mutable_sub_vector(RTOp_index_type global_offset, RTOp_index_type sub_dim, RTOp_value_type values[], ptrdiff_t values_stride, struct RTOp_MutableSubVector *sub_vec)
Definition: RTOp.c:77
int RTOp_reduce_reduct_objs(const struct RTOp_RTOp *op, RTOp_ReductTarget in_reduct_obj, RTOp_ReductTarget inout_reduct_obj)
Definition: RTOp.c:374
#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
const Scalar * values() const
size_type size() const
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
bool coord_invariant_impl() const
int RTOp_extract_reduct_obj_state(const struct RTOp_RTOp *op, const RTOp_ReductTarget reduct_obj, int num_values, RTOp_value_type value_data[], int num_indexes, RTOp_index_type index_data[], int num_chars, RTOp_char_type char_data[])
Definition: RTOp.c:280
void RTOp_sub_vector(RTOp_index_type global_offset, RTOp_index_type sub_dim, const RTOp_value_type values[], ptrdiff_t values_stride, struct RTOp_SubVector *sub_vec)
Definition: RTOp.c:52
int RTOp_get_op_name(const struct RTOp_RTOp *op, const char **op_name)
Definition: RTOp.c:108
int RTOp_apply_op(const struct RTOp_RTOp *op, const int num_vecs, const struct RTOp_SubVector sub_vecs[], const int num_targ_vecs, const struct RTOp_MutableSubVector targ_sub_vecs[], RTOp_ReductTarget reduct_obj)
Definition: RTOp.c:357
void reduce_reduct_objs_impl(const ReductTarget &in_reduct_obj, const Teuchos::Ptr< ReductTarget > &inout_reduct_obj) const
int RTOp_free_op(struct RTOp_RTOp *op)
Definition: RTOp.c:197
#define RTOp_ERR_INVALID_NUM_VECS
Definition: RTOp.h:266
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos_Ordinal subDim() const
T * getRawPtr() const
Teuchos_Ordinal globalOffset() const
void * obj_data
Definition: RTOp.h:800
const struct RTOp_RTOp_vtbl_t * vtbl
Definition: RTOp.h:802
Adapter subclass for RTOp_ReductTarget
void reduct_obj_reinit_impl(const Teuchos::Ptr< ReductTarget > &reduct_obj) const
Class for a mutable sub-vector.
int RTOp_reduct_obj_reinit(const struct RTOp_RTOp *op, RTOp_ReductTarget reduct_obj)
Definition: RTOp.c:249
#define RTOp_ERR_INVALID_NUM_TARG_VECS
Definition: RTOp.h:268
Class for a non-mutable sub-vector.
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()
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
#define RTOp_REDUCT_OBJ_NULL
Definition: RTOp.h:192