EpetraExt Package Browser (Single Doxygen Collection) Development
EpetraExt_DiagonalQuadraticResponseOnlyModelEvaluator.cpp
Go to the documentation of this file.
00001 /*
00002 //@HEADER
00003 // ***********************************************************************
00004 //
00005 //     EpetraExt: Epetra Extended - Linear Algebra Services Package
00006 //                 Copyright (2011) Sandia Corporation
00007 //
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
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 Michael A. Heroux (maherou@sandia.gov)
00039 //
00040 // ***********************************************************************
00041 //@HEADER
00042 */
00043 
00044 #include "EpetraExt_DiagonalQuadraticResponseOnlyModelEvaluator.hpp"
00045 #include "Teuchos_ScalarTraits.hpp"
00046 #include "Epetra_SerialComm.h"
00047 #include "Epetra_CrsMatrix.h"
00048 
00049 
00050 namespace EpetraExt {
00051 
00052 
00053 DiagonalQuadraticResponseOnlyModelEvaluator
00054 ::DiagonalQuadraticResponseOnlyModelEvaluator(
00055   const Teuchos::RCP<Epetra_Comm> &comm,
00056   const int localDim, const double &pt, const double &p0, const double &scale
00057   )
00058   :epetra_comm_(comm), scale_(scale)
00059 {
00060 
00061   using Teuchos::rcp;
00062 
00063   const int ng = 1;
00064 
00065   map_p_ = rcp(new Epetra_Map(-1, localDim, 0, *epetra_comm_));
00066   map_g_ = rcp(new Epetra_Map(ng, ng, 0, *epetra_comm_));
00067 
00068   pt_ = rcp(new Epetra_Vector(*map_p_));
00069   pt_->PutScalar(pt);
00070 
00071   p0_ = rcp(new Epetra_Vector(*map_p_));
00072   p0_->PutScalar(p0);
00073 
00074 }
00075 
00076 
00077 // Overridden from EpetraExt::ModelEvaluator
00078 
00079 
00080 Teuchos::RefCountPtr<const Epetra_Map>
00081 DiagonalQuadraticResponseOnlyModelEvaluator::get_x_map() const
00082 {
00083   return Teuchos::null;
00084 }
00085 
00086 
00087 Teuchos::RefCountPtr<const Epetra_Map>
00088 DiagonalQuadraticResponseOnlyModelEvaluator::get_f_map() const
00089 {
00090   return Teuchos::null;
00091 }
00092 
00093 
00094 Teuchos::RefCountPtr<const Epetra_Map>
00095 DiagonalQuadraticResponseOnlyModelEvaluator::get_p_map(int l) const
00096 {
00097   TEUCHOS_TEST_FOR_EXCEPT(l!=0);
00098   return map_p_;
00099 }
00100 
00101 
00102 Teuchos::RefCountPtr<const Epetra_Map>
00103 DiagonalQuadraticResponseOnlyModelEvaluator::get_g_map(int j) const
00104 {
00105   TEUCHOS_TEST_FOR_EXCEPT(j!=0);
00106   return map_g_;
00107 }
00108 
00109 
00110 Teuchos::RefCountPtr<const Epetra_Vector>
00111 DiagonalQuadraticResponseOnlyModelEvaluator::get_p_init(int l) const
00112 {
00113   TEUCHOS_TEST_FOR_EXCEPT(l!=0);
00114   return p0_;
00115 }
00116 
00117 
00118 EpetraExt::ModelEvaluator::InArgs
00119 DiagonalQuadraticResponseOnlyModelEvaluator::createInArgs() const
00120 {
00121   InArgsSetup inArgs;
00122   inArgs.setModelEvalDescription(this->description());
00123   inArgs.set_Np(1);
00124   return inArgs;
00125 }
00126 
00127 
00128 EpetraExt::ModelEvaluator::OutArgs
00129 DiagonalQuadraticResponseOnlyModelEvaluator::createOutArgs() const
00130 {
00131   OutArgsSetup outArgs;
00132   outArgs.setModelEvalDescription(this->description());
00133   outArgs.set_Np_Ng(1, 1);
00134   outArgs.setSupports(OUT_ARG_DgDp, 0, 0, DERIV_TRANS_MV_BY_ROW);
00135   outArgs.set_DgDp_properties(
00136     0, 0, DerivativeProperties(
00137       DERIV_LINEARITY_NONCONST,
00138       DERIV_RANK_DEFICIENT,
00139       true // supportsAdjoint
00140       )
00141     );
00142   return outArgs;
00143 }
00144 
00145 
00146 void DiagonalQuadraticResponseOnlyModelEvaluator::evalModel(
00147   const InArgs& inArgs, const OutArgs& outArgs
00148   ) const
00149 {
00150 
00151   using Teuchos::RCP;
00152   using Teuchos::dyn_cast;
00153   using Teuchos::rcp_dynamic_cast;
00154 
00155   //
00156   // Get the input arguments
00157   //
00158 
00159   const Epetra_Vector &p = *inArgs.get_p(0);
00160 
00161   //
00162   // Get the output arguments
00163   //
00164 
00165   const RCP<Epetra_Vector> g_out = outArgs.get_g(0);
00166 
00167   const RCP<Epetra_MultiVector> DgDp_trans_out =
00168     get_DgDp_mv(0, 0,outArgs,DERIV_TRANS_MV_BY_ROW);
00169 
00170   //
00171   // Compute the functions
00172   //
00173 
00174   if (nonnull(g_out) || nonnull(DgDp_trans_out)) {
00175 
00176     Epetra_Vector p_minus_pt(*map_p_);
00177 
00178     p_minus_pt = p;
00179     p_minus_pt.Update(-1.0, *pt_, 1.0);
00180 
00181     if (nonnull(g_out)) {
00182       double dot[1];
00183       p_minus_pt.Dot(p_minus_pt, dot);
00184       (*g_out)[0] = scale_ * 0.5 * dot[0];
00185     }
00186     
00187     if (nonnull(DgDp_trans_out)) {
00188       (*DgDp_trans_out) = p_minus_pt;
00189       DgDp_trans_out->Scale(scale_);
00190     }
00191 
00192   }
00193 
00194 }
00195 
00196 
00197 } // namespace EpetraExt
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines