TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
/home/kapf/tycho_docu/init.c
Go to the documentation of this file.
1 /*
2  * init.c
3  *
4  * Author: Wolfgang Kapferer
5  */
6 
7 
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <math.h>
11 
12 #include "variables_global.h"
13 #include "prototypes.h"
14 
18 int init_ppm(double **rho_1D, double **pre_1D, double **eng_1D, double **vx_1D, double **vy_1D,
19  double **vz_1D, double **marker_1D, double **dx0, double **xa0, double **xa, double **dx, double **a_coef,
20  double **ai_coef, double **b_coef, double **bi_coef, double **c_coef, double **ci_coef,
21  double **d_x, double **da, double **ar, double **dp, double **dr, double **du,
22  double **pl, double **p6, double **rl, double **r6, double **ul, double **u6,
23  double **vl, double **v6, double **wl, double **w6, double **el, double **e6,
24  double **ql, double **q6, double **deltaa, double **dv, double **dw, double **dq,
25  double **de, double **scratch1, double **scratch2, double **scratch3, double **diffa,
26  double **plft, double **prgh, double **ulft, double **urgh, double **rlft, double **rrgh,
27  double **Cdtdx, double **fCdtdx, double **clft, double **crgh, double **plfti, double **prghi,
28  double **pmid, double **pmold, double **wlft, double **wrgh, double **zlft, double **zrgh,
29  double **umidl, double **umidr, double **umid, double **dm, double **dtbdm, double **upmid,
30  double **xa1, double **xa2, double **xa3, double **vx_1D_old, double **e_int_1D, double **dvol,
31  double **dvol0, double **dvol1, double **delta, double **fluxr, double **fluxu, double **fluxv,
32  double **fluxw, double **fluxe, double **fluxq, double **dm0, double **steep, double **flat,
33  double ***para, double **pressure_solid_1D, double **rhodown, double **rhoup, double **rhofront,
34  double **rhoback, double **vxdown, double **vxup, double **vxfront, double **vxback, double **vydown,
35  double **vyup, double **vyfront, double **vyback, double **vzdown, double **vzup, double **vzfront,
36  double **vzback, int dimension) {
37 
38  int i;
39 
40  // the arrays which hold the hydro quantities
41  *rho_1D = calloc((max_array_length + 12), sizeof ** rho_1D);
42  *pre_1D = calloc((max_array_length + 12), sizeof ** pre_1D);
43  *eng_1D = calloc((max_array_length + 12), sizeof ** eng_1D);
44  *vx_1D = calloc((max_array_length + 12), sizeof ** vx_1D);
45  *vy_1D = calloc((max_array_length + 12), sizeof ** vy_1D);
46  *vz_1D = calloc((max_array_length + 12), sizeof ** vz_1D);
47 
48  *marker_1D = calloc((max_array_length + 12), sizeof ** marker_1D);
49  *pressure_solid_1D = calloc((max_array_length + 12), sizeof ** pressure_solid_1D);
50 
51  //for viscosity calculations
52  if (dimension > 1) {
53  *rhodown = calloc((max_array_length + 12), sizeof ** rhodown);
54  *rhoup = calloc((max_array_length + 12), sizeof ** rhoup);
55  *vxdown = calloc((max_array_length + 12), sizeof ** vxdown);
56  *vxup = calloc((max_array_length + 12), sizeof ** vxup);
57  *vydown = calloc((max_array_length + 12), sizeof ** vydown);
58  *vyup = calloc((max_array_length + 12), sizeof ** vyup);
59  *vzdown = calloc((max_array_length + 12), sizeof ** vzdown);
60  *vzup = calloc((max_array_length + 12), sizeof ** vzup);
61  }
62  if (dimension > 2) {
63  *rhofront = calloc((max_array_length + 12), sizeof ** rhofront);
64  *rhoback = calloc((max_array_length + 12), sizeof ** rhoback);
65  *vxfront = calloc((max_array_length + 12), sizeof ** vxfront);
66  *vxback = calloc((max_array_length + 12), sizeof ** vxback);
67  *vyfront = calloc((max_array_length + 12), sizeof ** vyfront);
68  *vyback = calloc((max_array_length + 12), sizeof ** vyback);
69  *vzfront = calloc((max_array_length + 12), sizeof ** vzfront);
70  *vzback = calloc((max_array_length + 12), sizeof ** vzback);
71  }
72 
73  *dx0 = calloc((max_array_length + 12), sizeof ** dx0);
74  *xa0 = calloc((max_array_length + 12), sizeof ** xa0);
75  *xa = calloc((max_array_length + 12), sizeof ** xa);
76  *dx = calloc((max_array_length + 12), sizeof ** dx);
77  //allocates for the ppm routine
78  //for the parabolic interpolation constants
79  *a_coef = calloc((max_array_length + 12), sizeof ** a_coef);
80  *ai_coef = calloc((max_array_length + 12), sizeof ** ai_coef);
81  *b_coef = calloc((max_array_length + 12), sizeof ** b_coef);
82  *bi_coef = calloc((max_array_length + 12), sizeof ** bi_coef);
83  *c_coef = calloc((max_array_length + 12), sizeof ** c_coef);
84  *ci_coef = calloc((max_array_length + 12), sizeof ** ci_coef);
85  *d_x = calloc((max_array_length + 12), sizeof ** d_x);
86  //for the parabolic interpolation
87  *da = calloc((max_array_length + 12), sizeof ** da);
88  *ar = calloc((max_array_length + 12), sizeof ** ar);
89  *dp = calloc((max_array_length + 12), sizeof ** dp);
90  *dr = calloc((max_array_length + 12), sizeof ** dr);
91  *du = calloc((max_array_length + 12), sizeof ** du);
92  *pl = calloc((max_array_length + 12), sizeof ** pl);
93  *p6 = calloc((max_array_length + 12), sizeof ** p6);
94  *rl = calloc((max_array_length + 12), sizeof ** rl);
95  *r6 = calloc((max_array_length + 12), sizeof ** r6);
96  *ul = calloc((max_array_length + 12), sizeof ** ul);
97  *u6 = calloc((max_array_length + 12), sizeof ** u6);
98  *vl = calloc((max_array_length + 12), sizeof ** vl);
99  *v6 = calloc((max_array_length + 12), sizeof ** v6);
100  *wl = calloc((max_array_length + 12), sizeof ** wl);
101  *w6 = calloc((max_array_length + 12), sizeof ** w6);
102  *el = calloc((max_array_length + 12), sizeof ** el);
103  *e6 = calloc((max_array_length + 12), sizeof ** e6);
104  *ql = calloc((max_array_length + 12), sizeof ** ql);
105  *q6 = calloc((max_array_length + 12), sizeof ** q6);
106  *deltaa = calloc((max_array_length + 12), sizeof ** deltaa);
107  *dv = calloc((max_array_length + 12), sizeof ** dv);
108  *dw = calloc((max_array_length + 12), sizeof ** dw);
109  *dq = calloc((max_array_length + 12), sizeof ** dq);
110  *de = calloc((max_array_length + 12), sizeof ** de);
111  *scratch1 = calloc((max_array_length + 12), sizeof ** scratch1);
112  *scratch2 = calloc((max_array_length + 12), sizeof ** scratch2);
113  *scratch3 = calloc((max_array_length + 12), sizeof ** scratch3);
114  *diffa = calloc((max_array_length + 12), sizeof ** diffa);
115  //for the states
116  *plft = calloc((max_array_length + 12), sizeof ** plft);
117  *prgh = calloc((max_array_length + 12), sizeof ** prgh);
118  *ulft = calloc((max_array_length + 12), sizeof ** ulft);
119  *urgh = calloc((max_array_length + 12), sizeof ** urgh);
120  *rlft = calloc((max_array_length + 12), sizeof ** rlft);
121  *rrgh = calloc((max_array_length + 12), sizeof ** rrgh);
122  *Cdtdx = calloc((max_array_length + 12), sizeof ** Cdtdx);
123  *fCdtdx = calloc((max_array_length + 12), sizeof ** fCdtdx);
124  //for the riemann solver
125  *clft = calloc((max_array_length + 12), sizeof ** clft);
126  *crgh = calloc((max_array_length + 12), sizeof ** crgh);
127  *plfti = calloc((max_array_length + 12), sizeof ** plfti);
128  *prghi = calloc((max_array_length + 12), sizeof ** prghi);
129  *pmid = calloc((max_array_length + 12), sizeof ** pmid);
130  *pmold = calloc((max_array_length + 12), sizeof ** pmold);
131  *wlft = calloc((max_array_length + 12), sizeof ** wlft);
132  *wrgh = calloc((max_array_length + 12), sizeof ** wrgh);
133  *zlft = calloc((max_array_length + 12), sizeof ** zlft);
134  *zrgh = calloc((max_array_length + 12), sizeof ** zrgh);
135  *umidl = calloc((max_array_length + 12), sizeof ** umidl);
136  *umidr = calloc((max_array_length + 12), sizeof ** umidr);
137  *umid = calloc((max_array_length + 12), sizeof ** umid);
138  // for the evolution
139  *dm = calloc((max_array_length + 12), sizeof ** dm);
140  *dtbdm = calloc((max_array_length + 12), sizeof ** dtbdm);
141  *upmid = calloc((max_array_length + 12), sizeof ** upmid);
142  *xa1 = calloc((max_array_length + 12), sizeof ** xa1);
143  *xa2 = calloc((max_array_length + 12), sizeof ** xa2);
144  *xa3 = calloc((max_array_length + 12), sizeof ** xa3);
145  *vx_1D_old = calloc((max_array_length + 12), sizeof ** vx_1D_old);
146  *e_int_1D = calloc((max_array_length + 12), sizeof ** e_int_1D);
147  *dvol = calloc((max_array_length + 12), sizeof ** dvol);
148  *dvol0 = calloc((max_array_length + 12), sizeof ** dvol0);
149  *dvol1 = calloc((max_array_length + 12), sizeof ** dvol1);
150  // for remapping
151  *delta = calloc((max_array_length + 12), sizeof ** delta);
152  *fluxr = calloc((max_array_length + 12), sizeof ** fluxr);
153  *fluxu = calloc((max_array_length + 12), sizeof ** fluxu);
154  *fluxv = calloc((max_array_length + 12), sizeof ** fluxv);
155  *fluxw = calloc((max_array_length + 12), sizeof ** fluxw);
156  *fluxe = calloc((max_array_length + 12), sizeof ** fluxe);
157  *fluxq = calloc((max_array_length + 12), sizeof ** fluxq);
158  *dm0 = calloc((max_array_length + 12), sizeof ** dm0);
159  // steep and flat coefficients for the flatten function
160  *steep = calloc((max_array_length + 12), sizeof ** steep);
161  *flat = calloc((max_array_length + 12), sizeof ** flat);
162  //for the para_coefficient
163  *para = calloc((max_array_length + 12), sizeof **para);
164  for (i = 0; i < (max_array_length + 12); i++) {
165  *((*para) + i) = calloc(5, sizeof ***para);
166  }
167 
168  return 0;
169 }
170 
174 int ppm_free(double **rho_1D, double **pre_1D, double **eng_1D, double **vx_1D, double **vy_1D,
175  double **vz_1D, double **marker_1D, double **pressure_solid_1D,
176  double **dx0, double **xa0, double **xa, double **dx, double **a_coef,
177  double **ai_coef, double **b_coef, double **bi_coef, double **c_coef, double **ci_coef,
178  double **d_x, double **da, double **ar, double **dp, double **dr, double **du,
179  double **pl, double **p6, double **rl, double **r6, double **ul, double **u6,
180  double **vl, double **v6, double **wl, double **w6, double **el, double **e6,
181  double **ql, double **q6, double **deltaa, double **dv, double **dw, double **dq,
182  double **de, double **scratch1, double **scratch2, double **scratch3, double **diffa,
183  double **plft, double **prgh, double **ulft, double **urgh, double **rlft, double **rrgh,
184  double **Cdtdx, double **fCdtdx, double **clft, double **crgh, double **plfti, double **prghi,
185  double **pmid, double **pmold, double **wlft, double **wrgh, double **zlft, double **zrgh,
186  double **umidl, double **umidr, double **umid, double **dm, double **dtbdm, double **upmid,
187  double **xa1, double **xa2, double **xa3, double **vx_1D_old, double **e_int_1D, double **dvol,
188  double **dvol0, double **dvol1, double **delta, double **fluxr, double **fluxu, double **fluxv,
189  double **fluxw, double **fluxe, double **fluxq, double **dm0, double **steep, double **flat,
190  double ***para, double **rhodown, double **rhoup, double **rhofront,
191  double **rhoback, double **vxdown, double **vxup, double **vxfront, double **vxback, double **vydown,
192  double **vyup, double **vyfront, double **vyback, double **vzdown, double **vzup, double **vzfront,
193  double **vzback, int dimension) {
194  int i;
195 
196  // the arrays which hold the hydro quantities
197  free(*rho_1D);
198  free(*pre_1D);
199  free(*eng_1D);
200  free(*vx_1D);
201  free(*vy_1D);
202  free(*vz_1D);
203 
204  free(*marker_1D);
205  free(*pressure_solid_1D);
206 
207  //free the 1D quantities for the viscosity calculations
208  if (dimension > 1) {
209  free(*rhodown);
210  free(*rhoup);
211  free(*vxdown);
212  free(*vxup);
213  free(*vydown);
214  free(*vyup);
215  free(*vzdown);
216  free(*vzup);
217  }
218  if (dimension > 2) {
219  free(*rhofront);
220  free(*rhoback);
221  free(*vxfront);
222  free(*vxback);
223  free(*vyfront);
224  free(*vyback);
225  free(*vzfront);
226  free(*vzback);
227  }
228 
229  free(*dx0);
230  free(*xa0);
231  free(*xa);
232  free(*dx);
233  //allocates for the ppm routine
234  //for the parabolic interpolation constants
235  free(*a_coef);
236  free(*ai_coef);
237  free(*b_coef);
238  free(*bi_coef);
239  free(*c_coef);
240  free(*ci_coef);
241  free(*d_x);
242  free(*da);
243  free(*ar);
244  free(*dp);
245  free(*dr);
246  free(*du);
247  free(*pl);
248  free(*p6);
249  free(*rl);
250  free(*r6);
251  free(*ul);
252  free(*u6);
253  free(*vl);
254  free(*v6);
255  free(*wl);
256  free(*w6);
257  free(*el);
258  free(*e6);
259  free(*ql);
260  free(*q6);
261  free(*deltaa);
262  free(*dv);
263  free(*dw);
264  free(*dq);
265  free(*de);
266  free(*scratch1);
267  free(*scratch2);
268  free(*scratch3);
269  free(*diffa);
270  //for states
271  free(*plft);
272  free(*prgh);
273  free(*ulft);
274  free(*urgh);
275  free(*rlft);
276  free(*rrgh);
277  free(*Cdtdx);
278  free(*fCdtdx);
279  //Riemann solver
280  free(*clft);
281  free(*crgh);
282  free(*plfti);
283  free(*prghi);
284  free(*pmid);
285  free(*pmold);
286  free(*wlft);
287  free(*wrgh);
288  free(*zlft);
289  free(*zrgh);
290  free(*umidl);
291  free(*umidr);
292  free(*umid);
293  //evolve
294  free(*dm);
295  free(*dtbdm);
296  free(*upmid);
297  free(*xa1);
298  free(*xa2);
299  free(*xa3);
300  free(*vx_1D_old);
301  free(*e_int_1D);
302  free(*dvol);
303  free(*dvol0);
304  free(*dvol1);
305  //remap
306  free(*delta);
307  free(*fluxr);
308  free(*fluxu);
309  free(*fluxv);
310  free(*fluxw);
311  free(*fluxe);
312  free(*fluxq);
313  free(*dm0);
314  //steep and flat for flatten
315  free(*steep);
316  free(*flat);
317  //for para_coef
318  for (i = 0; i < (max_array_length + 12); i++) {
319  free(*((*para) + i));
320  }
321  free(*para);
322 
323  return 0;
324 }
325 
326 int init_diffusion(double **temperature_1D, double **temperature_1D_future, double **mass, int **dom_1D) {
327 
328  *temperature_1D = calloc((max_array_length + 4), sizeof **temperature_1D);
329  *temperature_1D_future = calloc((max_array_length + 4), sizeof **temperature_1D_future);
330  *mass = calloc((max_array_length + 4), sizeof **mass);
331  *dom_1D = calloc((max_array_length + 4), sizeof **dom_1D);
332 
333  return 0;
334 }
335 
336 int free_diffusion(double **temperature_1D, double **temperature_1D_future, double **mass, int **dom_1D) {
337 
338  free(*temperature_1D);
339  free(*temperature_1D_future);
340  free(*mass);
341  free(*dom_1D);
342 
343  return 0;
344 }
345 
346 int init_viscosity(double **viscosity_array, double **vx_flux, double **vy_flux, double **vz_flux, int **dom_1D) {
347 
348  *viscosity_array = calloc((max_array_length + 2), sizeof **viscosity_array);
349  *vx_flux = calloc((max_array_length + 2), sizeof **vx_flux);
350  *vy_flux = calloc((max_array_length + 2), sizeof **vy_flux);
351  *vz_flux = calloc((max_array_length + 2), sizeof **vz_flux);
352  *dom_1D = calloc((max_array_length + 2), sizeof **dom_1D);
353 
354 
355  return 0;
356 }
357 
358 int free_viscosity(double **viscosity_array, double **vx_flux, double **vy_flux, double **vz_flux, int **dom_1D) {
359 
360  free(*viscosity_array);
361  free(*vx_flux);
362  free(*vy_flux);
363  free(*vz_flux);
364  free(*dom_1D);
365 
366  return 0;
367 }