MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RTOp_ROp_comp_err_with_mu.c
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
6 // Copyright (2003) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 #include <math.h>
45 
46 /* ///////////////////////////////////////////// */
47 /* RTOp_ROp_comp_err_with_mu.c */
48 
49 /* */
50 /* Note: This file was created automatically by 'new_rtop.pl' */
51 /* on 7/24/2002 at 23:46 */
52 /* */
53 
54 #define max(a,b) ( (a) > (b) ? (a) : (b) )
55 #define min(a,b) ( (a) < (b) ? (a) : (b) )
56 
58 #include "RTOp_obj_value_value_vtbl.h" /* vtbl for operator object instance data */
59 #include "RTOp_reduct_max_value.h"
60 
61 
62 /* Implementation functions for RTOp_RTOp */
63 
65  const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
66  , const int num_vecs, const struct RTOp_SubVector vecs[]
67  , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
68  , RTOp_ReductTarget reduct_obj )
69 {
70  /* */
71  /* Declare local variables */
72  /* */
73 
74  /* Access to the operator object instance data */
75  struct RTOp_value_value_type *data_cntr = (struct RTOp_value_value_type*)obj_data;
76  RTOp_value_type *mu = &data_cntr->value1;
77  RTOp_value_type *inf_bound = &data_cntr->value2;
78  /* Access to the reduction object data */
79  RTOp_value_type *comp_err = (RTOp_value_type*)reduct_obj;
80  /* Vector data */
81  RTOp_index_type sub_dim;
82  /* v0 */
83  const RTOp_value_type *v0_val;
84  ptrdiff_t v0_val_s;
85  /* v1 */
86  const RTOp_value_type *v1_val;
87  ptrdiff_t v1_val_s;
88  /* v2 */
89  const RTOp_value_type *v2_val;
90  ptrdiff_t v2_val_s;
91  /* v3 */
92  const RTOp_value_type *v3_val;
93  ptrdiff_t v3_val_s;
94  /* v4 */
95  const RTOp_value_type *v4_val;
96  ptrdiff_t v4_val_s;
97 
98  /* Automatic temporary variables */
99  register RTOp_index_type k;
100  /* Temporary element-wise reduction object */
101  RTOp_value_type comp_err_ith;
102 
103  /* */
104  /* Validate the input */
105  /* */
106  if( num_vecs != 5 || ( num_vecs && vecs == NULL ) )
108  if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
110  if( /* Validate sub_dim */
111  vecs[1].sub_dim != vecs[0].sub_dim
112  || vecs[2].sub_dim != vecs[0].sub_dim
113  || vecs[3].sub_dim != vecs[0].sub_dim
114  || vecs[4].sub_dim != vecs[0].sub_dim
115  )
117  assert(obj_data);
118  assert(reduct_obj);
119 
120 
121  /* */
122  /* Get pointers to data */
123  /* */
124  sub_dim = vecs[0].sub_dim;
125  /* v0 */
126  v0_val = vecs[0].values;
127  v0_val_s = vecs[0].values_stride;
128  /* v1 */
129  v1_val = vecs[1].values;
130  v1_val_s = vecs[1].values_stride;
131  /* v2 */
132  v2_val = vecs[2].values;
133  v2_val_s = vecs[2].values_stride;
134  /* v3 */
135  v3_val = vecs[3].values;
136  v3_val_s = vecs[3].values_stride;
137  /* v4 */
138  v4_val = vecs[4].values;
139  v4_val_s = vecs[4].values_stride;
140 
141 
142  /* */
143  /* Apply the operator: */
144  /* */
145  for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, v1_val += v1_val_s, v2_val += v2_val_s, v3_val += v3_val_s, v4_val += v4_val_s )
146  {
147  /* Element-wise reduction */
148  comp_err_ith = 0;
149  if ((*v1_val) > -(*inf_bound))
150  { comp_err_ith = fabs((*v3_val)*((*v0_val)-(*v1_val))-(*mu)); }
151 
152  if ((*v2_val) < (*inf_bound))
153  { comp_err_ith = max(comp_err_ith, fabs((*v4_val)*((*v2_val)-(*v0_val))-(*mu))); }
154 
155  /* Reduction of intermediates */
156  (*comp_err) = max( (*comp_err), comp_err_ith );
157  }
158 
159  return 0; /* success? */
160 }
161 
162 /* Virtual function table */
164 {
167  ,"ROp_comp_err_with_mu"
168  ,NULL
172 };
173 
174 /* Class specific functions */
175 
177 {
178 #ifdef RTOp_DEBUG
179  assert(op);
180 #endif
181  op->obj_data = NULL;
183  op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data);
184  return RTOp_ROp_comp_err_with_mu_init(mu,inf_bound,op);
185 }
186 
188 {
189  op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data);
190  op->obj_data = NULL;
191  op->vtbl = NULL;
192  return 0;
193 }
194 
196 {
197  struct RTOp_value_value_type *ptr_data_cntr = (struct RTOp_value_value_type*)op->obj_data;
198  RTOp_value_type *ptr_mu = &ptr_data_cntr->value1;
199  RTOp_value_type *ptr_inf_bound = &ptr_data_cntr->value2;
200  *ptr_mu = mu;
201  *ptr_inf_bound = inf_bound;
202  return 0;
203 }
205 {
206  return *((RTOp_value_type*)reduct_obj);
207 }
208 
int RTOp_ROp_comp_err_with_mu_construct(RTOp_value_type mu, RTOp_value_type inf_bound, struct RTOp_RTOp *op)
ptrdiff_t values_stride
Definition: RTOp.h:305
double RTOp_value_type
Definition: RTOp.h:69
void * RTOp_ReductTarget
Definition: RTOp.h:191
#define max(a, b)
int RTOp_ROp_comp_err_with_mu_init(RTOp_value_type mu, RTOp_value_type inf_bound, struct RTOp_RTOp *op)
int(* obj_create)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void **obj)
Definition: RTOp.h:941
const struct RTOp_obj_type_vtbl_t RTOp_obj_value_value_vtbl
const struct RTOp_obj_type_vtbl_t * obj_data_vtbl
Definition: RTOp.h:819
const struct RTOp_RTOp_vtbl_t RTOp_ROp_comp_err_with_mu_vtbl
#define RTOp_ERR_INCOMPATIBLE_VECS
Definition: RTOp.h:270
const RTOp_value_type * values
Definition: RTOp.h:303
int RTOp_get_reduct_max_value_op(const struct RTOp_RTOp_vtbl_t *vtbl, const void *obj_data, RTOp_reduct_op_func_ptr_t *reduct_op_func_ptr)
#define RTOp_ERR_INVALID_NUM_VECS
Definition: RTOp.h:266
int(* obj_free)(const struct RTOp_obj_type_vtbl_t *vtbl, const void *instance_data, void **obj)
Definition: RTOp.h:1019
void * obj_data
Definition: RTOp.h:800
const struct RTOp_RTOp_vtbl_t * vtbl
Definition: RTOp.h:802
static int RTOp_ROp_comp_err_with_mu_apply_op(const struct RTOp_RTOp_vtbl_t *vtbl, const void *obj_data, const int num_vecs, const struct RTOp_SubVector vecs[], const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[], RTOp_ReductTarget reduct_obj)
int RTOp_reduct_max_value(const struct RTOp_RTOp_vtbl_t *vtbl, const void *obj_data, RTOp_ReductTarget in_targ_obj, RTOp_ReductTarget inout_targ_obj)
int RTOp_ROp_comp_err_with_mu_destroy(struct RTOp_RTOp *op)
RTOp_index_type sub_dim
Definition: RTOp.h:301
RTOp_value_type RTOp_ROp_comp_err_with_mu_val(RTOp_ReductTarget reduct_obj)
#define RTOp_ERR_INVALID_NUM_TARG_VECS
Definition: RTOp.h:268
const struct RTOp_obj_type_vtbl_t RTOp_obj_value_vtbl
Teuchos_Ordinal RTOp_index_type
Definition: RTOp.h:68