// @HEADER // ***************************************************************************** // Sacado Package // // Copyright 2006 NTESS and the Sacado contributors. // SPDX-License-Identifier: LGPL-2.1-or-later // ***************************************************************************** // @HEADER #ifndef FE_JAC_FILL_FUNCS_HPP #define FE_JAC_FILL_FUNCS_HPP #include "Sacado_No_Kokkos.hpp" #include "Sacado_Fad_SimpleFad.hpp" #include "Teuchos_Time.hpp" #include "Teuchos_CommandLineProcessor.hpp" // ADOL-C includes #ifdef HAVE_ADOLC #ifdef PACKAGE #undef PACKAGE #endif #ifdef PACKAGE_NAME #undef PACKAGE_NAME #endif #ifdef PACKAGE_BUGREPORT #undef PACKAGE_BUGREPORT #endif #ifdef PACKAGE_STRING #undef PACKAGE_STRING #endif #ifdef PACKAGE_TARNAME #undef PACKAGE_TARNAME #endif #ifdef PACKAGE_VERSION #undef PACKAGE_VERSION #endif #ifdef VERSION #undef VERSION #endif //#define ADOLC_TAPELESS #define NUMBER_DIRECTIONS 100 #include "adolc/adouble.h" #include "adolc/drivers/drivers.h" #include "adolc/interfaces.h" #include "adolc/taping.h" #endif #ifdef HAVE_ADIC // We have included an ADIC differentiated version of the element fill // routine to compare the speed of operator overloading to source // transformation. To run this code, all that is necessary is to turn // on the ADIC TPL. However to modify the code, it is necessary to // re-run the ADIC source transformation tool. To do so, first update // the changes to adic_element_fill.c. Then set the following environment // variables: // export ADIC_ARCH=linux // export ADIC=/home/etphipp/AD_libs/adic // Next run ADIC via in the tests/performance source directory: // ${ADIC}/bin/linux/adiC -vd gradient -i adic_element_fill.init // Finally, copy the resulting differentiated function in adic_element_fill.ad.c // back into this file. The function will need to be edited by changing // the allocation of s to a std::vector (the compiler // doesn't seem to like malloc), and commenting out the g_filenum lines. #define ad_GRAD_MAX 130 #include "ad_deriv.h" #endif // A performance test that computes a finite-element-like Jacobian using // several Fad variants struct ElemData { static const unsigned int nqp = 2; static const unsigned int nnode = 2; double w[nqp], jac[nqp], phi[nqp][nnode], dphi[nqp][nnode]; unsigned int gid[nnode]; ElemData(double mesh_spacing) { // Quadrature points double xi[nqp]; xi[0] = -1.0 / std::sqrt(3.0); xi[1] = 1.0 / std::sqrt(3.0); for (unsigned int i=0; i void fad_init_fill(const ElemData& e, unsigned int neqn, const std::vector& x, std::vector& x_fad) { for (unsigned int node=0; node void template_element_fill(const ElemData& e, unsigned int neqn, const std::vector& x, std::vector& u, std::vector& du, std::vector& f) { // Construct element solution, derivative for (unsigned int qp=0; qp s(e.nqp); for (unsigned int qp=0; qp void fad_process_fill(const ElemData& e, unsigned int neqn, const std::vector& f_fad, std::vector& f, std::vector< std::vector >& jac) { for (unsigned int eqn_row=0; eqn_row double fad_jac_fill(unsigned int num_nodes, unsigned int num_eqns, double mesh_spacing) { ElemData e(mesh_spacing); // Solution vector, residual, jacobian std::vector x(num_nodes*num_eqns), f(num_nodes*num_eqns); std::vector< std::vector > jac(num_nodes*num_eqns); for (unsigned int node_row=0; node_row((e.nnode+1)*num_eqns); for (unsigned int node_col=0; node_col x_fad(e.nnode*num_eqns), f_fad(e.nnode*num_eqns); std::vector u(e.nqp*num_eqns), du(e.nqp*num_eqns); for (unsigned int i=0; i& x, std::vector& x_local, std::vector& x_ad); void adolc_process_fill(bool retape, int tag, const ElemData& e, unsigned int neqn, std::vector& x_local, std::vector& f_ad, std::vector& f, std::vector& f_local, std::vector< std::vector >& jac, double **seed, double **jac_local); double adolc_jac_fill(unsigned int num_nodes, unsigned int num_eqns, double mesh_spacing); double adolc_retape_jac_fill(unsigned int num_nodes, unsigned int num_eqns, double mesh_spacing); #else void adolc_tapeless_init_fill(const ElemData& e, unsigned int neqn, const std::vector& x, std::vector& x_ad); void adolc_tapeless_process_fill(const ElemData& e, unsigned int neqn, const std::vector& f_ad, std::vector& f, std::vector< std::vector >& jac); double adolc_tapeless_jac_fill(unsigned int num_nodes, unsigned int num_eqns, double mesh_spacing); #endif #endif #ifdef HAVE_ADIC void adic_init_fill(const ElemData& e, unsigned int neqn, const std::vector& x, std::vector& x_fad); void adic_element_fill(ElemData *e,unsigned int neqn,DERIV_TYPE *x,DERIV_TYPE *u,DERIV_TYPE *du,DERIV_TYPE *f); void adic_process_fill(const ElemData& e, unsigned int neqn, const std::vector& f_fad, std::vector& f, std::vector< std::vector >& jac); double adic_jac_fill(unsigned int num_nodes, unsigned int num_eqns, double mesh_spacing); inline void AD_Init(int arg0) { ad_AD_GradInit(arg0); } inline void AD_Final() { ad_AD_GradFinal(); } #endif #endif