EpetraExt_DiagonalQuadraticResponseOnlyModelEvaluator.cpp

Go to the documentation of this file.
00001 #include "EpetraExt_DiagonalQuadraticResponseOnlyModelEvaluator.hpp"
00002 #include "Teuchos_ScalarTraits.hpp"
00003 #include "Epetra_SerialComm.h"
00004 #include "Epetra_CrsMatrix.h"
00005 
00006 
00007 namespace EpetraExt {
00008 
00009 
00010 DiagonalQuadraticResponseOnlyModelEvaluator
00011 ::DiagonalQuadraticResponseOnlyModelEvaluator(
00012   const Teuchos::RCP<Epetra_Comm> &comm,
00013   const int localDim, const double &pt, const double &p0, const double &scale
00014   )
00015   :epetra_comm_(comm), scale_(scale)
00016 {
00017 
00018   using Teuchos::rcp;
00019 
00020   const int ng = 1;
00021 
00022   map_p_ = rcp(new Epetra_Map(-1, localDim, 0, *epetra_comm_));
00023   map_g_ = rcp(new Epetra_Map(ng, ng, 0, *epetra_comm_));
00024 
00025   pt_ = rcp(new Epetra_Vector(*map_p_));
00026   pt_->PutScalar(pt);
00027 
00028   p0_ = rcp(new Epetra_Vector(*map_p_));
00029   p0_->PutScalar(p0);
00030 
00031 }
00032 
00033 
00034 // Overridden from EpetraExt::ModelEvaluator
00035 
00036 
00037 Teuchos::RefCountPtr<const Epetra_Map>
00038 DiagonalQuadraticResponseOnlyModelEvaluator::get_x_map() const
00039 {
00040   return Teuchos::null;
00041 }
00042 
00043 
00044 Teuchos::RefCountPtr<const Epetra_Map>
00045 DiagonalQuadraticResponseOnlyModelEvaluator::get_f_map() const
00046 {
00047   return Teuchos::null;
00048 }
00049 
00050 
00051 Teuchos::RefCountPtr<const Epetra_Map>
00052 DiagonalQuadraticResponseOnlyModelEvaluator::get_p_map(int l) const
00053 {
00054   TEST_FOR_EXCEPT(l!=0);
00055   return map_p_;
00056 }
00057 
00058 
00059 Teuchos::RefCountPtr<const Epetra_Map>
00060 DiagonalQuadraticResponseOnlyModelEvaluator::get_g_map(int j) const
00061 {
00062   TEST_FOR_EXCEPT(j!=0);
00063   return map_g_;
00064 }
00065 
00066 
00067 Teuchos::RefCountPtr<const Epetra_Vector>
00068 DiagonalQuadraticResponseOnlyModelEvaluator::get_p_init(int l) const
00069 {
00070   TEST_FOR_EXCEPT(l!=0);
00071   return p0_;
00072 }
00073 
00074 
00075 EpetraExt::ModelEvaluator::InArgs
00076 DiagonalQuadraticResponseOnlyModelEvaluator::createInArgs() const
00077 {
00078   InArgsSetup inArgs;
00079   inArgs.setModelEvalDescription(this->description());
00080   inArgs.set_Np(1);
00081   return inArgs;
00082 }
00083 
00084 
00085 EpetraExt::ModelEvaluator::OutArgs
00086 DiagonalQuadraticResponseOnlyModelEvaluator::createOutArgs() const
00087 {
00088   OutArgsSetup outArgs;
00089   outArgs.setModelEvalDescription(this->description());
00090   outArgs.set_Np_Ng(1, 1);
00091   outArgs.setSupports(OUT_ARG_DgDp, 0, 0, DERIV_TRANS_MV_BY_ROW);
00092   outArgs.set_DgDp_properties(
00093     0, 0, DerivativeProperties(
00094       DERIV_LINEARITY_NONCONST,
00095       DERIV_RANK_DEFICIENT,
00096       true // supportsAdjoint
00097       )
00098     );
00099   return outArgs;
00100 }
00101 
00102 
00103 void DiagonalQuadraticResponseOnlyModelEvaluator::evalModel(
00104   const InArgs& inArgs, const OutArgs& outArgs
00105   ) const
00106 {
00107 
00108   using Teuchos::RCP;
00109   using Teuchos::dyn_cast;
00110   using Teuchos::rcp_dynamic_cast;
00111 
00112   //
00113   // Get the input arguments
00114   //
00115 
00116   const Epetra_Vector &p = *inArgs.get_p(0);
00117 
00118   //
00119   // Get the output arguments
00120   //
00121 
00122   const RCP<Epetra_Vector> g_out = outArgs.get_g(0);
00123 
00124   const RCP<Epetra_MultiVector> DgDp_trans_out =
00125     get_DgDp_mv(0, 0,outArgs,DERIV_TRANS_MV_BY_ROW);
00126 
00127   //
00128   // Compute the functions
00129   //
00130 
00131   if (!is_null(g_out) || !is_null(DgDp_trans_out)) {
00132 
00133     Epetra_Vector p_minus_pt(*map_p_);
00134 
00135     p_minus_pt = p;
00136     p_minus_pt.Update(-1.0, *pt_, 1.0);
00137 
00138     if (!is_null(g_out)) {
00139       double dot[1];
00140       p_minus_pt.Dot(p_minus_pt, dot);
00141       (*g_out)[0] = scale_ * 0.5 * dot[0];
00142     }
00143     
00144     if (!is_null(DgDp_trans_out)) {
00145       (*DgDp_trans_out) = p_minus_pt;
00146       DgDp_trans_out->Scale(scale_);
00147     }
00148 
00149   }
00150 
00151 }
00152 
00153 
00154 } // namespace EpetraExt

Generated on Wed May 12 21:24:45 2010 for EpetraExt by  doxygen 1.4.7