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

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