EpetraExt Development
EpetraExt_ModelEvaluator.cpp
Go to the documentation of this file.
00001 //@HEADER
00002 // ***********************************************************************
00003 //
00004 //     EpetraExt: Epetra Extended - Linear Algebra Services Package
00005 //                 Copyright (2011) Sandia Corporation
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 
00042 #include "EpetraExt_ModelEvaluator.h"
00043 #include "Teuchos_implicit_cast.hpp"
00044 
00045 
00046 namespace EpetraExt {
00047 
00048 
00049 //
00050 // ModelEvaluator::InArgs
00051 //
00052 
00053 
00054 ModelEvaluator::InArgs::InArgs()
00055   :modelEvalDescription_("WARNING!  THIS INARGS OBJECT IS UNINITALIZED!")
00056 {
00057   std::fill_n(&supports_[0],NUM_E_IN_ARGS_MEMBERS,false);
00058   t_     = 0.0;
00059   alpha_ = 0.0;
00060   beta_  = 0.0;
00061 }
00062 
00063 
00064 bool ModelEvaluator::InArgs::supports(EInArgsMembers arg) const
00065 {
00066   TEST_FOR_EXCEPTION(
00067     int(arg)>=NUM_E_IN_ARGS_MEMBERS || int(arg) < 0,std::logic_error
00068     ,"model = \'"<<modelEvalDescription_<<"\': Error, arg="<<toString(arg)<<" is invalid!"
00069     );
00070   return supports_[arg];
00071 }
00072 
00073 bool ModelEvaluator::InArgs::supports(EInArgs_p_sg arg, int l) const
00074 {
00075   assert_l(l);
00076   return supports_p_sg_[l];
00077 }
00078 
00079 bool ModelEvaluator::InArgs::supports(EInArgs_p_mp arg, int l) const
00080 {
00081   assert_l(l);
00082   return supports_p_mp_[l];
00083 }
00084 
00085 void ModelEvaluator::InArgs::_setSupports( EInArgsMembers arg, bool supports )
00086 {
00087   TEST_FOR_EXCEPTION(
00088     int(arg)>=NUM_E_IN_ARGS_MEMBERS || int(arg) < 0,std::logic_error
00089     ,"model = \'"<<modelEvalDescription_<<"\':Error, arg="<<toString(arg)<<" is invalid!"
00090     );
00091   supports_[arg] = supports;
00092 }
00093 
00094 void ModelEvaluator::InArgs::_setSupports(EInArgs_p_sg arg, int l, bool supports)
00095 {
00096   assert_l(l);
00097   supports_p_sg_[l] = supports;
00098 }
00099 
00100 void ModelEvaluator::InArgs::_setSupports(EInArgs_p_mp arg, int l, bool supports)
00101 {
00102   assert_l(l);
00103   supports_p_mp_[l] = supports;
00104 }
00105 
00106 
00107 void ModelEvaluator::InArgs::assert_supports(EInArgsMembers arg) const
00108 {
00109   TEST_FOR_EXCEPTION(
00110     !supports_[arg], std::logic_error
00111     ,"EpetraExt::ModelEvaluator::InArgs::assert_supports(arg): model = \'"<<modelEvalDescription_<<"\': Error, "
00112     "The argument arg = " << toString(arg) << " is not supported!"
00113     );
00114 }
00115 
00116 void ModelEvaluator::InArgs::assert_supports(EInArgs_p_sg arg, int l) const
00117 {
00118   assert_l(l);
00119   TEST_FOR_EXCEPTION(
00120     !supports_p_sg_[l], std::logic_error
00121     ,"EpetraExt::ModelEvaluator::InArgs::assert_supports(IN_ARG_p_sg,l): "
00122     "model = \'"<<modelEvalDescription_<<"\': Error,"
00123     "The argument p_sg(l) with index l = " << l << " is not supported!"
00124     );
00125 }
00126 
00127 void ModelEvaluator::InArgs::assert_supports(EInArgs_p_mp arg, int l) const
00128 {
00129   assert_l(l);
00130   TEST_FOR_EXCEPTION(
00131     !supports_p_mp_[l], std::logic_error
00132     ,"EpetraExt::ModelEvaluator::InArgs::assert_supports(IN_ARG_p_mp,l): "
00133     "model = \'"<<modelEvalDescription_<<"\': Error,"
00134     "The argument p_mp(l) with index l = " << l << " is not supported!"
00135     );
00136 }
00137 
00138 
00139 void ModelEvaluator::InArgs::assert_l(int l) const
00140 {
00141   TEST_FOR_EXCEPTION(
00142     !( 0 <= l && l < Np() ), std::logic_error
00143     ,"EpetraExt::ModelEvaluator::InArgs::assert_l(l): model = \'"<<modelEvalDescription_<<"\': Error, "
00144     "The parameter l = " << l << " is not in the range [0,"<<Np()-1<<"]!"
00145     );
00146 }
00147 
00148 
00149 //
00150 // ModelEvaluator::OutArgs
00151 //
00152 
00153 
00154 ModelEvaluator::OutArgs::OutArgs()
00155   :modelEvalDescription_("WARNING!  THIS OUTARGS OBJECT IS UNINITALIZED!"),
00156   isFailed_( false )
00157 {
00158   std::fill_n(&supports_[0],NUM_E_OUT_ARGS_MEMBERS,false);
00159 }
00160 
00161 
00162 bool ModelEvaluator::OutArgs::supports(EOutArgsMembers arg) const
00163 {
00164   TEST_FOR_EXCEPTION(
00165     int(arg)>=NUM_E_OUT_ARGS_MEMBERS || int(arg) < 0,std::logic_error
00166     ,"model = \'"<<modelEvalDescription_<<"\': Error, arg="<<toString(arg)<<" is invalid!"
00167     );
00168   return supports_[arg];
00169 }
00170 
00171 
00172 const ModelEvaluator::DerivativeSupport&
00173 ModelEvaluator::OutArgs::supports(EOutArgsDfDp arg, int l) const
00174 {
00175   assert_l(l);
00176   return supports_DfDp_[l];
00177 }
00178 
00179 
00180 const ModelEvaluator::DerivativeSupport&
00181 ModelEvaluator::OutArgs::supports(EOutArgsDgDx_dot arg, int j) const
00182 {
00183   assert_j(j);
00184   return supports_DgDx_dot_[j];
00185 }
00186 
00187 
00188 const ModelEvaluator::DerivativeSupport&
00189 ModelEvaluator::OutArgs::supports(EOutArgsDgDx arg, int j) const
00190 {
00191   assert_j(j);
00192   return supports_DgDx_[j];
00193 }
00194 
00195 
00196 const ModelEvaluator::DerivativeSupport&
00197 ModelEvaluator::OutArgs::supports(EOutArgsDgDp arg, int j, int l) const
00198 {
00199   assert_j(j);
00200   assert_l(l);
00201   return supports_DgDp_[ j*Np() + l ];
00202 }
00203 
00204 bool ModelEvaluator::OutArgs::supports(EOutArgs_g_sg arg, int j) const
00205 {
00206   assert_j(j);
00207   return supports_g_sg_[j];
00208 }
00209 
00210 const ModelEvaluator::DerivativeSupport&
00211 ModelEvaluator::OutArgs::supports(EOutArgsDfDp_sg arg, int l) const
00212 {
00213   assert_l(l);
00214   return supports_DfDp_sg_[l];
00215 }
00216 
00217 
00218 const ModelEvaluator::DerivativeSupport&
00219 ModelEvaluator::OutArgs::supports(EOutArgsDgDx_dot_sg arg, int j) const
00220 {
00221   assert_j(j);
00222   return supports_DgDx_dot_sg_[j];
00223 }
00224 
00225 
00226 const ModelEvaluator::DerivativeSupport&
00227 ModelEvaluator::OutArgs::supports(EOutArgsDgDx_sg arg, int j) const
00228 {
00229   assert_j(j);
00230   return supports_DgDx_sg_[j];
00231 }
00232 
00233 const ModelEvaluator::DerivativeSupport&
00234 ModelEvaluator::OutArgs::supports(EOutArgsDgDp_sg arg, int j, int l) const
00235 {
00236   assert_j(j);
00237   assert_l(l);
00238   return supports_DgDp_sg_[ j*Np() + l ];
00239 }
00240 
00241 bool ModelEvaluator::OutArgs::supports(EOutArgs_g_mp arg, int j) const
00242 {
00243   assert_j(j);
00244   return supports_g_mp_[j];
00245 }
00246 
00247 const ModelEvaluator::DerivativeSupport&
00248 ModelEvaluator::OutArgs::supports(EOutArgsDfDp_mp arg, int l) const
00249 {
00250   assert_l(l);
00251   return supports_DfDp_mp_[l];
00252 }
00253 
00254 
00255 const ModelEvaluator::DerivativeSupport&
00256 ModelEvaluator::OutArgs::supports(EOutArgsDgDx_dot_mp arg, int j) const
00257 {
00258   assert_j(j);
00259   return supports_DgDx_dot_mp_[j];
00260 }
00261 
00262 
00263 const ModelEvaluator::DerivativeSupport&
00264 ModelEvaluator::OutArgs::supports(EOutArgsDgDx_mp arg, int j) const
00265 {
00266   assert_j(j);
00267   return supports_DgDx_mp_[j];
00268 }
00269 
00270 const ModelEvaluator::DerivativeSupport&
00271 ModelEvaluator::OutArgs::supports(EOutArgsDgDp_mp arg, int j, int l) const
00272 {
00273   assert_j(j);
00274   assert_l(l);
00275   return supports_DgDp_mp_[ j*Np() + l ];
00276 }
00277 
00278 
00279 bool ModelEvaluator::OutArgs::funcOrDerivesAreSet(EOutArgsMembers arg) const
00280 {
00281   using Teuchos::implicit_cast;
00282   bool areSet = false;
00283   switch(arg) {
00284     case OUT_ARG_f: {
00285       if (!is_null(f_)) areSet = true;
00286       if (!is_null(W_)) areSet = true;
00287       for ( int l = 0; l < implicit_cast<int>(DfDp_.size()); ++l )
00288         if(!DfDp_[l].isEmpty()) areSet = true;
00289       break;
00290     }
00291     default:
00292       TEST_FOR_EXCEPTION(true,std::logic_error,
00293         "ModelEvaluator::OutArgs::funcOrDerivesAreSet(arg): Error, we can not handle"
00294         " the argument " << toString(arg) << "yet!");
00295   }
00296   return areSet;
00297 }
00298 
00299 void ModelEvaluator::OutArgs::setFailed() const
00300 {
00301   isFailed_ = true;
00302   // TODO: Set objects to NaN?
00303 }
00304 
00305 bool ModelEvaluator::OutArgs::isFailed() const
00306 {
00307   return isFailed_;
00308 }
00309 
00310 
00311 void ModelEvaluator::OutArgs::_setModelEvalDescription( const std::string &modelEvalDescription )
00312 {
00313   modelEvalDescription_ = modelEvalDescription;
00314 }
00315 
00316 
00317 void ModelEvaluator::OutArgs::_set_Np_Ng(int Np, int Ng)
00318 {
00319   if(Np) {
00320     supports_DfDp_.resize(Np);
00321     DfDp_.resize(Np);
00322     std::fill_n(DfDp_.begin(),Np,Derivative());
00323     DfDp_properties_.resize(Np);
00324     std::fill_n(DfDp_properties_.begin(),Np,DerivativeProperties());
00325 
00326     supports_DfDp_sg_.resize(Np);
00327     DfDp_sg_.resize(Np);
00328     std::fill_n(DfDp_sg_.begin(),Np,SGDerivative());
00329     DfDp_sg_properties_.resize(Np);
00330     std::fill_n(DfDp_sg_properties_.begin(),Np,DerivativeProperties());
00331 
00332     supports_DfDp_mp_.resize(Np);
00333     DfDp_mp_.resize(Np);
00334     std::fill_n(DfDp_mp_.begin(),Np,MPDerivative());
00335     DfDp_mp_properties_.resize(Np);
00336     std::fill_n(DfDp_mp_properties_.begin(),Np,DerivativeProperties());
00337   }
00338   if(Ng) {
00339     g_.resize(Ng);
00340     supports_DgDx_dot_.resize(Ng);
00341     DgDx_dot_.resize(Ng);
00342     std::fill_n(DgDx_dot_.begin(),Ng,Derivative());
00343     DgDx_dot_properties_.resize(Ng);
00344     std::fill_n(DgDx_dot_properties_.begin(),Ng,DerivativeProperties());
00345     supports_DgDx_.resize(Ng);
00346     DgDx_.resize(Ng);
00347     std::fill_n(DgDx_.begin(),Ng,Derivative());
00348     DgDx_properties_.resize(Ng);
00349     std::fill_n(DgDx_properties_.begin(),Ng,DerivativeProperties());
00350 
00351     g_sg_.resize(Ng);
00352     supports_g_sg_.resize(Ng);
00353     supports_DgDx_dot_sg_.resize(Ng);
00354     DgDx_dot_sg_.resize(Ng);
00355     std::fill_n(DgDx_dot_sg_.begin(),Ng,SGDerivative());
00356     DgDx_dot_sg_properties_.resize(Ng);
00357     std::fill_n(DgDx_dot_sg_properties_.begin(),Ng,DerivativeProperties());
00358     supports_DgDx_sg_.resize(Ng);
00359     DgDx_sg_.resize(Ng);
00360     std::fill_n(DgDx_sg_.begin(),Ng,SGDerivative());
00361     DgDx_sg_properties_.resize(Ng);
00362     std::fill_n(DgDx_sg_properties_.begin(),Ng,DerivativeProperties());
00363 
00364     g_mp_.resize(Ng);
00365     supports_g_mp_.resize(Ng);
00366     supports_DgDx_dot_mp_.resize(Ng);
00367     DgDx_dot_mp_.resize(Ng);
00368     std::fill_n(DgDx_dot_mp_.begin(),Ng,MPDerivative());
00369     DgDx_dot_mp_properties_.resize(Ng);
00370     std::fill_n(DgDx_dot_mp_properties_.begin(),Ng,DerivativeProperties());
00371     supports_DgDx_mp_.resize(Ng);
00372     DgDx_mp_.resize(Ng);
00373     std::fill_n(DgDx_mp_.begin(),Ng,MPDerivative());
00374     DgDx_mp_properties_.resize(Ng);
00375     std::fill_n(DgDx_mp_properties_.begin(),Ng,DerivativeProperties());
00376   }
00377   if(Np && Ng) {
00378     const int NpNg = Np*Ng;
00379     supports_DgDp_.resize(NpNg);
00380     DgDp_.resize(NpNg);
00381     std::fill_n(DgDp_.begin(),NpNg,Derivative());
00382     DgDp_properties_.resize(NpNg);
00383     std::fill_n(DgDp_properties_.begin(),NpNg,DerivativeProperties());
00384 
00385     supports_DgDp_sg_.resize(NpNg);
00386     DgDp_sg_.resize(NpNg);
00387     std::fill_n(DgDp_sg_.begin(),NpNg,SGDerivative());
00388     DgDp_sg_properties_.resize(NpNg);
00389     std::fill_n(DgDp_sg_properties_.begin(),NpNg,DerivativeProperties());
00390 
00391     supports_DgDp_mp_.resize(NpNg);
00392     DgDp_mp_.resize(NpNg);
00393     std::fill_n(DgDp_mp_.begin(),NpNg,MPDerivative());
00394     DgDp_mp_properties_.resize(NpNg);
00395     std::fill_n(DgDp_mp_properties_.begin(),NpNg,DerivativeProperties());
00396   }
00397 }
00398 
00399 void ModelEvaluator::OutArgs::_setSupports( EOutArgsMembers arg, bool supports )
00400 {
00401   TEST_FOR_EXCEPTION(
00402     int(arg)>=NUM_E_OUT_ARGS_MEMBERS || int(arg) < 0,std::logic_error
00403     ,"model = \'"<<modelEvalDescription_<<"\': Error, arg="<<toString(arg)<<" is invalid!"
00404     );
00405   supports_[arg] = supports;
00406 }
00407 
00408 
00409 void ModelEvaluator::OutArgs::_setSupports( EOutArgsDfDp arg, int l, const DerivativeSupport& supports )
00410 {
00411   assert_l(l);
00412   supports_DfDp_[l] = supports;
00413 }
00414 
00415 
00416 void ModelEvaluator::OutArgs::_setSupports( EOutArgsDgDx_dot arg, int j, const DerivativeSupport& supports )
00417 {
00418   assert_j(j);
00419   supports_DgDx_dot_[j] = supports;
00420 }
00421 
00422 
00423 void ModelEvaluator::OutArgs::_setSupports( EOutArgsDgDx arg, int j, const DerivativeSupport& supports )
00424 {
00425   assert_j(j);
00426   supports_DgDx_[j] = supports;
00427 }
00428 
00429 
00430 void ModelEvaluator::OutArgs::_setSupports( EOutArgsDgDp arg, int j, int l, const DerivativeSupport& supports )
00431 {
00432   assert_j(j);
00433   assert_l(l);
00434   supports_DgDp_[ j*Np() + l ] = supports;
00435 }
00436 
00437 void ModelEvaluator::OutArgs::_setSupports( EOutArgs_g_sg arg, int j, bool supports )
00438 {
00439   assert_j(j);
00440   supports_g_sg_[j] = supports;
00441 }
00442 
00443 void ModelEvaluator::OutArgs::_setSupports( EOutArgsDfDp_sg arg, int l, const DerivativeSupport& supports )
00444 {
00445   assert_l(l);
00446   supports_DfDp_sg_[l] = supports;
00447 }
00448 
00449 
00450 void ModelEvaluator::OutArgs::_setSupports( EOutArgsDgDx_dot_sg arg, int j, const DerivativeSupport& supports )
00451 {
00452   assert_j(j);
00453   supports_DgDx_dot_sg_[j] = supports;
00454 }
00455 
00456 
00457 void ModelEvaluator::OutArgs::_setSupports( EOutArgsDgDx_sg arg, int j, const DerivativeSupport& supports )
00458 {
00459   assert_j(j);
00460   supports_DgDx_sg_[j] = supports;
00461 }
00462 
00463 void ModelEvaluator::OutArgs::_setSupports( EOutArgsDgDp_sg arg, int j, int l, const DerivativeSupport& supports )
00464 {
00465   assert_j(j);
00466   assert_l(l);
00467   supports_DgDp_sg_[ j*Np() + l ] = supports;
00468 }
00469 
00470 void ModelEvaluator::OutArgs::_setSupports( EOutArgs_g_mp arg, int j, bool supports )
00471 {
00472   assert_j(j);
00473   supports_g_mp_[j] = supports;
00474 }
00475 
00476 void ModelEvaluator::OutArgs::_setSupports( EOutArgsDfDp_mp arg, int l, const DerivativeSupport& supports )
00477 {
00478   assert_l(l);
00479   supports_DfDp_mp_[l] = supports;
00480 }
00481 
00482 
00483 void ModelEvaluator::OutArgs::_setSupports( EOutArgsDgDx_dot_mp arg, int j, const DerivativeSupport& supports )
00484 {
00485   assert_j(j);
00486   supports_DgDx_dot_mp_[j] = supports;
00487 }
00488 
00489 
00490 void ModelEvaluator::OutArgs::_setSupports( EOutArgsDgDx_mp arg, int j, const DerivativeSupport& supports )
00491 {
00492   assert_j(j);
00493   supports_DgDx_mp_[j] = supports;
00494 }
00495 
00496 void ModelEvaluator::OutArgs::_setSupports( EOutArgsDgDp_mp arg, int j, int l, const DerivativeSupport& supports )
00497 {
00498   assert_j(j);
00499   assert_l(l);
00500   supports_DgDp_mp_[ j*Np() + l ] = supports;
00501 }
00502 
00503 
00504 void ModelEvaluator::OutArgs::_set_W_properties( const DerivativeProperties &W_properties )
00505 {
00506   W_properties_ = W_properties;
00507 }
00508 
00509 void ModelEvaluator::OutArgs::_set_WPrec_properties( const DerivativeProperties &WPrec_properties )
00510 {
00511   WPrec_properties_ = WPrec_properties;
00512 }
00513 
00514 void ModelEvaluator::OutArgs::_set_DfDp_properties( int l, const DerivativeProperties &properties )
00515 {
00516   assert_supports(OUT_ARG_DfDp,l);
00517   DfDp_properties_[l] = properties;
00518 }
00519 
00520 
00521 void ModelEvaluator::OutArgs::_set_DgDx_dot_properties( int j, const DerivativeProperties &properties )
00522 {
00523   assert_supports(OUT_ARG_DgDx_dot,j);
00524   DgDx_dot_properties_[j] = properties;
00525 }
00526 
00527 
00528 void ModelEvaluator::OutArgs::_set_DgDx_properties( int j, const DerivativeProperties &properties )
00529 {
00530   assert_supports(OUT_ARG_DgDx,j);
00531   DgDx_properties_[j] = properties;
00532 }
00533 
00534 
00535 void ModelEvaluator::OutArgs::_set_DgDp_properties( int j, int l, const DerivativeProperties &properties )
00536 {
00537   assert_supports(OUT_ARG_DgDp,j,l);
00538   DgDp_properties_[ j*Np() + l ] = properties;
00539 }
00540 
00541 void ModelEvaluator::OutArgs::_set_DfDp_sg_properties( int l, const DerivativeProperties &properties )
00542 {
00543   assert_supports(OUT_ARG_DfDp_sg,l);
00544   DfDp_sg_properties_[l] = properties;
00545 }
00546 
00547 
00548 void ModelEvaluator::OutArgs::_set_DgDx_dot_sg_properties( int j, const DerivativeProperties &properties )
00549 {
00550   assert_supports(OUT_ARG_DgDx_dot_sg,j);
00551   DgDx_dot_sg_properties_[j] = properties;
00552 }
00553 
00554 
00555 void ModelEvaluator::OutArgs::_set_DgDx_sg_properties( int j, const DerivativeProperties &properties )
00556 {
00557   assert_supports(OUT_ARG_DgDx_sg,j);
00558   DgDx_sg_properties_[j] = properties;
00559 }
00560 
00561 void ModelEvaluator::OutArgs::_set_DgDp_sg_properties( int j, int l, const DerivativeProperties &properties )
00562 {
00563   assert_supports(OUT_ARG_DgDp_sg,j,l);
00564   DgDp_sg_properties_[ j*Np() + l ] = properties;
00565 }
00566 
00567 
00568 void ModelEvaluator::OutArgs::_set_DfDp_mp_properties( int l, const DerivativeProperties &properties )
00569 {
00570   assert_supports(OUT_ARG_DfDp_mp,l);
00571   DfDp_mp_properties_[l] = properties;
00572 }
00573 
00574 
00575 void ModelEvaluator::OutArgs::_set_DgDx_dot_mp_properties( int j, const DerivativeProperties &properties )
00576 {
00577   assert_supports(OUT_ARG_DgDx_dot_mp,j);
00578   DgDx_dot_mp_properties_[j] = properties;
00579 }
00580 
00581 
00582 void ModelEvaluator::OutArgs::_set_DgDx_mp_properties( int j, const DerivativeProperties &properties )
00583 {
00584   assert_supports(OUT_ARG_DgDx_mp,j);
00585   DgDx_mp_properties_[j] = properties;
00586 }
00587 
00588 void ModelEvaluator::OutArgs::_set_DgDp_mp_properties( int j, int l, const DerivativeProperties &properties )
00589 {
00590   assert_supports(OUT_ARG_DgDp_mp,j,l);
00591   DgDp_mp_properties_[ j*Np() + l ] = properties;
00592 }
00593 
00594 
00595 void ModelEvaluator::OutArgs::assert_supports(EOutArgsMembers arg) const
00596 {
00597   TEST_FOR_EXCEPTION(
00598     !supports_[arg], std::logic_error
00599     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(arg): "
00600     "model = \'"<<modelEvalDescription_<<"\': Error, "
00601     "The argument arg = " << toString(arg) << " is not supported!"
00602     );
00603 }
00604 
00605 
00606 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDfDp arg, int l) const
00607 {
00608   assert_l(l);
00609   TEST_FOR_EXCEPTION(
00610     supports_DfDp_[l].none(), std::logic_error
00611     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DfDp,l): "
00612     "model = \'"<<modelEvalDescription_<<"\': Error,"
00613     "The argument DfDp(l) with index l = " << l << " is not supported!"
00614     );
00615 }
00616 
00617 
00618 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDx_dot arg, int j) const
00619 {
00620   assert_j(j);
00621   TEST_FOR_EXCEPTION(
00622     supports_DgDx_dot_[j].none(), std::logic_error
00623     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDx_dot,j): "
00624     "model = \'"<<modelEvalDescription_<<"\': Error,"
00625     "The argument DgDx_dot(j) with index j = " << j << " is not supported!"
00626     );
00627 }
00628 
00629 
00630 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDx arg, int j) const
00631 {
00632   assert_j(j);
00633   TEST_FOR_EXCEPTION(
00634     supports_DgDx_[j].none(), std::logic_error
00635     ,"TEpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDx,j): "
00636     "model = \'"<<modelEvalDescription_<<"\': Error,"
00637     "The argument DgDx(j) with index j = " << j << " is not supported!"
00638     );
00639 }
00640 
00641 
00642 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDp arg, int j, int l) const
00643 {
00644   assert_j(j);
00645   assert_l(l);
00646   TEST_FOR_EXCEPTION(
00647     supports_DgDp_[ j*Np() + l ].none(), std::logic_error
00648     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDp,j,l): "
00649     "model = \'"<<modelEvalDescription_<<"\': Error,"
00650     "The argument DgDp(j,l) with indexes j = " << j << " and l = " << l << " is not supported!"
00651     );
00652 }
00653 
00654 void ModelEvaluator::OutArgs::assert_supports(EOutArgs_g_sg arg, int j) const
00655 {
00656   assert_j(j);
00657   TEST_FOR_EXCEPTION(
00658     !supports_g_sg_[j], std::logic_error
00659     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_g_sg,j): "
00660     "model = \'"<<modelEvalDescription_<<"\': Error,"
00661     "The argument g_sg(j) with index j = " << j << " is not supported!"
00662     );
00663 }
00664 
00665 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDfDp_sg arg, int l) const
00666 {
00667   assert_l(l);
00668   TEST_FOR_EXCEPTION(
00669     supports_DfDp_sg_[l].none(), std::logic_error
00670     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DfDp_sg,l): "
00671     "model = \'"<<modelEvalDescription_<<"\': Error,"
00672     "The argument DfDp_sg(l) with index l = " << l << " is not supported!"
00673     );
00674 }
00675 
00676 
00677 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDx_dot_sg arg, int j) const
00678 {
00679   assert_j(j);
00680   TEST_FOR_EXCEPTION(
00681     supports_DgDx_dot_sg_[j].none(), std::logic_error
00682     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDx_dot_sg,j): "
00683     "model = \'"<<modelEvalDescription_<<"\': Error,"
00684     "The argument DgDx_dot_sg(j) with index j = " << j << " is not supported!"
00685     );
00686 }
00687 
00688 
00689 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDx_sg arg, int j) const
00690 {
00691   assert_j(j);
00692   TEST_FOR_EXCEPTION(
00693     supports_DgDx_sg_[j].none(), std::logic_error
00694     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDx_sg,j): "
00695     "model = \'"<<modelEvalDescription_<<"\': Error,"
00696     "The argument DgDx_sg(j) with index j = " << j << " is not supported!"
00697     );
00698 }
00699 
00700 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDp_sg arg, int j, int l) const
00701 {
00702   assert_j(j);
00703   assert_l(l);
00704   TEST_FOR_EXCEPTION(
00705     supports_DgDp_sg_[ j*Np() + l ].none(), std::logic_error
00706     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDp_sg,j,l): "
00707     "model = \'"<<modelEvalDescription_<<"\': Error,"
00708     "The argument DgDp_sg(j,l) with indexes j = " << j << " and l = " << l << " is not supported!"
00709     );
00710 }
00711 
00712 void ModelEvaluator::OutArgs::assert_supports(EOutArgs_g_mp arg, int j) const
00713 {
00714   assert_j(j);
00715   TEST_FOR_EXCEPTION(
00716     !supports_g_mp_[j], std::logic_error
00717     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_g_mp,j): "
00718     "model = \'"<<modelEvalDescription_<<"\': Error,"
00719     "The argument g_mp(j) with index j = " << j << " is not supported!"
00720     );
00721 }
00722 
00723 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDfDp_mp arg, int l) const
00724 {
00725   assert_l(l);
00726   TEST_FOR_EXCEPTION(
00727     supports_DfDp_mp_[l].none(), std::logic_error
00728     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DfDp_mp,l): "
00729     "model = \'"<<modelEvalDescription_<<"\': Error,"
00730     "The argument DfDp_mp(l) with index l = " << l << " is not supported!"
00731     );
00732 }
00733 
00734 
00735 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDx_dot_mp arg, int j) const
00736 {
00737   assert_j(j);
00738   TEST_FOR_EXCEPTION(
00739     supports_DgDx_dot_mp_[j].none(), std::logic_error
00740     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDx_dot_mp,j): "
00741     "model = \'"<<modelEvalDescription_<<"\': Error,"
00742     "The argument DgDx_dot_mp(j) with index j = " << j << " is not supported!"
00743     );
00744 }
00745 
00746 
00747 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDx_mp arg, int j) const
00748 {
00749   assert_j(j);
00750   TEST_FOR_EXCEPTION(
00751     supports_DgDx_mp_[j].none(), std::logic_error
00752     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDx_mp,j): "
00753     "model = \'"<<modelEvalDescription_<<"\': Error,"
00754     "The argument DgDx_mp(j) with index j = " << j << " is not supported!"
00755     );
00756 }
00757 
00758 void ModelEvaluator::OutArgs::assert_supports(EOutArgsDgDp_mp arg, int j, int l) const
00759 {
00760   assert_j(j);
00761   assert_l(l);
00762   TEST_FOR_EXCEPTION(
00763     supports_DgDp_mp_[ j*Np() + l ].none(), std::logic_error
00764     ,"EpetraExt::ModelEvaluator::OutArgs::assert_supports(OUT_ARG_DgDp_mp,j,l): "
00765     "model = \'"<<modelEvalDescription_<<"\': Error,"
00766     "The argument DgDp_mp(j,l) with indexes j = " << j << " and l = " << l << " is not supported!"
00767     );
00768 }
00769 
00770 
00771 void ModelEvaluator::OutArgs::assert_l(int l) const
00772 {
00773   TEST_FOR_EXCEPTION(
00774     Np()==0, std::logic_error
00775     ,"EpetraExt::ModelEvaluator::OutArgs::assert_l(l): model = \'"<<modelEvalDescription_<<"\':  Error, "
00776     "no auxiliary parameters subvectors p(l) are supported!!"
00777     );
00778   TEST_FOR_EXCEPTION(
00779     !( 0 <= l && l < Np() ), std::logic_error
00780     ,"EpetraExt::ModelEvaluator::OutArgs::assert_l(l): "
00781     "model = \'"<<modelEvalDescription_<<"\': Error, "
00782     "The parameter subvector p(l) index l = " << l << " is not in the range [0,"<<Np()-1<<"]!"
00783     );
00784 }
00785 
00786 
00787 void ModelEvaluator::OutArgs::assert_j(int j) const
00788 {
00789   TEST_FOR_EXCEPTION(
00790     Ng()==0, std::logic_error
00791     ,"EpetraExt::ModelEvaluator::OutArgs::assert_j(j): model = \'"<<modelEvalDescription_<<"\':  Error, "
00792     "no auxiliary functions g(j) are supported!!"
00793     );
00794   TEST_FOR_EXCEPTION(
00795     !( 0 <= j && j < Ng() ), std::logic_error
00796     ,"EpetraExt::ModelEvaluator::OutArgs::assert_j(j): model = \'"<<modelEvalDescription_<<"\':  Error, "
00797     "The auxiliary function g(j) index j = " << j << " is not in the range [0,"<<Ng()-1<<"]!"
00798     );
00799 }
00800 
00801 
00802 //
00803 // ModelEvaluator
00804 //
00805 
00806 
00807 // Destructor
00808 
00809 
00810 ModelEvaluator::~ModelEvaluator()
00811 {}
00812 
00813 
00814 // Vector maps
00815  
00816  
00817 Teuchos::RefCountPtr<const Epetra_Map>
00818 ModelEvaluator::get_p_map(int l) const
00819 { return Teuchos::null; }
00820 
00821 Teuchos::RefCountPtr<const Teuchos::Array<std::string> >
00822 ModelEvaluator::get_p_names(int l) const
00823 { return Teuchos::null; }
00824 
00825 Teuchos::RefCountPtr<const Epetra_Map>
00826 ModelEvaluator::get_g_map(int j) const
00827 { return Teuchos::null; }
00828 
00829 
00830 // Initial guesses for variables/parameters
00831 
00832 
00833 Teuchos::RefCountPtr<const Epetra_Vector>
00834 ModelEvaluator::get_x_init() const
00835 { return Teuchos::null; }
00836 
00837 Teuchos::RefCountPtr<const Epetra_Vector>
00838 ModelEvaluator::get_x_dot_init() const
00839 { return Teuchos::null; }
00840 
00841 Teuchos::RefCountPtr<const Epetra_Vector>
00842 ModelEvaluator::get_p_init(int l) const
00843 { return Teuchos::null; }
00844 
00845 double ModelEvaluator::get_t_init() const
00846 { return 0.0; }
00847 
00848 
00849 // Bounds for variables/parameters
00850 
00851 
00852 double ModelEvaluator::getInfBound() const
00853 {
00854   return 1e+50;
00855 }
00856 
00857 
00858 Teuchos::RefCountPtr<const Epetra_Vector>
00859 ModelEvaluator::get_x_lower_bounds() const
00860 { return Teuchos::null; }
00861 
00862 
00863 Teuchos::RefCountPtr<const Epetra_Vector>
00864 ModelEvaluator::get_x_upper_bounds() const
00865 { return Teuchos::null; }
00866 
00867 
00868 Teuchos::RefCountPtr<const Epetra_Vector>
00869 ModelEvaluator::get_p_lower_bounds(int l) const
00870 { return Teuchos::null; }
00871 
00872 
00873 Teuchos::RefCountPtr<const Epetra_Vector>
00874 ModelEvaluator::get_p_upper_bounds(int l) const
00875 { return Teuchos::null; }
00876 
00877 
00878 double ModelEvaluator::get_t_lower_bound() const
00879 { return 0.0; }
00880 
00881 
00882 double ModelEvaluator::get_t_upper_bound() const
00883 { return 0.0; }
00884 
00885 
00886 // Factory functions for creating derivative objects
00887 
00888 
00889 Teuchos::RefCountPtr<Epetra_Operator>
00890 ModelEvaluator::create_W() const
00891 { return Teuchos::null; }
00892 
00893 Teuchos::RefCountPtr<EpetraExt::ModelEvaluator::Preconditioner>
00894 ModelEvaluator::create_WPrec() const
00895 { return Teuchos::null; }
00896 
00897 Teuchos::RefCountPtr<Epetra_Operator>
00898 ModelEvaluator::create_DfDp_op(int l) const
00899 { return Teuchos::null; }
00900 
00901 Teuchos::RefCountPtr<Epetra_Operator>
00902 ModelEvaluator::create_DgDx_dot_op(int j) const
00903 { return Teuchos::null; }
00904 
00905 Teuchos::RefCountPtr<Epetra_Operator>
00906 ModelEvaluator::create_DgDx_op(int j) const
00907 { return Teuchos::null; }
00908 
00909 Teuchos::RefCountPtr<Epetra_Operator>
00910 ModelEvaluator::create_DgDp_op( int j, int l ) const
00911 { return Teuchos::null; }
00912 
00913 } // namespace EpetraExt
00914 
00915 
00916 //
00917 // Helper functions
00918 //
00919 
00920 
00921 std::string EpetraExt::toString(
00922    ModelEvaluator::EDerivativeMultiVectorOrientation orientation
00923    )
00924 {
00925   switch(orientation) {
00926     case ModelEvaluator::DERIV_MV_BY_COL:
00927       return "DERIV_MV_BY_COL";
00928     case ModelEvaluator::DERIV_TRANS_MV_BY_ROW:
00929       return "DERIV_TRANS_MV_BY_ROW";
00930     default:
00931       TEST_FOR_EXCEPT(true);
00932   }
00933   return ""; // Should never be called
00934 }
00935 
00936 
00937 std::string EpetraExt::toString( ModelEvaluator::EInArgsMembers inArg )
00938 {
00939   switch(inArg) {
00940     case ModelEvaluator::IN_ARG_x_dot:
00941       return "IN_ARG_x_dot";
00942     case ModelEvaluator::IN_ARG_x:
00943       return "IN_ARG_x";
00944     case ModelEvaluator::IN_ARG_x_dot_poly:
00945       return "IN_ARG_x_dot_poly";
00946     case ModelEvaluator::IN_ARG_x_poly:
00947       return "IN_ARG_x_poly";
00948     case ModelEvaluator::IN_ARG_x_dot_sg:
00949       return "IN_ARG_x_dot_sg";
00950     case ModelEvaluator::IN_ARG_x_sg:
00951       return "IN_ARG_x_sg";
00952     case ModelEvaluator::IN_ARG_x_dot_mp:
00953       return "IN_ARG_x_dot_mp";
00954     case ModelEvaluator::IN_ARG_x_mp:
00955       return "IN_ARG_x_mp";
00956     case ModelEvaluator::IN_ARG_t:
00957       return "IN_ARG_t";
00958     case ModelEvaluator::IN_ARG_alpha:
00959       return "IN_ARG_alpha";
00960     case ModelEvaluator::IN_ARG_beta:
00961       return "IN_ARG_beta";
00962     default:
00963       TEST_FOR_EXCEPT("Invalid inArg!");
00964   }
00965   return ""; // Will never be executed!
00966 }
00967 
00968 
00969 std::string EpetraExt::toString( ModelEvaluator::EOutArgsMembers outArg )
00970 {
00971   switch(outArg) {
00972     case  ModelEvaluator::OUT_ARG_f:
00973       return "OUT_ARG_f";
00974     case ModelEvaluator::OUT_ARG_W:
00975       return "OUT_ARG_W";
00976     case ModelEvaluator::OUT_ARG_WPrec:
00977       return "OUT_ARG_WPrec";
00978     case ModelEvaluator::OUT_ARG_f_poly:
00979       return "OUT_ARG_f_poly";
00980     case ModelEvaluator::OUT_ARG_f_sg:
00981       return "OUT_ARG_f_sg";
00982     case ModelEvaluator::OUT_ARG_W_sg:
00983       return "OUT_ARG_W_sg";
00984     case ModelEvaluator::OUT_ARG_f_mp:
00985       return "OUT_ARG_f_mp";
00986     case ModelEvaluator::OUT_ARG_W_mp:
00987       return "OUT_ARG_W_mp";
00988     default:
00989       TEST_FOR_EXCEPT("Invalid outArg!");
00990   }
00991   return ""; // Will never be executed!
00992 }
00993 
00994 
00995 Teuchos::RefCountPtr<Epetra_Operator>
00996 EpetraExt::getLinearOp(
00997   const std::string &modelEvalDescription,
00998   const ModelEvaluator::Derivative &deriv,
00999   const std::string &derivName
01000   )
01001 {
01002   TEST_FOR_EXCEPTION(
01003     deriv.getMultiVector().get() != NULL, std::logic_error
01004     ,"For model \'" << modelEvalDescription << "\' the derivative \'"
01005     << derivName << "\' is of type Epetra_MultiVector and not of type Epetra_Operator!"
01006     );
01007   return deriv.getLinearOp();
01008 }
01009 
01010 
01011 Teuchos::RefCountPtr<Epetra_MultiVector>
01012 EpetraExt::getMultiVector(
01013   const std::string &modelEvalDescription,
01014   const ModelEvaluator::Derivative &deriv,
01015   const std::string &derivName,
01016   const ModelEvaluator::EDerivativeMultiVectorOrientation mvOrientation
01017   )
01018 {
01019   TEST_FOR_EXCEPTION(
01020     deriv.getLinearOp().get() != NULL, std::logic_error
01021     ,"For model \'" << modelEvalDescription << "\' the derivative \'"
01022     << derivName << "\' is of type Epetra_Operator and not of type Epetra_MultiVector!"
01023     );
01024   Teuchos::RefCountPtr<Epetra_MultiVector>
01025     mv = deriv.getMultiVector();
01026   if(mv.get()) {
01027     TEST_FOR_EXCEPTION(
01028       deriv.getMultiVectorOrientation()!=mvOrientation, std::logic_error
01029       ,"For model \'" << modelEvalDescription << "\' the derivative \'"
01030       << derivName << "\' if not the orientation \'" << toString(mvOrientation)
01031       << "\'"
01032       );
01033   }
01034   return mv;
01035 }
01036 
01037 
01038 Teuchos::RefCountPtr<Epetra_Operator>
01039 EpetraExt::get_DfDp_op(
01040   const int l,
01041   const ModelEvaluator::OutArgs &outArgs
01042   )
01043 {
01044   std::ostringstream derivName; derivName << "DfDp("<<l<<")";
01045   return getLinearOp(
01046     outArgs.modelEvalDescription()
01047     ,outArgs.get_DfDp(l)
01048     ,derivName.str()
01049     );
01050 }
01051 
01052 
01053 Teuchos::RefCountPtr<Epetra_MultiVector>
01054 EpetraExt::get_DfDp_mv(
01055   const int l,
01056   const ModelEvaluator::OutArgs &outArgs
01057   )
01058 {
01059   std::ostringstream derivName; derivName << "DfDp("<<l<<")";
01060   return getMultiVector(
01061     outArgs.modelEvalDescription()
01062     ,outArgs.get_DfDp(l)
01063     ,derivName.str()
01064     ,ModelEvaluator::DERIV_MV_BY_COL
01065     );
01066 }
01067 
01068 
01069 Teuchos::RefCountPtr<Epetra_MultiVector>
01070 EpetraExt::get_DgDx_dot_mv(
01071   const int j,
01072   const ModelEvaluator::OutArgs &outArgs,
01073   const ModelEvaluator::EDerivativeMultiVectorOrientation mvOrientation
01074   )
01075 {
01076   std::ostringstream derivName; derivName << "DgDx_dot("<<j<<")";
01077   return getMultiVector(
01078     outArgs.modelEvalDescription(),
01079     outArgs.get_DgDx_dot(j),
01080     derivName.str(),
01081     mvOrientation
01082     );
01083 }
01084 
01085 
01086 Teuchos::RefCountPtr<Epetra_MultiVector>
01087 EpetraExt::get_DgDx_mv(
01088   const int j,
01089   const ModelEvaluator::OutArgs &outArgs,
01090   const ModelEvaluator::EDerivativeMultiVectorOrientation mvOrientation
01091   )
01092 {
01093   std::ostringstream derivName; derivName << "DgDx("<<j<<")";
01094   return getMultiVector(
01095     outArgs.modelEvalDescription(),
01096     outArgs.get_DgDx(j),
01097     derivName.str(),
01098     mvOrientation
01099     );
01100 }
01101 
01102 
01103 Teuchos::RefCountPtr<Epetra_MultiVector>
01104 EpetraExt::get_DgDp_mv(
01105   const int j,
01106   const int l,
01107   const ModelEvaluator::OutArgs &outArgs,
01108   const ModelEvaluator::EDerivativeMultiVectorOrientation mvOrientation
01109   )
01110 {
01111   std::ostringstream derivName; derivName << "DgDp("<<j<<","<<l<<")";
01112   return getMultiVector(
01113     outArgs.modelEvalDescription(),
01114     outArgs.get_DgDp(j,l),
01115     derivName.str(),
01116     mvOrientation
01117     );
01118 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines