TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
/home/kapf/tycho_docu/flatten.c
Go to the documentation of this file.
1 /*
2  * flatten.c
3  *
4  * Author: Wolfgang Kapferer
5  */
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <math.h>
10 
11 #include "variables_global.h"
12 #include "prototypes.h"
13 
17 inline double max_flatten(double a, double b) {
18  double tmp = 0.0;
19 
20  if (a < b) tmp = b;
21  if (a == b)tmp = b;
22  if (a > b) tmp = a;
23 
24  return tmp;
25 }
26 
30 inline double min_flatten(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 
47 int flatten(int nmin, int nmax, double *pre_1D, double *vx_1D, double *steep, double *flat) {
48 
49  int i;
50  double temp1, temp2, temp3;
51  double delp1, delp2, shock;
52  double epsilon, omega1, omega2;
53 
54  epsilon = 0.3;
55  omega1 = 0.75;
56  omega2 = 5.0;
57 
58  /*
59  Look for presence of a shock using pressure gradient and sign of
60  velocity jump: shock = 1 if there is a shock in the zone, else shock = 0
61  Compute steepness parameter based on steepness of pressure jump IF
62  there is a shock.
63  */
64 
65  for (i = nmin - 4; i <= nmax + 4; i++) {
66  // delp1 und delp2 are the pressure difference over the next and next after next cells
67  delp1 = pre_1D[i + 1] - pre_1D[i - 1];
68  delp2 = pre_1D[i + 2] - pre_1D[i - 2];
69 
70  // the actual shock detection
71  if (fabs(delp2) < small) delp2 = small;
72  shock = fabs(delp1) / min_flatten(pre_1D[i + 1], pre_1D[i - 1]) - epsilon;
73  shock = max_flatten(0.0, shock);
74  if (shock > 0.0) shock = 1.0;
75  if (vx_1D[i - 1] < vx_1D[i + 1]) shock = 0.0;
76  temp1 = (delp1 / delp2 - omega1) * omega2;
77 
78  // the steepness parameter
79  steep[i] = shock * max_flatten(0.0, temp1);
80  }
81 
82  //Set phony boundary conditions for the steepness parameter
83 
84  steep[nmin - 5] = steep[nmin - 4];
85  steep[nmax + 5] = steep[nmax + 4];
86 
87  //Set flattening coefficient based on the steepness in neighboring zones
88  for (i = nmin - 4; i <= nmax + 4; i++) {
89  temp2 = max_flatten(steep[i - 1], steep[i]);
90  temp3 = max_flatten(steep[i + 1], temp2);
91  flat[i] = max_flatten(0.0, min_flatten(0.5, temp3));
92  if (flat[i] > 0) shock_or_not = 1;
93  }
94 
95 
96  return 0;
97 }