TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
/home/kapf/tycho_docu/viscosity.c
Go to the documentation of this file.
1 /*
2  * viscosity.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_viscosity(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 
34 int viscosity(int i, int j, int k, int flag, int nmin, int nmax,
35  double *rho_1D, double * vx_1D, double *vy_1D, double *vz_1D,
36  double *pre_1D, double *e_int_1D, double *eng_1D, int lefter,
37  double *rhodown, double *rhoup, double *rhofront, double *rhoback,
38  double *vxdown, double *vxup, double *vxfront, double *vxback,
39  double *vydown, double *vyup, double *vyfront, double *vyback,
40  double *vzdown, double *vzup, double *vzfront, double *vzback,
41  int dimension) {
42 
43  int n;
44  double viscosity_term;
45  double temperature_i, temperature_ii;
46  double term_x, term_y, term_z;
47  double term_x_1, term_y_1, term_z_1;
48  double term_x_2, term_y_2, term_z_2;
49  double dx, dm, dm0, dtbdx;
50  double *dxflux, *dyflux, *dzflux;
51 
52  dm = 0.0;
53  dm0 = 0.0;
54  dx = 0.0;
55  dtbdx = 0.0;
56 
57  dxflux = calloc((max_array_length + 12), sizeof dxflux);
58  dyflux = calloc((max_array_length + 12), sizeof dyflux);
59  dzflux = calloc((max_array_length + 12), sizeof dzflux);
60 
61 
62  // spacing in all three directions
63  if (flag == 0) dx = (xmax - xmin) / (double) x;
64  if (flag == 1) dx = (ymax - ymin) / (double) y;
65  if (flag == 2) dx = (zmax - zmin) / (double) z;
66 
67  for (n = nmin - 1; n <= nmax + 1; n++) {
68 
69  term_x = 0.0;
70  term_y = 0.0;
71  term_z = 0.0;
72 
73  term_x_1 = 0.0;
74  term_y_1 = 0.0;
75  term_z_1 = 0.0;
76 
77  term_x_2 = 0.0;
78  term_y_2 = 0.0;
79  term_z_2 = 0.0;
80 
81  //the core computation of viscosity
82  temperature_i = pre_1D[n] / (gasconstant * rho_1D[n]);
83  temperature_ii = pre_1D[n - 1] / (gasconstant * rho_1D[n - 1]);
84 
85  viscosity_term = -0.5 * (dynamic_viscosity(temperature_i) + dynamic_viscosity(temperature_ii));
86 
87  //the dxflux term----------------------------------------------------------------------------------
88  term_x = -viscosity_term / dx * (rho_1D[n]*(4.0 / 3.0)*(vx_1D[n] - vx_1D[n - 1]));
89  if (dimension > 1) {
90  term_x_1 = (rhoup[n] + rhodown[n])*(2.0 / 3.0)*(vyup[n] - vydown[n])*0.5;
91  term_x_1 += (rhoup[n - 1] + rhodown[n - 1])*(2.0 / 3.0)*(vyup[n - 1] - vydown[n - 1])*0.5;
92  }
93  if (dimension > 2) {
94  term_x_2 = (rhoback[n] + rhofront[n])*(2.0 / 3.0)*(vzfront[n] - vzback[n])*0.5;
95  term_x_2 += (rhoback[n - 1] + rhofront[n - 1])*(2.0 / 3.0)*(vzfront[n - 1] - vzback[n - 1])*0.5;
96  }
97 
98  dxflux[n] = term_x - 0.25 * (term_x_1 + term_x_2);
99  //the dxflux term----------------------------------------------------------------------------------
100 
101  //the dyflux term----------------------------------------------------------------------------------
102  if (dimension > 1) {
103  term_y = -viscosity_term / dx * (rho_1D[n]*(4.0 / 3.0)*(vy_1D[n] - vy_1D[n - 1]));
104  term_y_1 = (rhoup[n] + rhodown[n])*(vxup[n] - vxdown[n])*0.5;
105  term_y_1 += (rhoup[n - 1] + rhodown[n - 1])*(vxup[n - 1] - vxdown[n - 1])*0.5;
106 
107  dyflux[n] = term_y + 0.25 * term_y_1;
108  }
109  //the dyflux term----------------------------------------------------------------------------------
110 
111  //the dzflux term----------------------------------------------------------------------------------
112  if (dimension > 2) {
113  term_z = -viscosity_term / dx * (rho_1D[n]*(4.0 / 3.0)*(vz_1D[n] - vz_1D[n - 1]));
114  term_z_1 = (rhoback[n] - rhofront[n])*(vxback[n] - vxfront[n])*0.5;
115  term_z_1 += (rhoback[n - 1] + rhofront[n - 1])*(vxback[n - 1] - vxfront[n - 1])*0.5;
116 
117  dzflux[n] = term_z + 0.25 * term_z_1;
118  }
119  //the dzflux term----------------------------------------------------------------------------------
120  }
121 
122  //Now the viscosity effect on the hydro quantities will be calculated
123  for (n = nmin; n <= nmax; n++) {
124 
125  dm0 = 1 / rho_1D[n];
126  dtbdx = dt / dx;
127 
128  vx_1D[n] = (vx_1D[n] * rho_1D[n] - dtbdx * (dxflux[n + 1] - dxflux[n])) * dm0;
129  vy_1D[n] = (vy_1D[n] * rho_1D[n] - dtbdx * (dyflux[n + 1] - dyflux[n])) * dm0;
130  vz_1D[n] = (vz_1D[n] * rho_1D[n] - dtbdx * (dzflux[n + 1] - dzflux[n])) * dm0;
131 
132  }
133 
134  free(dxflux);
135  free(dyflux);
136  free(dzflux);
137 
138  return 0;
139 }