FEApp_SolutionTwoNormResponseFunction.cpp

Go to the documentation of this file.
00001 // $Id$ 
00002 // $Source$ 
00003 // @HEADER
00004 // ***********************************************************************
00005 // 
00006 //                           Sacado Package
00007 //                 Copyright (2006) Sandia Corporation
00008 // 
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 // 
00012 // This library is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU Lesser General Public License as
00014 // published by the Free Software Foundation; either version 2.1 of the
00015 // License, or (at your option) any later version.
00016 //  
00017 // This library is distributed in the hope that it will be useful, but
00018 // WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // Lesser General Public License for more details.
00021 //  
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License along with this library; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 // USA
00026 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
00027 // (etphipp@sandia.gov).
00028 // 
00029 // ***********************************************************************
00030 // @HEADER
00031 
00032 #include "FEApp_SolutionTwoNormResponseFunction.hpp"
00033 #include "Epetra_Comm.h"
00034 
00035 FEApp::SolutionTwoNormResponseFunction::
00036 SolutionTwoNormResponseFunction()
00037 {
00038 }
00039 
00040 FEApp::SolutionTwoNormResponseFunction::
00041 ~SolutionTwoNormResponseFunction()
00042 {
00043 }
00044 
00045 unsigned int
00046 FEApp::SolutionTwoNormResponseFunction::
00047 numResponses() const 
00048 {
00049   return 1;
00050 }
00051 
00052 void
00053 FEApp::SolutionTwoNormResponseFunction::
00054 evaluateResponses(const Epetra_Vector* xdot,
00055       const Epetra_Vector& x,
00056       const Teuchos::Array< Teuchos::RCP<ParamVec> >& p,
00057       Epetra_Vector& g)
00058 {
00059   x.Norm2(&g[0]);
00060 }
00061 
00062 void
00063 FEApp::SolutionTwoNormResponseFunction::
00064 evaluateTangents(
00065      const Epetra_Vector* xdot,
00066      const Epetra_Vector& x,
00067      const Teuchos::Array< Teuchos::RCP<ParamVec> >& p,
00068      const Teuchos::Array< Teuchos::RCP<ParamVec> >& deriv_p,
00069      const Teuchos::Array< Teuchos::RCP<Epetra_MultiVector> >& dxdot_dp,
00070      const Teuchos::Array< Teuchos::RCP<Epetra_MultiVector> >& dx_dp,
00071      Epetra_Vector* g,
00072      const Teuchos::Array< Teuchos::RCP<Epetra_MultiVector> >& gt)
00073 {
00074   // Evaluate response g
00075   if (g != NULL)
00076     x.Norm2(&(*g)[0]);
00077 
00078   // Evaluate tangent of g = dg/dx*dx/dp + dg/dxdot*dxdot/dp + dg/dp
00079   // dg/dx = 1/||x|| * x^T
00080   for (unsigned int j=0; j<gt.size(); j++)
00081     if (gt[j] != Teuchos::null)
00082       gt[j]->Multiply('T','N',1.0,x,*dx_dp[j],0.0);
00083 }
00084 
00085 void
00086 FEApp::SolutionTwoNormResponseFunction::
00087 evaluateGradients(
00088     const Epetra_Vector* xdot,
00089     const Epetra_Vector& x,
00090     const Teuchos::Array< Teuchos::RCP<ParamVec> >& p,
00091     const Teuchos::Array< Teuchos::RCP<ParamVec> >& deriv_p,
00092     Epetra_Vector* g,
00093     Epetra_MultiVector* dg_dx,
00094     Epetra_MultiVector* dg_dxdot,
00095     const Teuchos::Array< Teuchos::RCP<Epetra_MultiVector> >& dg_dp)
00096 {
00097 
00098   // Evaluate response g
00099   if (g != NULL)
00100     x.Norm2(&(*g)[0]);
00101 
00102   // Evaluate dg/dx
00103   if (dg_dx != NULL) {
00104     double nrm;
00105     if (g != NULL)
00106       nrm = (*g)[0];
00107     else
00108       x.Norm2(&nrm);
00109     dg_dx->Scale(1.0/nrm,x);
00110   }
00111 
00112   // Evaluate dg/dxdot
00113   if (dg_dxdot != NULL)
00114     dg_dxdot->PutScalar(0.0);
00115 
00116   // Evaluate dg/dp
00117   for (unsigned int j=0; j<dg_dp.size(); j++)
00118     if (dg_dp[j] != Teuchos::null)
00119       dg_dp[j]->PutScalar(0.0);
00120 }
00121 
00122 #if SG_ACTIVE
00123 void
00124 FEApp::SolutionTwoNormResponseFunction::
00125 evaluateSGResponses(const Stokhos::VectorOrthogPoly<Epetra_Vector>* sg_xdot,
00126         const Stokhos::VectorOrthogPoly<Epetra_Vector>& sg_x,
00127         const ParamVec* p,
00128         const ParamVec* sg_p,
00129         const Teuchos::Array<SGType>* sg_p_vals,
00130         Stokhos::VectorOrthogPoly<Epetra_Vector>& sg_g)
00131 {
00132   int sz = sg_x.size();
00133   int N = sg_x[0].MyLength();
00134   SGType nrm_local = 0.0;
00135   SGType x(sz);
00136   for (int i=0; i<N; i++) {
00137     for (int k=0; k<sz; k++)
00138       x.fastAccessCoeff(k) = sg_x[k][i];
00139     nrm_local += x*x;
00140   }
00141 #ifdef HAVE_MPI
00142   SGType nrm(sz);
00143   sg_x[0].Map().Comm().SumAll(nrm_local.coeff(), nrm.coeff(), sz);
00144 #else
00145   SGType& nrm = nrm_local;
00146 #endif
00147   nrm = std::sqrt(nrm);
00148   for (int k=0; k<sz; k++)
00149     sg_g[k][0] = nrm.fastAccessCoeff(k);
00150 }
00151 #endif

Generated on Wed May 12 21:39:33 2010 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.4.7