RTOp_TOp_correct_multipliers.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 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00026 // 
00027 // ***********************************************************************
00028 // @HEADER
00029 */
00030 /* ///////////////////////////////////////////// */
00031 /* RTOp_TOp_Correct_Multipliers.c */
00032 
00033 /* */
00034 /* Note: This file was created automatically by 'new_rtop.pl' */
00035 /*       on 7/1/2002 at 18:11 */
00036 /* */
00037 
00038 #define max(a,b) ( (a) > (b) ? (a) : (b) )
00039 #define min(a,b) ( (a) < (b) ? (a) : (b) )
00040 
00041 #include "RTOp_TOp_correct_multipliers.h"
00042 #include "RTOp_obj_value_index_vtbl.h"  /* vtbl for operator object instance data */
00043 
00044 
00045 
00046 /* Implementation functions for RTOp_RTOp */
00047 
00048 static int RTOp_TOp_Correct_Multipliers_apply_op(
00049   const struct RTOp_RTOp_vtbl_t* vtbl, const void* obj_data
00050   , const int num_vecs, const struct RTOp_SubVector vecs[]
00051   , const int num_targ_vecs, const struct RTOp_MutableSubVector targ_vecs[]
00052   , RTOp_ReductTarget reduct_obj )
00053 {
00054   /* */
00055   /* Declare local variables */
00056   /* */
00057 
00058   /* Access to the operator object instance data */
00059   struct RTOp_value_index_type *data_cntr = (struct RTOp_value_index_type*)obj_data;
00060   RTOp_value_type *inf_bound_limit = &data_cntr->value;
00061   RTOp_index_type *lower_or_upper = &data_cntr->index;
00062   /* Vector data */
00063   RTOp_index_type           sub_dim;
00064   /* z0 */
00065   RTOp_value_type           *z0_val;
00066   ptrdiff_t                 z0_val_s;
00067   /* v0 */
00068   const RTOp_value_type     *v0_val;
00069   ptrdiff_t                 v0_val_s;
00070 
00071   /* Automatic temporary variables */
00072   register RTOp_index_type  k;
00073 
00074   /* */
00075   /* Validate the input */
00076   /* */
00077   if( num_vecs != 1 || ( num_vecs && vecs == NULL ) )
00078     return RTOp_ERR_INVALID_NUM_VECS;
00079   if( num_targ_vecs != 1 || ( num_targ_vecs && targ_vecs == NULL ) )
00080     return RTOp_ERR_INVALID_NUM_TARG_VECS;
00081   if( /* Validate sub_dim */
00082     targ_vecs[0].sub_dim != vecs[0].sub_dim
00083     )
00084     return RTOp_ERR_INCOMPATIBLE_VECS;
00085   assert(obj_data);
00086 
00087 
00088   /* */
00089   /* Get pointers to data */
00090   /* */
00091   sub_dim       = vecs[0].sub_dim;
00092   /* z0 */
00093   z0_val        = targ_vecs[0].values;
00094   z0_val_s      = targ_vecs[0].values_stride;
00095   /* v0 */
00096   v0_val        = vecs[0].values;
00097   v0_val_s      = vecs[0].values_stride;
00098 
00099 
00100   /* */
00101   /* Apply the operator: */
00102   /* */
00103   for( k = 0; k < sub_dim; ++k, v0_val += v0_val_s, z0_val += z0_val_s )
00104     {
00105     /* Element-wise transformation */
00106     if ( (*z0_val) < 0 )
00107       {
00108       /* should only get here if the value is slightly negative */
00109       assert(*z0_val > -1e-50);
00110       (*z0_val) = 0.0;
00111       }
00112       else if ( (*lower_or_upper) == 0 )
00113         {
00114       (*z0_val) = ((*v0_val) <= (*inf_bound_limit)) ? 0.0 : (*z0_val);
00115       }
00116       else
00117         {
00118       (*z0_val) = ((*v0_val) >= (*inf_bound_limit)) ? 0.0 : (*z0_val);
00119       }
00120         }
00121 
00122   return 0; /* success? */
00123 }
00124 
00125 /* Virtual function table */
00126 const struct RTOp_RTOp_vtbl_t RTOp_TOp_Correct_Multipliers_vtbl =
00127 {
00128   &RTOp_obj_value_index_vtbl
00129   ,&RTOp_obj_null_vtbl
00130   ,"TOp_Correct_Multipliers"
00131   ,NULL
00132   ,RTOp_TOp_Correct_Multipliers_apply_op
00133   ,NULL
00134   ,NULL
00135 };
00136 
00137 /* Class specific functions */
00138 
00139 int RTOp_TOp_Correct_Multipliers_construct( RTOp_value_type inf_bound_limit, RTOp_index_type lower_or_upper,  struct RTOp_RTOp* op )
00140 {
00141 #ifdef RTOp_DEBUG
00142   assert(op);
00143 #endif
00144   op->obj_data  = NULL;
00145   op->vtbl      = &RTOp_TOp_Correct_Multipliers_vtbl;
00146   op->vtbl->obj_data_vtbl->obj_create(NULL,NULL,&op->obj_data);
00147   return RTOp_TOp_Correct_Multipliers_init(inf_bound_limit,lower_or_upper,op);
00148 }
00149 
00150 int RTOp_TOp_Correct_Multipliers_destroy( struct RTOp_RTOp* op )
00151 {
00152   op->vtbl->obj_data_vtbl->obj_free(NULL,NULL,&op->obj_data);
00153   op->obj_data  = NULL;
00154   op->vtbl      = NULL;
00155   return 0;
00156 }
00157 
00158 int RTOp_TOp_Correct_Multipliers_init( RTOp_value_type inf_bound_limit, RTOp_index_type lower_or_upper, struct RTOp_RTOp* op )
00159 {
00160   struct RTOp_value_index_type *ptr_data_cntr = (struct RTOp_value_index_type*)op->obj_data;
00161   RTOp_value_type *ptr_inf_bound_limit = &ptr_data_cntr->value;
00162   RTOp_index_type *ptr_lower_or_upper = &ptr_data_cntr->index;
00163   *ptr_inf_bound_limit = inf_bound_limit;
00164   *ptr_lower_or_upper = lower_or_upper;
00165   return 0;
00166 }
00167 

Generated on Tue Jul 13 09:30:54 2010 for MOOCHO (Single Doxygen Collection) by  doxygen 1.4.7