LOCAL void g_fprint_raw_state( FILE *file, Locstate state, int dim) { int i; static char mname[3][3] = { "mx", "my", "mz"}; (void) fprintf(file,"state %p\n",state); //(void) fprintf(file,"\t%-7s = %"FFMT" %-7s = %"FFMT"\n\t","density", // Dens(state),"energy",Energy(state)); (void) fprintf(file,"\t%-7s = %22.16g %-7s = %22.16g\n\t","density", Dens(state),"energy",Energy(state)); for (i = 0; i < dim; i++) (void) fprintf(file,"%-7s = %"FFMT" ",mname[i],Mom(state)[i]); (void) fprintf(file,"\n"); (void) fprintf(file,"\ttype = %u, failed = %u\n", state_type(state),material_failure(state)); if (debugging("prt_params")) fprint_Gas_param(file,Params(state)); else (void) fprintf(file,"Gas_param = %llu\n", gas_param_number(Params(state))); if (debugging("local_gamma")) { (void) fprintf(file,"Local gamma set: %s\n", Local_gamma_set(state) ? "YES" : "NO"); if (Local_gamma_set(state)) (void) fprintf(file,"Local gamma = %"FFMT"\n", Local_gamma(state)); } } /*end g_fprint_raw_state*/
void EulerNext(double att[3], double rot[3], double dt) { double _Mfg[3][3]; clsMatrix Mfg(3, 3, (double *)_Mfg, TRUE); clsMetric::AttitudeToTransformMatrix(att, _Mfg, NULL); double p = rot[0]; double q = rot[1]; double r = rot[2]; // double _Mom[3][3] = { { 0, -r, q }, { r, 0, -p }, { -q, p, 0 } }; // clsMatrix Mom(3, 3, (double *)_Mom, TRUE); //Mom = I-Mom*dt // double _Mom[3][3] = { { 1, r*dt, -q*dt }, { -r*dt, 1, p*dt }, { q*dt, -p*dt, 1 } }; double dt2 = dt*dt/2; double _Mom[3][3] = { //second order estimation { 1-(q*q+r*r)*dt2, r*dt+p*q*dt2, -q*dt+p*r*dt2 }, { -r*dt+p*q*dt2, 1-(p*p+r*r)*dt2, p*dt+q*r*dt2 }, { q*dt+p*r*dt2, -p*dt+q*r*dt2, 1-(p*p+q*q)*dt2 } }; clsMatrix Mom(3, 3, (double *)_Mom, TRUE); //Mfg = exp(Mom*dt)*Mfg, using Tayler series approximation double _New[3][3]; clsMatrix New(3, 3, (double *)_New, TRUE); clsMatrix::X(Mom, Mfg, New); //get next attitude after dt att[0] = ::atan2(_New[1][2], _New[2][2]); if (-New[0][2] >= 1) att[1] = PI/2; else if (-New[0][2] <= -1) att[1] = -PI/2; else att[1] = ::asin(-_New[0][2]); att[2] = ::atan2(_New[0][1], _New[0][0]); }
void EulerNextOde4(double att[3], double rot[3], double dt) { double _Mfg[3][3]; clsMatrix Mfg(3, 3, (double *)_Mfg, TRUE); clsMetric::AttitudeToTransformMatrix(att, _Mfg, NULL); double p = rot[0]; double q = rot[1]; double r = rot[2]; double _Mom[3][3] = { { 0, -r, q }, { r, 0, -p }, { -q, p, 0 } }; clsMatrix Mom(3, 3, (double *)_Mom, TRUE); double _Mom2[3][3]; clsMatrix Mom2(3, 3, (double *)_Mom2, TRUE); clsMatrix::X(Mom, Mom, Mom2); //squre Mom double _Mom3[3][3]; clsMatrix Mom3(3, 3, (double *)_Mom3, TRUE); clsMatrix::X(Mom2, Mom, Mom3); double _Mom4[4][4]; clsMatrix Mom4(3, 3, (double *)_Mom4, TRUE); clsMatrix::X(Mom3, Mom, Mom4); //expm(Mom) = I-Mom*dt+(Mom*dt)^2/2-(Mom*dt)^3/6+(Mom*dt)^4/24 Mom *= -dt; Mom2 *= dt*dt/2; Mom3 *= -dt*dt*dt/6; Mom4 *= dt*dt*dt*dt/24; Mom += Mom2; Mom += Mom3; Mom += Mom4; Mom[0][0] += 1; Mom[1][1] += 1; Mom[2][2] += 1; //Mfg = exp(Mom*dt)*Mfg, using fourth order Tayler series double _New[3][3]; clsMatrix New(3, 3, (double *)_New, TRUE); clsMatrix::X(Mom, Mfg, New); //get next attitude after dt att[0] = ::atan2(_New[1][2], _New[2][2]); if (-New[0][2] >= 1) att[1] = PI/2; else if (-New[0][2] <= -1) att[1] = -PI/2; else att[1] = ::asin(-_New[0][2]); att[2] = ::atan2(_New[0][1], _New[0][0]); }
EXPORT void g_print_internal_energy( const char *mesg, float **ucon, Vec_Muscl *vmuscl, int start, int end) { int i, j, dim = vmuscl->dim; float int_e, ke; float E, m[MAXD], rho; Locstate *state = vmuscl->vst->state + vmuscl->offset; static Locstate st = NULL; if (st == NULL) { g_alloc_state(&st,vmuscl->sizest); } (void) printf("%s\n",mesg); (void) printf("%-4s %-14s %-14s\n","n","Int_energy","Pressure"); for (j = start; j < end; ++j) { Dens(st) = rho = ucon[0][j]; Energy(st) = E = ucon[1][j]; ke = 0.0; for (i = 0; i < dim; ++i) { Mom(st)[i] = m[i] = ucon[2+i][j]; ke += 0.5*sqr(m[i])/rho; } Set_params(st,state[j]); set_type_of_state(st,GAS_STATE); reset_gamma(st); int_e = (E - ke)/rho; (void) printf("%-4d %-14g %-14g",j,int_e,pressure(st)); if (int_e < 0.0) (void) printf("\tNEGATIVE INTERNAL ENERGY\n"); else (void) printf("\n"); } } /*end g_print_internal_energy*/
EXPORT bool output_spectral_in_time( char *basename, Wave *wave, Front *front) { COMPONENT comp; Locstate state; float *coords; float *L = wave->rect_grid->L; float *U = wave->rect_grid->U; float *h = wave->rect_grid->h; float kk,kx,ky,dk,Ek,Vk; int icoords[MAXD]; int dim = wave->rect_grid->dim; int status; char eng_name[100],vor_name[100]; static FILE *eng_file,*vor_file; static int first = YES; int i, ix, iy; int xmax, ymax, kmax, mx, my, dummy; COMPLEX **mesh_eng,**mesh_vor; Locstate lstate,rstate,bstate,tstate; debug_print("fft","Entered output_spectral_in_time()\n"); if (first) { first = NO; (void) sprintf(eng_name,"%s.energy-time.dat",basename); (void) sprintf(vor_name,"%s.vorticity-time.dat",basename); eng_file = fopen(eng_name,"w"); vor_file = fopen(vor_name,"w"); fprintf(eng_file,"VARIABLES=k,E(k)\n",xmax,ymax); fprintf(vor_file,"VARIABLES=k,V(k)\n",xmax,ymax); } xmax = wave->rect_grid->gmax[0]; ymax = wave->rect_grid->gmax[1]; if (!Powerof2(xmax,&mx,&dummy) || !Powerof2(ymax,&my,&dummy)) { screen("output_spectral_in_time() cannot analyze " "mesh not power of 2\n"); screen("xmax = %d ymax = %d\n",xmax,ymax); return FUNCTION_FAILED; } bi_array(&mesh_eng,xmax,ymax,sizeof(COMPLEX)); bi_array(&mesh_vor,xmax,ymax,sizeof(COMPLEX)); for (iy = 0; iy < ymax; ++iy) { for (ix = 0; ix < xmax; ++ix) { icoords[0] = ix; icoords[1] = iy; coords = Rect_coords(icoords,wave); comp = Rect_comp(icoords,wave); state = Rect_state(icoords,wave); if (ix != 0) icoords[0] = ix - 1; else icoords[0] = ix; lstate = Rect_state(icoords,wave); if (ix != xmax-1) icoords[0] = ix + 1; else icoords[0] = ix; rstate = Rect_state(icoords,wave); icoords[0] = ix; if (iy != 0) icoords[1] = iy - 1; else icoords[1] = iy; bstate = Rect_state(icoords,wave); if (iy != ymax-1) icoords[1] = iy + 1; else icoords[1] = iy; tstate = Rect_state(icoords,wave); mesh_eng[ix][iy].real = kinetic_energy(state); mesh_eng[ix][iy].imag = 0.0; mesh_vor[ix][iy].real = (Mom(rstate)[1]/Dens(rstate) - Mom(lstate)[1]/Dens(lstate))/h[0] - (Mom(tstate)[0]/Dens(tstate) - Mom(bstate)[0]/Dens(bstate))/h[1]; mesh_vor[ix][iy].imag = 0.0; } } fft2d(mesh_eng,xmax,ymax,1); fft2d(mesh_vor,xmax,ymax,1); kmax = xmax/2; dk = 2.0*PI/(U[0] - L[0]); fprintf(eng_file,"ZONE\n",kk,Ek); fprintf(vor_file,"ZONE\n",kk,Vk); for (i = 0; i < kmax; ++i) { Ek = 0.0; Vk = 0.0; kk = 2.0*i*PI/(U[0] - L[0]); for (iy = 0; iy < ymax/2; ++iy) { for (ix = 0; ix < xmax/2; ++ix) { kx = 2.0*ix*PI/(U[0] - L[0]); ky = 2.0*iy*PI/(U[1] - L[1]); if (sqrt(sqr(kx)+sqr(ky)) >= kk-0.5*dk && sqrt(sqr(kx)+sqr(ky)) < kk+0.5*dk) { Ek += 2.0*sqrt(sqr(mesh_eng[ix][iy].real) + sqr(mesh_eng[ix][iy].imag)); Vk += 2.0*sqrt(sqr(mesh_vor[ix][iy].real) + sqr(mesh_vor[ix][iy].imag)); } } } fprintf(eng_file,"%lf\t%lf\n",kk,Ek); fprintf(vor_file,"%lf\t%lf\n",kk,Vk); } fflush(eng_file); fflush(vor_file); free_these(2,mesh_eng,mesh_vor); debug_print("fft","Left output_spectral_in_time()\n"); return FUNCTION_SUCCEEDED; } /*end output_spectral_in_time*/
EXPORT bool output_spectral_analysis( char *basename, Wave *wave, Front *front) { COMPONENT comp; Locstate state; float *coords; float *L = wave->rect_grid->L; float *U = wave->rect_grid->U; float *h = wave->rect_grid->h; int icoords[MAXD]; int dim = wave->rect_grid->dim; int status; int step = front->step; char energy_name[100],vorticity_name[100], enstrophy_name[100],dens_name[100],pres_name[100]; FILE *energy_file,*vorticity_file, *enstrophy_file,*dens_file,*pres_file; debug_print("fft","Entered fft_energy_spectral()\n"); (void) sprintf(energy_name,"%s.energy%s.dat",basename, right_flush(step,TSTEP_FIELD_WIDTH)); (void) sprintf(vorticity_name,"%s.vorticity%s.dat",basename, right_flush(step,TSTEP_FIELD_WIDTH)); (void) sprintf(enstrophy_name,"%s.enstrophy%s.dat",basename, right_flush(step,TSTEP_FIELD_WIDTH)); (void) sprintf(dens_name,"%s.density%s.dat",basename, right_flush(step,TSTEP_FIELD_WIDTH)); (void) sprintf(pres_name,"%s.pressure%s.dat",basename, right_flush(step,TSTEP_FIELD_WIDTH)); energy_file = fopen(energy_name,"w"); vorticity_file = fopen(vorticity_name,"w"); enstrophy_file = fopen(enstrophy_name,"w"); dens_file = fopen(dens_name,"w"); pres_file = fopen(pres_name,"w"); if (wave->sizest == 0) { debug_print("fft","Left fft_energy_spectral()\n"); return FUNCTION_FAILED; } switch (dim) { #if defined(ONED) case 1: { int ix; int xmax; COMPLEX *mesh_energy; xmax = wave->rect_grid->gmax[0]; uni_array(&mesh_energy,xmax,sizeof(COMPLEX)); for (ix = 0; ix < xmax; ++ix) { icoords[0] = ix; coords = Rect_coords(icoords,wave); comp = Rect_comp(icoords,wave); state = Rect_state(icoords,wave); mesh_energy[ix].real = Energy(state); mesh_energy[ix].imag = 0.0; } break; } #endif /* defined(ONED) */ #if defined(TWOD) case 2: { int ix, iy; int xmax, ymax, mx, my, dummy; COMPLEX **mesh_energy,**mesh_vorticity,**mesh_enstrophy; Locstate lstate,rstate,bstate,tstate; float kk,kx,ky,dk; xmax = wave->rect_grid->gmax[0]; ymax = wave->rect_grid->gmax[1]; if (!Powerof2(xmax,&mx,&dummy) || !Powerof2(ymax,&my,&dummy)) { screen("fft_energy_spectral() cannot analyze " "mesh not power of 2\n"); screen("xmax = %d ymax = %d\n",xmax,ymax); return FUNCTION_FAILED; } bi_array(&mesh_energy,xmax,ymax,sizeof(COMPLEX)); bi_array(&mesh_vorticity,xmax,ymax,sizeof(COMPLEX)); fprintf(energy_file,"zone i=%d, j=%d\n",xmax,ymax); fprintf(vorticity_file,"zone i=%d, j=%d\n",xmax,ymax); fprintf(dens_file,"zone i=%d, j=%d\n",xmax,ymax); fprintf(pres_file,"zone i=%d, j=%d\n",xmax,ymax); fprintf(enstrophy_file,"zone i=%d, j=%d\n",xmax,ymax); for (iy = 0; iy < ymax; ++iy) { for (ix = 0; ix < xmax; ++ix) { icoords[0] = ix; icoords[1] = iy; coords = Rect_coords(icoords,wave); comp = Rect_comp(icoords,wave); state = Rect_state(icoords,wave); mesh_energy[ix][iy].real = kinetic_energy(state); mesh_energy[ix][iy].imag = 0.0; if (ix != 0) icoords[0] = ix - 1; else icoords[0] = ix; lstate = Rect_state(icoords,wave); if (ix != xmax-1) icoords[0] = ix + 1; else icoords[0] = ix; rstate = Rect_state(icoords,wave); icoords[0] = ix; if (iy != 0) icoords[1] = iy - 1; else icoords[1] = iy; bstate = Rect_state(icoords,wave); if (iy != ymax-1) icoords[1] = iy + 1; else icoords[1] = iy; tstate = Rect_state(icoords,wave); mesh_vorticity[ix][iy].real = (Mom(rstate)[1]/Dens(rstate) - Mom(lstate)[1]/Dens(lstate))/h[0] - (Mom(tstate)[0]/Dens(tstate) - Mom(bstate)[0]/Dens(bstate))/h[1]; mesh_vorticity[ix][iy].imag = 0.0; fprintf(energy_file,"%lf\n",kinetic_energy(state)); fprintf(vorticity_file,"%lf\n",mesh_vorticity[ix][iy].real); fprintf(enstrophy_file,"%lf\n", sqr(mesh_vorticity[ix][iy].real)); fprintf(dens_file,"%lf\n",Dens(state)); fprintf(pres_file,"%lf\n",pressure(state)); } } fft_output2d(basename,"energy",step,wave->rect_grid, mesh_energy); fft_output2d(basename,"vorticity",step,wave->rect_grid, mesh_vorticity); free_these(2,mesh_energy,mesh_vorticity); break; } #endif /* defined(TWOD) */ #if defined(THREED) case 3: { int ix, iy, iz; int xmax, ymax, zmax; COMPLEX ***mesh_energy; xmax = wave->rect_grid->gmax[0]; ymax = wave->rect_grid->gmax[1]; zmax = wave->rect_grid->gmax[2]; tri_array(&mesh_energy,xmax,ymax,zmax,sizeof(COMPLEX)); for (iz = 0; iz < zmax; ++iz) { icoords[2] = iz; for (iy = 0; iy < ymax; ++iy) { icoords[1] = iy; for (ix = 0; ix < xmax; ++ix) { icoords[0] = ix; coords = Rect_coords(icoords,wave); comp = Rect_comp(icoords,wave); state = Rect_state(icoords,wave); mesh_energy[ix][iy][iz].real = Energy(state); mesh_energy[ix][iy][iz].imag = 0.0; } } } break; } #endif /* defined(THREED) */ } fclose(energy_file); fclose(vorticity_file); fclose(enstrophy_file); fclose(dens_file); fclose(pres_file); debug_print("fft","Left fft_energy_spectral()\n"); return FUNCTION_SUCCEEDED; } /*end fft_energy_spectral*/
/*ARGSUSED*/ EXPORT void get_state_1d_overlay( float *coords, Locstate s, COMP_TYPE *ct, HYPER_SURF *hs, INTERFACE *intfc, INIT_DATA *init, int stype) { ONED_OVERLAY *olay = (ONED_OVERLAY*)ct->extra; INPUT_SOLN **is = olay->is; RECT_GRID *gr = &is[0]->grid; INTERFACE *intfc1d = olay->intfc1d; float x, coords1d[3], m, sp; float dcoords[3]; float c0[3], c1[3]; float alpha; int i0[3], i1[3], i, dim = ct->params->dim; int nvars = olay->prt->n_restart_vars; static Locstate s0 = 0, s1 = 0; debug_print("init_states","Entered get_state_1d_overlay()\n"); if (s0 == NULL) { (*ct->params->_alloc_state)(&s0,ct->params->sizest); (*ct->params->_alloc_state)(&s1,ct->params->sizest); } for (i = 0; i < dim; ++i) dcoords[i] = coords[i] - olay->origin[i]; switch (olay->overlay_type) { case RADIAL_OVERLAY: x = mag_vector(dcoords,dim); break; case CYLINDRICAL_OVERLAY: sp = scalar_product(dcoords,olay->direction,dim); for (i = 0; i < dim; ++i) dcoords[i] -= sp*olay->direction[i]; x = mag_vector(dcoords,dim); break; case RECTANGULAR_OVERLAY: x = scalar_product(dcoords,olay->direction,dim); break; case OVERLAY_TYPE_UNSET: default: x = -HUGE_VAL; screen("ERROR in get_state_1d_overlay(), unset overlay type\n"); clean_up(ERROR); break; } if (x > gr->U[0]) x = gr->U[0]; if (x < gr->L[0]) x = gr->L[0]; coords1d[0] = x; if (rect_in_which(coords1d,i0,gr) == FUNCTION_FAILED) { screen("ERROR in get_state_1d_overlay(), rect_in_which() failed\n"); print_general_vector("dcoords = ",dcoords,dim,"\n"); (void) printf("overlay type = %d, x = %g\n",olay->overlay_type,x); (void) printf("rectangular grid gr\n"); print_rectangular_grid(gr); (void) printf("One dimensional interface\n"); print_interface(intfc1d); clean_up(ERROR); } c0[0] = cell_center(i0[0],0,gr); if (x < c0[0]) { i1[0] = i0[0]; i0[0]--; if (i0[0] < 0) i0[0] = 0; c1[0] = c0[0]; c0[0] = cell_center(i0[0],0,gr); } else { i1[0] = i0[0] + 1; if (i1[0] >= gr->gmax[0]) i1[0] = i0[0]; c1[0] = cell_center(i1[0],0,gr); } if (component(c0,intfc1d) != ct->comp) { set_oned_state_from_interface(c0,s0,ct,olay); } else { g_restart_initializer(i0,nvars,ct->comp,is,s0,init); Init_params(s0,ct->params); } if (component(c1,intfc1d) != ct->comp) { set_oned_state_from_interface(c1,s1,ct,olay); } else { g_restart_initializer(i1,nvars,ct->comp,is,s1,init); Init_params(s1,ct->params); } alpha = (c1[0] > c0[0]) ? (x - c0[0])/(c1[0] - c0[0]) : 0.5; ct->params->dim = 1; interpolate_states(olay->front,1.0-alpha,alpha,c0,s0,c1,s1,s); ct->params->dim = dim; m = Mom(s)[0]; switch (olay->overlay_type) { case RADIAL_OVERLAY: case CYLINDRICAL_OVERLAY: if (x > 0.0) { for (i = 0; i < dim; ++i) Mom(s)[i] = m*dcoords[i]/x; } else { for (i = 0; i < dim; ++i) Mom(s)[i] = 0.0; } break; case RECTANGULAR_OVERLAY: for (i = 0; i < dim; ++i) Mom(s)[i] = m*olay->direction[i]; break; case OVERLAY_TYPE_UNSET: default: screen("ERROR in get_state_1d_overlay(), unset overlay type\n"); clean_up(ERROR); break; } set_state(s,stype,s); } /*end get_state_1d_overlay*/
//---------------------------------------------------------------------- int main(int argc, char** argv) { int i, j, k; double r_ij; FILE *XYZ_file, *p_file; std::ifstream IN_file; std::string buffer; std::string IN_filename = "in"; std::string OUT_filename ="out"; std::string XYZ_filename = "xyz"; parameters param; state stat; Vector sumaP; /* Load data */ IN_file.open(IN_filename); IN_file >> param.n; std::getline(IN_file, buffer); IN_file >> param.m; std::getline(IN_file, buffer); IN_file >> param.e; std::getline(IN_file, buffer); IN_file >> param.R; std::getline(IN_file, buffer); IN_file >> param.f; std::getline(IN_file, buffer); IN_file >> param.L; std::getline(IN_file, buffer); IN_file >> param.a; std::getline(IN_file, buffer); IN_file >> stat.T; std::getline(IN_file, buffer); IN_file >> param.tau; std::getline(IN_file, buffer); IN_file >> param.So; std::getline(IN_file, buffer); IN_file >> param.Sd; std::getline(IN_file, buffer); IN_file >> param.Sout; std::getline(IN_file, buffer); IN_file >> param.Sxyz; std::getline(IN_file, buffer); IN_file.close(); param.L = param.L * param.a*(param.n - 1); /* Okreslanie stanu poczatkowego ukladu */ srand(time_t(NULL)); param.N = (int) pow(param.n, 3); stat.r = new Vector[param.N]; stat.p = new Vector[param.N]; stat.F_p = new Vector[param.N]; stat.F_s = new Vector[param.N]; printf("init \n"); for (i = 0; i < param.n; i++){ for (j = 0; j < param.n; j++){ for (k = 0; k < param.n; k++){ stat.r[i + j*param.n + k*param.n*param.n].x = (i - (param.n - 1) / 2.f)*param.a + (j - (param.n - 1) / 2) * param.a / 2.f + (k - (param.n - 1) / 2)*param.a / 2.f; stat.r[i + j*param.n + k*param.n*param.n].y = (j - (param.n - 1) / 2)*param.a*sqrt(3.f) / 2 + (k - (param.n - 1) / 2)*param.a*sqrt(3.f) / 6; stat.r[i + j*param.n + k*param.n*param.n].z = (k - (param.n - 1) / 2)*param.a * sqrt(2.f / 3.f); } } } /* XYZ_file = fopen( XYZ_filename.c_str(), "w"); fprintf(XYZ_file, "%d\n", param.N); fprintf(XYZ_file, "STEP:\t%d\n", param.N); for (i = 0; i < param.N; i++){ fprintf(XYZ_file, "Ar\t%f\t%f\t%f\n", stat.r[i].x, stat.r[i].y, stat.r[i].z); } fprintf(XYZ_file, "\n", param.N); */ printf("p \n"); for (i = 0; i < param.N; i++){ stat.r[i].r = sqrt(pow(stat.r[i].x, 2) + pow(stat.r[i].y, 2) + pow(stat.r[i].z, 2)); stat.p[i].x = znak()*sqrt(2*param.m*(-K_B*stat.T*log(r0_1()) / 2)); stat.p[i].y = znak()*sqrt(2*param.m*(-K_B*stat.T*log(r0_1()) / 2)); stat.p[i].z = znak()*sqrt(2*param.m*(-K_B*stat.T*log(r0_1()) / 2)); stat.p[i].r = sqrt(pow(stat.p[i].x, 2) + pow(stat.p[i].y, 2) + pow(stat.p[i].z, 2)); } sumaP.x = 0; sumaP.y = 0; sumaP.z = 0; printf("sum p \n"); for (i = 0; i < param.N; i++){ sumaP.x += stat.p[i].x; sumaP.y += stat.p[i].y; sumaP.z += stat.p[i].z; stat.F_s[i].x = 0; stat.F_s[i].y = 0; stat.F_s[i].z = 0; stat.F_p[i].x = 0; stat.F_p[i].y = 0; stat.F_p[i].z = 0; } p_file = fopen( "p", "w"); /* for (i = 0; i < param.N; i++){ stat.p[i].x -= sumaP.x / (double) param.N; stat.p[i].y -= sumaP.y / (double) param.N; stat.p[i].z -= sumaP.z / (double) param.N; fprintf(p_file, "%f\t%f\t%f\n", stat.p[i].x, stat.p[i].y, stat.p[i].z); } */ fclose(p_file); /* Initial state */ stat.V_p = 0; stat.V_s = 0; printf("main \n"); for (i = 0; i < param.N; i++){ /* if (stat.r[i].r >= param.L){ stat.V_s += param.f*pow(stat.r[i].r - param.L, 2) / 2; stat.F_s[i].x += param.f*(param.L - stat.r[i].r)* stat.r[i].x / stat.r[i].r; stat.F_s[i].y += param.f*(param.L - stat.r[i].r)* stat.r[i].y / stat.r[i].r; stat.F_s[i].z += param.f*(param.L - stat.r[i].r)* stat.r[i].z / stat.r[i].r; } */ for (j = i; j < param.N; j++){ if (i != j){ r_ij = sqrt(pow(stat.r[i].x - stat.r[j].x, 2) + pow(stat.r[i].y - stat.r[j].y, 2) + pow(stat.r[i].z - stat.r[j].z, 2)); stat.V_p += param.e*(pow(param.R / r_ij, 12) - 2 * pow(param.R / r_ij, 6)); stat.F_p[i].x += 12 * param.e*(pow(param.R / r_ij, 12) - pow(param.R / r_ij, 6))*(stat.r[i].x - stat.r[j].x) / pow(r_ij, 2); stat.F_p[j].x -= stat.F_p[i].x; stat.F_p[i].y += 12 * param.e*(pow(param.R / r_ij, 12) - pow(param.R / r_ij, 6))*(stat.r[i].y - stat.r[j].y) / pow(r_ij, 2); stat.F_p[j].y -= stat.F_p[i].y; stat.F_p[i].z += 12 * param.e*(pow(param.R / r_ij, 12) - pow(param.R / r_ij, 6))*(stat.r[i].z - stat.r[j].z) / pow(r_ij, 2); stat.F_p[j].z -= stat.F_p[i].z; } } printf("%d/%d\r",i,param.N); } printf("\n"); //-------------------------------------------------------------------- printf("Hello, OpenCL\n"); //Setup our GLUT window and OpenGL related things //glut callback functions are setup here too init_gl(argc, argv); //initialize our CL object, this sets up the context example = new CL(); //load and build our CL program from the file #include "part2.cl" //std::string kernel_source is defined in this file example->loadProgram(kernel_source); //initialize our particle system with positions, velocities and color int num = NUM_PARTICLES; std::vector<Vec4> pos(num); std::vector<Vec4> color(num); std::vector<Vec4> F_p(num); std::vector<Vec4> F_s(num); std::vector<Vec4> Mom(num); //fill our vectors with initial data for(int i = 0; i < num; i++) { pos[i].x = stat.r[i].x; pos[i].y = stat.r[i].y; pos[i].z = stat.r[i].z; pos[i].w = 1.0f; F_p[i].x = stat.F_p[i].x; F_p[i].y = stat.F_p[i].y; F_p[i].z = stat.F_p[i].z; F_p[i].w = 1.0f; F_s[i].x = stat.F_s[i].x; F_s[i].y = stat.F_s[i].y; F_s[i].z = stat.F_s[i].z; F_s[i].w = 1.0f; Mom[i].x = stat.p[i].x; Mom[i].y = stat.p[i].y; Mom[i].z = stat.p[i].z; Mom[i].w = 1.0f; color[i] = Vec4(1.0f, 0.0f,0.0f, 1.0f); } //our load data function sends our initial values to the GPU example->loadData(pos, color, F_p, F_s, Mom); //initialize the kernel example->popCorn(); //this starts the GLUT program, from here on out everything we want //to do needs to be done in glut callback functions glutMainLoop(); }
int Look_txt() { TCHAR filter[] = TEXT("Ghemical MD results File (*.txt)\0*.txt\0") TEXT("All Files (*.*)\0*.*\0"); TCHAR fpath[1024]; TCHAR filename[1024]; sprintf(filename, "\0"); { DWORD nFilterIndex; vector<string> names; vector<string> *pnames = &names; vector<vector<double> > vectors; vectors.reserve(2000000); while (OpenFileDlg(0, filter, fpath, nFilterIndex) == S_OK) { ReadDatFile(NULL, fpath, filename, &vectors, pnames); pnames = NULL; printf("\nfilename %s\n\n", filename); int cols = names.size(); int rows = vectors.size(); #if WRITE_LOCKED_FORCES int cMom = 4 - 1; int cVx = 5 - 1; int cFxup = 14 - 1; int cFxdw = 17 - 1; int cVxup = 8 - 1; int cVxdw = 11 - 1; #endif #if WRITE_WORKED_FORCES int cMom = 4 - 1; int cVx = 5 - 1; int cVxup = 14 - 1; int cVxdw = 17 - 1; int cVx_wk_up = 8 - 1; int cVx_wk_dw = 11 - 1; int cFx_wk_up = 20 - 1; int cFx_wk_dw = 23 - 1; #endif vector<double> means(cols, 0.0); printf("vectors.size() = %d\n",rows); printf("names.size() = %d\n", cols); for (vector<vector<double> >::iterator it = vectors.begin(); it != vectors.end(); it++) { for (int c = 0; c < cols; c++) { means[c] += (*it).operator [](c); } } for (int c = 0; c < cols; c++) { means[c] /= rows; printf("mean(%s) = %f\n", names[c].c_str(), means[c]); } #if WRITE_LOCKED_FORCES || WRITE_WORKED_FORCES int r0 = 0; cout << "enter r0\n"; cin >> r0; #endif #if WRITE_LOCKED_FORCES vector<double> dF(rows-r0); for (int r = r0; r < rows; r++) { dF[r-r0] = vectors[r][cFxup] - vectors[r][cFxdw]; } Statistika (dF, "dF"); vector<double> Mom(rows-r0); for (r = r0; r < rows; r++) { Mom[r-r0] = vectors[r][cMom]; } Statistika (Mom, "Mom"); vector<double> dV(rows-r0); for (r = r0; r < rows; r++) { dV[r-r0] = vectors[r][cVxup] - vectors[r][cVxdw]; } Statistika (dV, "dV"); vector<double> Vx(rows-r0); for (r = r0; r < rows; r++) { Vx[r-r0] = vectors[r][cVx]; } Statistika (Vx, "Vx"); #endif #if WRITE_WORKED_FORCES vector<double> dF_wk(rows-r0); for (int r = r0; r < rows; r++) { dF_wk[r-r0] = vectors[r][cFx_wk_up] - vectors[r][cFx_wk_dw]; } Statistika (dF_wk, "dF_wk"); vector<double> dV_wk(rows-r0); for (r = r0; r < rows; r++) { dV_wk[r-r0] = vectors[r][cVx_wk_up] - vectors[r][cVx_wk_dw]; } Statistika (dV_wk, "dV_wk"); //if (!worked[n1]) vector<double> Mom(rows-r0); for (r = r0; r < rows; r++) { Mom[r-r0] = vectors[r][cMom]; } Statistika (Mom, "Mom"); vector<double> dV(rows-r0); for (r = r0; r < rows; r++) { dV[r-r0] = vectors[r][cVxup] - vectors[r][cVxdw]; } Statistika (dV, "dV"); vector<double> Vx(rows-r0); for (r = r0; r < rows; r++) { Vx[r-r0] = vectors[r][cVx]; } Statistika (Vx, "Vx"); #endif } } /*else { DWORD nFilterIndex; if (SaveFileDlg(0, filename, filter, nFilterIndex) == S_OK) { SetDlgItemText(ref->hDlg,IDC_EDIT_TRAJFILE2, filename); } }*/ printf("Hello World!\n"); return 0; }