TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
/home/kapf/tycho_docu/parabola.c
Go to the documentation of this file.
1 /*
2  * parabola.c
3  *
4  * Author: Wolfgang Kapferer
5  */
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <math.h>
10 //special Headerfiles
11 #include "variables_global.h"
12 #include "prototypes.h"
13 
17 inline double signum_parabola(double a) {
18  double tmp = 0.0;
19 
20  if (a < 0) tmp = -1.0;
21  if (a == 0) tmp = 0.0;
22  if (a > 0) tmp = +1.0;
23 
24  return tmp;
25 }
26 
30 inline double min_par(double a, double b) {
31  double tmp = 0.0;
32 
33  if (a < b) tmp = a;
34  if (a == b)tmp = a;
35  if (a > b) tmp = b;
36 
37  return tmp;
38 
39 }
40 
45 int parabola(int nmin, int nmax, double *a, double *deltaa,
46  double *a6, double *al, int flag1, double *diffa,
47  double *da, double **para, double *ar, double *flat,
48  double *scratch1, double *scratch2, double *scratch3) {
49  int i;
50  double tmp1, tmp2, tmp3, onemfl;
51 
52 
53  for (i = nmin - 2; i <= nmax + 1; i++) {
54  diffa[i] = a[i + 1] - a[i];
55  }
56 
57  //Equation 1.7 of Colella & Woodward, Journal of Computational Physics 53, 174-201. 1984
58  //da(j) = D1 * (a(j+1) - a(j)) + D2 * (a(j) - a(j-1))
59  for (i = nmin - 1; i <= nmax + 1; i++) {
60  da[i] = para[i][3] * diffa[i] + para[i][4] * diffa[i - 1];
61  tmp1 = min_par(fabs(da[i]), 2.0 * fabs(diffa[i - 1]));
62  tmp2 = min_par(2.0 * fabs(diffa[i]), tmp1);
63  tmp3 = signum_parabola(da[i]);
64  da[i] = tmp2*tmp3;
65  }
66 
67 
68  //zero da(n) if a(n) is a local max/min
69  for (i = nmin - 1; i <= nmax + 1; i++) {
70  if (diffa[i - 1] * diffa[i] < 0.0) da[i] = 0.0;
71  }
72 
73 
74  //Equation 1.6 of of Colella & Woodward, Journal of Computational Physics 53, 174-201. 1984
75  //a(j+.5) = a(j) + C1 * (a(j+1)-a(j)) + C2 * dma(j+1) + C3 * dma(j)
76  //MONOT: Limit ar(n) to the range defined by a(n) and a(n+1)
77  for (i = nmin - 1; i <= nmax; i++) {
78  ar[i] = a[i] + para[i][0] * diffa[i] + para[i][1] * da[i + 1] + para[i][2] * da[i];
79  al[i + 1] = ar[i];
80  }
81 
82  //eqn. 4.1 - flatten interpolation in zones with a shock ( flat(n)->1. )
83  for (i = nmin; i <= nmax; i++) {
84  onemfl = 1.0 - flat[i];
85  ar[i] = flat[i] * a[i] + onemfl * ar[i];
86  al[i] = flat[i] * a[i] + onemfl * al[i];
87  }
88 
89  /*
90  MONOTONICITY constraints:
91  compute delta_a, a_6
92  MONOT: if a is a local max/min, flatten zone structure ar,al -> a.
93  MONOT: compute monotonzsed values using eq. 1.10 of of Colella & Woodward, Journal of Computational Physics 53, 174-201. 1984
94  if parabola exceeds al/ar, reset ar/al so that slope -> 0.
95  Recalculate delta_a and a_6
96  */
97  for (i = nmin; i <= nmax; i++) {
98 
99  onemfl = 1.0 - flat[i];
100  ar[i] = flat[i] * a[i] + onemfl * ar[i];
101  al[i] = flat[i] * a[i] + onemfl * al[i];
102 
103  deltaa[i] = ar[i] - al[i];
104  a6[i] = 6.0 * (a[i] - 0.5 * (al[i] + ar[i]));
105  scratch1[i] = (ar[i] - a[i])*(a[i] - al[i]);
106  scratch2[i] = deltaa[i] * deltaa[i];
107  scratch3[i] = deltaa[i] * a6[i];
108 
109  if (scratch1[i] <= 0.0) {
110  ar[i] = a[i];
111  al[i] = a[i];
112  }
113  if (scratch2[i] < +scratch3[i]) al[i] = 3.0 * a[i] - 2.0 * ar[i];
114  if (scratch2[i] < -scratch3[i]) ar[i] = 3.0 * a[i] - 2.0 * al[i];
115 
116 
117  deltaa[i] = ar[i] - al[i];
118  a6[i] = 6.0 * (a[i] - 0.5 * (al[i] + ar[i]));
119 
120  }
121 
122  for (i = nmin; i <= nmax; i++) {
123  if (scratch1[i] <= 0.0) {
124  ar[i] = a[i];
125  al[i] = a[i];
126  }
127  if (scratch2[i] < +scratch3[i]) al[i] = 3.0 * a[i] - 2.0 * ar[i];
128  if (scratch2[i] < -scratch3[i]) ar[i] = 3.0 * a[i] - 2.0 * al[i];
129  }
130 
131 
132 
133  for (i = nmin; i <= nmax; i++) {
134  deltaa[i] = ar[i] - al[i];
135  a6[i] = 6.0 * (a[i] - 0.5 * (al[i] + ar[i]));
136  }
137 
138  return 0;
139 }