10 #ifndef FE_JAC_FILL_FUNCS_HPP
11 #define FE_JAC_FILL_FUNCS_HPP
27 #ifdef PACKAGE_BUGREPORT
28 #undef PACKAGE_BUGREPORT
33 #ifdef PACKAGE_TARNAME
34 #undef PACKAGE_TARNAME
36 #ifdef PACKAGE_VERSION
37 #undef PACKAGE_VERSION
43 #define NUMBER_DIRECTIONS 100
44 #include "adolc/adouble.h"
45 #include "adolc/drivers/drivers.h"
46 #include "adolc/interfaces.h"
47 #include "adolc/taping.h"
66 #define ad_GRAD_MAX 130
75 static const unsigned int nqp = 2;
76 static const unsigned int nnode = 2;
86 for (
unsigned int i=0;
i<
nqp;
i++) {
91 jac[
i] = 0.5*mesh_spacing;
94 phi[
i][0] = 0.5*(1.0 - xi[
i]);
95 phi[
i][1] = 0.5*(1.0 + xi[
i]);
102 template <
class FadType>
105 const std::vector<double>&
x,
106 std::vector<FadType>& x_fad) {
107 for (
unsigned int node=0; node<e.
nnode; node++)
108 for (
unsigned int eqn=0; eqn<neqn; eqn++)
109 x_fad[node*neqn+eqn] =
FadType(e.
nnode*neqn, node*neqn+eqn,
110 x[e.
gid[node]*neqn+eqn]);
116 const std::vector<T>&
x,
121 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
122 for (
unsigned int eqn=0; eqn<neqn; eqn++) {
123 u[qp*neqn+eqn] = 0.0;
124 du[qp*neqn+eqn] = 0.0;
125 for (
unsigned int node=0; node<e.
nnode; node++) {
126 u[qp*neqn+eqn] += x[node*neqn+eqn] * e.
phi[qp][node];
127 du[qp*neqn+eqn] += x[node*neqn+eqn] * e.
dphi[qp][node];
133 std::vector<T> s(e.
nqp);
134 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
136 for (
unsigned int eqn=0; eqn<neqn; eqn++)
137 s[qp] += u[qp*neqn+eqn]*u[qp*neqn+eqn];
141 for (
unsigned int node=0; node<e.
nnode; node++) {
142 for (
unsigned int eqn=0; eqn<neqn; eqn++) {
143 unsigned int row = node*neqn+eqn;
145 for (
unsigned int qp=0; qp<e.
nqp; qp++) {
146 double c1 = e.
w[qp]*e.
jac[qp];
147 double c2 = -e.
dphi[qp][node]/(e.
jac[qp]*e.
jac[qp]);
149 c1*(c2*du[qp*neqn+eqn] + e.
phi[qp][node]*s[qp]*
exp(u[qp*neqn+eqn]));
155 template <
class FadType>
158 const std::vector<FadType>& f_fad,
159 std::vector<double>& f,
160 std::vector< std::vector<double> >& jac) {
161 for (
unsigned int eqn_row=0; eqn_row<neqn; eqn_row++) {
162 f[e.
gid[0]*neqn+eqn_row] += f_fad[0*neqn+eqn_row].val();
163 f[e.
gid[1]*neqn+eqn_row] += f_fad[1*neqn+eqn_row].val();
164 for (
unsigned int node_col=0; node_col<e.
nnode; node_col++) {
165 for (
unsigned int eqn_col=0; eqn_col<neqn; eqn_col++) {
166 unsigned int col = node_col*neqn+eqn_col;
167 unsigned int next_col = (node_col+1)*neqn+eqn_col;
168 jac[e.
gid[0]*neqn+eqn_row][next_col] +=
169 f_fad[0*neqn+eqn_row].fastAccessDx(col);
170 jac[e.
gid[1]*neqn+eqn_row][col] +=
171 f_fad[1*neqn+eqn_row].fastAccessDx(col);
177 template <
class FadType>
179 double mesh_spacing) {
183 std::vector<double>
x(num_nodes*num_eqns),
f(num_nodes*num_eqns);
184 std::vector< std::vector<double> > jac(num_nodes*num_eqns);
185 for (
unsigned int node_row=0; node_row<num_nodes; node_row++) {
186 for (
unsigned int eqn_row=0; eqn_row<num_eqns; eqn_row++) {
187 unsigned int row = node_row*num_eqns + eqn_row;
188 x[row] = (mesh_spacing*node_row - 0.5)*(mesh_spacing*node_row - 0.5);
190 jac[row] = std::vector<double>((e.
nnode+1)*num_eqns);
191 for (
unsigned int node_col=0; node_col<e.
nnode+1; node_col++) {
192 for (
unsigned int eqn_col=0; eqn_col<num_eqns; eqn_col++) {
193 unsigned int col = node_col*num_eqns + eqn_col;
202 std::vector<FadType> x_fad(e.
nnode*num_eqns), f_fad(e.
nnode*num_eqns);
203 std::vector<FadType> u(e.
nqp*num_eqns), du(e.
nqp*num_eqns);
204 for (
unsigned int i=0;
i<num_nodes-1;
i++) {
231 double mesh_spacing);
232 double residual_fill(
unsigned int num_nodes,
unsigned int num_eqns,
233 double mesh_spacing);
236 #ifndef ADOLC_TAPELESS
237 void adolc_init_fill(
bool retape,
241 const std::vector<double>&
x,
242 std::vector<double>& x_local,
243 std::vector<adouble>& x_ad);
245 void adolc_process_fill(
bool retape,
249 std::vector<double>& x_local,
250 std::vector<adouble>& f_ad,
251 std::vector<double>& f,
252 std::vector<double>& f_local,
253 std::vector< std::vector<double> >& jac,
257 double adolc_jac_fill(
unsigned int num_nodes,
unsigned int num_eqns,
258 double mesh_spacing);
260 double adolc_retape_jac_fill(
unsigned int num_nodes,
unsigned int num_eqns,
261 double mesh_spacing);
265 void adolc_tapeless_init_fill(
const ElemData& e,
267 const std::vector<double>&
x,
268 std::vector<adtl::adouble>& x_ad);
270 void adolc_tapeless_process_fill(
const ElemData& e,
272 const std::vector<adtl::adouble>& f_ad,
273 std::vector<double>& f,
274 std::vector< std::vector<double> >& jac);
276 double adolc_tapeless_jac_fill(
unsigned int num_nodes,
unsigned int num_eqns,
277 double mesh_spacing);
283 void adic_init_fill(
const ElemData& e,
285 const std::vector<double>&
x,
286 std::vector<DERIV_TYPE>& x_fad);
288 void adic_process_fill(
const ElemData& e,
290 const std::vector<DERIV_TYPE>& f_fad,
291 std::vector<double>& f,
292 std::vector< std::vector<double> >& jac);
293 double adic_jac_fill(
unsigned int num_nodes,
unsigned int num_eqns,
294 double mesh_spacing);
295 inline void AD_Init(
int arg0) {
296 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)