FEApp_DakotaElementJacobianInterface.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 "Sacado_ConfigDefs.h"
00033 
00034 #ifdef HAVE_DAKOTA
00035 
00036 #include "FEApp_DakotaElementJacobianInterface.hpp"
00037 #include "Teuchos_TestForException.hpp"
00038 
00039 // Define interface class
00040 FEApp::DakotaElementJacobianInterface::
00041 DakotaElementJacobianInterface(
00042       const Dakota::ProblemDescDB& problem_db_,
00043       const Teuchos::RCP< FEApp::AbstractPDE<FEApp::JacobianType> >& pde_,
00044       const ParamVec& pvec_,
00045       const Teuchos::RCP<const FEApp::AbstractQuadrature>& quad_,
00046       unsigned int ndof_,
00047       double alpha_,
00048       double beta_) : 
00049   Dakota::DirectApplicInterface(problem_db_),
00050   pde(pde_),
00051   pvec(pvec_),
00052   quad(quad_),
00053   numParameters(pvec.size()),
00054   numEquations(ndof_),
00055   e(),
00056   sg_xdot(),
00057   sg_x(),
00058   xdot(numEquations),
00059   x(numEquations),
00060   f(numEquations),
00061   alpha(alpha_),
00062   beta(beta_)
00063 {
00064   for (unsigned int i=0; i<numEquations; i++) {
00065     x[i].resize(numEquations);
00066     xdot[i].resize(numEquations);
00067     x[i].fastAccessDx(i) = beta;
00068     xdot[i].fastAccessDx(i) = alpha;
00069   }
00070 }
00071 
00072 void
00073 FEApp::DakotaElementJacobianInterface::
00074 reset(const Teuchos::RCP<const FEApp::AbstractElement>& e_,
00075       const Teuchos::RCP< std::vector<SGFadType> >& sg_xdot_,
00076       const Teuchos::RCP< std::vector<SGFadType> >& sg_x_)
00077 {
00078   e = e_;
00079   sg_xdot = sg_xdot_;
00080   sg_x = sg_x_;
00081 }
00082 
00083 int 
00084 FEApp::DakotaElementJacobianInterface::
00085 derived_map_ac(const Dakota::String& ac_name)
00086 {
00087   // test for consistency of problem definition between ModelEval and Dakota
00088   TEST_FOR_EXCEPTION(numVars != numParameters, logic_error,
00089                      "FEApp_Dakota Adapter Error: ");
00090   TEST_FOR_EXCEPTION(numADV != 0, logic_error,
00091                      "FEApp_Dakota Adapter Error: ");
00092   TEST_FOR_EXCEPTION(numFns != numEquations*numEquations, logic_error,
00093                      "FEApp_Dakota Adapter Error: ");
00094   TEST_FOR_EXCEPTION(hessFlag, logic_error,
00095                      "FEApp_Dakota Adapter Error: ");
00096   TEST_FOR_EXCEPTION(gradFlag, logic_error,
00097                      "FEApp_Dakota Adapter Error: ");
00098 
00099   // Set parameters in FEApp
00100   for (std::size_t i=0; i<pvec.size(); ++i)
00101     pvec[i].family->setRealValue<FEApp::JacobianType>(xC[i]);
00102 
00103   std::vector<double> xxC(xC.length());
00104   for (int i=0; i<xC.length(); i++)
00105     xxC[i] = xC[i];
00106 
00107   // Evaluate xdot, x on SG basis
00108   for (unsigned int i=0; i<numEquations; i++) {
00109     x[i].val() = ((*sg_x)[i]).val().evaluate(xxC);
00110     if (sg_xdot != Teuchos::null)
00111       xdot[i].val() = ((*sg_xdot)[i]).val().evaluate(xxC);
00112   }
00113   
00114   // Evaluate element residual
00115   if (sg_xdot != Teuchos::null)
00116     pde->evaluateElementResidual(*quad, *e, &xdot, x, f);
00117   else
00118     pde->evaluateElementResidual(*quad, *e, NULL, x, f);
00119   
00120   // Load function values back into Dakota vector
00121   for (std::size_t i=0; i<numEquations; i++)
00122     for (std::size_t j=0; j<numEquations; j++) {
00123       fnVals[j+i*numEquations] = f[i].fastAccessDx(j);
00124   }
00125 
00126   return 0;
00127 }
00128 
00129 #endif // HAVE_DAKOTA
00130 

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