MOOCHO (Single Doxygen Collection) Version of the Day
RTOp_ROp_fraction_to_boundary.c
Go to the documentation of this file.
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 // 
00005 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00006 //                  Copyright (2003) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00039 // 
00040 // ***********************************************************************
00041 // @HEADER
00042 */
00043 
00044 /* ///////////////////////////////////////////// */
00045 /* RTOp_ROp_fraction_to_boundary.c */
00046 
00047 /* */
00048 /* Note: This file was created automatically by 'new_rtop.pl' */
00049 /*       on 7/8/2002 at 18:22 */
00050 /* */
00051 
00052 #define max(a,b) ( (a) > (b) ? (a) : (b) )
00053 #define min(a,b) ( (a) < (b) ? (a) : (b) )
00054 
00055 #include "RTOp_ROp_fraction_to_boundary.h"
00056 #include "RTOp_obj_value_vtbl.h"  /* vtbl for operator object instance data */
00057 #include "RTOp_reduct_min_value.h"  /* Reduction of intermediate reduction objects */
00058 
00059 
00060 
00061 /* Implementation functions for RTOp_RTOp */
00062 
00063 static int RTOp_ROp_fraction_to_boundary_apply_op(
00064   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
00065   , const int num_vecs, const struct RTOp_SubVector vecs[]
00066   , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
00067   , RTOp_ReductTarget reduct_obj )
00068 {
00069   /* */
00070   /* Declare local variables */
00071   /* */
00072 
00073   /* Access to the operator object instance data */
00074   RTOp_value_type *tau = (RTOp_value_type*)obj_data;
00075   /* Access to the reduction object data */
00076   RTOp_value_type *alpha_max = (RTOp_value_type*)reduct_obj;
00077   /* Vector data */
00078   RTOp_index_type           sub_dim;
00079   /* v0 */
00080   const RTOp_value_type     *v0_val;
00081   ptrdiff_t                 v0_val_s;
00082   /* v1 */
00083   const RTOp_value_type     *v1_val;
00084   ptrdiff_t                 v1_val_s;
00085   /* v2 */
00086   const RTOp_value_type     *v2_val;
00087   ptrdiff_t                 v2_val_s;
00088   /* v3 */
00089   const RTOp_value_type     *v3_val;
00090   ptrdiff_t                 v3_val_s;
00091 
00092   /* Automatic temporary variables */
00093   register RTOp_index_type  k;
00094   /* Temporary element-wise reduction object */
00095   RTOp_value_type alpha_max_ith;
00096 
00097   /* */
00098   /* Validate the input */
00099   /* */
00100   if( num_vecs != 4 || ( num_vecs && vecs == NULL ) )
00101     return RTOp_ERR_INVALID_NUM_VECS;
00102   if( num_targ_vecs != 0 || ( num_targ_vecs && targ_vecs == NULL ) )
00103     return RTOp_ERR_INVALID_NUM_TARG_VECS;
00104   if( /* Validate sub_dim */
00105     vecs[1].sub_dim != vecs[0].sub_dim
00106     || vecs[2].sub_dim != vecs[0].sub_dim
00107     || vecs[3].sub_dim != vecs[0].sub_dim
00108     )
00109     return RTOp_ERR_INCOMPATIBLE_VECS;
00110   assert(obj_data);
00111   assert(reduct_obj);
00112 
00113 
00114   /* */
00115   /* Get pointers to data */
00116   /* */
00117   sub_dim       = vecs[0].sub_dim;
00118   /* v0 */
00119   v0_val        = vecs[0].values;
00120   v0_val_s      = vecs[0].values_stride;
00121   /* v1 */
00122   v1_val        = vecs[1].values;
00123   v1_val_s      = vecs[1].values_stride;
00124   /* v2 */
00125   v2_val        = vecs[2].values;
00126   v2_val_s      = vecs[2].values_stride;
00127   /* v3 */
00128   v3_val        = vecs[3].values;
00129   v3_val_s      = vecs[3].values_stride;
00130 
00131 
00132   /* */
00133   /* Apply the operator: */
00134   /* */
00135   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 )
00136   {
00137     /* Element-wise reduction */
00138     if ((*v1_val) < 0)
00139        { alpha_max_ith = (*tau)*((*v0_val)-(*v2_val))/(-(*v1_val)); }
00140     else
00141        { alpha_max_ith = (*tau)*((*v3_val)-(*v0_val))/((*v1_val)); }
00142 
00143     /* Reduction of intermediates */
00144     (*alpha_max) = min( (*alpha_max), alpha_max_ith );
00145   }
00146 
00147   return 0; /* success? */
00148 }
00149 
00150 static int RTOp_ROp_fraction_to_boundary_reduct_obj_reinit(
00151   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
00152   ,RTOp_ReductTarget reduct_obj
00153   )
00154 {
00155   RTOp_value_type *alpha_max = (RTOp_value_type*)reduct_obj;
00156   *alpha_max = 1.0;
00157   return 0;
00158 }
00159 
00160 /* Virtual function table */
00161 const struct RTOp_RTOp_vtbl_t RTOp_ROp_fraction_to_boundary_vtbl =
00162 {
00163   &RTOp_obj_value_vtbl
00164   ,&RTOp_obj_value_vtbl
00165   ,"ROp_fraction_to_boundary"
00166   ,RTOp_ROp_fraction_to_boundary_reduct_obj_reinit
00167   ,RTOp_ROp_fraction_to_boundary_apply_op
00168   ,RTOp_reduct_min_value
00169   ,RTOp_get_reduct_min_value_op
00170 };
00171 
00172 /* Class specific functions */
00173 
00174 int RTOp_ROp_fraction_to_boundary_construct( RTOp_value_type tau,  struct RTOp_RTOp* op )
00175 {
00176 #ifdef RTOp_DEBUG
00177   assert(op);
00178 #endif
00179   op->obj_data  = NULL;
00180   op->vtbl      = &RTOp_ROp_fraction_to_boundary_vtbl;
00181   op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data);
00182   return RTOp_ROp_fraction_to_boundary_init(tau,op);
00183 }
00184 
00185 int RTOp_ROp_fraction_to_boundary_destroy( struct RTOp_RTOp* op )
00186 {
00187   op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data);
00188   op->obj_data  = NULL;
00189   op->vtbl      = NULL;
00190   return 0;
00191 }
00192 
00193 int RTOp_ROp_fraction_to_boundary_init( RTOp_value_type tau, struct RTOp_RTOp* op )
00194 {
00195   RTOp_value_type *ptr_tau = (RTOp_value_type*)op->obj_data;
00196   *ptr_tau = tau;
00197   return 0;
00198 }
00199 RTOp_value_type RTOp_ROp_fraction_to_boundary_val(RTOp_ReductTarget reduct_obj)
00200 {
00201   return *((RTOp_value_type*)reduct_obj);
00202 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines