TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
/home/kapf/tycho_docu/dt_calc.c
Go to the documentation of this file.
1 /*
2  * dt_calc.c
3  *
4  * Author: Wolfgang Kapferer
5  */
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <math.h>
10 
11 #ifdef _OPENMP
12 #include <omp.h>
13 #endif
14 
15 #include "variables_global.h"
16 #include "prototypes.h"
17 
21 inline double max_dt(double a, double b) {
22  double tmp;
23 
24  if (a < b) tmp = b;
25  if (a == b)tmp = b;
26  if (a > b) tmp = a;
27 
28  return tmp;
29 }
30 
34 inline double min_dt(double a, double b) {
35  double tmp;
36 
37  if (a < b) tmp = a;
38  if (a == b)tmp = a;
39  if (a > b) tmp = b;
40 
41  return tmp;
42 }
43 
50 int dt_calc(int x, int y, int z) {
51  int i, j, k;
52  double rdt1, tmpdy, tmpdz, tmp;
53  double xvel, yvel, zvel, svel;
54  double max_tmp1, max_tmp2, max_tmp3, min_tmp1, dtx, dt3;
55  double kin_viscosity;
56  double s_visc;
57  double temperature;
58 
59  rdt1 = 0.0;
60  svel = 0.0;
61  kin_viscosity = 0.0;
62  s_visc = 0.0;
63 
64  /*
65  The signal velocity is calculated and compared to the
66  gas velocity in each cell. The routine searches for
67  the maximum in the whole computational domain.
68  */
69  if (dimension == 1) {
70  k = 0;
71  j = 0;
72 
73  for (i = 0; i < x; i++) {
74  if (dom[i][j][k] == 0) {
75  svel = sqrt(Gamma1 * pre[i][j][k] / rho[i][j][k]) / zdx[i];
76  xvel = fabs(vx[i][j][k]) / zdx[i];
77  tmp = max_dt(svel, xvel);
78  rdt1 = max_dt(tmp, rdt1);
79 
80  if (viscosity_on_off == 1) {
81  temperature = pre[i][j][k] / (gasconstant * rho[i][j][k]);
82  kin_viscosity = kinematic_viscosity(temperature, rho[i][j][k]);
83  s_visc = kin_viscosity / (tmp * tmp);
84  rdt1 = max_dt(s_visc, rdt1);
85  }
86  }
87  }
88  }
89 
90 
91 #ifdef _OPENMP
92 #pragma omp parallel default(none) \
93  private(j, i, k, tmpdy, tmp, svel, xvel, \
94  yvel, max_tmp2, max_tmp3, temperature, \
95  kin_viscosity,s_visc) \
96  shared(x, y, z, dom, rho, pre, Gamma1, vx, \
97  vy, zdx, zdy, dimension, rdt1, \
98  viscosity_on_off, gasconstant)
99  {
100 #endif
101  if (dimension == 2) {
102  k = 0;
103 
104  for (i = 0; i < x; i++) {
105 
106 #ifdef _OPENMP
107 #pragma omp for schedule(static)
108 #endif
109  for (j = 0; j < y; j++) {
110  if (dom[i][j][k] == 0) {
111  tmpdy = zdy[j];
112  tmp = min_dt(zdx[i], tmpdy);
113  svel = sqrt(Gamma1 * pre[i][j][k] / rho[i][j][k]) / tmp;
114  xvel = fabs(vx[i][j][k]) / zdx[i];
115  yvel = fabs(vy[i][j][k]) / tmpdy;
116  max_tmp2 = max_dt(svel, xvel);
117  max_tmp3 = max_dt(max_tmp2, yvel);
118  rdt1 = max_dt(max_tmp3, rdt1);
119 
120  if (viscosity_on_off == 1) {
121  temperature = pre[i][j][k] / (gasconstant * rho[i][j][k]);
122  kin_viscosity = kinematic_viscosity(temperature, rho[i][j][k]);
123  s_visc = kin_viscosity / (tmp * tmp);
124  rdt1 = max_dt(s_visc, rdt1);
125  }
126  }
127  }
128  }
129 
130  }
131 
132 #ifdef _OPENMP
133  }
134 #endif
135 
136 
137 #ifdef _OPENMP
138 #pragma omp parallel default(none) \
139  private(j, i, k, tmpdy, tmp, tmpdz, svel, xvel, \
140  yvel, zvel, max_tmp1, max_tmp2, max_tmp3, \
141  min_tmp1, temperature, \
142  kin_viscosity,s_visc) \
143  shared(x, y, z, dom, rho, pre, Gamma1, vx, \
144  vy, vz, zdx, zdy, zdz,dimension, rdt1, \
145  viscosity_on_off, gasconstant)
146  {
147 #endif
148 
149  if (dimension == 3) {
150 
151  for (i = 0; i < x; i++) {
152 
153 #ifdef _OPENMP
154 #pragma omp for schedule(static)
155 #endif
156  for (j = 0; j < y; j++) {
157  for (k = 0; k < z; k++) {
158  if (dom[i][j][k] == 0) {
159  tmpdy = zdy[j];
160  tmpdz = zdz[k];
161  min_tmp1 = min_dt(tmpdy, tmpdz);
162  tmp = min_dt(zdx[i], min_tmp1);
163  svel = sqrt(Gamma1 * pre[i][j][k] / rho[i][j][k]) / tmp;
164  xvel = fabs(vx[i][j][k]) / zdx[i];
165  yvel = fabs(vy[i][j][k]) / tmpdy;
166  zvel = fabs(vz[i][j][k]) / tmpdz;
167  max_tmp1 = max_dt(xvel, yvel);
168  max_tmp2 = max_dt(zvel, svel);
169  max_tmp3 = max_dt(max_tmp1, max_tmp2);
170  rdt1 = max_dt(max_tmp3, rdt1);
171 
172  if (viscosity_on_off == 1) {
173  temperature = pre[i][j][k] / (gasconstant * rho[i][j][k]);
174  kin_viscosity = kinematic_viscosity(temperature, rho[i][j][k]);
175  s_visc = kin_viscosity / (tmp * tmp);
176  rdt1 = max_dt(s_visc, rdt1);
177  }
178  }
179  }
180  }
181  }
182  }
183 
184 #ifdef _OPENMP
185  }
186 #endif
187 
188  // here the CFL condition is applied
189  dtx = courant / rdt1;
190 
191  // In order to avoid strong time step changes
192  dt3 = 1.2 * olddt;
193  dt = min_dt(dt3, dtx);
194 
195  if (dt == 0.0) {
196  printf("A time_simstep of zero ---> STOP\n");
197  exit(42);
198  }
199 
200  return 0;
201 }