Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
adic_element_fill.c
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #include <math.h>
11 #include <stdlib.h>
12 
13 typedef struct {
14  int nqp;
15  int nnode;
16  InactiveDouble *w, *jac, **phi, **dphi;
17  int *gid;
18 } ElemData;
19 
21  unsigned int neqn,
22  const double* x,
23  double* u,
24  double* du,
25  double* f) {
26  /* Construct element solution, derivative */
27  for (unsigned int qp=0; qp<e->nqp; qp++) {
28  for (unsigned int eqn=0; eqn<neqn; eqn++) {
29  u[qp*neqn+eqn] = 0.0;
30  du[qp*neqn+eqn] = 0.0;
31  for (unsigned int node=0; node<e->nnode; node++) {
32  u[qp*neqn+eqn] += x[node*neqn+eqn] * e->phi[qp][node];
33  du[qp*neqn+eqn] += x[node*neqn+eqn] * e->dphi[qp][node];
34  }
35  }
36  }
37 
38  /* Compute sum of equations for coupling */
39  double *s = malloc(e->nqp*sizeof(double));
40  for (unsigned int qp=0; qp<e->nqp; qp++) {
41  s[qp] = 0.0;
42  for (unsigned int eqn=0; eqn<neqn; eqn++)
43  s[qp] += u[qp*neqn+eqn]*u[qp*neqn+eqn];
44  }
45 
46  /* Evaluate element residual */
47  for (unsigned int node=0; node<e->nnode; node++) {
48  for (unsigned int eqn=0; eqn<neqn; eqn++) {
49  unsigned int row = node*neqn+eqn;
50  f[row] = 0.0;
51  for (unsigned int qp=0; qp<e->nqp; qp++) {
52  f[row] +=
53  e->w[qp]*e->jac[qp]*(-e->dphi[qp][node]/(e->jac[qp]*e->jac[qp])*du[qp*neqn+eqn] + e->phi[qp][node]*s[qp]*exp(u[qp*neqn+eqn]));
54  }
55  }
56  }
57 
58  free(s);
59 }
InactiveDouble * jac
InactiveDouble * w
void adic_element_fill(ElemData *e, unsigned int neqn, const DERIV_TYPE *x, DERIV_TYPE *u, DERIV_TYPE *du, DERIV_TYPE *f)
double InactiveDouble
Definition: ad_deriv.h:20
InactiveDouble ** phi
InactiveDouble ** dphi
exp(expr.val())