TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
/home/kapf/tycho_docu/riemann.c
Go to the documentation of this file.
1 /*
2  * riemann.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_riemann(double a, double b) {
18  double tmp;
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 
46 int riemann(int nmin, int nmax, double *clft, double *crgh,
47  double *rlft, double *rrgh, double *plfti,
48  double *prghi, double *pmid, double *pmold,
49  double *plft, double *wrgh, double *prgh, double *wlft,
50  double *zlft, double *zrgh, double *umidl, double *umidr,
51  double *umid, double *urgh, double *ulft) {
52  int n, l;
53 
54  double tol = 1.0E-3;
55  double gamfac2, gamfac1;
56 
57  gamfac2 = Gamma1 + 1.0;
58  gamfac1 = 0.5 * (gamfac2) / Gamma1;
59 
60 
61  //Obtain first guess for Pmid by assuming Wlft, Wrgh = Clft, Crgh
62  for (n = nmin; n <= nmax; n++) {
63  clft[n] = sqrt(Gamma1 * plft[n] * rlft[n]);
64  crgh[n] = sqrt(Gamma1 * prgh[n] * rrgh[n]);
65  rlft[n] = 1.0 / rlft[n];
66  rrgh[n] = 1.0 / rrgh[n];
67  plfti[n] = 1.0 / plft[n];
68  prghi[n] = 1.0 / prgh[n];
69  pmid[n] = prgh[n] - plft[n] - crgh[n]*(urgh[n] - ulft[n]);
70  pmid[n] = plft[n] + pmid[n] * clft[n] / (clft[n] + crgh[n]);
71  pmid[n] = max_riemann(smallp, pmid[n]);
72  }
73 
74  /*
75  Iterate up to 8 time_sims using Newton's method to converge on correct Pmid
76  -use previous guess for pmid to get wavespeeds: wlft, wrgh
77  -find the slope in the u-P plane for each state: zlft, zrgh
78  -use the wavespeeds and pmid to guess umid on each side: umidl, umidr
79  -project tangents from (pmid,umidl) and (pmid,umidr) to get new pmid
80  -make sure pmid does not fall below floor value for pressure
81  */
82  for (n = nmin; n <= nmax; n++) {
83  for (l = 0; l < 12; l++) {
84  pmold[n] = pmid[n];
85  wlft[n] = 1.0 + gamfac1 * (pmid[n] - plft[n]) * plfti[n];
86  wrgh[n] = 1.0 + gamfac1 * (pmid[n] - prgh[n]) * prghi[n];
87  wlft[n] = clft[n] * sqrt(wlft[n]);
88  wrgh[n] = crgh[n] * sqrt(wrgh[n]);
89  zlft[n] = 4.0 * rlft[n] * wlft[n] * wlft[n];
90  zrgh[n] = 4.0 * rrgh[n] * wrgh[n] * wrgh[n];
91  zlft[n] = -zlft[n] * wlft[n] / (zlft[n] - gamfac2 * (pmid[n] - plft[n]));
92  zrgh[n] = zrgh[n] * wrgh[n] / (zrgh[n] - gamfac2 * (pmid[n] - prgh[n]));
93  umidl[n] = ulft[n] - (pmid[n] - plft[n]) / wlft[n];
94  umidr[n] = urgh[n] + (pmid[n] - prgh[n]) / wrgh[n];
95  pmid[n] = pmid[n] + (umidr[n] - umidl[n])*(zlft[n] * zrgh[n]) / (zrgh[n] - zlft[n]);
96  pmid[n] = max_riemann(smallp, pmid[n]);
97  if (fabs(pmid[n] - pmold[n]) / pmid[n] < tol) break;
98  }
99  }
100 
101 
102  //Calculate umid by averaging umidl, umidr based on new pmid
103  for (n = nmin; n <= nmax; n++) {
104  umidl[n] = ulft[n] - (pmid[n] - plft[n]) / wlft[n];
105  umidr[n] = urgh[n] + (pmid[n] - prgh[n]) / wrgh[n];
106  umid [n] = 0.5 * (umidl[n] + umidr[n]);
107  }
108 
109  return 0;
110 }