30 #ifndef FE_JAC_FILL_FUNCS_HPP
31 #define FE_JAC_FILL_FUNCS_HPP
47 #ifdef PACKAGE_BUGREPORT
48 #undef PACKAGE_BUGREPORT
53 #ifdef PACKAGE_TARNAME
54 #undef PACKAGE_TARNAME
56 #ifdef PACKAGE_VERSION
57 #undef PACKAGE_VERSION
63 #define NUMBER_DIRECTIONS 100
64 #include "adolc/adouble.h"
65 #include "adolc/drivers/drivers.h"
66 #include "adolc/interfaces.h"
85 #define ad_GRAD_MAX 130
94 static const unsigned int nqp = 2;
95 static const unsigned int nnode = 2;
105 for (
unsigned int i=0; i<
nqp; i++) {
110 jac[i] = 0.5*mesh_spacing;
113 phi[i][0] = 0.5*(1.0 - xi[i]);
114 phi[i][1] = 0.5*(1.0 + xi[i]);
121 template <
class FadType>
124 const std::vector<double>& x,
125 std::vector<FadType>& x_fad) {
126 for (
unsigned int node=0; node<e.
nnode; node++)
127 for (
unsigned int eqn=0; eqn<neqn; eqn++)
128 x_fad[node*neqn+eqn] =
FadType(e.
nnode*neqn, node*neqn+eqn,
129 x[e.
gid[node]*neqn+eqn]);
135 const std::vector<T>& x,
140 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
141 for (
unsigned int eqn=0; eqn<neqn; eqn++) {
142 u[qp*neqn+eqn] = 0.0;
143 du[qp*neqn+eqn] = 0.0;
144 for (
unsigned int node=0; node<e.
nnode; node++) {
145 u[qp*neqn+eqn] += x[node*neqn+eqn] * e.
phi[qp][node];
146 du[qp*neqn+eqn] += x[node*neqn+eqn] * e.
dphi[qp][node];
152 std::vector<T> s(e.
nqp);
153 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
155 for (
unsigned int eqn=0; eqn<neqn; eqn++)
156 s[qp] += u[qp*neqn+eqn]*u[qp*neqn+eqn];
160 for (
unsigned int node=0; node<e.
nnode; node++) {
161 for (
unsigned int eqn=0; eqn<neqn; eqn++) {
162 unsigned int row = node*neqn+eqn;
164 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
165 double c1 = e.
w[qp]*e.
jac[qp];
166 double c2 = -e.
dphi[qp][node]/(e.
jac[qp]*e.
jac[qp]);
168 c1*(c2*du[qp*neqn+eqn] + e.
phi[qp][node]*s[qp]*
exp(u[qp*neqn+eqn]));
174 template <
class FadType>
177 const std::vector<FadType>& f_fad,
178 std::vector<double>& f,
179 std::vector< std::vector<double> >& jac) {
180 for (
unsigned int eqn_row=0; eqn_row<neqn; eqn_row++) {
181 f[e.
gid[0]*neqn+eqn_row] += f_fad[0*neqn+eqn_row].val();
182 f[e.
gid[1]*neqn+eqn_row] += f_fad[1*neqn+eqn_row].val();
183 for (
unsigned int node_col=0; node_col<e.
nnode; node_col++) {
184 for (
unsigned int eqn_col=0; eqn_col<neqn; eqn_col++) {
185 unsigned int col = node_col*neqn+eqn_col;
186 unsigned int next_col = (node_col+1)*neqn+eqn_col;
187 jac[e.
gid[0]*neqn+eqn_row][next_col] +=
188 f_fad[0*neqn+eqn_row].fastAccessDx(col);
189 jac[e.
gid[1]*neqn+eqn_row][col] +=
190 f_fad[1*neqn+eqn_row].fastAccessDx(col);
196 template <
class FadType>
198 double mesh_spacing) {
202 std::vector<double> x(num_nodes*num_eqns),
f(num_nodes*num_eqns);
203 std::vector< std::vector<double> > jac(num_nodes*num_eqns);
204 for (
unsigned int node_row=0; node_row<num_nodes; node_row++) {
205 for (
unsigned int eqn_row=0; eqn_row<num_eqns; eqn_row++) {
206 unsigned int row = node_row*num_eqns + eqn_row;
207 x[row] = (mesh_spacing*node_row - 0.5)*(mesh_spacing*node_row - 0.5);
209 jac[row] = std::vector<double>((e.
nnode+1)*num_eqns);
210 for (
unsigned int node_col=0; node_col<e.
nnode+1; node_col++) {
211 for (
unsigned int eqn_col=0; eqn_col<num_eqns; eqn_col++) {
212 unsigned int col = node_col*num_eqns + eqn_col;
221 std::vector<FadType> x_fad(e.
nnode*num_eqns), f_fad(e.
nnode*num_eqns);
222 std::vector<FadType> u(e.
nqp*num_eqns), du(e.
nqp*num_eqns);
223 for (
unsigned int i=0; i<num_nodes-1; i++) {
250 double mesh_spacing);
251 double residual_fill(
unsigned int num_nodes,
unsigned int num_eqns,
252 double mesh_spacing);
255 #ifndef ADOLC_TAPELESS
256 void adolc_init_fill(
bool retape,
260 const std::vector<double>& x,
261 std::vector<double>& x_local,
262 std::vector<adouble>& x_ad);
264 void adolc_process_fill(
bool retape,
268 std::vector<double>& x_local,
269 std::vector<adouble>& f_ad,
270 std::vector<double>& f,
271 std::vector<double>& f_local,
272 std::vector< std::vector<double> >& jac,
276 double adolc_jac_fill(
unsigned int num_nodes,
unsigned int num_eqns,
277 double mesh_spacing);
279 double adolc_retape_jac_fill(
unsigned int num_nodes,
unsigned int num_eqns,
280 double mesh_spacing);
284 void adolc_tapeless_init_fill(
const ElemData& e,
286 const std::vector<double>& x,
287 std::vector<adtl::adouble>& x_ad);
289 void adolc_tapeless_process_fill(
const ElemData& e,
291 const std::vector<adtl::adouble>& f_ad,
292 std::vector<double>& f,
293 std::vector< std::vector<double> >& jac);
295 double adolc_tapeless_jac_fill(
unsigned int num_nodes,
unsigned int num_eqns,
296 double mesh_spacing);
302 void adic_init_fill(
const ElemData& e,
304 const std::vector<double>& x,
305 std::vector<DERIV_TYPE>& x_fad);
307 void adic_process_fill(
const ElemData& e,
309 const std::vector<DERIV_TYPE>& f_fad,
310 std::vector<double>& f,
311 std::vector< std::vector<double> >& jac);
312 double adic_jac_fill(
unsigned int num_nodes,
unsigned int num_eqns,
313 double mesh_spacing);
314 inline void AD_Init(
int arg0) {
315 ad_AD_GradInit(arg0);
double residual_fill(unsigned int num_nodes, unsigned int num_eqns, double mesh_spacing)
void template_element_fill(const ElemData &e, unsigned int neqn, const std::vector< T > &x, std::vector< T > &u, std::vector< T > &du, std::vector< T > &f)
void adic_element_fill(ElemData *e, unsigned int neqn, const DERIV_TYPE *x, DERIV_TYPE *u, DERIV_TYPE *du, DERIV_TYPE *f)
double analytic_jac_fill(unsigned int num_nodes, unsigned int num_eqns, double mesh_spacing)
Sacado::Fad::DFad< double > FadType
ElemData(double mesh_spacing)
void fad_init_fill(const ElemData &e, unsigned int neqn, const std::vector< double > &x, std::vector< FadType > &x_fad)
void start(bool reset=false)
void fad_process_fill(const ElemData &e, unsigned int neqn, const std::vector< FadType > &f_fad, std::vector< double > &f, std::vector< std::vector< double > > &jac)
double totalElapsedTime(bool readCurrentTime=false) const
double fad_jac_fill(unsigned int num_nodes, unsigned int num_eqns, double mesh_spacing)