00001
00002
00003
00004 #include "utilf.h"
00005 #include "markers.h"
00006 #include "surfaces.h"
00007 #include "extra.h"
00008 #include "global.h"
00009 #include "ini_conditions.h"
00010 #include "save.h"
00011 #include "make_bc.h"
00012 #include "mg.h"
00013 #include "save.h"
00014 #include <readSIunits.h>
00015 #include <time.h>
00016
00017
00018 void initialize()
00019 {
00020 int restart, i, j;
00021 FILE *fptr, *fptr1, *fptr2;
00022
00023 readglob();
00024 initglobal();
00025
00026 restart = 0;
00027 intread("restart", &restart, stdin);
00028 printf("restart=%d\n", restart);
00029
00030 printhist();
00031 printnumbers();
00032
00033 switch(num.ng = computeng(num.nx, num.ny)) {
00034 case NXERROR:
00035 printf("computeng(): bad nx size\n");
00036 exit(NXERROR);
00037 case NYERROR:
00038 printf("computeng(): bad ny size\n");
00039 exit(NYERROR);
00040 case NGERROR:
00041 printf("computeng(): bad ng size\n");
00042 exit(NGERROR);
00043 }
00044 if (initpressure(num.nx, num.ny, num.ng)) {
00045 printf("initpressure(): cannot allocate memory\n");
00046 exit(1);
00047 }
00048
00049 if (restart == 0) {
00050 interfaces = (interface *)malloc(sizeof(interface));
00051 Nint = 1;
00052 inifile(interfaces, num.nx, num.ny, "file.init");
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 }
00074 else if (restart == 1) {
00075 iniget(u, v, ap, p, &interfaces, &Nint, &phys.po, &phys.vo,
00076 &phys.t, &phys.pext,
00077 &num.tau, num.nx, num.ny, "save.dat");
00078 printf("fields u v ap p read\n");
00079 }
00080
00081 fptr = fopen("markers.init", "wt");
00082 fptr1 = fopen("curvature.init", "wt");
00083 fptr2 = fopen("splines.init", "wt");
00084 for (i = 0; i < Nint; i++) {
00085 interface_splines(interfaces[i], num.nx, num.ny);
00086 interface_write_markers(interfaces[i], fptr);
00087 interface_write_splines(interfaces[i], fptr2, 1000);
00088 curvature_write(interfaces[i], fptr1);
00089 interface_redis(&interfaces[i], num.lredis/2.);
00090 interface_splines(interfaces[i], num.nx, num.ny);
00091 }
00092 fclose(fptr); fclose(fptr1); fclose(fptr2);
00093
00094 printf("Filling fractions ... ");
00095 interface_fill(interfaces, 1, ap, num.nx, num.ny);
00096 printf("Ok\n");
00097
00098 printf("Initializing fraction fields ... "); fflush(stdout);
00099 cut_interface(interfaces[0], &cutp, 0.0, 0.0);
00100 cut_interface(interfaces[0], &cutu, -0.5, 0.0);
00101 cut_interface(interfaces[0], &cutv, 0.0, -0.5);
00102 interface_surfaces(interfaces[0], cutp, sxp, syp, ap, cc,
00103 S12, work, num.nx, num.ny);
00104
00105 for (i = 2; i <= num.nx; i++)
00106 for (j = 2; j <= num.ny; j++) {
00107 au[i][j] = (ap[i][j] + ap[i-1][j])/2.;
00108 av[i][j] = (ap[i][j] + ap[i][j-1])/2.;
00109 }
00110 interface_surfaces(interfaces[0], cutu, sxu, syu, au, a1,
00111 S12, work, num.nx, num.ny);
00112 interface_surfaces(interfaces[0], cutv, sxv, syv, av, a2,
00113 S12, work, num.nx, num.ny);
00114 printf("Ok\n");
00115
00116
00117
00118
00119
00120 bc_vector_bound(u, v, num.nx, num.ny);
00121
00122 printxpl(u, v, ap, p, num.nx, num.ny, num.tau, num.du, num.dp, "init.datb");
00123
00124 }
00125
00126
00127 int main(int argc, char *argv[])
00128 {
00129 int t, steptime;
00130 long CPUtime;
00131
00132 initialize();
00133 CPUtime = 0;
00134 for (t = 0; t <= num.tmax; t++) {
00135 steptime = clock();
00136 if (t > 0 && t % out.tsave == 0) {
00137 rename("save.dat", "save.dat.bak");
00138 save(u, v, ap, p, interfaces, Nint, phys.po, phys.vo, phys.t, phys.pext,
00139 num.tau, num.nx, num.ny, "save.dat");
00140 printf("fields u v ap p written\n");
00141 }
00142 timestep(t);
00143 CPUtime += clock() - steptime ;
00144 }
00145 printf("CPU time: %g s\n", (float) CPUtime /
00146 (float) CLOCKS_PER_SEC);
00147 printf("Grid points / sec: %g\n",(float) (num.tmax + 1) * num.nx * num.ny
00148 / (float) CPUtime * CLOCKS_PER_SEC);
00149 }
00150
00151
00152
00153
00154
00155
00156
00157