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*neqn*sizeof(double));
00031   for (unsigned int qp=0; qp<e->nqp; qp++) {
00032     for (unsigned int eqn=0; eqn<neqn; eqn++) {
00033       s[qp*neqn+eqn] = 0.0;
00034       for (unsigned int j=0; j<neqn; j++) {
00035         if (j != eqn)
00036           s[qp*neqn+eqn] += u[qp*neqn+j]; 
00037       }
00038     }
00039   }
00040 
00041   /* Evaluate element residual */
00042   for (unsigned int node=0; node<e->nnode; node++) {
00043     for (unsigned int eqn=0; eqn<neqn; eqn++) {
00044       unsigned int row = node*neqn+eqn;
00045       f[row] = 0.0;
00046       for (unsigned int qp=0; qp<e->nqp; qp++) {
00047   f[row] += 
00048     e->w[qp]*e->jac[qp]*(-(1.0/(e->jac[qp]*e->jac[qp]))*
00049            du[qp*neqn+eqn]*e->dphi[qp][node] + 
00050            e->phi[qp][node]*(exp(u[qp*neqn+eqn]) + 
00051                 u[qp*neqn+eqn]*s[qp*neqn+eqn]));
00052       }
00053     }
00054   }
00055 
00056   free(s);
00057 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines