Sacado Package Browser (Single Doxygen Collection) Version of the Day
adic_element_fill.c
Go to the documentation of this file.
00001 #include <math.h>
00002 #include <stdlib.h>
00003 
00004 typedef struct {
00005   int nqp;
00006   int nnode;
00007   InactiveDouble *w, *jac, **phi, **dphi;
00008   int *gid;
00009 } ElemData;
00010 
00011 void adic_element_fill(ElemData* e, 
00012            unsigned int neqn,
00013            const double* x, 
00014            double* u, 
00015            double* du, 
00016            double* f) {
00017   /* Construct element solution, derivative */
00018   for (unsigned int qp=0; qp<e->nqp; qp++) {
00019     for (unsigned int eqn=0; eqn<neqn; eqn++) {
00020       u[qp*neqn+eqn] = 0.0;
00021       du[qp*neqn+eqn] = 0.0;
00022       for (unsigned int node=0; node<e->nnode; node++) {
00023   u[qp*neqn+eqn] += x[node*neqn+eqn] * e->phi[qp][node];
00024   du[qp*neqn+eqn] += x[node*neqn+eqn] * e->dphi[qp][node];
00025       }
00026     }
00027   }
00028 
00029   /* Compute sum of equations for coupling */
00030   double *s = malloc(e->nqp*sizeof(double));
00031   for (unsigned int qp=0; qp<e->nqp; qp++) {
00032     s[qp] = 0.0;
00033     for (unsigned int eqn=0; eqn<neqn; eqn++)
00034       s[qp] += u[qp*neqn+eqn]*u[qp*neqn+eqn];
00035   }
00036 
00037   /* Evaluate element residual */
00038   for (unsigned int node=0; node<e->nnode; node++) {
00039     for (unsigned int eqn=0; eqn<neqn; eqn++) {
00040       unsigned int row = node*neqn+eqn;
00041       f[row] = 0.0;
00042       for (unsigned int qp=0; qp<e->nqp; qp++) {
00043   f[row] += 
00044     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]));
00045       }
00046     }
00047   }
00048 
00049   free(s);
00050 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines