TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
/home/kapf/tycho_docu/states.c
Go to the documentation of this file.
1 /*
2  * states.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_states(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 
30 int states(int nmin, int nmax, int flag, double *pre_1D, double *rho_1D,
31  double *dx, double *Cdtdx, double *fCdtdx, double *plft,
32  double *pl, double *dp, double *p6, double *ulft, double *ul,
33  double *du, double *u6, double *rlft, double *rl, double *dr,
34  double *r6, double *prgh, double *urgh, double *rrgh) {
35  int i, ii;
36  double hdt, svel;
37  double fourthd;
38 
39  fourthd = 4.0 / 3.0;
40  svel = 0.0;
41  hdt = 0.5 * dt;
42 
43  for (i = nmin - 4; i <= nmax + 4; i++) {
44  Cdtdx[i] = sqrt(Gamma1 * pre_1D[i] / rho_1D[i]) / (dx[i]);
45  svel = max_states(svel, Cdtdx[i]);
46  Cdtdx[i] = Cdtdx[i] * hdt;
47  fCdtdx[i] = 1.0 - fourthd * Cdtdx[i];
48  }
49 
50  for (i = nmin - 4; i <= nmax + 4; i++) {
51  ii = i + 1;
52  plft[ii] = pl[i] + dp[i] - Cdtdx[i]*(dp[i] - fCdtdx[i] * p6[i]);
53  ulft[ii] = ul[i] + du[i] - Cdtdx[i]*(du[i] - fCdtdx[i] * u6[i]);
54  rlft[ii] = rl[i] + dr[i] - Cdtdx[i]*(dr[i] - fCdtdx[i] * r6[i]);
55  plft[ii] = max_states(smallp, plft[ii]);
56  rlft[ii] = max_states(smallr, rlft[ii]);
57  if (flag == 0) {
58  ulft[ii] = ulft[ii] + hdt * grav_acc;
59  } else {
60  ulft[ii] = ulft[ii];
61  }
62  prgh[i] = pl[i] + Cdtdx[i]*(dp[i] + fCdtdx[i] * p6[i]);
63  urgh[i] = ul[i] + Cdtdx[i]*(du[i] + fCdtdx[i] * u6[i]);
64  rrgh[i] = rl[i] + Cdtdx[i]*(dr[i] + fCdtdx[i] * r6[i]);
65  prgh[i] = max_states(smallp, prgh[i]);
66  rrgh[i] = max_states(smallr, rrgh[i]);
67  if (flag == 1) {
68  if (gravity_on_off == 1) urgh[i] = urgh[i] + hdt * grav_acc;
69  if (gravity_on_off == 0) urgh[i] = urgh[i];
70  } else {
71  urgh[i] = urgh[i];
72  }
73  }
74 
75 
76  return 0;
77 }