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"
67 #include "adolc/taping.h"
86 #define ad_GRAD_MAX 130
95 static const unsigned int nqp = 2;
96 static const unsigned int nnode = 2;
106 for (
unsigned int i=0;
i<
nqp;
i++) {
111 jac[
i] = 0.5*mesh_spacing;
114 phi[
i][0] = 0.5*(1.0 - xi[
i]);
115 phi[
i][1] = 0.5*(1.0 + xi[
i]);
122 template <
class FadType>
125 const std::vector<double>&
x,
126 std::vector<FadType>& x_fad) {
127 for (
unsigned int node=0; node<e.
nnode; node++)
128 for (
unsigned int eqn=0; eqn<neqn; eqn++)
129 x_fad[node*neqn+eqn] =
FadType(e.
nnode*neqn, node*neqn+eqn,
130 x[e.
gid[node]*neqn+eqn]);
136 const std::vector<T>&
x,
141 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
142 for (
unsigned int eqn=0; eqn<neqn; eqn++) {
143 u[qp*neqn+eqn] = 0.0;
144 du[qp*neqn+eqn] = 0.0;
145 for (
unsigned int node=0; node<e.
nnode; node++) {
146 u[qp*neqn+eqn] += x[node*neqn+eqn] * e.
phi[qp][node];
147 du[qp*neqn+eqn] += x[node*neqn+eqn] * e.
dphi[qp][node];
153 std::vector<T> s(e.
nqp);
154 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
156 for (
unsigned int eqn=0; eqn<neqn; eqn++)
157 s[qp] += u[qp*neqn+eqn]*u[qp*neqn+eqn];
161 for (
unsigned int node=0; node<e.
nnode; node++) {
162 for (
unsigned int eqn=0; eqn<neqn; eqn++) {
163 unsigned int row = node*neqn+eqn;
165 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
166 double c1 = e.
w[qp]*e.
jac[qp];
167 double c2 = -e.
dphi[qp][node]/(e.
jac[qp]*e.
jac[qp]);
169 c1*(c2*du[qp*neqn+eqn] + e.
phi[qp][node]*s[qp]*
exp(u[qp*neqn+eqn]));
175 template <
class FadType>
178 const std::vector<FadType>& f_fad,
179 std::vector<double>& f,
180 std::vector< std::vector<double> >& jac) {
181 for (
unsigned int eqn_row=0; eqn_row<neqn; eqn_row++) {
182 f[e.
gid[0]*neqn+eqn_row] += f_fad[0*neqn+eqn_row].val();
183 f[e.
gid[1]*neqn+eqn_row] += f_fad[1*neqn+eqn_row].val();
184 for (
unsigned int node_col=0; node_col<e.
nnode; node_col++) {
185 for (
unsigned int eqn_col=0; eqn_col<neqn; eqn_col++) {
186 unsigned int col = node_col*neqn+eqn_col;
187 unsigned int next_col = (node_col+1)*neqn+eqn_col;
188 jac[e.
gid[0]*neqn+eqn_row][next_col] +=
189 f_fad[0*neqn+eqn_row].fastAccessDx(col);
190 jac[e.
gid[1]*neqn+eqn_row][col] +=
191 f_fad[1*neqn+eqn_row].fastAccessDx(col);
197 template <
class FadType>
199 double mesh_spacing) {
203 std::vector<double>
x(num_nodes*num_eqns),
f(num_nodes*num_eqns);
204 std::vector< std::vector<double> > jac(num_nodes*num_eqns);
205 for (
unsigned int node_row=0; node_row<num_nodes; node_row++) {
206 for (
unsigned int eqn_row=0; eqn_row<num_eqns; eqn_row++) {
207 unsigned int row = node_row*num_eqns + eqn_row;
208 x[row] = (mesh_spacing*node_row - 0.5)*(mesh_spacing*node_row - 0.5);
210 jac[row] = std::vector<double>((e.
nnode+1)*num_eqns);
211 for (
unsigned int node_col=0; node_col<e.
nnode+1; node_col++) {
212 for (
unsigned int eqn_col=0; eqn_col<num_eqns; eqn_col++) {
213 unsigned int col = node_col*num_eqns + eqn_col;
222 std::vector<FadType> x_fad(e.
nnode*num_eqns), f_fad(e.
nnode*num_eqns);
223 std::vector<FadType> u(e.
nqp*num_eqns), du(e.
nqp*num_eqns);
224 for (
unsigned int i=0;
i<num_nodes-1;
i++) {
251 double mesh_spacing);
252 double residual_fill(
unsigned int num_nodes,
unsigned int num_eqns,
253 double mesh_spacing);
256 #ifndef ADOLC_TAPELESS
257 void adolc_init_fill(
bool retape,
261 const std::vector<double>&
x,
262 std::vector<double>& x_local,
263 std::vector<adouble>& x_ad);
265 void adolc_process_fill(
bool retape,
269 std::vector<double>& x_local,
270 std::vector<adouble>& f_ad,
271 std::vector<double>& f,
272 std::vector<double>& f_local,
273 std::vector< std::vector<double> >& jac,
277 double adolc_jac_fill(
unsigned int num_nodes,
unsigned int num_eqns,
278 double mesh_spacing);
280 double adolc_retape_jac_fill(
unsigned int num_nodes,
unsigned int num_eqns,
281 double mesh_spacing);
285 void adolc_tapeless_init_fill(
const ElemData& e,
287 const std::vector<double>&
x,
288 std::vector<adtl::adouble>& x_ad);
290 void adolc_tapeless_process_fill(
const ElemData& e,
292 const std::vector<adtl::adouble>& f_ad,
293 std::vector<double>& f,
294 std::vector< std::vector<double> >& jac);
296 double adolc_tapeless_jac_fill(
unsigned int num_nodes,
unsigned int num_eqns,
297 double mesh_spacing);
303 void adic_init_fill(
const ElemData& e,
305 const std::vector<double>&
x,
306 std::vector<DERIV_TYPE>& x_fad);
308 void adic_process_fill(
const ElemData& e,
310 const std::vector<DERIV_TYPE>& f_fad,
311 std::vector<double>& f,
312 std::vector< std::vector<double> >& jac);
313 double adic_jac_fill(
unsigned int num_nodes,
unsigned int num_eqns,
314 double mesh_spacing);
315 inline void AD_Init(
int arg0) {
316 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)