TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
/home/kapf/tycho_docu/evolve.c
Go to the documentation of this file.
1 /*
2  * evolve.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_evolve(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 
32 int evolve(int nmin, int nmax, int flag, double *rho_1D, double *dvol,
33  double *dm, double *dtbdm, double *xa1, double *xa,
34  double *dvol1, double *umid, double *upmid,
35  double *pmid, double *xa2, double *dx, double *xa3,
36  double *vx_1D_old, double *vx_1D, double *vy_1D,
37  double *vz_1D, double *eng_1D,
38  double *e_int_1D, double *pre_1D) {
39 
40  int i;
41 
42  // Calculate the mass and upmid in a cell
43  for (i = nmin - 3; i <= nmax + 4; i++) {
44  dm[i] = rho_1D[i] * dvol[i];
45  dtbdm[i] = dt / dm[i];
46  xa1[i] = xa[i];
47  dvol1[i] = dvol[i];
48  xa[i] = xa[i] + dt * umid[i];
49  upmid[i] = umid[i] * pmid[i];
50  }
51 
52  xa1[nmin - 4] = xa[nmin - 4];
53  xa1[nmax + 5] = xa[nmax + 5];
54 
55  // Calculate the cell centered coordinates
56  for (i = nmin - 4; i <= nmax + 5; i++) {
57  xa2[i] = xa1[i] + 0.5 * dx[i];
58  dx[i] = xa[i + 1] - xa[i];
59  xa3[i] = xa[i] + 0.5 * dx[i];
60  }
61 
62  for (i = nmin - 3; i <= nmax + 4; i++) {
63  dvol[i] = dx[i];
64  }
65 
66  // new densities
67  for (i = nmin - 3; i <= nmax + 3; i++) {
68  rho_1D[i] = rho_1D[i]*(dvol1[i] / dvol[i]);
69  rho_1D[i] = max_evolve(rho_1D[i], smallr);
70 
71  // velocity evolution due to pressure acceleration and external forces.
72  vx_1D_old[i] = vx_1D[i];
73  if (flag == 1) {
74  if (gravity_on_off == 1) {
75  vx_1D[i] = vx_1D[i] - dtbdm[i]*(pmid[i + 1] - pmid[i]) + dt * grav_acc;
76  eng_1D[i] = eng_1D[i] - dtbdm[i]*(upmid[i + 1] - upmid[i]) + 0.5 * dt *
77  grav_acc * (vx_1D_old[i] + vx_1D[i]);
78  }
79  if (gravity_on_off == 0) {
80  vx_1D[i] = vx_1D[i] - dtbdm[i]*(pmid[i + 1] - pmid[i]);
81  eng_1D[i] = eng_1D[i] - dtbdm[i]*(upmid[i + 1] - upmid[i]);
82  }
83  } else {
84  vx_1D[i] = vx_1D[i] - dtbdm[i]*(pmid[i + 1] - pmid[i]);
85  eng_1D[i] = eng_1D[i] - dtbdm[i]*(upmid[i + 1] - upmid[i]);
86  }
87 
88  // total energy evolution
89  e_int_1D[i] = eng_1D[i] - 0.5 * (pow(vx_1D[i], 2) + pow(vy_1D[i], 2) + pow(vz_1D[i], 2));
90  pre_1D[i] = max_evolve(rho_1D[i] * e_int_1D[i] * Gamma, smallp);
91  }
92 
93  return 0;
94 }