proteus  1.8.1
C/C++/Fortran libraries
numericalFlux.c
Go to the documentation of this file.
1 #include "numericalFlux.h"
2 
3 #define TR_ALPHA 0.5
4 #define TR_ALPHA_EXT 1.0
5 
6 
7 /***********************************************************************
8  try some different numerical fluxes
9  ***********************************************************************/
10 
15  double sonicFlux,
16  int nInteriorElementBoundaries_global,
17  int nElementBoundaries_element,
18  int nQuadraturePoints_elementBoundary,
19  int nSpace,
20  int* interiorElementBoundaries,
21  int* elementBoundaryElements,
22  int* elementBoundaryLocalElementBoundaries,
23  double* n,
24  double* u,
25  double* f,
26  double* df,
27  double* flux,
28  double* dflux_left,
29  double* dflux_right)
30 {
31  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,J;
32  double left_flux,right_flux,u_left,u_right,left_speed,right_speed,sonicSpeed;
33  sonicSpeed = 0.0;
34  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
35  {
36  ebN = interiorElementBoundaries[ebNI];
37  left_eN_global = elementBoundaryElements[ebN*2+0];
38  right_eN_global = elementBoundaryElements[ebN*2+1];
39  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
40  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
41  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
42  {
43  left_speed =0.0;
44  right_speed=0.0;
45  left_flux=0.0;
46  right_flux=0.0;
47  for(J=0;J<nSpace;J++)
48  {
49  left_speed
50  +=
51  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
52  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
53  k*nSpace+
54  J]
55  *
56  df[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
57  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
58  k*nSpace+
59  J];
60  right_speed
61  +=
62  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
63  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
64  k*nSpace+
65  J]
66  *
67  df[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
68  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
69  k*nSpace+
70  J];
71  left_flux
72  +=
73  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
74  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
75  k*nSpace+
76  J]
77  *
78  f[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
79  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
80  k*nSpace+
81  J];
82  right_flux
83  +=
84  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
85  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
86  k*nSpace+
87  J]
88  *
89  f[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
90  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
91  k*nSpace+
92  J];
93  }
94 
95  u_left = u[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
96  left_ebN_element*nQuadraturePoints_elementBoundary+
97  k];
98  u_right= u[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
99  right_ebN_element*nQuadraturePoints_elementBoundary+
100  k];
101  /***************************************************
102  Simple convex flux with one sonic point potentially
103  Generic scalar riemann solution (1d too)
104  f(u_riem) = max_{u_R <= u <= u_L} if u_L >= u_R
105  = min_{u_L <= u <= u_R} if u_L < u_R
106  **************************************************/
107  /*cases*/
108  if (u_left >= u_right)
109  {
110  if (left_flux >= right_flux)
111  {
112  flux[ebN*nQuadraturePoints_elementBoundary+
113  k] = left_flux;
114  dflux_left[ebN*nQuadraturePoints_elementBoundary+
115  k] = left_speed;
116  dflux_right[ebN*nQuadraturePoints_elementBoundary+
117  k] = 0.0;
118  }
119  else
120  {
121  flux[ebN*nQuadraturePoints_elementBoundary+
122  k] = right_flux;
123  dflux_left[ebN*nQuadraturePoints_elementBoundary+
124  k] = 0.0;
125  dflux_right[ebN*nQuadraturePoints_elementBoundary+
126  k] = right_speed;
127  }
128  }/*max*/
129  else
130  {
131  /*min*/
132  flux[ebN*nQuadraturePoints_elementBoundary+
133  k] = left_flux;
134  dflux_left[ebN*nQuadraturePoints_elementBoundary+
135  k] = left_speed;
136  dflux_right[ebN*nQuadraturePoints_elementBoundary+
137  k] = 0.0;
138 
139  if (right_flux <= flux[ebN*nQuadraturePoints_elementBoundary+k])
140  {
141  flux[ebN*nQuadraturePoints_elementBoundary+
142  k] = right_flux;
143  dflux_left[ebN*nQuadraturePoints_elementBoundary+
144  k] = 0.0;
145  dflux_right[ebN*nQuadraturePoints_elementBoundary+
146  k] = right_speed;
147  }
148  if (u_left <= sonicPoint && sonicPoint <= u_right &&
149  sonicFlux < flux[ebN*nQuadraturePoints_elementBoundary+k])/*only consider if sonicPoint in interval*/
150  {
151  flux[ebN*nQuadraturePoints_elementBoundary+
152  k] = sonicFlux;
153 
154  dflux_left[ebN*nQuadraturePoints_elementBoundary+
155  k] = sonicSpeed;
156  dflux_right[ebN*nQuadraturePoints_elementBoundary+
157  k]= sonicSpeed;
158  }
159 
160  }/*min not containing sonic point*/
161  /*mwf debug
162  if (fabs(u_left-u_right) > 1.0e-2)
163  {
164  printf("conv flux ebN=%d eN_left=%d eN_right=%d u_left=%g u_right=%g left_flux=%g right_flux=%g flux=%g\n\t",
165  ebN,left_eN_global,right_eN_global,u_left,u_right,left_flux,right_flux,flux[ebN*nQuadraturePoints_elementBoundary+k]);
166  for (J=0; J < nSpace; J++)
167  {
168  printf("n[%d] = %g ",J,n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
169  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
170  k*nSpace+J]);
171  }
172  printf("\n");
173 
174  }
175  */
176  }/*k*/
177  }/*ebnI*/
178 }
180  int nInteriorElementBoundaries_global,
181  int nElementBoundaries_element,
182  int nQuadraturePoints_elementBoundary,
183  int nQuadraturePoints_element,
184  int nSpace,
185  int* interiorElementBoundaries,
186  int* elementBoundaryElements,
187  int* elementBoundaryLocalElementBoundaries,
188  double* n,
189  double* u,
190  double* f,
191  double* df,
192  double* df_element,
193  double* flux,
194  double* dflux_left,
195  double* dflux_right)
196 {
197  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,J;
198  double left_flux,right_flux,u_left,u_right,left_speed,right_speed,
199  maxSpeed_left,maxSpeed_right,maxSpeed_element,maxSpeed,tmp_left,tmp_right;
200  /*for now use outer normal at first quadrature point for element speed calculations*/
201 
202  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
203  {
204  ebN = interiorElementBoundaries[ebNI];
205  left_eN_global = elementBoundaryElements[ebN*2+0];
206  right_eN_global = elementBoundaryElements[ebN*2+1];
207  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
208  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
209  /*first calculate maximum value for df/du on neighboring elements and use this
210  in Rusanov (local lax-friedrichs) flux
211  h(a,b) = 0.5*(f(a)+f(b)) - 0.5*alpha*(b-a)
212  */
213  maxSpeed_left =0.0; maxSpeed_right=0.0; maxSpeed=0.0;
214  for (k=0; k < nQuadraturePoints_element; k++)
215  {
216  tmp_left = 0.0; tmp_right=0.0;
217  /*evaluate df at interior elemnent point but compute its value dotted with normal for speed*/
218  for (J=0; J < nSpace; J++)
219  {
220  tmp_left +=
221  df_element[left_eN_global*nQuadraturePoints_element*nSpace+ k*nSpace + J]
222  *
223  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
224  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
225  0*nSpace+
226  J];
227 
228  tmp_right +=
229  df_element[right_eN_global*nQuadraturePoints_element*nSpace+ k*nSpace + J]
230  *
231  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
232  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
233  0*nSpace+
234  J];
235  }
236  maxSpeed_left = fabs(tmp_left) > maxSpeed_left ? fabs(tmp_left) : maxSpeed_left;
237  maxSpeed_right= fabs(tmp_right) > maxSpeed_right ? fabs(tmp_right) : maxSpeed_right;
238  }
239  maxSpeed_element = maxSpeed_right > maxSpeed_left ? maxSpeed_right : maxSpeed_left;
240  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
241  {
242  left_speed =0.0;
243  right_speed=0.0;
244  left_flux=0.0;
245  right_flux=0.0;
246  for(J=0;J<nSpace;J++)
247  {
248  left_speed
249  +=
250  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
251  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
252  k*nSpace+
253  J]
254  *
255  df[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
256  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
257  k*nSpace+
258  J];
259  right_speed
260  +=
261  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
262  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
263  k*nSpace+
264  J]
265  *
266  df[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
267  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
268  k*nSpace+
269  J];
270  left_flux
271  +=
272  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
273  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
274  k*nSpace+
275  J]
276  *
277  f[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
278  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
279  k*nSpace+
280  J];
281  right_flux
282  +=
283  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
284  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
285  k*nSpace+
286  J]
287  *
288  f[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
289  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
290  k*nSpace+
291  J];
292  }
293 
294  u_left = u[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
295  left_ebN_element*nQuadraturePoints_elementBoundary+
296  k];
297  u_right= u[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
298  right_ebN_element*nQuadraturePoints_elementBoundary+
299  k];
300  maxSpeed = fabs(left_speed) > maxSpeed_element ? fabs(left_speed) : maxSpeed_element;
301  maxSpeed = fabs(right_speed) > maxSpeed ? fabs(right_speed) : maxSpeed;
302  maxSpeed*= safetyFactor;
303  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.5*(left_flux + right_flux) - 0.5*maxSpeed*(u_right-u_left);
304  dflux_left[ebN*nQuadraturePoints_elementBoundary+k] = 0.5*left_speed + 0.5*maxSpeed;
305  dflux_right[ebN*nQuadraturePoints_elementBoundary+k]= 0.5*right_speed - 0.5*maxSpeed;
306  /*mwf debug
307  if (fabs(u_left-u_right) > 1.0e-2)
308  {
309  printf("Rusanov ebN=%d eN_left=%d eN_right=%d u_left=%g u_right=%g left_flux=%g right_flux=%g flux=%g\n\t",
310  ebN,left_eN_global,right_eN_global,u_left,u_right,left_flux,right_flux,flux[ebN*nQuadraturePoints_elementBoundary+k]);
311  for (J=0; J < nSpace; J++)
312  {
313  printf("n[%d] = %g ",J,n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
314  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
315  k*nSpace+J]);
316  }
317  printf("\n");
318 
319  printf("maxSpeed_element= %g maxSpeed_left=%g maxSpeed_right=%g left_speed=%g right_speed=%g maxSpeed=%g\n",
320  maxSpeed_element,maxSpeed_left,maxSpeed_right,left_speed,right_speed,maxSpeed);
321  }
322  mwf end debug*/
323  }/*k*/
324  }/*ebnI*/
325 }
327  int nExteriorElementBoundaries_global,
328  int nElementBoundaries_element,
329  int nQuadraturePoints_elementBoundary,
330  int nQuadraturePoints_element,
331  int nSpace,
332  int* exteriorElementBoundaries,
333  int* elementBoundaryElements,
334  int* elementBoundaryLocalElementBoundaries,
335  int* isDOFBoundary,
336  int* inflowFlag,
337  double* n,
338  double* bc_u,
339  double* bc_f,
340  double* bc_df,
341  double* u,
342  double* f,
343  double* df,
344  double* df_element,
345  double* flux,
346  double* dflux)
347 {
348  int ebNE,ebN,eN_global,ebN_element,k,J;
349  double left_flux,right_flux,u_left,u_right,left_speed,right_speed,
350  maxSpeed_element,maxSpeed,tmp_left;
351  /*for now use outer normal at first quadrature point for element speed calculations*/
352 
353  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
354  {
355  ebN = exteriorElementBoundaries[ebNE];
356  eN_global = elementBoundaryElements[ebN*2+0];
357  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
358  /*first calculate maximum value for df/du on neighboring element and use this
359  in Rusanov (local lax-friedrichs) flux
360  h(a,b) = 0.5*(f(a)+f(b)) - 0.5*alpha*(b-a)
361  */
362  maxSpeed_element =0.0; maxSpeed=0.0;
363  for (k=0; k < nQuadraturePoints_element; k++)
364  {
365  tmp_left = 0.0;
366  /*evaluate df at interior elemnent point but compute its value dotted with normal for speed*/
367  for (J=0; J < nSpace; J++)
368  {
369  tmp_left +=
370  df_element[eN_global*nQuadraturePoints_element*nSpace+ k*nSpace + J]
371  *
372  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
373  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
374  0*nSpace+
375  J];
376  }
377  maxSpeed_element = fabs(tmp_left) > maxSpeed_element ? fabs(tmp_left) : maxSpeed_element;
378  }
379  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
380  {
381  left_speed =0.0;
382  right_speed=0.0;
383  left_flux=0.0;
384  right_flux=0.0;
385  for(J=0;J<nSpace;J++)
386  {
387  left_speed
388  +=
389  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
390  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
391  k*nSpace+
392  J]
393  *
394  df[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
395  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
396  k*nSpace+
397  J];
398  right_speed
399  +=
400  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
401  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
402  k*nSpace+
403  J]
404  *
405  bc_df[ebNE*nQuadraturePoints_elementBoundary*nSpace+
406  k*nSpace+
407  J];
408  left_flux
409  +=
410  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
411  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
412  k*nSpace+
413  J]
414  *
415  f[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
416  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
417  k*nSpace+
418  J];
419  right_flux
420  +=
421  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
422  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
423  k*nSpace+
424  J]
425  *
426  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
427  k*nSpace+
428  J];
429  }
430 
431  u_left = u[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
432  ebN_element*nQuadraturePoints_elementBoundary+
433  k];
434  u_right= bc_u[ebNE*nQuadraturePoints_elementBoundary+
435  k];
436  maxSpeed = fabs(left_speed) > maxSpeed_element ? fabs(left_speed) : maxSpeed_element;
437  maxSpeed = fabs(right_speed) > maxSpeed ? fabs(right_speed) : maxSpeed;
438  maxSpeed*= safetyFactor;
439  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.5*(left_flux + right_flux) - 0.5*maxSpeed*(u_right-u_left);
440  dflux[ebN*nQuadraturePoints_elementBoundary+k] = 0.5*left_speed + 0.5*maxSpeed;
441 
442  /*mwf debug
443  if (fabs(u_left-u_right) > 1.0e-2)
444  {
445  printf("Rusanov exterior ebN=%d eN=%d u_left=%g u_right=%g left_flux=%g right_flux=%g flux=%g\n\t",
446  ebN,eN_global,u_left,u_right,left_flux,right_flux,flux[ebN*nQuadraturePoints_elementBoundary+k]);
447  for (J=0; J < nSpace; J++)
448  {
449  printf("n[%d] = %g ",J,n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
450  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
451  k*nSpace+J]);
452  }
453  printf("\n");
454 
455  printf("maxSpeed_element= %g left_speed=%g right_speed=%g maxSpeed=%g\n",
456  maxSpeed_element,left_speed,right_speed,maxSpeed);
457  }
458  mwf end debug*/
459  }/*k*/
460  }/*ebnI*/
461 }
462 
464  int nExteriorElementBoundaries_global,
465  int nQuadraturePoints_elementBoundary,
466  int nQuadraturePoints_element,
467  int nSpace,
468  int* exteriorElementBoundaries,
469  int* elementBoundaryElements,
470  int* elementBoundaryLocalElementBoundaries,
471  int* isDOFBoundary,
472  int* inflowFlag,
473  double* n,
474  double* bc_u,
475  double* bc_f,
476  double* bc_df,
477  double* u,
478  double* f,
479  double* df,
480  double* df_element,
481  double* flux,
482  double* dflux)
483 {
484  int ebNE,ebN,eN_global,k,J;
485  double left_flux,right_flux,u_left,u_right,left_speed,right_speed,
486  maxSpeed_element,maxSpeed,tmp_left;
487  /*for now use outer normal at first quadrature point for element speed calculations*/
488 
489  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
490  {
491  ebN = exteriorElementBoundaries[ebNE];
492  eN_global = elementBoundaryElements[ebN*2+0];
493  /*first calculate maximum value for df/du on neighboring element and use this
494  in Rusanov (local lax-friedrichs) flux
495  h(a,b) = 0.5*(f(a)+f(b)) - 0.5*alpha*(b-a)
496  */
497  maxSpeed_element =0.0; maxSpeed=0.0;
498  for (k=0; k < nQuadraturePoints_element; k++)
499  {
500  tmp_left = 0.0;
501  /*evaluate df at interior elemnent point but compute its value dotted with normal for speed*/
502  for (J=0; J < nSpace; J++)
503  {
504  tmp_left +=
505  df_element[eN_global*nQuadraturePoints_element*nSpace+ k*nSpace + J]
506  *
507  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
508  0*nSpace+
509  J];
510  }
511  maxSpeed_element = fabs(tmp_left) > maxSpeed_element ? fabs(tmp_left) : maxSpeed_element;
512  }
513  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
514  {
515  left_speed =0.0;
516  right_speed=0.0;
517  left_flux=0.0;
518  right_flux=0.0;
519  for(J=0;J<nSpace;J++)
520  {
521  left_speed
522  +=
523  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
524  k*nSpace+
525  J]
526  *
527  df[ebNE*nQuadraturePoints_elementBoundary*nSpace+
528  k*nSpace+
529  J];
530  right_speed
531  +=
532  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
533  k*nSpace+
534  J]
535  *
536  bc_df[ebNE*nQuadraturePoints_elementBoundary*nSpace+
537  k*nSpace+
538  J];
539  left_flux
540  +=
541  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
542  k*nSpace+
543  J]
544  *
545  f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
546  k*nSpace+
547  J];
548  right_flux
549  +=
550  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
551  k*nSpace+
552  J]
553  *
554  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
555  k*nSpace+
556  J];
557  }
558 
559  u_left = u[ebNE*nQuadraturePoints_elementBoundary+
560  k];
561  u_right= bc_u[ebNE*nQuadraturePoints_elementBoundary+
562  k];
563  maxSpeed = fabs(left_speed) > maxSpeed_element ? fabs(left_speed) : maxSpeed_element;
564  maxSpeed = fabs(right_speed) > maxSpeed ? fabs(right_speed) : maxSpeed;
565  maxSpeed*= safetyFactor;
566  flux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.5*(left_flux + right_flux) - 0.5*maxSpeed*(u_right-u_left);
567  dflux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.5*left_speed + 0.5*maxSpeed;
568 
569  /*mwf debug
570  if (fabs(u_left-u_right) > 1.0e-2)
571  {
572  printf("Rusanov exterior ebN=%d u_left=%g u_right=%g left_flux=%g right_flux=%g flux=%g\n\t",
573  ebNE,u_left,u_right,left_flux,right_flux,flux[ebNE*nQuadraturePoints_elementBoundary+k]);
574  for (J=0; J < nSpace; J++)
575  {
576  printf("n[%d] = %g ",J,n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
577  k*nSpace+J]);
578  }
579  printf("\n");
580 
581  printf("maxSpeed_element= %g left_speed=%g right_speed=%g maxSpeed=%g\n",
582  maxSpeed_element,left_speed,right_speed,maxSpeed);
583  }
584  mwf end debug*/
585  }/*k*/
586  }/*ebnE*/
587 }
592  int nInteriorElementBoundaries_global,
593  int nElementBoundaries_element,
594  int nQuadraturePoints_elementBoundary,
595  int nQuadraturePoints_element,
596  int nSpace,
597  int* interiorElementBoundaries,
598  int* elementBoundaryElements,
599  int* elementBoundaryLocalElementBoundaries,
600  double* n,
601  double* u,
602  double* f,
603  double* lambda_bar_element,
604  double* flux)
605 {
606  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,J;
607  double left_flux,right_flux,u_left,u_right,
608  maxSpeed_left,maxSpeed_right,maxSpeed_element,maxSpeed,tmp_left,tmp_right;
609  /*for now use outer normal at first quadrature point for element speed calculations*/
610 
611  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
612  {
613  ebN = interiorElementBoundaries[ebNI];
614  left_eN_global = elementBoundaryElements[ebN*2+0];
615  right_eN_global = elementBoundaryElements[ebN*2+1];
616  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
617  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
618  /*first calculate maximum value for df/du on neighboring elements and use this
619  in Rusanov (local lax-friedrichs) flux
620  h(a,b) = 0.5*(f(a)+f(b)) - 0.5*alpha*(b-a)
621  */
622  maxSpeed_left =0.0; maxSpeed_right=0.0; maxSpeed=0.0;
623  for (k=0; k < nQuadraturePoints_element; k++)
624  {
625  tmp_left = lambda_bar_element[left_eN_global*nQuadraturePoints_element + k];
626  tmp_right= lambda_bar_element[right_eN_global*nQuadraturePoints_element + k];
627  maxSpeed_left = fabs(tmp_left) > maxSpeed_left ? fabs(tmp_left) : maxSpeed_left;
628  maxSpeed_right= fabs(tmp_right) > maxSpeed_right ? fabs(tmp_right) : maxSpeed_right;
629  }
630  maxSpeed_element = maxSpeed_right > maxSpeed_left ? maxSpeed_right : maxSpeed_left;
631  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
632  {
633  left_flux=0.0;
634  right_flux=0.0;
635  for(J=0;J<nSpace;J++)
636  {
637  left_flux
638  +=
639  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
640  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
641  k*nSpace+
642  J]
643  *
644  f[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
645  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
646  k*nSpace+
647  J];
648  right_flux
649  +=
650  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
651  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
652  k*nSpace+
653  J]
654  *
655  f[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
656  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
657  k*nSpace+
658  J];
659  }
660 
661  u_left = u[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
662  left_ebN_element*nQuadraturePoints_elementBoundary+
663  k];
664  u_right= u[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
665  right_ebN_element*nQuadraturePoints_elementBoundary+
666  k];
667 /* maxSpeed = fabs(left_speed) > maxSpeed_element ? fabs(left_speed) : maxSpeed_element; */
668 /* maxSpeed = fabs(right_speed) > maxSpeed ? fabs(right_speed) : maxSpeed; */
669  maxSpeed = maxSpeed_element;
670  maxSpeed*= safetyFactor;
671  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.5*(left_flux + right_flux) - 0.5*maxSpeed*(u_right-u_left);
672  /*mwf debug
673  if (fabs(u_left-u_right) > 1.0e-2)
674  {
675  printf("Rusanov ebN=%d eN_left=%d eN_right=%d u_left=%g u_right=%g left_flux=%g right_flux=%g flux=%g\n\t",
676  ebN,left_eN_global,right_eN_global,u_left,u_right,left_flux,right_flux,flux[ebN*nQuadraturePoints_elementBoundary+k]);
677  for (J=0; J < nSpace; J++)
678  {
679  printf("n[%d] = %g ",J,n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
680  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
681  k*nSpace+J]);
682  }
683  printf("\n");
684 
685  printf("maxSpeed_element= %g maxSpeed_left=%g maxSpeed_right=%g left_speed=%g right_speed=%g maxSpeed=%g\n",
686  maxSpeed_element,maxSpeed_left,maxSpeed_right,left_speed,right_speed,maxSpeed);
687  }
688  mwf end debug*/
689  }/*k*/
690  }/*ebnI*/
691 }
693  int nExteriorElementBoundaries_global,
694  int nQuadraturePoints_elementBoundary,
695  int nQuadraturePoints_element,
696  int nSpace,
697  int* exteriorElementBoundaries,
698  int* elementBoundaryElements,
699  int* elementBoundaryLocalElementBoundaries,
700  int* isDOFBoundary,
701  int* inflowFlag,
702  double* n,
703  double* bc_u,
704  double* bc_f,
705  double* u,
706  double* f,
707  double* lambda_bar,
708  double* flux)
709 {
710  int ebNE,ebN,eN_global,k,J;
711  double left_flux,right_flux,u_left,u_right,
712  maxSpeed_element,maxSpeed,tmp_left;
713  /*for now use outer normal at first quadrature point for element speed calculations*/
714 
715  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
716  {
717  ebN = exteriorElementBoundaries[ebNE];
718  eN_global = elementBoundaryElements[ebN*2+0];
719  /*first calculate maximum value for df/du on neighboring element and use this
720  in Rusanov (local lax-friedrichs) flux
721  h(a,b) = 0.5*(f(a)+f(b)) - 0.5*alpha*(b-a)
722  */
723  maxSpeed_element =0.0; maxSpeed=0.0;
724  for (k=0; k < nQuadraturePoints_element; k++)
725  {
726  tmp_left = lambda_bar[eN_global*nQuadraturePoints_element + k];
727  maxSpeed_element = fabs(tmp_left) > maxSpeed_element ? fabs(tmp_left) : maxSpeed_element;
728  }
729  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
730  {
731  left_flux=0.0;
732  right_flux=0.0;
733  for(J=0;J<nSpace;J++)
734  {
735  left_flux
736  +=
737  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
738  k*nSpace+
739  J]
740  *
741  f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
742  k*nSpace+
743  J];
744  right_flux
745  +=
746  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
747  k*nSpace+
748  J]
749  *
750  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
751  k*nSpace+
752  J];
753  }
754 
755  u_left = u[ebNE*nQuadraturePoints_elementBoundary+
756  k];
757  u_right= bc_u[ebNE*nQuadraturePoints_elementBoundary+
758  k];
759 /* maxSpeed = fabs(left_speed) > maxSpeed_element ? fabs(left_speed) : maxSpeed_element; */
760 /* maxSpeed = fabs(right_speed) > maxSpeed ? fabs(right_speed) : maxSpeed; */
761  maxSpeed =maxSpeed_element;
762  maxSpeed*= safetyFactor;
763  flux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.5*(left_flux + right_flux) - 0.5*maxSpeed*(u_right-u_left);
764 
765  /*mwf debug
766  if (fabs(u_left-u_right) > 1.0e-2)
767  {
768  printf("Rusanov exterior ebN=%d u_left=%g u_right=%g left_flux=%g right_flux=%g flux=%g\n\t",
769  ebNE,u_left,u_right,left_flux,right_flux,flux[ebNE*nQuadraturePoints_elementBoundary+k]);
770  for (J=0; J < nSpace; J++)
771  {
772  printf("n[%d] = %g ",J,n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
773  k*nSpace+J]);
774  }
775  printf("\n");
776 
777  printf("maxSpeed_element= %g left_speed=%g right_speed=%g maxSpeed=%g\n",
778  maxSpeed_element,left_speed,right_speed,maxSpeed);
779  }
780  mwf end debug*/
781  }/*k*/
782  }/*ebnE*/
783 }
785  int nExteriorElementBoundaries_global,
786  int nElementBoundaries_element,
787  int nQuadraturePoints_elementBoundary,
788  int nQuadraturePoints_element,
789  int nSpace,
790  int* exteriorElementBoundaries,
791  int* elementBoundaryElements,
792  int* elementBoundaryLocalElementBoundaries,
793  int* isDOFBoundary,
794  int* inflowFlag,
795  double* n,
796  double* bc_u,
797  double* bc_f,
798  double* u,
799  double* f,
800  double* lambda_bar,
801  double* flux)
802 {
803  int ebNE,ebN,eN_global,ebN_element,k,J;
804  double left_flux,right_flux,u_left,u_right,
805  maxSpeed_element,maxSpeed,tmp_left;
806  /*for now use outer normal at first quadrature point for element speed calculations*/
807 
808  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
809  {
810  ebN = exteriorElementBoundaries[ebNE];
811  eN_global = elementBoundaryElements[ebN*2+0];
812  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
813  /*first calculate maximum value for df/du on neighboring element and use this
814  in Rusanov (local lax-friedrichs) flux
815  h(a,b) = 0.5*(f(a)+f(b)) - 0.5*alpha*(b-a)
816  */
817  maxSpeed_element =0.0; maxSpeed=0.0;
818  for (k=0; k < nQuadraturePoints_element; k++)
819  {
820  tmp_left = lambda_bar[eN_global*nQuadraturePoints_element+k];
821  maxSpeed_element = fabs(tmp_left) > maxSpeed_element ? fabs(tmp_left) : maxSpeed_element;
822  }
823  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
824  {
825  left_flux=0.0;
826  right_flux=0.0;
827  for(J=0;J<nSpace;J++)
828  {
829  left_flux
830  +=
831  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
832  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
833  k*nSpace+
834  J]
835  *
836  f[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
837  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
838  k*nSpace+
839  J];
840  right_flux
841  +=
842  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
843  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
844  k*nSpace+
845  J]
846  *
847  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
848  k*nSpace+
849  J];
850  }
851 
852  u_left = u[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
853  ebN_element*nQuadraturePoints_elementBoundary+
854  k];
855  u_right= bc_u[ebNE*nQuadraturePoints_elementBoundary+
856  k];
857 /* maxSpeed = fabs(left_speed) > maxSpeed_element ? fabs(left_speed) : maxSpeed_element; */
858 /* maxSpeed = fabs(right_speed) > maxSpeed ? fabs(right_speed) : maxSpeed; */
859  maxSpeed = maxSpeed_element;
860  maxSpeed*= safetyFactor;
861  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.5*(left_flux + right_flux) - 0.5*maxSpeed*(u_right-u_left);
862 
863  /*mwf debug
864  if (fabs(u_left-u_right) > 1.0e-2)
865  {
866  printf("Rusanov exterior ebN=%d eN=%d u_left=%g u_right=%g left_flux=%g right_flux=%g flux=%g\n\t",
867  ebN,eN_global,u_left,u_right,left_flux,right_flux,flux[ebN*nQuadraturePoints_elementBoundary+k]);
868  for (J=0; J < nSpace; J++)
869  {
870  printf("n[%d] = %g ",J,n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
871  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
872  k*nSpace+J]);
873  }
874  printf("\n");
875 
876  printf("maxSpeed_element= %g left_speed=%g right_speed=%g maxSpeed=%g\n",
877  maxSpeed_element,left_speed,right_speed,maxSpeed);
878  }
879  mwf end debug*/
880  }/*k*/
881  }/*ebnI*/
882 }
883 
884 /************************************************************************
885  begin moving over exterior numerical flux routines and changing to index
886  boundary quadrature arrays as nExternalElementBoundaries * .
887  ************************************************************************/
892  double penalty_floor,
893  int nInteriorElementBoundaries_global,
894  int nElementBoundaries_element,
895  int nQuadraturePoints_elementBoundary,
896  int nSpace,
897  int* interiorElementBoundaries,
898  int* elementBoundaryElements,
899  int* elementBoundaryLocalElementBoundaries,
900  double* n,
901  double* a,
902  double* grad_phi,
903  double* u,
904  double* penalty,
905  double* flux)
906 {
907  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,J,I,nSpace2=nSpace*nSpace;
908  double diffusiveVelocityComponent_I,max_a=0.0;
909  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
910  {
911  ebN = interiorElementBoundaries[ebNI];
912  left_eN_global = elementBoundaryElements[ebN*2+0];
913  right_eN_global = elementBoundaryElements[ebN*2+1];
914  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
915  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
916  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
917  {
918  max_a = 0.0;
919  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
920  for(I=0;I<nSpace;I++)
921  {
922  diffusiveVelocityComponent_I=0.0;
923  for(J=0;J<nSpace;J++)
924  {
925  diffusiveVelocityComponent_I
926  -=
927  (a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
928  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
929  k*nSpace2+
930  I*nSpace+
931  J]
932  *
933  grad_phi[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
934  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
935  k*nSpace+J]
936  +
937  a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
938  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
939  k*nSpace2+
940  I*nSpace+
941  J]
942  *
943  grad_phi[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
944  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
945  k*nSpace+J]);
946  max_a = fmax(max_a,a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
947  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
948  k*nSpace2+
949  I*nSpace+
950  J]);
951  max_a = fmax(max_a,a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
952  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
953  k*nSpace2+
954  I*nSpace+
955  J]);
956  }
957  flux[ebN*nQuadraturePoints_elementBoundary+
958  k]
959  +=
960  diffusiveVelocityComponent_I
961  *
962  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
963  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
964  k*nSpace+
965  I];
966  }
967  flux[ebN*nQuadraturePoints_elementBoundary+
968  k] *= 0.5;
970  max_a = fmax(max_a,penalty_floor);
971  double penalty_flux = penalty[ebN*nQuadraturePoints_elementBoundary+
972  k]
973  *
974  (u[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
975  left_ebN_element*nQuadraturePoints_elementBoundary+
976  k]-
977  u[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
978  right_ebN_element*nQuadraturePoints_elementBoundary+
979  k]);
980  if (scale_penalty) penalty_flux *= max_a;
981  flux[ebN*nQuadraturePoints_elementBoundary+
982  k]
983  += penalty_flux;
984  }
985  }
986 }
988  double penalty_floor,
989  int nInteriorElementBoundaries_global,
990  int nElementBoundaries_element,
991  int nQuadraturePoints_elementBoundary,
992  int nSpace,
993  int* rowptr,
994  int* colind,
995  int* interiorElementBoundaries,
996  int* elementBoundaryElements,
997  int* elementBoundaryLocalElementBoundaries,
998  double* n,
999  double* a,
1000  double* grad_phi,
1001  double* u,
1002  double* penalty,
1003  double* flux)
1004 {
1005  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,I,m,nnz=rowptr[nSpace];
1006  double diffusiveVelocityComponent_I,max_a=0.0;
1007  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
1008  {
1009  ebN = interiorElementBoundaries[ebNI];
1010  left_eN_global = elementBoundaryElements[ebN*2+0];
1011  right_eN_global = elementBoundaryElements[ebN*2+1];
1012  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
1013  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
1014  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
1015  {
1016  max_a = 0.0;
1017  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
1018  for(I=0;I<nSpace;I++)
1019  {
1020  diffusiveVelocityComponent_I=0.0;
1021  for(m=rowptr[I];m<rowptr[I+1];m++)
1022  {
1023  diffusiveVelocityComponent_I
1024  -=
1025  (a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1026  left_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1027  k*nnz+
1028  m]
1029  *
1030  grad_phi[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1031  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1032  k*nSpace+colind[m]]
1033  +
1034  a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1035  right_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1036  k*nnz+
1037  m]
1038  *
1039  grad_phi[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1040  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1041  k*nSpace+colind[m]]);
1042  max_a = fmax(max_a,a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1043  left_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1044  k*nnz+
1045  m]);
1046  max_a = fmax(max_a,a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1047  right_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1048  k*nnz+
1049  m]);
1050  }
1051  flux[ebN*nQuadraturePoints_elementBoundary+
1052  k]
1053  +=
1054  diffusiveVelocityComponent_I
1055  *
1056  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1057  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1058  k*nSpace+
1059  I];
1060  }
1061  flux[ebN*nQuadraturePoints_elementBoundary+
1062  k] *= 0.5;
1064  max_a = fmax(max_a,penalty_floor);
1065  double penalty_flux = penalty[ebN*nQuadraturePoints_elementBoundary+
1066  k]
1067  *
1068  (u[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
1069  left_ebN_element*nQuadraturePoints_elementBoundary+
1070  k]-
1071  u[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
1072  right_ebN_element*nQuadraturePoints_elementBoundary+
1073  k]);
1074  if (scale_penalty) penalty_flux *= max_a;
1075  /*mwf debug
1076  printf("calcIntNumDiffFlux_sd scale= %d k= %d max_a= %g penalty= %g \n",scale_penalty,k,max_a,penalty_flux);
1077  */
1078  flux[ebN*nQuadraturePoints_elementBoundary+
1079  k]
1080  += penalty_flux;
1081  }
1082  }
1083 }
1084 
1085 /*
1086  \brief Calculate the diffusive flux at interior element boundary quadrature points
1087 
1088 void calculateInteriorNumericalDiffusiveFlux(int nInteriorElementBoundaries_global,
1089  int nElementBoundaries_element,
1090  int nQuadraturePoints_elementBoundary,
1091  int nSpace,
1092  int* interiorElementBoundaries,
1093  int* elementBoundaryElements,
1094  int* elementBoundaryLocalElementBoundaries,
1095  double* n,
1096  double* a,
1097  double* grad_phi,
1098  double* u,
1099  double* penalty,
1100  double* flux)
1101 {
1102  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,J,I,nSpace2=nSpace*nSpace;
1103  double diffusiveVelocityComponent_I;
1104  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
1105  {
1106  ebN = interiorElementBoundaries[ebNI];
1107  left_eN_global = elementBoundaryElements[ebN*2+0];
1108  right_eN_global = elementBoundaryElements[ebN*2+1];
1109  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
1110  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
1111  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
1112  {
1113  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
1114  for(I=0;I<nSpace;I++)
1115  {
1116  diffusiveVelocityComponent_I=0.0;
1117  for(J=0;J<nSpace;J++)
1118  {
1119  diffusiveVelocityComponent_I
1120  -=
1121  (a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1122  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1123  k*nSpace2+
1124  I*nSpace+
1125  J]
1126  *
1127  grad_phi[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1128  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1129  k*nSpace+J]
1130  +
1131  a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1132  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1133  k*nSpace2+
1134  I*nSpace+
1135  J]
1136  *
1137  grad_phi[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1138  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1139  k*nSpace+J]);
1140  }
1141  flux[ebN*nQuadraturePoints_elementBoundary+
1142  k]
1143  +=
1144  diffusiveVelocityComponent_I
1145  *
1146  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1147  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1148  k*nSpace+
1149  I];
1150  }
1151  flux[ebN*nQuadraturePoints_elementBoundary+
1152  k] *= 0.5;
1153  // \todo make penalty in DG on phi instead of u
1154  flux[ebN*nQuadraturePoints_elementBoundary+
1155  k]
1156  +=
1157  penalty[ebN*nQuadraturePoints_elementBoundary+
1158  k]
1159  *
1160  (u[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
1161  left_ebN_element*nQuadraturePoints_elementBoundary+
1162  k]-
1163  u[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
1164  right_ebN_element*nQuadraturePoints_elementBoundary+
1165  k]);
1166  }
1167  }
1168 }
1169 void calculateInteriorNumericalDiffusiveFlux_sd(int nInteriorElementBoundaries_global,
1170  int nElementBoundaries_element,
1171  int nQuadraturePoints_elementBoundary,
1172  int nSpace,
1173  int* rowptr,
1174  int* colind,
1175  int* interiorElementBoundaries,
1176  int* elementBoundaryElements,
1177  int* elementBoundaryLocalElementBoundaries,
1178  double* n,
1179  double* a,
1180  double* grad_phi,
1181  double* u,
1182  double* penalty,
1183  double* flux)
1184 {
1185  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,I,m,nnz=rowptr[nSpace];
1186  double diffusiveVelocityComponent_I;
1187  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
1188  {
1189  ebN = interiorElementBoundaries[ebNI];
1190  left_eN_global = elementBoundaryElements[ebN*2+0];
1191  right_eN_global = elementBoundaryElements[ebN*2+1];
1192  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
1193  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
1194  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
1195  {
1196  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
1197  for(I=0;I<nSpace;I++)
1198  {
1199  diffusiveVelocityComponent_I=0.0;
1200  for(m=rowptr[I];m<rowptr[I+1];m++)
1201  {
1202  diffusiveVelocityComponent_I
1203  -=
1204  (a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1205  left_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1206  k*nnz+
1207  m]
1208  *
1209  grad_phi[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1210  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1211  k*nSpace+colind[m]]
1212  +
1213  a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1214  right_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1215  k*nnz+
1216  m]
1217  *
1218  grad_phi[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1219  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1220  k*nSpace+colind[m]]);
1221  }
1222  flux[ebN*nQuadraturePoints_elementBoundary+
1223  k]
1224  +=
1225  diffusiveVelocityComponent_I
1226  *
1227  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1228  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1229  k*nSpace+
1230  I];
1231  }
1232  flux[ebN*nQuadraturePoints_elementBoundary+
1233  k] *= 0.5;
1234  // \todo make penalty in DG on phi instead of u
1235  flux[ebN*nQuadraturePoints_elementBoundary+
1236  k]
1237  +=
1238  penalty[ebN*nQuadraturePoints_elementBoundary+
1239  k]
1240  *
1241  (u[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
1242  left_ebN_element*nQuadraturePoints_elementBoundary+
1243  k]-
1244  u[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
1245  right_ebN_element*nQuadraturePoints_elementBoundary+
1246  k]);
1247  }
1248  }
1249 }
1250 */
1251 
1256  double penalty_floor,
1257  int nInteriorElementBoundaries_global,
1258  int nElementBoundaries_element,
1259  int nQuadraturePoints_elementBoundary,
1260  int nDOF_trial_element,
1261  int nSpace,
1262  int* l2g,
1263  int* interiorElementBoundaries,
1264  int* elementBoundaryElements,
1265  int* elementBoundaryLocalElementBoundaries,
1266  double* n,
1267  double* a,
1268  double* da,
1269  double* grad_phi,
1270  double* dphi,
1271  double* v,
1272  double* grad_v,
1273  double* penalty,
1274  double* fluxJacobian)
1275 {
1276  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,j,left_j_global,right_j_global,I,J,nSpace2=nSpace*nSpace;
1277  double leftJacobian,rightJacobian,diffusiveVelocityComponent_I_leftJacobian,diffusiveVelocityComponent_I_rightJacobian,diffusiveVelocityComponent_I_leftJacobian2,diffusiveVelocityComponent_I_rightJacobian2,max_a=0.0;
1278  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
1279  {
1280  ebN = interiorElementBoundaries[ebNI];
1281  left_eN_global = elementBoundaryElements[ebN*2+0];
1282  right_eN_global = elementBoundaryElements[ebN*2+1];
1283  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
1284  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
1285  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
1286  {
1287  max_a = 0.0;
1288  for(j=0;j<nDOF_trial_element;j++)
1289  {
1290  leftJacobian=0.0;
1291  rightJacobian=0.0;
1292  left_j_global = l2g[left_eN_global*nDOF_trial_element+j];
1293  right_j_global= l2g[right_eN_global*nDOF_trial_element+j];
1294  for(I=0;I<nSpace;I++)
1295  {
1296  diffusiveVelocityComponent_I_leftJacobian=0.0;
1297  diffusiveVelocityComponent_I_leftJacobian2=0.0;
1298  diffusiveVelocityComponent_I_rightJacobian=0.0;
1299  diffusiveVelocityComponent_I_rightJacobian2=0.0;
1300  for(J=0;J<nSpace;J++)
1301  {
1302  diffusiveVelocityComponent_I_leftJacobian
1303  -=
1304  da[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1305  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1306  k*nSpace2+
1307  I*nSpace+
1308  J]
1309  *
1310  grad_phi[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1311  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1312  k*nSpace+
1313  J];
1314  diffusiveVelocityComponent_I_rightJacobian
1315  -=
1316  da[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1317  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1318  k*nSpace2+
1319  I*nSpace+
1320  J]
1321  *
1322  grad_phi[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1323  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1324  k*nSpace+
1325  J];
1326  diffusiveVelocityComponent_I_leftJacobian2
1327  -=
1328  a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1329  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1330  k*nSpace2+
1331  I*nSpace+
1332  J]
1333  *
1334  grad_v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1335  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1336  k*nDOF_trial_element*nSpace+
1337  j*nSpace+
1338  J];
1339  diffusiveVelocityComponent_I_rightJacobian2
1340  -=
1341  a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1342  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1343  k*nSpace2+
1344  I*nSpace+
1345  J]
1346  *
1347  grad_v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1348  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1349  k*nDOF_trial_element*nSpace+
1350  j*nSpace+
1351  J];
1352  max_a = fmax(max_a,a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1353  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1354  k*nSpace2+
1355  I*nSpace+
1356  J]);
1357  max_a = fmax(max_a,a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1358  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1359  k*nSpace2+
1360  I*nSpace+
1361  J]);
1362 
1363  }
1364  leftJacobian
1365  +=
1366  (diffusiveVelocityComponent_I_leftJacobian
1367  *
1368  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1369  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1370  k*nDOF_trial_element+
1371  j]
1372  +
1373  diffusiveVelocityComponent_I_leftJacobian2*
1374  dphi[left_j_global])
1375  *
1376  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1377  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1378  k*nSpace+
1379  I];
1380  rightJacobian
1381  +=
1382  (diffusiveVelocityComponent_I_rightJacobian
1383  *
1384  v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1385  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1386  k*nDOF_trial_element+
1387  j]
1388  +
1389  diffusiveVelocityComponent_I_rightJacobian2*dphi[right_j_global])
1390  *
1391  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1392  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1393  k*nSpace+
1394  I];
1395  }
1396  leftJacobian *= 0.5;
1397  rightJacobian *= 0.5;
1398  max_a = fmax(max_a,penalty_floor);
1399  double penaltyJacobian_term = penalty[ebN*nQuadraturePoints_elementBoundary+
1400  k];
1401  if (scale_penalty) penaltyJacobian_term *= max_a;
1402  leftJacobian
1403  +=
1404  penaltyJacobian_term
1405  *
1406  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1407  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1408  k*nDOF_trial_element+
1409  j];
1410  rightJacobian
1411  -=
1412  penaltyJacobian_term
1413  *
1414  v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1415  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1416  k*nDOF_trial_element+
1417  j];
1418  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1419  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1420  k*nDOF_trial_element+
1421  j] += leftJacobian;
1422  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1423  1*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1424  k*nDOF_trial_element+
1425  j] += rightJacobian;
1426  }
1427  }
1428  }
1429 }
1430 
1432  double penalty_floor,
1433  int nInteriorElementBoundaries_global,
1434  int nElementBoundaries_element,
1435  int nQuadraturePoints_elementBoundary,
1436  int nDOF_trial_element,
1437  int nSpace,
1438  int* rowptr,
1439  int* colind,
1440  int* l2g,
1441  int* interiorElementBoundaries,
1442  int* elementBoundaryElements,
1443  int* elementBoundaryLocalElementBoundaries,
1444  double* n,
1445  double* a,
1446  double* da,
1447  double* grad_phi,
1448  double* dphi,
1449  double* v,
1450  double* grad_v,
1451  double* penalty,
1452  double* fluxJacobian)
1453 {
1454  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,j,left_j_global,right_j_global,I,m,nnz=rowptr[nSpace];
1455  double leftJacobian,rightJacobian,diffusiveVelocityComponent_I_leftJacobian,diffusiveVelocityComponent_I_rightJacobian,diffusiveVelocityComponent_I_leftJacobian2,diffusiveVelocityComponent_I_rightJacobian2,max_a;
1456  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
1457  {
1458  ebN = interiorElementBoundaries[ebNI];
1459  left_eN_global = elementBoundaryElements[ebN*2+0];
1460  right_eN_global = elementBoundaryElements[ebN*2+1];
1461  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
1462  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
1463  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
1464  {
1465  max_a = 0.0;
1466  for(j=0;j<nDOF_trial_element;j++)
1467  {
1468  leftJacobian=0.0;
1469  rightJacobian=0.0;
1470  left_j_global = l2g[left_eN_global*nDOF_trial_element+j];
1471  right_j_global= l2g[right_eN_global*nDOF_trial_element+j];
1472  for(I=0;I<nSpace;I++)
1473  {
1474  diffusiveVelocityComponent_I_leftJacobian=0.0;
1475  diffusiveVelocityComponent_I_leftJacobian2=0.0;
1476  diffusiveVelocityComponent_I_rightJacobian=0.0;
1477  diffusiveVelocityComponent_I_rightJacobian2=0.0;
1478  for(m=rowptr[I];m<rowptr[I+1];m++)
1479  {
1480  diffusiveVelocityComponent_I_leftJacobian
1481  -=
1482  da[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1483  left_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1484  k*nnz+
1485  m]
1486  *
1487  grad_phi[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1488  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1489  k*nSpace+
1490  colind[m]];
1491  diffusiveVelocityComponent_I_rightJacobian
1492  -=
1493  da[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1494  right_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1495  k*nnz+
1496  m]
1497  *
1498  grad_phi[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1499  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1500  k*nSpace+
1501  colind[m]];
1502  diffusiveVelocityComponent_I_leftJacobian2
1503  -=
1504  a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1505  left_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1506  k*nnz+
1507  m]
1508  *
1509  grad_v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1510  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1511  k*nDOF_trial_element*nSpace+
1512  j*nSpace+
1513  colind[m]];
1514  diffusiveVelocityComponent_I_rightJacobian2
1515  -=
1516  a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1517  right_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1518  k*nnz+
1519  m]
1520  *
1521  grad_v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1522  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1523  k*nDOF_trial_element*nSpace+
1524  j*nSpace+
1525  colind[m]];
1526  max_a = fmax(max_a,a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1527  left_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1528  k*nnz+
1529  m]);
1530  max_a = fmax(max_a,a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1531  right_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1532  k*nnz+
1533  m]);
1534 
1535  }
1536  leftJacobian
1537  +=
1538  (diffusiveVelocityComponent_I_leftJacobian
1539  *
1540  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1541  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1542  k*nDOF_trial_element+
1543  j]
1544  +
1545  diffusiveVelocityComponent_I_leftJacobian2*
1546  dphi[left_j_global])
1547  *
1548  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1549  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1550  k*nSpace+
1551  I];
1552  rightJacobian
1553  +=
1554  (diffusiveVelocityComponent_I_rightJacobian
1555  *
1556  v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1557  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1558  k*nDOF_trial_element+
1559  j]
1560  +
1561  diffusiveVelocityComponent_I_rightJacobian2*dphi[right_j_global])
1562  *
1563  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1564  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1565  k*nSpace+
1566  I];
1567  }
1568  leftJacobian *= 0.5;
1569  rightJacobian *= 0.5;
1570  max_a = fmax(max_a,penalty_floor);
1571  double penaltyJacobian_term = penalty[ebN*nQuadraturePoints_elementBoundary+
1572  k];
1573  if (scale_penalty) penaltyJacobian_term *= max_a;
1574  leftJacobian
1575  +=
1576  penaltyJacobian_term
1577  *
1578  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1579  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1580  k*nDOF_trial_element+
1581  j];
1582  rightJacobian
1583  -=
1584  penaltyJacobian_term
1585  *
1586  v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1587  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1588  k*nDOF_trial_element+
1589  j];
1590  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1591  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1592  k*nDOF_trial_element+
1593  j] += leftJacobian;
1594  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1595  1*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1596  k*nDOF_trial_element+
1597  j] += rightJacobian;
1598  }
1599  }
1600  }
1601 }
1602 
1603 /*
1604  \brief Calculate the diffusive flux Jacobian at interior element boundary quadrature points
1605 
1606 void updateInteriorNumericalDiffusiveFluxJacobian(int nInteriorElementBoundaries_global,
1607  int nElementBoundaries_element,
1608  int nQuadraturePoints_elementBoundary,
1609  int nDOF_trial_element,
1610  int nSpace,
1611  int* l2g,
1612  int* interiorElementBoundaries,
1613  int* elementBoundaryElements,
1614  int* elementBoundaryLocalElementBoundaries,
1615  double* n,
1616  double* a,
1617  double* da,
1618  double* grad_phi,
1619  double* dphi,
1620  double* v,
1621  double* grad_v,
1622  double* penalty,
1623  double* fluxJacobian)
1624 {
1625  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,j,left_j_global,right_j_global,I,J,nSpace2=nSpace*nSpace;
1626  double leftJacobian,rightJacobian,diffusiveVelocityComponent_I_leftJacobian,diffusiveVelocityComponent_I_rightJacobian,diffusiveVelocityComponent_I_leftJacobian2,diffusiveVelocityComponent_I_rightJacobian2;
1627  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
1628  {
1629  ebN = interiorElementBoundaries[ebNI];
1630  left_eN_global = elementBoundaryElements[ebN*2+0];
1631  right_eN_global = elementBoundaryElements[ebN*2+1];
1632  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
1633  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
1634  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
1635  {
1636  for(j=0;j<nDOF_trial_element;j++)
1637  {
1638  leftJacobian=0.0;
1639  rightJacobian=0.0;
1640  left_j_global = l2g[left_eN_global*nDOF_trial_element+j];
1641  right_j_global= l2g[right_eN_global*nDOF_trial_element+j];
1642  for(I=0;I<nSpace;I++)
1643  {
1644  diffusiveVelocityComponent_I_leftJacobian=0.0;
1645  diffusiveVelocityComponent_I_leftJacobian2=0.0;
1646  diffusiveVelocityComponent_I_rightJacobian=0.0;
1647  diffusiveVelocityComponent_I_rightJacobian2=0.0;
1648  for(J=0;J<nSpace;J++)
1649  {
1650  diffusiveVelocityComponent_I_leftJacobian
1651  -=
1652  da[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1653  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1654  k*nSpace2+
1655  I*nSpace+
1656  J]
1657  *
1658  grad_phi[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1659  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1660  k*nSpace+
1661  J];
1662  diffusiveVelocityComponent_I_rightJacobian
1663  -=
1664  da[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1665  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1666  k*nSpace2+
1667  I*nSpace+
1668  J]
1669  *
1670  grad_phi[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1671  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1672  k*nSpace+
1673  J];
1674  diffusiveVelocityComponent_I_leftJacobian2
1675  -=
1676  a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1677  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1678  k*nSpace2+
1679  I*nSpace+
1680  J]
1681  *
1682  grad_v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1683  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1684  k*nDOF_trial_element*nSpace+
1685  j*nSpace+
1686  J];
1687  diffusiveVelocityComponent_I_rightJacobian2
1688  -=
1689  a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1690  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1691  k*nSpace2+
1692  I*nSpace+
1693  J]
1694  *
1695  grad_v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1696  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1697  k*nDOF_trial_element*nSpace+
1698  j*nSpace+
1699  J];
1700 
1701  }
1702  leftJacobian
1703  +=
1704  (diffusiveVelocityComponent_I_leftJacobian
1705  *
1706  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1707  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1708  k*nDOF_trial_element+
1709  j]
1710  +
1711  diffusiveVelocityComponent_I_leftJacobian2*
1712  dphi[left_j_global])
1713  *
1714  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1715  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1716  k*nSpace+
1717  I];
1718  rightJacobian
1719  +=
1720  (diffusiveVelocityComponent_I_rightJacobian
1721  *
1722  v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1723  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1724  k*nDOF_trial_element+
1725  j]
1726  +
1727  diffusiveVelocityComponent_I_rightJacobian2*dphi[right_j_global])
1728  *
1729  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1730  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1731  k*nSpace+
1732  I];
1733  }
1734  leftJacobian *= 0.5;
1735  rightJacobian *= 0.5;
1736  leftJacobian
1737  +=
1738  penalty[ebN*nQuadraturePoints_elementBoundary+
1739  k]
1740  *
1741  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1742  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1743  k*nDOF_trial_element+
1744  j];
1745  rightJacobian
1746  -=
1747  penalty[ebN*nQuadraturePoints_elementBoundary+
1748  k]
1749  *
1750  v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1751  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1752  k*nDOF_trial_element+
1753  j];
1754  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1755  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1756  k*nDOF_trial_element+
1757  j] += leftJacobian;
1758  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1759  1*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1760  k*nDOF_trial_element+
1761  j] += rightJacobian;
1762  }
1763  }
1764  }
1765 }
1766 
1767 void updateInteriorNumericalDiffusiveFluxJacobian_sd(int nInteriorElementBoundaries_global,
1768  int nElementBoundaries_element,
1769  int nQuadraturePoints_elementBoundary,
1770  int nDOF_trial_element,
1771  int nSpace,
1772  int* rowptr,
1773  int* colind,
1774  int* l2g,
1775  int* interiorElementBoundaries,
1776  int* elementBoundaryElements,
1777  int* elementBoundaryLocalElementBoundaries,
1778  double* n,
1779  double* a,
1780  double* da,
1781  double* grad_phi,
1782  double* dphi,
1783  double* v,
1784  double* grad_v,
1785  double* penalty,
1786  double* fluxJacobian)
1787 {
1788  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,j,left_j_global,right_j_global,I,m,nnz=rowptr[nSpace];
1789  double leftJacobian,rightJacobian,diffusiveVelocityComponent_I_leftJacobian,diffusiveVelocityComponent_I_rightJacobian,diffusiveVelocityComponent_I_leftJacobian2,diffusiveVelocityComponent_I_rightJacobian2;
1790  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
1791  {
1792  ebN = interiorElementBoundaries[ebNI];
1793  left_eN_global = elementBoundaryElements[ebN*2+0];
1794  right_eN_global = elementBoundaryElements[ebN*2+1];
1795  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
1796  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
1797  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
1798  {
1799  for(j=0;j<nDOF_trial_element;j++)
1800  {
1801  leftJacobian=0.0;
1802  rightJacobian=0.0;
1803  left_j_global = l2g[left_eN_global*nDOF_trial_element+j];
1804  right_j_global= l2g[right_eN_global*nDOF_trial_element+j];
1805  for(I=0;I<nSpace;I++)
1806  {
1807  diffusiveVelocityComponent_I_leftJacobian=0.0;
1808  diffusiveVelocityComponent_I_leftJacobian2=0.0;
1809  diffusiveVelocityComponent_I_rightJacobian=0.0;
1810  diffusiveVelocityComponent_I_rightJacobian2=0.0;
1811  for(m=rowptr[I];m<rowptr[I+1];m++)
1812  {
1813  diffusiveVelocityComponent_I_leftJacobian
1814  -=
1815  da[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1816  left_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1817  k*nnz+
1818  m]
1819  *
1820  grad_phi[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1821  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1822  k*nSpace+
1823  colind[m]];
1824  diffusiveVelocityComponent_I_rightJacobian
1825  -=
1826  da[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1827  right_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1828  k*nnz+
1829  m]
1830  *
1831  grad_phi[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1832  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1833  k*nSpace+
1834  colind[m]];
1835  diffusiveVelocityComponent_I_leftJacobian2
1836  -=
1837  a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1838  left_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1839  k*nnz+
1840  m]
1841  *
1842  grad_v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1843  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1844  k*nDOF_trial_element*nSpace+
1845  j*nSpace+
1846  colind[m]];
1847  diffusiveVelocityComponent_I_rightJacobian2
1848  -=
1849  a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
1850  right_ebN_element*nQuadraturePoints_elementBoundary*nnz+
1851  k*nnz+
1852  m]
1853  *
1854  grad_v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1855  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
1856  k*nDOF_trial_element*nSpace+
1857  j*nSpace+
1858  colind[m]];
1859 
1860  }
1861  leftJacobian
1862  +=
1863  (diffusiveVelocityComponent_I_leftJacobian
1864  *
1865  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1866  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1867  k*nDOF_trial_element+
1868  j]
1869  +
1870  diffusiveVelocityComponent_I_leftJacobian2*
1871  dphi[left_j_global])
1872  *
1873  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1874  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1875  k*nSpace+
1876  I];
1877  rightJacobian
1878  +=
1879  (diffusiveVelocityComponent_I_rightJacobian
1880  *
1881  v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1882  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1883  k*nDOF_trial_element+
1884  j]
1885  +
1886  diffusiveVelocityComponent_I_rightJacobian2*dphi[right_j_global])
1887  *
1888  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1889  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1890  k*nSpace+
1891  I];
1892  }
1893  leftJacobian *= 0.5;
1894  rightJacobian *= 0.5;
1895  leftJacobian
1896  +=
1897  penalty[ebN*nQuadraturePoints_elementBoundary+
1898  k]
1899  *
1900  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1901  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1902  k*nDOF_trial_element+
1903  j];
1904  rightJacobian
1905  -=
1906  penalty[ebN*nQuadraturePoints_elementBoundary+
1907  k]
1908  *
1909  v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1910  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1911  k*nDOF_trial_element+
1912  j];
1913  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1914  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1915  k*nDOF_trial_element+
1916  j] += leftJacobian;
1917  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1918  1*nQuadraturePoints_elementBoundary*nDOF_trial_element+
1919  k*nDOF_trial_element+
1920  j] += rightJacobian;
1921  }
1922  }
1923  }
1924 }
1925 */
1926 
1931  double penalty_floor,
1932  int nExteriorElementBoundaries_global,
1933  int nElementBoundaries_element,
1934  int nQuadraturePoints_elementBoundary,
1935  int nSpace,
1936  int* exteriorElementBoundaries,
1937  int* elementBoundaryElements,
1938  int* elementBoundaryLocalElementBoundaries,
1939  int* isDOFBoundary,
1940  double* n,
1941  double* bc_a,
1942  double* bc_grad_phi,
1943  double* bc_u,
1944  double* a,
1945  double* grad_phi,
1946  double* u,
1947  double* penalty,
1948  double* flux)
1949 {
1950  int ebNE,ebN,eN_global,ebN_element,k,J,I,nSpace2=nSpace*nSpace;
1951  double diffusiveVelocityComponent_I,penaltyFlux,max_a=0.0;
1952  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
1953  {
1954  ebN = exteriorElementBoundaries[ebNE];
1955  eN_global = elementBoundaryElements[ebN*2+0];
1956  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
1957  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
1958  {
1959  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
1960  {
1961  max_a = 0.0;
1962  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
1963  for(I=0;I<nSpace;I++)
1964  {
1965  diffusiveVelocityComponent_I=0.0;
1966  for(J=0;J<nSpace;J++)
1967  {
1968  diffusiveVelocityComponent_I
1969  -=
1970  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1971  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1972  k*nSpace2+
1973  I*nSpace+
1974  J]
1975  *
1976  grad_phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1977  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1978  k*nSpace+J];
1979  max_a = fmax(max_a,a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
1980  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
1981  k*nSpace2+
1982  I*nSpace+
1983  J]);
1984  }
1985  flux[ebN*nQuadraturePoints_elementBoundary+k]
1986  +=
1987  diffusiveVelocityComponent_I
1988  *
1989  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
1990  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
1991  k*nSpace+
1992  I];
1993  }
1994  max_a = fmax(penalty_floor,max_a);
1995  penaltyFlux = penalty[ebN*nQuadraturePoints_elementBoundary+
1996  k]
1997  *
1998  (u[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
1999  ebN_element*nQuadraturePoints_elementBoundary+
2000  k]
2001  -
2002  bc_u[ebNE*nQuadraturePoints_elementBoundary+
2003  k]);
2004  if (scale_penalty) penaltyFlux *= max_a;
2005  flux[ebN*nQuadraturePoints_elementBoundary+k] += penaltyFlux;
2006  }
2007  }
2008  }
2009 }
2011  double penalty_floor,
2012  int nExteriorElementBoundaries_global,
2013  int nElementBoundaries_element,
2014  int nQuadraturePoints_elementBoundary,
2015  int nSpace,
2016  int* rowptr,
2017  int* colind,
2018  int* exteriorElementBoundaries,
2019  int* elementBoundaryElements,
2020  int* elementBoundaryLocalElementBoundaries,
2021  int* isDOFBoundary,
2022  double* n,
2023  double* bc_a,
2024  double* bc_grad_phi,
2025  double* bc_u,
2026  double* a,
2027  double* grad_phi,
2028  double* u,
2029  double* penalty,
2030  double* flux)
2031 {
2032  int ebNE,ebN,eN_global,ebN_element,k,I,m,nnz=rowptr[nSpace];
2033  double diffusiveVelocityComponent_I,penaltyFlux,max_a=0.0;
2034  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2035  {
2036  ebN = exteriorElementBoundaries[ebNE];
2037  eN_global = elementBoundaryElements[ebN*2+0];
2038  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
2039  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
2040  {
2041  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;//cek initializing to zero, hack, need to warn user if diffusion with no Dirichlet or Neumann condition
2042  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
2043  {
2044  max_a = 0.0;
2045  for(I=0;I<nSpace;I++)
2046  {
2047  diffusiveVelocityComponent_I=0.0;
2048  for(m=rowptr[I];m<rowptr[I+1];m++)
2049  {
2050  diffusiveVelocityComponent_I
2051  -=
2052  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
2053  ebN_element*nQuadraturePoints_elementBoundary*nnz+
2054  k*nnz+
2055  m]
2056  *
2057  grad_phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2058  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2059  k*nSpace+colind[m]];
2060  max_a = fmax(max_a,a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
2061  ebN_element*nQuadraturePoints_elementBoundary*nnz+
2062  k*nnz+
2063  m]);
2064  }
2065  flux[ebN*nQuadraturePoints_elementBoundary+k]
2066  +=
2067  diffusiveVelocityComponent_I
2068  *
2069  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2070  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2071  k*nSpace+
2072  I];
2073  }
2074  max_a = fmax(penalty_floor,max_a);
2075  penaltyFlux = penalty[ebN*nQuadraturePoints_elementBoundary+
2076  k]
2077  *
2078  (u[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
2079  ebN_element*nQuadraturePoints_elementBoundary+
2080  k]
2081  -
2082  bc_u[ebNE*nQuadraturePoints_elementBoundary+
2083  k]);
2084  if (scale_penalty) penaltyFlux *= max_a;
2085  flux[ebN*nQuadraturePoints_elementBoundary+k] += penaltyFlux;
2086  }
2087  }
2088  }
2089 }
2094  double penalty_floor,
2095  int nExteriorElementBoundaries_global,
2096  int nQuadraturePoints_elementBoundary,
2097  int nSpace,
2098  int* exteriorElementBoundaries,
2099  int* elementBoundaryElements,
2100  int* elementBoundaryLocalElementBoundaries,
2101  int* isDOFBoundary,
2102  double* n,
2103  double* bc_a,
2104  double* bc_grad_phi,
2105  double* bc_u,
2106  double* a,
2107  double* grad_phi,
2108  double* u,
2109  double* penalty,
2110  double* flux)
2111 {
2112  int ebNE,k,J,I,nSpace2=nSpace*nSpace;
2113  double diffusiveVelocityComponent_I,penaltyFlux,max_a=0.0;
2114  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2115  {
2116  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
2117  {
2118  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
2119  {
2120  flux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
2121  max_a=0.0;
2122  for(I=0;I<nSpace;I++)
2123  {
2124  diffusiveVelocityComponent_I=0.0;
2125  for(J=0;J<nSpace;J++)
2126  {
2127  diffusiveVelocityComponent_I
2128  -=
2129  a[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
2130  k*nSpace2+
2131  I*nSpace+
2132  J]
2133  *
2134  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
2135  k*nSpace+J];
2136  max_a = fmax(max_a,a[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
2137  k*nSpace2+
2138  I*nSpace+
2139  J]);
2140  }
2141  flux[ebNE*nQuadraturePoints_elementBoundary+k]
2142  +=
2143  diffusiveVelocityComponent_I
2144  *
2145  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
2146  k*nSpace+
2147  I];
2148  }
2149  max_a = fmax(max_a,penalty_floor);
2150  penaltyFlux = penalty[ebNE*nQuadraturePoints_elementBoundary+
2151  k]
2152  *
2153  (u[ebNE*nQuadraturePoints_elementBoundary+
2154  k]
2155  -
2156  bc_u[ebNE*nQuadraturePoints_elementBoundary+
2157  k]);
2158  if (scale_penalty) penaltyFlux *= max_a;
2159  flux[ebNE*nQuadraturePoints_elementBoundary+k] += penaltyFlux;
2160  }
2161  }
2162  }
2163 }
2164 
2166  double penalty_floor,
2167  int nExteriorElementBoundaries_global,
2168  int nQuadraturePoints_elementBoundary,
2169  int nSpace,
2170  int* rowptr,
2171  int* colind,
2172  int* exteriorElementBoundaries,
2173  int* elementBoundaryElements,
2174  int* elementBoundaryLocalElementBoundaries,
2175  int* isDOFBoundary,
2176  double* n,
2177  double* bc_a,
2178  double* bc_grad_phi,
2179  double* bc_u,
2180  double* a,
2181  double* grad_phi,
2182  double* u,
2183  double* penalty,
2184  double* flux)
2185 {
2186  int ebNE,k,I,m,nnz=rowptr[nSpace];
2187  double diffusiveVelocityComponent_I,penaltyFlux,max_a;
2188  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2189  {
2190  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
2191  {
2192  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
2193  {
2194  flux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
2195  max_a=0.0;
2196  for(I=0;I<nSpace;I++)
2197  {
2198  diffusiveVelocityComponent_I=0.0;
2199  for(m=rowptr[I];m<rowptr[I+1];m++)
2200  {
2201  diffusiveVelocityComponent_I
2202  -=
2203  a[ebNE*nQuadraturePoints_elementBoundary*nnz+
2204  k*nnz+
2205  m]
2206  *
2207  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
2208  k*nSpace+colind[m]];
2209  max_a = fmax(max_a,a[ebNE*nQuadraturePoints_elementBoundary*nnz+
2210  k*nnz+
2211  m]);
2212  }
2213  flux[ebNE*nQuadraturePoints_elementBoundary+k]
2214  +=
2215  diffusiveVelocityComponent_I
2216  *
2217  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
2218  k*nSpace+
2219  I];
2220  }
2221  max_a = fmax(penalty_floor,max_a);
2222  penaltyFlux = penalty[ebNE*nQuadraturePoints_elementBoundary+
2223  k]
2224  *
2225  (u[ebNE*nQuadraturePoints_elementBoundary+
2226  k]
2227  -
2228  bc_u[ebNE*nQuadraturePoints_elementBoundary+
2229  k]);
2230 
2231  if (scale_penalty) penaltyFlux *= max_a;
2232  flux[ebNE*nQuadraturePoints_elementBoundary+k] += penaltyFlux;
2233  }
2234  }
2235  }
2236 }
2237 
2238 
2239 /*
2240  \brief Calculate the diffusive flux at exterior element boundary quadrature points
2241 
2242 void calculateExteriorNumericalDiffusiveFlux(int nExteriorElementBoundaries_global,
2243  int nElementBoundaries_element,
2244  int nQuadraturePoints_elementBoundary,
2245  int nSpace,
2246  int* exteriorElementBoundaries,
2247  int* elementBoundaryElements,
2248  int* elementBoundaryLocalElementBoundaries,
2249  int* isDOFBoundary,
2250  double* n,
2251  double* bc_a,
2252  double* bc_grad_phi,
2253  double* bc_u,
2254  double* a,
2255  double* grad_phi,
2256  double* u,
2257  double* penalty,
2258  double* flux)
2259 {
2260  int ebNE,ebN,eN_global,ebN_element,k,J,I,nSpace2=nSpace*nSpace;
2261  double diffusiveVelocityComponent_I,penaltyFlux;
2262  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2263  {
2264  ebN = exteriorElementBoundaries[ebNE];
2265  eN_global = elementBoundaryElements[ebN*2+0];
2266  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
2267  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
2268  {
2269  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
2270  {
2271  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
2272  for(I=0;I<nSpace;I++)
2273  {
2274  diffusiveVelocityComponent_I=0.0;
2275  for(J=0;J<nSpace;J++)
2276  {
2277  diffusiveVelocityComponent_I
2278  -=
2279  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
2280  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
2281  k*nSpace2+
2282  I*nSpace+
2283  J]
2284  *
2285  grad_phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2286  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2287  k*nSpace+J];
2288  }
2289  flux[ebN*nQuadraturePoints_elementBoundary+k]
2290  +=
2291  diffusiveVelocityComponent_I
2292  *
2293  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2294  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2295  k*nSpace+
2296  I];
2297  }
2298  penaltyFlux = penalty[ebN*nQuadraturePoints_elementBoundary+
2299  k]
2300  *
2301  (u[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
2302  ebN_element*nQuadraturePoints_elementBoundary+
2303  k]
2304  -
2305  bc_u[ebNE*nQuadraturePoints_elementBoundary+
2306  k]);
2307  flux[ebN*nQuadraturePoints_elementBoundary+k] += penaltyFlux;
2308  }
2309  }
2310  }
2311 }
2312 void calculateExteriorNumericalDiffusiveFlux_sd(int nExteriorElementBoundaries_global,
2313  int nElementBoundaries_element,
2314  int nQuadraturePoints_elementBoundary,
2315  int nSpace,
2316  int* rowptr,
2317  int* colind,
2318  int* exteriorElementBoundaries,
2319  int* elementBoundaryElements,
2320  int* elementBoundaryLocalElementBoundaries,
2321  int* isDOFBoundary,
2322  double* n,
2323  double* bc_a,
2324  double* bc_grad_phi,
2325  double* bc_u,
2326  double* a,
2327  double* grad_phi,
2328  double* u,
2329  double* penalty,
2330  double* flux)
2331 {
2332  int ebNE,ebN,eN_global,ebN_element,k,I,m,nnz=rowptr[nSpace];
2333  double diffusiveVelocityComponent_I,penaltyFlux;
2334  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2335  {
2336  ebN = exteriorElementBoundaries[ebNE];
2337  eN_global = elementBoundaryElements[ebN*2+0];
2338  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
2339  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
2340  {
2341  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;//cek initializing to zero, hack, need to warn user if diffusion with no Dirichlet or Neumann condition
2342  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
2343  {
2344  for(I=0;I<nSpace;I++)
2345  {
2346  diffusiveVelocityComponent_I=0.0;
2347  for(m=rowptr[I];m<rowptr[I+1];m++)
2348  {
2349  diffusiveVelocityComponent_I
2350  -=
2351  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
2352  ebN_element*nQuadraturePoints_elementBoundary*nnz+
2353  k*nnz+
2354  m]
2355  *
2356  grad_phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2357  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2358  k*nSpace+colind[m]];
2359  }
2360  flux[ebN*nQuadraturePoints_elementBoundary+k]
2361  +=
2362  diffusiveVelocityComponent_I
2363  *
2364  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2365  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2366  k*nSpace+
2367  I];
2368  }
2369  penaltyFlux = penalty[ebN*nQuadraturePoints_elementBoundary+
2370  k]
2371  *
2372  (u[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
2373  ebN_element*nQuadraturePoints_elementBoundary+
2374  k]
2375  -
2376  bc_u[ebNE*nQuadraturePoints_elementBoundary+
2377  k]);
2378  flux[ebN*nQuadraturePoints_elementBoundary+k] += penaltyFlux;
2379  }
2380  }
2381  }
2382 } */
2383 /*
2384  \brief Calculate the diffusive flux at exterior element boundary quadrature points
2385 
2386 void calculateGlobalExteriorNumericalDiffusiveFlux(int nExteriorElementBoundaries_global,
2387  int nQuadraturePoints_elementBoundary,
2388  int nSpace,
2389  int* exteriorElementBoundaries,
2390  int* elementBoundaryElements,
2391  int* elementBoundaryLocalElementBoundaries,
2392  int* isDOFBoundary,
2393  double* n,
2394  double* bc_a,
2395  double* bc_grad_phi,
2396  double* bc_u,
2397  double* a,
2398  double* grad_phi,
2399  double* u,
2400  double* penalty,
2401  double* flux)
2402 {
2403  int ebNE,k,J,I,nSpace2=nSpace*nSpace;
2404  double diffusiveVelocityComponent_I,penaltyFlux,max_a;
2405  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2406  {
2407  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
2408  {
2409  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
2410  {
2411  flux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
2412  max_a=0.0;
2413  for(I=0;I<nSpace;I++)
2414  {
2415  diffusiveVelocityComponent_I=0.0;
2416  for(J=0;J<nSpace;J++)
2417  {
2418  diffusiveVelocityComponent_I
2419  -=
2420  a[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
2421  k*nSpace2+
2422  I*nSpace+
2423  J]
2424  *
2425  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
2426  k*nSpace+J];
2427  max_a = fmax(max_a,a[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
2428  k*nSpace2+
2429  I*nSpace+
2430  J]);
2431  }
2432  flux[ebNE*nQuadraturePoints_elementBoundary+k]
2433  +=
2434  diffusiveVelocityComponent_I
2435  *
2436  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
2437  k*nSpace+
2438  I];
2439  }
2440  penaltyFlux = penalty[ebNE*nQuadraturePoints_elementBoundary+
2441  k]
2442  *
2443  (u[ebNE*nQuadraturePoints_elementBoundary+
2444  k]
2445  -
2446  bc_u[ebNE*nQuadraturePoints_elementBoundary+
2447  k]);
2448  flux[ebNE*nQuadraturePoints_elementBoundary+k] += penaltyFlux;
2449  }
2450  }
2451  }
2452 }
2453 
2454 void calculateGlobalExteriorNumericalDiffusiveFlux_sd(int nExteriorElementBoundaries_global,
2455  int nQuadraturePoints_elementBoundary,
2456  int nSpace,
2457  int* rowptr,
2458  int* colind,
2459  int* exteriorElementBoundaries,
2460  int* elementBoundaryElements,
2461  int* elementBoundaryLocalElementBoundaries,
2462  int* isDOFBoundary,
2463  double* n,
2464  double* bc_a,
2465  double* bc_grad_phi,
2466  double* bc_u,
2467  double* a,
2468  double* grad_phi,
2469  double* u,
2470  double* penalty,
2471  double* flux)
2472 {
2473  int ebNE,k,I,m,nnz=rowptr[nSpace];
2474  double diffusiveVelocityComponent_I,penaltyFlux,max_a;
2475  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2476  {
2477  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
2478  {
2479  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
2480  {
2481  flux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
2482  max_a=0.0;
2483  for(I=0;I<nSpace;I++)
2484  {
2485  diffusiveVelocityComponent_I=0.0;
2486  for(m=rowptr[I];m<rowptr[I+1];m++)
2487  {
2488  diffusiveVelocityComponent_I
2489  -=
2490  a[ebNE*nQuadraturePoints_elementBoundary*nnz+
2491  k*nnz+
2492  m]
2493  *
2494  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
2495  k*nSpace+colind[m]];
2496  max_a = fmax(max_a,a[ebNE*nQuadraturePoints_elementBoundary*nnz+
2497  k*nnz+
2498  m]);
2499  }
2500  flux[ebNE*nQuadraturePoints_elementBoundary+k]
2501  +=
2502  diffusiveVelocityComponent_I
2503  *
2504  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
2505  k*nSpace+
2506  I];
2507  }
2508  penaltyFlux = penalty[ebNE*nQuadraturePoints_elementBoundary+
2509  k]
2510  *
2511  (u[ebNE*nQuadraturePoints_elementBoundary+
2512  k]
2513  -
2514  bc_u[ebNE*nQuadraturePoints_elementBoundary+
2515  k]);
2516  flux[ebNE*nQuadraturePoints_elementBoundary+k] += penaltyFlux;
2517  }
2518  }
2519  }
2520 }
2521 */
2522 
2523 void calculateExteriorNumericalDiffusiveFlux_free(int nExteriorElementBoundaries_global,
2524  int nElementBoundaries_element,
2525  int nQuadraturePoints_elementBoundary,
2526  int nSpace,
2527  int* exteriorElementBoundaries,
2528  int* elementBoundaryElements,
2529  int* elementBoundaryLocalElementBoundaries,
2530  int* isDOFBoundary,
2531  double* n,
2532  double* bc_a,
2533  double* bc_grad_phi,
2534  double* bc_u,
2535  double* a,
2536  double* grad_phi,
2537  double* u,
2538  double* penalty,
2539  double* flux)
2540 {
2541  int ebNE,ebN,eN_global,ebN_element,k,J,I,nSpace2=nSpace*nSpace;
2542  double diffusiveVelocityComponent_I;
2543  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2544  {
2545  ebN = exteriorElementBoundaries[ebNE];
2546  eN_global = elementBoundaryElements[ebN*2+0];
2547  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
2548  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
2549  {
2550  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
2551  for(I=0;I<nSpace;I++)
2552  {
2553  diffusiveVelocityComponent_I=0.0;
2554  for(J=0;J<nSpace;J++)
2555  {
2556  diffusiveVelocityComponent_I
2557  -=
2558  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
2559  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
2560  k*nSpace2+
2561  I*nSpace+
2562  J]
2563  *
2564  grad_phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2565  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2566  k*nSpace+J];
2567  }
2568  flux[ebN*nQuadraturePoints_elementBoundary+k]
2569  +=
2570  diffusiveVelocityComponent_I
2571  *
2572  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2573  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2574  k*nSpace+
2575  I];
2576  }
2577  }
2578  }
2579 }
2580 void calculateExteriorNumericalDiffusiveFlux_free_sd(int nExteriorElementBoundaries_global,
2581  int nElementBoundaries_element,
2582  int nQuadraturePoints_elementBoundary,
2583  int nSpace,
2584  int* rowptr,
2585  int* colind,
2586  int* exteriorElementBoundaries,
2587  int* elementBoundaryElements,
2588  int* elementBoundaryLocalElementBoundaries,
2589  int* isDOFBoundary,
2590  double* n,
2591  double* bc_a,
2592  double* bc_grad_phi,
2593  double* bc_u,
2594  double* a,
2595  double* grad_phi,
2596  double* u,
2597  double* penalty,
2598  double* flux)
2599 {
2600  int ebNE,ebN,eN_global,ebN_element,k,I,m,nnz=rowptr[nSpace];
2601  double diffusiveVelocityComponent_I;
2602  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2603  {
2604  ebN = exteriorElementBoundaries[ebNE];
2605  eN_global = elementBoundaryElements[ebN*2+0];
2606  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
2607  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
2608  {
2609  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
2610  for(I=0;I<nSpace;I++)
2611  {
2612  diffusiveVelocityComponent_I=0.0;
2613  for(m=rowptr[I];m<rowptr[I+1];m++)
2614  {
2615  diffusiveVelocityComponent_I
2616  -=
2617  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
2618  ebN_element*nQuadraturePoints_elementBoundary*nnz+
2619  k*nnz+
2620  m]
2621  *
2622  grad_phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2623  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2624  k*nSpace+colind[m]];
2625  }
2626  flux[ebN*nQuadraturePoints_elementBoundary+k]
2627  +=
2628  diffusiveVelocityComponent_I
2629  *
2630  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2631  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2632  k*nSpace+
2633  I];
2634  }
2635  }
2636  }
2637 }
2638 void calculateGlobalExteriorNumericalDiffusiveFlux_free(int nExteriorElementBoundaries_global,
2639  int nQuadraturePoints_elementBoundary,
2640  int nSpace,
2641  int* exteriorElementBoundaries,
2642  int* elementBoundaryElements,
2643  int* elementBoundaryLocalElementBoundaries,
2644  int* isDOFBoundary,
2645  double* n,
2646  double* bc_a,
2647  double* bc_grad_phi,
2648  double* bc_u,
2649  double* a,
2650  double* grad_phi,
2651  double* u,
2652  double* penalty,
2653  double* flux)
2654 {
2655  int ebNE,k,J,I,nSpace2=nSpace*nSpace;
2656  double diffusiveVelocityComponent_I;
2657  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2658  {
2659  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
2660  {
2661  flux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
2662  for(I=0;I<nSpace;I++)
2663  {
2664  diffusiveVelocityComponent_I=0.0;
2665  for(J=0;J<nSpace;J++)
2666  {
2667  diffusiveVelocityComponent_I
2668  -=
2669  a[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
2670  k*nSpace2+
2671  I*nSpace+
2672  J]
2673  *
2674  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
2675  k*nSpace+J];
2676  }
2677  flux[ebNE*nQuadraturePoints_elementBoundary+k]
2678  +=
2679  diffusiveVelocityComponent_I
2680  *
2681  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
2682  k*nSpace+
2683  I];
2684  }
2685  }
2686  }
2687 }
2688 void calculateGlobalExteriorNumericalDiffusiveFlux_free_sd(int nExteriorElementBoundaries_global,
2689  int nQuadraturePoints_elementBoundary,
2690  int nSpace,
2691  int* rowptr,
2692  int* colind,
2693  int* exteriorElementBoundaries,
2694  int* elementBoundaryElements,
2695  int* elementBoundaryLocalElementBoundaries,
2696  int* isDOFBoundary,
2697  double* n,
2698  double* bc_a,
2699  double* bc_grad_phi,
2700  double* bc_u,
2701  double* a,
2702  double* grad_phi,
2703  double* u,
2704  double* penalty,
2705  double* flux)
2706 {
2707  int ebNE,k,I,m,nnz=rowptr[nSpace];
2708  double diffusiveVelocityComponent_I;
2709  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2710  {
2711  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
2712  {
2713  flux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
2714  for(I=0;I<nSpace;I++)
2715  {
2716  diffusiveVelocityComponent_I=0.0;
2717  for(m=rowptr[I];m<rowptr[I+1];m++)
2718  {
2719  diffusiveVelocityComponent_I
2720  -=
2721  a[ebNE*nQuadraturePoints_elementBoundary*nnz+
2722  k*nnz+
2723  m]
2724  *
2725  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
2726  k*nSpace+colind[m]];
2727  }
2728  flux[ebNE*nQuadraturePoints_elementBoundary+k]
2729  +=
2730  diffusiveVelocityComponent_I
2731  *
2732  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
2733  k*nSpace+
2734  I];
2735  }
2736  }
2737  }
2738 }
2739 
2744  double penalty_floor,
2745  int nExteriorElementBoundaries_global,
2746  int nElementBoundaries_element,
2747  int nQuadraturePoints_elementBoundary,
2748  int nDOF_trial_element,
2749  int nSpace,
2750  int* l2g,
2751  int* exteriorElementBoundaries,
2752  int* elementBoundaryElements,
2753  int* elementBoundaryLocalElementBoundaries,
2754  int* isDOFBoundary,
2755  double* n,
2756  double* a,
2757  double* da,
2758  double* grad_phi,
2759  double* dphi,
2760  double* v,
2761  double* grad_v,
2762  double* penalty,
2763  double* fluxJacobian)
2764 {
2765  int ebNE,ebN,eN_global,ebN_element,k,j,j_global,I,J,nSpace2=nSpace*nSpace;
2766  double Jacobian,diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2,max_a=0.0;
2767  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2768  {
2769  ebN = exteriorElementBoundaries[ebNE];
2770  eN_global = elementBoundaryElements[ebN*2+0];
2771  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
2772  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
2773  {
2774  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
2775  {
2776  max_a = 0.0;
2777  for(j=0;j<nDOF_trial_element;j++)
2778  {
2779  Jacobian=0.0;
2780  j_global = l2g[eN_global*nDOF_trial_element+j];
2781  for(I=0;I<nSpace;I++)
2782  {
2783  diffusiveVelocityComponent_I_Jacobian=0.0;
2784  diffusiveVelocityComponent_I_Jacobian2=0.0;
2785  for(J=0;J<nSpace;J++)
2786  {
2787  diffusiveVelocityComponent_I_Jacobian
2788  -=
2789  da[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
2790  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
2791  k*nSpace2+
2792  I*nSpace+
2793  J]
2794  *
2795  grad_phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2796  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2797  k*nSpace+
2798  J];
2799  diffusiveVelocityComponent_I_Jacobian2
2800  -=
2801  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
2802  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
2803  k*nSpace2+
2804  I*nSpace+
2805  J]
2806  *
2807  grad_v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
2808  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
2809  k*nDOF_trial_element*nSpace+
2810  j*nSpace+
2811  J];
2812  max_a = fmax(max_a,a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
2813  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
2814  k*nSpace2+
2815  I*nSpace+
2816  J]);
2817  }
2818  Jacobian
2819  +=
2820  (diffusiveVelocityComponent_I_Jacobian
2821  *
2822  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
2823  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
2824  k*nDOF_trial_element+
2825  j]
2826  +
2827  diffusiveVelocityComponent_I_Jacobian2*
2828  dphi[j_global])
2829  *
2830  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2831  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2832  k*nSpace+
2833  I];
2834  }
2835  max_a = fmax(penalty_floor,max_a);
2836  double penaltyJacobian = penalty[ebN*nQuadraturePoints_elementBoundary+
2837  k]
2838  *
2839  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
2840  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
2841  k*nDOF_trial_element+
2842  j];
2843  if (scale_penalty) penaltyJacobian *= max_a;
2844  Jacobian += penaltyJacobian;
2845  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
2846  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
2847  k*nDOF_trial_element+
2848  j]
2849  += Jacobian;
2850  }
2851  }
2852  }
2853  }
2854 }
2855 
2857  double penalty_floor,
2858  int nExteriorElementBoundaries_global,
2859  int nElementBoundaries_element,
2860  int nQuadraturePoints_elementBoundary,
2861  int nDOF_trial_element,
2862  int nSpace,
2863  int* rowptr,
2864  int* colind,
2865  int* l2g,
2866  int* exteriorElementBoundaries,
2867  int* elementBoundaryElements,
2868  int* elementBoundaryLocalElementBoundaries,
2869  int* isDOFBoundary,
2870  double* n,
2871  double* a,
2872  double* da,
2873  double* grad_phi,
2874  double* dphi,
2875  double* v,
2876  double* grad_v,
2877  double* penalty,
2878  double* fluxJacobian)
2879 {
2880  int ebNE,ebN,eN_global,ebN_element,k,j,j_global,I,m,nnz=rowptr[nSpace];
2881  double Jacobian,diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2,max_a=0.0;
2882  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2883  {
2884  ebN = exteriorElementBoundaries[ebNE];
2885  eN_global = elementBoundaryElements[ebN*2+0];
2886  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
2887  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
2888  {
2889  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
2890  {
2891  max_a=0.0;
2892  for(j=0;j<nDOF_trial_element;j++)
2893  {
2894  Jacobian=0.0;
2895  j_global = l2g[eN_global*nDOF_trial_element+j];
2896  for(I=0;I<nSpace;I++)
2897  {
2898  diffusiveVelocityComponent_I_Jacobian=0.0;
2899  diffusiveVelocityComponent_I_Jacobian2=0.0;
2900  for(m=rowptr[I];m<rowptr[I+1];m++)
2901  {
2902  diffusiveVelocityComponent_I_Jacobian
2903  -=
2904  da[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
2905  ebN_element*nQuadraturePoints_elementBoundary*nnz+
2906  k*nnz+
2907  m]
2908  *
2909  grad_phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2910  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2911  k*nSpace+
2912  colind[m]];
2913  diffusiveVelocityComponent_I_Jacobian2
2914  -=
2915  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
2916  ebN_element*nQuadraturePoints_elementBoundary*nnz+
2917  k*nnz+
2918  m]
2919  *
2920  grad_v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
2921  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
2922  k*nDOF_trial_element*nSpace+
2923  j*nSpace+
2924  colind[m]];
2925  max_a = fmax(max_a,a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
2926  ebN_element*nQuadraturePoints_elementBoundary*nnz+
2927  k*nnz+
2928  m]);
2929  }
2930  Jacobian
2931  +=
2932  (diffusiveVelocityComponent_I_Jacobian
2933  *
2934  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
2935  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
2936  k*nDOF_trial_element+
2937  j]
2938  +
2939  diffusiveVelocityComponent_I_Jacobian2*
2940  dphi[j_global])
2941  *
2942  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
2943  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
2944  k*nSpace+
2945  I];
2946  }
2947  max_a = fmax(penalty_floor,max_a);
2948  double penaltyJacobian = penalty[ebN*nQuadraturePoints_elementBoundary+
2949  k]
2950  *
2951  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
2952  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
2953  k*nDOF_trial_element+
2954  j];
2955 
2956  if (scale_penalty) penaltyJacobian *= max_a;
2957 
2958  Jacobian += penaltyJacobian;
2959 
2960  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
2961  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
2962  k*nDOF_trial_element+
2963  j]
2964  += Jacobian;
2965  }
2966  }
2967  }
2968  }
2969 }
2974  double penalty_floor,
2975  int nExteriorElementBoundaries_global,
2976  int nQuadraturePoints_elementBoundary,
2977  int nDOF_trial_element,
2978  int nSpace,
2979  int* l2g,
2980  int* exteriorElementBoundaries,
2981  int* elementBoundaryElements,
2982  int* elementBoundaryLocalElementBoundaries,
2983  int* isDOFBoundary,
2984  double* n,
2985  double* a,
2986  double* da,
2987  double* grad_phi,
2988  double* dphi,
2989  double* v,
2990  double* grad_v,
2991  double* penalty,
2992  double* fluxJacobian)
2993 {
2994  int ebNE,ebN,eN_global,k,j,j_global,I,J,nSpace2=nSpace*nSpace;
2995  double Jacobian,diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2,max_a;
2996  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
2997  {
2998  ebN = exteriorElementBoundaries[ebNE];
2999  eN_global = elementBoundaryElements[ebN*2+0];
3000  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
3001  {
3002  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] >= 1)
3003  {
3004  for(j=0;j<nDOF_trial_element;j++)
3005  {
3006  Jacobian=0.0;
3007  j_global = l2g[eN_global*nDOF_trial_element+j];
3008  max_a=0.0;
3009  for(I=0;I<nSpace;I++)
3010  {
3011  diffusiveVelocityComponent_I_Jacobian=0.0;
3012  diffusiveVelocityComponent_I_Jacobian2=0.0;
3013  for(J=0;J<nSpace;J++)
3014  {
3015  diffusiveVelocityComponent_I_Jacobian
3016  -=
3017  da[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
3018  k*nSpace2+
3019  I*nSpace+
3020  J]
3021  *
3022  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
3023  k*nSpace+
3024  J];
3025  diffusiveVelocityComponent_I_Jacobian2
3026  -=
3027  a[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
3028  k*nSpace2+
3029  I*nSpace+
3030  J]
3031  *
3032  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3033  k*nDOF_trial_element*nSpace+
3034  j*nSpace+
3035  J];
3036  max_a = fmax(max_a,a[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
3037  k*nSpace2+
3038  I*nSpace+
3039  J]);
3040 
3041  }
3042  Jacobian
3043  +=
3044  (diffusiveVelocityComponent_I_Jacobian
3045  *
3046  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3047  k*nDOF_trial_element+
3048  j]
3049  +
3050  diffusiveVelocityComponent_I_Jacobian2*
3051  dphi[j_global])
3052  *
3053  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
3054  k*nSpace+
3055  I];
3056  }
3057  max_a = fmax(penalty_floor,max_a);
3058  double penaltyJacobian = penalty[ebNE*nQuadraturePoints_elementBoundary+
3059  k]
3060  *
3061  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3062  k*nDOF_trial_element+
3063  j];
3064  if (scale_penalty) penaltyJacobian *= max_a;
3065 
3066  Jacobian += penaltyJacobian;
3067 
3068  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3069  k*nDOF_trial_element+
3070  j]
3071  += Jacobian;
3072  }
3073  }
3074  }
3075  }
3076 }
3078  double penalty_floor,
3079  int nExteriorElementBoundaries_global,
3080  int nQuadraturePoints_elementBoundary,
3081  int nDOF_trial_element,
3082  int nSpace,
3083  int* rowptr,
3084  int* colind,
3085  int* l2g,
3086  int* exteriorElementBoundaries,
3087  int* elementBoundaryElements,
3088  int* elementBoundaryLocalElementBoundaries,
3089  int* isDOFBoundary,
3090  double* n,
3091  double* a,
3092  double* da,
3093  double* grad_phi,
3094  double* dphi,
3095  double* v,
3096  double* grad_v,
3097  double* penalty,
3098  double* fluxJacobian)
3099 {
3100  int ebNE,ebN,eN_global,k,j,j_global,I,m,nnz=rowptr[nSpace];
3101  double Jacobian,diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2,max_a;
3102  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
3103  {
3104  ebN = exteriorElementBoundaries[ebNE];
3105  eN_global = elementBoundaryElements[ebN*2+0];
3106  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
3107  {
3108  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] >= 1)
3109  {
3110  for(j=0;j<nDOF_trial_element;j++)
3111  {
3112  Jacobian=0.0;
3113  j_global = l2g[eN_global*nDOF_trial_element+j];
3114  max_a=0.0;
3115  for(I=0;I<nSpace;I++)
3116  {
3117  diffusiveVelocityComponent_I_Jacobian=0.0;
3118  diffusiveVelocityComponent_I_Jacobian2=0.0;
3119  for(m=rowptr[I];m<rowptr[I+1];m++)
3120  {
3121  diffusiveVelocityComponent_I_Jacobian
3122  -=
3123  da[ebNE*nQuadraturePoints_elementBoundary*nnz+
3124  k*nnz+
3125  m]
3126  *
3127  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
3128  k*nSpace+
3129  colind[m]];
3130  diffusiveVelocityComponent_I_Jacobian2
3131  -=
3132  a[ebNE*nQuadraturePoints_elementBoundary*nnz+
3133  k*nnz+
3134  m]
3135  *
3136  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3137  k*nDOF_trial_element*nSpace+
3138  j*nSpace+
3139  colind[m]];
3140  max_a = fmax(max_a,a[ebNE*nQuadraturePoints_elementBoundary*nnz+
3141  k*nnz+
3142  m]);
3143 
3144  }
3145  Jacobian
3146  +=
3147  (diffusiveVelocityComponent_I_Jacobian
3148  *
3149  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3150  k*nDOF_trial_element+
3151  j]
3152  +
3153  diffusiveVelocityComponent_I_Jacobian2*
3154  dphi[j_global])
3155  *
3156  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
3157  k*nSpace+
3158  I];
3159  }
3160  max_a = fmax(penalty_floor,max_a);
3161 
3162  double penaltyJacobian = penalty[ebNE*nQuadraturePoints_elementBoundary+
3163  k]
3164  *
3165  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3166  k*nDOF_trial_element+
3167  j];
3168  if (scale_penalty) penaltyJacobian *= max_a;
3169 
3170  Jacobian += penaltyJacobian;
3171 
3172  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3173  k*nDOF_trial_element+
3174  j]
3175  += Jacobian;
3176  }
3177  }
3178  }
3179  }
3180 }
3181 
3182 /*
3183  \brief Update the diffusive flux Jacobian at exterior element boundary quadrature points
3184 
3185 void updateExteriorNumericalDiffusiveFluxJacobian(int nExteriorElementBoundaries_global,
3186  int nElementBoundaries_element,
3187  int nQuadraturePoints_elementBoundary,
3188  int nDOF_trial_element,
3189  int nSpace,
3190  int* l2g,
3191  int* exteriorElementBoundaries,
3192  int* elementBoundaryElements,
3193  int* elementBoundaryLocalElementBoundaries,
3194  int* isDOFBoundary,
3195  double* n,
3196  double* a,
3197  double* da,
3198  double* grad_phi,
3199  double* dphi,
3200  double* v,
3201  double* grad_v,
3202  double* penalty,
3203  double* fluxJacobian)
3204 {
3205  int ebNE,ebN,eN_global,ebN_element,k,j,j_global,I,J,nSpace2=nSpace*nSpace;
3206  double Jacobian,diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2;
3207  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
3208  {
3209  ebN = exteriorElementBoundaries[ebNE];
3210  eN_global = elementBoundaryElements[ebN*2+0];
3211  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
3212  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
3213  {
3214  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
3215  {
3216  for(j=0;j<nDOF_trial_element;j++)
3217  {
3218  Jacobian=0.0;
3219  j_global = l2g[eN_global*nDOF_trial_element+j];
3220  for(I=0;I<nSpace;I++)
3221  {
3222  diffusiveVelocityComponent_I_Jacobian=0.0;
3223  diffusiveVelocityComponent_I_Jacobian2=0.0;
3224  for(J=0;J<nSpace;J++)
3225  {
3226  diffusiveVelocityComponent_I_Jacobian
3227  -=
3228  da[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
3229  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
3230  k*nSpace2+
3231  I*nSpace+
3232  J]
3233  *
3234  grad_phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3235  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3236  k*nSpace+
3237  J];
3238  diffusiveVelocityComponent_I_Jacobian2
3239  -=
3240  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
3241  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
3242  k*nSpace2+
3243  I*nSpace+
3244  J]
3245  *
3246  grad_v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3247  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3248  k*nDOF_trial_element*nSpace+
3249  j*nSpace+
3250  J];
3251  }
3252  Jacobian
3253  +=
3254  (diffusiveVelocityComponent_I_Jacobian
3255  *
3256  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3257  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3258  k*nDOF_trial_element+
3259  j]
3260  +
3261  diffusiveVelocityComponent_I_Jacobian2*
3262  dphi[j_global])
3263  *
3264  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3265  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3266  k*nSpace+
3267  I];
3268  }
3269  Jacobian
3270  +=
3271  penalty[ebN*nQuadraturePoints_elementBoundary+
3272  k]
3273  *
3274  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3275  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3276  k*nDOF_trial_element+
3277  j];
3278  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3279  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3280  k*nDOF_trial_element+
3281  j]
3282  += Jacobian;
3283  }
3284  }
3285  }
3286  }
3287 }
3288 void updateExteriorNumericalDiffusiveFluxJacobian_sd(int nExteriorElementBoundaries_global,
3289  int nElementBoundaries_element,
3290  int nQuadraturePoints_elementBoundary,
3291  int nDOF_trial_element,
3292  int nSpace,
3293  int* rowptr,
3294  int* colind,
3295  int* l2g,
3296  int* exteriorElementBoundaries,
3297  int* elementBoundaryElements,
3298  int* elementBoundaryLocalElementBoundaries,
3299  int* isDOFBoundary,
3300  double* n,
3301  double* a,
3302  double* da,
3303  double* grad_phi,
3304  double* dphi,
3305  double* v,
3306  double* grad_v,
3307  double* penalty,
3308  double* fluxJacobian)
3309 {
3310  int ebNE,ebN,eN_global,ebN_element,k,j,j_global,I,m,nnz=rowptr[nSpace];
3311  double Jacobian,diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2;
3312  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
3313  {
3314  ebN = exteriorElementBoundaries[ebNE];
3315  eN_global = elementBoundaryElements[ebN*2+0];
3316  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
3317  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
3318  {
3319  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
3320  {
3321  for(j=0;j<nDOF_trial_element;j++)
3322  {
3323  Jacobian=0.0;
3324  j_global = l2g[eN_global*nDOF_trial_element+j];
3325  for(I=0;I<nSpace;I++)
3326  {
3327  diffusiveVelocityComponent_I_Jacobian=0.0;
3328  diffusiveVelocityComponent_I_Jacobian2=0.0;
3329  for(m=rowptr[I];m<rowptr[I+1];m++)
3330  {
3331  diffusiveVelocityComponent_I_Jacobian
3332  -=
3333  da[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
3334  ebN_element*nQuadraturePoints_elementBoundary*nnz+
3335  k*nnz+
3336  m]
3337  *
3338  grad_phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3339  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3340  k*nSpace+
3341  colind[m]];
3342  diffusiveVelocityComponent_I_Jacobian2
3343  -=
3344  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
3345  ebN_element*nQuadraturePoints_elementBoundary*nnz+
3346  k*nnz+
3347  m]
3348  *
3349  grad_v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3350  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3351  k*nDOF_trial_element*nSpace+
3352  j*nSpace+
3353  colind[m]];
3354  }
3355  Jacobian
3356  +=
3357  (diffusiveVelocityComponent_I_Jacobian
3358  *
3359  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3360  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3361  k*nDOF_trial_element+
3362  j]
3363  +
3364  diffusiveVelocityComponent_I_Jacobian2*
3365  dphi[j_global])
3366  *
3367  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3368  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3369  k*nSpace+
3370  I];
3371  }
3372  Jacobian
3373  +=
3374  penalty[ebN*nQuadraturePoints_elementBoundary+
3375  k]
3376  *
3377  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3378  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3379  k*nDOF_trial_element+
3380  j];
3381  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3382  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3383  k*nDOF_trial_element+
3384  j]
3385  += Jacobian;
3386  }
3387  }
3388  }
3389  }
3390 } */
3391 /*
3392  \brief Update the diffusive flux Jacobian at exterior element boundary quadrature points
3393 
3394 void updateGlobalExteriorNumericalDiffusiveFluxJacobian(int nExteriorElementBoundaries_global,
3395  int nQuadraturePoints_elementBoundary,
3396  int nDOF_trial_element,
3397  int nSpace,
3398  int* l2g,
3399  int* exteriorElementBoundaries,
3400  int* elementBoundaryElements,
3401  int* elementBoundaryLocalElementBoundaries,
3402  int* isDOFBoundary,
3403  double* n,
3404  double* a,
3405  double* da,
3406  double* grad_phi,
3407  double* dphi,
3408  double* v,
3409  double* grad_v,
3410  double* penalty,
3411  double* fluxJacobian)
3412 {
3413  int ebNE,ebN,eN_global,k,j,j_global,I,J,nSpace2=nSpace*nSpace;
3414  double Jacobian,diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2,max_a;
3415  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
3416  {
3417  ebN = exteriorElementBoundaries[ebNE];
3418  eN_global = elementBoundaryElements[ebN*2+0];
3419  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
3420  {
3421  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] >= 1)
3422  {
3423  for(j=0;j<nDOF_trial_element;j++)
3424  {
3425  Jacobian=0.0;
3426  j_global = l2g[eN_global*nDOF_trial_element+j];
3427  max_a=0.0;
3428  for(I=0;I<nSpace;I++)
3429  {
3430  diffusiveVelocityComponent_I_Jacobian=0.0;
3431  diffusiveVelocityComponent_I_Jacobian2=0.0;
3432  for(J=0;J<nSpace;J++)
3433  {
3434  diffusiveVelocityComponent_I_Jacobian
3435  -=
3436  da[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
3437  k*nSpace2+
3438  I*nSpace+
3439  J]
3440  *
3441  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
3442  k*nSpace+
3443  J];
3444  diffusiveVelocityComponent_I_Jacobian2
3445  -=
3446  a[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
3447  k*nSpace2+
3448  I*nSpace+
3449  J]
3450  *
3451  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3452  k*nDOF_trial_element*nSpace+
3453  j*nSpace+
3454  J];
3455  max_a = fmax(max_a,a[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
3456  k*nSpace2+
3457  I*nSpace+
3458  J]);
3459 
3460  }
3461  Jacobian
3462  +=
3463  (diffusiveVelocityComponent_I_Jacobian
3464  *
3465  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3466  k*nDOF_trial_element+
3467  j]
3468  +
3469  diffusiveVelocityComponent_I_Jacobian2*
3470  dphi[j_global])
3471  *
3472  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
3473  k*nSpace+
3474  I];
3475  }
3476  Jacobian
3477  +=
3478  penalty[ebNE*nQuadraturePoints_elementBoundary+
3479  k]
3480  *
3481  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3482  k*nDOF_trial_element+
3483  j];
3484  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3485  k*nDOF_trial_element+
3486  j]
3487  += Jacobian;
3488  }
3489  }
3490  }
3491  }
3492 }
3493 void updateGlobalExteriorNumericalDiffusiveFluxJacobian_sd(int nExteriorElementBoundaries_global,
3494  int nQuadraturePoints_elementBoundary,
3495  int nDOF_trial_element,
3496  int nSpace,
3497  int* rowptr,
3498  int* colind,
3499  int* l2g,
3500  int* exteriorElementBoundaries,
3501  int* elementBoundaryElements,
3502  int* elementBoundaryLocalElementBoundaries,
3503  int* isDOFBoundary,
3504  double* n,
3505  double* a,
3506  double* da,
3507  double* grad_phi,
3508  double* dphi,
3509  double* v,
3510  double* grad_v,
3511  double* penalty,
3512  double* fluxJacobian)
3513 {
3514  int ebNE,ebN,eN_global,k,j,j_global,I,m,nnz=rowptr[nSpace];
3515  double Jacobian,diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2,max_a;
3516  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
3517  {
3518  ebN = exteriorElementBoundaries[ebNE];
3519  eN_global = elementBoundaryElements[ebN*2+0];
3520  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
3521  {
3522  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] >= 1)
3523  {
3524  for(j=0;j<nDOF_trial_element;j++)
3525  {
3526  Jacobian=0.0;
3527  j_global = l2g[eN_global*nDOF_trial_element+j];
3528  max_a=0.0;
3529  for(I=0;I<nSpace;I++)
3530  {
3531  diffusiveVelocityComponent_I_Jacobian=0.0;
3532  diffusiveVelocityComponent_I_Jacobian2=0.0;
3533  for(m=rowptr[I];m<rowptr[I+1];m++)
3534  {
3535  diffusiveVelocityComponent_I_Jacobian
3536  -=
3537  da[ebNE*nQuadraturePoints_elementBoundary*nnz+
3538  k*nnz+
3539  m]
3540  *
3541  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
3542  k*nSpace+
3543  colind[m]];
3544  diffusiveVelocityComponent_I_Jacobian2
3545  -=
3546  a[ebNE*nQuadraturePoints_elementBoundary*nnz+
3547  k*nnz+
3548  m]
3549  *
3550  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3551  k*nDOF_trial_element*nSpace+
3552  j*nSpace+
3553  colind[m]];
3554  max_a = fmax(max_a,a[ebNE*nQuadraturePoints_elementBoundary*nnz+
3555  k*nnz+
3556  I*nSpace+
3557  m]);
3558 
3559  }
3560  Jacobian
3561  +=
3562  (diffusiveVelocityComponent_I_Jacobian
3563  *
3564  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3565  k*nDOF_trial_element+
3566  j]
3567  +
3568  diffusiveVelocityComponent_I_Jacobian2*
3569  dphi[j_global])
3570  *
3571  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
3572  k*nSpace+
3573  I];
3574  }
3575  Jacobian
3576  +=
3577  penalty[ebNE*nQuadraturePoints_elementBoundary+
3578  k]
3579  *
3580  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3581  k*nDOF_trial_element+
3582  j];
3583  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3584  k*nDOF_trial_element+
3585  j]
3586  += Jacobian;
3587  }
3588  }
3589  }
3590  }
3591 }*/
3592 
3593 void updateExteriorNumericalDiffusiveFluxJacobian_free(int nExteriorElementBoundaries_global,
3594  int nElementBoundaries_element,
3595  int nQuadraturePoints_elementBoundary,
3596  int nDOF_trial_element,
3597  int nSpace,
3598  int* l2g,
3599  int* exteriorElementBoundaries,
3600  int* elementBoundaryElements,
3601  int* elementBoundaryLocalElementBoundaries,
3602  int* isDOFBoundary,
3603  double* n,
3604  double* a,
3605  double* da,
3606  double* grad_phi,
3607  double* dphi,
3608  double* v,
3609  double* grad_v,
3610  double* penalty,
3611  double* fluxJacobian)
3612 {
3613  int ebNE,ebN,eN_global,ebN_element,k,j,j_global,I,J,nSpace2=nSpace*nSpace;
3614  double diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2;
3615  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
3616  {
3617  ebN = exteriorElementBoundaries[ebNE];
3618  eN_global = elementBoundaryElements[ebN*2+0];
3619  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
3620  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
3621  {
3622  for(j=0;j<nDOF_trial_element;j++)
3623  {
3624  j_global = l2g[eN_global*nDOF_trial_element+j];
3625  for(I=0;I<nSpace;I++)
3626  {
3627  diffusiveVelocityComponent_I_Jacobian=0.0;
3628  diffusiveVelocityComponent_I_Jacobian2=0.0;
3629  for(J=0;J<nSpace;J++)
3630  {
3631  diffusiveVelocityComponent_I_Jacobian
3632  -=
3633  da[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
3634  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
3635  k*nSpace2+
3636  I*nSpace+
3637  J]
3638  *
3639  grad_phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3640  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3641  k*nSpace+
3642  J];
3643  diffusiveVelocityComponent_I_Jacobian2
3644  -=
3645  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
3646  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
3647  k*nSpace2+
3648  I*nSpace+
3649  J]
3650  *
3651  grad_v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3652  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3653  k*nDOF_trial_element*nSpace+
3654  j*nSpace+
3655  J];
3656  }
3657  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3658  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3659  k*nDOF_trial_element+
3660  j]+=
3661  (diffusiveVelocityComponent_I_Jacobian
3662  *
3663  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3664  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3665  k*nDOF_trial_element+
3666  j]
3667  +
3668  diffusiveVelocityComponent_I_Jacobian2*
3669  dphi[j_global])
3670  *
3671  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3672  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3673  k*nSpace+
3674  I];
3675  }
3676  }
3677  }
3678  }
3679 }
3680 void updateExteriorNumericalDiffusiveFluxJacobian_free_sd(int nExteriorElementBoundaries_global,
3681  int nElementBoundaries_element,
3682  int nQuadraturePoints_elementBoundary,
3683  int nDOF_trial_element,
3684  int nSpace,
3685  int* rowptr,
3686  int* colind,
3687  int* l2g,
3688  int* exteriorElementBoundaries,
3689  int* elementBoundaryElements,
3690  int* elementBoundaryLocalElementBoundaries,
3691  int* isDOFBoundary,
3692  double* n,
3693  double* a,
3694  double* da,
3695  double* grad_phi,
3696  double* dphi,
3697  double* v,
3698  double* grad_v,
3699  double* penalty,
3700  double* fluxJacobian)
3701 {
3702  int ebNE,ebN,eN_global,ebN_element,k,j,j_global,I,m,nnz=rowptr[nSpace];
3703  double diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2;
3704  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
3705  {
3706  ebN = exteriorElementBoundaries[ebNE];
3707  eN_global = elementBoundaryElements[ebN*2+0];
3708  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
3709  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
3710  {
3711  for(j=0;j<nDOF_trial_element;j++)
3712  {
3713  j_global = l2g[eN_global*nDOF_trial_element+j];
3714  for(I=0;I<nSpace;I++)
3715  {
3716  diffusiveVelocityComponent_I_Jacobian=0.0;
3717  diffusiveVelocityComponent_I_Jacobian2=0.0;
3718  for(m=rowptr[I];m<rowptr[I+1];m++)
3719  {
3720  diffusiveVelocityComponent_I_Jacobian
3721  -=
3722  da[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
3723  ebN_element*nQuadraturePoints_elementBoundary*nnz+
3724  k*nnz+
3725  m]
3726  *
3727  grad_phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3728  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3729  k*nSpace+
3730  colind[m]];
3731  diffusiveVelocityComponent_I_Jacobian2
3732  -=
3733  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
3734  ebN_element*nQuadraturePoints_elementBoundary*nnz+
3735  k*nnz+
3736  m]
3737  *
3738  grad_v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3739  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3740  k*nDOF_trial_element*nSpace+
3741  j*nSpace+
3742  colind[m]];
3743  }
3744  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3745  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3746  k*nDOF_trial_element+
3747  j]+=
3748  (diffusiveVelocityComponent_I_Jacobian
3749  *
3750  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3751  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3752  k*nDOF_trial_element+
3753  j]
3754  +
3755  diffusiveVelocityComponent_I_Jacobian2*
3756  dphi[j_global])
3757  *
3758  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3759  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3760  k*nSpace+
3761  I];
3762  }
3763  }
3764  }
3765  }
3766 }
3767 
3768 void updateGlobalExteriorNumericalDiffusiveFluxJacobian_free(int nExteriorElementBoundaries_global,
3769  int nQuadraturePoints_elementBoundary,
3770  int nDOF_trial_element,
3771  int nSpace,
3772  int* l2g,
3773  int* exteriorElementBoundaries,
3774  int* elementBoundaryElements,
3775  int* elementBoundaryLocalElementBoundaries,
3776  int* isDOFBoundary,
3777  double* n,
3778  double* a,
3779  double* da,
3780  double* grad_phi,
3781  double* dphi,
3782  double* v,
3783  double* grad_v,
3784  double* penalty,
3785  double* fluxJacobian)
3786 {
3787  int ebNE,ebN,eN_global,k,j,j_global,I,J,nSpace2=nSpace*nSpace;
3788  double diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2;
3789  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
3790  {
3791  ebN = exteriorElementBoundaries[ebNE];
3792  eN_global = elementBoundaryElements[ebN*2+0];
3793  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
3794  {
3795  for(j=0;j<nDOF_trial_element;j++)
3796  {
3797  j_global = l2g[eN_global*nDOF_trial_element+j];
3798  for(I=0;I<nSpace;I++)
3799  {
3800  diffusiveVelocityComponent_I_Jacobian=0.0;
3801  diffusiveVelocityComponent_I_Jacobian2=0.0;
3802  for(J=0;J<nSpace;J++)
3803  {
3804  diffusiveVelocityComponent_I_Jacobian
3805  -=
3806  da[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
3807  k*nSpace2+
3808  I*nSpace+
3809  J]
3810  *
3811  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
3812  k*nSpace+
3813  J];
3814  diffusiveVelocityComponent_I_Jacobian2
3815  -=
3816  a[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
3817  k*nSpace2+
3818  I*nSpace+
3819  J]
3820  *
3821  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3822  k*nDOF_trial_element*nSpace+
3823  j*nSpace+
3824  J];
3825  }
3826  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3827  k*nDOF_trial_element+
3828  j]+=
3829  (diffusiveVelocityComponent_I_Jacobian
3830  *
3831  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3832  k*nDOF_trial_element+
3833  j]
3834  +
3835  diffusiveVelocityComponent_I_Jacobian2*
3836  dphi[j_global])
3837  *
3838  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
3839  k*nSpace+
3840  I];
3841  }
3842  }
3843  }
3844  }
3845 }
3846 void updateGlobalExteriorNumericalDiffusiveFluxJacobian_free_sd(int nExteriorElementBoundaries_global,
3847  int nQuadraturePoints_elementBoundary,
3848  int nDOF_trial_element,
3849  int nSpace,
3850  int* rowptr,
3851  int* colind,
3852  int* l2g,
3853  int* exteriorElementBoundaries,
3854  int* elementBoundaryElements,
3855  int* elementBoundaryLocalElementBoundaries,
3856  int* isDOFBoundary,
3857  double* n,
3858  double* a,
3859  double* da,
3860  double* grad_phi,
3861  double* dphi,
3862  double* v,
3863  double* grad_v,
3864  double* penalty,
3865  double* fluxJacobian)
3866 {
3867  int ebNE,ebN,eN_global,k,j,j_global,I,m,nnz=rowptr[nSpace];
3868  double diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2;
3869  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
3870  {
3871  ebN = exteriorElementBoundaries[ebNE];
3872  eN_global = elementBoundaryElements[ebN*2+0];
3873  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
3874  {
3875  for(j=0;j<nDOF_trial_element;j++)
3876  {
3877  j_global = l2g[eN_global*nDOF_trial_element+j];
3878  for(I=0;I<nSpace;I++)
3879  {
3880  diffusiveVelocityComponent_I_Jacobian=0.0;
3881  diffusiveVelocityComponent_I_Jacobian2=0.0;
3882  for(m=rowptr[I];m<rowptr[I+1];m++)
3883  {
3884  diffusiveVelocityComponent_I_Jacobian
3885  -=
3886  da[ebNE*nQuadraturePoints_elementBoundary*nnz+
3887  k*nnz+
3888  m]
3889  *
3890  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
3891  k*nSpace+
3892  colind[m]];
3893  diffusiveVelocityComponent_I_Jacobian2
3894  -=
3895  a[ebNE*nQuadraturePoints_elementBoundary*nnz+
3896  k*nnz+
3897  m]
3898  *
3899  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
3900  k*nDOF_trial_element*nSpace+
3901  j*nSpace+
3902  colind[m]];
3903  }
3904  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3905  k*nDOF_trial_element+
3906  j]+=
3907  (diffusiveVelocityComponent_I_Jacobian
3908  *
3909  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
3910  k*nDOF_trial_element+
3911  j]
3912  +
3913  diffusiveVelocityComponent_I_Jacobian2*
3914  dphi[j_global])
3915  *
3916  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
3917  k*nSpace+
3918  I];
3919  }
3920  }
3921  }
3922  }
3923 }
3927 void calculateInteriorNumericalAdvectiveFlux(int nInteriorElementBoundaries_global,
3928  int nElementBoundaries_element,
3929  int nQuadraturePoints_elementBoundary,
3930  int nSpace,
3931  int* interiorElementBoundaries,
3932  int* elementBoundaryElements,
3933  int* elementBoundaryLocalElementBoundaries,
3934  double* n,
3935  double* u,
3936  double* f,
3937  double* df,
3938  double* flux,
3939  double* dflux_left,
3940  double* dflux_right)
3941 {
3942  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,J;
3943  double left_speed,right_speed,left_flux,right_flux,shock_speed,flux_jump,u_jump;
3944  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
3945  {
3946  ebN = interiorElementBoundaries[ebNI];
3947  left_eN_global = elementBoundaryElements[ebN*2+0];
3948  right_eN_global = elementBoundaryElements[ebN*2+1];
3949  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
3950  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
3951  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
3952  {
3953  left_speed=0.0;
3954  right_speed=0.0;
3955  left_flux=0.0;
3956  right_flux=0.0;
3957  /*mwf add default shock speed is zero*/
3958  shock_speed=0.0;
3959  for(J=0;J<nSpace;J++)
3960  {
3961  left_speed
3962  +=
3963  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3964  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3965  k*nSpace+
3966  J]
3967  *
3968  df[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3969  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3970  k*nSpace+
3971  J];
3972  right_speed
3973  +=
3974  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3975  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3976  k*nSpace+
3977  J]
3978  *
3979  df[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3980  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3981  k*nSpace+
3982  J];
3983  left_flux
3984  +=
3985  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3986  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3987  k*nSpace+
3988  J]
3989  *
3990  f[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3991  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3992  k*nSpace+
3993  J];
3994  right_flux
3995  +=
3996  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
3997  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
3998  k*nSpace+
3999  J]
4000  *
4001  f[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4002  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4003  k*nSpace+
4004  J];
4005  }
4006  flux_jump = (right_flux - left_flux);
4007  u_jump = (u[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
4008  right_ebN_element*nQuadraturePoints_elementBoundary+
4009  k]
4010  -
4011  u[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
4012  left_ebN_element*nQuadraturePoints_elementBoundary+
4013  k]);
4014  if (fabs(u_jump) > fabs(flux_jump*1.0e-16))
4015  shock_speed = flux_jump/u_jump;
4016  if (left_speed >= 0.0 && right_speed >= 0.0)
4017  {
4018  flux[ebN*nQuadraturePoints_elementBoundary+
4019  k] = left_flux;
4020  dflux_left[ebN*nQuadraturePoints_elementBoundary+
4021  k] = left_speed;
4022  dflux_right[ebN*nQuadraturePoints_elementBoundary+
4023  k] = 0.0;
4024  }
4025  else if (left_speed <= 0.0 && right_speed <= 0.0)
4026  {
4027  flux[ebN*nQuadraturePoints_elementBoundary+
4028  k] = right_flux;
4029  dflux_left[ebN*nQuadraturePoints_elementBoundary+
4030  k] = 0.0;
4031  dflux_right[ebN*nQuadraturePoints_elementBoundary+
4032  k] = right_speed;
4033  }
4034  else if (left_speed >= 0.0 && right_speed <= 0.0)
4035  {
4036  if (shock_speed >= 0.0)
4037  {
4038  flux[ebN*nQuadraturePoints_elementBoundary+
4039  k] = left_flux;
4040  dflux_left[ebN*nQuadraturePoints_elementBoundary+
4041  k] = left_speed;
4042  dflux_right[ebN*nQuadraturePoints_elementBoundary+
4043  k] = 0.0;
4044  }
4045  else
4046  {
4047  flux[ebN*nQuadraturePoints_elementBoundary+
4048  k] = right_flux;
4049  dflux_left[ebN*nQuadraturePoints_elementBoundary+
4050  k] = 0.0;
4051  dflux_right[ebN*nQuadraturePoints_elementBoundary+
4052  k] = right_speed;
4053  }
4054  }
4055  else
4056  {
4057  /*transonic rarefaction*/
4058  printf("Transonic rarefaction detected in interior. This numerical flux treats transonic rarefactions incorrectly. left_speed= %12.5e right_speed= %12.5e \n",left_speed,right_speed);
4059  for (J=0; J < nSpace; J++)
4060  {
4061  printf("n_l[%d]=%g df_l[%d]=%g df_r[%d]=%g \n",J,
4062  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4063  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4064  k*nSpace+
4065  J],
4066  J,
4067  df[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4068  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4069  k*nSpace+
4070  J],
4071  J,
4072  df[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4073  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4074  k*nSpace+
4075  J]);
4076 
4077  }
4078  flux[ebN*nQuadraturePoints_elementBoundary+
4079  k] = 0.5*(left_flux + right_flux);
4080  dflux_left[ebN*nQuadraturePoints_elementBoundary+
4081  k] = 0.5*left_speed;
4082  dflux_right[ebN*nQuadraturePoints_elementBoundary+
4083  k] = 0.5*right_speed;
4084  }
4085  }
4086  }
4087 }
4088 
4092 void updateInteriorNumericalAdvectiveFluxJacobian(int nInteriorElementBoundaries_global,
4093  int nElementBoundaries_element,
4094  int nQuadraturePoints_elementBoundary,
4095  int nDOF_trial_element,
4096  int* interiorElementBoundaries,
4097  int* elementBoundaryElements,
4098  int* elementBoundaryLocalElementBoundaries,
4099  double* dflux_left,
4100  double* dflux_right,
4101  double* v,
4102  double* fluxJacobian)
4103 {
4104  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,j;
4105  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
4106  {
4107  ebN = interiorElementBoundaries[ebNI];
4108  left_eN_global = elementBoundaryElements[ebN*2+0];
4109  right_eN_global = elementBoundaryElements[ebN*2+1];
4110  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
4111  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
4112  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
4113  for(j=0;j<nDOF_trial_element;j++)
4114  {
4115  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4116  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4117  k*nDOF_trial_element+
4118  j]
4119  +=
4120  dflux_left[ebN*nQuadraturePoints_elementBoundary+
4121  k]
4122  *
4123  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4124  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4125  k*nDOF_trial_element+
4126  j];
4127  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4128  1*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4129  k*nDOF_trial_element+
4130  j]
4131  +=
4132  dflux_right[ebN*nQuadraturePoints_elementBoundary+
4133  k]
4134  *
4135  v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4136  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4137  k*nDOF_trial_element+
4138  j];
4139  }
4140  }
4141 }
4145 void updateInteriorTwoSidedNumericalFluxJacobian(int nInteriorElementBoundaries_global,
4146  int nElementBoundaries_element,
4147  int nQuadraturePoints_elementBoundary,
4148  int nDOF_trial_element,
4149  int* interiorElementBoundaries,
4150  int* elementBoundaryElements,
4151  int* elementBoundaryLocalElementBoundaries,
4152  double* dflux_left,
4153  double* dflux_right,
4154  double* v,
4155  double* fluxJacobian_2sided)
4156 {
4157  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,j;
4158  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
4159  {
4160  ebN = interiorElementBoundaries[ebNI];
4161  left_eN_global = elementBoundaryElements[ebN*2+0];
4162  right_eN_global = elementBoundaryElements[ebN*2+1];
4163  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
4164  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
4165  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
4166  for(j=0;j<nDOF_trial_element;j++)
4167  {
4168  /*left neighbour flux first*/
4169  fluxJacobian_2sided[ebN*2*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4170  0*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+/*left flux*/
4171  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+/*left neig. dep*/
4172  k*nDOF_trial_element+
4173  j]
4174  +=
4175  dflux_left[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
4176  left_ebN_element*nQuadraturePoints_elementBoundary+
4177  k]
4178  *
4179  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4180  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4181  k*nDOF_trial_element+
4182  j];
4183  fluxJacobian_2sided[ebN*2*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4184  0*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+/*left flux*/
4185  1*nQuadraturePoints_elementBoundary*nDOF_trial_element+/*right neig. dep*/
4186  k*nDOF_trial_element+
4187  j]
4188  +=
4189  dflux_right[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
4190  left_ebN_element*nQuadraturePoints_elementBoundary+
4191  k]
4192  *
4193  v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4194  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4195  k*nDOF_trial_element+
4196  j];
4197  /*right neighbour flux*/
4198  fluxJacobian_2sided[ebN*2*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4199  1*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+/*right flux*/
4200  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+/*left neig. dep*/
4201  k*nDOF_trial_element+
4202  j]
4203  +=
4204  dflux_left[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
4205  right_ebN_element*nQuadraturePoints_elementBoundary+
4206  k]
4207  *
4208  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4209  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4210  k*nDOF_trial_element+
4211  j];
4212  fluxJacobian_2sided[ebN*2*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4213  1*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+/*right flux*/
4214  1*nQuadraturePoints_elementBoundary*nDOF_trial_element+/*right neig. dep*/
4215  k*nDOF_trial_element+
4216  j]
4217  +=
4218  dflux_right[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
4219  right_ebN_element*nQuadraturePoints_elementBoundary+
4220  k]
4221  *
4222  v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4223  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
4224  k*nDOF_trial_element+
4225  j];
4226  }
4227  }
4228 }
4229 
4233 void calculateInteriorNumericalAdvectiveFlux_average(int nInteriorElementBoundaries_global,
4234  int nElementBoundaries_element,
4235  int nQuadraturePoints_elementBoundary,
4236  int nSpace,
4237  int* interiorElementBoundaries,
4238  int* elementBoundaryElements,
4239  int* elementBoundaryLocalElementBoundaries,
4240  double* n,
4241  double* u,
4242  double* f,
4243  double* df,
4244  double* flux,
4245  double* dflux_left,
4246  double* dflux_right)
4247 {
4248  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,J;
4249  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
4250  {
4251  ebN = interiorElementBoundaries[ebNI];
4252  left_eN_global = elementBoundaryElements[ebN*2+0];
4253  right_eN_global = elementBoundaryElements[ebN*2+1];
4254  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
4255  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
4256  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
4257  {
4258  flux[ebN*nQuadraturePoints_elementBoundary+
4259  k] =0.0;
4260  dflux_left[ebN*nQuadraturePoints_elementBoundary+
4261  k] = 0.0;
4262  dflux_right[ebN*nQuadraturePoints_elementBoundary+
4263  k] = 0.0;
4264  for(J=0;J<nSpace;J++)
4265  {
4266  flux[ebN*nQuadraturePoints_elementBoundary+
4267  k] += n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4268  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4269  k*nSpace+
4270  J]
4271  *
4272  (f[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4273  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4274  k*nSpace+
4275  J]
4276  +
4277  f[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4278  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4279  k*nSpace+
4280  J]);
4281  dflux_left[ebN*nQuadraturePoints_elementBoundary+
4282  k] += n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4283  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4284  k*nSpace+
4285  J]
4286  *
4287  df[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4288  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4289  k*nSpace+
4290  J];
4291  dflux_right[ebN*nQuadraturePoints_elementBoundary+
4292  k] += n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4293  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4294  k*nSpace+
4295  J]
4296  *
4297  df[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4298  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4299  k*nSpace+
4300  J];
4301  }
4302  flux[ebN*nQuadraturePoints_elementBoundary+
4303  k] *= 0.5;
4304  dflux_left[ebN*nQuadraturePoints_elementBoundary+
4305  k] *= 0.5;
4306  dflux_right[ebN*nQuadraturePoints_elementBoundary+
4307  k] *= 0.5;
4308  }
4309  }
4310 }
4311 
4315 void calculateExteriorNumericalAdvectiveFlux_NoBC(int nExteriorElementBoundaries_global,
4316  int nElementBoundaries_element,
4317  int nQuadraturePoints_elementBoundary,
4318  int nSpace,
4319  int* exteriorElementBoundaries,
4320  int* elementBoundaryElements,
4321  int* elementBoundaryLocalElementBoundaries,
4322  int* inflowFlag,
4323  double* n,
4324  double* f,
4325  double* df,
4326  double* flux,
4327  double* dflux_left)
4328 {
4329  int ebNE,ebN,eN_global,ebN_element,k,J;
4330  memset(inflowFlag,0,sizeof(int)*nExteriorElementBoundaries_global*nQuadraturePoints_elementBoundary);
4331  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
4332  {
4333  ebN = exteriorElementBoundaries[ebNE];
4334  eN_global = elementBoundaryElements[ebN*2+0];
4335  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
4336  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
4337  {
4338  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
4339  dflux_left[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
4340  inflowFlag[ebNE*nQuadraturePoints_elementBoundary+k]=0;
4341  for(J=0;J<nSpace;J++)
4342  {
4343  flux[ebN*nQuadraturePoints_elementBoundary+k]
4344  +=
4345  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4346  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4347  k*nSpace+
4348  J]
4349  *
4350  f[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4351  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4352  k*nSpace+
4353  J];
4354  dflux_left[ebN*nQuadraturePoints_elementBoundary+k]
4355  +=
4356  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4357  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4358  k*nSpace+
4359  J]
4360  *
4361  df[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4362  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4363  k*nSpace+
4364  J];
4365  }
4366  if(dflux_left[ebN*nQuadraturePoints_elementBoundary+k] < 0.0)
4367  {
4368  /* cek debug, setting inflow flow to zero */
4369  inflowFlag[ebNE*nQuadraturePoints_elementBoundary+k] = 1;
4370  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
4371  dflux_left[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
4372  }
4373  }
4374  }
4375 }
4379 void calculateGlobalExteriorNumericalAdvectiveFlux_NoBC(int nExteriorElementBoundaries_global,
4380  int nQuadraturePoints_elementBoundary,
4381  int nSpace,
4382  int* exteriorElementBoundaries,
4383  int* elementBoundaryElements,
4384  int* elementBoundaryLocalElementBoundaries,
4385  int* inflowFlag,
4386  double* n,
4387  double* f,
4388  double* df,
4389  double* flux,
4390  double* dflux_left)
4391 {
4392  int ebNE,ebN,eN_global,ebN_element,k,J;
4393  memset(inflowFlag,0,sizeof(int)*nExteriorElementBoundaries_global*nQuadraturePoints_elementBoundary);
4394  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
4395  {
4396  ebN = exteriorElementBoundaries[ebNE];
4397  eN_global = elementBoundaryElements[ebN*2+0];
4398  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
4399  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
4400  {
4401  flux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
4402  dflux_left[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
4403  inflowFlag[ebNE*nQuadraturePoints_elementBoundary+k]=0;
4404  for(J=0;J<nSpace;J++)
4405  {
4406  flux[ebNE*nQuadraturePoints_elementBoundary+k]
4407  +=
4408  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4409  k*nSpace+
4410  J]
4411  *
4412  f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4413  k*nSpace+
4414  J];
4415  dflux_left[ebNE*nQuadraturePoints_elementBoundary+k]
4416  +=
4417  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4418  k*nSpace+
4419  J]
4420  *
4421  df[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4422  k*nSpace+
4423  J];
4424  }
4425  if(dflux_left[ebNE*nQuadraturePoints_elementBoundary+k] < 0.0)
4426  {
4427  /* cek debug, setting inflow flow to zero */
4428  inflowFlag[ebNE*nQuadraturePoints_elementBoundary+k] = 1;
4429  flux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
4430  dflux_left[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
4431  }
4432  }
4433  }
4434 }
4435 
4439 void calculateExteriorNumericalAdvectiveFlux(int nExteriorElementBoundaries_global,
4440  int nElementBoundaries_element,
4441  int nQuadraturePoints_elementBoundary,
4442  int nSpace,
4443  int* exteriorElementBoundaries,
4444  int* elementBoundaryElements,
4445  int* elementBoundaryLocalElementBoundaries,
4446  int *isDOFBoundary,
4447  int *inflowFlag,
4448  double* n,
4449  double* bc_u,
4450  double* bc_f,
4451  double* bc_df,
4452  double* u,
4453  double* f,
4454  double* df,
4455  double* flux,
4456  double* dflux)
4457 {
4458  int ebNE,ebN,eN_global,ebN_element,k,J;
4459  double left_speed,right_speed,left_flux,right_flux,shock_speed,flux_jump,u_jump;
4460  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
4461  {
4462  ebN = exteriorElementBoundaries[ebNE];
4463  eN_global = elementBoundaryElements[ebN*2+0];
4464  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
4465  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
4466  {
4467  left_speed=0.0;
4468  right_speed=0.0;
4469  left_flux=0.0;
4470  right_flux=0.0;
4471  /*mwf add default shock speed is zero*/
4472  shock_speed=0.0;
4473  for(J=0;J<nSpace;J++)
4474  {
4475  left_speed
4476  +=
4477  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4478  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4479  k*nSpace+
4480  J]
4481  *
4482  df[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4483  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4484  k*nSpace+
4485  J];
4486  right_speed
4487  +=
4488  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4489  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4490  k*nSpace+
4491  J]
4492  *
4493  bc_df[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4494  k*nSpace+
4495  J];
4496  left_flux
4497  +=
4498  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4499  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4500  k*nSpace+
4501  J]
4502  *
4503  f[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4504  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4505  k*nSpace+
4506  J];
4507  right_flux
4508  +=
4509  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4510  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4511  k*nSpace+
4512  J]
4513  *
4514  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4515  k*nSpace+
4516  J];
4517  }
4518  flux_jump = (right_flux - left_flux);
4519  u_jump = (bc_u[ebNE*nQuadraturePoints_elementBoundary+
4520  k]
4521  -
4522  u[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
4523  ebN_element*nQuadraturePoints_elementBoundary+
4524  k]);
4525  if (fabs(u_jump) > fabs(flux_jump*1.0e-16))
4526  shock_speed = flux_jump/u_jump;
4527  if (left_speed >= 0.0 && right_speed >= 0.0)
4528  {
4529  flux[ebN*nQuadraturePoints_elementBoundary+
4530  k] = left_flux;
4531  dflux[ebN*nQuadraturePoints_elementBoundary+
4532  k] = left_speed;
4533  }
4534  else if (left_speed <= 0.0 && right_speed <= 0.0)
4535  {
4536  flux[ebN*nQuadraturePoints_elementBoundary+
4537  k] = right_flux;
4538  if (isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
4539  dflux[ebN*nQuadraturePoints_elementBoundary+
4540  k] = 0.0;
4541  else
4542  dflux[ebN*nQuadraturePoints_elementBoundary+
4543  k] = right_speed;
4544  }
4545  else if (left_speed >= 0.0 && right_speed <= 0.0)
4546  {
4547  if (shock_speed >= 0.0)
4548  {
4549  flux[ebN*nQuadraturePoints_elementBoundary+
4550  k] = left_flux;
4551  dflux[ebN*nQuadraturePoints_elementBoundary+
4552  k] = left_speed;
4553  }
4554  else
4555  {
4556  flux[ebN*nQuadraturePoints_elementBoundary+
4557  k] = right_flux;
4558  if (isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
4559  dflux[ebN*nQuadraturePoints_elementBoundary+
4560  k] = 0.0;
4561  else
4562  dflux[ebN*nQuadraturePoints_elementBoundary+
4563  k] = right_speed;
4564  }
4565  }
4566  else
4567  {
4568  /*transonic rarefaction*/
4569  printf("Transonic rarefaction detected on exterior. This numerical flux treats transonic rarefactions incorrectly. left_speed= %12.5e right_speed= %12.5e \n",left_speed,right_speed);
4570  for (J=0; J < nSpace; J++)
4571  {
4572  printf("n_l[%d]=%g df_l[%d]=%g df_r[%d]=%g \n",J,
4573  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4574  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4575  k*nSpace+
4576  J],
4577  J,
4578  df[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4579  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4580  k*nSpace+
4581  J],
4582  J,
4583  bc_df[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4584  k*nSpace+
4585  J]);
4586 
4587  }
4588  flux[ebN*nQuadraturePoints_elementBoundary+
4589  k] = 0.5*(left_flux + right_flux);
4590  if (isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
4591  dflux[ebN*nQuadraturePoints_elementBoundary+
4592  k] = 0.5*left_speed;
4593  else
4594  dflux[ebN*nQuadraturePoints_elementBoundary+
4595  k] = 0.5*(left_speed+right_speed);
4596  }
4597 /* printf("exterior flux %d %d %12.5e \n",ebN,k,flux[ebN*nQuadraturePoints_elementBoundary+k]); */
4598  /*mwf debug
4599  printf("in exterior diagonal eN=%d u_left=%g left_flux=%g left_speed=%g bc_u=%g right_flux=%g right_speed=%g shock_speed=%g\n",
4600  eN_global,u[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
4601  ebN_element*nQuadraturePoints_elementBoundary+
4602  k],
4603  left_flux,
4604  left_speed,
4605  bc_u[ebNE*nQuadraturePoints_elementBoundary+
4606  k],
4607  right_flux,
4608  right_speed,
4609  shock_speed);
4610  printf("\tflux = %g n=[",flux[ebN*nQuadraturePoints_elementBoundary+k]);
4611  for (J=0; J < nSpace; J++)
4612  printf(" %g ",n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4613  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4614  k*nSpace+
4615  J]);
4616  printf("]\n");
4617  mwf end debug */
4618 /* if(dflux[ebN*nQuadraturePoints_elementBoundary+k] < 0.0) */
4619 /* { */
4620 /* /\* cek debug, setting inflow flow to zero *\/ */
4621 /* inflowFlag[ebNE*nQuadraturePoints_elementBoundary+k] = 1; */
4622 /* flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0; */
4623 /* dflux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0; */
4624 /* } */
4625  }
4626  }
4627 }
4628 
4632 void calculateGlobalExteriorNumericalAdvectiveFlux(int nExteriorElementBoundaries_global,
4633  int nQuadraturePoints_elementBoundary,
4634  int nSpace,
4635  int* exteriorElementBoundaries,
4636  int* elementBoundaryElements,
4637  int* elementBoundaryLocalElementBoundaries,
4638  int *isDOFBoundary,
4639  int *inflowFlag,
4640  double* n,
4641  double* bc_u,
4642  double* bc_f,
4643  double* bc_df,
4644  double* u,
4645  double* f,
4646  double* df,
4647  double* flux,
4648  double* dflux)
4649 {
4650  int ebNE,ebN,eN_global,k,J;
4651  double left_speed,right_speed,left_flux,right_flux,shock_speed,flux_jump,u_jump;
4652  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
4653  {
4654  ebN = exteriorElementBoundaries[ebNE];
4655  eN_global = elementBoundaryElements[ebN*2+0];
4656  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
4657  {
4658  left_speed=0.0;
4659  right_speed=0.0;
4660  left_flux=0.0;
4661  right_flux=0.0;
4662  shock_speed=0.0;
4663  for(J=0;J<nSpace;J++)
4664  {
4665  left_speed
4666  +=
4667  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4668  k*nSpace+
4669  J]
4670  *
4671  df[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4672  k*nSpace+
4673  J];
4674  right_speed
4675  +=
4676  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4677  k*nSpace+
4678  J]
4679  *
4680  bc_df[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4681  k*nSpace+
4682  J];
4683  left_flux
4684  +=
4685  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4686  k*nSpace+
4687  J]
4688  *
4689  f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4690  k*nSpace+
4691  J];
4692  right_flux
4693  +=
4694  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4695  k*nSpace+
4696  J]
4697  *
4698  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4699  k*nSpace+
4700  J];
4701  }
4702  flux_jump = (right_flux - left_flux);
4703  u_jump = (bc_u[ebNE*nQuadraturePoints_elementBoundary+
4704  k]
4705  -
4706  u[ebNE*nQuadraturePoints_elementBoundary+
4707  k]);
4708  if (fabs(u_jump) > fabs(flux_jump*1.0e-16))
4709  shock_speed = flux_jump/u_jump;
4710  if (left_speed >= 0.0 && right_speed >= 0.0)
4711  {
4712  flux[ebNE*nQuadraturePoints_elementBoundary+
4713  k] = left_flux;
4714  dflux[ebNE*nQuadraturePoints_elementBoundary+
4715  k] = left_speed;
4716  }
4717  else if (left_speed <= 0.0 && right_speed <= 0.0)
4718  {
4719  flux[ebNE*nQuadraturePoints_elementBoundary+
4720  k] = right_flux;
4721  if (isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
4722  dflux[ebNE*nQuadraturePoints_elementBoundary+
4723  k] = 0.0;
4724  else
4725  dflux[ebNE*nQuadraturePoints_elementBoundary+
4726  k] = right_speed;
4727  }
4728  else if (left_speed >= 0.0 && right_speed <= 0.0)
4729  {
4730  if (shock_speed >= 0.0)
4731  {
4732  flux[ebNE*nQuadraturePoints_elementBoundary+
4733  k] = left_flux;
4734  dflux[ebNE*nQuadraturePoints_elementBoundary+
4735  k] = left_speed;
4736  }
4737  else
4738  {
4739  flux[ebNE*nQuadraturePoints_elementBoundary+
4740  k] = right_flux;
4741  if (isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
4742  dflux[ebNE*nQuadraturePoints_elementBoundary+
4743  k] = 0.0;
4744  else
4745  dflux[ebNE*nQuadraturePoints_elementBoundary+
4746  k] = right_speed;
4747  }
4748  }
4749  else
4750  {
4751  /*transonic rarefaction*/
4752  printf("Transonic rarefaction detected on exterior. This numerical flux treats transonic rarefactions incorrectly. left_speed= %12.5e right_speed= %12.5e \n",left_speed,right_speed);
4753  for (J=0; J < nSpace; J++)
4754  {
4755  printf("n_l[%d]=%g df_l[%d]=%g df_r[%d]=%g \n",J,
4756  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4757  k*nSpace+
4758  J],
4759  J,
4760  df[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4761  k*nSpace+
4762  J],
4763  J,
4764  bc_df[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4765  k*nSpace+
4766  J]);
4767 
4768  }
4769  flux[ebNE*nQuadraturePoints_elementBoundary+
4770  k] = 0.5*(left_flux + right_flux);
4771  if (isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
4772  dflux[ebNE*nQuadraturePoints_elementBoundary+
4773  k] = 0.5*left_speed;
4774  else
4775  dflux[ebNE*nQuadraturePoints_elementBoundary+
4776  k] = 0.5*(left_speed+right_speed);
4777  }
4778 /* printf("exterior flux %d %d %12.5e \n",ebNE,k,flux[ebNE*nQuadraturePoints_elementBoundary+k]); */
4779 /* if(dflux[ebN*nQuadraturePoints_elementBoundary+k] < 0.0) */
4780 /* { */
4781 /* /\* cek debug, setting inflow flow to zero *\/ */
4782 /* inflowFlag[ebNE*nQuadraturePoints_elementBoundary+k] = 1; */
4783 /* flux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0; */
4784 /* dflux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0; */
4785 /* } */
4786  }
4787  }
4788 }
4789 void calculateExteriorNumericalAdvectiveFlux_free(int nExteriorElementBoundaries_global,
4790  int nElementBoundaries_element,
4791  int nQuadraturePoints_elementBoundary,
4792  int nSpace,
4793  int* exteriorElementBoundaries,
4794  int* elementBoundaryElements,
4795  int* elementBoundaryLocalElementBoundaries,
4796  int *isDOFBoundary,
4797  int *inflowFlag,
4798  double* n,
4799  double* bc_u,
4800  double* bc_f,
4801  double* bc_df,
4802  double* u,
4803  double* f,
4804  double* df,
4805  double* flux,
4806  double* dflux)
4807 {
4808  int ebNE,ebN,eN_global,ebN_element,k,J;
4809  double left_speed,right_speed,left_flux,right_flux,shock_speed;
4810  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
4811  {
4812  ebN = exteriorElementBoundaries[ebNE];
4813  eN_global = elementBoundaryElements[ebN*2+0];
4814  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
4815  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
4816  {
4817  left_speed=0.0;
4818  right_speed=0.0;
4819  left_flux=0.0;
4820  right_flux=0.0;
4821  /*mwf add default shock speed is zero*/
4822  shock_speed=0.0;
4823  for(J=0;J<nSpace;J++)
4824  {
4825  left_speed
4826  +=
4827  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4828  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4829  k*nSpace+
4830  J]
4831  *
4832  df[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4833  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4834  k*nSpace+
4835  J];
4836  left_flux
4837  +=
4838  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4839  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4840  k*nSpace+
4841  J]
4842  *
4843  f[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4844  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4845  k*nSpace+
4846  J];
4847  }
4848  flux[ebN*nQuadraturePoints_elementBoundary+
4849  k] = left_flux;
4850  dflux[ebN*nQuadraturePoints_elementBoundary+
4851  k] = left_speed;
4852  }
4853  }
4854 }
4855 
4856 void calculateGlobalExteriorNumericalAdvectiveFlux_free(int nExteriorElementBoundaries_global,
4857  int nQuadraturePoints_elementBoundary,
4858  int nSpace,
4859  int* exteriorElementBoundaries,
4860  int* elementBoundaryElements,
4861  int* elementBoundaryLocalElementBoundaries,
4862  int *isDOFBoundary,
4863  int *inflowFlag,
4864  double* n,
4865  double* bc_u,
4866  double* bc_f,
4867  double* bc_df,
4868  double* u,
4869  double* f,
4870  double* df,
4871  double* flux,
4872  double* dflux)
4873 {
4874  int ebNE,ebN,eN_global,k,J;
4875  double left_speed,right_speed,left_flux,right_flux,shock_speed;
4876  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
4877  {
4878  ebN = exteriorElementBoundaries[ebNE];
4879  eN_global = elementBoundaryElements[ebN*2+0];
4880  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
4881  {
4882  left_speed=0.0;
4883  right_speed=0.0;
4884  left_flux=0.0;
4885  right_flux=0.0;
4886  shock_speed=0.0;
4887  for(J=0;J<nSpace;J++)
4888  {
4889  left_speed
4890  +=
4891  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4892  k*nSpace+
4893  J]
4894  *
4895  df[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4896  k*nSpace+
4897  J];
4898  left_flux
4899  +=
4900  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4901  k*nSpace+
4902  J]
4903  *
4904  f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
4905  k*nSpace+
4906  J];
4907  }
4908  flux[ebNE*nQuadraturePoints_elementBoundary+
4909  k] = left_flux;
4910  dflux[ebNE*nQuadraturePoints_elementBoundary+
4911  k] = left_speed;
4912  }
4913  }
4914 }
4918 void calculateExteriorNumericalAdvectiveFluxStokesP2D(int nExteriorElementBoundaries_global,
4919  int nElementBoundaries_element,
4920  int nQuadraturePoints_elementBoundary,
4921  int nSpace,
4922  int* exteriorElementBoundaries,
4923  int* elementBoundaryElements,
4924  int* elementBoundaryLocalElementBoundaries,
4925  int *isDOFBoundary_p,
4926  int *isDOFBoundary_u,
4927  int *isDOFBoundary_v,
4928  double* n,
4929  double* bc_f,
4930  double* bc_fpu,
4931  double* bc_fpv,
4932  double* f,
4933  double* fpu,
4934  double* fpv,
4935  double* df_du,
4936  double* df_dv,
4937  double* dfpu_dp,
4938  double* dfpv_dp,
4939  double* flux,
4940  double* fluxpu,
4941  double* fluxpv,
4942  double* dflux_du,
4943  double* dflux_dv,
4944  double* dfluxpu_dp,
4945  double* dfluxpv_dp)
4946 {
4947  int ebNE,ebN,eN_global,ebN_element,k;
4948  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
4949  {
4950  ebN = exteriorElementBoundaries[ebNE];
4951  eN_global = elementBoundaryElements[ebN*2+0];
4952  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
4953  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
4954  {
4955  fluxpu[ebN*nQuadraturePoints_elementBoundary+
4956  k] = 0.0;
4957  fluxpv[ebN*nQuadraturePoints_elementBoundary+
4958  k] = 0.0;
4959  flux[ebN*nQuadraturePoints_elementBoundary+
4960  k] = 0.0;
4961 
4962  //u and v momentum fluxes due to pressure
4963  if (isDOFBoundary_p[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
4964  {
4965  dfluxpu_dp[ebN*nQuadraturePoints_elementBoundary+
4966  k]
4967  =
4968  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4969  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4970  k*nSpace+
4971  0]
4972  *
4973  dfpu_dp[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4974  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4975  k*nSpace+
4976  0];
4977  fluxpu[ebN*nQuadraturePoints_elementBoundary+
4978  k]+=
4979  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4980  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4981  k*nSpace+
4982  0]
4983  *
4984  fpu[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4985  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4986  k*nSpace+
4987  0];
4988  dfluxpv_dp[ebN*nQuadraturePoints_elementBoundary+
4989  k]
4990  =
4991  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4992  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4993  k*nSpace+
4994  1]
4995  *
4996  dfpv_dp[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
4997  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
4998  k*nSpace+
4999  1];
5000  fluxpv[ebN*nQuadraturePoints_elementBoundary+
5001  k]+=
5002  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5003  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5004  k*nSpace+
5005  1]
5006  *
5007  fpv[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5008  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5009  k*nSpace+
5010  1];
5011  }
5012  else
5013  {
5014  fluxpu[ebN*nQuadraturePoints_elementBoundary+
5015  k]+=
5016  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5017  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5018  k*nSpace+
5019  0]
5020  *
5021  bc_fpu[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5022  k*nSpace+
5023  0];
5024  fluxpv[ebN*nQuadraturePoints_elementBoundary+
5025  k]+=
5026  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5027  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5028  k*nSpace+
5029  1]
5030  *
5031  bc_fpv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5032  k*nSpace+
5033  1];
5034  }
5035  //mass flux
5036  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
5037  {
5038  dflux_du[ebN*nQuadraturePoints_elementBoundary+
5039  k]
5040  =
5041  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5042  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5043  k*nSpace+
5044  0]
5045  *
5046  df_du[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5047  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5048  k*nSpace+
5049  0];
5050  flux[ebN*nQuadraturePoints_elementBoundary+
5051  k]+=
5052  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5053  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5054  k*nSpace+
5055  0]
5056  *
5057  f[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5058  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5059  k*nSpace+
5060  0];
5061  }
5062  else
5063  {
5064  flux[ebN*nQuadraturePoints_elementBoundary+
5065  k]+=
5066  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5067  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5068  k*nSpace+
5069  0]
5070  *
5071  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5072  k*nSpace+
5073  0];
5074  }
5075  if (isDOFBoundary_v[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
5076  {
5077  dflux_dv[ebN*nQuadraturePoints_elementBoundary+
5078  k]
5079  =
5080  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5081  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5082  k*nSpace+
5083  1]
5084  *
5085  df_dv[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5086  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5087  k*nSpace+
5088  1];
5089  flux[ebN*nQuadraturePoints_elementBoundary+
5090  k]+=
5091  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5092  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5093  k*nSpace+
5094  1]
5095  *
5096  f[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5097  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5098  k*nSpace+
5099  1];
5100  }
5101  else
5102  {
5103  flux[ebN*nQuadraturePoints_elementBoundary+
5104  k]+=
5105  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5106  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5107  k*nSpace+
5108  1]
5109  *
5110  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5111  k*nSpace+
5112  1];
5113  }
5114  }
5115  }
5116 }
5117 void calculateExteriorNumericalAdvectiveFluxNavierStokes2D(int nExteriorElementBoundaries_global,
5118  int nElementBoundaries_element,
5119  int nQuadraturePoints_elementBoundary,
5120  int nSpace,
5121  int* exteriorElementBoundaries,
5122  int* elementBoundaryElements,
5123  int* elementBoundaryLocalElementBoundaries,
5124  int *isDOFBoundary_p,
5125  int *isDOFBoundary_u,
5126  int *isDOFBoundary_v,
5127  double* n,
5128  double* bc_p,
5129  double* bc_f_mass,
5130  double* bc_f_umom,
5131  double* bc_f_vmom,
5132  double* p,
5133  double* f_mass,
5134  double* f_umom,
5135  double* f_vmom,
5136  double* df_mass_du,
5137  double* df_mass_dv,
5138  double* df_umom_du,
5139  double* df_umom_dv,
5140  double* df_vmom_du,
5141  double* df_vmom_dv,
5142  double* flux_mass,
5143  double* flux_umom,
5144  double* flux_vmom,
5145  double* dflux_mass_du,
5146  double* dflux_mass_dv,
5147  double* dflux_umom_dp,
5148  double* dflux_umom_du,
5149  double* dflux_umom_dv,
5150  double* dflux_vmom_dp,
5151  double* dflux_vmom_du,
5152  double* dflux_vmom_dv)
5153 {
5154  int ebNE,ebN,eN_global,ebN_element,k;
5155  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
5156  {
5157  ebN = exteriorElementBoundaries[ebNE];
5158  eN_global = elementBoundaryElements[ebN*2+0];
5159  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
5160  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
5161  {
5162  flux_umom[ebN*nQuadraturePoints_elementBoundary+
5163  k] = 0.0;
5164  flux_vmom[ebN*nQuadraturePoints_elementBoundary+
5165  k] = 0.0;
5166  flux_mass[ebN*nQuadraturePoints_elementBoundary+
5167  k] = 0.0;
5168  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
5169  {
5170  dflux_mass_du[ebN*nQuadraturePoints_elementBoundary+
5171  k]
5172  =
5173  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5174  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5175  k*nSpace+
5176  0]
5177  *
5178  df_mass_du[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5179  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5180  k*nSpace+
5181  0];
5182  flux_mass[ebN*nQuadraturePoints_elementBoundary+
5183  k]+=
5184  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5185  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5186  k*nSpace+
5187  0]
5188  *
5189  f_mass[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5190  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5191  k*nSpace+
5192  0];
5193  dflux_umom_du[ebN*nQuadraturePoints_elementBoundary+
5194  k]
5195  =
5196  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5197  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5198  k*nSpace+
5199  0]
5200  *
5201  df_umom_du[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5202  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5203  k*nSpace+
5204  0];
5205  flux_umom[ebN*nQuadraturePoints_elementBoundary+
5206  k]
5207  +=
5208  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5209  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5210  k*nSpace+
5211  0]
5212  *
5213  f_umom[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5214  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5215  k*nSpace+
5216  0];
5217  dflux_vmom_du[ebN*nQuadraturePoints_elementBoundary+
5218  k]
5219  =
5220  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5221  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5222  k*nSpace+
5223  0]
5224  *
5225  df_vmom_du[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5226  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5227  k*nSpace+
5228  0];
5229  flux_vmom[ebN*nQuadraturePoints_elementBoundary+
5230  k]
5231  +=
5232  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5233  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5234  k*nSpace+
5235  0]
5236  *
5237  f_vmom[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5238  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5239  k*nSpace+
5240  0];
5241  }
5242  else
5243  {
5244  flux_mass[ebN*nQuadraturePoints_elementBoundary+
5245  k]
5246  +=
5247  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5248  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5249  k*nSpace+
5250  0]
5251  *
5252  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5253  k*nSpace+
5254  0];
5255  flux_umom[ebN*nQuadraturePoints_elementBoundary+
5256  k]
5257  +=
5258  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5259  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5260  k*nSpace+
5261  0]
5262  *
5263  bc_f_umom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5264  k*nSpace+
5265  0];
5266  flux_vmom[ebN*nQuadraturePoints_elementBoundary+
5267  k]
5268  +=
5269  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5270  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5271  k*nSpace+
5272  0]
5273  *
5274  bc_f_vmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5275  k*nSpace+
5276  0];
5277  }
5278  if (isDOFBoundary_p[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
5279  {
5280  dflux_umom_dp[ebN*nQuadraturePoints_elementBoundary+
5281  k]
5282  =
5283  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5284  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5285  k*nSpace+
5286  0];
5287  flux_umom[ebN*nQuadraturePoints_elementBoundary+
5288  k]
5289  +=
5290  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5291  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5292  k*nSpace+
5293  0]
5294  *
5295  (p[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
5296  ebN_element*nQuadraturePoints_elementBoundary+
5297  k]
5298  -
5299  bc_p[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
5300  ebN_element*nQuadraturePoints_elementBoundary+
5301  k]);
5302  dflux_vmom_dp[ebN*nQuadraturePoints_elementBoundary+
5303  k]
5304  =
5305  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5306  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5307  k*nSpace+
5308  1];
5309  flux_vmom[ebN*nQuadraturePoints_elementBoundary+
5310  k]+=
5311  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
5312  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
5313  k*nSpace+
5314  1]
5315  *
5316  (p[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
5317  ebN_element*nQuadraturePoints_elementBoundary+
5318  k]
5319  -
5320  bc_p[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
5321  ebN_element*nQuadraturePoints_elementBoundary+
5322  k]);
5323  }
5324  }
5325  }
5326 }
5327 
5328 void calculateGlobalExteriorNumericalAdvectiveFluxNavierStokes2D(int nExteriorElementBoundaries_global,
5329  int nQuadraturePoints_elementBoundary,
5330  int nSpace,
5331  int* exteriorElementBoundaries,
5332  int* elementBoundaryElements,
5333  int* elementBoundaryLocalElementBoundaries,
5334  int *isDOFBoundary_p,
5335  int *isDOFBoundary_u,
5336  int *isDOFBoundary_v,
5337  double* n,
5338  double* bc_p,
5339  double* bc_f_mass,
5340  double* bc_f_umom,
5341  double* bc_f_vmom,
5342  double* p,
5343  double* oneByRho,
5344  double* f_mass,
5345  double* f_umom,
5346  double* f_vmom,
5347  double* df_mass_du,
5348  double* df_mass_dv,
5349  double* df_umom_dp,
5350  double* df_umom_du,
5351  double* df_umom_dv,
5352  double* df_vmom_dp,
5353  double* df_vmom_du,
5354  double* df_vmom_dv,
5355  double* flux_mass,
5356  double* flux_umom,
5357  double* flux_vmom,
5358  double* dflux_mass_dp,
5359  double* dflux_mass_du,
5360  double* dflux_mass_dv,
5361  double* dflux_umom_dp,
5362  double* dflux_umom_du,
5363  double* dflux_umom_dv,
5364  double* dflux_vmom_dp,
5365  double* dflux_vmom_du,
5366  double* dflux_vmom_dv,
5367  double* velocity)
5368 {
5369  int ebNE,k;
5370  double flowDirection;
5371  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
5372  {
5373  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
5374  {
5375  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
5376  k] = 0.0;
5377  dflux_mass_du[ebNE*nQuadraturePoints_elementBoundary+
5378  k] = 0.0;
5379  dflux_mass_dv[ebNE*nQuadraturePoints_elementBoundary+
5380  k] = 0.0;
5381 
5382  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
5383  k] = 0.0;
5384  dflux_umom_dp[ebNE*nQuadraturePoints_elementBoundary+
5385  k] = 0.0;
5386  dflux_umom_du[ebNE*nQuadraturePoints_elementBoundary+
5387  k] = 0.0;
5388  dflux_umom_dv[ebNE*nQuadraturePoints_elementBoundary+
5389  k] = 0.0;
5390 
5391  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
5392  k] = 0.0;
5393  dflux_vmom_dp[ebNE*nQuadraturePoints_elementBoundary+
5394  k] = 0.0;
5395  dflux_vmom_du[ebNE*nQuadraturePoints_elementBoundary+
5396  k] = 0.0;
5397  dflux_vmom_dv[ebNE*nQuadraturePoints_elementBoundary+
5398  k] = 0.0;
5399 
5400  flowDirection=n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5401  k*nSpace+
5402  0]
5403  *
5404  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5405  k*nSpace+
5406  0]
5407  +
5408  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5409  k*nSpace+
5410  1]
5411  *
5412  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5413  k*nSpace+
5414  1];
5415  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
5416  {
5417  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
5418  k]
5419  +=
5420  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5421  k*nSpace+
5422  0]
5423  *
5424  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5425  k*nSpace+
5426  0];
5427  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5428  k*nSpace+
5429  0]
5430  =
5431  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5432  k*nSpace+
5433  0];
5434  dflux_mass_du[ebNE*nQuadraturePoints_elementBoundary+
5435  k]
5436  +=
5437  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5438  k*nSpace+
5439  0]
5440  *
5441  df_mass_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5442  k*nSpace+
5443  0];
5444  if (flowDirection >= 0.0)
5445  {
5446  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
5447  k]
5448  +=
5449  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5450  k*nSpace+
5451  0]
5452  *
5453  f_umom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5454  k*nSpace+
5455  0];
5456  dflux_umom_du[ebNE*nQuadraturePoints_elementBoundary+
5457  k]
5458  +=
5459  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5460  k*nSpace+
5461  0]
5462  *
5463  df_umom_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5464  k*nSpace+
5465  0];
5466  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
5467  k]
5468  +=
5469  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5470  k*nSpace+
5471  0]
5472  *
5473  f_vmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5474  k*nSpace+
5475  0];
5476  dflux_vmom_du[ebNE*nQuadraturePoints_elementBoundary+
5477  k]
5478  +=
5479  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5480  k*nSpace+
5481  0]
5482  *
5483  df_vmom_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5484  k*nSpace+
5485  0];
5486  dflux_vmom_dv[ebNE*nQuadraturePoints_elementBoundary+
5487  k]
5488  +=
5489  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5490  k*nSpace+
5491  0]
5492  *
5493  df_vmom_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5494  k*nSpace+
5495  0];
5496  }
5497  }
5498  else
5499  {
5500  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
5501  k]
5502  +=
5503  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5504  k*nSpace+
5505  0]
5506  *
5507  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5508  k*nSpace+
5509  0];
5510  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5511  k*nSpace+
5512  0]
5513  =
5514  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5515  k*nSpace+
5516  0];
5517  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
5518  k]
5519  +=
5520  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5521  k*nSpace+
5522  0]
5523  *
5524  bc_f_umom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5525  k*nSpace+
5526  0];
5527  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
5528  k]
5529  +=
5530  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5531  k*nSpace+
5532  0]
5533  *
5534  bc_f_vmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5535  k*nSpace+
5536  0];
5537  if (isDOFBoundary_v[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
5538  dflux_vmom_dv[ebNE*nQuadraturePoints_elementBoundary+
5539  k]
5540  +=
5541  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5542  k*nSpace+
5543  0]
5544  *
5545  df_vmom_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5546  k*nSpace+
5547  0];
5548  }
5549  if (isDOFBoundary_v[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
5550  {
5551  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
5552  k]
5553  +=
5554  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5555  k*nSpace+
5556  1]
5557  *
5558  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5559  k*nSpace+
5560  1];
5561  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5562  k*nSpace+
5563  1]
5564  =
5565  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5566  k*nSpace+
5567  1];
5568  dflux_mass_dv[ebNE*nQuadraturePoints_elementBoundary+
5569  k]
5570  +=
5571  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5572  k*nSpace+
5573  1]
5574  *
5575  df_mass_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5576  k*nSpace+
5577  1];
5578  if (flowDirection >= 0.0)
5579  {
5580  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
5581  k]
5582  +=
5583  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5584  k*nSpace+
5585  1]
5586  *
5587  f_umom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5588  k*nSpace+
5589  1];
5590  dflux_umom_du[ebNE*nQuadraturePoints_elementBoundary+
5591  k]
5592  +=
5593  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5594  k*nSpace+
5595  1]
5596  *
5597  df_umom_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5598  k*nSpace+
5599  1];
5600  dflux_umom_dv[ebNE*nQuadraturePoints_elementBoundary+
5601  k]
5602  +=
5603  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5604  k*nSpace+
5605  1]
5606  *
5607  df_umom_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5608  k*nSpace+
5609  1];
5610  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
5611  k]
5612  +=
5613  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5614  k*nSpace+
5615  1]
5616  *
5617  f_vmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5618  k*nSpace+
5619  1];
5620  dflux_vmom_dv[ebNE*nQuadraturePoints_elementBoundary+
5621  k]
5622  += n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5623  k*nSpace+
5624  1]
5625  *
5626  df_vmom_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5627  k*nSpace+
5628  1];
5629  }
5630  }
5631  else
5632  {
5633  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
5634  k]
5635  +=
5636  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5637  k*nSpace+
5638  1]
5639  *
5640  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5641  k*nSpace+
5642  1];
5643  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5644  k*nSpace+
5645  1]
5646  =
5647  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5648  k*nSpace+
5649  1];
5650 
5651  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
5652  k]
5653  +=
5654  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5655  k*nSpace+
5656  1]
5657  *
5658  bc_f_umom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5659  k*nSpace+
5660  1];
5661  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
5662  dflux_umom_du[ebNE*nQuadraturePoints_elementBoundary+
5663  k]
5664  +=
5665  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5666  k*nSpace+
5667  1]
5668  *
5669  df_umom_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5670  k*nSpace+
5671  1];
5672  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
5673  k]
5674  +=
5675  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5676  k*nSpace+
5677  1]
5678  *
5679  bc_f_vmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5680  k*nSpace+
5681  1];
5682  }
5683  if (isDOFBoundary_p[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
5684  {
5685  /* flux_mass[ebNE*nQuadraturePoints_elementBoundary+ */
5686  /* k] */
5687  /* += */
5688  /* oneByRho[ebNE*nQuadraturePoints_elementBoundary+ */
5689  /* k]*(bc_p[ebNE*nQuadraturePoints_elementBoundary+ */
5690  /* k] */
5691  /* - */
5692  /* p[ebNE*nQuadraturePoints_elementBoundary+ */
5693  /* k]); */
5694  /* dflux_mass_dp[ebNE*nQuadraturePoints_elementBoundary+ */
5695  /* k] */
5696  /* = -oneByRho[ebNE*nQuadraturePoints_elementBoundary+ */
5697  /* k]; */
5698  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
5699  k]
5700  +=
5701  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5702  k*nSpace+
5703  0]
5704  *
5705  (bc_p[ebNE*nQuadraturePoints_elementBoundary+
5706  k]
5707  -
5708  p[ebNE*nQuadraturePoints_elementBoundary+
5709  k]);
5710  dflux_umom_dp[ebNE*nQuadraturePoints_elementBoundary+
5711  k]
5712  = -n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5713  k*nSpace+
5714  0];
5715  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
5716  k]
5717  += n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5718  k*nSpace+
5719  1]
5720  *
5721  (bc_p[ebNE*nQuadraturePoints_elementBoundary+
5722  k]
5723  -
5724  p[ebNE*nQuadraturePoints_elementBoundary+
5725  k]);
5726  dflux_vmom_dp[ebNE*nQuadraturePoints_elementBoundary+
5727  k]
5728  = -n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5729  k*nSpace+
5730  1];
5731  }
5732  }
5733  }
5734 }
5735 void calculateGlobalExteriorNumericalAdvectiveFluxNavierStokes3D(int nExteriorElementBoundaries_global,
5736  int nQuadraturePoints_elementBoundary,
5737  int nSpace,
5738  int* exteriorElementBoundaries,
5739  int* elementBoundaryElements,
5740  int* elementBoundaryLocalElementBoundaries,
5741  int *isDOFBoundary_p,
5742  int *isDOFBoundary_u,
5743  int *isDOFBoundary_v,
5744  int *isDOFBoundary_w,
5745  double* n,
5746  double* bc_p,
5747  double* bc_f_mass,
5748  double* bc_f_umom,
5749  double* bc_f_vmom,
5750  double* bc_f_wmom,
5751  double* p,
5752  double* f_mass,
5753  double* f_umom,
5754  double* f_vmom,
5755  double* f_wmom,
5756  double* df_mass_du,
5757  double* df_mass_dv,
5758  double* df_mass_dw,
5759  double* df_umom_dp,
5760  double* df_umom_du,
5761  double* df_umom_dv,
5762  double* df_umom_dw,
5763  double* df_vmom_dp,
5764  double* df_vmom_du,
5765  double* df_vmom_dv,
5766  double* df_vmom_dw,
5767  double* df_wmom_dp,
5768  double* df_wmom_du,
5769  double* df_wmom_dv,
5770  double* df_wmom_dw,
5771  double* flux_mass,
5772  double* flux_umom,
5773  double* flux_vmom,
5774  double* flux_wmom,
5775  double* dflux_mass_du,
5776  double* dflux_mass_dv,
5777  double* dflux_mass_dw,
5778  double* dflux_umom_dp,
5779  double* dflux_umom_du,
5780  double* dflux_umom_dv,
5781  double* dflux_umom_dw,
5782  double* dflux_vmom_dp,
5783  double* dflux_vmom_du,
5784  double* dflux_vmom_dv,
5785  double* dflux_vmom_dw,
5786  double* dflux_wmom_dp,
5787  double* dflux_wmom_du,
5788  double* dflux_wmom_dv,
5789  double* dflux_wmom_dw,
5790  double* velocity)
5791 {
5792  int ebNE,k;
5793  double flowDirection;
5794  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
5795  {
5796  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
5797  {
5798  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
5799  k] = 0.0;
5800  dflux_mass_du[ebNE*nQuadraturePoints_elementBoundary+
5801  k] = 0.0;
5802  dflux_mass_dv[ebNE*nQuadraturePoints_elementBoundary+
5803  k] = 0.0;
5804  dflux_mass_dw[ebNE*nQuadraturePoints_elementBoundary+
5805  k] = 0.0;
5806 
5807  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
5808  k] = 0.0;
5809  dflux_umom_dp[ebNE*nQuadraturePoints_elementBoundary+
5810  k] = 0.0;
5811  dflux_umom_du[ebNE*nQuadraturePoints_elementBoundary+
5812  k] = 0.0;
5813  dflux_umom_dv[ebNE*nQuadraturePoints_elementBoundary+
5814  k] = 0.0;
5815  dflux_umom_dw[ebNE*nQuadraturePoints_elementBoundary+
5816  k] = 0.0;
5817 
5818  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
5819  k] = 0.0;
5820  dflux_vmom_dp[ebNE*nQuadraturePoints_elementBoundary+
5821  k] = 0.0;
5822  dflux_vmom_du[ebNE*nQuadraturePoints_elementBoundary+
5823  k] = 0.0;
5824  dflux_vmom_dv[ebNE*nQuadraturePoints_elementBoundary+
5825  k] = 0.0;
5826  dflux_vmom_dw[ebNE*nQuadraturePoints_elementBoundary+
5827  k] = 0.0;
5828 
5829  flux_wmom[ebNE*nQuadraturePoints_elementBoundary+
5830  k] = 0.0;
5831  dflux_wmom_dp[ebNE*nQuadraturePoints_elementBoundary+
5832  k] = 0.0;
5833  dflux_wmom_du[ebNE*nQuadraturePoints_elementBoundary+
5834  k] = 0.0;
5835  dflux_wmom_dv[ebNE*nQuadraturePoints_elementBoundary+
5836  k] = 0.0;
5837  dflux_wmom_dw[ebNE*nQuadraturePoints_elementBoundary+
5838  k] = 0.0;
5839 
5840  flowDirection=n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5841  k*nSpace+
5842  0]
5843  *
5844  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5845  k*nSpace+
5846  0]
5847  +
5848  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5849  k*nSpace+
5850  1]
5851  *
5852  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5853  k*nSpace+
5854  1]+
5855  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5856  k*nSpace+
5857  2]
5858  *
5859  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5860  k*nSpace+
5861  2];
5862  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
5863  {
5864  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
5865  k]
5866  +=
5867  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5868  k*nSpace+
5869  0]
5870  *
5871  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5872  k*nSpace+
5873  0];
5874  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5875  k*nSpace+
5876  0]
5877  =
5878  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5879  k*nSpace+
5880  0];
5881  dflux_mass_du[ebNE*nQuadraturePoints_elementBoundary+
5882  k]
5883  +=
5884  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5885  k*nSpace+
5886  0]
5887  *
5888  df_mass_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5889  k*nSpace+
5890  0];
5891  if (flowDirection >= 0.0)
5892  {
5893  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
5894  k]
5895  +=
5896  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5897  k*nSpace+
5898  0]
5899  *
5900  f_umom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5901  k*nSpace+
5902  0];
5903  dflux_umom_du[ebNE*nQuadraturePoints_elementBoundary+
5904  k]
5905  +=
5906  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5907  k*nSpace+
5908  0]
5909  *
5910  df_umom_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5911  k*nSpace+
5912  0];
5913  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
5914  k]
5915  +=
5916  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5917  k*nSpace+
5918  0]
5919  *
5920  f_vmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5921  k*nSpace+
5922  0];
5923  dflux_vmom_du[ebNE*nQuadraturePoints_elementBoundary+
5924  k]
5925  +=
5926  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5927  k*nSpace+
5928  0]
5929  *
5930  df_vmom_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5931  k*nSpace+
5932  0];
5933  dflux_vmom_dv[ebNE*nQuadraturePoints_elementBoundary+
5934  k]
5935  +=
5936  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5937  k*nSpace+
5938  0]
5939  *
5940  df_vmom_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5941  k*nSpace+
5942  0];
5943  flux_wmom[ebNE*nQuadraturePoints_elementBoundary+
5944  k]
5945  +=
5946  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5947  k*nSpace+
5948  0]
5949  *
5950  f_wmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5951  k*nSpace+
5952  0];
5953  dflux_wmom_du[ebNE*nQuadraturePoints_elementBoundary+
5954  k]
5955  +=
5956  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5957  k*nSpace+
5958  0]
5959  *
5960  df_wmom_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5961  k*nSpace+
5962  0];
5963  dflux_wmom_dw[ebNE*nQuadraturePoints_elementBoundary+
5964  k]
5965  +=
5966  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5967  k*nSpace+
5968  0]
5969  *
5970  df_wmom_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5971  k*nSpace+
5972  0];
5973  }
5974  }
5975  else
5976  {
5977  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
5978  k]
5979  +=
5980  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5981  k*nSpace+
5982  0]
5983  *
5984  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5985  k*nSpace+
5986  0];
5987  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5988  k*nSpace+
5989  0]
5990  =
5991  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5992  k*nSpace+
5993  0];
5994  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
5995  k]
5996  +=
5997  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
5998  k*nSpace+
5999  0]
6000  *
6001  bc_f_umom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6002  k*nSpace+
6003  0];
6004  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
6005  k]
6006  +=
6007  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6008  k*nSpace+
6009  0]
6010  *
6011  bc_f_vmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6012  k*nSpace+
6013  0];
6014  if (isDOFBoundary_v[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6015  dflux_vmom_dv[ebNE*nQuadraturePoints_elementBoundary+
6016  k]
6017  +=
6018  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6019  k*nSpace+
6020  0]
6021  *
6022  df_vmom_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6023  k*nSpace+
6024  0];
6025  flux_wmom[ebNE*nQuadraturePoints_elementBoundary+
6026  k]
6027  +=
6028  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6029  k*nSpace+
6030  0]
6031  *
6032  bc_f_wmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6033  k*nSpace+
6034  0];
6035  if (isDOFBoundary_w[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6036  dflux_wmom_dw[ebNE*nQuadraturePoints_elementBoundary+
6037  k]
6038  +=
6039  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6040  k*nSpace+
6041  0]
6042  *
6043  df_wmom_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6044  k*nSpace+
6045  0];
6046  }
6047  if (isDOFBoundary_v[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6048  {
6049  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
6050  k]
6051  +=
6052  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6053  k*nSpace+
6054  1]
6055  *
6056  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6057  k*nSpace+
6058  1];
6059  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6060  k*nSpace+
6061  1]
6062  =
6063  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6064  k*nSpace+
6065  1];
6066  dflux_mass_dv[ebNE*nQuadraturePoints_elementBoundary+
6067  k]
6068  +=
6069  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6070  k*nSpace+
6071  1]
6072  *
6073  df_mass_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6074  k*nSpace+
6075  1];
6076  if (flowDirection >= 0.0)
6077  {
6078  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
6079  k]
6080  +=
6081  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6082  k*nSpace+
6083  1]
6084  *
6085  f_umom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6086  k*nSpace+
6087  1];
6088  dflux_umom_du[ebNE*nQuadraturePoints_elementBoundary+
6089  k]
6090  +=
6091  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6092  k*nSpace+
6093  1]
6094  *
6095  df_umom_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6096  k*nSpace+
6097  1];
6098  dflux_umom_dv[ebNE*nQuadraturePoints_elementBoundary+
6099  k]
6100  +=
6101  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6102  k*nSpace+
6103  1]
6104  *
6105  df_umom_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6106  k*nSpace+
6107  1];
6108  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
6109  k]
6110  +=
6111  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6112  k*nSpace+
6113  1]
6114  *
6115  f_vmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6116  k*nSpace+
6117  1];
6118  dflux_vmom_dv[ebNE*nQuadraturePoints_elementBoundary+
6119  k]
6120  += n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6121  k*nSpace+
6122  1]
6123  *
6124  df_vmom_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6125  k*nSpace+
6126  1];
6127  flux_wmom[ebNE*nQuadraturePoints_elementBoundary+
6128  k]
6129  +=
6130  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6131  k*nSpace+
6132  1]
6133  *
6134  f_wmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6135  k*nSpace+
6136  1];
6137  dflux_wmom_dw[ebNE*nQuadraturePoints_elementBoundary+
6138  k]
6139  +=
6140  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6141  k*nSpace+
6142  1]
6143  *
6144  df_wmom_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6145  k*nSpace+
6146  1];
6147  dflux_wmom_dv[ebNE*nQuadraturePoints_elementBoundary+
6148  k]
6149  +=
6150  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6151  k*nSpace+
6152  1]
6153  *
6154  df_wmom_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6155  k*nSpace+
6156  1];
6157  }
6158  }
6159  else
6160  {
6161  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
6162  k]
6163  +=
6164  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6165  k*nSpace+
6166  1]
6167  *
6168  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6169  k*nSpace+
6170  1];
6171  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6172  k*nSpace+
6173  1]
6174  =
6175  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6176  k*nSpace+
6177  1];
6178  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
6179  k]
6180  +=
6181  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6182  k*nSpace+
6183  1]
6184  *
6185  bc_f_umom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6186  k*nSpace+
6187  1];
6188  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6189  dflux_umom_du[ebNE*nQuadraturePoints_elementBoundary+
6190  k]
6191  +=
6192  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6193  k*nSpace+
6194  1]
6195  *
6196  df_umom_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6197  k*nSpace+
6198  1];
6199  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
6200  k]
6201  +=
6202  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6203  k*nSpace+
6204  1]
6205  *
6206  bc_f_vmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6207  k*nSpace+
6208  1];
6209  flux_wmom[ebNE*nQuadraturePoints_elementBoundary+
6210  k]
6211  +=
6212  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6213  k*nSpace+
6214  1]
6215  *
6216  bc_f_wmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6217  k*nSpace+
6218  1];
6219  if (isDOFBoundary_w[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6220  dflux_wmom_dw[ebNE*nQuadraturePoints_elementBoundary+
6221  k]
6222  +=
6223  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6224  k*nSpace+
6225  1]
6226  *
6227  df_wmom_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6228  k*nSpace+
6229  1];
6230  }
6231  if (isDOFBoundary_w[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6232  {
6233  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
6234  k]
6235  +=
6236  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6237  k*nSpace+
6238  2]
6239  *
6240  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6241  k*nSpace+
6242  2];
6243  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6244  k*nSpace+
6245  2]
6246  =
6247  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6248  k*nSpace+
6249  2];
6250  dflux_mass_dw[ebNE*nQuadraturePoints_elementBoundary+
6251  k]
6252  +=
6253  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6254  k*nSpace+
6255  2]
6256  *
6257  df_mass_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6258  k*nSpace+
6259  2];
6260  if (flowDirection >= 0.0)
6261  {
6262  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
6263  k]
6264  +=
6265  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6266  k*nSpace+
6267  2]
6268  *
6269  f_umom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6270  k*nSpace+
6271  2];
6272  dflux_umom_du[ebNE*nQuadraturePoints_elementBoundary+
6273  k]
6274  +=
6275  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6276  k*nSpace+
6277  2]
6278  *
6279  df_umom_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6280  k*nSpace+
6281  2];
6282  dflux_umom_dw[ebNE*nQuadraturePoints_elementBoundary+
6283  k]
6284  +=
6285  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6286  k*nSpace+
6287  2]
6288  *
6289  df_umom_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6290  k*nSpace+
6291  2];
6292  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
6293  k]
6294  +=
6295  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6296  k*nSpace+
6297  2]
6298  *
6299  f_vmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6300  k*nSpace+
6301  2];
6302  dflux_vmom_dv[ebNE*nQuadraturePoints_elementBoundary+
6303  k]
6304  += n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6305  k*nSpace+
6306  2]
6307  *
6308  df_vmom_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6309  k*nSpace+
6310  2];
6311  dflux_vmom_dw[ebNE*nQuadraturePoints_elementBoundary+
6312  k]
6313  += n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6314  k*nSpace+
6315  2]
6316  *
6317  df_vmom_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6318  k*nSpace+
6319  2];
6320  flux_wmom[ebNE*nQuadraturePoints_elementBoundary+
6321  k]
6322  +=
6323  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6324  k*nSpace+
6325  2]
6326  *
6327  f_wmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6328  k*nSpace+
6329  2];
6330  dflux_wmom_dw[ebNE*nQuadraturePoints_elementBoundary+
6331  k]
6332  +=
6333  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6334  k*nSpace+
6335  2]
6336  *
6337  df_wmom_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6338  k*nSpace+
6339  2];
6340  }
6341  }
6342  else
6343  {
6344  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
6345  k]
6346  +=
6347  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6348  k*nSpace+
6349  2]
6350  *
6351  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6352  k*nSpace+
6353  2];
6354  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6355  k*nSpace+
6356  2]
6357  =
6358  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6359  k*nSpace+
6360  2];
6361  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
6362  k]
6363  +=
6364  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6365  k*nSpace+
6366  2]
6367  *
6368  bc_f_umom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6369  k*nSpace+
6370  2];
6371  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6372  dflux_umom_du[ebNE*nQuadraturePoints_elementBoundary+
6373  k]
6374  +=
6375  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6376  k*nSpace+
6377  2]
6378  *
6379  df_umom_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6380  k*nSpace+
6381  2];
6382  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
6383  k]
6384  +=
6385  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6386  k*nSpace+
6387  2]
6388  *
6389  bc_f_vmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6390  k*nSpace+
6391  2];
6392  if (isDOFBoundary_v[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6393  dflux_vmom_dv[ebNE*nQuadraturePoints_elementBoundary+
6394  k]
6395  +=
6396  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6397  k*nSpace+
6398  2]
6399  *
6400  df_vmom_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6401  k*nSpace+
6402  2];
6403  flux_wmom[ebNE*nQuadraturePoints_elementBoundary+
6404  k]
6405  +=
6406  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6407  k*nSpace+
6408  2]
6409  *
6410  bc_f_wmom[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6411  k*nSpace+
6412  2];
6413  }
6414  if (isDOFBoundary_p[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
6415  {
6416  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
6417  k]
6418  +=
6419  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6420  k*nSpace+
6421  0]
6422  *
6423  (bc_p[ebNE*nQuadraturePoints_elementBoundary+
6424  k]
6425  -
6426  p[ebNE*nQuadraturePoints_elementBoundary+
6427  k]);
6428  dflux_umom_dp[ebNE*nQuadraturePoints_elementBoundary+
6429  k]
6430  = -n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6431  k*nSpace+
6432  0];
6433  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
6434  k]
6435  += n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6436  k*nSpace+
6437  1]
6438  *
6439  (bc_p[ebNE*nQuadraturePoints_elementBoundary+
6440  k]
6441  -
6442  p[ebNE*nQuadraturePoints_elementBoundary+
6443  k]);
6444  dflux_vmom_dp[ebNE*nQuadraturePoints_elementBoundary+
6445  k]
6446  = -n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6447  k*nSpace+
6448  1];
6449  flux_wmom[ebNE*nQuadraturePoints_elementBoundary+
6450  k]
6451  += n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6452  k*nSpace+
6453  2]
6454  *
6455  (bc_p[ebNE*nQuadraturePoints_elementBoundary+
6456  k]
6457  -
6458  p[ebNE*nQuadraturePoints_elementBoundary+
6459  k]);
6460  dflux_wmom_dp[ebNE*nQuadraturePoints_elementBoundary+
6461  k]
6462  = -n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6463  k*nSpace+
6464  2];
6465  }
6466  }
6467  }
6468 }
6472 void calculateGlobalExteriorNumericalAdvectiveFluxStokesP2D(int nExteriorElementBoundaries_global,
6473  int nQuadraturePoints_elementBoundary,
6474  int nSpace,
6475  int* exteriorElementBoundaries,
6476  int* elementBoundaryElements,
6477  int* elementBoundaryLocalElementBoundaries,
6478  int *isDOFBoundary_p,
6479  int *isDOFBoundary_u,
6480  int *isDOFBoundary_v,
6481  double* n,
6482  double* bc_f,
6483  double* bc_fpu,
6484  double* bc_fpv,
6485  double* f,
6486  double* fpu,
6487  double* fpv,
6488  double* df_du,
6489  double* df_dv,
6490  double* dfpu_dp,
6491  double* dfpv_dp,
6492  double* flux,
6493  double* fluxpu,
6494  double* fluxpv,
6495  double* dflux_du,
6496  double* dflux_dv,
6497  double* dfluxpu_dp,
6498  double* dfluxpv_dp)
6499 {
6500  int ebNE,k;
6501  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
6502  {
6503  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
6504  {
6505  fluxpu[ebNE*nQuadraturePoints_elementBoundary+
6506  k] = 0.0;
6507  fluxpv[ebNE*nQuadraturePoints_elementBoundary+
6508  k] = 0.0;
6509  flux[ebNE*nQuadraturePoints_elementBoundary+
6510  k] = 0.0;
6511 
6512  //u and v momentum fluxes due to pressure
6513  if (isDOFBoundary_p[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6514  {
6515  dfluxpu_dp[ebNE*nQuadraturePoints_elementBoundary+
6516  k]
6517  =
6518  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6519  k*nSpace+
6520  0]
6521  *
6522  dfpu_dp[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6523  k*nSpace+
6524  0];
6525  fluxpu[ebNE*nQuadraturePoints_elementBoundary+
6526  k]+=
6527  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6528  k*nSpace+
6529  0]
6530  *
6531  fpu[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6532  k*nSpace+
6533  0];
6534  dfluxpv_dp[ebNE*nQuadraturePoints_elementBoundary+
6535  k]
6536  =
6537  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6538  k*nSpace+
6539  1]
6540  *
6541  dfpv_dp[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6542  k*nSpace+
6543  1];
6544  fluxpv[ebNE*nQuadraturePoints_elementBoundary+
6545  k]+=
6546  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6547  k*nSpace+
6548  1]
6549  *
6550  fpv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6551  k*nSpace+
6552  1];
6553  }
6554  else
6555  {
6556  fluxpu[ebNE*nQuadraturePoints_elementBoundary+
6557  k]+=
6558  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6559  k*nSpace+
6560  0]
6561  *
6562  bc_fpu[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6563  k*nSpace+
6564  0];
6565  fluxpv[ebNE*nQuadraturePoints_elementBoundary+
6566  k]+=
6567  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6568  k*nSpace+
6569  1]
6570  *
6571  bc_fpv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6572  k*nSpace+
6573  1];
6574  }
6575  //mass flux
6576  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6577  {
6578  dflux_du[ebNE*nQuadraturePoints_elementBoundary+
6579  k]
6580  =
6581  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6582  k*nSpace+
6583  0]
6584  *
6585  df_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6586  k*nSpace+
6587  0];
6588  flux[ebNE*nQuadraturePoints_elementBoundary+
6589  k]+=
6590  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6591  k*nSpace+
6592  0]
6593  *
6594  f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6595  k*nSpace+
6596  0];
6597  }
6598  else
6599  {
6600  flux[ebNE*nQuadraturePoints_elementBoundary+
6601  k]+=
6602  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6603  k*nSpace+
6604  0]
6605  *
6606  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6607  k*nSpace+
6608  0];
6609  }
6610  if (isDOFBoundary_v[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6611  {
6612  dflux_dv[ebNE*nQuadraturePoints_elementBoundary+
6613  k]
6614  =
6615  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6616  k*nSpace+
6617  1]
6618  *
6619  df_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6620  k*nSpace+
6621  1];
6622  flux[ebNE*nQuadraturePoints_elementBoundary+
6623  k]+=
6624  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6625  k*nSpace+
6626  1]
6627  *
6628  f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6629  k*nSpace+
6630  1];
6631  }
6632  else
6633  {
6634  flux[ebNE*nQuadraturePoints_elementBoundary+
6635  k]+=
6636  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6637  k*nSpace+
6638  1]
6639  *
6640  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6641  k*nSpace+
6642  1];
6643  }
6644  }
6645  }
6646 }
6650 void calculateExteriorNumericalAdvectiveFluxStokesP3D(int nExteriorElementBoundaries_global,
6651  int nElementBoundaries_element,
6652  int nQuadraturePoints_elementBoundary,
6653  int nSpace,
6654  int* exteriorElementBoundaries,
6655  int* elementBoundaryElements,
6656  int* elementBoundaryLocalElementBoundaries,
6657  int *isDOFBoundary_p,
6658  int *isDOFBoundary_u,
6659  int *isDOFBoundary_v,
6660  int *isDOFBoundary_w,
6661  double* n,
6662  double* bc_f,
6663  double* bc_fpu,
6664  double* bc_fpv,
6665  double* bc_fpw,
6666  double* f,
6667  double* fpu,
6668  double* fpv,
6669  double* fpw,
6670  double* df_du,
6671  double* df_dv,
6672  double* df_dw,
6673  double* dfpu_dp,
6674  double* dfpv_dp,
6675  double* dfpw_dp,
6676  double* flux,
6677  double* fluxpu,
6678  double* fluxpv,
6679  double* fluxpw,
6680  double* dflux_du,
6681  double* dflux_dv,
6682  double* dflux_dw,
6683  double* dfluxpu_dp,
6684  double* dfluxpv_dp,
6685  double* dfluxpw_dp)
6686 {
6687  int ebNE,ebN,eN_global,ebN_element,k;
6688  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
6689  {
6690  ebN = exteriorElementBoundaries[ebNE];
6691  eN_global = elementBoundaryElements[ebN*2+0];
6692  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
6693  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
6694  {
6695  fluxpu[ebN*nQuadraturePoints_elementBoundary+
6696  k] = 0.0;
6697  fluxpv[ebN*nQuadraturePoints_elementBoundary+
6698  k] = 0.0;
6699  fluxpw[ebN*nQuadraturePoints_elementBoundary+
6700  k] = 0.0;
6701  flux[ebN*nQuadraturePoints_elementBoundary+
6702  k] = 0.0;
6703 
6704  //u, v and w momentum fluxes due to pressure
6705  if (isDOFBoundary_p[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6706  {
6707  dfluxpu_dp[ebN*nQuadraturePoints_elementBoundary+
6708  k]
6709  =
6710  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6711  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6712  k*nSpace+
6713  0]
6714  *
6715  dfpu_dp[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6716  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6717  k*nSpace+
6718  0];
6719  fluxpu[ebN*nQuadraturePoints_elementBoundary+
6720  k]+=
6721  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6722  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6723  k*nSpace+
6724  0]
6725  *
6726  fpu[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6727  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6728  k*nSpace+
6729  0];
6730  dfluxpv_dp[ebN*nQuadraturePoints_elementBoundary+
6731  k]
6732  =
6733  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6734  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6735  k*nSpace+
6736  1]
6737  *
6738  dfpv_dp[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6739  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6740  k*nSpace+
6741  1];
6742  fluxpv[ebN*nQuadraturePoints_elementBoundary+
6743  k]+=
6744  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6745  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6746  k*nSpace+
6747  1]
6748  *
6749  fpv[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6750  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6751  k*nSpace+
6752  1];
6753  dfluxpw_dp[ebN*nQuadraturePoints_elementBoundary+
6754  k]
6755  =
6756  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6757  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6758  k*nSpace+
6759  2]
6760  *
6761  dfpw_dp[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6762  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6763  k*nSpace+
6764  2];
6765  fluxpw[ebN*nQuadraturePoints_elementBoundary+
6766  k]+=
6767  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6768  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6769  k*nSpace+
6770  2]
6771  *
6772  fpw[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6773  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6774  k*nSpace+
6775  2];
6776  }
6777  else
6778  {
6779  fluxpu[ebN*nQuadraturePoints_elementBoundary+
6780  k]+=
6781  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6782  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6783  k*nSpace+
6784  0]
6785  *
6786  bc_fpu[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6787  k*nSpace+
6788  0];
6789  fluxpv[ebN*nQuadraturePoints_elementBoundary+
6790  k]+=
6791  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6792  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6793  k*nSpace+
6794  1]
6795  *
6796  bc_fpv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6797  k*nSpace+
6798  1];
6799  fluxpw[ebN*nQuadraturePoints_elementBoundary+
6800  k]+=
6801  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6802  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6803  k*nSpace+
6804  2]
6805  *
6806  bc_fpw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6807  k*nSpace+
6808  2];
6809  }
6810  //mass flux
6811  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6812  {
6813  dflux_du[ebN*nQuadraturePoints_elementBoundary+
6814  k]
6815  =
6816  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6817  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6818  k*nSpace+
6819  0]
6820  *
6821  df_du[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6822  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6823  k*nSpace+
6824  0];
6825  flux[ebN*nQuadraturePoints_elementBoundary+
6826  k]+=
6827  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6828  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6829  k*nSpace+
6830  0]
6831  *
6832  f[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6833  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6834  k*nSpace+
6835  0];
6836  }
6837  else
6838  {
6839  flux[ebN*nQuadraturePoints_elementBoundary+
6840  k]+=
6841  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6842  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6843  k*nSpace+
6844  0]
6845  *
6846  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6847  k*nSpace+
6848  0];
6849  }
6850  if (isDOFBoundary_v[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6851  {
6852  dflux_dv[ebN*nQuadraturePoints_elementBoundary+
6853  k]
6854  =
6855  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6856  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6857  k*nSpace+
6858  1]
6859  *
6860  df_dv[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6861  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6862  k*nSpace+
6863  1];
6864  flux[ebN*nQuadraturePoints_elementBoundary+
6865  k]+=
6866  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6867  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6868  k*nSpace+
6869  1]
6870  *
6871  f[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6872  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6873  k*nSpace+
6874  1];
6875  }
6876  else
6877  {
6878  flux[ebN*nQuadraturePoints_elementBoundary+
6879  k]+=
6880  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6881  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6882  k*nSpace+
6883  1]
6884  *
6885  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6886  k*nSpace+
6887  1];
6888  }
6889  if (isDOFBoundary_w[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6890  {
6891  dflux_dw[ebN*nQuadraturePoints_elementBoundary+
6892  k]
6893  =
6894  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6895  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6896  k*nSpace+
6897  2]
6898  *
6899  df_dw[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6900  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6901  k*nSpace+
6902  2];
6903  flux[ebN*nQuadraturePoints_elementBoundary+
6904  k]+=
6905  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6906  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6907  k*nSpace+
6908  2]
6909  *
6910  f[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6911  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6912  k*nSpace+
6913  2];
6914  }
6915  else
6916  {
6917  flux[ebN*nQuadraturePoints_elementBoundary+
6918  k]+=
6919  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
6920  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
6921  k*nSpace+
6922  2]
6923  *
6924  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6925  k*nSpace+
6926  2];
6927  }
6928  }
6929  }
6930 }
6934 void calculateGlobalExteriorNumericalAdvectiveFluxStokesP3D(int nExteriorElementBoundaries_global,
6935  int nQuadraturePoints_elementBoundary,
6936  int nSpace,
6937  int* exteriorElementBoundaries,
6938  int* elementBoundaryElements,
6939  int* elementBoundaryLocalElementBoundaries,
6940  int *isDOFBoundary_p,
6941  int *isDOFBoundary_u,
6942  int *isDOFBoundary_v,
6943  int *isDOFBoundary_w,
6944  double* n,
6945  double* bc_f,
6946  double* bc_fpu,
6947  double* bc_fpv,
6948  double* bc_fpw,
6949  double* f,
6950  double* fpu,
6951  double* fpv,
6952  double* fpw,
6953  double* df_du,
6954  double* df_dv,
6955  double* df_dw,
6956  double* dfpu_dp,
6957  double* dfpv_dp,
6958  double* dfpw_dp,
6959  double* flux,
6960  double* fluxpu,
6961  double* fluxpv,
6962  double* fluxpw,
6963  double* dflux_du,
6964  double* dflux_dv,
6965  double* dflux_dw,
6966  double* dfluxpu_dp,
6967  double* dfluxpv_dp,
6968  double* dfluxpw_dp)
6969 {
6970  int ebNE,k;
6971  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
6972  {
6973  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
6974  {
6975  fluxpu[ebNE*nQuadraturePoints_elementBoundary+
6976  k] = 0.0;
6977  fluxpv[ebNE*nQuadraturePoints_elementBoundary+
6978  k] = 0.0;
6979  fluxpw[ebNE*nQuadraturePoints_elementBoundary+
6980  k] = 0.0;
6981  flux[ebNE*nQuadraturePoints_elementBoundary+
6982  k] = 0.0;
6983 
6984  //u, v and w momentum fluxes due to pressure
6985  if (isDOFBoundary_p[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
6986  {
6987  dfluxpu_dp[ebNE*nQuadraturePoints_elementBoundary+
6988  k]
6989  =
6990  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6991  k*nSpace+
6992  0]
6993  *
6994  dfpu_dp[ebNE*nQuadraturePoints_elementBoundary*nSpace+
6995  k*nSpace+
6996  0];
6997  fluxpu[ebNE*nQuadraturePoints_elementBoundary+
6998  k]+=
6999  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7000  k*nSpace+
7001  0]
7002  *
7003  fpu[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7004  k*nSpace+
7005  0];
7006  dfluxpv_dp[ebNE*nQuadraturePoints_elementBoundary+
7007  k]
7008  =
7009  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7010  k*nSpace+
7011  1]
7012  *
7013  dfpv_dp[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7014  k*nSpace+
7015  1];
7016  fluxpv[ebNE*nQuadraturePoints_elementBoundary+
7017  k]+=
7018  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7019  k*nSpace+
7020  1]
7021  *
7022  fpv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7023  k*nSpace+
7024  1];
7025  dfluxpw_dp[ebNE*nQuadraturePoints_elementBoundary+
7026  k]
7027  =
7028  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7029  k*nSpace+
7030  2]
7031  *
7032  dfpw_dp[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7033  k*nSpace+
7034  2];
7035  fluxpw[ebNE*nQuadraturePoints_elementBoundary+
7036  k]+=
7037  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7038  k*nSpace+
7039  2]
7040  *
7041  fpw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7042  k*nSpace+
7043  2];
7044  }
7045  else
7046  {
7047  fluxpu[ebNE*nQuadraturePoints_elementBoundary+
7048  k]+=
7049  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7050  k*nSpace+
7051  0]
7052  *
7053  bc_fpu[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7054  k*nSpace+
7055  0];
7056  fluxpv[ebNE*nQuadraturePoints_elementBoundary+
7057  k]+=
7058  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7059  k*nSpace+
7060  1]
7061  *
7062  bc_fpv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7063  k*nSpace+
7064  1];
7065  fluxpw[ebNE*nQuadraturePoints_elementBoundary+
7066  k]+=
7067  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7068  k*nSpace+
7069  2]
7070  *
7071  bc_fpw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7072  k*nSpace+
7073  2];
7074  }
7075  //mass flux
7076  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
7077  {
7078  dflux_du[ebNE*nQuadraturePoints_elementBoundary+
7079  k]
7080  =
7081  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7082  k*nSpace+
7083  0]
7084  *
7085  df_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7086  k*nSpace+
7087  0];
7088  flux[ebNE*nQuadraturePoints_elementBoundary+
7089  k]+=
7090  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7091  k*nSpace+
7092  0]
7093  *
7094  f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7095  k*nSpace+
7096  0];
7097  }
7098  else
7099  {
7100  flux[ebNE*nQuadraturePoints_elementBoundary+
7101  k]+=
7102  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7103  k*nSpace+
7104  0]
7105  *
7106  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7107  k*nSpace+
7108  0];
7109  }
7110  if (isDOFBoundary_v[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
7111  {
7112  dflux_dv[ebNE*nQuadraturePoints_elementBoundary+
7113  k]
7114  =
7115  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7116  k*nSpace+
7117  1]
7118  *
7119  df_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7120  k*nSpace+
7121  1];
7122  flux[ebNE*nQuadraturePoints_elementBoundary+
7123  k]+=
7124  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7125  k*nSpace+
7126  1]
7127  *
7128  f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7129  k*nSpace+
7130  1];
7131  }
7132  else
7133  {
7134  flux[ebNE*nQuadraturePoints_elementBoundary+
7135  k]+=
7136  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7137  k*nSpace+
7138  1]
7139  *
7140  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7141  k*nSpace+
7142  1];
7143  }
7144  if (isDOFBoundary_w[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
7145  {
7146  dflux_dw[ebNE*nQuadraturePoints_elementBoundary+
7147  k]
7148  =
7149  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7150  k*nSpace+
7151  2]
7152  *
7153  df_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7154  k*nSpace+
7155  2];
7156  flux[ebNE*nQuadraturePoints_elementBoundary+
7157  k]+=
7158  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7159  k*nSpace+
7160  2]
7161  *
7162  f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7163  k*nSpace+
7164  2];
7165  }
7166  else
7167  {
7168  flux[ebNE*nQuadraturePoints_elementBoundary+
7169  k]+=
7170  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7171  k*nSpace+
7172  2]
7173  *
7174  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7175  k*nSpace+
7176  2];
7177  }
7178  }
7179  }
7180 }
7181 
7186 void calculateGlobalExteriorNumericalAdvectiveFluxStokes2D(int nExteriorElementBoundaries_global,
7187  int nQuadraturePoints_elementBoundary,
7188  int nSpace,
7189  int* exteriorElementBoundaries,
7190  int* elementBoundaryElements,
7191  int* elementBoundaryLocalElementBoundaries,
7192  int *isDOFBoundary_p,
7193  int *isDOFBoundary_u,
7194  int *isDOFBoundary_v,
7195  double* n,
7196  double* bc_p,
7197  double* bc_f_mass,
7198  double* p,
7199  double* f_mass,
7200  double* df_mass_du,
7201  double* df_mass_dv,
7202  double* flux_mass,
7203  double* flux_umom,
7204  double* flux_vmom,
7205  double* dflux_mass_du,
7206  double* dflux_mass_dv,
7207  double* dflux_umom_dp,
7208  double* dflux_vmom_dp,
7209  double* velocity)
7210 
7211 {
7212  int ebNE,k;
7213  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
7214  {
7215  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
7216  {
7217  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
7218  k] = 0.0;
7219  dflux_mass_du[ebNE*nQuadraturePoints_elementBoundary+
7220  k] = 0.0;
7221  dflux_mass_dv[ebNE*nQuadraturePoints_elementBoundary+
7222  k] = 0.0;
7223 
7224  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
7225  k] = 0.0;
7226  dflux_umom_dp[ebNE*nQuadraturePoints_elementBoundary+
7227  k] = 0.0;
7228  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
7229  k] = 0.0;
7230  dflux_vmom_dp[ebNE*nQuadraturePoints_elementBoundary+
7231  k] = 0.0;
7232 
7233  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
7234  {
7235  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7236  k*nSpace+
7237  0] =
7238  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7239  k*nSpace+
7240  0];
7241  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
7242  k]
7243  +=
7244  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7245  k*nSpace+
7246  0]
7247  *
7248  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7249  k*nSpace+
7250  0];
7251  dflux_mass_du[ebNE*nQuadraturePoints_elementBoundary+
7252  k]
7253  +=
7254  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7255  k*nSpace+
7256  0]
7257  *
7258  df_mass_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7259  k*nSpace+
7260  0];
7261  }
7262  else
7263  {
7264  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7265  k*nSpace+
7266  0] =
7267  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7268  k*nSpace+
7269  0];
7270  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
7271  k]
7272  +=
7273  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7274  k*nSpace+
7275  0]
7276  *
7277  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7278  k*nSpace+
7279  0];
7280  }
7281  if (isDOFBoundary_v[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
7282  {
7283  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7284  k*nSpace+
7285  1] =
7286  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7287  k*nSpace+
7288  1];
7289  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
7290  k]
7291  +=
7292  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7293  k*nSpace+
7294  1]
7295  *
7296  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7297  k*nSpace+
7298  1];
7299  dflux_mass_dv[ebNE*nQuadraturePoints_elementBoundary+
7300  k]
7301  +=
7302  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7303  k*nSpace+
7304  1]
7305  *
7306  df_mass_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7307  k*nSpace+
7308  1];
7309  }
7310  else
7311  {
7312  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7313  k*nSpace+
7314  1] =
7315  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7316  k*nSpace+
7317  1];
7318  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
7319  k]
7320  +=
7321  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7322  k*nSpace+
7323  1]
7324  *
7325  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7326  k*nSpace+
7327  1];
7328  }
7329  if (isDOFBoundary_p[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
7330  {
7331  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
7332  k]
7333  +=
7334  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7335  k*nSpace+
7336  0]
7337  *
7338  (bc_p[ebNE*nQuadraturePoints_elementBoundary+
7339  k]
7340  -
7341  p[ebNE*nQuadraturePoints_elementBoundary+
7342  k]);
7343  dflux_umom_dp[ebNE*nQuadraturePoints_elementBoundary+
7344  k]
7345  = -n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7346  k*nSpace+
7347  0];
7348  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
7349  k]
7350  += n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7351  k*nSpace+
7352  1]
7353  *
7354  (bc_p[ebNE*nQuadraturePoints_elementBoundary+
7355  k]
7356  -
7357  p[ebNE*nQuadraturePoints_elementBoundary+
7358  k]);
7359  dflux_vmom_dp[ebNE*nQuadraturePoints_elementBoundary+
7360  k]
7361  = -n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7362  k*nSpace+
7363  1];
7364  }
7365  }
7366  }
7367 }
7368 
7369 void calculateGlobalExteriorNumericalAdvectiveFluxStokes3D(int nExteriorElementBoundaries_global,
7370  int nQuadraturePoints_elementBoundary,
7371  int nSpace,
7372  int* exteriorElementBoundaries,
7373  int* elementBoundaryElements,
7374  int* elementBoundaryLocalElementBoundaries,
7375  int *isDOFBoundary_p,
7376  int *isDOFBoundary_u,
7377  int *isDOFBoundary_v,
7378  int *isDOFBoundary_w,
7379  double* n,
7380  double* bc_p,
7381  double* bc_f_mass,
7382  double* p,
7383  double* f_mass,
7384  double* df_mass_du,
7385  double* df_mass_dv,
7386  double* df_mass_dw,
7387  double* flux_mass,
7388  double* flux_umom,
7389  double* flux_vmom,
7390  double* flux_wmom,
7391  double* dflux_mass_du,
7392  double* dflux_mass_dv,
7393  double* dflux_mass_dw,
7394  double* dflux_umom_dp,
7395  double* dflux_vmom_dp,
7396  double* dflux_wmom_dp,
7397  double* velocity)
7398 
7399 {
7400  int ebNE,k;
7401  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
7402  {
7403  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
7404  {
7405  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
7406  k] = 0.0;
7407  dflux_mass_du[ebNE*nQuadraturePoints_elementBoundary+
7408  k] = 0.0;
7409  dflux_mass_dv[ebNE*nQuadraturePoints_elementBoundary+
7410  k] = 0.0;
7411  dflux_mass_dw[ebNE*nQuadraturePoints_elementBoundary+
7412  k] = 0.0;
7413 
7414  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
7415  k] = 0.0;
7416  dflux_umom_dp[ebNE*nQuadraturePoints_elementBoundary+
7417  k] = 0.0;
7418 
7419  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
7420  k] = 0.0;
7421  dflux_vmom_dp[ebNE*nQuadraturePoints_elementBoundary+
7422  k] = 0.0;
7423 
7424  flux_wmom[ebNE*nQuadraturePoints_elementBoundary+
7425  k] = 0.0;
7426  dflux_wmom_dp[ebNE*nQuadraturePoints_elementBoundary+
7427  k] = 0.0;
7428 
7429  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
7430  {
7431  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7432  k*nSpace+
7433  0] =
7434  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7435  k*nSpace+
7436  0];
7437  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
7438  k]
7439  +=
7440  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7441  k*nSpace+
7442  0]
7443  *
7444  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7445  k*nSpace+
7446  0];
7447  dflux_mass_du[ebNE*nQuadraturePoints_elementBoundary+
7448  k]
7449  +=
7450  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7451  k*nSpace+
7452  0]
7453  *
7454  df_mass_du[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7455  k*nSpace+
7456  0];
7457  }
7458  else
7459  {
7460  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7461  k*nSpace+
7462  0] =
7463  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7464  k*nSpace+
7465  0];
7466  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
7467  k]
7468  +=
7469  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7470  k*nSpace+
7471  0]
7472  *
7473  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7474  k*nSpace+
7475  0];
7476  }
7477  if (isDOFBoundary_v[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
7478  {
7479  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7480  k*nSpace+
7481  1] =
7482  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7483  k*nSpace+
7484  1];
7485  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
7486  k]
7487  +=
7488  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7489  k*nSpace+
7490  1]
7491  *
7492  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7493  k*nSpace+
7494  1];
7495  dflux_mass_dv[ebNE*nQuadraturePoints_elementBoundary+
7496  k]
7497  +=
7498  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7499  k*nSpace+
7500  1]
7501  *
7502  df_mass_dv[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7503  k*nSpace+
7504  1];
7505  }
7506  else
7507  {
7508  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7509  k*nSpace+
7510  1] =
7511  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7512  k*nSpace+
7513  1];
7514  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
7515  k]
7516  +=
7517  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7518  k*nSpace+
7519  1]
7520  *
7521  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7522  k*nSpace+
7523  1];
7524  }
7525  if (isDOFBoundary_w[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
7526  {
7527  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7528  k*nSpace+
7529  2] =
7530  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7531  k*nSpace+
7532  2];
7533  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
7534  k]
7535  +=
7536  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7537  k*nSpace+
7538  2]
7539  *
7540  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7541  k*nSpace+
7542  2];
7543  dflux_mass_dw[ebNE*nQuadraturePoints_elementBoundary+
7544  k]
7545  +=
7546  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7547  k*nSpace+
7548  2]
7549  *
7550  df_mass_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7551  k*nSpace+
7552  2];
7553  }
7554  else
7555  {
7556  velocity[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7557  k*nSpace+
7558  2] =
7559  f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7560  k*nSpace+
7561  2];
7562  flux_mass[ebNE*nQuadraturePoints_elementBoundary+
7563  k]
7564  +=
7565  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7566  k*nSpace+
7567  2]
7568  *
7569  bc_f_mass[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7570  k*nSpace+
7571  2];
7572  }
7573  if (isDOFBoundary_p[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
7574  {
7575  flux_umom[ebNE*nQuadraturePoints_elementBoundary+
7576  k]
7577  +=
7578  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7579  k*nSpace+
7580  0]
7581  *
7582  (bc_p[ebNE*nQuadraturePoints_elementBoundary+
7583  k]
7584  -
7585  p[ebNE*nQuadraturePoints_elementBoundary+
7586  k]);
7587  dflux_umom_dp[ebNE*nQuadraturePoints_elementBoundary+
7588  k]
7589  = -n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7590  k*nSpace+
7591  0];
7592  flux_vmom[ebNE*nQuadraturePoints_elementBoundary+
7593  k]
7594  += n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7595  k*nSpace+
7596  1]
7597  *
7598  (bc_p[ebNE*nQuadraturePoints_elementBoundary+
7599  k]
7600  -
7601  p[ebNE*nQuadraturePoints_elementBoundary+
7602  k]);
7603  dflux_vmom_dp[ebNE*nQuadraturePoints_elementBoundary+
7604  k]
7605  = -n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7606  k*nSpace+
7607  1];
7608  flux_wmom[ebNE*nQuadraturePoints_elementBoundary+
7609  k]
7610  += n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7611  k*nSpace+
7612  2]
7613  *
7614  (bc_p[ebNE*nQuadraturePoints_elementBoundary+
7615  k]
7616  -
7617  p[ebNE*nQuadraturePoints_elementBoundary+
7618  k]);
7619  dflux_wmom_dp[ebNE*nQuadraturePoints_elementBoundary+
7620  k]
7621  = -n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7622  k*nSpace+
7623  2];
7624  }
7625  }
7626  }
7627 }
7628 
7629 
7633 void calculateExteriorNumericalAdvectiveFlux_average(int nExteriorElementBoundaries_global,
7634  int nElementBoundaries_element,
7635  int nQuadraturePoints_elementBoundary,
7636  int nSpace,
7637  int* exteriorElementBoundaries,
7638  int* elementBoundaryElements,
7639  int* elementBoundaryLocalElementBoundaries,
7640  int *isDOFBoundary,
7641  int *inflowFlag,
7642  double* n,
7643  double* bc_u,
7644  double* bc_f,
7645  double* bc_df,
7646  double* u,
7647  double* f,
7648  double* df,
7649  double* flux,
7650  double* dflux)
7651 {
7652  int ebNE,ebN,eN_global,ebN_element,k,J;
7653  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
7654  {
7655  ebN = exteriorElementBoundaries[ebNE];
7656  eN_global = elementBoundaryElements[ebN*2+0];
7657  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
7658  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
7659  {
7660  flux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
7661  dflux[ebN*nQuadraturePoints_elementBoundary+k] = 0.0;
7662  for(J=0;J<nSpace;J++)
7663  {
7664  flux[ebN*nQuadraturePoints_elementBoundary+k] +=
7665  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
7666  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
7667  k*nSpace+
7668  J]
7669  *
7670  (f[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
7671  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
7672  k*nSpace+
7673  J]
7674  +
7675  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7676  k*nSpace+
7677  J]);
7678  dflux[ebN*nQuadraturePoints_elementBoundary+k] +=
7679  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
7680  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
7681  k*nSpace+
7682  J]
7683  *
7684  df[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
7685  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
7686  k*nSpace+
7687  J];
7688  }
7689 /* flux[ebN*nQuadraturePoints_elementBoundary+k] *= 0.5; */
7690 /* if (isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1) */
7691 /* dflux[ebN*nQuadraturePoints_elementBoundary+k] *= 0.5; */
7692 /* for(J=0;J<nSpace;J++) */
7693 /* { */
7694 /* flux[ebN*nQuadraturePoints_elementBoundary+k] += */
7695 /* n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+ */
7696 /* ebN_element*nQuadraturePoints_elementBoundary*nSpace+ */
7697 /* k*nSpace+ */
7698 /* J] */
7699 /* * */
7700 /* f[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+ */
7701 /* ebN_element*nQuadraturePoints_elementBoundary*nSpace+ */
7702 /* k*nSpace+ */
7703 /* J]; */
7704 /* } */
7705  }
7706  }
7707 }
7711 void calculateGlobalExteriorNumericalAdvectiveFlux_average(int nExteriorElementBoundaries_global,
7712  int nQuadraturePoints_elementBoundary,
7713  int nSpace,
7714  int* exteriorElementBoundaries,
7715  int* elementBoundaryElements,
7716  int* elementBoundaryLocalElementBoundaries,
7717  int *isDOFBoundary,
7718  int *inflowFlag,
7719  double* n,
7720  double* bc_u,
7721  double* bc_f,
7722  double* bc_df,
7723  double* u,
7724  double* f,
7725  double* df,
7726  double* flux,
7727  double* dflux)
7728 {
7729  int ebNE,k,J;
7730  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
7731  {
7732  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
7733  {
7734  flux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
7735  dflux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
7736  for(J=0;J<nSpace;J++)
7737  {
7738  flux[ebNE*nQuadraturePoints_elementBoundary+k] +=
7739  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7740  k*nSpace+
7741  J]
7742  *
7743  (f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7744  k*nSpace+
7745  J]
7746  +
7747  bc_f[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7748  k*nSpace+
7749  J]);
7750  dflux[ebNE*nQuadraturePoints_elementBoundary+k] +=
7751  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7752  k*nSpace+
7753  J]
7754  *
7755  df[ebNE*nQuadraturePoints_elementBoundary*nSpace+
7756  k*nSpace+
7757  J];
7758  }
7759  }
7760  }
7761 }
7765 void calculateGlobalExteriorInflowNumericalAdvectiveFlux(int nExteriorElementBoundaries_global,
7766  int nQuadraturePoints_elementBoundary,
7767  int nSpace,
7768  int* exteriorElementBoundaries,
7769  int* elementBoundaryElements,
7770  int* elementBoundaryLocalElementBoundaries,
7771  int* inflowFlag,
7772  double* inflowFlux,
7773  double* n,
7774  double* f,
7775  double* df,
7776  double* flux,
7777  double* dflux_left)
7778 {
7779  int ebNE,k;
7780  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
7781  {
7782  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
7783  {
7784  if (inflowFlag[ebNE*nQuadraturePoints_elementBoundary+k])
7785  {
7786  flux[ebNE*nQuadraturePoints_elementBoundary+k] =
7787  inflowFlux[ebNE*nQuadraturePoints_elementBoundary+
7788  k];
7789  dflux_left[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
7790  }
7791  }
7792  }
7793 }
7797 void updateExteriorNumericalAdvectiveFluxJacobian(int nExteriorElementBoundaries_global,
7798  int nElementBoundaries_element,
7799  int nQuadraturePoints_elementBoundary,
7800  int nDOF_trial_element,
7801  int* exteriorElementBoundaries,
7802  int* elementBoundaryElements,
7803  int* elementBoundaryLocalElementBoundaries,
7804  int* inflowFlag,
7805  double* dflux_left,
7806  double* v,
7807  double* fluxJacobian)
7808 {
7809  int ebNE,ebN,left_eN_global,left_ebN_element,k,j;
7810  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
7811  {
7812  ebN = exteriorElementBoundaries[ebNE];
7813  left_eN_global = elementBoundaryElements[ebN*2+0];
7814  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
7815  /*mwf assume inflow boundary points have had their dflux_left zeroed?*/
7816  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
7817  {
7818  /*mwf only set jacobian if not on inflow? causes problems I think*/
7819  /*if (!inflowFlag[ebNE*nQuadraturePoints_elementBoundary+k])*/
7820  if (1)
7821  {
7822  for(j=0;j<nDOF_trial_element;j++)
7823  {
7824  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
7825  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
7826  k*nDOF_trial_element+
7827  j]
7828  +=
7829  dflux_left[ebN*nQuadraturePoints_elementBoundary+
7830  k]
7831  *
7832  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
7833  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
7834  k*nDOF_trial_element+
7835  j];
7836  }/*j*/
7837  }/*if on outflow*/
7838  }/*k*/
7839  }/*ebNE*/
7840 }
7844 void updateGlobalExteriorNumericalAdvectiveFluxJacobian(int nExteriorElementBoundaries_global,
7845  int nQuadraturePoints_elementBoundary,
7846  int nDOF_trial_element,
7847  int* exteriorElementBoundaries,
7848  int* elementBoundaryElements,
7849  int* elementBoundaryLocalElementBoundaries,
7850  int* inflowFlag,
7851  double* dflux_left,
7852  double* v,
7853  double* fluxJacobian)
7854 {
7855  int ebNE,ebN,left_eN_global,left_ebN_element,k,j;
7856  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
7857  {
7858  ebN = exteriorElementBoundaries[ebNE];
7859  left_eN_global = elementBoundaryElements[ebN*2+0];
7860  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
7861  /*mwf assume inflow boundary points have had their dflux_left zeroed?*/
7862  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
7863  {
7864  /*mwf only set jacobian if not on inflow? causes problems I think*/
7865  /*if (!inflowFlag[ebNE*nQuadraturePoints_elementBoundary+k])*/
7866  if (1)
7867  {
7868  for(j=0;j<nDOF_trial_element;j++)
7869  {
7870  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
7871  k*nDOF_trial_element+
7872  j]
7873  +=
7874  dflux_left[ebNE*nQuadraturePoints_elementBoundary+
7875  k]
7876  *
7877  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
7878  k*nDOF_trial_element+
7879  j];
7880  }/*j*/
7881  }/*if on outflow*/
7882  }/*k*/
7883  }/*ebNE*/
7884 }
7885 void updateExteriorNumericalAdvectiveFluxJacobian_free(int nExteriorElementBoundaries_global,
7886  int nElementBoundaries_element,
7887  int nQuadraturePoints_elementBoundary,
7888  int nDOF_trial_element,
7889  int* exteriorElementBoundaries,
7890  int* elementBoundaryElements,
7891  int* elementBoundaryLocalElementBoundaries,
7892  int* inflowFlag,
7893  double* dflux_left,
7894  double* v,
7895  double* fluxJacobian)
7896 {
7897  int ebNE,ebN,left_eN_global,left_ebN_element,k,j;
7898  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
7899  {
7900  ebN = exteriorElementBoundaries[ebNE];
7901  left_eN_global = elementBoundaryElements[ebN*2+0];
7902  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
7903  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
7904  {
7905  for(j=0;j<nDOF_trial_element;j++)
7906  {
7907  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
7908  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
7909  k*nDOF_trial_element+
7910  j]
7911  +=
7912  dflux_left[ebN*nQuadraturePoints_elementBoundary+
7913  k]
7914  *
7915  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
7916  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
7917  k*nDOF_trial_element+
7918  j];
7919  }/*j*/
7920  }/*k*/
7921  }/*ebNE*/
7922 }
7923 void updateGlobalExteriorNumericalAdvectiveFluxJacobian_free(int nExteriorElementBoundaries_global,
7924  int nQuadraturePoints_elementBoundary,
7925  int nDOF_trial_element,
7926  int* exteriorElementBoundaries,
7927  int* elementBoundaryElements,
7928  int* elementBoundaryLocalElementBoundaries,
7929  int* inflowFlag,
7930  double* dflux_left,
7931  double* v,
7932  double* fluxJacobian)
7933 {
7934  int ebNE,ebN,left_eN_global,left_ebN_element,k,j;
7935  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
7936  {
7937  ebN = exteriorElementBoundaries[ebNE];
7938  left_eN_global = elementBoundaryElements[ebN*2+0];
7939  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
7940  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
7941  {
7942  for(j=0;j<nDOF_trial_element;j++)
7943  {
7944  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
7945  k*nDOF_trial_element+
7946  j]
7947  +=
7948  dflux_left[ebNE*nQuadraturePoints_elementBoundary+
7949  k]
7950  *
7951  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
7952  k*nDOF_trial_element+
7953  j];
7954 /* fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+ */
7955 /* 0*nQuadraturePoints_elementBoundary*nDOF_trial_element+ */
7956 /* k*nDOF_trial_element+ */
7957 /* j] */
7958 /* += */
7959 /* dflux_left[ebN*nQuadraturePoints_elementBoundary+ */
7960 /* k] */
7961 /* * */
7962 /* v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+ */
7963 /* left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+ */
7964 /* k*nDOF_trial_element+ */
7965 /* j]; */
7966  }/*j*/
7967  }/*k*/
7968  }/*ebNE*/
7969 }
7973 void setInflowFlux(int nExteriorElementBoundaries_global,
7974  int nQuadraturePoints_elementBoundary,
7975  int* exteriorElementBoundaries,
7976  double* inflowFlux,
7977  double* flux)
7978 {
7979  int ebNE,ebN,k;
7980  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
7981  {
7982  ebN = exteriorElementBoundaries[ebNE];
7983  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
7984  inflowFlux[ebNE*nQuadraturePoints_elementBoundary+
7985  k]
7986  =
7987  flux[ebN*nQuadraturePoints_elementBoundary+
7988  k];
7989  }
7990 }
7991 
7992 /*********** LDG ***********/
7996 void calculateInteriorNumericalDiffusiveFlux_LDG_upwind(int nInteriorElementBoundaries_global,
7997  int nElementBoundaries_element,
7998  int nQuadraturePoints_elementBoundary,
7999  int nSpace,
8000  int* interiorElementBoundaries,
8001  int* elementBoundaryElements,
8002  int* elementBoundaryLocalElementBoundaries,
8003  double* n,
8004  double* u,
8005  double* a,
8006  double* phi,
8007  double* V,
8008  double* penalty,
8009  double* flux)
8010 {
8011  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,I,J,nSpace2=nSpace*nSpace;
8012  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
8013  {
8014  ebN = interiorElementBoundaries[ebNI];
8015  left_eN_global = elementBoundaryElements[ebN*2+0];
8016  right_eN_global = elementBoundaryElements[ebN*2+1];
8017  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
8018  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
8019  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
8020  {
8021  flux[ebN*nQuadraturePoints_elementBoundary+
8022  k] = 0.0;
8023  for(I=0;I<nSpace;I++)
8024  for(J=0;J<nSpace;J++)
8025  {
8026  flux[ebN*nQuadraturePoints_elementBoundary+
8027  k]
8028  +=
8029  TR_ALPHA*
8030  a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
8031  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
8032  k*nSpace2+
8033  I*nSpace+
8034  J]
8035  *
8036  V[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8037  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8038  k*nSpace+
8039  J]
8040  *
8041  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8042  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8043  k*nSpace+
8044  I];
8045  flux[ebN*nQuadraturePoints_elementBoundary+
8046  k]
8047  +=
8048  (1.0-TR_ALPHA)*
8049  a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
8050  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
8051  k*nSpace2+
8052  I*nSpace+
8053  J]
8054  *
8055  V[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8056  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8057  k*nSpace+
8058  J]
8059  *
8060  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8061  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8062  k*nSpace+
8063  I];
8064  }
8065  flux[ebN*nQuadraturePoints_elementBoundary+
8066  k]
8067  +=
8068  penalty[ebN*nQuadraturePoints_elementBoundary+k]
8069  *
8070  (phi[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
8071  left_ebN_element*nQuadraturePoints_elementBoundary+
8072  k]
8073  -
8074  phi[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
8075  right_ebN_element*nQuadraturePoints_elementBoundary+
8076  k]);
8077  }
8078  }
8079 }
8080 
8081 void calculateInteriorNumericalDiffusiveFlux_LDG_upwind_sd(int nInteriorElementBoundaries_global,
8082  int nElementBoundaries_element,
8083  int nQuadraturePoints_elementBoundary,
8084  int nSpace,
8085  int* rowptr,
8086  int* colind,
8087  int* interiorElementBoundaries,
8088  int* elementBoundaryElements,
8089  int* elementBoundaryLocalElementBoundaries,
8090  double* n,
8091  double* u,
8092  double* a,
8093  double* phi,
8094  double* V,
8095  double* penalty,
8096  double* flux)
8097 {
8098  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,I,m,nnz=rowptr[nSpace];
8099  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
8100  {
8101  ebN = interiorElementBoundaries[ebNI];
8102  left_eN_global = elementBoundaryElements[ebN*2+0];
8103  right_eN_global = elementBoundaryElements[ebN*2+1];
8104  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
8105  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
8106  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
8107  {
8108  flux[ebN*nQuadraturePoints_elementBoundary+
8109  k] = 0.0;
8110  for(I=0;I<nSpace;I++)
8111  for(m=rowptr[I];m<rowptr[I+1];m++)
8112  {
8113  flux[ebN*nQuadraturePoints_elementBoundary+
8114  k]
8115  +=
8116  TR_ALPHA*
8117  a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
8118  left_ebN_element*nQuadraturePoints_elementBoundary*nnz+
8119  k*nnz+
8120  m]
8121  *
8122  V[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8123  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8124  k*nSpace+
8125  colind[m]]
8126  *
8127  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8128  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8129  k*nSpace+
8130  I];
8131  flux[ebN*nQuadraturePoints_elementBoundary+
8132  k]
8133  +=
8134  (1.0-TR_ALPHA)*
8135  a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
8136  right_ebN_element*nQuadraturePoints_elementBoundary*nnz+
8137  k*nnz+
8138  m]
8139  *
8140  V[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8141  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8142  k*nSpace+
8143  colind[m]]
8144  *
8145  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8146  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8147  k*nSpace+
8148  I];
8149  }
8150  flux[ebN*nQuadraturePoints_elementBoundary+
8151  k]
8152  +=
8153  penalty[ebN*nQuadraturePoints_elementBoundary+k]
8154  *
8155  (phi[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
8156  left_ebN_element*nQuadraturePoints_elementBoundary+
8157  k]
8158  -
8159  phi[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
8160  right_ebN_element*nQuadraturePoints_elementBoundary+
8161  k]);
8162  }
8163  }
8164 }
8165 
8169 void updateInteriorNumericalDiffusiveFluxJacobian_LDG_upwind(int nInteriorElementBoundaries_global,
8170  int nElementBoundaries_element,
8171  int nQuadraturePoints_elementBoundary,
8172  int nDOF_trial_element,
8173  int nSpace,
8174  int* interiorElementBoundaries,
8175  int* elementBoundaryElements,
8176  int* elementBoundaryLocalElementBoundaries,
8177  double* n,
8178  double* a,
8179  double* da,
8180  double* dphi,
8181  double* V,
8182  double* DV,
8183  double* DV_eb,
8184  double* v,
8185  double* penalty,
8186  double* fluxJacobian,
8187  double* fluxJacobian_eb)
8188 {
8189  int ebNI,ebN,eN_ebN_element,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,j,I,J,nSpace2=nSpace*nSpace;
8190  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
8191  {
8192  ebN = interiorElementBoundaries[ebNI];
8193  left_eN_global = elementBoundaryElements[ebN*2+0];
8194  right_eN_global = elementBoundaryElements[ebN*2+1];
8195  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
8196  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
8197  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
8198  {
8199  for(j=0;j<nDOF_trial_element;j++)
8200  {
8201  for(I=0;I<nSpace;I++)
8202  for(J=0;J<nSpace;J++)
8203  {
8204  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8205  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8206  k*nDOF_trial_element+
8207  j]
8208  +=
8209  TR_ALPHA*(a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
8210  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
8211  k*nSpace2+
8212  I*nSpace+
8213  J]
8214  *
8215  DV[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8216  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8217  k*nDOF_trial_element*nSpace+
8218  j*nSpace+
8219  J]
8220  +
8221  da[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
8222  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
8223  k*nSpace2+
8224  I*nSpace+
8225  J]
8226  *
8227  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8228  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8229  k*nDOF_trial_element+
8230  j]
8231  *
8232  V[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8233  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8234  k*nSpace+
8235  J]
8236  )
8237  *
8238  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8239  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8240  k*nSpace+
8241  I];
8242  for (eN_ebN_element=0;eN_ebN_element<nElementBoundaries_element;eN_ebN_element++)
8243  fluxJacobian_eb[ebN*2*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8244  0*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8245  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8246  k*nDOF_trial_element+
8247  j]
8248  +=
8249  TR_ALPHA*a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
8250  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
8251  k*nSpace2+
8252  I*nSpace+
8253  J]
8254  *
8255  DV_eb[left_eN_global*nElementBoundaries_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8256  left_ebN_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8257  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8258  k*nDOF_trial_element*nSpace+
8259  j*nSpace+
8260  J]
8261  *
8262  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8263  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8264  k*nSpace+
8265  I];
8266  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8267  1*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8268  k*nDOF_trial_element+
8269  j]
8270  +=
8271  (1.0-TR_ALPHA)*a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
8272  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
8273  k*nSpace2+
8274  I*nSpace+
8275  J]
8276  *
8277  DV[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8278  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8279  k*nDOF_trial_element*nSpace+
8280  j*nSpace+
8281  J]
8282  *
8283  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8284  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8285  k*nSpace+
8286  I];
8287  for (eN_ebN_element=0;eN_ebN_element<nElementBoundaries_element;eN_ebN_element++)
8288  fluxJacobian_eb[ebN*2*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8289  1*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8290  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8291  k*nDOF_trial_element+
8292  j]
8293  +=
8294  (1.0-TR_ALPHA)*a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
8295  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
8296  k*nSpace2+
8297  I*nSpace+
8298  J]
8299  *
8300  DV_eb[right_eN_global*nElementBoundaries_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8301  right_ebN_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8302  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8303  k*nDOF_trial_element*nSpace+
8304  j*nSpace+
8305  J]
8306  *
8307  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8308  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8309  k*nSpace+
8310  I];
8311  }
8312  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8313  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8314  k*nDOF_trial_element+
8315  j]
8316  +=
8317  penalty[ebN*nQuadraturePoints_elementBoundary +k]
8318  *
8319  dphi[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
8320  left_ebN_element*nQuadraturePoints_elementBoundary+
8321  k]
8322  *
8323  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8324  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8325  k*nDOF_trial_element+
8326  j];
8327  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8328  1*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8329  k*nDOF_trial_element+
8330  j]
8331  -=
8332  penalty[ebN*nQuadraturePoints_elementBoundary + k]
8333  *
8334  dphi[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
8335  right_ebN_element*nQuadraturePoints_elementBoundary+
8336  k]
8337  *
8338  v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8339  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8340  k*nDOF_trial_element+
8341  j];
8342  }
8343  }
8344  }
8345 }
8346 
8347 void updateInteriorNumericalDiffusiveFluxJacobian_LDG_upwind_sd(int nInteriorElementBoundaries_global,
8348  int nElementBoundaries_element,
8349  int nQuadraturePoints_elementBoundary,
8350  int nDOF_trial_element,
8351  int nSpace,
8352  int* rowptr,
8353  int* colind,
8354  int* interiorElementBoundaries,
8355  int* elementBoundaryElements,
8356  int* elementBoundaryLocalElementBoundaries,
8357  double* n,
8358  double* a,
8359  double* da,
8360  double* dphi,
8361  double* V,
8362  double* DV,
8363  double* DV_eb,
8364  double* v,
8365  double* penalty,
8366  double* fluxJacobian,
8367  double* fluxJacobian_eb)
8368 {
8369  int ebNI,ebN,eN_ebN_element,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,j,I,m,nnz=rowptr[nSpace];
8370  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
8371  {
8372  ebN = interiorElementBoundaries[ebNI];
8373  left_eN_global = elementBoundaryElements[ebN*2+0];
8374  right_eN_global = elementBoundaryElements[ebN*2+1];
8375  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
8376  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
8377  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
8378  {
8379  for(j=0;j<nDOF_trial_element;j++)
8380  {
8381  for(I=0;I<nSpace;I++)
8382  for(m=rowptr[I];m<rowptr[I+1];m++)
8383  {
8384  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8385  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8386  k*nDOF_trial_element+
8387  j]
8388  +=
8389  TR_ALPHA*(a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
8390  left_ebN_element*nQuadraturePoints_elementBoundary*nnz+
8391  k*nnz+
8392  m]
8393  *
8394  DV[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8395  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8396  k*nDOF_trial_element*nSpace+
8397  j*nSpace+
8398  colind[m]]
8399  +
8400  da[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
8401  left_ebN_element*nQuadraturePoints_elementBoundary*nnz+
8402  k*nnz+
8403  m]
8404  *
8405  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8406  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8407  k*nDOF_trial_element+
8408  j]
8409  *
8410  V[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8411  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8412  k*nSpace+
8413  colind[m]]
8414  )
8415  *
8416  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8417  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8418  k*nSpace+
8419  I];
8420  for (eN_ebN_element=0;eN_ebN_element<nElementBoundaries_element;eN_ebN_element++)
8421  fluxJacobian_eb[ebN*2*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8422  0*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8423  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8424  k*nDOF_trial_element+
8425  j]
8426  +=
8427  TR_ALPHA*a[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
8428  left_ebN_element*nQuadraturePoints_elementBoundary*nnz+
8429  k*nnz+
8430  m]
8431  *
8432  DV_eb[left_eN_global*nElementBoundaries_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8433  left_ebN_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8434  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8435  k*nDOF_trial_element*nSpace+
8436  j*nSpace+
8437  colind[m]]
8438  *
8439  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8440  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8441  k*nSpace+
8442  I];
8443  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8444  1*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8445  k*nDOF_trial_element+
8446  j]
8447  +=
8448  (1.0-TR_ALPHA)*a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
8449  right_ebN_element*nQuadraturePoints_elementBoundary*nnz+
8450  k*nnz+
8451  m]
8452  *
8453  DV[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8454  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8455  k*nDOF_trial_element*nSpace+
8456  j*nSpace+
8457  colind[m]]
8458  *
8459  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8460  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8461  k*nSpace+
8462  I];
8463  for (eN_ebN_element=0;eN_ebN_element<nElementBoundaries_element;eN_ebN_element++)
8464  fluxJacobian_eb[ebN*2*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8465  1*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8466  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8467  k*nDOF_trial_element+
8468  j]
8469  +=
8470  (1.0-TR_ALPHA)*a[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
8471  right_ebN_element*nQuadraturePoints_elementBoundary*nnz+
8472  k*nnz+
8473  m]
8474  *
8475  DV_eb[right_eN_global*nElementBoundaries_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8476  right_ebN_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8477  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8478  k*nDOF_trial_element*nSpace+
8479  j*nSpace+
8480  colind[m]]
8481  *
8482  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8483  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8484  k*nSpace+
8485  I];
8486  }
8487  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8488  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8489  k*nDOF_trial_element+
8490  j]
8491  +=
8492  penalty[ebN*nQuadraturePoints_elementBoundary +k]
8493  *
8494  dphi[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
8495  left_ebN_element*nQuadraturePoints_elementBoundary+
8496  k]
8497  *
8498  v[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8499  left_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8500  k*nDOF_trial_element+
8501  j];
8502  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8503  1*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8504  k*nDOF_trial_element+
8505  j]
8506  -=
8507  penalty[ebN*nQuadraturePoints_elementBoundary + k]
8508  *
8509  dphi[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
8510  right_ebN_element*nQuadraturePoints_elementBoundary+
8511  k]
8512  *
8513  v[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8514  right_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8515  k*nDOF_trial_element+
8516  j];
8517  }
8518  }
8519  }
8520 }
8521 
8525 void calculateExteriorNumericalDiffusiveFlux_LDG_upwind(int nExteriorElementBoundaries_global,
8526  int nElementBoundaries_element,
8527  int nQuadraturePoints_elementBoundary,
8528  int nSpace,
8529  int* exteriorElementBoundaries,
8530  int* elementBoundaryElements,
8531  int* elementBoundaryLocalElementBoundaries,
8532  double* n,
8533  double* u,
8534  double* a,
8535  double* phi_bc,
8536  double* phi,
8537  double* V,
8538  double* penalty,
8539  double* flux)
8540 {
8541  int ebNE,ebN,eN_global,ebN_element,k,I,J,nSpace2=nSpace*nSpace;
8542  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
8543  {
8544  ebN = exteriorElementBoundaries[ebNE];
8545  eN_global = elementBoundaryElements[ebN*2+0];
8546  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
8547  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
8548  {
8549  flux[ebN*nQuadraturePoints_elementBoundary+
8550  k] =0.0;
8551  for(I=0;I<nSpace;I++)
8552  for(J=0;J<nSpace;J++)
8553  {
8554  flux[ebN*nQuadraturePoints_elementBoundary+
8555  k]
8556  +=
8557  TR_ALPHA_EXT*
8558  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
8559  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
8560  k*nSpace2+
8561  I*nSpace+
8562  J]
8563  *
8564  V[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8565  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8566  k*nSpace+
8567  J]
8568  *
8569  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8570  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8571  k*nSpace+
8572  I];
8573  }
8574  flux[ebN*nQuadraturePoints_elementBoundary+
8575  k] +=
8576  penalty[ebN*nQuadraturePoints_elementBoundary+
8577  k]*
8578  (phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
8579  ebN_element*nQuadraturePoints_elementBoundary+
8580  k]
8581  -
8582  phi_bc[ebNE*nQuadraturePoints_elementBoundary+
8583  k]);
8584 
8585  }
8586  }
8587 }
8588 void calculateExteriorNumericalDiffusiveFlux_LDG_upwind_sd(int nExteriorElementBoundaries_global,
8589  int nElementBoundaries_element,
8590  int nQuadraturePoints_elementBoundary,
8591  int nSpace,
8592  int* rowptr,
8593  int* colind,
8594  int* exteriorElementBoundaries,
8595  int* elementBoundaryElements,
8596  int* elementBoundaryLocalElementBoundaries,
8597  double* n,
8598  double* u,
8599  double* a,
8600  double* phi_bc,
8601  double* phi,
8602  double* V,
8603  double* penalty,
8604  double* flux)
8605 {
8606  int ebNE,ebN,eN_global,ebN_element,k,I,m,nnz=rowptr[nSpace];
8607  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
8608  {
8609  ebN = exteriorElementBoundaries[ebNE];
8610  eN_global = elementBoundaryElements[ebN*2+0];
8611  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
8612  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
8613  {
8614  flux[ebN*nQuadraturePoints_elementBoundary+
8615  k] =0.0;
8616  for(I=0;I<nSpace;I++)
8617  for(m=rowptr[I];m<rowptr[I+1];m++)
8618  {
8619  flux[ebN*nQuadraturePoints_elementBoundary+
8620  k]
8621  +=
8622  TR_ALPHA_EXT*
8623  a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
8624  ebN_element*nQuadraturePoints_elementBoundary*nnz+
8625  k*nnz+
8626  m]
8627  *
8628  V[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8629  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8630  k*nSpace+
8631  colind[m]]
8632  *
8633  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8634  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8635  k*nSpace+
8636  I];
8637  }
8638  flux[ebN*nQuadraturePoints_elementBoundary+
8639  k] +=
8640  penalty[ebN*nQuadraturePoints_elementBoundary+
8641  k]*
8642  (phi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
8643  ebN_element*nQuadraturePoints_elementBoundary+
8644  k]
8645  -
8646  phi_bc[ebNE*nQuadraturePoints_elementBoundary+
8647  k]);
8648 
8649  }
8650  }
8651 }
8655 void calculateGlobalExteriorNumericalDiffusiveFlux_LDG_upwind(int nExteriorElementBoundaries_global,
8656  int nElementBoundaries_element,
8657  int nQuadraturePoints_elementBoundary,
8658  int nSpace,
8659  int* exteriorElementBoundaries,
8660  int* elementBoundaryElements,
8661  int* elementBoundaryLocalElementBoundaries,
8662  double* n,
8663  double* u,
8664  double* a,
8665  double* phi_bc,
8666  double* phi,
8667  double* V,
8668  double* penalty,
8669  double* flux)
8670 {
8671  int ebNE,ebN,eN_global,ebN_element,k,I,J,nSpace2=nSpace*nSpace;
8672  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
8673  {
8674  ebN = exteriorElementBoundaries[ebNE];
8675  eN_global = elementBoundaryElements[ebN*2+0];
8676  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
8677  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
8678  {
8679  flux[ebNE*nQuadraturePoints_elementBoundary+
8680  k] =0.0;
8681  for(I=0;I<nSpace;I++)
8682  for(J=0;J<nSpace;J++)
8683  {
8684  flux[ebNE*nQuadraturePoints_elementBoundary+
8685  k]
8686  +=
8687  TR_ALPHA_EXT*
8688  a[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
8689  k*nSpace2+
8690  I*nSpace+
8691  J]
8692  *
8693  V[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8694  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8695  k*nSpace+
8696  J]
8697  *
8698  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
8699  k*nSpace+
8700  I];
8701  }
8702  flux[ebNE*nQuadraturePoints_elementBoundary+
8703  k] +=
8704  penalty[ebNE*nQuadraturePoints_elementBoundary+
8705  k]*
8706  (phi[ebNE*nQuadraturePoints_elementBoundary+
8707  k]
8708  -
8709  phi_bc[ebNE*nQuadraturePoints_elementBoundary+
8710  k]);
8711 
8712  }
8713  }
8714 }
8715 void calculateGlobalExteriorNumericalDiffusiveFlux_LDG_upwind_sd(int nExteriorElementBoundaries_global,
8716  int nElementBoundaries_element,
8717  int nQuadraturePoints_elementBoundary,
8718  int nSpace,
8719  int* rowptr,
8720  int* colind,
8721  int* exteriorElementBoundaries,
8722  int* elementBoundaryElements,
8723  int* elementBoundaryLocalElementBoundaries,
8724  double* n,
8725  double* u,
8726  double* a,
8727  double* phi_bc,
8728  double* phi,
8729  double* V,
8730  double* penalty,
8731  double* flux)
8732 {
8733  int ebNE,ebN,eN_global,ebN_element,k,I,m,nnz=rowptr[nSpace];
8734  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
8735  {
8736  ebN = exteriorElementBoundaries[ebNE];
8737  eN_global = elementBoundaryElements[ebN*2+0];
8738  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
8739  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
8740  {
8741  flux[ebNE*nQuadraturePoints_elementBoundary+
8742  k] =0.0;
8743  for(I=0;I<nSpace;I++)
8744  for(m=rowptr[I];m<rowptr[I+1];m++)
8745  {
8746  flux[ebNE*nQuadraturePoints_elementBoundary+
8747  k]
8748  +=
8749  TR_ALPHA_EXT*
8750  a[ebNE*nQuadraturePoints_elementBoundary*nnz+
8751  k*nnz+
8752  m]
8753  *
8754  V[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8755  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8756  k*nSpace+
8757  colind[m]]
8758  *
8759  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
8760  k*nSpace+
8761  I];
8762  }
8763  flux[ebNE*nQuadraturePoints_elementBoundary+
8764  k] +=
8765  penalty[ebNE*nQuadraturePoints_elementBoundary+
8766  k]*
8767  (phi[ebNE*nQuadraturePoints_elementBoundary+
8768  k]
8769  -
8770  phi_bc[ebNE*nQuadraturePoints_elementBoundary+
8771  k]);
8772 
8773  }
8774  }
8775 }
8780  int nExteriorElementBoundaries_global,
8781  int nElementBoundaries_element,
8782  int nQuadraturePoints_elementBoundary,
8783  int nDOF_trial_element,
8784  int nSpace,
8785  int* exteriorElementBoundaries,
8786  int* elementBoundaryElements,
8787  int* elementBoundaryLocalElementBoundaries,
8788  double* n,
8789  double* a,
8790  double* da,
8791  double* dphi,
8792  double* V,
8793  double* DV,
8794  double* DV_eb,
8795  double* v,
8796  double* penalty,
8797  double* fluxJacobian,
8798  double* fluxJacobian_eb)
8799 {
8800  int ebNE,ebN,eN_global,ebN_element,eN_ebN_element,k,j,I,J,nSpace2=nSpace*nSpace;
8801  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
8802  {
8803  ebN = exteriorElementBoundaries[ebNE];
8804  eN_global = elementBoundaryElements[ebN*2+0];
8805  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
8806  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
8807  {
8808  if(isDiffusiveFluxBoundary[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
8809  {
8810  for(j=0;j<nDOF_trial_element;j++)
8811  {
8812  for(I=0;I<nSpace;I++)
8813  for(J=0;J<nSpace;J++)
8814  {
8815  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8816  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8817  k*nDOF_trial_element+
8818  j]
8819  +=
8820  TR_ALPHA_EXT*
8821  (a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
8822  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
8823  k*nSpace2+
8824  I*nSpace+
8825  J]
8826  *
8827  DV[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8828  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8829  k*nDOF_trial_element*nSpace+
8830  j*nSpace+
8831  J]
8832  +
8833  da[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
8834  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
8835  k*nSpace2+
8836  I*nSpace+
8837  J]
8838  *
8839  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8840  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8841  k*nDOF_trial_element+
8842  j]
8843  *
8844  V[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8845  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8846  k*nSpace+
8847  J]
8848  )
8849  *
8850  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8851  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8852  k*nSpace+
8853  I];
8854  for (eN_ebN_element=0;eN_ebN_element<nElementBoundaries_element;eN_ebN_element++)
8855  {
8856  fluxJacobian_eb[ebN*2*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8857  0*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8858  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8859  k*nDOF_trial_element+
8860  j]
8861  +=
8862  TR_ALPHA_EXT*a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace2+
8863  ebN_element*nQuadraturePoints_elementBoundary*nSpace2+
8864  k*nSpace2+
8865  I*nSpace+
8866  J]
8867  *
8868  DV_eb[eN_global*nElementBoundaries_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8869  ebN_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8870  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8871  k*nDOF_trial_element*nSpace+
8872  j*nSpace+
8873  J]
8874  *
8875  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8876  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8877  k*nSpace+
8878  I];
8879  }
8880  }
8881  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8882  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8883  k*nDOF_trial_element+
8884  j]
8885  +=
8886  penalty[ebN*nQuadraturePoints_elementBoundary +k]
8887  *
8888  dphi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
8889  ebN_element*nQuadraturePoints_elementBoundary+
8890  k]
8891  *
8892  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8893  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8894  k*nDOF_trial_element+
8895  j];
8896  }
8897  }
8898  }
8899  }
8900 }
8902  int nExteriorElementBoundaries_global,
8903  int nElementBoundaries_element,
8904  int nQuadraturePoints_elementBoundary,
8905  int nDOF_trial_element,
8906  int nSpace,
8907  int* rowptr,
8908  int* colind,
8909  int* exteriorElementBoundaries,
8910  int* elementBoundaryElements,
8911  int* elementBoundaryLocalElementBoundaries,
8912  double* n,
8913  double* a,
8914  double* da,
8915  double* dphi,
8916  double* V,
8917  double* DV,
8918  double* DV_eb,
8919  double* v,
8920  double* penalty,
8921  double* fluxJacobian,
8922  double* fluxJacobian_eb)
8923 {
8924  int ebNE,ebN,eN_global,ebN_element,eN_ebN_element,k,j,I,m,nnz=rowptr[nSpace];
8925  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
8926  {
8927  ebN = exteriorElementBoundaries[ebNE];
8928  eN_global = elementBoundaryElements[ebN*2+0];
8929  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
8930  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
8931  {
8932  if(isDiffusiveFluxBoundary[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
8933  {
8934  for(j=0;j<nDOF_trial_element;j++)
8935  {
8936  for(I=0;I<nSpace;I++)
8937  for(m=rowptr[I];m<rowptr[I+1];m++)
8938  {
8939  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8940  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8941  k*nDOF_trial_element+
8942  j]
8943  +=
8944  TR_ALPHA_EXT*
8945  (a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
8946  ebN_element*nQuadraturePoints_elementBoundary*nnz+
8947  k*nnz+
8948  m]
8949  *
8950  DV[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8951  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8952  k*nDOF_trial_element*nSpace+
8953  j*nSpace+
8954  colind[m]]
8955  +
8956  da[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
8957  ebN_element*nQuadraturePoints_elementBoundary*nnz+
8958  k*nnz+
8959  m]
8960  *
8961  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8962  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8963  k*nDOF_trial_element+
8964  j]
8965  *
8966  V[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8967  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8968  k*nSpace+
8969  colind[m]]
8970  )
8971  *
8972  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8973  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8974  k*nSpace+
8975  I];
8976  for (eN_ebN_element=0;eN_ebN_element<nElementBoundaries_element;eN_ebN_element++)
8977  {
8978  fluxJacobian_eb[ebN*2*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8979  0*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8980  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
8981  k*nDOF_trial_element+
8982  j]
8983  +=
8984  TR_ALPHA_EXT*a[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz+
8985  ebN_element*nQuadraturePoints_elementBoundary*nnz+
8986  k*nnz+
8987  m]
8988  *
8989  DV_eb[eN_global*nElementBoundaries_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8990  ebN_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8991  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
8992  k*nDOF_trial_element*nSpace+
8993  j*nSpace+
8994  colind[m]]
8995  *
8996  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
8997  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
8998  k*nSpace+
8999  I];
9000  }
9001  }
9002  fluxJacobian[ebN*2*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9003  0*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9004  k*nDOF_trial_element+
9005  j]
9006  +=
9007  penalty[ebN*nQuadraturePoints_elementBoundary +k]
9008  *
9009  dphi[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
9010  ebN_element*nQuadraturePoints_elementBoundary+
9011  k]
9012  *
9013  v[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9014  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9015  k*nDOF_trial_element+
9016  j];
9017  }
9018  }
9019  }
9020  }
9021 }
9026  int nExteriorElementBoundaries_global,
9027  int nElementBoundaries_element,
9028  int nQuadraturePoints_elementBoundary,
9029  int nDOF_trial_element,
9030  int nSpace,
9031  int* exteriorElementBoundaries,
9032  int* elementBoundaryElements,
9033  int* elementBoundaryLocalElementBoundaries,
9034  double* n,
9035  double* a,
9036  double* da,
9037  double* dphi,
9038  double* V,
9039  double* DV,
9040  double* DV_eb,
9041  double* v,
9042  double* penalty,
9043  double* fluxJacobian_exterior,
9044  double* fluxJacobian_eb)
9045 {
9046  int ebNE,ebN,eN_global,ebN_element,eN_ebN_element,k,j,I,J,nSpace2=nSpace*nSpace;
9047  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
9048  {
9049  ebN = exteriorElementBoundaries[ebNE];
9050  eN_global = elementBoundaryElements[ebN*2+0];
9051  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
9052  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
9053  {
9054  if(isDiffusiveFluxBoundary[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
9055  {
9056  for(j=0;j<nDOF_trial_element;j++)
9057  {
9058  for(I=0;I<nSpace;I++)
9059  for(J=0;J<nSpace;J++)
9060  {
9061  fluxJacobian_exterior[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9062  k*nDOF_trial_element+
9063  j]
9064  +=
9065  TR_ALPHA_EXT*
9066  (a[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
9067  k*nSpace2+
9068  I*nSpace+
9069  J]
9070  *
9071  DV[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
9072  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
9073  k*nDOF_trial_element*nSpace+
9074  j*nSpace+
9075  J]
9076  +
9077  da[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
9078  k*nSpace2+
9079  I*nSpace+
9080  J]
9081  *
9082  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9083  k*nDOF_trial_element+
9084  j]
9085  *
9086  V[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
9087  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
9088  k*nSpace+
9089  J]
9090  )
9091  *
9092  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
9093  k*nSpace+
9094  I];
9095  for (eN_ebN_element=0;eN_ebN_element<nElementBoundaries_element;eN_ebN_element++)
9096  {
9097  fluxJacobian_eb[ebN*2*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9098  0*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9099  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9100  k*nDOF_trial_element+
9101  j]
9102  +=
9103  TR_ALPHA_EXT*a[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
9104  k*nSpace2+
9105  I*nSpace+
9106  J]
9107  *
9108  DV_eb[eN_global*nElementBoundaries_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
9109  ebN_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
9110  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
9111  k*nDOF_trial_element*nSpace+
9112  j*nSpace+
9113  J]
9114  *
9115  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
9116  k*nSpace+
9117  I];
9118  }
9119  }
9120  fluxJacobian_exterior[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9121  k*nDOF_trial_element+
9122  j]
9123  +=
9124  penalty[ebNE*nQuadraturePoints_elementBoundary +k]
9125  *
9126  dphi[ebNE*nQuadraturePoints_elementBoundary+
9127  k]
9128  *
9129  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9130  k*nDOF_trial_element+
9131  j];
9132  }
9133  }
9134  }
9135  }
9136 }
9137 
9139  int nExteriorElementBoundaries_global,
9140  int nElementBoundaries_element,
9141  int nQuadraturePoints_elementBoundary,
9142  int nDOF_trial_element,
9143  int nSpace,
9144  int* rowptr,
9145  int* colind,
9146  int* exteriorElementBoundaries,
9147  int* elementBoundaryElements,
9148  int* elementBoundaryLocalElementBoundaries,
9149  double* n,
9150  double* a,
9151  double* da,
9152  double* dphi,
9153  double* V,
9154  double* DV,
9155  double* DV_eb,
9156  double* v,
9157  double* penalty,
9158  double* fluxJacobian_exterior,
9159  double* fluxJacobian_eb)
9160 {
9161  int ebNE,ebN,eN_global,ebN_element,eN_ebN_element,k,j,I,m,nnz=rowptr[nSpace];
9162  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
9163  {
9164  ebN = exteriorElementBoundaries[ebNE];
9165  eN_global = elementBoundaryElements[ebN*2+0];
9166  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
9167  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
9168  {
9169  if(isDiffusiveFluxBoundary[ebNE*nQuadraturePoints_elementBoundary+k] != 1)
9170  {
9171  for(j=0;j<nDOF_trial_element;j++)
9172  {
9173  for(I=0;I<nSpace;I++)
9174  for(m=rowptr[I];m<rowptr[I+1];m++)
9175  {
9176  fluxJacobian_exterior[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9177  k*nDOF_trial_element+
9178  j]
9179  +=
9180  TR_ALPHA_EXT*
9181  (a[ebNE*nQuadraturePoints_elementBoundary*nnz+
9182  k*nnz+
9183  m]
9184  *
9185  DV[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
9186  ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
9187  k*nDOF_trial_element*nSpace+
9188  j*nSpace+
9189  colind[m]]
9190  +
9191  da[ebNE*nQuadraturePoints_elementBoundary*nnz+
9192  k*nnz+
9193  m]
9194  *
9195  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9196  k*nDOF_trial_element+
9197  j]
9198  *
9199  V[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
9200  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
9201  k*nSpace+
9202  colind[m]]
9203  )
9204  *
9205  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
9206  k*nSpace+
9207  I];
9208  for (eN_ebN_element=0;eN_ebN_element<nElementBoundaries_element;eN_ebN_element++)
9209  {
9210  fluxJacobian_eb[ebN*2*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9211  0*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9212  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9213  k*nDOF_trial_element+
9214  j]
9215  +=
9216  TR_ALPHA_EXT*a[ebNE*nQuadraturePoints_elementBoundary*nnz+
9217  k*nnz+
9218  m]
9219  *
9220  DV_eb[eN_global*nElementBoundaries_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
9221  ebN_element*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
9222  eN_ebN_element*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
9223  k*nDOF_trial_element*nSpace+
9224  j*nSpace+
9225  colind[m]]
9226  *
9227  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
9228  k*nSpace+
9229  I];
9230  }
9231  }
9232  fluxJacobian_exterior[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9233  k*nDOF_trial_element+
9234  j]
9235  +=
9236  penalty[ebNE*nQuadraturePoints_elementBoundary +k]
9237  *
9238  dphi[ebNE*nQuadraturePoints_elementBoundary+
9239  k]
9240  *
9241  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
9242  k*nDOF_trial_element+
9243  j];
9244  }
9245  }
9246  }
9247  }
9248 }
9249 /*
9250  pick matrices in "extended mixed formulation"
9251 
9252  \hat{a}^{-1} \vec v = \grad p (check sign)
9253  \pm \deld (\tilde{a} \vec v ) in mass conservation
9254  */
9256  int nElements_global,
9257  int nElementBoundaries_element,
9258  int nQuadraturePoints_element,
9259  int nQuadraturePoints_elementBoundary,
9260  int nSpace,
9261  const int * rowptr,
9262  const int * colind,
9263  const double * ebq_a,
9264  const double * q_a,
9265  double *eb_aHat,
9266  double *eb_aTilde,
9267  double *aHat,
9268  double *aTilde)
9269 {
9270  int eN,ebN,k,I,m,nnz=rowptr[nSpace];
9271  double factor=0.0;
9272  if (aSplit == 0)
9273  { /*inverted matrix is identity*/
9274  for (eN = 0; eN < nElements_global; eN++)
9275  for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
9276  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
9277  {
9278  for (I = 0; I < nSpace; I++)
9279  for (m=rowptr[I]; m < rowptr[I+1]; m++)
9280  {
9281  /*for starters only treats as diagonal*/
9282  factor = colind[m] == I ? 1.0 : 0.0;
9283  /*mwf debug
9284  printf("calc LDG split eN=%d ebN=%d k=%d I=%d m=%d J=%d factor=%g \n",
9285  eN,ebN,k,I,m,colind[m],factor);
9286  */
9287  eb_aHat[eN*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz +
9288  ebN*nQuadraturePoints_elementBoundary*nnz +
9289  k*nnz +
9290  m] = factor;
9291  }
9292  /* printf("aHat*aTilde \n"); */
9293  /* for (I = 0; I < nSpace; I++) */
9294  /* { */
9295  /* assert(nnz == nSpace*nSpace); */
9296  /* int J,K; */
9297  /* for (J = 0; J < nSpace; J++) */
9298  /* { */
9299  /* double res = 0.0; */
9300  /* for (K=0;K<nSpace;K++) */
9301  /* res += eb_aHat[eN*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz + */
9302  /* ebN*nQuadraturePoints_elementBoundary*nnz + */
9303  /* k*nnz + I*nSpace + K] */
9304  /* *eb_aTilde[eN*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz + */
9305  /* ebN*nQuadraturePoints_elementBoundary*nnz + */
9306  /* k*nnz + K*nSpace + J]; */
9307  /* printf("%i %i %12.5e \n",I,J,res); */
9308  /* } */
9309  /* } */
9310  }
9311  for (eN = 0; eN < nElements_global; eN++)
9312  for (k = 0; k < nQuadraturePoints_element; k++)
9313  for (I = 0; I < nSpace; I++)
9314  for (m=rowptr[I]; m < rowptr[I+1]; m++)
9315  {
9316  /*for starters only treats as diagonal*/
9317  factor = colind[m] == I ? 1.0 : 0.0;
9318  aHat[eN*nQuadraturePoints_element*nnz +
9319  k*nnz +
9320  m] = factor;
9321  }
9322  }
9323  else if (aSplit == 1)
9324  { /*inverted matrix is a*/
9325  for (eN = 0; eN < nElements_global; eN++)
9326  for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
9327  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
9328  {
9329  for (I = 0; I < nSpace; I++)
9330  for (m=rowptr[I]; m < rowptr[I+1]; m++)
9331  {
9332  /*for starters only treats as diagonal*/
9333  factor = colind[m] == I ? 1.0 : 0.0;
9334  eb_aTilde[eN*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz +
9335  ebN*nQuadraturePoints_elementBoundary*nnz +
9336  k*nnz +
9337  m] = factor;
9338  }
9339  /* printf("aHat*aTilde \n"); */
9340  /* for (I = 0; I < nSpace; I++) */
9341  /* { */
9342  /* assert(nnz == nSpace*nSpace); */
9343  /* int J,K; */
9344  /* for (J = 0; J < nSpace; J++) */
9345  /* { */
9346  /* double res = 0.0; */
9347  /* for (K=0;K<nSpace;K++) */
9348  /* res += eb_aHat[eN*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz + */
9349  /* ebN*nQuadraturePoints_elementBoundary*nnz + */
9350  /* k*nnz + I*nSpace + K] */
9351  /* *eb_aTilde[eN*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz + */
9352  /* ebN*nQuadraturePoints_elementBoundary*nnz + */
9353  /* k*nnz + K*nSpace + J]; */
9354  /* printf("%i %i %12.5e \n",I,J,res); */
9355  /* } */
9356  /* } */
9357  }
9358  for (eN = 0; eN < nElements_global; eN++)
9359  for (k = 0; k < nQuadraturePoints_element; k++)
9360  {
9361  for (I = 0; I < nSpace; I++)
9362  for (m=rowptr[I]; m < rowptr[I+1]; m++)
9363  {
9364  /*for starters only treats as diagonal*/
9365  factor = colind[m] == I ? 1.0 : 0.0;
9366  aTilde[eN*nQuadraturePoints_element*nnz +
9367  k*nnz +
9368  m] = factor;
9369  }
9370  /* for (I = 0; I < nSpace; I++) */
9371  /* { */
9372  /* assert(nnz == nSpace*nSpace); */
9373  /* int J,K; */
9374  /* for (J = 0; J < nSpace; J++) */
9375  /* { */
9376  /* double res = 0.0; */
9377  /* for (K=0;K<nSpace;K++) */
9378  /* res += aHat[eN*nQuadraturePoints_element*nnz + */
9379  /* k*nnz + I*nSpace + K] */
9380  /* *aTilde[eN*nQuadraturePoints_element*nnz + */
9381  /* k*nnz + K*nSpace + J]; */
9382  /* printf("%i %i %12.5e \n",I,J,res); */
9383  /* } */
9384  /* } */
9385  }
9386  }
9387  else
9388  {
9389  assert(aSplit == 2);
9390  /*inverted matrix is sqrt(a)*/
9391  for (eN = 0; eN < nElements_global; eN++)
9392  for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
9393  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
9394  for (I = 0; I < nSpace; I++)
9395  for (m=rowptr[I]; m < rowptr[I+1]; m++)
9396  {
9397  /*for starters only treats as diagonal*/
9398  factor = colind[m] == I ? sqrt(ebq_a[eN*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz +
9399  ebN*nQuadraturePoints_elementBoundary*nnz +
9400  k*nnz +
9401  m]) : 0.0;
9402  eb_aTilde[eN*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz +
9403  ebN*nQuadraturePoints_elementBoundary*nnz +
9404  k*nnz +
9405  m] = factor;
9406  eb_aHat[eN*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nnz +
9407  ebN*nQuadraturePoints_elementBoundary*nnz +
9408  k*nnz +
9409  m] = factor;
9410  }
9411  for (eN = 0; eN < nElements_global; eN++)
9412  for (k = 0; k < nQuadraturePoints_element; k++)
9413  for (I = 0; I < nSpace; I++)
9414  for (m=rowptr[I]; m < rowptr[I+1]; m++)
9415  {
9416  /*for starters only treats as diagonal*/
9417  factor = colind[m] == I ? sqrt(q_a[eN*nQuadraturePoints_element*nnz +
9418  k*nnz +
9419  m]) : 0.0;
9420  aTilde[eN*nQuadraturePoints_element*nnz +
9421  k*nnz +
9422  m] = factor;
9423  aHat[eN*nQuadraturePoints_element*nnz +
9424  k*nnz +
9425  m] = factor;
9426  }
9427 
9428  }
9429 }
9430 
9431 
9432 /***********************************************************************
9433  end LDG
9434  **********************************************************************/
9435 void calculateInteriorLesaintRaviartNumericalFlux(int nInteriorElementBoundaries_global,
9436  int nElementBoundaries_element,
9437  int nQuadraturePoints_elementBoundary,
9438  int nSpace,
9439  int speedEvalFlag,
9440  int* interiorElementBoundaries,
9441  int* elementBoundaryElements,
9442  int* elementBoundaryLocalElementBoundaries,
9443  double* n,
9444  double* u,
9445  double* H,
9446  double* dH,
9447  double* flux,
9448  double* dflux_left,
9449  double* dflux_right)
9450 {
9451  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,J;
9452  double left_flux,right_flux,u_left,u_right,left_speed,right_speed,
9453  tmp_left,tmp_right;
9454  /*for now use outer normal at first quadrature point for element speed calculations*/
9455 
9456  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
9457  {
9458  ebN = interiorElementBoundaries[ebNI];
9459  left_eN_global = elementBoundaryElements[ebN*2+0];
9460  right_eN_global = elementBoundaryElements[ebN*2+1];
9461  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
9462  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
9463  /*
9464  dH_{L/R} = dH_{eN_left/eN_right} . n_{eN_left}
9465 
9466  dH_min = min(dH_L,dH_R), dH_max = max(dH_L,dH_R)
9467 
9468  if dH_min < 0
9469  flux_eN_left = |dH_min| (u^{L}- u^{R})
9470  else
9471  flux_eN_left = 0
9472  if dH_max > 0
9473  flux_eN_right = |dH_max| (u^{R}-u^{L})
9474  else
9475  flux_eN_right = 0
9476  */
9477  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
9478  {
9479  left_speed =0.0;
9480  right_speed=0.0;
9481  left_flux=0.0;
9482  right_flux=0.0;
9483  tmp_left = 0.0;
9484  tmp_right = 0.0;
9485  /*compute speed relative to left normal*/
9486  for(J=0;J<nSpace;J++)
9487  {
9488  tmp_left
9489  +=
9490  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
9491  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
9492  k*nSpace+
9493  J]
9494  *
9495  dH[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
9496  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
9497  k*nSpace+
9498  J];
9499  tmp_right
9500  +=
9501  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
9502  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
9503  k*nSpace+
9504  J]
9505  *
9506  dH[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
9507  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
9508  k*nSpace+
9509  J];
9510  }
9511  /*left_speed = min(dH_L,dH_R); right_speed = max(dH_L,dH_R) */
9512  left_speed = tmp_left; right_speed = tmp_right;
9513  if (tmp_right < tmp_left)
9514  {
9515  left_speed = tmp_right; right_speed = tmp_left;
9516  }
9517  u_left = u[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
9518  left_ebN_element*nQuadraturePoints_elementBoundary+
9519  k];
9520  u_right= u[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
9521  right_ebN_element*nQuadraturePoints_elementBoundary+
9522  k];
9523  if (left_speed < 0.0)/*inflow for left*/
9524  {
9525  left_flux = fabs(left_speed)*(u_left-u_right);
9526  flux[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9527  left_ebN_element*nQuadraturePoints_elementBoundary+ k ] = left_flux;
9528  dflux_left[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9529  left_ebN_element*nQuadraturePoints_elementBoundary+ k ] = fabs(left_speed);
9530  dflux_right[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9531  left_ebN_element*nQuadraturePoints_elementBoundary+ k ] =-fabs(left_speed);
9532 
9533  }
9534  else
9535  {
9536  left_flux = 0.0;
9537  flux[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9538  left_ebN_element*nQuadraturePoints_elementBoundary+ k ] = left_flux;
9539  dflux_left[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9540  left_ebN_element*nQuadraturePoints_elementBoundary+ k ] = 0.0;
9541  dflux_right[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9542  left_ebN_element*nQuadraturePoints_elementBoundary+ k ] = 0.0;
9543 
9544  }
9545  if (right_speed > 0.0)/*inflow for right*/
9546  {
9547  right_flux = fabs(right_speed)*(u_right-u_left);
9548  flux[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9549  right_ebN_element*nQuadraturePoints_elementBoundary+ k ] = right_flux;
9550  dflux_left[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9551  right_ebN_element*nQuadraturePoints_elementBoundary+ k ] = -fabs(right_speed);
9552  dflux_right[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9553  right_ebN_element*nQuadraturePoints_elementBoundary+ k ] = fabs(right_speed);
9554  }
9555  else
9556  {
9557  right_flux = 0.0;
9558  flux[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9559  right_ebN_element*nQuadraturePoints_elementBoundary+ k ] = right_flux;
9560  dflux_left[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9561  right_ebN_element*nQuadraturePoints_elementBoundary+ k ] = 0.0;
9562  dflux_right[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9563  right_ebN_element*nQuadraturePoints_elementBoundary+ k ] = 0.0;
9564  }
9565 
9566  }/*k*/
9567  }/*ebnI*/
9568 }
9569 void calculateExteriorLesaintRaviartNumericalFlux(int nExteriorElementBoundaries_global,
9570  int nElementBoundaries_element,
9571  int nQuadraturePoints_elementBoundary,
9572  int nSpace,
9573  int speedEvalFlag,
9574  int* exteriorElementBoundaries,
9575  int* elementBoundaryElements,
9576  int* elementBoundaryLocalElementBoundaries,
9577  int* isDOFBoundary,
9578  int* inflowFlag,
9579  double* n,
9580  double* bc_u,
9581  double* bc_H,
9582  double* bc_dH,
9583  double* u,
9584  double* H,
9585  double* dH,
9586  double* flux,
9587  double* dflux)
9588 {
9589  int ebNE,ebN,eN_global,ebN_element,k,J;
9590  double left_flux,right_flux,u_left,u_right,left_speed,right_speed,tmp_left,tmp_right;
9591  /*for now use outer normal at first quadrature point for element speed calculations*/
9592 
9593  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
9594  {
9595  ebN = exteriorElementBoundaries[ebNE];
9596  eN_global = elementBoundaryElements[ebN*2+0];
9597  ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
9598  /*
9599  dH_{L/R} = dH_{eN_left/eN_right} . n_{eN_left}
9600 
9601  dH_min = min(dH_L,dH_R), dH_max = max(dH_L,dH_R)
9602 
9603  if dH_min < 0
9604  flux_eN_left = |dH_min| (u^{L}- u^{R})
9605  else
9606  flux_eN_left = 0
9607  if dH_max > 0
9608  flux_eN_right = |dH_max| (u^{R}-u^{L})
9609  else
9610  flux_eN_right = 0
9611  */
9612 
9613  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
9614  {
9615  left_speed =0.0;
9616  right_speed=0.0;
9617  left_flux=0.0;
9618  right_flux=0.0;
9619  tmp_left = 0.0;
9620  tmp_right = 0.0;
9621  for(J=0;J<nSpace;J++)
9622  {
9623  tmp_left
9624  +=
9625  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
9626  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
9627  k*nSpace+
9628  J]
9629  *
9630  dH[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
9631  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
9632  k*nSpace+
9633  J];
9634  tmp_right
9635  +=
9636  n[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
9637  ebN_element*nQuadraturePoints_elementBoundary*nSpace+
9638  k*nSpace+
9639  J]
9640  *
9641  bc_dH[ebNE*nQuadraturePoints_elementBoundary*nSpace+
9642  k*nSpace+
9643  J];
9644  }
9645  /*left_speed = min(dH_L,dH_R); right_speed = max(dH_L,dH_R) */
9646  left_speed = tmp_left; right_speed = tmp_right;
9647  if (tmp_right < tmp_left)
9648  {
9649  left_speed = tmp_right; right_speed = tmp_left;
9650  }
9651  u_left = u[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
9652  ebN_element*nQuadraturePoints_elementBoundary+
9653  k];
9654  u_right= bc_u[ebNE*nQuadraturePoints_elementBoundary+
9655  k];
9656  if (left_speed < 0.0)/*inflow for left*/
9657  {
9658  left_flux = fabs(left_speed)*(u_left-u_right);
9659  flux[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9660  ebN_element*nQuadraturePoints_elementBoundary+ k ] = left_flux;
9661  dflux[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9662  ebN_element*nQuadraturePoints_elementBoundary+ k ] = fabs(left_speed);
9663  }
9664  else
9665  {
9666  left_flux = 0.0;
9667  flux[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9668  ebN_element*nQuadraturePoints_elementBoundary+ k ] = left_flux;
9669  dflux[eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
9670  ebN_element*nQuadraturePoints_elementBoundary+ k ] = 0.0;
9671  }
9672  }/*k*/
9673  }/*ebnE*/
9674 }
9675 void calculateGlobalExteriorLesaintRaviartNumericalFlux(int nExteriorElementBoundaries_global,
9676  int nQuadraturePoints_elementBoundary,
9677  int nSpace,
9678  int speedEvalFlag,
9679  int* exteriorElementBoundaries,
9680  int* elementBoundaryElements,
9681  int* elementBoundaryLocalElementBoundaries,
9682  int* isDOFBoundary,
9683  int* inflowFlag,
9684  double* n,
9685  double* bc_u,
9686  double* bc_H,
9687  double* bc_dH,
9688  double* u,
9689  double* H,
9690  double* dH,
9691  double* flux,
9692  double* dflux)
9693 {
9694  int ebNE,ebN,eN_global,k,J;
9695  double left_flux,right_flux,u_left,u_right,left_speed,right_speed,tmp_left,tmp_right;
9696 
9697  /*for now use outer normal at first quadrature point for element speed calculations*/
9698 
9699  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
9700  {
9701  ebN = exteriorElementBoundaries[ebNE];
9702  eN_global = elementBoundaryElements[ebN*2+0];
9703  /*
9704  dH_{L/R} = dH_{eN_left/eN_right} . n_{eN_left}
9705 
9706  dH_min = min(dH_L,dH_R), dH_max = max(dH_L,dH_R)
9707 
9708  if dH_min < 0
9709  flux_eN_left = |dH_min| (u^{L}- u^{R})
9710  else
9711  flux_eN_left = 0
9712  if dH_max > 0
9713  flux_eN_right = |dH_max| (u^{R}-u^{L})
9714  else
9715  flux_eN_right = 0
9716  */
9717  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
9718  {
9719  left_speed =0.0;
9720  right_speed=0.0;
9721  left_flux=0.0;
9722  right_flux=0.0;
9723  tmp_left = 0.0;
9724  tmp_right = 0.0;
9725  for(J=0;J<nSpace;J++)
9726  {
9727  tmp_left
9728  +=
9729  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
9730  k*nSpace+
9731  J]
9732  *
9733  dH[ebNE*nQuadraturePoints_elementBoundary*nSpace+
9734  k*nSpace+
9735  J];
9736  tmp_right
9737  +=
9738  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
9739  k*nSpace+
9740  J]
9741  *
9742  bc_dH[ebNE*nQuadraturePoints_elementBoundary*nSpace+
9743  k*nSpace+
9744  J];
9745  }
9746  /*left_speed = min(dH_L,dH_R); right_speed = max(dH_L,dH_R) */
9747  left_speed = tmp_left; right_speed = tmp_right;
9748  if (tmp_right < tmp_left)
9749  {
9750  left_speed = tmp_right; right_speed = tmp_left;
9751  }
9752  u_left = u[ebNE*nQuadraturePoints_elementBoundary+
9753  k];
9754  u_right= bc_u[ebNE*nQuadraturePoints_elementBoundary+
9755  k];
9756 
9757  if (left_speed < 0.0)/*inflow for left*/
9758  {
9759  left_flux = fabs(left_speed)*(u_left-u_right);
9760  flux[ebNE*nQuadraturePoints_elementBoundary + k ] = left_flux;
9761  dflux[ebNE*nQuadraturePoints_elementBoundary + k ] = fabs(left_speed);
9762  }
9763  else
9764  {
9765  left_flux = 0.0;
9766  flux[ebNE*nQuadraturePoints_elementBoundary + k ] = left_flux;
9767  dflux[ebNE*nQuadraturePoints_elementBoundary + k ] = 0.0;
9768  }
9769 
9770  }/*k*/
9771  }/*ebnE*/
9772 }
9773 void calculateGlobalExteriorNumericalFluxDarcyFCFF(int nExteriorElementBoundaries_global,
9774  int nQuadraturePoints_elementBoundary,
9775  int nSpace,
9776  const int* exteriorElementBoundaries,
9777  const int* elementBoundaryElements,
9778  const int* elementBoundaryLocalElementBoundaries,
9779  const int* isDOFBoundary_uw,
9780  const int* isDOFBoundary_um,
9781  const double* n,
9782  const double* bc_f_m,
9783  const double* bc_a_wm,
9784  const double* bc_a_mw,
9785  const double* bc_a_mm,
9786  const double* bc_grad_phi_w,
9787  const double* bc_grad_phi_m,
9788  const double* bc_u_w,
9789  const double* bc_u_m,
9790  const double* f_m, /*lambda_n K_s g(b rho_n-rho_w)*/
9791  const double* df_m_dw, /*dlambda_n K_s g(b rho_n-rho_w)*/
9792  const double* a_wm, /*lambda_w K_s*/
9793  const double* a_mw, /*lambda_n K_s*/
9794  const double* a_mm, /*lambda_t K_s*/
9795  const double* grad_phi_w, /*psi_c*/
9796  const double* grad_phi_m, /*psi_w - rho g . x*/
9797  const double* u_w, /*S_w*/
9798  const double* u_m, /*psi_w*/
9799  const double* penalty_w,
9800  const double* penalty_m,
9801  double * advectiveFlux_m,
9802  double * dadvectiveFlux_m_dw,
9803  double * diffusiveFlux_wm,
9804  double * diffusiveFlux_mw,
9805  double * diffusiveFlux_mm)
9806 {
9807  int ebNE,ebN,I,J,k,nSpace2=nSpace*nSpace;
9808  double diffusiveFlux_I=0.0,penaltyFlux = 0.0;
9809 
9810  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
9811  {
9812  ebN = exteriorElementBoundaries[ebNE];
9813  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
9814  {
9815  /*compute diffusive flux for first (w) equation (aq. mass
9816  balance for part of boundary where u_0 (i.e., S_w) is
9817  specified*/
9818  diffusiveFlux_wm[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
9819  advectiveFlux_m[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
9820  diffusiveFlux_mw[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
9821  diffusiveFlux_mm[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
9822 
9823  dadvectiveFlux_m_dw[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
9824  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
9825  {
9826  /*integration by parts term for diffusive flux*/
9827  for (I = 0; I < nSpace; I++)
9828  {
9829  diffusiveFlux_I = 0.0;
9830  for (J = 0; J < nSpace; J++)
9831  {
9832  diffusiveFlux_I -=
9833  a_wm[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
9834  k*nSpace2 +
9835  I*nSpace +
9836  J]
9837  *
9838  grad_phi_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
9839  k*nSpace +
9840  J];
9841  }
9842  diffusiveFlux_wm[ebNE*nQuadraturePoints_elementBoundary+k] +=
9843  diffusiveFlux_I
9844  *
9845  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
9846  k*nSpace+
9847  I];
9848  }/*I, a_wm grad phi_m term */
9849  /*boundary penalty term*/
9850  penaltyFlux =
9851  penalty_w[ebNE*nQuadraturePoints_elementBoundary + k]
9852  *
9853  (u_w[ebNE*nQuadraturePoints_elementBoundary + k]
9854  -
9855  bc_u_w[ebNE*nQuadraturePoints_elementBoundary + k]);
9856  diffusiveFlux_wm[ebNE*nQuadraturePoints_elementBoundary +k] +=
9857  penaltyFlux;
9858  }/*u_w boundary*/
9859  if(isDOFBoundary_um[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
9860  {
9861  /*just evaluate the 'advective flux term for the mixture equation
9862  using the internal value since gravity term actually depends on
9863  u_w = S_w and not u_m = psi_w (unless it's compressible)*/
9864  for (I = 0; I < nSpace; I++)
9865  {
9866  advectiveFlux_m[ebNE*nQuadraturePoints_elementBoundary + k] +=
9867  f_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
9868  k*nSpace +
9869  I]
9870  *
9871  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
9872  k*nSpace +
9873  I];
9874  /*basic fc_ff class doesn't have compressibility*/
9875 /* dadvectiveFlux_m_dm[ebNE*nQuadraturePoints_elementBoundary + k] += */
9876 /* df_m_dm[ebNE*nQuadraturePoints_elementBoundary*nSpace + */
9877 /* k*nSpace + */
9878 /* I] */
9879 /* * */
9880 /* n[ebNE*nQuadraturePoints_elementBoundary*nSpace + */
9881 /* k*nSpace + */
9882 /* I]; */
9883  dadvectiveFlux_m_dw[ebNE*nQuadraturePoints_elementBoundary + k] +=
9884  df_m_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace +
9885  k*nSpace +
9886  I]
9887  *
9888  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
9889  k*nSpace +
9890  I];
9891 
9892  }/*calculation of advective flux*/
9893  /*integration by parts term for diffusive flux wrt phi_w = psi_c*/
9894  for (I = 0; I < nSpace; I++)
9895  {
9896  diffusiveFlux_I = 0.0;
9897  for (J = 0; J < nSpace; J++)
9898  {
9899  diffusiveFlux_I -=
9900  a_mw[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
9901  k*nSpace2 +
9902  I*nSpace +
9903  J]
9904  *
9905  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
9906  k*nSpace +
9907  J];
9908  }/*J*/
9909  diffusiveFlux_mw[ebNE*nQuadraturePoints_elementBoundary + k] +=
9910  diffusiveFlux_I
9911  *
9912  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
9913  k*nSpace +
9914  I];
9915  }/*I, a_mw grad phi_w term */
9916  /*integration by parts term for diffusive flux wrt phi_m = psi_w*/
9917  for (I = 0; I < nSpace; I++)
9918  {
9919  diffusiveFlux_I = 0.0;
9920  for (J = 0; J < nSpace; J++)
9921  {
9922  diffusiveFlux_I -=
9923  a_mm[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
9924  k*nSpace2 +
9925  I*nSpace +
9926  J]
9927  *
9928  grad_phi_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
9929  k*nSpace +
9930  J];
9931  }/*J*/
9932  diffusiveFlux_mm[ebNE*nQuadraturePoints_elementBoundary + k] +=
9933  diffusiveFlux_I
9934  *
9935  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
9936  k*nSpace +
9937  I];
9938  }/*I, a_mw grad phi_w term */
9939  /*boundary penalty term*/
9940  penaltyFlux =
9941  penalty_m[ebNE*nQuadraturePoints_elementBoundary + k]
9942  *
9943  (u_m[ebNE*nQuadraturePoints_elementBoundary + k]
9944  -
9945  bc_u_m[ebNE*nQuadraturePoints_elementBoundary + k]);
9946  diffusiveFlux_mm[ebNE*nQuadraturePoints_elementBoundary +k] +=
9947  penaltyFlux;
9948  }/*um boundary*/
9949  }/*k*/
9950  }/*ebNE*/
9951 }
9952 void calculateGlobalExteriorNumericalFluxDarcyFCFF_sd(int nExteriorElementBoundaries_global,
9953  int nQuadraturePoints_elementBoundary,
9954  int nSpace,
9955  int* rowptr_wm,
9956  int* colind_wm,
9957  int* rowptr_mw,
9958  int* colind_mw,
9959  int* rowptr_mm,
9960  int* colind_mm,
9961  const int* exteriorElementBoundaries,
9962  const int* elementBoundaryElements,
9963  const int* elementBoundaryLocalElementBoundaries,
9964  const int* isDOFBoundary_uw,
9965  const int* isDOFBoundary_um,
9966  const double* n,
9967  const double* bc_f_m,
9968  const double* bc_a_wm,
9969  const double* bc_a_mw,
9970  const double* bc_a_mm,
9971  const double* bc_grad_phi_w,
9972  const double* bc_grad_phi_m,
9973  const double* bc_u_w,
9974  const double* bc_u_m,
9975  const double* f_m, /*lambda_n K_s g(b rho_n-rho_w)*/
9976  const double* df_m_dw, /*dlambda_n K_s g(b rho_n-rho_w)*/
9977  const double* a_wm, /*lambda_w K_s*/
9978  const double* a_mw, /*lambda_n K_s*/
9979  const double* a_mm, /*lambda_t K_s*/
9980  const double* grad_phi_w, /*psi_c*/
9981  const double* grad_phi_m, /*psi_w - rho g . x*/
9982  const double* u_w, /*S_w*/
9983  const double* u_m, /*psi_w*/
9984  const double* penalty_w,
9985  const double* penalty_m,
9986  double * advectiveFlux_m,
9987  double * dadvectiveFlux_m_dw,
9988  double * diffusiveFlux_wm,
9989  double * diffusiveFlux_mw,
9990  double * diffusiveFlux_mm)
9991 {
9992  int ebNE,ebN,I,k,m,nnz_wm=rowptr_wm[nSpace],nnz_mw=rowptr_mw[nSpace],nnz_mm=rowptr_mm[nSpace];
9993  double diffusiveFlux_I=0.0,penaltyFlux = 0.0;
9994 
9995  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
9996  {
9997  ebN = exteriorElementBoundaries[ebNE];
9998  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
9999  {
10000  /*compute diffusive flux for first (w) equation (aq. mass
10001  balance for part of boundary where u_0 (i.e., S_w) is
10002  specified*/
10003  diffusiveFlux_wm[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
10004  advectiveFlux_m[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
10005  diffusiveFlux_mw[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
10006  diffusiveFlux_mm[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
10007 
10008  dadvectiveFlux_m_dw[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
10009  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
10010  {
10011  /*integration by parts term for diffusive flux*/
10012  for (I = 0; I < nSpace; I++)
10013  {
10014  diffusiveFlux_I = 0.0;
10015  for(m=rowptr_wm[I];m<rowptr_wm[I+1];m++)
10016  {
10017  diffusiveFlux_I -=
10018  a_wm[ebNE*nQuadraturePoints_elementBoundary*nnz_wm+
10019  k*nnz_wm+
10020  m]
10021  *
10022  grad_phi_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10023  k*nSpace +
10024  colind_wm[m]];
10025  }
10026  diffusiveFlux_wm[ebNE*nQuadraturePoints_elementBoundary+k] +=
10027  diffusiveFlux_I
10028  *
10029  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10030  k*nSpace+
10031  I];
10032  }/*I, a_wm grad phi_m term */
10033  /*boundary penalty term*/
10034  penaltyFlux =
10035  penalty_w[ebNE*nQuadraturePoints_elementBoundary + k]
10036  *
10037  (u_w[ebNE*nQuadraturePoints_elementBoundary + k]
10038  -
10039  bc_u_w[ebNE*nQuadraturePoints_elementBoundary + k]);
10040  diffusiveFlux_wm[ebNE*nQuadraturePoints_elementBoundary +k] +=
10041  penaltyFlux;
10042  }/*u_w boundary*/
10043  if(isDOFBoundary_um[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
10044  {
10045  /*just evaluate the 'advective flux term for the mixture equation
10046  using the internal value since gravity term actually depends on
10047  u_w = S_w and not u_m = psi_w (unless it's compressible)*/
10048  for (I = 0; I < nSpace; I++)
10049  {
10050  advectiveFlux_m[ebNE*nQuadraturePoints_elementBoundary + k] +=
10051  f_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10052  k*nSpace +
10053  I]
10054  *
10055  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10056  k*nSpace +
10057  I];
10058  /*basic fc_ff class doesn't have compressibility*/
10059 /* dadvectiveFlux_m_dm[ebNE*nQuadraturePoints_elementBoundary + k] += */
10060 /* df_m_dm[ebNE*nQuadraturePoints_elementBoundary*nSpace + */
10061 /* k*nSpace + */
10062 /* I] */
10063 /* * */
10064 /* n[ebNE*nQuadraturePoints_elementBoundary*nSpace + */
10065 /* k*nSpace + */
10066 /* I]; */
10067  dadvectiveFlux_m_dw[ebNE*nQuadraturePoints_elementBoundary + k] +=
10068  df_m_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10069  k*nSpace +
10070  I]
10071  *
10072  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10073  k*nSpace +
10074  I];
10075 
10076  }/*calculation of advective flux*/
10077  /*integration by parts term for diffusive flux wrt phi_w = psi_c*/
10078  for (I = 0; I < nSpace; I++)
10079  {
10080  diffusiveFlux_I = 0.0;
10081  for(m=rowptr_mw[I];m<rowptr_mw[I+1];m++)
10082  {
10083  diffusiveFlux_I -=
10084  a_mw[ebNE*nQuadraturePoints_elementBoundary*nnz_mw+
10085  k*nnz_mw+
10086  m]
10087  *
10088  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10089  k*nSpace +
10090  colind_mw[m]];
10091  }/*J*/
10092  diffusiveFlux_mw[ebNE*nQuadraturePoints_elementBoundary + k] +=
10093  diffusiveFlux_I
10094  *
10095  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10096  k*nSpace +
10097  I];
10098  }/*I, a_mw grad phi_w term */
10099  /*integration by parts term for diffusive flux wrt phi_m = psi_w*/
10100  for (I = 0; I < nSpace; I++)
10101  {
10102  diffusiveFlux_I = 0.0;
10103  for(m=rowptr_mm[I];m<rowptr_mm[I+1];m++)
10104  {
10105  diffusiveFlux_I -=
10106  a_mm[ebNE*nQuadraturePoints_elementBoundary*nnz_mm+
10107  k*nnz_mm+
10108  m]
10109  *
10110  grad_phi_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10111  k*nSpace +
10112  colind_mm[m]];
10113  }/*J*/
10114  diffusiveFlux_mm[ebNE*nQuadraturePoints_elementBoundary + k] +=
10115  diffusiveFlux_I
10116  *
10117  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10118  k*nSpace +
10119  I];
10120  }/*I, a_mw grad phi_w term */
10121  /*boundary penalty term*/
10122  penaltyFlux =
10123  penalty_m[ebNE*nQuadraturePoints_elementBoundary + k]
10124  *
10125  (u_m[ebNE*nQuadraturePoints_elementBoundary + k]
10126  -
10127  bc_u_m[ebNE*nQuadraturePoints_elementBoundary + k]);
10128  diffusiveFlux_mm[ebNE*nQuadraturePoints_elementBoundary +k] +=
10129  penaltyFlux;
10130  }/*um boundary*/
10131  }/*k*/
10132  }/*ebNE*/
10133 }
10134 
10136  int nQuadraturePoints_elementBoundary,
10137  int nSpace,
10138  int nDOF_trial_element,
10139  const int* l2g, /*for now assumes both solution spaces are the same!*/
10140  const int* exteriorElementBoundaries,
10141  const int* elementBoundaryElements,
10142  const int* elementBoundaryLocalElementBoundaries,
10143  const int* isDOFBoundary_uw,
10144  const int* isDOFBoundary_um,
10145  const double* n,
10146  const double* f_m, /*lambda_n K_s g(b rho_n-rho_w)*/
10147  const double* df_m_dw, /*dlambda_n K_s g(b rho_n-rho_w)*/
10148  const double* a_wm, /*lambda_w K_s*/
10149  const double* da_wm_dw, /* a' wrt S_w*/
10150  const double* da_wm_dm, /* a' wrt psi_w*/
10151  const double* a_mw, /*lambda_n K_s*/
10152  const double* da_mw_dw, /* a' wrt S_w*/
10153  const double* da_mw_dm, /* a' wrt psi_w*/
10154  const double* a_mm, /*lambda_t K_s*/
10155  const double* da_mm_dw, /* a' wrt S_w*/
10156  const double* da_mm_dm, /* a' wrt psi_w*/
10157  const double* grad_phi_w, /*psi_c*/
10158  const double* grad_phi_m, /*psi_w - rho g . x*/
10159  const double* dphi_w_w, /*\pd{psi_c}{S_w} */
10160  const double* dphi_w_m, /*\pd{psi_c}{psi_w}= 0 */
10161  const double* dphi_m_w, /*\pd{phi_w}{S_w} = 0 */
10162  const double* dphi_m_m, /*\pd{phi_w}{psi_w} = 1 - drho/dpsi_w g . x */
10163  const double* u_w, /*S_w*/
10164  const double* u_m, /*psi_w*/
10165  const double* v, /*trial functions, assumed in same space*/
10166  const double* grad_v, /*trial function gradients, assumed in same space*/
10167  const double* penalty_w,
10168  const double* penalty_m,
10169  double * fluxJacobian_ww,
10170  double * fluxJacobian_wm,
10171  double * fluxJacobian_mw,
10172  double * fluxJacobian_mm)
10173 {
10174  int ebNE,ebN,eN_global,j,j_global,I,J,k,nSpace2=nSpace*nSpace;
10175  double Jacobian_w,Jacobian_m,
10176  diffusiveVelocityComponent_I_Jacobian_w,
10177  diffusiveVelocityComponent_I_Jacobian_m,
10178  diffusiveVelocityComponent_I_Jacobian2_wm,
10179  diffusiveVelocityComponent_I_Jacobian2_ww,
10180  diffusiveVelocityComponent_I_Jacobian2_mw,
10181  diffusiveVelocityComponent_I_Jacobian2_mm;
10182 
10183  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
10184  {
10185  ebN = exteriorElementBoundaries[ebNE];
10186  eN_global = elementBoundaryElements[ebN*2 + 0];
10187  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
10188  {
10189  /*compute derivative of diffusive flux for first (w) equation (aq. mass
10190  balance for part of boundary where u_0 (i.e., S_w) is
10191  specified
10192  */
10193 
10194  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary + k] == 1)
10195  {
10196  /*NOTE! assuming u_w, u_m in the same space and nodal interpolant for potential*/
10197 
10198  for (j = 0; j < nDOF_trial_element; j++)
10199  {
10200  Jacobian_w = 0.; /*derivative wrt u_w = S_w */
10201  Jacobian_m = 0.; /*derivative wrt u_m = psi_w */
10202  j_global = l2g[eN_global*nDOF_trial_element + j];/*assuming same space for both*/
10203  for (I = 0; I < nSpace; I++)
10204  {
10205  diffusiveVelocityComponent_I_Jacobian_w = 0.0;
10206  diffusiveVelocityComponent_I_Jacobian_m = 0.0;
10207  diffusiveVelocityComponent_I_Jacobian2_mw = 0.0;
10208  diffusiveVelocityComponent_I_Jacobian2_mm = 0.0;
10209  for (J = 0; J < nSpace; J++)
10210  {
10211  /*only a_wm potential here*/
10212  diffusiveVelocityComponent_I_Jacobian_w -=
10213  da_wm_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10214  k*nSpace2 +
10215  I*nSpace +
10216  J]
10217  *
10218  grad_phi_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10219  k*nSpace +
10220  J];
10221  diffusiveVelocityComponent_I_Jacobian_m -=
10222  da_wm_dm[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10223  k*nSpace2 +
10224  I*nSpace +
10225  J]
10226  *
10227  grad_phi_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10228  k*nSpace +
10229  J];
10230 
10231  diffusiveVelocityComponent_I_Jacobian2_mw -=
10232  a_wm[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10233  k*nSpace2 +
10234  I*nSpace +
10235  J]
10236  * /*should be grad_v_m in general I believe*/
10237  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
10238  k*nDOF_trial_element*nSpace+
10239  j*nSpace+
10240  J];
10241  /*identical for now*/
10242  diffusiveVelocityComponent_I_Jacobian2_mm -=
10243  a_wm[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10244  k*nSpace2 +
10245  I*nSpace +
10246  J]
10247  * /*should be grad_v_m in general I believe*/
10248  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
10249  k*nDOF_trial_element*nSpace+
10250  j*nSpace+
10251  J];
10252 
10253  }/*J loop*/
10254  Jacobian_w +=
10255  diffusiveVelocityComponent_I_Jacobian_w
10256  */*should be v_w*/
10257  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10258  k*nDOF_trial_element +
10259  j]
10260  *
10261  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10262  k*nSpace +
10263  I];
10264  Jacobian_w +=
10265  diffusiveVelocityComponent_I_Jacobian2_mw
10266  *
10267  dphi_m_w[j_global]
10268  *
10269  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10270  k*nSpace +
10271  I];
10272  Jacobian_m +=
10273  diffusiveVelocityComponent_I_Jacobian_m
10274  */*should be v_m*/
10275  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10276  k*nDOF_trial_element +
10277  j]
10278  *
10279  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10280  k*nSpace +
10281  I];
10282  Jacobian_m +=
10283  diffusiveVelocityComponent_I_Jacobian2_mm
10284  *
10285  dphi_m_m[j_global]
10286  *
10287  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10288  k*nSpace +
10289  I];
10290  }/*I loop */
10291  /*only diagonal gets penalty term*/
10292  Jacobian_w +=
10293  penalty_w[ebNE*nQuadraturePoints_elementBoundary+k]
10294  * /*should be v_w*/
10295  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
10296  k*nDOF_trial_element+
10297  j];
10298  fluxJacobian_ww[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10299  k*nDOF_trial_element +
10300  j] +=
10301  Jacobian_w;
10302  fluxJacobian_wm[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10303  k*nDOF_trial_element +
10304  j] +=
10305  Jacobian_m;
10306  }/* j local dof loop*/
10307  }/*u_w dof boundary loop*/
10308  if (isDOFBoundary_um[ebNE*nQuadraturePoints_elementBoundary + k] == 1)
10309  {
10310  /*NOTE! assuming u_w, u_m in the same space and nodal interpolant for potential*/
10311 
10312  for (j = 0; j < nDOF_trial_element; j++)
10313  {
10314  Jacobian_w = 0.; /*derivative wrt u_w = S_w */
10315  Jacobian_m = 0.; /*derivative wrt u_m = psi_w */
10316  j_global = l2g[eN_global*nDOF_trial_element + j];/*assuming same space for both*/
10317  for (I = 0; I < nSpace; I++)
10318  {
10319  diffusiveVelocityComponent_I_Jacobian_w = 0.0;
10320  diffusiveVelocityComponent_I_Jacobian_m = 0.0;
10321  diffusiveVelocityComponent_I_Jacobian2_wm = 0.0;
10322  diffusiveVelocityComponent_I_Jacobian2_ww = 0.0;
10323  diffusiveVelocityComponent_I_Jacobian2_mw = 0.0;
10324  diffusiveVelocityComponent_I_Jacobian2_mm = 0.0;
10325  for (J = 0; J < nSpace; J++)
10326  {
10327  /*mw potential*/
10328  diffusiveVelocityComponent_I_Jacobian_w -=
10329  da_mw_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10330  k*nSpace2 +
10331  I*nSpace +
10332  J]
10333  *
10334  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10335  k*nSpace +
10336  J];
10337  diffusiveVelocityComponent_I_Jacobian_m -=
10338  da_mw_dm[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10339  k*nSpace2 +
10340  I*nSpace +
10341  J]
10342  *
10343  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10344  k*nSpace +
10345  J];
10346  /*mm potential*/
10347  diffusiveVelocityComponent_I_Jacobian_w -=
10348  da_mm_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10349  k*nSpace2 +
10350  I*nSpace +
10351  J]
10352  *
10353  grad_phi_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10354  k*nSpace +
10355  J];
10356  diffusiveVelocityComponent_I_Jacobian_m -=
10357  da_mm_dm[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10358  k*nSpace2 +
10359  I*nSpace +
10360  J]
10361  *
10362  grad_phi_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10363  k*nSpace +
10364  J];
10365 
10366  /*mw potential*/
10367  diffusiveVelocityComponent_I_Jacobian2_ww -=
10368  a_mw[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10369  k*nSpace2 +
10370  I*nSpace +
10371  J]
10372  * /*should be grad_v_w in general I believe*/
10373  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
10374  k*nDOF_trial_element*nSpace+
10375  j*nSpace+
10376  J];
10377  /*identical for now*/
10378  diffusiveVelocityComponent_I_Jacobian2_wm -=
10379  a_mw[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10380  k*nSpace2 +
10381  I*nSpace +
10382  J]
10383  * /*should be grad_v_m in general I believe*/
10384  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
10385  k*nDOF_trial_element*nSpace+
10386  j*nSpace+
10387  J];
10388 
10389  /*mm potential*/
10390  diffusiveVelocityComponent_I_Jacobian2_mw -=
10391  a_mm[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10392  k*nSpace2 +
10393  I*nSpace +
10394  J]
10395  * /*should be grad_v_w in general I believe*/
10396  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
10397  k*nDOF_trial_element*nSpace+
10398  j*nSpace+
10399  J];
10400  /*identical for now*/
10401  diffusiveVelocityComponent_I_Jacobian2_mm -=
10402  a_mm[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10403  k*nSpace2 +
10404  I*nSpace +
10405  J]
10406  * /*should be grad_v_m in general I believe*/
10407  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
10408  k*nDOF_trial_element*nSpace+
10409  j*nSpace+
10410  J];
10411 
10412  }/*J loop*/
10413  Jacobian_w +=
10414  diffusiveVelocityComponent_I_Jacobian_w
10415  */*should be v_w*/
10416  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10417  k*nDOF_trial_element +
10418  j]
10419  *
10420  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10421  k*nSpace +
10422  I];
10423  Jacobian_w +=
10424  diffusiveVelocityComponent_I_Jacobian2_ww
10425  *
10426  dphi_w_w[j_global]
10427  *
10428  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10429  k*nSpace +
10430  I];
10431  Jacobian_w +=
10432  diffusiveVelocityComponent_I_Jacobian2_mw
10433  *
10434  dphi_m_w[j_global]
10435  *
10436  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10437  k*nSpace +
10438  I];
10439 
10440  Jacobian_m +=
10441  diffusiveVelocityComponent_I_Jacobian_m
10442  */*should be v_m*/
10443  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10444  k*nDOF_trial_element +
10445  j]
10446  *
10447  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10448  k*nSpace +
10449  I];
10450  Jacobian_m +=
10451  diffusiveVelocityComponent_I_Jacobian2_wm
10452  *
10453  dphi_w_m[j_global]
10454  *
10455  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10456  k*nSpace +
10457  I];
10458  Jacobian_m +=
10459  diffusiveVelocityComponent_I_Jacobian2_mm
10460  *
10461  dphi_m_m[j_global]
10462  *
10463  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10464  k*nSpace +
10465  I];
10466  }/*I loop */
10467  /*only diagonal gets penalty term*/
10468  Jacobian_m +=
10469  penalty_m[ebNE*nQuadraturePoints_elementBoundary+k]
10470  * /*should be v_w*/
10471  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
10472  k*nDOF_trial_element+
10473  j];
10474  fluxJacobian_mw[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10475  k*nDOF_trial_element +
10476  j] +=
10477  Jacobian_w;
10478  fluxJacobian_mm[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10479  k*nDOF_trial_element +
10480  j] +=
10481  Jacobian_m;
10482  }/* j local dof loop*/
10483  }/*u_w dof boundary loop*/
10484 
10485  }/*k*/
10486  }/*ebNE*/
10487 
10488 }
10489 
10491  int nQuadraturePoints_elementBoundary,
10492  int nSpace,
10493  int nDOF_trial_element,
10494  int* rowptr_wm,
10495  int* colind_wm,
10496  int* rowptr_mw,
10497  int* colind_mw,
10498  int* rowptr_mm,
10499  int* colind_mm,
10500  const int* l2g, /*for now assumes both solution spaces are the same!*/
10501  const int* exteriorElementBoundaries,
10502  const int* elementBoundaryElements,
10503  const int* elementBoundaryLocalElementBoundaries,
10504  const int* isDOFBoundary_uw,
10505  const int* isDOFBoundary_um,
10506  const double* n,
10507  const double* f_m, /*lambda_n K_s g(b rho_n-rho_w)*/
10508  const double* df_m_dw, /*dlambda_n K_s g(b rho_n-rho_w)*/
10509  const double* a_wm, /*lambda_w K_s*/
10510  const double* da_wm_dw, /* a' wrt S_w*/
10511  const double* da_wm_dm, /* a' wrt psi_w*/
10512  const double* a_mw, /*lambda_n K_s*/
10513  const double* da_mw_dw, /* a' wrt S_w*/
10514  const double* da_mw_dm, /* a' wrt psi_w*/
10515  const double* a_mm, /*lambda_t K_s*/
10516  const double* da_mm_dw, /* a' wrt S_w*/
10517  const double* da_mm_dm, /* a' wrt psi_w*/
10518  const double* grad_phi_w, /*psi_c*/
10519  const double* grad_phi_m, /*psi_w - rho g . x*/
10520  const double* dphi_w_w, /*\pd{psi_c}{S_w} */
10521  const double* dphi_w_m, /*\pd{psi_c}{psi_w}= 0 */
10522  const double* dphi_m_w, /*\pd{phi_w}{S_w} = 0 */
10523  const double* dphi_m_m, /*\pd{phi_w}{psi_w} = 1 - drho/dpsi_w g . x */
10524  const double* u_w, /*S_w*/
10525  const double* u_m, /*psi_w*/
10526  const double* v, /*trial functions, assumed in same space*/
10527  const double* grad_v, /*trial function gradients, assumed in same space*/
10528  const double* penalty_w,
10529  const double* penalty_m,
10530  double * fluxJacobian_ww,
10531  double * fluxJacobian_wm,
10532  double * fluxJacobian_mw,
10533  double * fluxJacobian_mm)
10534 {
10535  int ebNE,ebN,eN_global,j,j_global,I,k,m,nnz_wm=rowptr_wm[nSpace],nnz_mw=rowptr_mw[nSpace],nnz_mm=rowptr_mm[nSpace];
10536  double Jacobian_w,Jacobian_m,
10537  diffusiveVelocityComponent_I_Jacobian_w,
10538  diffusiveVelocityComponent_I_Jacobian_m,
10539  diffusiveVelocityComponent_I_Jacobian2_wm,
10540  diffusiveVelocityComponent_I_Jacobian2_ww,
10541  diffusiveVelocityComponent_I_Jacobian2_mw,
10542  diffusiveVelocityComponent_I_Jacobian2_mm;
10543 
10544  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
10545  {
10546  ebN = exteriorElementBoundaries[ebNE];
10547  eN_global = elementBoundaryElements[ebN*2 + 0];
10548  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
10549  {
10550  /*compute derivative of diffusive flux for first (w) equation (aq. mass
10551  balance for part of boundary where u_0 (i.e., S_w) is
10552  specified
10553  */
10554 
10555  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary + k] == 1)
10556  {
10557  /*NOTE! assuming u_w, u_m in the same space and nodal interpolant for potential*/
10558 
10559  for (j = 0; j < nDOF_trial_element; j++)
10560  {
10561  Jacobian_w = 0.; /*derivative wrt u_w = S_w */
10562  Jacobian_m = 0.; /*derivative wrt u_m = psi_w */
10563  j_global = l2g[eN_global*nDOF_trial_element + j];/*assuming same space for both*/
10564  for (I = 0; I < nSpace; I++)
10565  {
10566  diffusiveVelocityComponent_I_Jacobian_w = 0.0;
10567  diffusiveVelocityComponent_I_Jacobian_m = 0.0;
10568  diffusiveVelocityComponent_I_Jacobian2_mw = 0.0;
10569  diffusiveVelocityComponent_I_Jacobian2_mm = 0.0;
10570  for(m=rowptr_wm[I];m<rowptr_wm[I+1];m++)
10571  {
10572  /*only a_wm potential here*/
10573  diffusiveVelocityComponent_I_Jacobian_w -=
10574  da_wm_dw[ebNE*nQuadraturePoints_elementBoundary*nnz_wm+
10575  k*nnz_wm+
10576  m]
10577  *
10578  grad_phi_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10579  k*nSpace +
10580  colind_wm[m]];
10581  diffusiveVelocityComponent_I_Jacobian_m -=
10582  da_wm_dm[ebNE*nQuadraturePoints_elementBoundary*nnz_wm+
10583  k*nnz_wm+
10584  m]
10585  *
10586  grad_phi_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10587  k*nSpace +
10588  colind_wm[m]];
10589 
10590  diffusiveVelocityComponent_I_Jacobian2_mw -=
10591  a_wm[ebNE*nQuadraturePoints_elementBoundary*nnz_wm+
10592  k*nnz_wm+
10593  m]
10594  * /*should be grad_v_m in general I believe*/
10595  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
10596  k*nDOF_trial_element*nSpace+
10597  j*nSpace+
10598  colind_wm[m]];
10599  /*identical for now*/
10600  diffusiveVelocityComponent_I_Jacobian2_mm -=
10601  a_wm[ebNE*nQuadraturePoints_elementBoundary*nnz_wm+
10602  k*nnz_wm+
10603  m]
10604  * /*should be grad_v_m in general I believe*/
10605  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
10606  k*nDOF_trial_element*nSpace+
10607  j*nSpace+
10608  colind_wm[m]];
10609 
10610  }/*J loop*/
10611  Jacobian_w +=
10612  diffusiveVelocityComponent_I_Jacobian_w
10613  */*should be v_w*/
10614  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10615  k*nDOF_trial_element +
10616  j]
10617  *
10618  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10619  k*nSpace +
10620  I];
10621  Jacobian_w +=
10622  diffusiveVelocityComponent_I_Jacobian2_mw
10623  *
10624  dphi_m_w[j_global]
10625  *
10626  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10627  k*nSpace +
10628  I];
10629  Jacobian_m +=
10630  diffusiveVelocityComponent_I_Jacobian_m
10631  */*should be v_m*/
10632  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10633  k*nDOF_trial_element +
10634  j]
10635  *
10636  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10637  k*nSpace +
10638  I];
10639  Jacobian_m +=
10640  diffusiveVelocityComponent_I_Jacobian2_mm
10641  *
10642  dphi_m_m[j_global]
10643  *
10644  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10645  k*nSpace +
10646  I];
10647  }/*I loop */
10648  /*only diagonal gets penalty term*/
10649  Jacobian_w +=
10650  penalty_w[ebNE*nQuadraturePoints_elementBoundary+k]
10651  * /*should be v_w*/
10652  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
10653  k*nDOF_trial_element+
10654  j];
10655  fluxJacobian_ww[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10656  k*nDOF_trial_element +
10657  j] +=
10658  Jacobian_w;
10659  fluxJacobian_wm[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10660  k*nDOF_trial_element +
10661  j] +=
10662  Jacobian_m;
10663  }/* j local dof loop*/
10664  }/*u_w dof boundary loop*/
10665  if (isDOFBoundary_um[ebNE*nQuadraturePoints_elementBoundary + k] == 1)
10666  {
10667  /*NOTE! assuming u_w, u_m in the same space and nodal interpolant for potential*/
10668 
10669  for (j = 0; j < nDOF_trial_element; j++)
10670  {
10671  Jacobian_w = 0.; /*derivative wrt u_w = S_w */
10672  Jacobian_m = 0.; /*derivative wrt u_m = psi_w */
10673  j_global = l2g[eN_global*nDOF_trial_element + j];/*assuming same space for both*/
10674  for (I = 0; I < nSpace; I++)
10675  {
10676  diffusiveVelocityComponent_I_Jacobian_w = 0.0;
10677  diffusiveVelocityComponent_I_Jacobian_m = 0.0;
10678  diffusiveVelocityComponent_I_Jacobian2_wm = 0.0;
10679  diffusiveVelocityComponent_I_Jacobian2_ww = 0.0;
10680  diffusiveVelocityComponent_I_Jacobian2_mw = 0.0;
10681  diffusiveVelocityComponent_I_Jacobian2_mm = 0.0;
10682  for (m=rowptr_mw[I];m<rowptr_mw[I+1];m++)
10683  {
10684  /*mw potential*/
10685  diffusiveVelocityComponent_I_Jacobian_w -=
10686  da_mw_dw[ebNE*nQuadraturePoints_elementBoundary*nnz_mw +
10687  k*nnz_mw +
10688  m]
10689  *
10690  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10691  k*nSpace +
10692  colind_mw[m]];
10693  diffusiveVelocityComponent_I_Jacobian_m -=
10694  da_mw_dm[ebNE*nQuadraturePoints_elementBoundary*nnz_mw +
10695  k*nnz_mw +
10696  m]
10697  *
10698  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10699  k*nSpace +
10700  colind_mw[m]];
10701  /*mm potential*/
10702  diffusiveVelocityComponent_I_Jacobian_w -=
10703  da_mm_dw[ebNE*nQuadraturePoints_elementBoundary*nnz_mw +
10704  k*nnz_mw +
10705  m]
10706  *
10707  grad_phi_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10708  k*nSpace +
10709  colind_mw[m]];
10710  diffusiveVelocityComponent_I_Jacobian_m -=
10711  da_mm_dm[ebNE*nQuadraturePoints_elementBoundary*nnz_mw +
10712  k*nnz_mw +
10713  m]
10714  *
10715  grad_phi_m[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10716  k*nSpace +
10717  colind_mw[m]];
10718 
10719  /*mw potential*/
10720  diffusiveVelocityComponent_I_Jacobian2_ww -=
10721  a_mw[ebNE*nQuadraturePoints_elementBoundary*nnz_mw +
10722  k*nnz_mw +
10723  m]
10724  * /*should be grad_v_w in general I believe*/
10725  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
10726  k*nDOF_trial_element*nSpace+
10727  j*nSpace+
10728  colind_mw[m]];
10729  /*identical for now*/
10730  diffusiveVelocityComponent_I_Jacobian2_wm -=
10731  a_mw[ebNE*nQuadraturePoints_elementBoundary*nnz_mw +
10732  k*nnz_mw +
10733  m]
10734  * /*should be grad_v_m in general I believe*/
10735  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
10736  k*nDOF_trial_element*nSpace+
10737  j*nSpace+
10738  colind_mw[m]];
10739 
10740  /*mm potential*/
10741  diffusiveVelocityComponent_I_Jacobian2_mw -=
10742  a_mm[ebNE*nQuadraturePoints_elementBoundary*nnz_mw +
10743  k*nnz_mw +
10744  m]
10745  * /*should be grad_v_w in general I believe*/
10746  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
10747  k*nDOF_trial_element*nSpace+
10748  j*nSpace+
10749  colind_mw[m]];
10750  /*identical for now*/
10751  diffusiveVelocityComponent_I_Jacobian2_mm -=
10752  a_mm[ebNE*nQuadraturePoints_elementBoundary*nnz_mw +
10753  k*nnz_mw +
10754  m]
10755  * /*should be grad_v_m in general I believe*/
10756  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
10757  k*nDOF_trial_element*nSpace+
10758  j*nSpace+
10759  colind_mw[m]];
10760 
10761  }/*J loop*/
10762  Jacobian_w +=
10763  diffusiveVelocityComponent_I_Jacobian_w
10764  */*should be v_w*/
10765  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10766  k*nDOF_trial_element +
10767  j]
10768  *
10769  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10770  k*nSpace +
10771  I];
10772  Jacobian_w +=
10773  diffusiveVelocityComponent_I_Jacobian2_ww
10774  *
10775  dphi_w_w[j_global]
10776  *
10777  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10778  k*nSpace +
10779  I];
10780  Jacobian_w +=
10781  diffusiveVelocityComponent_I_Jacobian2_mw
10782  *
10783  dphi_m_w[j_global]
10784  *
10785  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10786  k*nSpace +
10787  I];
10788 
10789  Jacobian_m +=
10790  diffusiveVelocityComponent_I_Jacobian_m
10791  */*should be v_m*/
10792  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10793  k*nDOF_trial_element +
10794  j]
10795  *
10796  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10797  k*nSpace +
10798  I];
10799  Jacobian_m +=
10800  diffusiveVelocityComponent_I_Jacobian2_wm
10801  *
10802  dphi_w_m[j_global]
10803  *
10804  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10805  k*nSpace +
10806  I];
10807  Jacobian_m +=
10808  diffusiveVelocityComponent_I_Jacobian2_mm
10809  *
10810  dphi_m_m[j_global]
10811  *
10812  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10813  k*nSpace +
10814  I];
10815  }/*I loop */
10816  /*only diagonal gets penalty term*/
10817  Jacobian_m +=
10818  penalty_m[ebNE*nQuadraturePoints_elementBoundary+k]
10819  * /*should be v_w*/
10820  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
10821  k*nDOF_trial_element+
10822  j];
10823  fluxJacobian_mw[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10824  k*nDOF_trial_element +
10825  j] +=
10826  Jacobian_w;
10827  fluxJacobian_mm[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
10828  k*nDOF_trial_element +
10829  j] +=
10830  Jacobian_m;
10831  }/* j local dof loop*/
10832  }/*u_w dof boundary loop*/
10833 
10834  }/*k*/
10835  }/*ebNE*/
10836 
10837 }
10838 
10839 void calculateGlobalExteriorNumericalFluxDarcyFC(int nExteriorElementBoundaries_global,
10840  int nQuadraturePoints_elementBoundary,
10841  int nSpace,
10842  const int* exteriorElementBoundaries,
10843  const int* elementBoundaryElements,
10844  const int* elementBoundaryLocalElementBoundaries,
10845  const int* isDOFBoundary_uw,/*1 set bc for s_w*/
10846  const int* isDOFBoundary_un,/*1 set bc for psi_w,
10847  2 set bc for psi_n*/
10848  int fluxBoundaryFlag_uw, /*0 no flow, 1 outflow*/
10849  int fluxBoundaryFlag_un,
10850  const double* n,
10851  const double* bc_a_ww,
10852  const double* bc_a_nn,
10853  const double* bc_grad_phi_w,
10854  const double* bc_grad_phi_n,
10855  const double* bc_s_w,
10856  const double* bc_psi_w,
10857  const double* bc_psi_n,
10858  const double* a_ww, /*lambda_w K_s*/
10859  const double* a_nn, /*lambda_n K_s*/
10860  const double* grad_phi_w, /*psi_w - rho_w g . x*/
10861  const double* grad_phi_n, /*psi_c + psi_w - rho_n g . x*/
10862  const double* s_w, /*s_w*/
10863  const double* psi_w, /*psi_w*/
10864  const double* psi_n,
10865  const double* penalty_w,
10866  const double* penalty_n,
10867  double * diffusiveFlux_ww,
10868  double * diffusiveFlux_nn)
10869 {
10870  int ebNE,ebN,I,J,k,nSpace2=nSpace*nSpace;
10871  double diffusiveFlux_I=0.0,penaltyFlux = 0.0,potential_gradient_w=0.0,potential_gradient_n=0.0;
10872 
10873  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
10874  {
10875  ebN = exteriorElementBoundaries[ebNE];
10876  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
10877  {
10878  /*compute diffusive flux for first (w) equation (aq. mass
10879  balance for part of boundary where u_0 (i.e., S_w) is
10880  specified*/
10881  diffusiveFlux_ww[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
10882  diffusiveFlux_nn[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
10883  /*allow outflow where potential gradient is out even if not Dirichlet,
10884  do not include K_s in calculation for now*/
10885  potential_gradient_w = 0.0; potential_gradient_n = 0.0;
10886  for (I=0; I < nSpace; I++)
10887  {
10888  potential_gradient_w += grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10889  k*nSpace + I]
10890  *
10891  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10892  k*nSpace+
10893  I];
10894  potential_gradient_n += grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10895  k*nSpace + I]
10896  *
10897  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10898  k*nSpace+
10899  I];
10900  }
10901  /*only allow s_w setting here?*/
10902  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary+k] == 1 || (potential_gradient_w > 0.0 && fluxBoundaryFlag_uw == 1))
10903  {
10904  /*integration by parts term for diffusive flux wrt phi_w = psi_w - rho_w g . x*/
10905  for (I = 0; I < nSpace; I++)
10906  {
10907  diffusiveFlux_I = 0.0;
10908  for (J = 0; J < nSpace; J++)
10909  {
10910  diffusiveFlux_I -=
10911  a_ww[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10912  k*nSpace2 +
10913  I*nSpace +
10914  J]
10915  *
10916  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10917  k*nSpace +
10918  J];
10919  }
10920  diffusiveFlux_ww[ebNE*nQuadraturePoints_elementBoundary+k] +=
10921  diffusiveFlux_I
10922  *
10923  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10924  k*nSpace+
10925  I];
10926  }/*I, a_wm grad phi_m term */
10927  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
10928  {
10929  /*boundary penalty term*/
10930  penaltyFlux =
10931  penalty_w[ebNE*nQuadraturePoints_elementBoundary + k]
10932  *
10933  (s_w[ebNE*nQuadraturePoints_elementBoundary + k]
10934  -
10935  bc_s_w[ebNE*nQuadraturePoints_elementBoundary + k]);
10936  diffusiveFlux_ww[ebNE*nQuadraturePoints_elementBoundary +k] +=
10937  penaltyFlux;
10938  }
10939  }/*s_w boundary*/
10940  /*1 set psi_w, 2 set psi_n*/
10941  if(isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary+k] >= 1 || (potential_gradient_n > 0.0 && fluxBoundaryFlag_un == 1))
10942  {
10943  /*integration by parts term for diffusive flux wrt phi_n = psi_c + psi_w - rho_n g . x*/
10944  for (I = 0; I < nSpace; I++)
10945  {
10946  diffusiveFlux_I = 0.0;
10947  for (J = 0; J < nSpace; J++)
10948  {
10949  diffusiveFlux_I -=
10950  a_nn[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
10951  k*nSpace2 +
10952  I*nSpace +
10953  J]
10954  *
10955  grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10956  k*nSpace +
10957  J];
10958  }/*J*/
10959  diffusiveFlux_nn[ebNE*nQuadraturePoints_elementBoundary + k] +=
10960  diffusiveFlux_I
10961  *
10962  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
10963  k*nSpace +
10964  I];
10965  }/*I, a_mw grad phi_n term */
10966  /*boundary penalty term*/
10967  penaltyFlux = 0.0;
10968  if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary+k] == 2)
10969  {
10970  penaltyFlux =
10971  penalty_n[ebNE*nQuadraturePoints_elementBoundary + k]
10972  *
10973  (psi_n[ebNE*nQuadraturePoints_elementBoundary + k]
10974  -
10975  bc_psi_n[ebNE*nQuadraturePoints_elementBoundary + k]);
10976  }
10977  else if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
10978  {
10979  penaltyFlux =
10980  penalty_n[ebNE*nQuadraturePoints_elementBoundary + k]
10981  *
10982  (psi_w[ebNE*nQuadraturePoints_elementBoundary + k]
10983  -
10984  bc_psi_w[ebNE*nQuadraturePoints_elementBoundary + k]);
10985 
10986  }
10987  diffusiveFlux_nn[ebNE*nQuadraturePoints_elementBoundary +k] +=
10988  penaltyFlux;
10989  }/*um boundary*/
10990  }/*k*/
10991  }/*ebNE*/
10992 }
10993 
10994 void calculateGlobalExteriorNumericalFluxDarcyFC_sd(int nExteriorElementBoundaries_global,
10995  int nQuadraturePoints_elementBoundary,
10996  int nSpace,
10997  int* rowptr_ww,
10998  int* colind_ww,
10999  int* rowptr_nn,
11000  int* colind_nn,
11001  const int* exteriorElementBoundaries,
11002  const int* elementBoundaryElements,
11003  const int* elementBoundaryLocalElementBoundaries,
11004  const int* isDOFBoundary_uw,/*1 set bc for s_w*/
11005  const int* isDOFBoundary_un,/*1 set bc for psi_w,
11006  2 set bc for psi_n*/
11007  int fluxBoundaryFlag_uw, /*0 no flow, 1 outflow*/
11008  int fluxBoundaryFlag_un,
11009  const double* n,
11010  const double* bc_a_ww,
11011  const double* bc_a_nn,
11012  const double* bc_grad_phi_w,
11013  const double* bc_grad_phi_n,
11014  const double* bc_s_w,
11015  const double* bc_psi_w,
11016  const double* bc_psi_n,
11017  const double* a_ww, /*lambda_w K_s*/
11018  const double* a_nn, /*lambda_n K_s*/
11019  const double* grad_phi_w, /*psi_w */
11020  const double* grad_phi_n, /*psi_c + psi_w */
11021  const double* s_w, /*s_w*/
11022  const double* psi_w, /*psi_w*/
11023  const double* psi_n,
11024  const double* penalty_w,
11025  const double* penalty_n,
11026  double * diffusiveFlux_ww,
11027  double * diffusiveFlux_nn)
11028 {
11029  int ebNE,ebN,I,k,m,nnz_ww=rowptr_ww[nSpace],nnz_nn=rowptr_nn[nSpace];
11030  double diffusiveFlux_I=0.0,penaltyFlux = 0.0,potential_gradient_w=0.0,potential_gradient_n=0.0;
11031  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
11032  {
11033  ebN = exteriorElementBoundaries[ebNE];
11034  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
11035  {
11036  /*compute diffusive flux for first (w) equation (aq. mass
11037  balance for part of boundary where u_0 (i.e., S_w) is
11038  specified*/
11039  diffusiveFlux_ww[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
11040  diffusiveFlux_nn[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
11041  /*allow outflow where potential gradient is out even if not Dirichlet,
11042  do not include K_s in calculation for now*/
11043  potential_gradient_w = 0.0; potential_gradient_n = 0.0;
11044  for (I=0; I < nSpace; I++)
11045  {
11046  potential_gradient_w += grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11047  k*nSpace + I]
11048  *
11049  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11050  k*nSpace+
11051  I];
11052  potential_gradient_n += grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11053  k*nSpace + I]
11054  *
11055  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11056  k*nSpace+
11057  I];
11058  }
11059 
11060  /*only allow s_w setting here?*/
11061  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary+k] == 1 || (potential_gradient_w > 0.0 && fluxBoundaryFlag_uw==1))
11062  {
11063  /*integration by parts term for diffusive flux wrt phi_w = psi_w */
11064  for (I = 0; I < nSpace; I++)
11065  {
11066  diffusiveFlux_I = 0.0;
11067  for(m=rowptr_ww[I];m<rowptr_ww[I+1];m++)
11068  {
11069  diffusiveFlux_I -=
11070  a_ww[ebNE*nQuadraturePoints_elementBoundary*nnz_ww +
11071  k*nnz_ww +
11072  m]
11073  *
11074  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11075  k*nSpace +
11076  colind_ww[m]];
11077  }
11078  diffusiveFlux_ww[ebNE*nQuadraturePoints_elementBoundary+k] +=
11079  diffusiveFlux_I
11080  *
11081  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11082  k*nSpace+
11083  I];
11084  }/*I, a_wm grad phi_m term */
11085  /*boundary penalty term*/
11086  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
11087  {
11088  penaltyFlux =
11089  penalty_w[ebNE*nQuadraturePoints_elementBoundary + k]
11090  *
11091  (s_w[ebNE*nQuadraturePoints_elementBoundary + k]
11092  -
11093  bc_s_w[ebNE*nQuadraturePoints_elementBoundary + k]);
11094  diffusiveFlux_ww[ebNE*nQuadraturePoints_elementBoundary +k] +=
11095  penaltyFlux;
11096  }
11097  }/*s_w boundary*/
11098  /*1 set psi_w, 2 set psi_n*/
11099  if(isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary+k] >= 1 || (potential_gradient_n > 0.0 && fluxBoundaryFlag_un==1))
11100  {
11101  /*integration by parts term for diffusive flux wrt phi_n = psi_c + psi_w */
11102  for (I = 0; I < nSpace; I++)
11103  {
11104  diffusiveFlux_I = 0.0;
11105  for(m=rowptr_nn[I];m<rowptr_nn[I+1];m++)
11106  {
11107  diffusiveFlux_I -=
11108  a_nn[ebNE*nQuadraturePoints_elementBoundary*nnz_nn +
11109  k*nnz_nn +
11110  m]
11111  *
11112  grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11113  k*nSpace +
11114  colind_nn[m]];
11115  }/*J*/
11116  diffusiveFlux_nn[ebNE*nQuadraturePoints_elementBoundary + k] +=
11117  diffusiveFlux_I
11118  *
11119  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11120  k*nSpace +
11121  I];
11122  }/*I, a_mw grad phi_n term */
11123  /*boundary penalty term*/
11124  penaltyFlux = 0.0;
11125  if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary+k] == 2)
11126  {
11127  penaltyFlux =
11128  penalty_n[ebNE*nQuadraturePoints_elementBoundary + k]
11129  *
11130  (psi_n[ebNE*nQuadraturePoints_elementBoundary + k]
11131  -
11132  bc_psi_n[ebNE*nQuadraturePoints_elementBoundary + k]);
11133  }
11134  else if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
11135  {
11136  penaltyFlux =
11137  penalty_n[ebNE*nQuadraturePoints_elementBoundary + k]
11138  *
11139  (psi_w[ebNE*nQuadraturePoints_elementBoundary + k]
11140  -
11141  bc_psi_w[ebNE*nQuadraturePoints_elementBoundary + k]);
11142 
11143  }
11144  diffusiveFlux_nn[ebNE*nQuadraturePoints_elementBoundary +k] +=
11145  penaltyFlux;
11146  }/*um boundary*/
11147  }/*k*/
11148  }/*ebNE*/
11149 }
11150 
11152  int nQuadraturePoints_elementBoundary,
11153  int nSpace,
11154  int nDOF_trial_element,
11155  const int* l2g, /*for now assumes both solution spaces are the same!*/
11156  const int* exteriorElementBoundaries,
11157  const int* elementBoundaryElements,
11158  const int* elementBoundaryLocalElementBoundaries,
11159  const int* isDOFBoundary_uw,/*1 set bc for s_w*/
11160  const int* isDOFBoundary_un,/*1 set bc for psi_w,
11161  2 set bc for psi_n*/
11162  int fluxBoundaryFlag_uw, /*0 no flow, 1 outflow*/
11163  int fluxBoundaryFlag_un,
11164  const double* n,
11165  const double* a_ww, /*lambda_w K_s*/
11166  const double* da_ww_dw, /* a' wrt S_w*/
11167  const double* da_ww_dn, /* a' wrt psi_w*/
11168  const double* a_nn, /*lambda_t K_s*/
11169  const double* da_nn_dw, /* a' wrt S_w*/
11170  const double* da_nn_dn, /* a' wrt psi_w*/
11171  const double* grad_phi_w, /*psi_w - rho_w g . x*/
11172  const double* grad_phi_n, /*psi_n + psi_w - rho_n g . x*/
11173  const double* dphi_w_w, /*\pd{phi_w}{S_w} = 0 */
11174  const double* dphi_w_n, /*\pd{phi_w}{psi_w}= 1 - drho_w g.x */
11175  const double* dphi_n_w, /*\pd{phi_n}{S_w} = \od{psi_c}{S_w} */
11176  const double* dphi_n_n, /*\pd{phi_n}{psi_w} = 1 - drho_n/dpsi_w g . x */
11177  const double* s_w, /*S_w*/
11178  const double* psi_w, /*psi_w*/
11179  const double* psi_n,
11180  const double* dpsi_n_dsw,
11181  const double* dpsi_n_dpsiw,
11182  const double* v, /*trial functions, assumed in same space*/
11183  const double* grad_v, /*trial function gradients, assumed in same space*/
11184  const double* penalty_w,
11185  const double* penalty_n,
11186  double * fluxJacobian_ww,
11187  double * fluxJacobian_wn,
11188  double * fluxJacobian_nw,
11189  double * fluxJacobian_nn)
11190 {
11191  int ebNE,ebN,eN_global,j,j_global,I,J,k,nSpace2=nSpace*nSpace;
11192  double Jacobian_w,Jacobian_n,
11193  diffusiveVelocityComponent_I_Jacobian_w,
11194  diffusiveVelocityComponent_I_Jacobian_n,
11195  diffusiveVelocityComponent_I_Jacobian2_wn,
11196  diffusiveVelocityComponent_I_Jacobian2_ww,
11197  diffusiveVelocityComponent_I_Jacobian2_nw,
11198  diffusiveVelocityComponent_I_Jacobian2_nn;
11199  double potential_gradient_w=0.0,potential_gradient_n=0.0;
11200 
11201  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
11202  {
11203  ebN = exteriorElementBoundaries[ebNE];
11204  eN_global = elementBoundaryElements[ebN*2 + 0];
11205  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
11206  {
11207  /*compute derivative of diffusive flux for first (w) equation (aq. mass
11208  balance for part of boundary where u_0 (i.e., S_w) is
11209  specified
11210  */
11211  /*allow outflow where potential gradient is out even if not Dirichlet,
11212  do not include K_s in calculation for now*/
11213  potential_gradient_w = 0.0; potential_gradient_n = 0.0;
11214  for (I=0; I < nSpace; I++)
11215  {
11216  potential_gradient_w += grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11217  k*nSpace + I]
11218  *
11219  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11220  k*nSpace+
11221  I];
11222  potential_gradient_n += grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11223  k*nSpace + I]
11224  *
11225  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11226  k*nSpace+
11227  I];
11228  }
11229  /*only allow setting s_w for this equation*/
11230  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary + k] == 1 || (potential_gradient_w > 0.0 && fluxBoundaryFlag_uw==1))
11231  {
11232  /*NOTE! assuming u_w, u_n in the same space and nodal interpolant for potential*/
11233 
11234  for (j = 0; j < nDOF_trial_element; j++)
11235  {
11236  Jacobian_w = 0.; /*derivative wrt u_w = S_w */
11237  Jacobian_n = 0.; /*derivative wrt u_n = psi_w */
11238  j_global = l2g[eN_global*nDOF_trial_element + j];/*assuming same space for both*/
11239  for (I = 0; I < nSpace; I++)
11240  {
11241  diffusiveVelocityComponent_I_Jacobian_w = 0.0;
11242  diffusiveVelocityComponent_I_Jacobian_n = 0.0;
11243  diffusiveVelocityComponent_I_Jacobian2_wn = 0.0;
11244  diffusiveVelocityComponent_I_Jacobian2_ww = 0.0;
11245  for (J = 0; J < nSpace; J++)
11246  {
11247  /*only a_ww potential here*/
11248  diffusiveVelocityComponent_I_Jacobian_w -=
11249  da_ww_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
11250  k*nSpace2 +
11251  I*nSpace +
11252  J]
11253  *
11254  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11255  k*nSpace +
11256  J];
11257  diffusiveVelocityComponent_I_Jacobian_n -=
11258  da_ww_dn[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
11259  k*nSpace2 +
11260  I*nSpace +
11261  J]
11262  *
11263  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11264  k*nSpace +
11265  J];
11266 
11267  diffusiveVelocityComponent_I_Jacobian2_ww -=
11268  a_ww[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
11269  k*nSpace2 +
11270  I*nSpace +
11271  J]
11272  * /*should be grad_v_w in general I believe*/
11273  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
11274  k*nDOF_trial_element*nSpace+
11275  j*nSpace+
11276  J];
11277  /*identical for now*/
11278  diffusiveVelocityComponent_I_Jacobian2_wn -=
11279  a_ww[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
11280  k*nSpace2 +
11281  I*nSpace +
11282  J]
11283  * /*should be grad_v_w in general I believe*/
11284  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
11285  k*nDOF_trial_element*nSpace+
11286  j*nSpace+
11287  J];
11288 
11289  }/*J loop*/
11290  Jacobian_w +=
11291  diffusiveVelocityComponent_I_Jacobian_w
11292  */*should be v_w*/
11293  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11294  k*nDOF_trial_element +
11295  j]
11296  *
11297  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11298  k*nSpace +
11299  I];
11300  Jacobian_w +=
11301  diffusiveVelocityComponent_I_Jacobian2_ww
11302  *
11303  dphi_w_w[j_global]
11304  *
11305  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11306  k*nSpace +
11307  I];
11308  Jacobian_n +=
11309  diffusiveVelocityComponent_I_Jacobian_n
11310  */*should be v_n*/
11311  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11312  k*nDOF_trial_element +
11313  j]
11314  *
11315  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11316  k*nSpace +
11317  I];
11318  Jacobian_n +=
11319  diffusiveVelocityComponent_I_Jacobian2_wn
11320  *
11321  dphi_w_n[j_global]
11322  *
11323  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11324  k*nSpace +
11325  I];
11326  }/*I loop */
11327  /*only diagonal gets penalty term*/
11328  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
11329  {
11330  Jacobian_w +=
11331  penalty_w[ebNE*nQuadraturePoints_elementBoundary+k]
11332  * /*should be v_w*/
11333  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
11334  k*nDOF_trial_element+
11335  j];
11336  }
11337  fluxJacobian_ww[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11338  k*nDOF_trial_element +
11339  j] +=
11340  Jacobian_w;
11341  fluxJacobian_wn[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11342  k*nDOF_trial_element +
11343  j] +=
11344  Jacobian_n;
11345  }/* j local dof loop*/
11346  }/*u_w dof boundary loop*/
11347  /*setting psi_w = 1, or psi_n = 2*/
11348  if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary + k] >= 1 || (potential_gradient_n > 0.0 && fluxBoundaryFlag_un==1))
11349  {
11350  /*NOTE! assuming u_w, u_m in the same space and nodal interpolant for potential*/
11351 
11352  for (j = 0; j < nDOF_trial_element; j++)
11353  {
11354  Jacobian_w = 0.; /*derivative wrt u_w = S_w */
11355  Jacobian_n = 0.; /*derivative wrt u_n = psi_w */
11356  j_global = l2g[eN_global*nDOF_trial_element + j];/*assuming same space for both*/
11357  for (I = 0; I < nSpace; I++)
11358  {
11359  diffusiveVelocityComponent_I_Jacobian_w = 0.0;
11360  diffusiveVelocityComponent_I_Jacobian_n = 0.0;
11361  diffusiveVelocityComponent_I_Jacobian2_nw = 0.0;
11362  diffusiveVelocityComponent_I_Jacobian2_nn = 0.0;
11363  for (J = 0; J < nSpace; J++)
11364  {
11365  /*nn potential*/
11366  diffusiveVelocityComponent_I_Jacobian_w -=
11367  da_nn_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
11368  k*nSpace2 +
11369  I*nSpace +
11370  J]
11371  *
11372  grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11373  k*nSpace +
11374  J];
11375  diffusiveVelocityComponent_I_Jacobian_n -=
11376  da_nn_dn[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
11377  k*nSpace2 +
11378  I*nSpace +
11379  J]
11380  *
11381  grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11382  k*nSpace +
11383  J];
11384 
11385  /*nn potential*/
11386  diffusiveVelocityComponent_I_Jacobian2_nw -=
11387  a_nn[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
11388  k*nSpace2 +
11389  I*nSpace +
11390  J]
11391  * /*should be grad_v_w in general I believe*/
11392  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
11393  k*nDOF_trial_element*nSpace+
11394  j*nSpace+
11395  J];
11396  /*identical for now*/
11397  diffusiveVelocityComponent_I_Jacobian2_nn -=
11398  a_nn[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
11399  k*nSpace2 +
11400  I*nSpace +
11401  J]
11402  * /*should be grad_v_m in general I believe*/
11403  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
11404  k*nDOF_trial_element*nSpace+
11405  j*nSpace+
11406  J];
11407 
11408  }/*J loop*/
11409  Jacobian_w +=
11410  diffusiveVelocityComponent_I_Jacobian_w
11411  */*should be v_w*/
11412  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11413  k*nDOF_trial_element +
11414  j]
11415  *
11416  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11417  k*nSpace +
11418  I];
11419  Jacobian_w +=
11420  diffusiveVelocityComponent_I_Jacobian2_nw
11421  *
11422  dphi_n_w[j_global]
11423  *
11424  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11425  k*nSpace +
11426  I];
11427 
11428  Jacobian_n +=
11429  diffusiveVelocityComponent_I_Jacobian_n
11430  */*should be v_n*/
11431  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11432  k*nDOF_trial_element +
11433  j]
11434  *
11435  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11436  k*nSpace +
11437  I];
11438  Jacobian_n +=
11439  diffusiveVelocityComponent_I_Jacobian2_nn
11440  *
11441  dphi_n_n[j_global]
11442  *
11443  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11444  k*nSpace +
11445  I];
11446  }/*I loop */
11447 
11448  if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary + k] == 2)
11449  {
11450  /*dependency of psi_n on psi_w*/
11451  Jacobian_n +=
11452  penalty_n[ebNE*nQuadraturePoints_elementBoundary+k]
11453  * /*should be v_n*/
11454  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
11455  k*nDOF_trial_element+
11456  j]
11457  *
11458  dpsi_n_dpsiw[ebNE*nQuadraturePoints_elementBoundary + k];
11459  /*dependency of psi_n on s_w */
11460  Jacobian_w +=
11461  penalty_n[ebNE*nQuadraturePoints_elementBoundary+k]
11462  * /*should be v_w*/
11463  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
11464  k*nDOF_trial_element+
11465  j]
11466  *
11467  dpsi_n_dsw[ebNE*nQuadraturePoints_elementBoundary + k];
11468  }
11469  else if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary + k] == 1)
11470  {
11471  /*only diagonal gets penalty term*/
11472  Jacobian_n +=
11473  penalty_n[ebNE*nQuadraturePoints_elementBoundary+k]
11474  * /*should be v_w*/
11475  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
11476  k*nDOF_trial_element+
11477  j];
11478 
11479  }
11480  fluxJacobian_nw[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11481  k*nDOF_trial_element +
11482  j] +=
11483  Jacobian_w;
11484  fluxJacobian_nn[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11485  k*nDOF_trial_element +
11486  j] +=
11487  Jacobian_n;
11488  }/* j local dof loop*/
11489  }/*u_w dof boundary loop*/
11490 
11491  }/*k*/
11492  }/*ebNE*/
11493 
11494 }
11495 
11497  int nQuadraturePoints_elementBoundary,
11498  int nSpace,
11499  int nDOF_trial_element,
11500  int* rowptr_ww,
11501  int* colind_ww,
11502  int* rowptr_nn,
11503  int* colind_nn,
11504  const int* l2g, /*for now assumes both solution spaces are the same!*/
11505  const int* exteriorElementBoundaries,
11506  const int* elementBoundaryElements,
11507  const int* elementBoundaryLocalElementBoundaries,
11508  const int* isDOFBoundary_uw,/*1 set bc for s_w*/
11509  const int* isDOFBoundary_un,/*1 set bc for psi_w,
11510  2 set bc for psi_n*/
11511  int fluxBoundaryFlag_uw, /*0 no flow, 1 outflow*/
11512  int fluxBoundaryFlag_un,
11513  const double* n,
11514  const double* a_ww, /*lambda_w K_s*/
11515  const double* da_ww_dw, /* a' wrt S_w*/
11516  const double* da_ww_dn, /* a' wrt psi_w*/
11517  const double* a_nn, /*lambda_t K_s*/
11518  const double* da_nn_dw, /* a' wrt S_w*/
11519  const double* da_nn_dn, /* a' wrt psi_w*/
11520  const double* grad_phi_w, /*psi_w - rho_w g . x*/
11521  const double* grad_phi_n, /*psi_n + psi_w - rho_n g . x*/
11522  const double* dphi_w_w, /*\pd{phi_w}{S_w} = 0 */
11523  const double* dphi_w_n, /*\pd{phi_w}{psi_w}= 1 - drho_w g.x */
11524  const double* dphi_n_w, /*\pd{phi_n}{S_w} = \od{psi_c}{S_w} */
11525  const double* dphi_n_n, /*\pd{phi_n}{psi_w} = 1 - drho_n/dpsi_w g . x */
11526  const double* s_w, /*S_w*/
11527  const double* psi_w, /*psi_w*/
11528  const double* psi_n,
11529  const double* dpsi_n_dsw,
11530  const double* dpsi_n_dpsiw,
11531  const double* v, /*trial functions, assumed in same space*/
11532  const double* grad_v, /*trial function gradients, assumed in same space*/
11533  const double* penalty_w,
11534  const double* penalty_n,
11535  double * fluxJacobian_ww,
11536  double * fluxJacobian_wn,
11537  double * fluxJacobian_nw,
11538  double * fluxJacobian_nn)
11539 {
11540  int ebNE,ebN,eN_global,j,j_global,I,k,m,nnz_ww=rowptr_ww[nSpace],nnz_nn=rowptr_nn[nSpace];
11541  double Jacobian_w,Jacobian_n,
11542  diffusiveVelocityComponent_I_Jacobian_w,
11543  diffusiveVelocityComponent_I_Jacobian_n,
11544  diffusiveVelocityComponent_I_Jacobian2_wn,
11545  diffusiveVelocityComponent_I_Jacobian2_ww,
11546  diffusiveVelocityComponent_I_Jacobian2_nw,
11547  diffusiveVelocityComponent_I_Jacobian2_nn;
11548  double potential_gradient_w=0.0,potential_gradient_n=0.0;
11549  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
11550  {
11551  ebN = exteriorElementBoundaries[ebNE];
11552  eN_global = elementBoundaryElements[ebN*2 + 0];
11553 
11554  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
11555  {
11556  /*compute derivative of diffusive flux for first (w) equation (aq. mass
11557  balance for part of boundary where u_0 (i.e., S_w) is
11558  specified
11559  */
11560  /*allow outflow where potential gradient is out even if not Dirichlet,
11561  do not include K_s in calculation for now*/
11562  potential_gradient_w = 0.0; potential_gradient_n = 0.0;
11563  for (I=0; I < nSpace; I++)
11564  {
11565  potential_gradient_w += grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11566  k*nSpace + I]
11567  *
11568  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11569  k*nSpace+
11570  I];
11571  potential_gradient_n += grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11572  k*nSpace + I]
11573  *
11574  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11575  k*nSpace+
11576  I];
11577  }
11578 
11579  /*only allow setting s_w for this equation*/
11580  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary + k] == 1 || (potential_gradient_w > 0.0 && fluxBoundaryFlag_uw==1))
11581  {
11582  /*NOTE! assuming u_w, u_n in the same space and nodal interpolant for potential*/
11583 
11584  for (j = 0; j < nDOF_trial_element; j++)
11585  {
11586  Jacobian_w = 0.; /*derivative wrt u_w = S_w */
11587  Jacobian_n = 0.; /*derivative wrt u_n = psi_w */
11588  j_global = l2g[eN_global*nDOF_trial_element + j];/*assuming same space for both*/
11589  for (I = 0; I < nSpace; I++)
11590  {
11591  diffusiveVelocityComponent_I_Jacobian_w = 0.0;
11592  diffusiveVelocityComponent_I_Jacobian_n = 0.0;
11593  diffusiveVelocityComponent_I_Jacobian2_wn = 0.0;
11594  diffusiveVelocityComponent_I_Jacobian2_ww = 0.0;
11595  for (m=rowptr_ww[I];m<rowptr_ww[I+1];m++)
11596  {
11597  /*only a_ww potential here*/
11598  diffusiveVelocityComponent_I_Jacobian_w -=
11599  da_ww_dw[ebNE*nQuadraturePoints_elementBoundary*nnz_ww +
11600  k*nnz_ww +
11601  m]
11602  *
11603  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11604  k*nSpace +
11605  colind_ww[m]];
11606  diffusiveVelocityComponent_I_Jacobian_n -=
11607  da_ww_dn[ebNE*nQuadraturePoints_elementBoundary*nnz_ww +
11608  k*nnz_ww +
11609  m]
11610  *
11611  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11612  k*nSpace +
11613  colind_ww[m]];
11614 
11615  diffusiveVelocityComponent_I_Jacobian2_ww -=
11616  a_ww[ebNE*nQuadraturePoints_elementBoundary*nnz_ww +
11617  k*nnz_ww +
11618  m]
11619  * /*should be grad_v_w in general I believe*/
11620  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
11621  k*nDOF_trial_element*nSpace+
11622  j*nSpace+
11623  colind_ww[m]];
11624  /*identical for now*/
11625  diffusiveVelocityComponent_I_Jacobian2_wn -=
11626  a_ww[ebNE*nQuadraturePoints_elementBoundary*nnz_ww +
11627  k*nnz_ww +
11628  m]
11629  * /*should be grad_v_w in general I believe*/
11630  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
11631  k*nDOF_trial_element*nSpace+
11632  j*nSpace+
11633  colind_ww[m]];
11634 
11635  }/*J loop*/
11636  Jacobian_w +=
11637  diffusiveVelocityComponent_I_Jacobian_w
11638  */*should be v_w*/
11639  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11640  k*nDOF_trial_element +
11641  j]
11642  *
11643  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11644  k*nSpace +
11645  I];
11646  Jacobian_w +=
11647  diffusiveVelocityComponent_I_Jacobian2_ww
11648  *
11649  dphi_w_w[j_global]
11650  *
11651  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11652  k*nSpace +
11653  I];
11654  Jacobian_n +=
11655  diffusiveVelocityComponent_I_Jacobian_n
11656  */*should be v_n*/
11657  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11658  k*nDOF_trial_element +
11659  j]
11660  *
11661  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11662  k*nSpace +
11663  I];
11664  Jacobian_n +=
11665  diffusiveVelocityComponent_I_Jacobian2_wn
11666  *
11667  dphi_w_n[j_global]
11668  *
11669  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11670  k*nSpace +
11671  I];
11672  }/*I loop */
11673  /*only diagonal gets penalty term*/
11674  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
11675  {
11676  Jacobian_w +=
11677  penalty_w[ebNE*nQuadraturePoints_elementBoundary+k]
11678  * /*should be v_w*/
11679  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
11680  k*nDOF_trial_element+
11681  j];
11682  }
11683  fluxJacobian_ww[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11684  k*nDOF_trial_element +
11685  j] +=
11686  Jacobian_w;
11687  fluxJacobian_wn[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11688  k*nDOF_trial_element +
11689  j] +=
11690  Jacobian_n;
11691  }/* j local dof loop*/
11692  }/*u_w dof boundary loop*/
11693  /*setting psi_w = 1, or psi_n = 2*/
11694  if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary + k] >= 1 || (potential_gradient_n > 0.0 && fluxBoundaryFlag_un==1))
11695  {
11696  /*NOTE! assuming u_w, u_m in the same space and nodal interpolant for potential*/
11697 
11698  for (j = 0; j < nDOF_trial_element; j++)
11699  {
11700  Jacobian_w = 0.; /*derivative wrt u_w = S_w */
11701  Jacobian_n = 0.; /*derivative wrt u_n = psi_w */
11702  j_global = l2g[eN_global*nDOF_trial_element + j];/*assuming same space for both*/
11703  for (I = 0; I < nSpace; I++)
11704  {
11705  diffusiveVelocityComponent_I_Jacobian_w = 0.0;
11706  diffusiveVelocityComponent_I_Jacobian_n = 0.0;
11707  diffusiveVelocityComponent_I_Jacobian2_nw = 0.0;
11708  diffusiveVelocityComponent_I_Jacobian2_nn = 0.0;
11709  for (m=rowptr_nn[I];m<rowptr_nn[I+1];m++)
11710  {
11711  /*nn potential*/
11712  diffusiveVelocityComponent_I_Jacobian_w -=
11713  da_nn_dw[ebNE*nQuadraturePoints_elementBoundary*nnz_nn +
11714  k*nnz_nn +
11715  m]
11716  *
11717  grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11718  k*nSpace +
11719  colind_nn[m]];
11720  diffusiveVelocityComponent_I_Jacobian_n -=
11721  da_nn_dn[ebNE*nQuadraturePoints_elementBoundary*nnz_nn +
11722  k*nnz_nn +
11723  m]
11724  *
11725  grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11726  k*nSpace +
11727  colind_nn[m]];
11728 
11729  /*nn potential*/
11730  diffusiveVelocityComponent_I_Jacobian2_nw -=
11731  a_nn[ebNE*nQuadraturePoints_elementBoundary*nnz_nn +
11732  k*nnz_nn +
11733  m]
11734  * /*should be grad_v_w in general I believe*/
11735  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
11736  k*nDOF_trial_element*nSpace+
11737  j*nSpace+
11738  colind_nn[m]];
11739  /*identical for now*/
11740  diffusiveVelocityComponent_I_Jacobian2_nn -=
11741  a_nn[ebNE*nQuadraturePoints_elementBoundary*nnz_nn +
11742  k*nnz_nn +
11743  m]
11744  * /*should be grad_v_m in general I believe*/
11745  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
11746  k*nDOF_trial_element*nSpace+
11747  j*nSpace+
11748  colind_nn[m]];
11749 
11750  }/*J loop*/
11751  Jacobian_w +=
11752  diffusiveVelocityComponent_I_Jacobian_w
11753  */*should be v_w*/
11754  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11755  k*nDOF_trial_element +
11756  j]
11757  *
11758  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11759  k*nSpace +
11760  I];
11761  Jacobian_w +=
11762  diffusiveVelocityComponent_I_Jacobian2_nw
11763  *
11764  dphi_n_w[j_global]
11765  *
11766  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11767  k*nSpace +
11768  I];
11769 
11770  Jacobian_n +=
11771  diffusiveVelocityComponent_I_Jacobian_n
11772  */*should be v_n*/
11773  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11774  k*nDOF_trial_element +
11775  j]
11776  *
11777  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11778  k*nSpace +
11779  I];
11780  Jacobian_n +=
11781  diffusiveVelocityComponent_I_Jacobian2_nn
11782  *
11783  dphi_n_n[j_global]
11784  *
11785  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
11786  k*nSpace +
11787  I];
11788  }/*I loop */
11789 
11790  if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary + k] == 2)
11791  {
11792  /*dependency of psi_n on psi_w*/
11793  Jacobian_n +=
11794  penalty_n[ebNE*nQuadraturePoints_elementBoundary+k]
11795  * /*should be v_n*/
11796  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
11797  k*nDOF_trial_element+
11798  j]
11799  *
11800  dpsi_n_dpsiw[ebNE*nQuadraturePoints_elementBoundary + k];
11801  /*dependency of psi_n on s_w */
11802  Jacobian_w +=
11803  penalty_n[ebNE*nQuadraturePoints_elementBoundary+k]
11804  * /*should be v_w*/
11805  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
11806  k*nDOF_trial_element+
11807  j]
11808  *
11809  dpsi_n_dsw[ebNE*nQuadraturePoints_elementBoundary + k];
11810  }
11811  else if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary + k] == 1)
11812  {
11813  /*only diagonal gets penalty term*/
11814  Jacobian_n +=
11815  penalty_n[ebNE*nQuadraturePoints_elementBoundary+k]
11816  * /*should be v_w*/
11817  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
11818  k*nDOF_trial_element+
11819  j];
11820 
11821  }
11822  fluxJacobian_nw[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11823  k*nDOF_trial_element +
11824  j] +=
11825  Jacobian_w;
11826  fluxJacobian_nn[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
11827  k*nDOF_trial_element +
11828  j] +=
11829  Jacobian_n;
11830  }/* j local dof loop*/
11831  }/*u_w dof boundary loop*/
11832 
11833  }/*k*/
11834  }/*ebNE*/
11835 
11836 }
11837 
11842 void calculateGlobalExteriorNumericalAdvectiveFlux_DarcyFC(int nExteriorElementBoundaries_global,
11843  int nQuadraturePoints_elementBoundary,
11844  int nSpace,
11845  int* exteriorElementBoundaries,
11846  int* elementBoundaryElements,
11847  int* elementBoundaryLocalElementBoundaries,
11848  int *isDOFBoundary_sw,
11849  int *isDOFBoundary_psiw,
11850  double* n,
11851  double* bc_sw,
11852  double* bc_psiw,
11853  double* bc_fw,
11854  double* bc_dfw_dsw,
11855  double* bc_dfw_dpsiw,
11856  double* bc_fn,
11857  double* bc_dfn_dsw,
11858  double* bc_dfn_dpsiw,
11859  double* sw,
11860  double* psiw,
11861  double* fw,
11862  double* dfw_dsw,
11863  double* dfw_dpsiw,
11864  double* fn,
11865  double* dfn_dsw,
11866  double* dfn_dpsiw,
11867  double* fluxw,
11868  double* dfluxw_dsw,
11869  double* dfluxw_dpsiw,
11870  double* fluxn,
11871  double* dfluxn_dsw,
11872  double* dfluxn_dpsiw)
11873 {
11874  int ebNE,ebN,eN_global,k,J;
11875  double left_flux;
11876  double dflux_dsw_left,dflux_dpsiw_left;
11877  int enforceOutflow = 1;
11878  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
11879  {
11880  ebN = exteriorElementBoundaries[ebNE];
11881  eN_global = elementBoundaryElements[ebN*2+0];
11882  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
11883  {
11884  left_flux=0.0;
11885  dflux_dsw_left=0.0;
11886  dflux_dpsiw_left=0.0;
11887  for(J=0;J<nSpace;J++)
11888  {
11889  dflux_dsw_left +=
11890  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
11891  k*nSpace+
11892  J]
11893  *
11894  dfw_dsw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
11895  k*nSpace+
11896  J];
11897  dflux_dpsiw_left +=
11898  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
11899  k*nSpace+
11900  J]
11901  *
11902  dfw_dpsiw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
11903  k*nSpace+
11904  J];
11905 
11906  left_flux
11907  +=
11908  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
11909  k*nSpace+
11910  J]
11911  *
11912  fw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
11913  k*nSpace+
11914  J];
11915  }
11916  if (!enforceOutflow || isDOFBoundary_sw[ebNE*nQuadraturePoints_elementBoundary+k] || left_flux >= 0.0)
11917  {
11918  fluxw[ebNE*nQuadraturePoints_elementBoundary+
11919  k] = left_flux;
11920  dfluxw_dsw[ebNE*nQuadraturePoints_elementBoundary+
11921  k] = dflux_dsw_left;
11922  dfluxw_dpsiw[ebNE*nQuadraturePoints_elementBoundary+
11923  k] = dflux_dpsiw_left;
11924  }
11925  else
11926  {
11927  fluxw[ebNE*nQuadraturePoints_elementBoundary+
11928  k] = 0.0;
11929  dfluxw_dsw[ebNE*nQuadraturePoints_elementBoundary+
11930  k] = 0.0;
11931  dfluxw_dpsiw[ebNE*nQuadraturePoints_elementBoundary+
11932  k] = 0.0;
11933 
11934  }
11935  /*now repeat for non-wetting phase*/
11936  left_flux=0.0;
11937  dflux_dsw_left=0.0;
11938  dflux_dpsiw_left=0.0;
11939  for(J=0;J<nSpace;J++)
11940  {
11941  dflux_dsw_left +=
11942  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
11943  k*nSpace+
11944  J]
11945  *
11946  dfn_dsw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
11947  k*nSpace+
11948  J];
11949  dflux_dpsiw_left +=
11950  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
11951  k*nSpace+
11952  J]
11953  *
11954  dfn_dpsiw[ebNE*nQuadraturePoints_elementBoundary*nSpace+
11955  k*nSpace+
11956  J];
11957  left_flux
11958  +=
11959  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
11960  k*nSpace+
11961  J]
11962  *
11963  fn[ebNE*nQuadraturePoints_elementBoundary*nSpace+
11964  k*nSpace+
11965  J];
11966  }
11967  if (!enforceOutflow || isDOFBoundary_psiw[ebNE*nQuadraturePoints_elementBoundary+k] || left_flux >= 0.0)
11968  {
11969  fluxn[ebNE*nQuadraturePoints_elementBoundary+
11970  k] = left_flux;
11971  dfluxn_dsw[ebNE*nQuadraturePoints_elementBoundary+
11972  k] = dflux_dsw_left;
11973  dfluxn_dpsiw[ebNE*nQuadraturePoints_elementBoundary+
11974  k] = dflux_dpsiw_left;
11975  }
11976  else
11977  {
11978  fluxn[ebNE*nQuadraturePoints_elementBoundary+
11979  k] = 0.0;
11980  dfluxn_dsw[ebNE*nQuadraturePoints_elementBoundary+
11981  k] = 0.0;
11982  dfluxn_dpsiw[ebNE*nQuadraturePoints_elementBoundary+
11983  k] = 0.0;
11984 
11985  }
11986  }/*k*/
11987  }
11988 }
11989 
11990 
11991 /*begin FCPP exterior flux terms*/
11992 void calculateGlobalExteriorNumericalFluxDarcyFCPP(int nExteriorElementBoundaries_global,
11993  int nQuadraturePoints_elementBoundary,
11994  int nSpace,
11995  const int* exteriorElementBoundaries,
11996  const int* elementBoundaryElements,
11997  const int* elementBoundaryLocalElementBoundaries,
11998  const int* isDOFBoundary_uw,/*1 set bc for psi_w*/
11999  const int* isDOFBoundary_un,/*1 set bc for psi_c,
12000  2 set bc for psi_n*/
12001  int fluxBoundaryFlag_uw, /*0 no flow, 1 outflow*/
12002  int fluxBoundaryFlag_un,
12003  const double* n,
12004  const double* bc_a_ww,
12005  const double* bc_a_nn,
12006  const double* bc_grad_phi_w,
12007  const double* bc_grad_phi_n,
12008  const double* bc_psi_w,
12009  const double* bc_psi_c,
12010  const double* bc_psi_n,
12011  const double* a_ww, /*lambda_w K_s*/
12012  const double* a_nn, /*lambda_n K_s*/
12013  const double* grad_phi_w, /*psi_w - rho_w g . x*/
12014  const double* grad_phi_n, /*psi_c + psi_w - rho_n g . x*/
12015  const double* psi_w, /*psi_w*/
12016  const double* psi_c, /*psi_c*/
12017  const double* psi_n,
12018  const double* penalty_w,
12019  const double* penalty_n,
12020  double * diffusiveFlux_ww,
12021  double * diffusiveFlux_nn)
12022 {
12023  int ebNE,ebN,I,J,k,nSpace2=nSpace*nSpace;
12024  double diffusiveFlux_I=0.0,penaltyFlux = 0.0;
12025  double potential_gradient_w=0.0,potential_gradient_n=0.0;
12026 
12027  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
12028  {
12029  ebN = exteriorElementBoundaries[ebNE];
12030  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
12031  {
12032  /*compute diffusive flux for first (w) equation (aq. mass
12033  balance for part of boundary where u_0 (i.e., S_w) is
12034  specified*/
12035  diffusiveFlux_ww[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
12036  diffusiveFlux_nn[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
12037  /*allow outflow where potential gradient is out even if not Dirichlet,
12038  do not include K_s in calculation for now*/
12039  potential_gradient_w = 0.0; potential_gradient_n = 0.0;
12040  for (I=0; I < nSpace; I++)
12041  {
12042  potential_gradient_w += grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12043  k*nSpace + I]
12044  *
12045  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12046  k*nSpace+
12047  I];
12048  potential_gradient_n += grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12049  k*nSpace + I]
12050  *
12051  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12052  k*nSpace+
12053  I];
12054  }
12055 
12056  /*only allow psi_w setting here?*/
12057  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary+k] == 1 || (potential_gradient_w > 0.0 && fluxBoundaryFlag_uw == 1))
12058  {
12059  /*integration by parts term for diffusive flux wrt phi_w = psi_w - rho_w g . x*/
12060  for (I = 0; I < nSpace; I++)
12061  {
12062  diffusiveFlux_I = 0.0;
12063  for (J = 0; J < nSpace; J++)
12064  {
12065  diffusiveFlux_I -=
12066  a_ww[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
12067  k*nSpace2 +
12068  I*nSpace +
12069  J]
12070  *
12071  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12072  k*nSpace +
12073  J];
12074  }
12075  diffusiveFlux_ww[ebNE*nQuadraturePoints_elementBoundary+k] +=
12076  diffusiveFlux_I
12077  *
12078  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12079  k*nSpace+
12080  I];
12081  }/*I, a_wm grad phi_m term */
12082  /*boundary penalty term*/
12083  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
12084  {
12085  penaltyFlux =
12086  penalty_w[ebNE*nQuadraturePoints_elementBoundary + k]
12087  *
12088  (psi_w[ebNE*nQuadraturePoints_elementBoundary + k]
12089  -
12090  bc_psi_w[ebNE*nQuadraturePoints_elementBoundary + k]);
12091  diffusiveFlux_ww[ebNE*nQuadraturePoints_elementBoundary +k] +=
12092  penaltyFlux;
12093  }
12094  }/*psi_w boundary*/
12095  /*1 set psi_c, 2 set psi_n*/
12096  if(isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary+k] >= 1 || (potential_gradient_n > 0.0 && fluxBoundaryFlag_un == 1))
12097  {
12098  /*integration by parts term for diffusive flux wrt phi_n = psi_c + psi_w - rho_n g . x*/
12099  for (I = 0; I < nSpace; I++)
12100  {
12101  diffusiveFlux_I = 0.0;
12102  for (J = 0; J < nSpace; J++)
12103  {
12104  diffusiveFlux_I -=
12105  a_nn[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
12106  k*nSpace2 +
12107  I*nSpace +
12108  J]
12109  *
12110  grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12111  k*nSpace +
12112  J];
12113  }/*J*/
12114  diffusiveFlux_nn[ebNE*nQuadraturePoints_elementBoundary + k] +=
12115  diffusiveFlux_I
12116  *
12117  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12118  k*nSpace +
12119  I];
12120  }/*I, a_mw grad phi_n term */
12121  /*boundary penalty term*/
12122  penaltyFlux = 0.0;
12123  //need to enforce psi_c >= 0
12124  if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary+k] == 2)
12125  {
12126  penaltyFlux =
12127  penalty_n[ebNE*nQuadraturePoints_elementBoundary + k]
12128  *
12129  (psi_n[ebNE*nQuadraturePoints_elementBoundary + k]
12130  -
12131  bc_psi_n[ebNE*nQuadraturePoints_elementBoundary + k]);
12132  }
12133  else if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
12134  {
12135  penaltyFlux =
12136  penalty_n[ebNE*nQuadraturePoints_elementBoundary + k]
12137  *
12138  (psi_c[ebNE*nQuadraturePoints_elementBoundary + k]
12139  -
12140  bc_psi_c[ebNE*nQuadraturePoints_elementBoundary + k]);
12141 
12142  }
12143  diffusiveFlux_nn[ebNE*nQuadraturePoints_elementBoundary +k] +=
12144  penaltyFlux;
12145  }/*um boundary*/
12146  }/*k*/
12147  }/*ebNE*/
12148 }
12149 
12150 void calculateGlobalExteriorNumericalFluxDarcyFCPP_sd(int nExteriorElementBoundaries_global,
12151  int nQuadraturePoints_elementBoundary,
12152  int nSpace,
12153  int* rowptr_ww,
12154  int* colind_ww,
12155  int* rowptr_nn,
12156  int* colind_nn,
12157  const int* exteriorElementBoundaries,
12158  const int* elementBoundaryElements,
12159  const int* elementBoundaryLocalElementBoundaries,
12160  const int* isDOFBoundary_uw,/*1 set bc for psi_w*/
12161  const int* isDOFBoundary_un,/*1 set bc for psi_c,
12162  2 set bc for psi_n*/
12163  int fluxBoundaryFlag_uw, /*0 no flow, 1 outflow*/
12164  int fluxBoundaryFlag_un,
12165  const double* n,
12166  const double* bc_a_ww,
12167  const double* bc_a_nn,
12168  const double* bc_grad_phi_w,
12169  const double* bc_grad_phi_n,
12170  const double* bc_psi_w,
12171  const double* bc_psi_c,
12172  const double* bc_psi_n,
12173  const double* a_ww, /*lambda_w K_s*/
12174  const double* a_nn, /*lambda_n K_s*/
12175  const double* grad_phi_w, /*psi_w - rho_w g . x*/
12176  const double* grad_phi_n, /*psi_c + psi_w - rho_n g . x*/
12177  const double* psi_w, /*s_w*/
12178  const double* psi_c, /*psi_w*/
12179  const double* psi_n,
12180  const double* penalty_w,
12181  const double* penalty_n,
12182  double * diffusiveFlux_ww,
12183  double * diffusiveFlux_nn)
12184 {
12185  int ebNE,ebN,I,k,m,nnz_ww=rowptr_ww[nSpace],nnz_nn=rowptr_nn[nSpace];
12186  double diffusiveFlux_I=0.0,penaltyFlux = 0.0,potential_gradient_w=0.0,potential_gradient_n=0.0;
12187  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
12188  {
12189  ebN = exteriorElementBoundaries[ebNE];
12190  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
12191  {
12192  /*compute diffusive flux for first (w) equation (aq. mass
12193  balance for part of boundary where u_0 (i.e., S_w) is
12194  specified*/
12195  diffusiveFlux_ww[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
12196  diffusiveFlux_nn[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
12197  potential_gradient_w = 0.0; potential_gradient_n = 0.0;
12198  for (I=0; I < nSpace; I++)
12199  {
12200  potential_gradient_w += grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12201  k*nSpace + I]
12202  *
12203  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12204  k*nSpace+
12205  I];
12206  potential_gradient_n += grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12207  k*nSpace + I]
12208  *
12209  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12210  k*nSpace+
12211  I];
12212  }
12213  /*mwf hack
12214  potential_gradient_w = 0.0; potential_gradient_n = 0.0;
12215  */
12216  /*only allow psi_w setting here?*/
12217  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary+k] == 1 || (potential_gradient_w > 0.0 && fluxBoundaryFlag_uw == 1))
12218  {
12219  /*integration by parts term for diffusive flux wrt phi_w = psi_w - rho_w g . x*/
12220  for (I = 0; I < nSpace; I++)
12221  {
12222  diffusiveFlux_I = 0.0;
12223  for(m=rowptr_ww[I];m<rowptr_ww[I+1];m++)
12224  {
12225  diffusiveFlux_I -=
12226  a_ww[ebNE*nQuadraturePoints_elementBoundary*nnz_ww +
12227  k*nnz_ww +
12228  m]
12229  *
12230  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12231  k*nSpace +
12232  colind_ww[m]];
12233  }
12234  diffusiveFlux_ww[ebNE*nQuadraturePoints_elementBoundary+k] +=
12235  diffusiveFlux_I
12236  *
12237  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12238  k*nSpace+
12239  I];
12240  }/*I, a_wm grad phi_m term */
12241  /*boundary penalty term*/
12242  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
12243  {
12244  penaltyFlux =
12245  penalty_w[ebNE*nQuadraturePoints_elementBoundary + k]
12246  *
12247  (psi_w[ebNE*nQuadraturePoints_elementBoundary + k]
12248  -
12249  bc_psi_w[ebNE*nQuadraturePoints_elementBoundary + k]);
12250  diffusiveFlux_ww[ebNE*nQuadraturePoints_elementBoundary +k] +=
12251  penaltyFlux;
12252  }
12253  }/*psi_w boundary*/
12254  /*1 set psi_c, 2 set psi_n*/
12255  if(isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary+k] >= 1 || (potential_gradient_n > 0.0 && fluxBoundaryFlag_un == 1))
12256  {
12257  /*integration by parts term for diffusive flux wrt phi_n = psi_c + psi_w - rho_n g . x*/
12258  for (I = 0; I < nSpace; I++)
12259  {
12260  diffusiveFlux_I = 0.0;
12261  for(m=rowptr_nn[I];m<rowptr_nn[I+1];m++)
12262  {
12263  diffusiveFlux_I -=
12264  a_nn[ebNE*nQuadraturePoints_elementBoundary*nnz_nn +
12265  k*nnz_nn +
12266  m]
12267  *
12268  grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12269  k*nSpace +
12270  colind_nn[m]];
12271  }/*J*/
12272  diffusiveFlux_nn[ebNE*nQuadraturePoints_elementBoundary + k] +=
12273  diffusiveFlux_I
12274  *
12275  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12276  k*nSpace +
12277  I];
12278  }/*I, a_mw grad phi_n term */
12279  /*boundary penalty term*/
12280  penaltyFlux = 0.0;
12281  if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary+k] == 2)
12282  {
12283  penaltyFlux =
12284  penalty_n[ebNE*nQuadraturePoints_elementBoundary + k]
12285  *
12286  (psi_n[ebNE*nQuadraturePoints_elementBoundary + k]
12287  -
12288  bc_psi_n[ebNE*nQuadraturePoints_elementBoundary + k]);
12289  }
12290  else if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
12291  {
12292  penaltyFlux =
12293  penalty_n[ebNE*nQuadraturePoints_elementBoundary + k]
12294  *
12295  (psi_c[ebNE*nQuadraturePoints_elementBoundary + k]
12296  -
12297  bc_psi_c[ebNE*nQuadraturePoints_elementBoundary + k]);
12298 
12299  }
12300  diffusiveFlux_nn[ebNE*nQuadraturePoints_elementBoundary +k] +=
12301  penaltyFlux;
12302  }/*um boundary*/
12303  }/*k*/
12304  }/*ebNE*/
12305 }
12306 
12308  int nQuadraturePoints_elementBoundary,
12309  int nSpace,
12310  int nDOF_trial_element,
12311  const int* l2g, /*for now assumes both solution spaces are the same!*/
12312  const int* exteriorElementBoundaries,
12313  const int* elementBoundaryElements,
12314  const int* elementBoundaryLocalElementBoundaries,
12315  const int* isDOFBoundary_uw,/*1 set bc for psi_w*/
12316  const int* isDOFBoundary_un,/*1 set bc for psi_c,
12317  2 set bc for psi_n*/
12318  int fluxBoundaryFlag_uw, /*0 no flow, 1 outflow*/
12319  int fluxBoundaryFlag_un,
12320  const double* n,
12321  const double* a_ww, /*lambda_w K_s*/
12322  const double* da_ww_dw, /* a' wrt S_w*/
12323  const double* da_ww_dn, /* a' wrt psi_w*/
12324  const double* a_nn, /*lambda_t K_s*/
12325  const double* da_nn_dw, /* a' wrt S_w*/
12326  const double* da_nn_dn, /* a' wrt psi_w*/
12327  const double* grad_phi_w, /*psi_w - rho_w g . x*/
12328  const double* grad_phi_n, /*psi_n + psi_w - rho_n g . x*/
12329  const double* dphi_w_w, /*\pd{phi_w}{psi_w} = 1 */
12330  const double* dphi_w_n, /*\pd{phi_w}{psi_c}= 0 */
12331  const double* dphi_n_w, /*\pd{phi_n}{psi_w} = 1 */
12332  const double* dphi_n_n, /*\pd{phi_n}{psi_c} = 1 */
12333  const double* psi_w, /*psi_w*/
12334  const double* psi_c, /*psi_c*/
12335  const double* psi_n,
12336  const double* dpsi_n_dpsiw,
12337  const double* dpsi_n_dpsic,
12338  const double* v, /*trial functions, assumed in same space*/
12339  const double* grad_v, /*trial function gradients, assumed in same space*/
12340  const double* penalty_w,
12341  const double* penalty_n,
12342  double * fluxJacobian_ww,
12343  double * fluxJacobian_wn,
12344  double * fluxJacobian_nw,
12345  double * fluxJacobian_nn)
12346 {
12347  int ebNE,ebN,eN_global,j,j_global,I,J,k,nSpace2=nSpace*nSpace;
12348  double Jacobian_w,Jacobian_n,
12349  diffusiveVelocityComponent_I_Jacobian_w,
12350  diffusiveVelocityComponent_I_Jacobian_n,
12351  diffusiveVelocityComponent_I_Jacobian2_wn,
12352  diffusiveVelocityComponent_I_Jacobian2_ww,
12353  diffusiveVelocityComponent_I_Jacobian2_nw,
12354  diffusiveVelocityComponent_I_Jacobian2_nn;
12355  double potential_gradient_w=0.0,potential_gradient_n=0.0;
12356  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
12357  {
12358  ebN = exteriorElementBoundaries[ebNE];
12359  eN_global = elementBoundaryElements[ebN*2 + 0];
12360  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
12361  {
12362  /*compute derivative of diffusive flux for first (w) equation (aq. mass
12363  balance for part of boundary where u_0 (i.e., psi_w) is
12364  specified
12365  */
12366  /*allow outflow where potential gradient is out even if not Dirichlet,
12367  do not include K_s in calculation for now*/
12368  potential_gradient_w = 0.0; potential_gradient_n = 0.0;
12369  for (I=0; I < nSpace; I++)
12370  {
12371  potential_gradient_w += grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12372  k*nSpace + I]
12373  *
12374  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12375  k*nSpace+
12376  I];
12377  potential_gradient_n += grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12378  k*nSpace + I]
12379  *
12380  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12381  k*nSpace+
12382  I];
12383  }
12384  /*only allow setting psi_w for this equation*/
12385  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary + k] == 1 || (potential_gradient_w > 0.0 && fluxBoundaryFlag_uw == 1))
12386  {
12387  /*NOTE! assuming u_w, u_n in the same space and nodal interpolant for potential*/
12388 
12389  for (j = 0; j < nDOF_trial_element; j++)
12390  {
12391  Jacobian_w = 0.; /*derivative wrt u_w = S_w */
12392  Jacobian_n = 0.; /*derivative wrt u_n = psi_w */
12393  j_global = l2g[eN_global*nDOF_trial_element + j];/*assuming same space for both*/
12394  for (I = 0; I < nSpace; I++)
12395  {
12396  diffusiveVelocityComponent_I_Jacobian_w = 0.0;
12397  diffusiveVelocityComponent_I_Jacobian_n = 0.0;
12398  diffusiveVelocityComponent_I_Jacobian2_wn = 0.0;
12399  diffusiveVelocityComponent_I_Jacobian2_ww = 0.0;
12400  for (J = 0; J < nSpace; J++)
12401  {
12402  /*only a_ww potential here*/
12403  diffusiveVelocityComponent_I_Jacobian_w -=
12404  da_ww_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
12405  k*nSpace2 +
12406  I*nSpace +
12407  J]
12408  *
12409  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12410  k*nSpace +
12411  J];
12412  diffusiveVelocityComponent_I_Jacobian_n -=
12413  da_ww_dn[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
12414  k*nSpace2 +
12415  I*nSpace +
12416  J]
12417  *
12418  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12419  k*nSpace +
12420  J];
12421 
12422  diffusiveVelocityComponent_I_Jacobian2_ww -=
12423  a_ww[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
12424  k*nSpace2 +
12425  I*nSpace +
12426  J]
12427  * /*should be grad_v_w in general I believe*/
12428  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
12429  k*nDOF_trial_element*nSpace+
12430  j*nSpace+
12431  J];
12432  /*identical for now*/
12433  diffusiveVelocityComponent_I_Jacobian2_wn -=
12434  a_ww[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
12435  k*nSpace2 +
12436  I*nSpace +
12437  J]
12438  * /*should be grad_v_w in general I believe*/
12439  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
12440  k*nDOF_trial_element*nSpace+
12441  j*nSpace+
12442  J];
12443 
12444  }/*J loop*/
12445  Jacobian_w +=
12446  diffusiveVelocityComponent_I_Jacobian_w
12447  */*should be v_w*/
12448  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12449  k*nDOF_trial_element +
12450  j]
12451  *
12452  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12453  k*nSpace +
12454  I];
12455  Jacobian_w +=
12456  diffusiveVelocityComponent_I_Jacobian2_ww
12457  *
12458  dphi_w_w[j_global]
12459  *
12460  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12461  k*nSpace +
12462  I];
12463  Jacobian_n +=
12464  diffusiveVelocityComponent_I_Jacobian_n
12465  */*should be v_n*/
12466  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12467  k*nDOF_trial_element +
12468  j]
12469  *
12470  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12471  k*nSpace +
12472  I];
12473  Jacobian_n +=
12474  diffusiveVelocityComponent_I_Jacobian2_wn
12475  *
12476  dphi_w_n[j_global]
12477  *
12478  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12479  k*nSpace +
12480  I];
12481  }/*I loop */
12482  /*only diagonal gets penalty term*/
12483  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
12484  {
12485  Jacobian_w +=
12486  penalty_w[ebNE*nQuadraturePoints_elementBoundary+k]
12487  * /*should be v_w*/
12488  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
12489  k*nDOF_trial_element+
12490  j];
12491  }
12492  fluxJacobian_ww[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12493  k*nDOF_trial_element +
12494  j] +=
12495  Jacobian_w;
12496  fluxJacobian_wn[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12497  k*nDOF_trial_element +
12498  j] +=
12499  Jacobian_n;
12500  }/* j local dof loop*/
12501  }/*u_w dof boundary loop*/
12502  /*setting psi_w = 1, or psi_n = 2*/
12503  if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary + k] >= 1 || (potential_gradient_n > 0.0 && fluxBoundaryFlag_un == 1))
12504  {
12505  /*NOTE! assuming u_w, u_m in the same space and nodal interpolant for potential*/
12506 
12507  for (j = 0; j < nDOF_trial_element; j++)
12508  {
12509  Jacobian_w = 0.; /*derivative wrt u_w = psi_w */
12510  Jacobian_n = 0.; /*derivative wrt u_n = psi_c */
12511  j_global = l2g[eN_global*nDOF_trial_element + j];/*assuming same space for both*/
12512  for (I = 0; I < nSpace; I++)
12513  {
12514  diffusiveVelocityComponent_I_Jacobian_w = 0.0;
12515  diffusiveVelocityComponent_I_Jacobian_n = 0.0;
12516  diffusiveVelocityComponent_I_Jacobian2_nw = 0.0;
12517  diffusiveVelocityComponent_I_Jacobian2_nn = 0.0;
12518  for (J = 0; J < nSpace; J++)
12519  {
12520  /*nn potential*/
12521  diffusiveVelocityComponent_I_Jacobian_w -=
12522  da_nn_dw[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
12523  k*nSpace2 +
12524  I*nSpace +
12525  J]
12526  *
12527  grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12528  k*nSpace +
12529  J];
12530  diffusiveVelocityComponent_I_Jacobian_n -=
12531  da_nn_dn[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
12532  k*nSpace2 +
12533  I*nSpace +
12534  J]
12535  *
12536  grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12537  k*nSpace +
12538  J];
12539 
12540  /*nn potential*/
12541  diffusiveVelocityComponent_I_Jacobian2_nw -=
12542  a_nn[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
12543  k*nSpace2 +
12544  I*nSpace +
12545  J]
12546  * /*should be grad_v_w in general I believe*/
12547  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
12548  k*nDOF_trial_element*nSpace+
12549  j*nSpace+
12550  J];
12551  /*identical for now*/
12552  diffusiveVelocityComponent_I_Jacobian2_nn -=
12553  a_nn[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
12554  k*nSpace2 +
12555  I*nSpace +
12556  J]
12557  * /*should be grad_v_m in general I believe*/
12558  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
12559  k*nDOF_trial_element*nSpace+
12560  j*nSpace+
12561  J];
12562 
12563  }/*J loop*/
12564  Jacobian_w +=
12565  diffusiveVelocityComponent_I_Jacobian_w
12566  */*should be v_w*/
12567  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12568  k*nDOF_trial_element +
12569  j]
12570  *
12571  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12572  k*nSpace +
12573  I];
12574  Jacobian_w +=
12575  diffusiveVelocityComponent_I_Jacobian2_nw
12576  *
12577  dphi_n_w[j_global]
12578  *
12579  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12580  k*nSpace +
12581  I];
12582 
12583  Jacobian_n +=
12584  diffusiveVelocityComponent_I_Jacobian_n
12585  */*should be v_n*/
12586  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12587  k*nDOF_trial_element +
12588  j]
12589  *
12590  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12591  k*nSpace +
12592  I];
12593  Jacobian_n +=
12594  diffusiveVelocityComponent_I_Jacobian2_nn
12595  *
12596  dphi_n_n[j_global]
12597  *
12598  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12599  k*nSpace +
12600  I];
12601  }/*I loop */
12602 
12603  if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary + k] == 2)
12604  {
12605  /*dependency of psi_n on psi_w*/
12606  Jacobian_n +=
12607  penalty_n[ebNE*nQuadraturePoints_elementBoundary+k]
12608  * /*should be v_n*/
12609  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
12610  k*nDOF_trial_element+
12611  j]
12612  *
12613  dpsi_n_dpsiw[ebNE*nQuadraturePoints_elementBoundary + k];
12614  /*dependency of psi_n on s_w */
12615  Jacobian_w +=
12616  penalty_n[ebNE*nQuadraturePoints_elementBoundary+k]
12617  * /*should be v_w*/
12618  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
12619  k*nDOF_trial_element+
12620  j]
12621  *
12622  dpsi_n_dpsic[ebNE*nQuadraturePoints_elementBoundary + k];
12623  }
12624  else if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary + k] == 1)
12625  {
12626  /*only diagonal gets penalty term*/
12627 
12628  Jacobian_n +=
12629  penalty_n[ebNE*nQuadraturePoints_elementBoundary+k]
12630  * /*should be v_w*/
12631  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
12632  k*nDOF_trial_element+
12633  j];
12634 
12635  }
12636  fluxJacobian_nw[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12637  k*nDOF_trial_element +
12638  j] +=
12639  Jacobian_w;
12640  fluxJacobian_nn[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12641  k*nDOF_trial_element +
12642  j] +=
12643  Jacobian_n;
12644  }/* j local dof loop*/
12645  }/*u_w dof boundary loop*/
12646 
12647  }/*k*/
12648  }/*ebNE*/
12649 
12650 }
12651 
12653  int nQuadraturePoints_elementBoundary,
12654  int nSpace,
12655  int nDOF_trial_element,
12656  int* rowptr_ww,
12657  int* colind_ww,
12658  int* rowptr_nn,
12659  int* colind_nn,
12660  const int* l2g, /*for now assumes both solution spaces are the same!*/
12661  const int* exteriorElementBoundaries,
12662  const int* elementBoundaryElements,
12663  const int* elementBoundaryLocalElementBoundaries,
12664  const int* isDOFBoundary_uw,/*1 set bc for psi_w*/
12665  const int* isDOFBoundary_un,/*1 set bc for psi_c,
12666  2 set bc for psi_n*/
12667  int fluxBoundaryFlag_uw, /*0 no flow, 1 outflow*/
12668  int fluxBoundaryFlag_un,
12669  const double* n,
12670  const double* a_ww, /*lambda_w K_s*/
12671  const double* da_ww_dw, /* a' wrt S_w*/
12672  const double* da_ww_dn, /* a' wrt psi_w*/
12673  const double* a_nn, /*lambda_t K_s*/
12674  const double* da_nn_dw, /* a' wrt S_w*/
12675  const double* da_nn_dn, /* a' wrt psi_w*/
12676  const double* grad_phi_w, /*psi_w - rho_w g . x*/
12677  const double* grad_phi_n, /*psi_n + psi_w - rho_n g . x*/
12678  const double* dphi_w_w, /*\pd{phi_w}{psi_w} = 1 */
12679  const double* dphi_w_n, /*\pd{phi_w}{psi_c}= 0 */
12680  const double* dphi_n_w, /*\pd{phi_n}{psi_w} = 1 */
12681  const double* dphi_n_n, /*\pd{phi_n}{psi_c} = 1 */
12682  const double* psi_w, /*psi_w*/
12683  const double* psi_c, /*psi_c*/
12684  const double* psi_n,
12685  const double* dpsi_n_dpsiw,
12686  const double* dpsi_n_dpsic,
12687  const double* v, /*trial functions, assumed in same space*/
12688  const double* grad_v, /*trial function gradients, assumed in same space*/
12689  const double* penalty_w,
12690  const double* penalty_n,
12691  double * fluxJacobian_ww,
12692  double * fluxJacobian_wn,
12693  double * fluxJacobian_nw,
12694  double * fluxJacobian_nn)
12695 {
12696  int ebNE,ebN,eN_global,j,j_global,I,k,m,nnz_ww=rowptr_ww[nSpace],nnz_nn=rowptr_nn[nSpace];
12697  double Jacobian_w,Jacobian_n,
12698  diffusiveVelocityComponent_I_Jacobian_w,
12699  diffusiveVelocityComponent_I_Jacobian_n,
12700  diffusiveVelocityComponent_I_Jacobian2_wn,
12701  diffusiveVelocityComponent_I_Jacobian2_ww,
12702  diffusiveVelocityComponent_I_Jacobian2_nw,
12703  diffusiveVelocityComponent_I_Jacobian2_nn;
12704  double potential_gradient_w=0.0,potential_gradient_n=0.0;
12705  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
12706  {
12707  ebN = exteriorElementBoundaries[ebNE];
12708  eN_global = elementBoundaryElements[ebN*2 + 0];
12709 
12710  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
12711  {
12712  /*compute derivative of diffusive flux for first (w) equation (aq. mass
12713  balance for part of boundary where u_0 (i.e., psi_w) is
12714  specified
12715  */
12716  /*allow outflow where potential gradient is out even if not Dirichlet,
12717  do not include K_s in calculation for now*/
12718  potential_gradient_w = 0.0; potential_gradient_n = 0.0;
12719  for (I=0; I < nSpace; I++)
12720  {
12721  potential_gradient_w += grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12722  k*nSpace + I]
12723  *
12724  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12725  k*nSpace+
12726  I];
12727  potential_gradient_n += grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12728  k*nSpace + I]
12729  *
12730  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12731  k*nSpace+
12732  I];
12733  }
12734  /*mwf hack
12735  potential_gradient_w = 0.0; potential_gradient_n = 0.0;
12736  */
12737  /*only allow setting psi_w for this equation*/
12738  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary + k] == 1 || (potential_gradient_w > 0.0 && fluxBoundaryFlag_uw == 1))
12739  {
12740  /*NOTE! assuming u_w, u_n in the same space and nodal interpolant for potential*/
12741 
12742  for (j = 0; j < nDOF_trial_element; j++)
12743  {
12744  Jacobian_w = 0.; /*derivative wrt u_w = S_w */
12745  Jacobian_n = 0.; /*derivative wrt u_n = psi_w */
12746  j_global = l2g[eN_global*nDOF_trial_element + j];/*assuming same space for both*/
12747  for (I = 0; I < nSpace; I++)
12748  {
12749  diffusiveVelocityComponent_I_Jacobian_w = 0.0;
12750  diffusiveVelocityComponent_I_Jacobian_n = 0.0;
12751  diffusiveVelocityComponent_I_Jacobian2_wn = 0.0;
12752  diffusiveVelocityComponent_I_Jacobian2_ww = 0.0;
12753  for (m=rowptr_ww[I];m<rowptr_ww[I+1];m++)
12754  {
12755  /*only a_ww potential here*/
12756  diffusiveVelocityComponent_I_Jacobian_w -=
12757  da_ww_dw[ebNE*nQuadraturePoints_elementBoundary*nnz_ww +
12758  k*nnz_ww +
12759  m]
12760  *
12761  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12762  k*nSpace +
12763  colind_ww[m]];
12764  diffusiveVelocityComponent_I_Jacobian_n -=
12765  da_ww_dn[ebNE*nQuadraturePoints_elementBoundary*nnz_ww +
12766  k*nnz_ww +
12767  m]
12768  *
12769  grad_phi_w[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12770  k*nSpace +
12771  colind_ww[m]];
12772 
12773  diffusiveVelocityComponent_I_Jacobian2_ww -=
12774  a_ww[ebNE*nQuadraturePoints_elementBoundary*nnz_ww +
12775  k*nnz_ww +
12776  m]
12777  * /*should be grad_v_w in general I believe*/
12778  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
12779  k*nDOF_trial_element*nSpace+
12780  j*nSpace+
12781  colind_ww[m]];
12782  /*identical for now*/
12783  diffusiveVelocityComponent_I_Jacobian2_wn -=
12784  a_ww[ebNE*nQuadraturePoints_elementBoundary*nnz_ww +
12785  k*nnz_ww +
12786  m]
12787  * /*should be grad_v_w in general I believe*/
12788  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
12789  k*nDOF_trial_element*nSpace+
12790  j*nSpace+
12791  colind_ww[m]];
12792 
12793  }/*J loop*/
12794  Jacobian_w +=
12795  diffusiveVelocityComponent_I_Jacobian_w
12796  */*should be v_w*/
12797  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12798  k*nDOF_trial_element +
12799  j]
12800  *
12801  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12802  k*nSpace +
12803  I];
12804  Jacobian_w +=
12805  diffusiveVelocityComponent_I_Jacobian2_ww
12806  *
12807  dphi_w_w[j_global]
12808  *
12809  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12810  k*nSpace +
12811  I];
12812  Jacobian_n +=
12813  diffusiveVelocityComponent_I_Jacobian_n
12814  */*should be v_n*/
12815  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12816  k*nDOF_trial_element +
12817  j]
12818  *
12819  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12820  k*nSpace +
12821  I];
12822  Jacobian_n +=
12823  diffusiveVelocityComponent_I_Jacobian2_wn
12824  *
12825  dphi_w_n[j_global]
12826  *
12827  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12828  k*nSpace +
12829  I];
12830  }/*I loop */
12831  /*only diagonal gets penalty term*/
12832  if (isDOFBoundary_uw[ebNE*nQuadraturePoints_elementBoundary + k] == 1)
12833  {
12834  Jacobian_w +=
12835  penalty_w[ebNE*nQuadraturePoints_elementBoundary+k]
12836  * /*should be v_w*/
12837  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
12838  k*nDOF_trial_element+
12839  j];
12840  }
12841  fluxJacobian_ww[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12842  k*nDOF_trial_element +
12843  j] +=
12844  Jacobian_w;
12845  fluxJacobian_wn[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12846  k*nDOF_trial_element +
12847  j] +=
12848  Jacobian_n;
12849  }/* j local dof loop*/
12850  }/*u_w dof boundary loop*/
12851  /*setting psi_w = 1, or psi_n = 2*/
12852  if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary + k] >= 1 || (potential_gradient_n > 0.0 && fluxBoundaryFlag_un == 1))
12853  {
12854  /*NOTE! assuming u_w, u_m in the same space and nodal interpolant for potential*/
12855 
12856  for (j = 0; j < nDOF_trial_element; j++)
12857  {
12858  Jacobian_w = 0.; /*derivative wrt u_w = psi_w */
12859  Jacobian_n = 0.; /*derivative wrt u_n = psi_c */
12860  j_global = l2g[eN_global*nDOF_trial_element + j];/*assuming same space for both*/
12861  for (I = 0; I < nSpace; I++)
12862  {
12863  diffusiveVelocityComponent_I_Jacobian_w = 0.0;
12864  diffusiveVelocityComponent_I_Jacobian_n = 0.0;
12865  diffusiveVelocityComponent_I_Jacobian2_nw = 0.0;
12866  diffusiveVelocityComponent_I_Jacobian2_nn = 0.0;
12867  for (m=rowptr_nn[I];m<rowptr_nn[I+1];m++)
12868  {
12869  /*nn potential*/
12870  diffusiveVelocityComponent_I_Jacobian_w -=
12871  da_nn_dw[ebNE*nQuadraturePoints_elementBoundary*nnz_nn +
12872  k*nnz_nn +
12873  m]
12874  *
12875  grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12876  k*nSpace +
12877  colind_nn[m]];
12878  diffusiveVelocityComponent_I_Jacobian_n -=
12879  da_nn_dn[ebNE*nQuadraturePoints_elementBoundary*nnz_nn +
12880  k*nnz_nn +
12881  m]
12882  *
12883  grad_phi_n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12884  k*nSpace +
12885  colind_nn[m]];
12886 
12887  /*nn potential*/
12888  diffusiveVelocityComponent_I_Jacobian2_nw -=
12889  a_nn[ebNE*nQuadraturePoints_elementBoundary*nnz_nn +
12890  k*nnz_nn +
12891  m]
12892  * /*should be grad_v_w in general I believe*/
12893  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
12894  k*nDOF_trial_element*nSpace+
12895  j*nSpace+
12896  colind_nn[m]];
12897  /*identical for now*/
12898  diffusiveVelocityComponent_I_Jacobian2_nn -=
12899  a_nn[ebNE*nQuadraturePoints_elementBoundary*nnz_nn +
12900  k*nnz_nn +
12901  m]
12902  * /*should be grad_v_m in general I believe*/
12903  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace +
12904  k*nDOF_trial_element*nSpace+
12905  j*nSpace+
12906  colind_nn[m]];
12907 
12908  }/*J loop*/
12909  Jacobian_w +=
12910  diffusiveVelocityComponent_I_Jacobian_w
12911  */*should be v_w*/
12912  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12913  k*nDOF_trial_element +
12914  j]
12915  *
12916  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12917  k*nSpace +
12918  I];
12919  Jacobian_w +=
12920  diffusiveVelocityComponent_I_Jacobian2_nw
12921  *
12922  dphi_n_w[j_global]
12923  *
12924  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12925  k*nSpace +
12926  I];
12927 
12928  Jacobian_n +=
12929  diffusiveVelocityComponent_I_Jacobian_n
12930  */*should be v_n*/
12931  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12932  k*nDOF_trial_element +
12933  j]
12934  *
12935  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12936  k*nSpace +
12937  I];
12938  Jacobian_n +=
12939  diffusiveVelocityComponent_I_Jacobian2_nn
12940  *
12941  dphi_n_n[j_global]
12942  *
12943  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
12944  k*nSpace +
12945  I];
12946  }/*I loop */
12947 
12948  if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary + k] == 2)
12949  {
12950  /*dependency of psi_n on psi_w*/
12951  Jacobian_n +=
12952  penalty_n[ebNE*nQuadraturePoints_elementBoundary+k]
12953  * /*should be v_n*/
12954  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
12955  k*nDOF_trial_element+
12956  j]
12957  *
12958  dpsi_n_dpsiw[ebNE*nQuadraturePoints_elementBoundary + k];
12959  /*dependency of psi_n on psi_c */
12960  Jacobian_w +=
12961  penalty_n[ebNE*nQuadraturePoints_elementBoundary+k]
12962  * /*should be v_w*/
12963  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
12964  k*nDOF_trial_element+
12965  j]
12966  *
12967  dpsi_n_dpsic[ebNE*nQuadraturePoints_elementBoundary + k];
12968  }
12969  else if (isDOFBoundary_un[ebNE*nQuadraturePoints_elementBoundary + k] == 1)
12970  {
12971  /*only diagonal gets penalty term*/
12972  Jacobian_n +=
12973  penalty_n[ebNE*nQuadraturePoints_elementBoundary+k]
12974  * /*should be v_w*/
12975  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
12976  k*nDOF_trial_element+
12977  j];
12978 
12979  }
12980  fluxJacobian_nw[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12981  k*nDOF_trial_element +
12982  j] +=
12983  Jacobian_w;
12984  fluxJacobian_nn[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element +
12985  k*nDOF_trial_element +
12986  j] +=
12987  Jacobian_n;
12988  }/* j local dof loop*/
12989  }/*u_w dof boundary loop*/
12990 
12991  }/*k*/
12992  }/*ebNE*/
12993 
12994 }
12995 
12996 /*end FCPP exterior fluxes*/
12997 void calculateGlobalExteriorNumericalFluxDarcySplitPressure(int nExteriorElementBoundaries_global,
12998  int nQuadraturePoints_elementBoundary,
12999  int nSpace,
13000  const int* exteriorElementBoundaries,
13001  const int* elementBoundaryElements,
13002  const int* elementBoundaryLocalElementBoundaries,
13003  const int* isDOFBoundary_u,/*1 set bc for psi_w,
13004  2 set bc for psi_n*/
13005  const double* n,
13006  const double* bc_a,
13007  const double* bc_grad_phi,
13008  const double* bc_psi_w,
13009  const double* bc_psi_n,
13010  const double* a,
13011  const double* grad_phi,
13012  const double* psi_w, /*psi_w*/
13013  const double* psi_n,
13014  const double* penalty,
13015  double * diffusiveFlux)
13016 {
13017  int ebNE,ebN,I,J,k,nSpace2=nSpace*nSpace;
13018  double diffusiveFlux_I=0.0,penaltyFlux = 0.0;
13019 
13020  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
13021  {
13022  ebN = exteriorElementBoundaries[ebNE];
13023  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
13024  {
13025  diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
13026  /*1 set psi_w, 2 set psi_n*/
13027  if(isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] >= 1)
13028  {
13029  /*integration by parts term for diffusive flux wrt phi = psi_w*/
13030  for (I = 0; I < nSpace; I++)
13031  {
13032  diffusiveFlux_I = 0.0;
13033  for (J = 0; J < nSpace; J++)
13034  {
13035  diffusiveFlux_I -=
13036  a[ebNE*nQuadraturePoints_elementBoundary*nSpace2 +
13037  k*nSpace2 +
13038  I*nSpace +
13039  J]
13040  *
13041  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace +
13042  k*nSpace +
13043  J];
13044  }/*J*/
13045  diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary + k] +=
13046  diffusiveFlux_I
13047  *
13048  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
13049  k*nSpace +
13050  I];
13051  }/*I, a_mw grad phi_n term */
13052  /*boundary penalty term*/
13053  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] == 2)
13054  {
13055  penaltyFlux =
13056  penalty[ebNE*nQuadraturePoints_elementBoundary + k]
13057  *
13058  (psi_n[ebNE*nQuadraturePoints_elementBoundary + k]
13059  -
13060  bc_psi_n[ebNE*nQuadraturePoints_elementBoundary + k]);
13061  }
13062  else
13063  {
13064  assert(isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] == 1);
13065  penaltyFlux =
13066  penalty[ebNE*nQuadraturePoints_elementBoundary + k]
13067  *
13068  (psi_w[ebNE*nQuadraturePoints_elementBoundary + k]
13069  -
13070  bc_psi_w[ebNE*nQuadraturePoints_elementBoundary + k]);
13071 
13072  }
13073  diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary +k] +=
13074  penaltyFlux;
13075  }/*um boundary*/
13076  }/*k*/
13077  }/*ebNE*/
13078 }
13079 void calculateGlobalExteriorNumericalFluxDarcySplitPressure_sd(int nExteriorElementBoundaries_global,
13080  int nQuadraturePoints_elementBoundary,
13081  int nSpace,
13082  const int* rowptr,
13083  const int* colind,
13084  const int* exteriorElementBoundaries,
13085  const int* elementBoundaryElements,
13086  const int* elementBoundaryLocalElementBoundaries,
13087  const int* isDOFBoundary_u,/*1 set bc for psi_w,
13088  2 set bc for psi_n*/
13089  const double* n,
13090  const double* bc_a,
13091  const double* bc_grad_phi,
13092  const double* bc_psi_w,
13093  const double* bc_psi_n,
13094  const double* a,
13095  const double* grad_phi,
13096  const double* psi_w, /*psi_w*/
13097  const double* psi_n,
13098  const double* penalty,
13099  double * diffusiveFlux)
13100 {
13101  int ebNE,ebN,I,m,k,nnz = rowptr[nSpace];
13102  double diffusiveFlux_I=0.0,penaltyFlux = 0.0;
13103 
13104  for (ebNE = 0; ebNE < nExteriorElementBoundaries_global; ebNE++)
13105  {
13106  ebN = exteriorElementBoundaries[ebNE];
13107  for (k = 0; k < nQuadraturePoints_elementBoundary; k++)
13108  {
13109  diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
13110  /*1 set psi_w, 2 set psi_n*/
13111  if(isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] >= 1)
13112  {
13113  /*integration by parts term for diffusive flux wrt phi = psi_w*/
13114  for (I = 0; I < nSpace; I++)
13115  {
13116  diffusiveFlux_I = 0.0;
13117  for (m = rowptr[I]; m < rowptr[I+1]; m++)
13118  {
13119  diffusiveFlux_I -=
13120  a[ebNE*nQuadraturePoints_elementBoundary*nnz +
13121  k*nnz +
13122  m]
13123  *
13124  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace +
13125  k*nSpace +
13126  colind[m]];
13127  }/*J*/
13128  diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary + k] +=
13129  diffusiveFlux_I
13130  *
13131  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
13132  k*nSpace +
13133  I];
13134  }/*I, a_mw grad phi_n term */
13135  /*boundary penalty term*/
13136  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] == 2)
13137  {
13138  penaltyFlux =
13139  penalty[ebNE*nQuadraturePoints_elementBoundary + k]
13140  *
13141  (psi_n[ebNE*nQuadraturePoints_elementBoundary + k]
13142  -
13143  bc_psi_n[ebNE*nQuadraturePoints_elementBoundary + k]);
13144  }
13145  else
13146  {
13147  assert(isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] == 1);
13148  penaltyFlux =
13149  penalty[ebNE*nQuadraturePoints_elementBoundary + k]
13150  *
13151  (psi_w[ebNE*nQuadraturePoints_elementBoundary + k]
13152  -
13153  bc_psi_w[ebNE*nQuadraturePoints_elementBoundary + k]);
13154 
13155  }
13156  diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary +k] +=
13157  penaltyFlux;
13158  }/*um boundary*/
13159  }/*k*/
13160  }/*ebNE*/
13161 }
13162 
13163 void shallowWater_phi(double g,
13164  double h_l, double h_r,
13165  double u_l, double u_r,
13166  double c_l, double c_r,
13167  double h,
13168  double* phi, double* dphi, double* u_f,
13169  int* w_1, int* w_2)
13170 {
13171  double phi_l,dphi_l,phi_r,dphi_r,c;
13172  c = sqrt(g*h);
13173  if(h <= h_l)
13174  {
13175  phi_l = u_l + 2.0*(c_l - c);
13176  dphi_l = -g/c;
13177  *w_1 = 2;
13178  }
13179  else
13180  {
13181  phi_l = u_l - (h - h_l)*sqrt(0.5*g*(1.0/h+1.0/h_l));
13182  dphi_l = -sqrt(0.5*g*(1.0/h+1.0/h_l)) - (h - h_l)*(0.5/sqrt(0.5*g*(1.0/h+1.0/h_l)))*(-0.5*g/(h*h));
13183  *w_1 = 1;
13184  }
13185  if(h <= h_r)
13186  {
13187  phi_r = u_r - 2.0*(c_r - c);
13188  dphi_r = g/c;
13189  *w_2 = 2;
13190  }
13191  else
13192  {
13193  phi_r = u_r + (h - h_r)*sqrt(g*(1.0/h+1.0/h_r)/2.0);
13194  dphi_r = sqrt(0.5*g*(1.0/h+1.0/h_r)) + (h - h_r)*(0.5/sqrt(0.5*g*(1.0/h+1.0/h_r)))*(-0.5*g/(h*h));
13195  *w_2 = 1;
13196  }
13197  *phi = phi_l - phi_r;
13198  *dphi = dphi_l - dphi_r;
13199  *u_f =phi_l;
13200 }
13201 
13202 void shallowWater_Riemann(int verbose,
13203  double h_eps,double tol_u,
13204  double g,
13205  double h_l, double h_r,
13206  double hu_l, double hu_r,
13207  double* h_G, double* u_G)
13208 {
13209  int w_1,w_2;//wave types: 1=shock, 2=rarefaction, 3=intermediate dry region with wet left and right states
13210  double u_l,u_r,//left and right velocities
13211  c_l,c_r,//left and right characteristic speeds
13212  h_m,u_m,c_m,u_ml,u_mr,//intermediate states and characteristic speed
13213  phi_m,dphi_m,phi_m0,dh_m,//nonlinear function value,derivative, Newton correction
13214  s_1,s_2,//shock speeds
13215  sl_1,sl_2,sr_1,sr_2;//wave speeds at left and right edges of waves
13216  //compute u_l and u_r from momentum, make sure h_l and h_r non-negative, and catch small h relative to hu
13217  if (h_l < h_eps)
13218  {
13219  h_l = 0.0;
13220  u_l = 0.0;
13221  }
13222  else
13223  u_l = hu_l/h_l;
13224  if (h_r < h_eps)
13225  {
13226  h_r = 0.0;
13227  u_r = 0.0;
13228  }
13229  else
13230  u_r = hu_r/h_r;
13231  //
13232  //find intermediate state
13233  //
13234  c_l = sqrt(g*h_l);
13235  c_r = sqrt(g*h_r);
13236  h_m = (1.0/(16.0*g))*pow(u_l - u_r + 2.0*(c_l + c_r),2); //use h_m from two rarefaction solution as initial guess
13237  u_ml = u_l + 2.0*c_l;//at right edge of 0-rarefaction connecting left state and h=0
13238  u_mr = u_r - 2.0*c_r;//at left edge of 1-rarefaction connecting right state and h=0
13239  if (verbose)
13240  printf("%12.5e %12.5e %12.5e\n",h_m,h_l,h_r);
13241  if (h_l < h_eps || h_r < h_eps)//left or right state is dry
13242  {
13243  //initialize to rarefactions
13244  w_1 = 2;
13245  w_2 = 2;
13246  if (h_l < h_eps)
13247  w_1 = 1;//1-wave is shock
13248  if (h_r < h_eps)
13249  w_2 = 1;//2-wave is shock
13250  h_m = 0.0;//intermediate state is dry
13251  u_m = u_r + u_l - 2.0*(c_r - c_l);//connect to wet state with rarefaction or 0 if both states dry
13252  c_m = 0.0;
13253  }
13254  else if (u_ml <= u_mr)//intermediate state is dry
13255  {
13256  h_m = 0.0;
13257  u_m = 0.0;
13258  c_m = 0.0;
13259  w_1 = 3;
13260  w_2 = 3;
13261  }
13262  else if (h_m <= h_l && h_m <= h_r) //the solution is two rarefactions
13263  {
13264  c_m = sqrt(g*h_m);
13265  u_m = u_l + 2.0*(c_l - c_m);
13266  w_1 = 2;
13267  w_2 = 2;
13268  if (verbose)
13269  printf("picking 2 rarefactions %i %i %12.5e %12.5e \n",w_1,w_2,h_m,u_m);
13270  }
13271  else//calculate h_m,u_m using Newton's method
13272  {
13273  tol_u=fmin(fabs(u_l),fabs(u_r))*1.0e-8+1.0e-8;
13274  shallowWater_phi(g,h_l,h_r,u_l,u_r,c_l,c_r,h_m,&phi_m,&dphi_m,&u_m,&w_1,&w_2);
13275  phi_m0=phi_m;
13276  while (fabs(phi_m) > tol_u)
13277  {
13278  dh_m = -phi_m/dphi_m;
13279  h_m += dh_m;
13280  shallowWater_phi(g,h_l,h_r,u_l,u_r,c_l,c_r,h_m,&phi_m,&dphi_m,&u_m,&w_1,&w_2);
13281  }
13282  if (verbose)
13283  printf("wave types from newton %i %i \n",w_1,w_2);
13284  c_m = sqrt(g*h_m);
13285  }
13286  //compute characteristic speeds (used to find Godunov values)
13287  if (w_1 == 3)//two rarefactions connecting wet states to intermediate dry state
13288  {
13289  sl_1 = u_l - c_l;
13290  sr_1 = u_ml - c_m;
13291  sl_2 = u_mr + c_m;
13292  sr_2 = u_r + c_r;
13293  }
13294  else
13295  {
13296  if (w_1 == 1)//1-shock
13297  {
13298  if (fabs(h_l - h_m) <= 1.0e-10)//tiny shock, use left characteristic
13299  s_1 = u_l - c_l;
13300  else
13301  s_1 = (h_l * u_l - h_m * u_m)/(h_l - h_m);
13302  sl_1 = s_1;
13303  sr_1 = s_1;
13304  }
13305  else//1-rarefaction
13306  {
13307  sl_1 = u_l - c_l;
13308  sr_1 = u_m - c_m;
13309  }
13310  if (w_2 == 1)//2-shock
13311  {
13312  if (fabs(h_r - h_m) <= 1.0e-10)//tiny shock, use right characteristic
13313  s_2 = u_r + c_r;
13314  else
13315  s_2 = (h_r*u_r - h_m*u_m)/(h_r - h_m);
13316  sl_2 = s_2;
13317  sr_2 = s_2;
13318  }
13319  else//2-rarefaction
13320  {
13321  sl_2 = u_m + c_m;
13322  sr_2 = u_r + c_r;
13323  }
13324  }
13325  //compute Godunov values of h and u along x/t=0
13326  if (sl_1 < 0.0 && sr_1 > 0.0)//1-wave with left edge left going and right edge right going (transonic rarefaction)
13327  {
13328  *h_G = (1.0/(9.0*g))*pow(u_l + 2.0*c_l,2);
13329  *u_G = u_l - 2.0*(sqrt(g*(*h_G)) - c_l);
13330  if (verbose)
13331  printf("1-wave transonic rarefaction");
13332  }
13333  else if (sl_2 < 0.0 && sr_2 > 0.0) //2-wave is transonic rarefaction
13334  {
13335  *h_G = (1.0/(9.0*g))*pow(u_r - 2.0*c_r,2);
13336  *u_G = u_r + 2.0*(sqrt(g*(*h_G)) - c_r);
13337  if (verbose)
13338  printf("2-wave transonic rarefaction");
13339  }
13340  else if (sl_1 > 0.0)//left edge of 1-wave is right going (shock or supersonic rarefaction)
13341  {
13342  if (verbose)
13343  printf("1-wave supersonic");
13344  *h_G = h_l;
13345  *u_G = u_l;
13346  }
13347  else if (sr_2 < 0.0)//right edge of 2-wave is left going (shock or supersonic rarefaction)
13348  {
13349  if (verbose)
13350  printf("2-wave supersonic");
13351  *h_G = h_r;
13352  *u_G = u_r;
13353  }
13354  else//right edge of 1-wave is left going and left edge of 2-wave is right going so use the intermediate state
13355  {
13356  if (verbose)
13357  printf("intermediate state");
13358  *h_G = h_m;
13359  *u_G = u_m;
13360  }
13361  if (verbose)
13362  printf("%12.5e %12.5e %12.5e %12.5e\n",sl_1,sr_1,sl_2,sr_2);
13363 }
13364 
13365 void calculateInteriorNumericalFluxShallowWater_1D(int nInteriorElementBoundaries_global,
13366  int nElementBoundaries_element,
13367  int nQuadraturePoints_elementBoundary,
13368  double h_eps,
13369  double tol_u,
13370  double g,
13371  int* interiorElementBoundaries,
13372  int* elementBoundaryElements,
13373  int* elementBoundaryLocalElementBoundaries,
13374  double* n,
13375  double* h,
13376  double* hu,
13377  double* flux_h,
13378  double* flux_hu)
13379 {
13380  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,verbose=0;
13381  double h_l,h_r,hu_l,hu_r,h_G,u_G,n_lr;
13382  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
13383  {
13384  ebN = interiorElementBoundaries[ebNI];
13385  left_eN_global = elementBoundaryElements[ebN*2+0];
13386  right_eN_global = elementBoundaryElements[ebN*2+1];
13387  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
13388  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
13389  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
13390  {
13391  n_lr = n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13392  left_ebN_element*nQuadraturePoints_elementBoundary+
13393  k+
13394  0];
13395  h_l = fmax(0.0,h[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13396  left_ebN_element*nQuadraturePoints_elementBoundary+
13397  k]);
13398  h_r = fmax(0.0,h[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13399  right_ebN_element*nQuadraturePoints_elementBoundary+
13400  k]);
13401  hu_l = hu[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13402  left_ebN_element*nQuadraturePoints_elementBoundary+
13403  k]*n_lr;
13404  hu_r = hu[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13405  right_ebN_element*nQuadraturePoints_elementBoundary+
13406  k]*n_lr;
13407  shallowWater_Riemann(verbose,h_eps,tol_u,g,h_l,h_r,hu_l,hu_r,&h_G,&u_G);
13408  u_G *= n_lr;
13409  flux_h[ebN*nQuadraturePoints_elementBoundary+
13410  k] = h_G*u_G*n_lr;
13411  flux_hu[ebN*nQuadraturePoints_elementBoundary+
13412  k] = (h_G*u_G*u_G + 0.5*g*h_G*h_G)*n_lr;
13413  }/*k*/
13414  }/*ebnI*/
13415 }
13416 void calculateExteriorNumericalFluxShallowWater_1D(int nExteriorElementBoundaries_global,
13417  int nQuadraturePoints_elementBoundary,
13418  double h_eps,
13419  double tol_u,
13420  double g,
13421  double* n,
13422  double* h_lv,
13423  double* hu_lv,
13424  double* h_rv,
13425  double* hu_rv,
13426  double* flux_h,
13427  double* flux_hu)
13428 {
13429  int ebNE,k,verbose=0;
13430  double h_l,h_r,hu_l,hu_r,h_G,u_G,n_lr;
13431  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
13432  {
13433  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
13434  {
13435  n_lr = n[ebNE*nQuadraturePoints_elementBoundary+
13436  k+
13437  0];
13438  h_l = h_lv[ebNE*nQuadraturePoints_elementBoundary+
13439  k];
13440  h_r = h_rv[ebNE*nQuadraturePoints_elementBoundary+
13441  k];
13442  hu_l = hu_lv[ebNE*nQuadraturePoints_elementBoundary+
13443  k]*n_lr;
13444  hu_r = hu_rv[ebNE*nQuadraturePoints_elementBoundary+
13445  k]*n_lr;
13446  shallowWater_Riemann(verbose,h_eps,tol_u,g,h_l,h_r,hu_l, hu_r,&h_G,&u_G);
13447  u_G *= n_lr;
13448  flux_h[ebNE*nQuadraturePoints_elementBoundary+
13449  k] = h_G*u_G*n_lr;
13450  flux_hu[ebNE*nQuadraturePoints_elementBoundary+
13451  k] = (h_G*u_G*u_G + 0.5*g*h_G*h_G)*n_lr;
13452  }/*k*/
13453  }/*ebnE*/
13454 }
13455 
13456 void calculateInteriorNumericalFluxShallowWater_2D(int nInteriorElementBoundaries_global,
13457  int nElementBoundaries_element,
13458  int nQuadraturePoints_elementBoundary,
13459  double h_eps,
13460  double tol_u,
13461  double g,
13462  int* interiorElementBoundaries,
13463  int* elementBoundaryElements,
13464  int* elementBoundaryLocalElementBoundaries,
13465  double* n,
13466  double* h,
13467  double* hu,
13468  double* hv,
13469  double* flux_h,
13470  double* flux_hu,
13471  double* flux_hv)
13472 {
13473  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,verbose=0;
13474  double h_l,h_r,hu_l,hu_r,hv_l,hv_r,h_G,u_G,v_G,nx_lr,ny_lr,hVn_l,hVn_r,hVt_l,hVt_r,Vn_G,Vt_G,hVt_G;
13475  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
13476  {
13477  ebN = interiorElementBoundaries[ebNI];
13478  left_eN_global = elementBoundaryElements[ebN*2+0];
13479  right_eN_global = elementBoundaryElements[ebN*2+1];
13480  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
13481  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
13482  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
13483  {
13484  nx_lr = n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*2+
13485  left_ebN_element*nQuadraturePoints_elementBoundary*2+
13486  k*2+
13487  0];
13488  ny_lr = n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*2+
13489  left_ebN_element*nQuadraturePoints_elementBoundary*2+
13490  k*2+
13491  1];
13492  h_l = h[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13493  left_ebN_element*nQuadraturePoints_elementBoundary+
13494  k];
13495  h_r = h[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13496  right_ebN_element*nQuadraturePoints_elementBoundary+
13497  k];
13498  hu_l = hu[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13499  left_ebN_element*nQuadraturePoints_elementBoundary+
13500  k];
13501  hu_r = hu[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13502  right_ebN_element*nQuadraturePoints_elementBoundary+
13503  k];
13504  hv_l = hv[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13505  left_ebN_element*nQuadraturePoints_elementBoundary+
13506  k];
13507  hv_r = hv[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13508  right_ebN_element*nQuadraturePoints_elementBoundary+
13509  k];
13510  //project u and v onto interface normal and tangential components
13511  hVn_l = nx_lr*hu_l + ny_lr*hv_l;
13512  hVt_l = ny_lr*hu_l - nx_lr*hv_l;
13513  hVn_r = nx_lr*hu_r + ny_lr*hv_r;
13514  hVt_r = ny_lr*hu_r - nx_lr*hv_r;
13515  shallowWater_Riemann(verbose,h_eps,tol_u,g,h_l,h_r,hVn_l, hVn_r,&h_G,&Vn_G);
13516  if (Vn_G > 0.0)
13517  hVt_G = hVt_l;
13518  else
13519  hVt_G = hVt_r;
13520  if (h_G < h_eps)
13521  {
13522  Vt_G = 0.0;
13523  }
13524  else
13525  {
13526  Vt_G = hVt_G/h_G;
13527  }
13528  u_G = Vn_G*nx_lr + Vt_G*ny_lr;
13529  v_G = Vn_G*ny_lr - Vt_G*nx_lr;
13530  //calculate fluxes
13531  flux_h[ebN*nQuadraturePoints_elementBoundary+
13532  k] = h_G*u_G*nx_lr + h_G*v_G*ny_lr;
13533  flux_hu[ebN*nQuadraturePoints_elementBoundary+
13534  k] = (h_G*u_G*u_G + 0.5*g*h_G*h_G)*nx_lr + h_G*u_G*v_G*ny_lr;
13535  flux_hv[ebN*nQuadraturePoints_elementBoundary+
13536  k] = h_G*u_G*v_G*nx_lr + (h_G*v_G*v_G + 0.5*g*h_G*h_G)*ny_lr;
13537  }/*k*/
13538  }/*ebnI*/
13539 }
13540 
13541 void calculateExteriorNumericalFluxShallowWater_2D(int nExteriorElementBoundaries_global,
13542  int nQuadraturePoints_elementBoundary,
13543  double h_eps,
13544  double tol_u,
13545  double g,
13546  double* n,
13547  double* h_lq,
13548  double* hu_lq,
13549  double* hv_lq,
13550  double* h_rq,
13551  double* hu_rq,
13552  double* hv_rq,
13553  double* flux_h,
13554  double* flux_hu,
13555  double* flux_hv)
13556 {
13557  int ebNE,k,verbose=0;
13558  double h_l,h_r,hu_l,hu_r,hv_l,hv_r,h_G,u_G,v_G,nx_lr,ny_lr,hVn_l,hVn_r,hVt_l,hVt_r,Vn_G,Vt_G,hVt_G;
13559  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
13560  {
13561  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
13562  {
13563  nx_lr = n[ebNE*nQuadraturePoints_elementBoundary*2+
13564  k*2+
13565  0];
13566  ny_lr = n[ebNE*nQuadraturePoints_elementBoundary*2+
13567  k*2+
13568  1];
13569  h_l = h_lq[ebNE*nQuadraturePoints_elementBoundary+
13570  k];
13571  h_r = h_rq[ebNE*nQuadraturePoints_elementBoundary+
13572  k];
13573  hu_l = hu_lq[ebNE*nQuadraturePoints_elementBoundary+
13574  k];
13575  hu_r = hu_rq[ebNE*nQuadraturePoints_elementBoundary+
13576  k];
13577  hv_l = hv_lq[ebNE*nQuadraturePoints_elementBoundary+
13578  k];
13579  hv_r = hv_rq[ebNE*nQuadraturePoints_elementBoundary+
13580  k];
13581  //project hu and hv onto interface normal and tangential components
13582  hVn_l = nx_lr*hu_l + ny_lr*hv_l;
13583  hVt_l = ny_lr*hu_l - nx_lr*hv_l;
13584  hVn_r = nx_lr*hu_r + ny_lr*hv_r;
13585  hVt_r = ny_lr*hu_r - nx_lr*hv_r;
13586  shallowWater_Riemann(verbose,h_eps,tol_u,g,h_l,h_r,hVn_l,hVn_r,&h_G,&Vn_G);
13587  if (Vn_G > 0.0)
13588  hVt_G = hVt_l;
13589  else
13590  hVt_G = hVt_r;
13591  if (h_G < h_eps)
13592  {
13593  Vt_G = 0.0;
13594  }
13595  else
13596  {
13597  Vt_G = hVt_G/h_G;
13598  }
13599  u_G = Vn_G*nx_lr + Vt_G*ny_lr;
13600  v_G = Vn_G*ny_lr - Vt_G*nx_lr;
13601  flux_h[ebNE*nQuadraturePoints_elementBoundary+
13602  k] = h_G*u_G*nx_lr + h_G*v_G*ny_lr;
13603  flux_hu[ebNE*nQuadraturePoints_elementBoundary+
13604  k] = (h_G*u_G*u_G + 0.5*g*h_G*h_G)*nx_lr + h_G*u_G*v_G*ny_lr;
13605  flux_hv[ebNE*nQuadraturePoints_elementBoundary+
13606  k] = h_G*u_G*v_G*nx_lr + (h_G*v_G*v_G + 0.5*g*h_G*h_G)*ny_lr;
13607  }/*k*/
13608  }/*ebnE*/
13609 }
13610 void calculateInteriorNumericalFluxShallowWaterHLL_1D(int nInteriorElementBoundaries_global,
13611  int nElementBoundaries_element,
13612  int nQuadraturePoints_elementBoundary,
13613  double h_eps,
13614  double tol_u,
13615  double g,
13616  int* interiorElementBoundaries,
13617  int* elementBoundaryElements,
13618  int* elementBoundaryLocalElementBoundaries,
13619  double* n,
13620  double* h,
13621  double* hu,
13622  double* flux_h,
13623  double* flux_hu)
13624 {
13625  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,verbose=0;
13626  double h_l,h_r,hu_l,hu_r,u_l,u_r,n_lr,h_G,u_G;
13627 
13628  double h_Roe,u_Roe,/*avg h and u for calculating eigenvalues for Roe matrix,*/
13629  lambda_1L,lambda_2R,/*1 family wave for left state, 2 family wave for right state*/
13630  lambda_1Roe,lambda_2Roe,/*1 and 2 wave eigen values for Roe matrix*/
13631  lambda_min,lambda_max,/*upper and lower bound for eigenvalues*/
13632  h_LR,hu_LR;/*intermediate state
13633  u_LR = \lambda_max U_R -lambda_min U_L / (lambda_max - lambda_min)
13634  - (f(U_r)-f(U_L)/(lambda_max-lambda_min)
13635  */
13636  /*
13637  flux is
13638  f_HLL(U_L,U_R) = \frac{\lambda_max^- - \lambda_min^-}{\lambda_max-\lambda_min} f(U_R)
13639  +\frac{\lambda_max^+ - \lambda_min^+}{\lambda_max-\lambda_min} f(U_L)
13640  -\frac{1}{2}\frac{\lambda_max|\lambda_min| - \lambda_min|\lambda_max|}{\lambda_max-\lambda_min}(U_R-U_L)
13641  */
13642  double lambda_diff;
13643  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
13644  {
13645  ebN = interiorElementBoundaries[ebNI];
13646  left_eN_global = elementBoundaryElements[ebN*2+0];
13647  right_eN_global = elementBoundaryElements[ebN*2+1];
13648  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
13649  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
13650  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
13651  {
13652  n_lr = n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13653  left_ebN_element*nQuadraturePoints_elementBoundary+
13654  k+
13655  0];
13656  h_l = fmax(0.0,h[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13657  left_ebN_element*nQuadraturePoints_elementBoundary+
13658  k]);
13659  h_r = fmax(0.0,h[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13660  right_ebN_element*nQuadraturePoints_elementBoundary+
13661  k]);
13662  hu_l = hu[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13663  left_ebN_element*nQuadraturePoints_elementBoundary+
13664  k];
13665  hu_r = hu[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
13666  right_ebN_element*nQuadraturePoints_elementBoundary+
13667  k];
13668  u_l = 0.0; u_r =0.0; u_Roe = 0.0;
13669  if (h_l > h_eps)
13670  u_l = n_lr*hu_l/h_l;
13671  else
13672  h_l = 0.0;
13673  if (h_r > h_eps)
13674  u_r = n_lr*hu_r/h_r;
13675  else
13676  h_r = 0.0;
13677  /*Roe averages*/
13678  h_Roe = 0.5*(h_l+h_r);
13679  if (h_l + h_r > h_eps)
13680  u_Roe = (sqrt(h_l)*u_l + sqrt(h_r)*u_r)/(sqrt(h_l)+sqrt(h_r));
13681  /*Roe matrix speeds*/
13682  lambda_1Roe = u_Roe - sqrt(h_Roe*g); lambda_2Roe = u_Roe + sqrt(h_Roe*g);
13683  /*slowest/fastest eigenvalue at left/right state*/
13684  lambda_1L = u_l - sqrt(g*h_l); lambda_2R = u_r + sqrt(g*h_r);
13685  /*lower/upper bound on speeds*/
13686  lambda_min = fmin(lambda_1L,lambda_1Roe);
13687  lambda_max = fmax(lambda_2R,lambda_2Roe);
13688 
13689  /*mwf debug
13690  shallowWater_Riemann(verbose,h_eps,tol_u,g,h_l,h_r,hu_l*n_lr,hu_r*n_lr,&h_G,&u_G);
13691  u_G *= n_lr;
13692  */
13693 
13694  if (lambda_min >= 0.0)
13695  {
13696  /*left state travels at zero speed*/
13697  flux_h[ebN*nQuadraturePoints_elementBoundary+
13698  k] = h_l*u_l*n_lr;/*hu_l*n_lr;*/
13699  flux_hu[ebN*nQuadraturePoints_elementBoundary+
13700  k] = (h_l*u_l*u_l + 0.5*g*h_l*h_l)*n_lr;
13701 
13702  /*mwf debug
13703  if (fabs(flux_h[ebN*nQuadraturePoints_elementBoundary+k]-h_G*u_G*n_lr) > 1.0e-4 ||
13704  fabs(flux_hu[ebN*nQuadraturePoints_elementBoundary+k]-(h_G*u_G*u_G + 0.5*g*h_G*h_G)*n_lr) > 1.0e-4)
13705  {
13706  printf("SW HLL ebN=%d k=%d h_l=%g h_r=%g hu_l=%g hu_r=%g n_lr=%g u_l= %g u_r=%g h_Roe=%g u_Roe=%g\n",ebN,k,h_l,h_r,hu_l,hu_r,n_lr,u_l,u_r,h_Roe,u_Roe);
13707  printf("\t lambda_1Roe=%g lambda_2Roe=%g lambda_1L=%g lambda_2R=%g lambda_min=%g lambda_max=%g\n",
13708  lambda_1Roe,lambda_2Roe,lambda_1L,lambda_2R,lambda_min,lambda_max);
13709  printf("\t left state chosen flux_h= %g flux_hu= %g \n",
13710  flux_h[ebN*nQuadraturePoints_elementBoundary+k],
13711  flux_hu[ebN*nQuadraturePoints_elementBoundary+k]);
13712  printf("\t result from exact solve h_G= %g u_G=%g flux_h= %g flux_hu= %g \n",
13713  h_G,u_G,h_G*u_G*n_lr,(h_G*u_G*u_G + 0.5*g*h_G*h_G)*n_lr);
13714  }
13715  */
13716  }
13717  else if (lambda_max <= 0.0)
13718  {
13719  /*right state travels at zero speed*/
13720  flux_h[ebN*nQuadraturePoints_elementBoundary+
13721  k] = h_r*u_r*n_lr;/*hu_r*n_lr;*/
13722  flux_hu[ebN*nQuadraturePoints_elementBoundary+
13723  k] = (h_r*u_r*u_r + 0.5*g*h_r*h_r)*n_lr;
13724 
13725  /*mwf debug
13726  if (fabs(flux_h[ebN*nQuadraturePoints_elementBoundary+k]-h_G*u_G*n_lr) > 1.0e-4 ||
13727  fabs(flux_hu[ebN*nQuadraturePoints_elementBoundary+k]-(h_G*u_G*u_G + 0.5*g*h_G*h_G)*n_lr) > 1.0e-4)
13728  {
13729  printf("SW HLL ebN=%d k=%d h_l=%g h_r=%g hu_l=%g hu_r=%g n_lr=%g u_l= %g u_r=%g h_Roe=%g u_Roe=%g\n",ebN,k,h_l,h_r,hu_l,hu_r,n_lr,u_l,u_r,h_Roe,u_Roe);
13730  printf("\t lambda_1Roe=%g lambda_2Roe=%g lambda_1L=%g lambda_2R=%g lambda_min=%g lambda_max=%g\n",
13731  lambda_1Roe,lambda_2Roe,lambda_1L,lambda_2R,lambda_min,lambda_max);
13732  printf("\t right state chosen flux_h= %g flux_hu= %g \n",
13733  flux_h[ebN*nQuadraturePoints_elementBoundary+k],
13734  flux_hu[ebN*nQuadraturePoints_elementBoundary+k]);
13735  printf("\t result from exact solve h_G= %g u_G=%g flux_h= %g flux_hu= %g \n",
13736  h_G,u_G,h_G*u_G*n_lr,(h_G*u_G*u_G + 0.5*g*h_G*h_G)*n_lr);
13737  }
13738  */
13739  }
13740  else /*intermediate state travels with zero speed*/
13741  {
13742  lambda_diff = lambda_max-lambda_min;
13743  assert(fabs(lambda_diff) > 0.0);
13744  /*intermediate state chosen to enforce conservation of Riemann solution
13745  equivalent to decomposing flux jump as piecewise linear function
13746  f(U_R)-f(U_L) = \lambda_max(U_R-U_LR) + \lambda_min(U_LR-U_L)
13747  */
13748  h_LR = (lambda_max*h_r - lambda_min*h_l
13749  -n_lr*(h_r*u_r-h_l*u_l))/lambda_diff;
13750  assert(h_LR >= 0.0);
13751  hu_LR= (lambda_max*h_r*u_r - lambda_min*h_l*u_l
13752  -n_lr*(h_r*u_r*u_r + 0.5*g*h_r*h_r - h_l*u_l*u_l - 0.5*g*h_l*h_l))/lambda_diff;
13753 
13754  flux_h[ebN*nQuadraturePoints_elementBoundary+k] =
13755  (n_lr*(lambda_max*h_l*u_l-lambda_min*h_r*u_r) + (h_r-h_l)*lambda_max*lambda_min)/lambda_diff;
13756  flux_hu[ebN*nQuadraturePoints_elementBoundary+k] =
13757  (n_lr*(lambda_max*(h_l*u_l*u_l + 0.5*g*h_l*h_l)-lambda_min*(h_r*u_r*u_r + 0.5*g*h_r*h_r)) + (h_r*u_r-h_l*u_l)*lambda_max*lambda_min)/lambda_diff;
13758 
13759 /* flux_h[ebN*nQuadraturePoints_elementBoundary+k] = */
13760 /* (n_lr*(lambda_max*hu_l-lambda_min*hu_r) + (h_r-h_l)*lambda_max*lambda_min)/lambda_diff; */
13761 /* flux_hu[ebN*nQuadraturePoints_elementBoundary+k] = */
13762 /* (n_lr*(lambda_max*(h_l*u_l*u_l + 0.5*g*h_l*h_l)-lambda_min*(h_r*u_r*u_r + 0.5*g*h_r*h_r)) + (hu_r-hu_l)*lambda_max*lambda_min)/lambda_diff; */
13763 
13764 /* flux_h[ebN*nQuadraturePoints_elementBoundary+ */
13765 /* k] = */
13766 /* h_l*u_l*n_lr + lambda_min*(h_LR-h_l); */
13767 
13768 /* flux_hu[ebN*nQuadraturePoints_elementBoundary+ */
13769 /* k] = */
13770 /* (h_l*u_l*u_l + 0.5*g*h_l*h_l)*n_lr + lambda_min*(hu_LR-h_l*u_l); */
13771 
13772 
13773 /* if (h_LR < 1.0e-3) */
13774 /* { */
13775 /* /\*mwf hack*\/ */
13776 /* flux_h[ebN*nQuadraturePoints_elementBoundary+ */
13777 /* k] = */
13778 /* h_G*u_G*n_lr; */
13779 
13780 /* flux_hu[ebN*nQuadraturePoints_elementBoundary+ */
13781 /* k] = */
13782 /* (h_G*u_G*u_G + 0.5*g*h_G*h_G)*n_lr; */
13783 
13784 /* } */
13785  /*mwf debug
13786  if (fabs(flux_h[ebN*nQuadraturePoints_elementBoundary+k]-h_G*u_G*n_lr) > 1.0e-4 ||
13787  fabs(flux_hu[ebN*nQuadraturePoints_elementBoundary+k]-(h_G*u_G*u_G + 0.5*g*h_G*h_G)*n_lr) > 1.0e-4)
13788  {
13789  printf("SW HLL ebN=%d k=%d h_l=%g h_r=%g hu_l=%g hu_r=%g n_lr=%g u_l= %g u_r=%g h_Roe=%g u_Roe=%g\n",ebN,k,h_l,h_r,hu_l,hu_r,n_lr,u_l,u_r,h_Roe,u_Roe);
13790  printf("\t lambda_1Roe=%g lambda_2Roe=%g lambda_1L=%g lambda_2R=%g lambda_min=%g lambda_max=%g\n",
13791  lambda_1Roe,lambda_2Roe,lambda_1L,lambda_2R,lambda_min,lambda_max);
13792  printf("\t intermediate state chosen h_LR= %g hu_LR=%g flux_h= %g flux_hu= %g \n",
13793  h_LR,hu_LR,
13794  flux_h[ebN*nQuadraturePoints_elementBoundary+k],
13795  flux_hu[ebN*nQuadraturePoints_elementBoundary+k]);
13796  printf("\t result from exact solve h_G= %g u_G=%g flux_h= %g flux_hu= %g \n",
13797  h_G,u_G,h_G*u_G*n_lr,(h_G*u_G*u_G + 0.5*g*h_G*h_G)*n_lr);
13798  }
13799  */
13800  }
13801  }/*k*/
13802  }/*ebnI*/
13803 }
13804 void calculateExteriorNumericalFluxShallowWaterHLL_1D(int nExteriorElementBoundaries_global,
13805  int nQuadraturePoints_elementBoundary,
13806  double h_eps,
13807  double tol_u,
13808  double g,
13809  double* n,
13810  double* h_lv,
13811  double* hu_lv,
13812  double* h_rv,
13813  double* hu_rv,
13814  double* flux_h,
13815  double* flux_hu)
13816 {
13817  int ebNE,k,verbose=0;
13818  double h_l,h_r,hu_l,hu_r,u_l,u_r,n_lr;
13819  double h_Roe,u_Roe,/*avg h and u for calculating eigenvalues for Roe matrix,*/
13820  lambda_1L,lambda_2R,/*1 family wave for left state, 2 family wave for right state*/
13821  lambda_1Roe,lambda_2Roe,/*1 and 2 wave eigen values for Roe matrix*/
13822  lambda_min,lambda_max,/*upper and lower bound for eigenvalues*/
13823  h_LR,hu_LR;/*intermediate state
13824  u_LR = \lambda_max U_R -lambda_min U_L / (lambda_max - lambda_min)
13825  - (f(U_r)-f(U_L)/(lambda_max-lambda_min)
13826  */
13827  /*
13828  flux is
13829  f_HLL(U_L,U_R) = \frac{\lambda_max^- - \lambda_min^-}{\lambda_max-\lambda_min} f(U_R)
13830  +\frac{\lambda_max^+ - \lambda_min^+}{\lambda_max-\lambda_min} f(U_L)
13831  -\frac{1}{2}\frac{\lambda_max|\lambda_min| - \lambda_min|\lambda_max|}{\lambda_max-\lambda_min}(U_R-U_L)
13832  */
13833  double lambda_min_p,lambda_max_p,lambda_min_m,lambda_max_m,lambda_diff,pos,neg,mid;
13834  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
13835  {
13836  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
13837  {
13838  n_lr = n[ebNE*nQuadraturePoints_elementBoundary+
13839  k+
13840  0];
13841  h_l = fmax(0.0,h_lv[ebNE*nQuadraturePoints_elementBoundary+
13842  k]);
13843  h_r = fmax(0.0,h_rv[ebNE*nQuadraturePoints_elementBoundary+
13844  k]);
13845  hu_l = hu_lv[ebNE*nQuadraturePoints_elementBoundary+
13846  k];
13847  hu_r = hu_rv[ebNE*nQuadraturePoints_elementBoundary+
13848  k];
13849 
13850  u_l = 0.0; u_r =0.0; u_Roe = 0.0;
13851  if (h_l > h_eps)
13852  u_l = n_lr*hu_l/h_l;
13853  else
13854  h_l = 0.0;
13855  if (h_r > h_eps)
13856  u_r = n_lr*hu_r/h_r;
13857  else
13858  h_r = 0.0;
13859  /*Roe averages*/
13860  h_Roe = 0.5*(h_l+h_r);
13861  if (h_l + h_r > h_eps)
13862  u_Roe = (sqrt(h_l)*u_l + sqrt(h_r)*u_r)/(sqrt(h_l)+sqrt(h_r));
13863  /*Roe matrix speeds*/
13864  lambda_1Roe = u_Roe - sqrt(h_Roe*g); lambda_2Roe = u_Roe + sqrt(h_Roe*g);
13865  /*slowest/fastest eigenvalue at left/right state*/
13866  lambda_1L = u_l - sqrt(g*h_l); lambda_2R = u_r + sqrt(g*h_r);
13867  /*lower/upper bound on speeds*/
13868  lambda_min = fmin(lambda_1L,lambda_1Roe);
13869  lambda_max = fmax(lambda_2R,lambda_2Roe);
13870 
13871 
13872  if (lambda_min >= 0.0)
13873  {
13874  /*left state travels at zero speed*/
13875  flux_h[ebNE*nQuadraturePoints_elementBoundary+
13876  k] = h_l*u_l*n_lr;/*hu_l*n_lr;*/
13877  flux_hu[ebNE*nQuadraturePoints_elementBoundary+
13878  k] = (h_l*u_l*u_l + 0.5*g*h_l*h_l)*n_lr;
13879 
13880 
13881  }
13882  else if (lambda_max <= 0.0)
13883  {
13884  /*right state travels at zero speed*/
13885  flux_h[ebNE*nQuadraturePoints_elementBoundary+
13886  k] = h_r*u_r*n_lr;/*hu_r*n_lr*/;
13887  flux_hu[ebNE*nQuadraturePoints_elementBoundary+
13888  k] = (h_r*u_r*u_r + 0.5*g*h_r*h_r)*n_lr;
13889 
13890  }
13891 
13892  else /*intermediate state travels with zero speed*/
13893  {
13894  lambda_diff = lambda_max-lambda_min;
13895  assert(fabs(lambda_diff) > 0.0);
13896  /*intermediate state chosen to enforce conservation of Riemann solution
13897  equivalent to decomposing flux jump as piecewise linear function
13898  f(U_R)-f(U_L) = \lambda_max(U_R-U_LR) + \lambda_min(U_LR-U_L)
13899  */
13900  h_LR = (lambda_max*h_r - lambda_min*h_l
13901  -n_lr*(h_r*u_r-h_l*u_l))/lambda_diff;
13902  hu_LR= (lambda_max*hu_r - lambda_min*hu_l
13903  -n_lr*(h_r*u_r*u_r + 0.5*g*h_r*h_r - h_l*u_l*u_l - 0.5*g*h_l*h_l))/lambda_diff;
13904 
13905  if (h_LR < h_eps)
13906  {
13907  h_LR = 0.0; hu_LR = 0.0;
13908  }
13909 /* flux_h[ebN*nQuadraturePoints_elementBoundary+k] = */
13910 /* (n_lr*(lambda_max*h_l*u_l-lambda_min*h_r*u_r) + (h_r-h_l)*lambda_max*lambda_min)/lambda_diff; */
13911 /* flux_hu[ebN*nQuadraturePoints_elementBoundary+k] = */
13912 /* (n_lr*(lambda_max*(h_l*u_l*u_l + 0.5*g*h_l*h_l)-lambda_min*(h_r*u_r*u_r + 0.5*g*h_r*h_r)) + (h_r*u_r-h_l*u_l)*lambda_max*lambda_min)/lambda_diff; */
13913 
13914  flux_h[ebNE*nQuadraturePoints_elementBoundary+k] =
13915  (n_lr*(lambda_max*hu_l-lambda_min*hu_r) + (h_r-h_l)*lambda_max*lambda_min)/lambda_diff;
13916  flux_hu[ebNE*nQuadraturePoints_elementBoundary+k] =
13917  (n_lr*(lambda_max*(h_l*u_l*u_l + 0.5*g*h_l*h_l)-lambda_min*(h_r*u_r*u_r + 0.5*g*h_r*h_r)) + (hu_r-hu_l)*lambda_max*lambda_min)/lambda_diff;
13918 /* if (h_LR < h_eps) */
13919 /* { */
13920 /* h_LR = 0.0; hu_LR = 0.0; */
13921 /* } */
13922 /* flux_h[ebNE*nQuadraturePoints_elementBoundary+ */
13923 /* k] = */
13924 /* h_l*u_l*n_lr + lambda_min*(h_LR-h_l); */
13925 
13926 /* flux_hu[ebNE*nQuadraturePoints_elementBoundary+ */
13927 /* k] = */
13928 /* (h_l*u_l*u_l + 0.5*g*h_l*h_l)*n_lr + lambda_min*(hu_LR-h_l*u_l); */
13929 
13930  }
13931 
13932  }/*k*/
13933  }/*ebnE*/
13934 }
13935 
13936 
13937 void calculateInteriorChengShuNumericalFlux(int nInteriorElementBoundaries_global,
13938  int nElementBoundaries_element,
13939  int nQuadraturePoints_elementBoundary,
13940  int nQuadraturePoints_element,
13941  int nSpace,
13942  int speedEvalFlag,
13943  int* interiorElementBoundaries,
13944  int* elementBoundaryElements,
13945  int* elementBoundaryLocalElementBoundaries,
13946  double* n,
13947  double* u,
13948  double* H,
13949  double* dH,
13950  double* H_element,
13951  double* dH_element,
13952  double* flux,
13953  double* dflux_left,
13954  double* dflux_right)
13955 {
13956  int ebNI,ebN,left_eN_global,right_eN_global,left_ebN_element,right_ebN_element,k,J;
13957  double left_flux,right_flux,u_left,u_right,left_speed,right_speed,
13958  tmp_left,tmp_right,minSpeed_element,maxSpeed_element,minSpeed,
13959  maxSpeed;
13960  /*for now use outer normal at first quadrature point for element speed calculations*/
13961 
13962  for(ebNI=0;ebNI<nInteriorElementBoundaries_global;ebNI++)
13963  {
13964  ebN = interiorElementBoundaries[ebNI];
13965  left_eN_global = elementBoundaryElements[ebN*2+0];
13966  right_eN_global = elementBoundaryElements[ebN*2+1];
13967  left_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+0];
13968  right_ebN_element = elementBoundaryLocalElementBoundaries[ebN*2+1];
13969  /*
13970 
13971  dH_{L/R} = dH_{eN_left/eN_right} . n_{eN_left}
13972 
13973  first cut, take min over interior points as well as traces
13974  dH_min = min_{\Omega_{L} \cup \Omega_{R}}(dH_L,dH_R),
13975  dH_max = max_{\Omega_{L} \cup \Omega_{R}}(dH_L,dH_R)
13976 
13977  if dH_min < 0
13978  flux_eN_left = |dH_min| (u^{L}- u^{R})
13979  else
13980  flux_eN_left = 0
13981  if dH_max > 0
13982  flux_eN_right = |dH_max| (u^{R}-u^{L})
13983  else
13984  flux_eN_right = 0
13985  */
13986  minSpeed_element=0.0; maxSpeed_element=0.0;
13987  for(k=0; k < nQuadraturePoints_element; k++)
13988  {
13989  tmp_left = 0.0; tmp_right = 0.0;
13990  /*evaluate df at interior elemnent point but compute its value
13991  dotted with normal for speed
13992  assume normal constant over face*/
13993  /*compute speed relative to left normal*/
13994  for(J=0;J<nSpace;J++)
13995  {
13996  tmp_left
13997  +=
13998  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
13999  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
14000  0*nSpace+
14001  J]
14002  *
14003  dH_element[left_eN_global*nQuadraturePoints_element*nSpace+
14004  k*nSpace+
14005  J];
14006  tmp_right
14007  +=
14008  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
14009  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
14010  0*nSpace+
14011  J]
14012  *
14013  dH_element[right_eN_global*nQuadraturePoints_element*nSpace+
14014  k*nSpace+
14015  J];
14016  }
14017  if (tmp_left < minSpeed_element || k == 0)
14018  minSpeed_element = tmp_left;
14019  if (tmp_right < minSpeed_element)
14020  minSpeed_element = tmp_right;
14021  if (tmp_right > maxSpeed_element || k == 0)
14022  maxSpeed_element = tmp_right;
14023  if (tmp_left > maxSpeed_element)
14024  maxSpeed_element = tmp_left;
14025  }/*element loop*/
14026  /*now repeat min/max over quadrature points on boundary*/
14027  minSpeed = minSpeed_element; maxSpeed = maxSpeed_element;
14028  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
14029  {
14030  tmp_left = 0.0;
14031  tmp_right = 0.0;
14032  /*compute speed relative to left normal*/
14033  for(J=0;J<nSpace;J++)
14034  {
14035  tmp_left
14036  +=
14037  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
14038  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
14039  k*nSpace+
14040  J]
14041  *
14042  dH[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
14043  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
14044  k*nSpace+
14045  J];
14046  tmp_right
14047  +=
14048  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
14049  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
14050  k*nSpace+
14051  J]
14052  *
14053  dH[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
14054  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
14055  k*nSpace+
14056  J];
14057  }
14058  if (tmp_left < minSpeed)
14059  minSpeed = tmp_left;
14060  if (tmp_right < minSpeed)
14061  minSpeed = tmp_right;
14062  if (tmp_right > maxSpeed)
14063  maxSpeed = tmp_right;
14064  if (tmp_left > maxSpeed)
14065  maxSpeed = tmp_left;
14066  }/*first k loop*/
14067  /*now set penalty/flux terms*/
14068  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
14069  {
14070  /*now recompute and try rusanov style as hack*/
14071  tmp_left = 0.0;
14072  tmp_right = 0.0;
14073  /*compute speed relative to left normal*/
14074  for(J=0;J<nSpace;J++)
14075  {
14076  tmp_left
14077  +=
14078  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
14079  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
14080  k*nSpace+
14081  J]
14082  *
14083  dH[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
14084  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
14085  k*nSpace+
14086  J];
14087  tmp_right
14088  +=
14089  n[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
14090  left_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
14091  k*nSpace+
14092  J]
14093  *
14094  dH[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary*nSpace+
14095  right_ebN_element*nQuadraturePoints_elementBoundary*nSpace+
14096  k*nSpace+
14097  J];
14098  }
14099  /*original*/
14100  left_speed = minSpeed; right_speed = maxSpeed;
14101  if (speedEvalFlag == 1)
14102  {
14103  left_speed = 0.5*(tmp_left + minSpeed); right_speed = 0.5*(tmp_right + maxSpeed);
14104  }
14105  else if (speedEvalFlag == 2)
14106  {
14107  left_speed = minSpeed_element; right_speed = maxSpeed_element;
14108  }
14109  left_flux = 0.0; right_flux = 0.0;
14110  u_left = u[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
14111  left_ebN_element*nQuadraturePoints_elementBoundary+
14112  k];
14113  u_right= u[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary+
14114  right_ebN_element*nQuadraturePoints_elementBoundary+
14115  k];
14116  if (left_speed < 0.0)/*inflow for left*/
14117  {
14118  left_flux = fabs(left_speed)*(u_left-u_right);
14119  flux[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
14120  left_ebN_element*nQuadraturePoints_elementBoundary+ k ] = left_flux;
14121  dflux_left[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
14122  left_ebN_element*nQuadraturePoints_elementBoundary+ k ] = fabs(left_speed);
14123  dflux_right[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
14124  left_ebN_element*nQuadraturePoints_elementBoundary+ k ] =-fabs(left_speed);
14125 
14126  }
14127  else
14128  {
14129  left_flux = 0.0;
14130  flux[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
14131  left_ebN_element*nQuadraturePoints_elementBoundary+ k ] = left_flux;
14132  dflux_left[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
14133  left_ebN_element*nQuadraturePoints_elementBoundary+ k ] = 0.0;
14134  dflux_right[left_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
14135  left_ebN_element*nQuadraturePoints_elementBoundary+ k ] = 0.0;
14136 
14137  }
14138  if (right_speed > 0.0)/*inflow for right*/
14139  {
14140  right_flux = fabs(right_speed)*(u_right-u_left);
14141  flux[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
14142  right_ebN_element*nQuadraturePoints_elementBoundary+ k ] = right_flux;
14143  dflux_left[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
14144  right_ebN_element*nQuadraturePoints_elementBoundary+ k ] = -fabs(right_speed);
14145  dflux_right[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
14146  right_ebN_element*nQuadraturePoints_elementBoundary+ k ] = fabs(right_speed);
14147  }
14148  else
14149  {
14150  right_flux = 0.0;
14151  flux[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
14152  right_ebN_element*nQuadraturePoints_elementBoundary+ k ] = right_flux;
14153  dflux_left[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
14154  right_ebN_element*nQuadraturePoints_elementBoundary+ k ] = 0.0;
14155  dflux_right[right_eN_global*nElementBoundaries_element*nQuadraturePoints_elementBoundary +
14156  right_ebN_element*nQuadraturePoints_elementBoundary+ k ] = 0.0;
14157  }
14158 
14159  /*mwf debug
14160  printf("HJ Cheng Shu ebN=%d eN_left=%d eN_right=%d k=%d \n",ebN,left_eN_global,right_eN_global,k);
14161  printf("HJ Cheng Shu left_speed=%g right_speed=%g u_left=%g u_right=%g maxSpeed_element=%g minSpeed_element=%g\n",
14162  left_speed,right_speed,u_left,u_right,maxSpeed_element,minSpeed_element);
14163  */
14164  }/*k*/
14165  }/*ebnI*/
14166 }
14167 double smoothedHeaviside(double eps, double phi)
14168 {
14169  double H;
14170  if (phi > eps)
14171  H=1.0;
14172  else if (phi < -eps)
14173  H=0.0;
14174  else if (phi==0.0)
14175  H=0.5;
14176  else
14177  H = 0.5*(1.0 + phi/eps + sin(M_PI*phi/eps)/M_PI);
14178  return H;
14179 }
14180 
14181 double smoothedHeaviside_integral(double eps, double phi)
14182 {
14183  double HI;
14184  if (phi > eps)
14185  {
14186  HI= phi - eps + 0.5*(eps + 0.5*eps*eps/eps - eps*cos(M_PI*eps/eps)/(M_PI*M_PI)) - 0.5*((-eps) + 0.5*(-eps)*(-eps)/eps - eps*cos(M_PI*(-eps)/eps)/(M_PI*M_PI));
14187  }
14188  else if (phi < -eps)
14189  {
14190  HI=0.0;
14191  }
14192  else
14193  {
14194  HI = 0.5*(phi + 0.5*phi*phi/eps - eps*cos(M_PI*phi/eps)/(M_PI*M_PI)) - 0.5*((-eps) + 0.5*(-eps)*(-eps)/eps - eps*cos(M_PI*(-eps)/eps)/(M_PI*M_PI));
14195  }
14196  return HI;
14197 }
14198 
14199 double smoothedDirac(double eps, double phi)
14200 {
14201  double d;
14202  if (phi > eps)
14203  d=0.0;
14204  else if (phi < -eps)
14205  d=0.0;
14206  else
14207  d = 0.5*(1.0 + cos(M_PI*phi/eps))/eps;
14208  return d;
14209 }
14210 
14211 void applySeepageFace(int nExteriorElementBoundaries_global,
14212  int nQuadraturePoints_elementBoundary,
14213  int nSpace,
14214  int* exteriorElementBoundaries,
14215  int* elementBoundaryElements,
14216  int* elementBoundaryLocalElementBoundaries,
14217  int* isSeepageFace,
14218  int* isDOFBoundary,
14219  double epsFact,
14220  double* elementDiameters,
14221  double* g,
14222  double* n,
14223  double* grad_u,
14224  double* u,
14225  double* advectiveFlux,
14226  double* diffusiveFlux)
14227 {
14228  int ebNE,ebN,eN_global,k,J;
14229  double flow_direction,eps;
14230  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
14231  {
14232  ebN = exteriorElementBoundaries[ebNE];
14233  eN_global = elementBoundaryElements[ebN*2+0];
14234  eps=epsFact*elementDiameters[ebN];
14235  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
14236  {
14237  if (isSeepageFace[ebNE])
14238  {
14239  flow_direction=0.0;
14240  for(J=0;J<nSpace;J++)
14241  {
14242  flow_direction
14243  +=
14244  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14245  k*nSpace+
14246  J]
14247  *
14248  (g[J]-grad_u[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14249  k*nSpace+
14250  J]);
14251  }
14252  isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] = 1;
14253  if (flow_direction < 0.0 || u[ebNE*nQuadraturePoints_elementBoundary+k] < 0.0) //flow is coming back in and/or unsaturated
14254  {
14255  isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] = 0;
14256  advectiveFlux[ebNE*nQuadraturePoints_elementBoundary+
14257  k] = 0.0;
14258  diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary+
14259  k] = 0.0;
14260  }
14261  else if (u[ebNE*nQuadraturePoints_elementBoundary+k] < eps) //unsaturated
14262  {
14263  isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] = 1;
14264  advectiveFlux[ebNE*nQuadraturePoints_elementBoundary+
14265  k]*=smoothedHeaviside(eps,u[ebNE*nQuadraturePoints_elementBoundary+k]);
14266  diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary+
14267  k]*=smoothedHeaviside(eps,u[ebNE*nQuadraturePoints_elementBoundary+k]);
14268  }
14269  }
14270  }
14271  }
14272 }
14273 
14275  int* colind,
14276  int nExteriorElementBoundaries_global,
14277  int nQuadraturePoints_elementBoundary,
14278  int nSpace,
14279  int* isSeepageFace,
14280  int* isDOFBoundary,
14281  double* n,
14282  double* bc_u,
14283  double* K,
14284  double* grad_psi,
14285  double* u,
14286  double* K_rho_g,
14287  double* penalty,
14288  double* diffusiveFlux)
14289 {
14290  int ebNE,k,I,m,nnz=rowptr[nSpace];
14291  double flux,v_I;
14292  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
14293  {
14294  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
14295  {
14296  if (isSeepageFace[ebNE] || isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k])
14297  {
14298  flux = 0.0;
14299  for(I=0;I<nSpace;I++)
14300  {
14301  //initialize to gravity term
14302  v_I = K_rho_g[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14303  k*nSpace+
14304  I];
14305  //add pressure head term
14306  for(m=rowptr[I];m<rowptr[I+1];m++)
14307  {
14308  v_I
14309  -=
14310  K[ebNE*nQuadraturePoints_elementBoundary*nnz+
14311  k*nnz+
14312  m]
14313  *
14314  grad_psi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14315  k*nSpace+
14316  colind[m]];
14317  }
14318  flux +=
14319  v_I
14320  *
14321  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14322  k*nSpace+
14323  I];
14324  }
14325  //add Dirichlet penalty
14326  if (isSeepageFace[ebNE])
14327  bc_u[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
14328  diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary+k] =
14329  flux
14330  +
14331  penalty[ebNE*nQuadraturePoints_elementBoundary+k]
14332  *
14333  (u[ebNE*nQuadraturePoints_elementBoundary+k]
14334  -
14335  bc_u[ebNE*nQuadraturePoints_elementBoundary+k]);
14336  /* printf("Seepage Face %d %d psi = %12.5e psi_bc = %12.5e penalty = %12.5e flux = %12.5e \n", */
14337  /* ebNE, */
14338  /* isSeepageFace[ebNE], */
14339  /* u[ebNE*nQuadraturePoints_elementBoundary+k], */
14340  /* bc_u[ebNE*nQuadraturePoints_elementBoundary+k], */
14341  /* penalty[ebNE*nQuadraturePoints_elementBoundary+k], */
14342  /* flux); */
14343  if (isSeepageFace[ebNE])
14344  {
14345  //if (u[ebNE*nQuadraturePoints_elementBoundary+k] >= -0.01 || diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary+k] > 0.0)
14346  if (diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary+k] > 0.0)
14347  /* if ( */
14348  /* // (u[ebNE*nQuadraturePoints_elementBoundary+k] > 0.0) && */
14349  /* (flux > 0.0) */
14350  /* ) */
14351  {
14352  isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] = 1;
14353  }
14354  else
14355  {
14356  isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] = 0;
14357  diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
14358  }
14359  }
14360  }
14361  }
14362  }
14363 }
14364 
14366  int* colind,
14367  int nExteriorElementBoundaries_global,
14368  int nQuadraturePoints_elementBoundary,
14369  int nDOF_trial_element,
14370  int nSpace,
14371  int* isDOFBoundary,
14372  double* n,
14373  double* bc_u,
14374  double* K,
14375  double* dK,
14376  double* grad_psi,
14377  double* grad_v,
14378  double* u,
14379  double* dK_rho_g,
14380  double* v,
14381  double* penalty,
14382  double* fluxJacobian)
14383 {
14384  int ebNE,k,j,I,m,nnz=rowptr[nSpace];
14385  double dFlux_j,dv_I_j;
14386  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
14387  {
14388  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
14389  {
14390  if (isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k])
14391  {
14392  for (j=0;j<nDOF_trial_element;j++)
14393  {
14394  dFlux_j = 0.0;
14395  for(I=0;I<nSpace;I++)
14396  {
14397  //initialize to gravity term
14398  dv_I_j = dK_rho_g[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14399  k*nSpace+
14400  I]
14401  *
14402  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14403  k*nDOF_trial_element+
14404  j];
14405  //add pressure head term
14406  for(m=rowptr[I];m<rowptr[I+1];m++)
14407  {
14408  dv_I_j
14409  -=
14410  K[ebNE*nQuadraturePoints_elementBoundary*nnz+
14411  k*nnz+
14412  m]
14413  *
14414  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
14415  k*nDOF_trial_element*nSpace+
14416  j*nSpace+
14417  colind[m]]
14418  +
14419  dK[ebNE*nQuadraturePoints_elementBoundary*nnz+
14420  k*nnz+
14421  m]
14422  *
14423  grad_psi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14424  k*nSpace+
14425  colind[m]]
14426  *v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14427  k*nDOF_trial_element+
14428  j];
14429  }
14430  dFlux_j +=
14431  dv_I_j
14432  *
14433  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14434  k*nSpace+
14435  I];
14436  }
14437  //add Dirichlet penalty
14438  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14439  k*nDOF_trial_element+
14440  j]
14441  =
14442  dFlux_j
14443  +
14444  penalty[ebNE*nQuadraturePoints_elementBoundary+k]
14445  *v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14446  k*nDOF_trial_element+
14447  j];
14448  }
14449  }
14450  }
14451  }
14452 }
14453 
14454 void applySeepageFaceJacobian(int nExteriorElementBoundaries_global,
14455  int nQuadraturePoints_elementBoundary,
14456  int nDOF_trial_element,
14457  int nSpace,
14458  int* exteriorElementBoundaries,
14459  int* elementBoundaryElements,
14460  int* elementBoundaryLocalElementBoundaries,
14461  int* isSeepageFace,
14462  double epsFact,
14463  double* elementDiameters,
14464  double* g,
14465  double* n,
14466  double* grad_u,
14467  double* u,
14468  double* advectiveFlux,
14469  double* diffusiveFlux,
14470  double* v,
14471  double* fluxJacobian)
14472 {
14473  int ebNE,ebN,eN_global,k,J,j;
14474  double flow_direction,eps;
14475  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
14476  {
14477  ebN = exteriorElementBoundaries[ebNE];
14478  eN_global = elementBoundaryElements[ebN*2+0];
14479  eps=epsFact*elementDiameters[ebN];
14480  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
14481  {
14482  if (isSeepageFace[ebNE])
14483  {
14484  flow_direction=0.0;
14485  for(J=0;J<nSpace;J++)
14486  {
14487  flow_direction
14488  +=
14489  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14490  k*nSpace+
14491  J]
14492  *
14493  (g[J]-grad_u[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14494  k*nSpace+
14495  J]);
14496  }
14497  for(j=0;j<nDOF_trial_element;j++)
14498  {
14499  if (flow_direction < 0.0 || u[ebNE*nQuadraturePoints_elementBoundary+k] < 0.0) //flow is coming back in and/or unsaturated
14500  {
14501  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14502  k*nDOF_trial_element+
14503  j] = 0.0;
14504  }
14505  else if (u[ebNE*nQuadraturePoints_elementBoundary+k] < eps)//unsaturated
14506  {
14507  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14508  k*nDOF_trial_element+
14509  j]*=smoothedHeaviside(eps,u[ebNE*nQuadraturePoints_elementBoundary+k]);
14510  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14511  k*nDOF_trial_element+
14512  j] += (advectiveFlux[ebNE*nQuadraturePoints_elementBoundary+
14513  k] +
14514  diffusiveFlux[ebNE*nQuadraturePoints_elementBoundary+
14515  k])
14516  *
14517  smoothedDirac(eps,u[ebNE*nQuadraturePoints_elementBoundary+k])
14518  *
14519  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14520  k*nDOF_trial_element+
14521  j];
14522 
14523  }
14524  }
14525  }
14526  }
14527  }
14528 }
14529 
14530 void calculateGlobalExteriorNumericalStressFlux(int nExteriorElementBoundaries_global,
14531  int nQuadraturePoints_elementBoundary,
14532  int nSpace,
14533  int* exteriorElementBoundaries,
14534  int* elementBoundaryElements,
14535  int* elementBoundaryLocalElementBoundaries,
14536  int *isDOFBoundary_u,
14537  int *isDOFBoundary_v,
14538  int *isDOFBoundary_w,
14539  double* n,
14540  double* bc_u,
14541  double* bc_v,
14542  double* bc_w,
14543  double* sigma,
14544  double* u,
14545  double* v,
14546  double* w,
14547  double* penalty,
14548  double* stressFlux_u,
14549  double* stressFlux_v,
14550  double* stressFlux_w)
14551 {
14552  int ebNE,k,nSpace2=nSpace*nSpace;
14553  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
14554  {
14555  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
14556  {
14557  //cek hack debug
14558  penalty[ebNE*nQuadraturePoints_elementBoundary+k] = 1.0e5;
14559  //
14560  double *normal = n + ebNE*nQuadraturePoints_elementBoundary*nSpace+k*nSpace;
14561  double *stress = sigma + ebNE*nQuadraturePoints_elementBoundary*nSpace2+k*nSpace2;
14562  if (isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
14563  {
14564  double u_jump = -penalty[ebNE*nQuadraturePoints_elementBoundary+k]
14565  *
14566  (u[ebNE*nQuadraturePoints_elementBoundary+k]
14567  - bc_u[ebNE*nQuadraturePoints_elementBoundary+k]);
14568  stressFlux_u[ebNE*nQuadraturePoints_elementBoundary+k] = -(stress[0]*normal[0] + stress[1]*normal[1] + stress[2]*normal[2] + u_jump);
14569  //stressFlux_u[ebNE*nQuadraturePoints_elementBoundary+k] = -(u_jump);
14570  }
14571  if (isDOFBoundary_v[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
14572  {
14573  double v_jump = -penalty[ebNE*nQuadraturePoints_elementBoundary+k]*
14574  (v[ebNE*nQuadraturePoints_elementBoundary+k]
14575  - bc_v[ebNE*nQuadraturePoints_elementBoundary+k]);
14576  stressFlux_v[ebNE*nQuadraturePoints_elementBoundary+k] = -(stress[3]*normal[0] + stress[4]*normal[1] + stress[5]*normal[2] + v_jump);
14577  //stressFlux_v[ebNE*nQuadraturePoints_elementBoundary+k] = -(v_jump);
14578  }
14579  if (isDOFBoundary_w[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
14580  {
14581  double w_jump = -penalty[ebNE*nQuadraturePoints_elementBoundary+k]
14582  *
14583  (w[ebNE*nQuadraturePoints_elementBoundary+k]
14584  - bc_w[ebNE*nQuadraturePoints_elementBoundary+k]);
14585  stressFlux_w[ebNE*nQuadraturePoints_elementBoundary+k] = -(stress[6]*normal[0] + stress[7]*normal[1] + stress[8]*normal[2] + w_jump);
14586  //stressFlux_w[ebNE*nQuadraturePoints_elementBoundary+k] = -(w_jump);
14587  }
14588  }
14589  }
14590 }
14591 
14592 void updateExteriorNumericalStressFluxJacobian(int nExteriorElementBoundaries_global,
14593  int nQuadraturePoints_elementBoundary,
14594  int nDOF_trial_element,
14595  int nSpace,
14596  int* exteriorElementBoundaries,
14597  int* elementBoundaryElements,
14598  int* elementBoundaryLocalElementBoundaries,
14599  int* isDOFBoundary_u,
14600  int* isDOFBoundary_v,
14601  int* isDOFBoundary_w,
14602  int* isStressBoundary_u,
14603  int* isStressBoundary_v,
14604  int* isStressBoundary_w,
14605  double* n,
14606  double* dstress_u_u,
14607  double* dstress_u_v,
14608  double* dstress_u_w,
14609  double* dstress_v_u,
14610  double* dstress_v_v,
14611  double* dstress_v_w,
14612  double* dstress_w_u,
14613  double* dstress_w_v,
14614  double* dstress_w_w,
14615  double* v,
14616  double* grad_v,
14617  double* penalty,
14618  double* fluxJacobian_u_u,
14619  double* fluxJacobian_u_v,
14620  double* fluxJacobian_u_w,
14621  double* fluxJacobian_v_u,
14622  double* fluxJacobian_v_v,
14623  double* fluxJacobian_v_w,
14624  double* fluxJacobian_w_u,
14625  double* fluxJacobian_w_v,
14626  double* fluxJacobian_w_w)
14627 {
14628  //int ebNE,ebN,eN_global,k,j,j_global,I,J,nSpace2=nSpace*nSpace;
14629  int ebNE,k,j,I,J,nSpace2=nSpace*nSpace;
14630  //double Jacobian,diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2,max_a;
14631  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
14632  {
14633  //ebN = exteriorElementBoundaries[ebNE];
14634  //eN_global = elementBoundaryElements[ebN*2+0];
14635  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
14636  {
14637  if(isDOFBoundary_u[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
14638  {
14639  for(j=0;j<nDOF_trial_element;j++)
14640  {
14641  fluxJacobian_u_u[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14642  k*nDOF_trial_element+
14643  j]
14644  =penalty[ebNE*nQuadraturePoints_elementBoundary+k]
14645  *
14646  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14647  k*nDOF_trial_element+
14648  j];
14649  for (I=0;I<nSpace;I++)
14650  for (J=0;J<nSpace;J++)
14651  {
14652  fluxJacobian_u_u[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14653  k*nDOF_trial_element+
14654  j]
14655  -=
14656  dstress_u_u[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
14657  k*nSpace2+
14658  I*nSpace+
14659  J]
14660  *
14661  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
14662  k*nDOF_trial_element*nSpace+
14663  j*nSpace+
14664  J]
14665  *
14666  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14667  k*nSpace+
14668  I];
14669  fluxJacobian_u_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14670  k*nDOF_trial_element+
14671  j]
14672  -=
14673  dstress_u_v[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
14674  k*nSpace2+
14675  I*nSpace+
14676  J]
14677  *
14678  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
14679  k*nDOF_trial_element*nSpace+
14680  j*nSpace+
14681  J]
14682  *
14683  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14684  k*nSpace+
14685  I];
14686  fluxJacobian_u_w[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14687  k*nDOF_trial_element+
14688  j]
14689  -=
14690  dstress_u_w[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
14691  k*nSpace2+
14692  I*nSpace+
14693  J]
14694  *
14695  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
14696  k*nDOF_trial_element*nSpace+
14697  j*nSpace+
14698  J]
14699  *
14700  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14701  k*nSpace+
14702  I];
14703  }
14704  }
14705  }
14706  if(isDOFBoundary_v[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
14707  {
14708  for(j=0;j<nDOF_trial_element;j++)
14709  {
14710  fluxJacobian_v_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14711  k*nDOF_trial_element+
14712  j]
14713  =penalty[ebNE*nQuadraturePoints_elementBoundary+
14714  k]
14715  *
14716  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14717  k*nDOF_trial_element+
14718  j];
14719  for (I=0;I<nSpace;I++)
14720  for (J=0;J<nSpace;J++)
14721  {
14722  fluxJacobian_v_u[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14723  k*nDOF_trial_element+
14724  j]
14725  -=
14726  dstress_v_u[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
14727  k*nSpace2+
14728  I*nSpace+
14729  J]
14730  *
14731  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
14732  k*nDOF_trial_element*nSpace+
14733  j*nSpace+
14734  J]
14735  *
14736  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14737  k*nSpace+
14738  I];
14739  fluxJacobian_v_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14740  k*nDOF_trial_element+
14741  j]
14742  -=
14743  dstress_v_v[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
14744  k*nSpace2+
14745  I*nSpace+
14746  J]
14747  *
14748  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
14749  k*nDOF_trial_element*nSpace+
14750  j*nSpace+
14751  J]
14752  *
14753  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14754  k*nSpace+
14755  I];
14756  fluxJacobian_v_w[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14757  k*nDOF_trial_element+
14758  j]
14759  -=
14760  dstress_v_w[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
14761  k*nSpace2+
14762  I*nSpace+
14763  J]
14764  *
14765  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
14766  k*nDOF_trial_element*nSpace+
14767  j*nSpace+
14768  J]
14769  *
14770  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14771  k*nSpace+
14772  I];
14773  }
14774  }
14775  }
14776  if(isDOFBoundary_w[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
14777  {
14778  for(j=0;j<nDOF_trial_element;j++)
14779  {
14780  fluxJacobian_w_w[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14781  k*nDOF_trial_element+
14782  j]
14783  =
14784  penalty[ebNE*nQuadraturePoints_elementBoundary+
14785  k]
14786  *
14787  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14788  k*nDOF_trial_element+
14789  j];
14790  for (I=0;I<nSpace;I++)
14791  for (J=0;J<nSpace;J++)
14792  {
14793  fluxJacobian_w_u[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14794  k*nDOF_trial_element+
14795  j]
14796  -=
14797  dstress_w_u[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
14798  k*nSpace2+
14799  I*nSpace+
14800  J]
14801  *
14802  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
14803  k*nDOF_trial_element*nSpace+
14804  j*nSpace+
14805  J]
14806  *
14807  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14808  k*nSpace+
14809  I];
14810  fluxJacobian_w_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14811  k*nDOF_trial_element+
14812  j]
14813  -=
14814  dstress_w_v[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
14815  k*nSpace2+
14816  I*nSpace+
14817  J]
14818  *
14819  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
14820  k*nDOF_trial_element*nSpace+
14821  j*nSpace+
14822  J]
14823  *
14824  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14825  k*nSpace+
14826  I];
14827  fluxJacobian_w_w[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
14828  k*nDOF_trial_element+
14829  j]
14830  -=
14831  dstress_w_w[ebNE*nQuadraturePoints_elementBoundary*nSpace2+
14832  k*nSpace2+
14833  I*nSpace+
14834  J]
14835  *
14836  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
14837  k*nDOF_trial_element*nSpace+
14838  j*nSpace+
14839  J]
14840  *
14841  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14842  k*nSpace+
14843  I];
14844  }
14845  }
14846  }
14847  }
14848  }
14849 }
14850 
14856  double penalty_floor,
14857  int nExteriorElementBoundaries_global,
14858  int nQuadraturePoints_elementBoundary,
14859  int nSpace,
14860  int* rowptr,
14861  int* colind,
14862  int* exteriorElementBoundaries,
14863  int* elementBoundaryElements,
14864  int* elementBoundaryLocalElementBoundaries,
14865  int* isDOFBoundary,
14866  int* fluxBoundaryFlag, /*0 no flow, 1 outflow */
14867  double* n,
14868  double* bc_a,
14869  double* bc_grad_phi,
14870  double* bc_u,
14871  double* a,
14872  double* grad_phi,
14873  double* u,
14874  double* penalty,
14875  double* flux)
14876 {
14877  int ebNE,k,I,m,nnz=rowptr[nSpace];
14878  double diffusiveVelocityComponent_I,penaltyFlux,max_a;
14879  double potential_gradient=0.0;
14880  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
14881  {
14882  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
14883  {
14884  /*figure out if the potential gradient is pointing out or not to upwind*/
14885  potential_gradient=0.;
14886  for (I=0; I < nSpace; I++)
14887  {
14888  potential_gradient += grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace +
14889  k*nSpace + I]
14890  *
14891  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
14892  k*nSpace+
14893  I];
14894  }
14895  /* apply diffusive flux term if it's a Dirichlet boundary or outflow boundary and the potential gradient is out*/
14896  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1 || (potential_gradient > 0.0 && fluxBoundaryFlag == 1))
14897  {
14898  flux[ebNE*nQuadraturePoints_elementBoundary+k] = 0.0;
14899  max_a=0.0;
14900  for(I=0;I<nSpace;I++)
14901  {
14902  diffusiveVelocityComponent_I=0.0;
14903  for(m=rowptr[I];m<rowptr[I+1];m++)
14904  {
14905  diffusiveVelocityComponent_I
14906  -=
14907  a[ebNE*nQuadraturePoints_elementBoundary*nnz+
14908  k*nnz+
14909  m]
14910  *
14911  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14912  k*nSpace+colind[m]];
14913  max_a = fmax(max_a,a[ebNE*nQuadraturePoints_elementBoundary*nnz+
14914  k*nnz+
14915  m]);
14916  }
14917  flux[ebNE*nQuadraturePoints_elementBoundary+k]
14918  +=
14919  diffusiveVelocityComponent_I
14920  *
14921  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
14922  k*nSpace+
14923  I];
14924  }
14925  max_a = fmax(penalty_floor,max_a);
14926  if (isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k]==1)
14927  {
14928  penaltyFlux = penalty[ebNE*nQuadraturePoints_elementBoundary+
14929  k]
14930  *
14931  (u[ebNE*nQuadraturePoints_elementBoundary+
14932  k]
14933  -
14934  bc_u[ebNE*nQuadraturePoints_elementBoundary+
14935  k]);
14936 
14937  if (scale_penalty) penaltyFlux *= max_a;
14938  flux[ebNE*nQuadraturePoints_elementBoundary+k] += penaltyFlux;
14939  }
14940  }
14941  }
14942  }
14943 }
14944 
14946  double penalty_floor,
14947  int nExteriorElementBoundaries_global,
14948  int nQuadraturePoints_elementBoundary,
14949  int nDOF_trial_element,
14950  int nSpace,
14951  int* rowptr,
14952  int* colind,
14953  int* l2g,
14954  int* exteriorElementBoundaries,
14955  int* elementBoundaryElements,
14956  int* elementBoundaryLocalElementBoundaries,
14957  int* isDOFBoundary,
14958  int* fluxBoundaryFlag, /*0 no flow, 1 outflow */
14959  double* n,
14960  double* a,
14961  double* da,
14962  double* grad_phi,
14963  double* dphi,
14964  double* v,
14965  double* grad_v,
14966  double* penalty,
14967  double* fluxJacobian)
14968 {
14969  int ebNE,ebN,eN_global,k,j,j_global,I,m,nnz=rowptr[nSpace];
14970  double Jacobian,diffusiveVelocityComponent_I_Jacobian,diffusiveVelocityComponent_I_Jacobian2,max_a;
14971  double potential_gradient=0.;
14972  for(ebNE=0;ebNE<nExteriorElementBoundaries_global;ebNE++)
14973  {
14974  ebN = exteriorElementBoundaries[ebNE];
14975  eN_global = elementBoundaryElements[ebN*2+0];
14976  for(k=0;k<nQuadraturePoints_elementBoundary;k++)
14977  {
14978  /*figure out if the potential gradient is pointing out or not to upwind*/
14979  potential_gradient=0.;
14980  for (I=0; I < nSpace; I++)
14981  {
14982  potential_gradient += grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace +
14983  k*nSpace + I]
14984  *
14985  n[ebNE*nQuadraturePoints_elementBoundary*nSpace +
14986  k*nSpace+
14987  I];
14988  }
14989  /* apply diffusive flux term if it's a Dirichlet boundary or outflow boundary and the potential gradient is out*/
14990  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] >= 1 || (potential_gradient > 0.0 && fluxBoundaryFlag == 1))
14991  {
14992  for(j=0;j<nDOF_trial_element;j++)
14993  {
14994  Jacobian=0.0;
14995  j_global = l2g[eN_global*nDOF_trial_element+j];
14996  max_a=0.0;
14997  for(I=0;I<nSpace;I++)
14998  {
14999  diffusiveVelocityComponent_I_Jacobian=0.0;
15000  diffusiveVelocityComponent_I_Jacobian2=0.0;
15001  for(m=rowptr[I];m<rowptr[I+1];m++)
15002  {
15003  diffusiveVelocityComponent_I_Jacobian
15004  -=
15005  da[ebNE*nQuadraturePoints_elementBoundary*nnz+
15006  k*nnz+
15007  m]
15008  *
15009  grad_phi[ebNE*nQuadraturePoints_elementBoundary*nSpace+
15010  k*nSpace+
15011  colind[m]];
15012  diffusiveVelocityComponent_I_Jacobian2
15013  -=
15014  a[ebNE*nQuadraturePoints_elementBoundary*nnz+
15015  k*nnz+
15016  m]
15017  *
15018  grad_v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element*nSpace+
15019  k*nDOF_trial_element*nSpace+
15020  j*nSpace+
15021  colind[m]];
15022  max_a = fmax(max_a,a[ebNE*nQuadraturePoints_elementBoundary*nnz+
15023  k*nnz+
15024  m]);
15025 
15026  }
15027  Jacobian
15028  +=
15029  (diffusiveVelocityComponent_I_Jacobian
15030  *
15031  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
15032  k*nDOF_trial_element+
15033  j]
15034  +
15035  diffusiveVelocityComponent_I_Jacobian2*
15036  dphi[j_global])
15037  *
15038  n[ebNE*nQuadraturePoints_elementBoundary*nSpace+
15039  k*nSpace+
15040  I];
15041  }
15042  max_a = fmax(penalty_floor,max_a);
15043 
15044  if(isDOFBoundary[ebNE*nQuadraturePoints_elementBoundary+k] == 1)
15045  {
15046  double penaltyJacobian = penalty[ebNE*nQuadraturePoints_elementBoundary+
15047  k]
15048  *
15049  v[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
15050  k*nDOF_trial_element+
15051  j];
15052  if (scale_penalty) penaltyJacobian *= max_a;
15053 
15054  Jacobian += penaltyJacobian;
15055  }
15056  fluxJacobian[ebNE*nQuadraturePoints_elementBoundary*nDOF_trial_element+
15057  k*nDOF_trial_element+
15058  j]
15059  += Jacobian;
15060  }
15061  }
15062  }
15063  }
15064 }
smoothedHeaviside
double smoothedHeaviside(double eps, double phi)
Definition: numericalFlux.c:14167
updateExteriorNumericalDiffusiveFluxJacobian_free
void updateExteriorNumericalDiffusiveFluxJacobian_free(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *l2g, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *a, double *da, double *grad_phi, double *dphi, double *v, double *grad_v, double *penalty, double *fluxJacobian)
Definition: numericalFlux.c:3593
calculateGlobalExteriorNumericalStressFlux
void calculateGlobalExteriorNumericalStressFlux(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary_u, int *isDOFBoundary_v, int *isDOFBoundary_w, double *n, double *bc_u, double *bc_v, double *bc_w, double *sigma, double *u, double *v, double *w, double *penalty, double *stressFlux_u, double *stressFlux_v, double *stressFlux_w)
Definition: numericalFlux.c:14530
updateInteriorNumericalDiffusiveFluxJacobian_LDG_upwind
void updateInteriorNumericalDiffusiveFluxJacobian_LDG_upwind(int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *a, double *da, double *dphi, double *V, double *DV, double *DV_eb, double *v, double *penalty, double *fluxJacobian, double *fluxJacobian_eb)
Update the advective flux at at interior element boundaries.
Definition: numericalFlux.c:8169
calculateGlobalExteriorNumericalAdvectiveFlux_NoBC
void calculateGlobalExteriorNumericalAdvectiveFlux_NoBC(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *inflowFlag, double *n, double *f, double *df, double *flux, double *dflux_left)
Update the advective flux at exterior element boundaries.
Definition: numericalFlux.c:4379
calculateExteriorNumericalAdvectiveFluxRusanovWithEigenvalueBound
void calculateExteriorNumericalAdvectiveFluxRusanovWithEigenvalueBound(double safetyFactor, int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nQuadraturePoints_element, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *inflowFlag, double *n, double *bc_u, double *bc_f, double *u, double *f, double *lambda_bar, double *flux)
Definition: numericalFlux.c:784
updateExteriorNumericalDiffusiveFluxJacobian
void updateExteriorNumericalDiffusiveFluxJacobian(int scale_penalty, double penalty_floor, int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *l2g, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *a, double *da, double *grad_phi, double *dphi, double *v, double *grad_v, double *penalty, double *fluxJacobian)
Update the diffusive flux Jacobian at exterior element boundary quadrature points.
Definition: numericalFlux.c:2743
w
#define w(x)
Definition: jf.h:22
calculateGlobalExteriorNumericalAdvectiveFluxStokesP2D
void calculateGlobalExteriorNumericalAdvectiveFluxStokesP2D(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary_p, int *isDOFBoundary_u, int *isDOFBoundary_v, double *n, double *bc_f, double *bc_fpu, double *bc_fpv, double *f, double *fpu, double *fpv, double *df_du, double *df_dv, double *dfpu_dp, double *dfpv_dp, double *flux, double *fluxpu, double *fluxpv, double *dflux_du, double *dflux_dv, double *dfluxpu_dp, double *dfluxpv_dp)
Calculate the advective flux at at exterior element boundaries.
Definition: numericalFlux.c:6472
TR_ALPHA
#define TR_ALPHA
Definition: numericalFlux.c:3
updateGlobalExteriorNumericalDiffusiveFluxJacobian
void updateGlobalExteriorNumericalDiffusiveFluxJacobian(int scale_penalty, double penalty_floor, int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *l2g, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *a, double *da, double *grad_phi, double *dphi, double *v, double *grad_v, double *penalty, double *fluxJacobian)
Update the diffusive flux Jacobian at exterior element boundary quadrature points.
Definition: numericalFlux.c:2973
calculateExteriorNumericalAdvectiveFluxStokesP2D
void calculateExteriorNumericalAdvectiveFluxStokesP2D(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary_p, int *isDOFBoundary_u, int *isDOFBoundary_v, double *n, double *bc_f, double *bc_fpu, double *bc_fpv, double *f, double *fpu, double *fpv, double *df_du, double *df_dv, double *dfpu_dp, double *dfpv_dp, double *flux, double *fluxpu, double *fluxpv, double *dflux_du, double *dflux_dv, double *dfluxpu_dp, double *dfluxpv_dp)
Calculate the advective flux at at exterior element boundaries.
Definition: numericalFlux.c:4918
HI
#define HI
Definition: Headers.h:4
calculateGlobalExteriorNumericalFluxDarcyFCPP_sd
void calculateGlobalExteriorNumericalFluxDarcyFCPP_sd(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *rowptr_ww, int *colind_ww, int *rowptr_nn, int *colind_nn, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_uw, const int *isDOFBoundary_un, int fluxBoundaryFlag_uw, int fluxBoundaryFlag_un, const double *n, const double *bc_a_ww, const double *bc_a_nn, const double *bc_grad_phi_w, const double *bc_grad_phi_n, const double *bc_psi_w, const double *bc_psi_c, const double *bc_psi_n, const double *a_ww, const double *a_nn, const double *grad_phi_w, const double *grad_phi_n, const double *psi_w, const double *psi_c, const double *psi_n, const double *penalty_w, const double *penalty_n, double *diffusiveFlux_ww, double *diffusiveFlux_nn)
Definition: numericalFlux.c:12150
calculateGlobalExteriorNumericalDiffusiveFlux
void calculateGlobalExteriorNumericalDiffusiveFlux(int scale_penalty, double penalty_floor, int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *bc_a, double *bc_grad_phi, double *bc_u, double *a, double *grad_phi, double *u, double *penalty, double *flux)
Calculate the diffusive flux at exterior element boundary quadrature points.
Definition: numericalFlux.c:2093
calculateGlobalExteriorNumericalFluxDarcyFC_sd
void calculateGlobalExteriorNumericalFluxDarcyFC_sd(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *rowptr_ww, int *colind_ww, int *rowptr_nn, int *colind_nn, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_uw, const int *isDOFBoundary_un, int fluxBoundaryFlag_uw, int fluxBoundaryFlag_un, const double *n, const double *bc_a_ww, const double *bc_a_nn, const double *bc_grad_phi_w, const double *bc_grad_phi_n, const double *bc_s_w, const double *bc_psi_w, const double *bc_psi_n, const double *a_ww, const double *a_nn, const double *grad_phi_w, const double *grad_phi_n, const double *s_w, const double *psi_w, const double *psi_n, const double *penalty_w, const double *penalty_n, double *diffusiveFlux_ww, double *diffusiveFlux_nn)
Definition: numericalFlux.c:10994
calculateGlobalExteriorNumericalFluxDarcySplitPressure
void calculateGlobalExteriorNumericalFluxDarcySplitPressure(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_u, const double *n, const double *bc_a, const double *bc_grad_phi, const double *bc_psi_w, const double *bc_psi_n, const double *a, const double *grad_phi, const double *psi_w, const double *psi_n, const double *penalty, double *diffusiveFlux)
Definition: numericalFlux.c:12997
TR_ALPHA_EXT
#define TR_ALPHA_EXT
Definition: numericalFlux.c:4
calculateGlobalExteriorNumericalFluxDarcyFC_diffusiveFluxJacobian_sd
void calculateGlobalExteriorNumericalFluxDarcyFC_diffusiveFluxJacobian_sd(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int nDOF_trial_element, int *rowptr_ww, int *colind_ww, int *rowptr_nn, int *colind_nn, const int *l2g, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_uw, const int *isDOFBoundary_un, int fluxBoundaryFlag_uw, int fluxBoundaryFlag_un, const double *n, const double *a_ww, const double *da_ww_dw, const double *da_ww_dn, const double *a_nn, const double *da_nn_dw, const double *da_nn_dn, const double *grad_phi_w, const double *grad_phi_n, const double *dphi_w_w, const double *dphi_w_n, const double *dphi_n_w, const double *dphi_n_n, const double *s_w, const double *psi_w, const double *psi_n, const double *dpsi_n_dsw, const double *dpsi_n_dpsiw, const double *v, const double *grad_v, const double *penalty_w, const double *penalty_n, double *fluxJacobian_ww, double *fluxJacobian_wn, double *fluxJacobian_nw, double *fluxJacobian_nn)
Definition: numericalFlux.c:11496
calculateExteriorNumericalDiffusiveFlux_free_sd
void calculateExteriorNumericalDiffusiveFlux_free_sd(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *rowptr, int *colind, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *bc_a, double *bc_grad_phi, double *bc_u, double *a, double *grad_phi, double *u, double *penalty, double *flux)
Definition: numericalFlux.c:2580
updateGlobalExteriorNumericalDiffusiveFluxJacobian_sd
void updateGlobalExteriorNumericalDiffusiveFluxJacobian_sd(int scale_penalty, double penalty_floor, int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *rowptr, int *colind, int *l2g, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *a, double *da, double *grad_phi, double *dphi, double *v, double *grad_v, double *penalty, double *fluxJacobian)
Definition: numericalFlux.c:3077
neg
double neg(double a)
Definition: testFMMandFSW.cpp:10
updateInteriorNumericalDiffusiveFluxJacobian_LDG_upwind_sd
void updateInteriorNumericalDiffusiveFluxJacobian_LDG_upwind_sd(int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *rowptr, int *colind, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *a, double *da, double *dphi, double *V, double *DV, double *DV_eb, double *v, double *penalty, double *fluxJacobian, double *fluxJacobian_eb)
Definition: numericalFlux.c:8347
f
Double f
Definition: Headers.h:64
calculateExteriorLesaintRaviartNumericalFlux
void calculateExteriorLesaintRaviartNumericalFlux(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int speedEvalFlag, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *inflowFlag, double *n, double *bc_u, double *bc_H, double *bc_dH, double *u, double *H, double *dH, double *flux, double *dflux)
Definition: numericalFlux.c:9569
updateGlobalExteriorNumericalDiffusiveFluxJacobian_free
void updateGlobalExteriorNumericalDiffusiveFluxJacobian_free(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *l2g, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *a, double *da, double *grad_phi, double *dphi, double *v, double *grad_v, double *penalty, double *fluxJacobian)
Definition: numericalFlux.c:3768
calculateGlobalExteriorNumericalAdvectiveFlux
void calculateGlobalExteriorNumericalAdvectiveFlux(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *inflowFlag, double *n, double *bc_u, double *bc_f, double *bc_df, double *u, double *f, double *df, double *flux, double *dflux)
Calculate the advective flux at at exterior element boundaries.
Definition: numericalFlux.c:4632
shallowWater_phi
void shallowWater_phi(double g, double h_l, double h_r, double u_l, double u_r, double c_l, double c_r, double h, double *phi, double *dphi, double *u_f, int *w_1, int *w_2)
Definition: numericalFlux.c:13163
calculateExteriorNumericalDiffusiveFlux_LDG_upwind
void calculateExteriorNumericalDiffusiveFlux_LDG_upwind(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *u, double *a, double *phi_bc, double *phi, double *V, double *penalty, double *flux)
Calculate the advective flux at at interior element boundaries.
Definition: numericalFlux.c:8525
calculateGlobalExteriorNumericalFluxDarcyFC
void calculateGlobalExteriorNumericalFluxDarcyFC(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_uw, const int *isDOFBoundary_un, int fluxBoundaryFlag_uw, int fluxBoundaryFlag_un, const double *n, const double *bc_a_ww, const double *bc_a_nn, const double *bc_grad_phi_w, const double *bc_grad_phi_n, const double *bc_s_w, const double *bc_psi_w, const double *bc_psi_n, const double *a_ww, const double *a_nn, const double *grad_phi_w, const double *grad_phi_n, const double *s_w, const double *psi_w, const double *psi_n, const double *penalty_w, const double *penalty_n, double *diffusiveFlux_ww, double *diffusiveFlux_nn)
Definition: numericalFlux.c:10839
setInflowFlux
void setInflowFlux(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int *exteriorElementBoundaries, double *inflowFlux, double *flux)
Set the advective flux boundary condition at exterior element boundaries from the current exterior fl...
Definition: numericalFlux.c:7973
calculateGlobalExteriorNumericalDiffusiveFlux_LDG_upwind_sd
void calculateGlobalExteriorNumericalDiffusiveFlux_LDG_upwind_sd(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *rowptr, int *colind, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *u, double *a, double *phi_bc, double *phi, double *V, double *penalty, double *flux)
Definition: numericalFlux.c:8715
updateExteriorNumericalAdvectiveFluxJacobian_free
void updateExteriorNumericalAdvectiveFluxJacobian_free(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *inflowFlag, double *dflux_left, double *v, double *fluxJacobian)
Definition: numericalFlux.c:7885
calculateInteriorNumericalAdvectiveFluxConvexOneSonicPoint
void calculateInteriorNumericalAdvectiveFluxConvexOneSonicPoint(double sonicPoint, double sonicFlux, int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *u, double *f, double *df, double *flux, double *dflux_left, double *dflux_right)
Calculate the advective flux at at interior element boundaries for simple scalar nonlinear hyperbolic...
Definition: numericalFlux.c:14
updateExteriorNumericalStressFluxJacobian
void updateExteriorNumericalStressFluxJacobian(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary_u, int *isDOFBoundary_v, int *isDOFBoundary_w, int *isStressBoundary_u, int *isStressBoundary_v, int *isStressBoundary_w, double *n, double *dstress_u_u, double *dstress_u_v, double *dstress_u_w, double *dstress_v_u, double *dstress_v_v, double *dstress_v_w, double *dstress_w_u, double *dstress_w_v, double *dstress_w_w, double *v, double *grad_v, double *penalty, double *fluxJacobian_u_u, double *fluxJacobian_u_v, double *fluxJacobian_u_w, double *fluxJacobian_v_u, double *fluxJacobian_v_v, double *fluxJacobian_v_w, double *fluxJacobian_w_u, double *fluxJacobian_w_v, double *fluxJacobian_w_w)
Definition: numericalFlux.c:14592
n
Int n
Definition: Headers.h:28
updateExteriorNumericalDiffusiveFluxJacobian_LDG_upwind
void updateExteriorNumericalDiffusiveFluxJacobian_LDG_upwind(int *isDiffusiveFluxBoundary, int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *a, double *da, double *dphi, double *V, double *DV, double *DV_eb, double *v, double *penalty, double *fluxJacobian, double *fluxJacobian_eb)
update the flux Jacobian with the advective flux contribution at at exterior element boundaries
Definition: numericalFlux.c:8779
df
double df(double C, double b, double a, int q, int r)
Definition: analyticalSolutions.c:2209
phi
Double phi
Definition: Headers.h:76
calculateInteriorNumericalFluxShallowWater_2D
void calculateInteriorNumericalFluxShallowWater_2D(int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, double h_eps, double tol_u, double g, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *h, double *hu, double *hv, double *flux_h, double *flux_hu, double *flux_hv)
Definition: numericalFlux.c:13456
calculateGlobalExteriorNumericalFluxDarcyFCFF_diffusiveFluxJacobian
void calculateGlobalExteriorNumericalFluxDarcyFCFF_diffusiveFluxJacobian(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int nDOF_trial_element, const int *l2g, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_uw, const int *isDOFBoundary_um, const double *n, const double *f_m, const double *df_m_dw, const double *a_wm, const double *da_wm_dw, const double *da_wm_dm, const double *a_mw, const double *da_mw_dw, const double *da_mw_dm, const double *a_mm, const double *da_mm_dw, const double *da_mm_dm, const double *grad_phi_w, const double *grad_phi_m, const double *dphi_w_w, const double *dphi_w_m, const double *dphi_m_w, const double *dphi_m_m, const double *u_w, const double *u_m, const double *v, const double *grad_v, const double *penalty_w, const double *penalty_m, double *fluxJacobian_ww, double *fluxJacobian_wm, double *fluxJacobian_mw, double *fluxJacobian_mm)
Definition: numericalFlux.c:10135
calculateExteriorNumericalDiffusiveFlux_free
void calculateExteriorNumericalDiffusiveFlux_free(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *bc_a, double *bc_grad_phi, double *bc_u, double *a, double *grad_phi, double *u, double *penalty, double *flux)
Definition: numericalFlux.c:2523
calculateInteriorNumericalAdvectiveFluxRusanov
void calculateInteriorNumericalAdvectiveFluxRusanov(double safetyFactor, int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nQuadraturePoints_element, int nSpace, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *u, double *f, double *df, double *df_element, double *flux, double *dflux_left, double *dflux_right)
Definition: numericalFlux.c:179
updateInteriorTwoSidedNumericalFluxJacobian
void updateInteriorTwoSidedNumericalFluxJacobian(int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *dflux_left, double *dflux_right, double *v, double *fluxJacobian_2sided)
Calculate the two-sided flux jacobian at at interior element boundaries.
Definition: numericalFlux.c:4145
calculateGlobalExteriorNumericalDiffusiveFluxWithUpwinding_sd
void calculateGlobalExteriorNumericalDiffusiveFluxWithUpwinding_sd(int scale_penalty, double penalty_floor, int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *rowptr, int *colind, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *fluxBoundaryFlag, double *n, double *bc_a, double *bc_grad_phi, double *bc_u, double *a, double *grad_phi, double *u, double *penalty, double *flux)
Definition: numericalFlux.c:14855
calculateGlobalExteriorNumericalAdvectiveFlux_DarcyFC
void calculateGlobalExteriorNumericalAdvectiveFlux_DarcyFC(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary_sw, int *isDOFBoundary_psiw, double *n, double *bc_sw, double *bc_psiw, double *bc_fw, double *bc_dfw_dsw, double *bc_dfw_dpsiw, double *bc_fn, double *bc_dfn_dsw, double *bc_dfn_dpsiw, double *sw, double *psiw, double *fw, double *dfw_dsw, double *dfw_dpsiw, double *fn, double *dfn_dsw, double *dfn_dpsiw, double *fluxw, double *dfluxw_dsw, double *dfluxw_dpsiw, double *fluxn, double *dfluxn_dsw, double *dfluxn_dpsiw)
Calculate the advective (gravity) flux at at exterior element boundaries for Darcy FC does not upwind...
Definition: numericalFlux.c:11842
calculateInteriorNumericalFluxShallowWaterHLL_1D
void calculateInteriorNumericalFluxShallowWaterHLL_1D(int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, double h_eps, double tol_u, double g, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *h, double *hu, double *flux_h, double *flux_hu)
Definition: numericalFlux.c:13610
calculateGlobalExteriorInflowNumericalAdvectiveFlux
void calculateGlobalExteriorInflowNumericalAdvectiveFlux(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *inflowFlag, double *inflowFlux, double *n, double *f, double *df, double *flux, double *dflux_left)
Update the advective flux at exterior inflow element boundaries.
Definition: numericalFlux.c:7765
calculateGlobalExteriorNumericalAdvectiveFlux_free
void calculateGlobalExteriorNumericalAdvectiveFlux_free(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *inflowFlag, double *n, double *bc_u, double *bc_f, double *bc_df, double *u, double *f, double *df, double *flux, double *dflux)
Definition: numericalFlux.c:4856
calculateGlobalExteriorNumericalFluxDarcyFCFF_diffusiveFluxJacobian_sd
void calculateGlobalExteriorNumericalFluxDarcyFCFF_diffusiveFluxJacobian_sd(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int nDOF_trial_element, int *rowptr_wm, int *colind_wm, int *rowptr_mw, int *colind_mw, int *rowptr_mm, int *colind_mm, const int *l2g, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_uw, const int *isDOFBoundary_um, const double *n, const double *f_m, const double *df_m_dw, const double *a_wm, const double *da_wm_dw, const double *da_wm_dm, const double *a_mw, const double *da_mw_dw, const double *da_mw_dm, const double *a_mm, const double *da_mm_dw, const double *da_mm_dm, const double *grad_phi_w, const double *grad_phi_m, const double *dphi_w_w, const double *dphi_w_m, const double *dphi_m_w, const double *dphi_m_m, const double *u_w, const double *u_m, const double *v, const double *grad_v, const double *penalty_w, const double *penalty_m, double *fluxJacobian_ww, double *fluxJacobian_wm, double *fluxJacobian_mw, double *fluxJacobian_mm)
Definition: numericalFlux.c:10490
calculateExteriorNumericalAdvectiveFlux_NoBC
void calculateExteriorNumericalAdvectiveFlux_NoBC(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *inflowFlag, double *n, double *f, double *df, double *flux, double *dflux_left)
Update the advective flux at exterior element boundaries.
Definition: numericalFlux.c:4315
calculateExteriorNumericalFluxRichards_sd
void calculateExteriorNumericalFluxRichards_sd(int *rowptr, int *colind, int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *isSeepageFace, int *isDOFBoundary, double *n, double *bc_u, double *K, double *grad_psi, double *u, double *K_rho_g, double *penalty, double *diffusiveFlux)
Definition: numericalFlux.c:14274
H
Double H
Definition: Headers.h:65
calculateGlobalExteriorNumericalDiffusiveFlux_sd
void calculateGlobalExteriorNumericalDiffusiveFlux_sd(int scale_penalty, double penalty_floor, int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *rowptr, int *colind, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *bc_a, double *bc_grad_phi, double *bc_u, double *a, double *grad_phi, double *u, double *penalty, double *flux)
Definition: numericalFlux.c:2165
updateGlobalExteriorNumericalAdvectiveFluxJacobian
void updateGlobalExteriorNumericalAdvectiveFluxJacobian(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *inflowFlag, double *dflux_left, double *v, double *fluxJacobian)
Calculate the advective flux at global exterior element boundaries.
Definition: numericalFlux.c:7844
calculateGlobalExteriorNumericalAdvectiveFluxStokes2D
void calculateGlobalExteriorNumericalAdvectiveFluxStokes2D(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary_p, int *isDOFBoundary_u, int *isDOFBoundary_v, double *n, double *bc_p, double *bc_f_mass, double *p, double *f_mass, double *df_mass_du, double *df_mass_dv, double *flux_mass, double *flux_umom, double *flux_vmom, double *dflux_mass_du, double *dflux_mass_dv, double *dflux_umom_dp, double *dflux_vmom_dp, double *velocity)
Apply basic pressure boundary penalty term for Stokes.
Definition: numericalFlux.c:7186
calculateInteriorNumericalAdvectiveFluxRusanovWithEigenvalueBound
void calculateInteriorNumericalAdvectiveFluxRusanovWithEigenvalueBound(double safetyFactor, int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nQuadraturePoints_element, int nSpace, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *u, double *f, double *lambda_bar_element, double *flux)
Definition: numericalFlux.c:591
updateExteriorNumericalDiffusiveFluxJacobian_sd
void updateExteriorNumericalDiffusiveFluxJacobian_sd(int scale_penalty, double penalty_floor, int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *rowptr, int *colind, int *l2g, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *a, double *da, double *grad_phi, double *dphi, double *v, double *grad_v, double *penalty, double *fluxJacobian)
Definition: numericalFlux.c:2856
updateGlobalExteriorNumericalDiffusiveFluxJacobian_LDG_upwind
void updateGlobalExteriorNumericalDiffusiveFluxJacobian_LDG_upwind(int *isDiffusiveFluxBoundary, int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *a, double *da, double *dphi, double *V, double *DV, double *DV_eb, double *v, double *penalty, double *fluxJacobian_exterior, double *fluxJacobian_eb)
update the flux Jacobian with the advective flux contribution at at exterior element boundaries
Definition: numericalFlux.c:9025
v
Double v
Definition: Headers.h:95
calculateInteriorNumericalAdvectiveFlux
void calculateInteriorNumericalAdvectiveFlux(int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *u, double *f, double *df, double *flux, double *dflux_left, double *dflux_right)
Calculate the advective flux at at interior element boundaries.
Definition: numericalFlux.c:3927
updateGlobalExteriorNumericalDiffusiveFluxJacobian_free_sd
void updateGlobalExteriorNumericalDiffusiveFluxJacobian_free_sd(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *rowptr, int *colind, int *l2g, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *a, double *da, double *grad_phi, double *dphi, double *v, double *grad_v, double *penalty, double *fluxJacobian)
Definition: numericalFlux.c:3846
updateGlobalExteriorNumericalDiffusiveFluxWithUpwindingJacobian_sd
void updateGlobalExteriorNumericalDiffusiveFluxWithUpwindingJacobian_sd(int scale_penalty, double penalty_floor, int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *rowptr, int *colind, int *l2g, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *fluxBoundaryFlag, double *n, double *a, double *da, double *grad_phi, double *dphi, double *v, double *grad_v, double *penalty, double *fluxJacobian)
Definition: numericalFlux.c:14945
calculateInteriorNumericalDiffusiveFlux_LDG_upwind
void calculateInteriorNumericalDiffusiveFlux_LDG_upwind(int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *u, double *a, double *phi, double *V, double *penalty, double *flux)
Calculate the advective flux at at interior element boundaries.
Definition: numericalFlux.c:7996
numericalFlux.h
C implementations of numericalFlux calculations.
calculateInteriorNumericalDiffusiveFlux
void calculateInteriorNumericalDiffusiveFlux(int scale_penalty, double penalty_floor, int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *a, double *grad_phi, double *u, double *penalty, double *flux)
Calculate the diffusive flux at interior element boundary quadrature points.
Definition: numericalFlux.c:891
calculateGlobalExteriorNumericalFluxDarcySplitPressure_sd
void calculateGlobalExteriorNumericalFluxDarcySplitPressure_sd(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, const int *rowptr, const int *colind, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_u, const double *n, const double *bc_a, const double *bc_grad_phi, const double *bc_psi_w, const double *bc_psi_n, const double *a, const double *grad_phi, const double *psi_w, const double *psi_n, const double *penalty, double *diffusiveFlux)
Definition: numericalFlux.c:13079
calculateGlobalExteriorNumericalFluxDarcyFCPP
void calculateGlobalExteriorNumericalFluxDarcyFCPP(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_uw, const int *isDOFBoundary_un, int fluxBoundaryFlag_uw, int fluxBoundaryFlag_un, const double *n, const double *bc_a_ww, const double *bc_a_nn, const double *bc_grad_phi_w, const double *bc_grad_phi_n, const double *bc_psi_w, const double *bc_psi_c, const double *bc_psi_n, const double *a_ww, const double *a_nn, const double *grad_phi_w, const double *grad_phi_n, const double *psi_w, const double *psi_c, const double *psi_n, const double *penalty_w, const double *penalty_n, double *diffusiveFlux_ww, double *diffusiveFlux_nn)
Definition: numericalFlux.c:11992
calculateGlobalExteriorNumericalAdvectiveFluxRusanovWithEigenvalueBound
void calculateGlobalExteriorNumericalAdvectiveFluxRusanovWithEigenvalueBound(double safetyFactor, int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nQuadraturePoints_element, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *inflowFlag, double *n, double *bc_u, double *bc_f, double *u, double *f, double *lambda_bar, double *flux)
Definition: numericalFlux.c:692
shallowWater_Riemann
void shallowWater_Riemann(int verbose, double h_eps, double tol_u, double g, double h_l, double h_r, double hu_l, double hu_r, double *h_G, double *u_G)
Definition: numericalFlux.c:13202
calculateGlobalExteriorNumericalAdvectiveFluxNavierStokes2D
void calculateGlobalExteriorNumericalAdvectiveFluxNavierStokes2D(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary_p, int *isDOFBoundary_u, int *isDOFBoundary_v, double *n, double *bc_p, double *bc_f_mass, double *bc_f_umom, double *bc_f_vmom, double *p, double *oneByRho, double *f_mass, double *f_umom, double *f_vmom, double *df_mass_du, double *df_mass_dv, double *df_umom_dp, double *df_umom_du, double *df_umom_dv, double *df_vmom_dp, double *df_vmom_du, double *df_vmom_dv, double *flux_mass, double *flux_umom, double *flux_vmom, double *dflux_mass_dp, double *dflux_mass_du, double *dflux_mass_dv, double *dflux_umom_dp, double *dflux_umom_du, double *dflux_umom_dv, double *dflux_vmom_dp, double *dflux_vmom_du, double *dflux_vmom_dv, double *velocity)
Definition: numericalFlux.c:5328
calculateGlobalExteriorNumericalDiffusiveFlux_free
void calculateGlobalExteriorNumericalDiffusiveFlux_free(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *bc_a, double *bc_grad_phi, double *bc_u, double *a, double *grad_phi, double *u, double *penalty, double *flux)
Definition: numericalFlux.c:2638
u
Double u
Definition: Headers.h:89
c
Double c
Definition: Headers.h:54
smoothedDirac
double smoothedDirac(double eps, double phi)
Definition: numericalFlux.c:14199
calculateExteriorNumericalAdvectiveFluxNavierStokes2D
void calculateExteriorNumericalAdvectiveFluxNavierStokes2D(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary_p, int *isDOFBoundary_u, int *isDOFBoundary_v, double *n, double *bc_p, double *bc_f_mass, double *bc_f_umom, double *bc_f_vmom, double *p, double *f_mass, double *f_umom, double *f_vmom, double *df_mass_du, double *df_mass_dv, double *df_umom_du, double *df_umom_dv, double *df_vmom_du, double *df_vmom_dv, double *flux_mass, double *flux_umom, double *flux_vmom, double *dflux_mass_du, double *dflux_mass_dv, double *dflux_umom_dp, double *dflux_umom_du, double *dflux_umom_dv, double *dflux_vmom_dp, double *dflux_vmom_du, double *dflux_vmom_dv)
Definition: numericalFlux.c:5117
calculateGlobalExteriorNumericalAdvectiveFluxRusanov
void calculateGlobalExteriorNumericalAdvectiveFluxRusanov(double safetyFactor, int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nQuadraturePoints_element, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *inflowFlag, double *n, double *bc_u, double *bc_f, double *bc_df, double *u, double *f, double *df, double *df_element, double *flux, double *dflux)
Definition: numericalFlux.c:463
calculateGlobalExteriorNumericalFluxDarcyFCFF
void calculateGlobalExteriorNumericalFluxDarcyFCFF(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_uw, const int *isDOFBoundary_um, const double *n, const double *bc_f_m, const double *bc_a_wm, const double *bc_a_mw, const double *bc_a_mm, const double *bc_grad_phi_w, const double *bc_grad_phi_m, const double *bc_u_w, const double *bc_u_m, const double *f_m, const double *df_m_dw, const double *a_wm, const double *a_mw, const double *a_mm, const double *grad_phi_w, const double *grad_phi_m, const double *u_w, const double *u_m, const double *penalty_w, const double *penalty_m, double *advectiveFlux_m, double *dadvectiveFlux_m_dw, double *diffusiveFlux_wm, double *diffusiveFlux_mw, double *diffusiveFlux_mm)
Definition: numericalFlux.c:9773
calculateInteriorNumericalAdvectiveFlux_average
void calculateInteriorNumericalAdvectiveFlux_average(int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *u, double *f, double *df, double *flux, double *dflux_left, double *dflux_right)
Calculate the advective flux at at interior element boundaries.
Definition: numericalFlux.c:4233
updateInteriorNumericalDiffusiveFluxJacobian_sd
void updateInteriorNumericalDiffusiveFluxJacobian_sd(int scale_penalty, double penalty_floor, int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *rowptr, int *colind, int *l2g, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *a, double *da, double *grad_phi, double *dphi, double *v, double *grad_v, double *penalty, double *fluxJacobian)
Definition: numericalFlux.c:1431
calculateGlobalExteriorNumericalAdvectiveFluxNavierStokes3D
void calculateGlobalExteriorNumericalAdvectiveFluxNavierStokes3D(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary_p, int *isDOFBoundary_u, int *isDOFBoundary_v, int *isDOFBoundary_w, double *n, double *bc_p, double *bc_f_mass, double *bc_f_umom, double *bc_f_vmom, double *bc_f_wmom, double *p, double *f_mass, double *f_umom, double *f_vmom, double *f_wmom, double *df_mass_du, double *df_mass_dv, double *df_mass_dw, double *df_umom_dp, double *df_umom_du, double *df_umom_dv, double *df_umom_dw, double *df_vmom_dp, double *df_vmom_du, double *df_vmom_dv, double *df_vmom_dw, double *df_wmom_dp, double *df_wmom_du, double *df_wmom_dv, double *df_wmom_dw, double *flux_mass, double *flux_umom, double *flux_vmom, double *flux_wmom, double *dflux_mass_du, double *dflux_mass_dv, double *dflux_mass_dw, double *dflux_umom_dp, double *dflux_umom_du, double *dflux_umom_dv, double *dflux_umom_dw, double *dflux_vmom_dp, double *dflux_vmom_du, double *dflux_vmom_dv, double *dflux_vmom_dw, double *dflux_wmom_dp, double *dflux_wmom_du, double *dflux_wmom_dv, double *dflux_wmom_dw, double *velocity)
Definition: numericalFlux.c:5735
calculateExteriorNumericalDiffusiveFlux
void calculateExteriorNumericalDiffusiveFlux(int scale_penalty, double penalty_floor, int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *bc_a, double *bc_grad_phi, double *bc_u, double *a, double *grad_phi, double *u, double *penalty, double *flux)
Calculate the diffusive flux at exterior element boundary quadrature points.
Definition: numericalFlux.c:1930
updateExteriorNumericalDiffusiveFluxJacobian_free_sd
void updateExteriorNumericalDiffusiveFluxJacobian_free_sd(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *rowptr, int *colind, int *l2g, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *a, double *da, double *grad_phi, double *dphi, double *v, double *grad_v, double *penalty, double *fluxJacobian)
Definition: numericalFlux.c:3680
updateGlobalExteriorNumericalDiffusiveFluxJacobian_LDG_upwind_sd
void updateGlobalExteriorNumericalDiffusiveFluxJacobian_LDG_upwind_sd(int *isDiffusiveFluxBoundary, int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *rowptr, int *colind, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *a, double *da, double *dphi, double *V, double *DV, double *DV_eb, double *v, double *penalty, double *fluxJacobian_exterior, double *fluxJacobian_eb)
Definition: numericalFlux.c:9138
calculateGlobalExteriorNumericalFluxDarcyFCPP_diffusiveFluxJacobian
void calculateGlobalExteriorNumericalFluxDarcyFCPP_diffusiveFluxJacobian(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int nDOF_trial_element, const int *l2g, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_uw, const int *isDOFBoundary_un, int fluxBoundaryFlag_uw, int fluxBoundaryFlag_un, const double *n, const double *a_ww, const double *da_ww_dw, const double *da_ww_dn, const double *a_nn, const double *da_nn_dw, const double *da_nn_dn, const double *grad_phi_w, const double *grad_phi_n, const double *dphi_w_w, const double *dphi_w_n, const double *dphi_n_w, const double *dphi_n_n, const double *psi_w, const double *psi_c, const double *psi_n, const double *dpsi_n_dpsiw, const double *dpsi_n_dpsic, const double *v, const double *grad_v, const double *penalty_w, const double *penalty_n, double *fluxJacobian_ww, double *fluxJacobian_wn, double *fluxJacobian_nw, double *fluxJacobian_nn)
Definition: numericalFlux.c:12307
calculateGlobalExteriorLesaintRaviartNumericalFlux
void calculateGlobalExteriorLesaintRaviartNumericalFlux(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int speedEvalFlag, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *inflowFlag, double *n, double *bc_u, double *bc_H, double *bc_dH, double *u, double *H, double *dH, double *flux, double *dflux)
Definition: numericalFlux.c:9675
calculateExteriorNumericalFluxShallowWater_1D
void calculateExteriorNumericalFluxShallowWater_1D(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, double h_eps, double tol_u, double g, double *n, double *h_lv, double *hu_lv, double *h_rv, double *hu_rv, double *flux_h, double *flux_hu)
Definition: numericalFlux.c:13416
calculateInteriorLesaintRaviartNumericalFlux
void calculateInteriorLesaintRaviartNumericalFlux(int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int speedEvalFlag, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *u, double *H, double *dH, double *flux, double *dflux_left, double *dflux_right)
Definition: numericalFlux.c:9435
calculateExteriorNumericalAdvectiveFluxStokesP3D
void calculateExteriorNumericalAdvectiveFluxStokesP3D(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary_p, int *isDOFBoundary_u, int *isDOFBoundary_v, int *isDOFBoundary_w, double *n, double *bc_f, double *bc_fpu, double *bc_fpv, double *bc_fpw, double *f, double *fpu, double *fpv, double *fpw, double *df_du, double *df_dv, double *df_dw, double *dfpu_dp, double *dfpv_dp, double *dfpw_dp, double *flux, double *fluxpu, double *fluxpv, double *fluxpw, double *dflux_du, double *dflux_dv, double *dflux_dw, double *dfluxpu_dp, double *dfluxpv_dp, double *dfluxpw_dp)
Calculate the advective flux at at exterior element boundaries.
Definition: numericalFlux.c:6650
updateInteriorNumericalDiffusiveFluxJacobian
void updateInteriorNumericalDiffusiveFluxJacobian(int scale_penalty, double penalty_floor, int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *l2g, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *a, double *da, double *grad_phi, double *dphi, double *v, double *grad_v, double *penalty, double *fluxJacobian)
Calculate the diffusive flux Jacobian at interior element boundary quadrature points.
Definition: numericalFlux.c:1255
calculateExteriorNumericalAdvectiveFlux_free
void calculateExteriorNumericalAdvectiveFlux_free(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *inflowFlag, double *n, double *bc_u, double *bc_f, double *bc_df, double *u, double *f, double *df, double *flux, double *dflux)
Definition: numericalFlux.c:4789
calculateGlobalExteriorNumericalFluxDarcyFC_diffusiveFluxJacobian
void calculateGlobalExteriorNumericalFluxDarcyFC_diffusiveFluxJacobian(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int nDOF_trial_element, const int *l2g, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_uw, const int *isDOFBoundary_un, int fluxBoundaryFlag_uw, int fluxBoundaryFlag_un, const double *n, const double *a_ww, const double *da_ww_dw, const double *da_ww_dn, const double *a_nn, const double *da_nn_dw, const double *da_nn_dn, const double *grad_phi_w, const double *grad_phi_n, const double *dphi_w_w, const double *dphi_w_n, const double *dphi_n_w, const double *dphi_n_n, const double *s_w, const double *psi_w, const double *psi_n, const double *dpsi_n_dsw, const double *dpsi_n_dpsiw, const double *v, const double *grad_v, const double *penalty_w, const double *penalty_n, double *fluxJacobian_ww, double *fluxJacobian_wn, double *fluxJacobian_nw, double *fluxJacobian_nn)
Definition: numericalFlux.c:11151
calculateExteriorNumericalAdvectiveFlux_average
void calculateExteriorNumericalAdvectiveFlux_average(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *inflowFlag, double *n, double *bc_u, double *bc_f, double *bc_df, double *u, double *f, double *df, double *flux, double *dflux)
Calculate the advective flux at at exterior element boundaries.
Definition: numericalFlux.c:7633
calculateInteriorNumericalDiffusiveFlux_LDG_upwind_sd
void calculateInteriorNumericalDiffusiveFlux_LDG_upwind_sd(int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *rowptr, int *colind, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *u, double *a, double *phi, double *V, double *penalty, double *flux)
Definition: numericalFlux.c:8081
calculateInteriorNumericalDiffusiveFlux_sd
void calculateInteriorNumericalDiffusiveFlux_sd(int scale_penalty, double penalty_floor, int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *rowptr, int *colind, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *a, double *grad_phi, double *u, double *penalty, double *flux)
Definition: numericalFlux.c:987
calculateInteriorNumericalFluxShallowWater_1D
void calculateInteriorNumericalFluxShallowWater_1D(int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, double h_eps, double tol_u, double g, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *h, double *hu, double *flux_h, double *flux_hu)
Definition: numericalFlux.c:13365
calculateGlobalExteriorNumericalFluxDarcyFCFF_sd
void calculateGlobalExteriorNumericalFluxDarcyFCFF_sd(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *rowptr_wm, int *colind_wm, int *rowptr_mw, int *colind_mw, int *rowptr_mm, int *colind_mm, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_uw, const int *isDOFBoundary_um, const double *n, const double *bc_f_m, const double *bc_a_wm, const double *bc_a_mw, const double *bc_a_mm, const double *bc_grad_phi_w, const double *bc_grad_phi_m, const double *bc_u_w, const double *bc_u_m, const double *f_m, const double *df_m_dw, const double *a_wm, const double *a_mw, const double *a_mm, const double *grad_phi_w, const double *grad_phi_m, const double *u_w, const double *u_m, const double *penalty_w, const double *penalty_m, double *advectiveFlux_m, double *dadvectiveFlux_m_dw, double *diffusiveFlux_wm, double *diffusiveFlux_mw, double *diffusiveFlux_mm)
Definition: numericalFlux.c:9952
calculateExteriorNumericalDiffusiveFlux_LDG_upwind_sd
void calculateExteriorNumericalDiffusiveFlux_LDG_upwind_sd(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *rowptr, int *colind, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *u, double *a, double *phi_bc, double *phi, double *V, double *penalty, double *flux)
Definition: numericalFlux.c:8588
calculateExteriorNumericalAdvectiveFluxRusanov
void calculateExteriorNumericalAdvectiveFluxRusanov(double safetyFactor, int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nQuadraturePoints_element, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *inflowFlag, double *n, double *bc_u, double *bc_f, double *bc_df, double *u, double *f, double *df, double *df_element, double *flux, double *dflux)
Definition: numericalFlux.c:326
calculateDiffusionMatrixSplittings_LDG_sd
void calculateDiffusionMatrixSplittings_LDG_sd(int aSplit, int nElements_global, int nElementBoundaries_element, int nQuadraturePoints_element, int nQuadraturePoints_elementBoundary, int nSpace, const int *rowptr, const int *colind, const double *ebq_a, const double *q_a, double *eb_aHat, double *eb_aTilde, double *aHat, double *aTilde)
Definition: numericalFlux.c:9255
calculateExteriorNumericalDiffusiveFlux_sd
void calculateExteriorNumericalDiffusiveFlux_sd(int scale_penalty, double penalty_floor, int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *rowptr, int *colind, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *bc_a, double *bc_grad_phi, double *bc_u, double *a, double *grad_phi, double *u, double *penalty, double *flux)
Definition: numericalFlux.c:2010
updateExteriorNumericalDiffusiveFluxJacobian_LDG_upwind_sd
void updateExteriorNumericalDiffusiveFluxJacobian_LDG_upwind_sd(int *isDiffusiveFluxBoundary, int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *rowptr, int *colind, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *a, double *da, double *dphi, double *V, double *DV, double *DV_eb, double *v, double *penalty, double *fluxJacobian, double *fluxJacobian_eb)
Definition: numericalFlux.c:8901
calculateGlobalExteriorNumericalDiffusiveFlux_LDG_upwind
void calculateGlobalExteriorNumericalDiffusiveFlux_LDG_upwind(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *u, double *a, double *phi_bc, double *phi, double *V, double *penalty, double *flux)
Calculate the advective flux at at global exterior element boundaries.
Definition: numericalFlux.c:8655
calculateGlobalExteriorNumericalDiffusiveFlux_free_sd
void calculateGlobalExteriorNumericalDiffusiveFlux_free_sd(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *rowptr, int *colind, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, double *n, double *bc_a, double *bc_grad_phi, double *bc_u, double *a, double *grad_phi, double *u, double *penalty, double *flux)
Definition: numericalFlux.c:2688
calculateExteriorNumericalAdvectiveFlux
void calculateExteriorNumericalAdvectiveFlux(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *inflowFlag, double *n, double *bc_u, double *bc_f, double *bc_df, double *u, double *f, double *df, double *flux, double *dflux)
Calculate the advective flux at at exterior element boundaries.
Definition: numericalFlux.c:4439
calculateGlobalExteriorNumericalAdvectiveFluxStokes3D
void calculateGlobalExteriorNumericalAdvectiveFluxStokes3D(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary_p, int *isDOFBoundary_u, int *isDOFBoundary_v, int *isDOFBoundary_w, double *n, double *bc_p, double *bc_f_mass, double *p, double *f_mass, double *df_mass_du, double *df_mass_dv, double *df_mass_dw, double *flux_mass, double *flux_umom, double *flux_vmom, double *flux_wmom, double *dflux_mass_du, double *dflux_mass_dv, double *dflux_mass_dw, double *dflux_umom_dp, double *dflux_vmom_dp, double *dflux_wmom_dp, double *velocity)
Definition: numericalFlux.c:7369
smoothedHeaviside_integral
double smoothedHeaviside_integral(double eps, double phi)
Definition: numericalFlux.c:14181
pos
double pos(double a)
Definition: testFMMandFSW.cpp:8
calculateInteriorChengShuNumericalFlux
void calculateInteriorChengShuNumericalFlux(int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nQuadraturePoints_element, int nSpace, int speedEvalFlag, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *n, double *u, double *H, double *dH, double *H_element, double *dH_element, double *flux, double *dflux_left, double *dflux_right)
Definition: numericalFlux.c:13937
calculateGlobalExteriorNumericalFluxDarcyFCPP_diffusiveFluxJacobian_sd
void calculateGlobalExteriorNumericalFluxDarcyFCPP_diffusiveFluxJacobian_sd(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int nDOF_trial_element, int *rowptr_ww, int *colind_ww, int *rowptr_nn, int *colind_nn, const int *l2g, const int *exteriorElementBoundaries, const int *elementBoundaryElements, const int *elementBoundaryLocalElementBoundaries, const int *isDOFBoundary_uw, const int *isDOFBoundary_un, int fluxBoundaryFlag_uw, int fluxBoundaryFlag_un, const double *n, const double *a_ww, const double *da_ww_dw, const double *da_ww_dn, const double *a_nn, const double *da_nn_dw, const double *da_nn_dn, const double *grad_phi_w, const double *grad_phi_n, const double *dphi_w_w, const double *dphi_w_n, const double *dphi_n_w, const double *dphi_n_n, const double *psi_w, const double *psi_c, const double *psi_n, const double *dpsi_n_dpsiw, const double *dpsi_n_dpsic, const double *v, const double *grad_v, const double *penalty_w, const double *penalty_n, double *fluxJacobian_ww, double *fluxJacobian_wn, double *fluxJacobian_nw, double *fluxJacobian_nn)
Definition: numericalFlux.c:12652
calculateGlobalExteriorNumericalAdvectiveFluxStokesP3D
void calculateGlobalExteriorNumericalAdvectiveFluxStokesP3D(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary_p, int *isDOFBoundary_u, int *isDOFBoundary_v, int *isDOFBoundary_w, double *n, double *bc_f, double *bc_fpu, double *bc_fpv, double *bc_fpw, double *f, double *fpu, double *fpv, double *fpw, double *df_du, double *df_dv, double *df_dw, double *dfpu_dp, double *dfpv_dp, double *dfpw_dp, double *flux, double *fluxpu, double *fluxpv, double *fluxpw, double *dflux_du, double *dflux_dv, double *dflux_dw, double *dfluxpu_dp, double *dfluxpv_dp, double *dfluxpw_dp)
Calculate the advective flux at at exterior element boundaries.
Definition: numericalFlux.c:6934
updateExteriorNumericalAdvectiveFluxJacobian
void updateExteriorNumericalAdvectiveFluxJacobian(int nExteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *inflowFlag, double *dflux_left, double *v, double *fluxJacobian)
Calculate the advective flux at exterior element boundaries.
Definition: numericalFlux.c:7797
applySeepageFace
void applySeepageFace(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isSeepageFace, int *isDOFBoundary, double epsFact, double *elementDiameters, double *g, double *n, double *grad_u, double *u, double *advectiveFlux, double *diffusiveFlux)
Definition: numericalFlux.c:14211
applySeepageFaceJacobian
void applySeepageFaceJacobian(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isSeepageFace, double epsFact, double *elementDiameters, double *g, double *n, double *grad_u, double *u, double *advectiveFlux, double *diffusiveFlux, double *v, double *fluxJacobian)
Definition: numericalFlux.c:14454
updateInteriorNumericalAdvectiveFluxJacobian
void updateInteriorNumericalAdvectiveFluxJacobian(int nInteriorElementBoundaries_global, int nElementBoundaries_element, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int *interiorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, double *dflux_left, double *dflux_right, double *v, double *fluxJacobian)
Calculate the advective flux at at interior element boundaries.
Definition: numericalFlux.c:4092
calculateExteriorNumericalFluxShallowWaterHLL_1D
void calculateExteriorNumericalFluxShallowWaterHLL_1D(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, double h_eps, double tol_u, double g, double *n, double *h_lv, double *hu_lv, double *h_rv, double *hu_rv, double *flux_h, double *flux_hu)
Definition: numericalFlux.c:13804
nnz
#define nnz
Definition: Richards.h:9
calculateGlobalExteriorNumericalAdvectiveFlux_average
void calculateGlobalExteriorNumericalAdvectiveFlux_average(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nSpace, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *isDOFBoundary, int *inflowFlag, double *n, double *bc_u, double *bc_f, double *bc_df, double *u, double *f, double *df, double *flux, double *dflux)
Calculate the advective flux at at exterior element boundaries.
Definition: numericalFlux.c:7711
calculateExteriorNumericalFluxShallowWater_2D
void calculateExteriorNumericalFluxShallowWater_2D(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, double h_eps, double tol_u, double g, double *n, double *h_lq, double *hu_lq, double *hv_lq, double *h_rq, double *hu_rq, double *hv_rq, double *flux_h, double *flux_hu, double *flux_hv)
Definition: numericalFlux.c:13541
updateGlobalExteriorNumericalAdvectiveFluxJacobian_free
void updateGlobalExteriorNumericalAdvectiveFluxJacobian_free(int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int *exteriorElementBoundaries, int *elementBoundaryElements, int *elementBoundaryLocalElementBoundaries, int *inflowFlag, double *dflux_left, double *v, double *fluxJacobian)
Definition: numericalFlux.c:7923
calculateExteriorNumericalFluxJacobianRichards_sd
void calculateExteriorNumericalFluxJacobianRichards_sd(int *rowptr, int *colind, int nExteriorElementBoundaries_global, int nQuadraturePoints_elementBoundary, int nDOF_trial_element, int nSpace, int *isDOFBoundary, double *n, double *bc_u, double *K, double *dK, double *grad_psi, double *grad_v, double *u, double *dK_rho_g, double *v, double *penalty, double *fluxJacobian)
Definition: numericalFlux.c:14365