FEApp_BoundaryFlux1DResponseFunction.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_BoundaryFlux1DResponseFunction.hpp"
00033 
00034 FEApp::BoundaryFlux1DResponseFunction::
00035 BoundaryFlux1DResponseFunction(unsigned int left_gid,
00036                                unsigned int right_gid,
00037                                unsigned int eqn,
00038                                unsigned int num_eqns,
00039                                double grid_spacing_,
00040                                const Epetra_Map& dofMap) :
00041   grid_spacing(grid_spacing_),
00042   importer(NULL),
00043   bv(NULL)
00044 {
00045   // Compute GID's of left/right DOF's
00046   unsigned int left_dof = num_eqns*left_gid+eqn;
00047   unsigned int right_dof = num_eqns*right_gid+eqn;
00048 
00049   // Build importer to bring in left/right DOF's to all proc's
00050   int gids[4];
00051   gids[0] = left_dof;
00052   gids[1] = left_dof+num_eqns;
00053   gids[2] = right_dof-num_eqns;
00054   gids[3] = right_dof;
00055   boundaryMap = new Epetra_Map(4, 4, gids, 0, dofMap.Comm());
00056   importer = new Epetra_Import(*boundaryMap, dofMap);
00057   bv = new Epetra_Vector(*boundaryMap);
00058 }
00059 
00060 FEApp::BoundaryFlux1DResponseFunction::
00061 ~BoundaryFlux1DResponseFunction()
00062 {
00063   delete boundaryMap;
00064   delete importer;
00065   delete bv;
00066 }
00067 
00068 unsigned int
00069 FEApp::BoundaryFlux1DResponseFunction::
00070 numResponses() const 
00071 {
00072   return 2;
00073 }
00074 
00075 void
00076 FEApp::BoundaryFlux1DResponseFunction::
00077 evaluateResponses(const Epetra_Vector* xdot,
00078       const Epetra_Vector& x,
00079       const Teuchos::Array< Teuchos::RCP<ParamVec> >& p,
00080       Epetra_Vector& g)
00081 {
00082   // Import boundary values
00083   bv->Import(x, *importer, Insert);
00084 
00085   // Compute fluxes
00086   g[0] = ((*bv)[1] - (*bv)[0]) / grid_spacing;
00087   g[1] = ((*bv)[3] - (*bv)[2]) / grid_spacing;
00088 }
00089 
00090 void
00091 FEApp::BoundaryFlux1DResponseFunction::
00092 evaluateTangents(
00093      const Epetra_Vector* xdot,
00094      const Epetra_Vector& x,
00095      const Teuchos::Array< Teuchos::RCP<ParamVec> >& p,
00096      const Teuchos::Array< Teuchos::RCP<ParamVec> >& deriv_p,
00097      const Teuchos::Array< Teuchos::RCP<Epetra_MultiVector> >& dxdot_dp,
00098      const Teuchos::Array< Teuchos::RCP<Epetra_MultiVector> >& dx_dp,
00099      Epetra_Vector* g,
00100      const Teuchos::Array< Teuchos::RCP<Epetra_MultiVector> >& gt)
00101 {
00102   // Evaluate response g
00103   if (g != NULL) {
00104     bv->Import(x, *importer, Insert);
00105     (*g)[0] = ((*bv)[1] - (*bv)[0]) / grid_spacing;
00106     (*g)[1] = ((*bv)[3] - (*bv)[2]) / grid_spacing;
00107   }
00108 
00109   // Evaluate tangent of g = dg/dx*dx/dp + dg/dxdot*dxdot/dp + dg/dp
00110   for (unsigned int j=0; j<gt.size(); j++)
00111     if (gt[j] != Teuchos::null) {
00112       Epetra_MultiVector bvt(*boundaryMap, dx_dp[j]->NumVectors());
00113       bvt.Import(*dx_dp[j], *importer, Insert);
00114       for (int i=0; i<dx_dp[j]->NumVectors(); i++) {
00115   (*gt[j])[i][0] = (bvt[i][1] - bvt[i][0]) / grid_spacing;
00116   (*gt[j])[i][1] = (bvt[i][3] - bvt[i][2]) / grid_spacing;
00117       }
00118     }
00119 }
00120 
00121 void
00122 FEApp::BoundaryFlux1DResponseFunction::
00123 evaluateGradients(
00124     const Epetra_Vector* xdot,
00125     const Epetra_Vector& x,
00126     const Teuchos::Array< Teuchos::RCP<ParamVec> >& p,
00127     const Teuchos::Array< Teuchos::RCP<ParamVec> >& deriv_p,
00128     Epetra_Vector* g,
00129     Epetra_MultiVector* dg_dx,
00130     Epetra_MultiVector* dg_dxdot,
00131     const Teuchos::Array< Teuchos::RCP<Epetra_MultiVector> >& dg_dp)
00132 {
00133 
00134   // Evaluate response g
00135   if (g != NULL) {
00136     bv->Import(x, *importer, Insert);
00137     (*g)[0] = ((*bv)[1] - (*bv)[0]) / grid_spacing;
00138     (*g)[1] = ((*bv)[3] - (*bv)[2]) / grid_spacing;
00139   }
00140 
00141   // Evaluate dg/dx
00142   if (dg_dx != NULL) {
00143     Epetra_MultiVector bv_dx(*boundaryMap, 2);
00144     bv_dx.PutScalar(0.0);
00145     bv_dx[0][0] = -1.0 / grid_spacing;
00146     bv_dx[0][1] =  1.0 / grid_spacing;
00147     bv_dx[1][2] = -1.0 / grid_spacing;
00148     bv_dx[1][3] =  1.0 / grid_spacing;
00149     dg_dx->PutScalar(0.0);
00150     dg_dx->Export(bv_dx, *importer, Insert);
00151   }
00152 
00153   // Evaluate dg/dxdot
00154   if (dg_dxdot != NULL)
00155     dg_dxdot->PutScalar(0.0);
00156 
00157   // Evaluate dg/dp
00158   for (unsigned int j=0; j<dg_dp.size(); j++)
00159     if (dg_dp[j] != Teuchos::null)
00160       dg_dp[j]->PutScalar(0.0);
00161 }
00162 
00163 #if SG_ACTIVE
00164 void
00165 FEApp::BoundaryFlux1DResponseFunction::
00166 evaluateSGResponses(const Stokhos::VectorOrthogPoly<Epetra_Vector>* sg_xdot,
00167         const Stokhos::VectorOrthogPoly<Epetra_Vector>& sg_x,
00168         const ParamVec* p,
00169         const ParamVec* sg_p,
00170         const Teuchos::Array<SGType>* sg_p_vals,
00171         Stokhos::VectorOrthogPoly<Epetra_Vector>& sg_g)
00172 {
00173   unsigned int sz = sg_x.size();
00174   for (unsigned int i=0; i<sz; i++) {
00175 
00176     // Import boundary values
00177     bv->Import(sg_x[i], *importer, Insert);
00178     
00179     // Compute fluxes
00180     sg_g[i][0] = ((*bv)[1] - (*bv)[0]) / grid_spacing;
00181     sg_g[i][1] = ((*bv)[3] - (*bv)[2]) / grid_spacing;
00182 
00183   }
00184 }
00185 #endif

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