void tea_leaf_cheby_first_step(double *ch_alphas, double *ch_betas, int *fields, double *error, double *theta, double cn, int max_cheby_iters, int *est_itc, double solve_time, double rx, double ry) { double bb = 0; // calculate 2 norm of u0 tea_leaf_calc_2norm(0, &bb); // initialise 'p' array tea_leaf_cheby_init(u,u0,vector_p,vector_r,vector_Mi,vector_w,vector_z,vector_Kx,vector_Ky,tri_cp,tri_bfp,rx,ry,*theta,tl_preconditioner_type); // if (profiler_on) halo_time = timer() update_halo(fields,1); // if (profiler_on) solve_time = solve_time + (timer()-halo_time) tea_leaf_cheby_iterate(u,u0,vector_p,vector_r,vector_Mi,vector_w,vector_z,vector_Kx,vector_Ky,tri_cp,tri_bfp,ch_alphas, ch_betas, rx,ry,1,tl_preconditioner_type); tea_leaf_calc_2norm(1, error); double it_alpha = eps/2.0*sqrt(bb/(*error));//eps*bb/(4.0*(*error)); double gamm = (sqrt(cn) - 1.0)/(sqrt(cn) + 1.0); *est_itc = round(log(it_alpha)/(log(gamm))); ops_fprintf(g_out," est itc\n%11d\n",*est_itc); ops_printf(" est itc\n%11d\n",*est_itc); }
void timestep() { double dtlp; double kernel_time, c, t; if(profiler_on) ops_timers_core(&c,&kernel_time); //calc_dt(&dt) dt = dtinit; // if(profiler_on) profiler%timestep=profiler%timestep+(timer()-kernel_time) ops_fprintf(g_out, " Step %8d time %.7lf timestep %-10.2E\n", step, currtime, dt); ops_printf(" Step %8d time %.7lf timestep %-10.2E\n", step, currtime, dt); }
void field_summary() { double qa_diff; //initialize sizes using global values int x_min = field.x_min; int x_max = field.x_max; int y_min = field.y_min; int y_max = field.y_max; int rangexy_inner[] = {x_min,x_max,y_min,y_max}; // inner range without border double vol= 0.0 , mass = 0.0, ie = 0.0, temp = 0.0; ops_par_loop(field_summary_kernel, "field_summary_kernel", tea_grid, 2, rangexy_inner, ops_arg_dat(volume, 1, S2D_00, "double", OPS_READ), ops_arg_dat(density, 1, S2D_00, "double", OPS_READ), ops_arg_dat(energy1, 1, S2D_00, "double", OPS_READ), ops_arg_dat(u, 1, S2D_00, "double", OPS_READ), ops_arg_reduce(red_vol, 1, "double", OPS_INC), ops_arg_reduce(red_mass, 1, "double", OPS_INC), ops_arg_reduce(red_ie, 1, "double", OPS_INC), ops_arg_reduce(red_temp, 1, "double", OPS_INC)); //printf("mass = %lf\n",mass); ops_reduction_result(red_vol,&vol); ops_reduction_result(red_mass,&mass); ops_reduction_result(red_ie,&ie); ops_reduction_result(red_temp,&temp); ops_fprintf(g_out,"\n"); ops_fprintf(g_out,"\n Time %lf\n",clover_time); ops_fprintf(g_out," %-10s %-10s %-15s %-10s %-s\n", " Volume"," Mass"," Density"," Internal Energy","Temperature"); ops_fprintf(g_out," step: %3d %-10.3E %-10.3E %-15.3E %-10.3E %-.3E", step, vol, mass, mass/vol, ie, temp); if(complete == 1) { if(test_problem>0) { if (test_problem == 1) qa_diff = fabs((100.0 * (temp / 157.55084183279294)) - 100.0); if (test_problem == 2) // tea_bm_short.in qa_diff = fabs((100.0 * (temp / 106.27221178646569)) - 100.0); if (test_problem == 3) qa_diff = fabs((100.0 * (temp / 99.955877498324000)) - 100.0); if (test_problem == 4) qa_diff = fabs((100.0 * (temp / 97.277332050749976)) - 100.0); if (test_problem == 5) qa_diff = fabs((100.0 * (temp / 95.462351583362249)) - 100.0); ops_printf("Test problem %3d is within %-10.7E%% of the expected solution\n",test_problem, qa_diff); ops_fprintf(g_out,"\nTest problem %3d is within %10.7E%% of the expected solution\n",test_problem, qa_diff); if(qa_diff < 0.001) { ops_printf(" This test is considered PASSED\n"); ops_fprintf(g_out," This test is considered PASSED\n"); } else { ops_printf(" This test is considered FAILED\n"); ops_fprintf(g_out," This test is considered FAILED\n"); } } } fflush(g_out); //ops_exit();//exit for now //exit(0); }
void read_input() { //some defailt values before read input test_problem = 0; state_max = 0; number_of_states = 0; //grid = (grid_type ) xmalloc(sizeof(grid_type_core)); grid.xmin = 0; grid.ymin = 0; grid.zmin = 0; grid.xmax = 100; grid.ymax = 100; grid.zmax = 100; grid.x_cells = 10; grid.y_cells = 10; grid.z_cells = 10; end_time = 10.0; end_step = g_ibig; complete = FALSE; visit_frequency=10; summary_frequency=10; dtinit = 0.1; dtmax = 1.0; dtmin = 0.0000001; dtrise = 1.05; dtc_safe = 0.75; dtu_safe = 0.5; dtv_safe = 0.5; dtw_safe = 0.5; dtdiv_safe = 0.5; use_vector_loops = TRUE; // //need to read in the following through I/O .. hard coded below // ops_fprintf(g_out," Reading input file\n"); #define LINESZ 1024 char buff[LINESZ]; FILE *fin = fopen ("clover.in", "r"); if (fin != NULL) { while (fgets (buff, LINESZ, fin)) { char* token = strtok(buff, " ="); while (token) { if(strcmp(token,"*clover\n") != 0 && strcmp(token,"*endclover\n") != 0 ) { //printf("token: %s ", token); if(strcmp(token,"initial_timestep") == 0) { token = strtok(NULL, " ="); dtinit = atof(token); ops_fprintf(g_out," %20s: %e\n", "initial_timestep",dtinit); } else if(strcmp(token,"max_timestep") == 0) { token = strtok(NULL, " ="); dtmax = atof(token); ops_fprintf(g_out," %20s: %e\n", "max_timestep",dtmax); } else if(strcmp(token,"timestep_rise") == 0) { token = strtok(NULL, " ="); dtrise = atof(token); ops_fprintf(g_out," %20s: %e\n", "timestep_rise",dtrise); } else if(strcmp(token,"end_time") == 0) { token = strtok(NULL, " ="); end_time = atof(token); ops_fprintf(g_out," %20s: %e\n", "end_time",end_time); } else if(strcmp(token,"end_step") == 0) { token = strtok(NULL, " ="); end_step = atof(token); ops_fprintf(g_out," %20s: %e\n", "end_step",end_step); } else if(strcmp(token,"xmin") == 0) { token = strtok(NULL, " ="); grid.xmin = atof(token); ops_fprintf(g_out," %20s: %e\n", "xmin",grid.xmin); } else if(strcmp(token,"xmax") == 0) { token = strtok(NULL, " ="); grid.xmax = atof(token); ops_fprintf(g_out," %20s: %e\n", "xmax",grid.xmax); } else if(strcmp(token,"ymin") == 0) { token = strtok(NULL, " ="); grid.ymin = atof(token); ops_fprintf(g_out," %20s: %e\n", "ymin",grid.ymin); } else if(strcmp(token,"ymax") == 0) { token = strtok(NULL, " ="); grid.ymax = atof(token); ops_fprintf(g_out," %20s: %e\n", "ymax",grid.ymax); } else if(strcmp(token,"zmin") == 0) { token = strtok(NULL, " ="); grid.zmin = atof(token); ops_fprintf(g_out," %20s: %e\n", "zmin",grid.zmin); } else if(strcmp(token,"zmax") == 0) { token = strtok(NULL, " ="); grid.zmax = atof(token); ops_fprintf(g_out," %20s: %e\n", "zmax",grid.zmax); } else if(strcmp(token,"x_cells") == 0) { token = strtok(NULL, " ="); grid.x_cells = atof(token); ops_fprintf(g_out," %20s: %d\n", "x_cells",grid.x_cells); } else if(strcmp(token,"y_cells") == 0) { token = strtok(NULL, " ="); grid.y_cells = atof(token); ops_fprintf(g_out," %20s: %d\n", "y_cells",grid.y_cells); } else if(strcmp(token,"z_cells") == 0) { token = strtok(NULL, " ="); grid.z_cells = atof(token); ops_fprintf(g_out," %20s: %d\n", "z_cells",grid.z_cells); } else if(strcmp(token,"visit_frequency") == 0) { token = strtok(NULL, " ="); visit_frequency = atoi(token); ops_fprintf(g_out," %20s: %d\n", "visit_frequency",visit_frequency); } else if(strcmp(token,"summary_frequency") == 0) { token = strtok(NULL, " ="); summary_frequency = atoi(token); ops_fprintf(g_out," %20s: %d\n", "summary_frequency",summary_frequency); } else if(strcmp(token,"test_problem") == 0) { token = strtok(NULL, " ="); test_problem = atoi(token); ops_fprintf(g_out," %20s: %d\n", "test_problem",test_problem); } else if(strcmp(token,"profiler_on") == 0) { token = strtok(NULL, " ="); profiler_on = atoi(token); ops_fprintf(g_out," %20s: %d\n", "profiler_on",profiler_on); } else if(strcmp(token,"state") == 0) { ops_fprintf(g_out,"\n"); ops_fprintf(g_out," Reading specification for state %d\n",number_of_states+1); ops_fprintf(g_out,"\n"); token = strtok(NULL, " ="); states = (state_type *) xrealloc(states, sizeof(state_type) * (number_of_states+1)); states[number_of_states].xvel = 0.0; states[number_of_states].yvel = 0.0; states[number_of_states].zvel = 0.0; token = strtok(NULL, " ="); while(token) { if(strcmp(token,"xvel") == 0) { token = strtok(NULL, " ="); states[number_of_states].xvel = atof(token); ops_fprintf(g_out,"xvel: %e\n", states[number_of_states].xvel); } if(strcmp(token,"yvel") == 0) { token = strtok(NULL, " ="); states[number_of_states].yvel = atof(token); ops_fprintf(g_out,"yvel: %e\n", states[number_of_states].yvel); } if(strcmp(token,"zvel") == 0) { token = strtok(NULL, " ="); states[number_of_states].zvel = atof(token); ops_fprintf(g_out,"zvel: %e\n", states[number_of_states].zvel); } if(strcmp(token,"xmin") == 0) { token = strtok(NULL, " ="); states[number_of_states].xmin = atof(token); ops_fprintf(g_out," %20s: %e\n","state xmin",states[number_of_states].xmin); } if(strcmp(token,"xmax") == 0) { token = strtok(NULL, " ="); states[number_of_states].xmax = atof(token); ops_fprintf(g_out," %20s: %e\n","state xmax",states[number_of_states].xmax); } if(strcmp(token,"ymin") == 0) { token = strtok(NULL, " ="); states[number_of_states].ymin = atof(token); ops_fprintf(g_out," %20s: %e\n","state ymin",states[number_of_states].ymin); } if(strcmp(token,"ymax") == 0) { token = strtok(NULL, " ="); states[number_of_states].ymax = atof(token); ops_fprintf(g_out," %20s: %e\n","state ymax",states[number_of_states].ymax); } if(strcmp(token,"zmin") == 0) { token = strtok(NULL, " ="); states[number_of_states].zmin = atof(token); ops_fprintf(g_out," %20s: %e\n","state zmin",states[number_of_states].zmin); } if(strcmp(token,"zmax") == 0) { token = strtok(NULL, " ="); states[number_of_states].zmax = atof(token); ops_fprintf(g_out," %20s: %e\n","state zmax",states[number_of_states].zmax); } if(strcmp(token,"density") == 0) { token = strtok(NULL, " ="); states[number_of_states].density = atof(token); ops_fprintf(g_out," %20s: %e\n", "state density",states[number_of_states].density); } if(strcmp(token,"energy") == 0) { token = strtok(NULL, " ="); states[number_of_states].energy = atof(token); ops_fprintf(g_out," %20s: %e\n", "state energy",states[number_of_states].energy); } if(strcmp(token,"geometry") == 0) { token = strtok(NULL, " ="); if(strcmp(token,"cuboid") == 0) { states[number_of_states].geometry = g_cube; ops_fprintf(g_out," %20s: %s\n","state geometry","cuboid"); } else if(strcmp(token,"sphere") == 0) { states[number_of_states].geometry = g_sphe; ops_fprintf(g_out," %20s: %s\n","state geometry","sphere"); } else if(strcmp(token,"point") == 0) { states[number_of_states].geometry = g_point; ops_fprintf(g_out," %20s: %s\n","state geometry","point"); } } token = strtok(NULL, " ="); } number_of_states++; ops_fprintf(g_out,"\n"); } } token = strtok(NULL, " ="); } } fclose (fin); } if(number_of_states == 0) { ops_printf("read_input, No states defined.\n"); exit(-1); } ops_fprintf(g_out,"\n"); ops_fprintf(g_out," Input read finished\n"); ops_fprintf(g_out,"\n"); //field = (field_type ) xmalloc(sizeof(field_type_core)); field.x_min = 0 +2; //+2 to account for the boundary field.y_min = 0 +2; //+2 to account for the boundary field.z_min = 0 +2; //+2 to account for the boundary field.x_max = grid.x_cells +2; //+2 to account for the boundary field.y_max = grid.y_cells +2; //+2 to account for the boundary field.z_max = grid.z_cells +2; //+2 to account for the boundary field.left = 0; field.bottom = 0; field.back = 0; float dx= (grid.xmax-grid.xmin)/(float)(grid.x_cells); float dy= (grid.ymax-grid.ymin)/(float)(grid.y_cells); float dz= (grid.zmax-grid.zmin)/(float)(grid.z_cells); for(int i = 0; i < number_of_states; i++) { states[i].xmin = states[i].xmin + (dx/100.00); states[i].ymin = states[i].ymin + (dy/100.00); states[i].zmin = states[i].zmin + (dz/100.00); states[i].xmax = states[i].xmax - (dx/100.00); states[i].ymax = states[i].ymax - (dy/100.00); states[i].zmax = states[i].zmax - (dz/100.00); } }
void field_summary() { double qa_diff; int x_min = field.x_min; int x_max = field.x_max; int y_min = field.y_min; int y_max = field.y_max; int z_min = field.z_min; int z_max = field.z_max; int rangexyz_inner[] = {x_min, x_max, y_min, y_max, z_min, z_max}; ideal_gas(FALSE); double vol = 0.0, mass = 0.0, ie = 0.0, ke = 0.0, press = 0.0; ops_par_loop_field_summary_kernel( "field_summary_kernel", clover_grid, 3, rangexyz_inner, ops_arg_dat(volume, 1, S3D_000, "double", OPS_READ), ops_arg_dat(density0, 1, S3D_000, "double", OPS_READ), ops_arg_dat(energy0, 1, S3D_000, "double", OPS_READ), ops_arg_dat(pressure, 1, S3D_000, "double", OPS_READ), ops_arg_dat(xvel0, 1, S3D_000_fP1P1P1, "double", OPS_READ), ops_arg_dat(yvel0, 1, S3D_000_fP1P1P1, "double", OPS_READ), ops_arg_dat(zvel0, 1, S3D_000_fP1P1P1, "double", OPS_READ), ops_arg_reduce(red_vol, 1, "double", OPS_INC), ops_arg_reduce(red_mass, 1, "double", OPS_INC), ops_arg_reduce(red_ie, 1, "double", OPS_INC), ops_arg_reduce(red_ke, 1, "double", OPS_INC), ops_arg_reduce(red_press, 1, "double", OPS_INC)); ops_reduction_result(red_vol, &vol); ops_reduction_result(red_mass, &mass); ops_reduction_result(red_ie, &ie); ops_reduction_result(red_ke, &ke); ops_reduction_result(red_press, &press); ops_fprintf(g_out, "\n"); ops_fprintf(g_out, "\n Time %lf\n", clover_time); ops_fprintf(g_out, " %-10s %-10s %-10s %-10s %-15s %-15s %-s\n", " Volume", " Mass", " Density", " Pressure", " Internal Energy", "Kinetic Energy", "Total Energy"); ops_fprintf(g_out, " step: %3d %-10.3E %-10.3E %-10.3E %-10.3E " "%-15.3E %-15.3E %-.3E", step, vol, mass, mass / vol, press / vol, ie, ke, ie + ke); if (complete == TRUE && test_problem) { qa_diff = DBL_MAX; if (test_problem == 1) qa_diff = fabs((100.0 * (ke / 3.64560737191257)) - 100.0); if (test_problem == 2) qa_diff = fabs((100.0 * (ke / 20.0546870878964)) - 100.0); if (test_problem == 3) qa_diff = fabs((100.0 * (ke / 0.37517221925665)) - 100.0); if (test_problem == 4) qa_diff = fabs((100.0 * (ke / 17.9845165368889)) - 100.0); if (test_problem == 5) qa_diff = fabs((100.0 * (ke / 2.05018938455107)) - 100.0); ops_printf( "\n\nTest problem %d is within %3.15E %% of the expected solution\n", test_problem, qa_diff); ops_fprintf( g_out, "\n\nTest problem %d is within %3.15E %% of the expected solution\n", test_problem, qa_diff); if (qa_diff < 0.001) { ops_printf("This test is considered PASSED\n"); ops_fprintf(g_out, "This test is considered PASSED\n"); } else { ops_printf("This test is considered FAILED\n"); ops_fprintf(g_out, "This test is considered FAILED\n"); } } fflush(g_out); }