int main(int argc, char **argv){ int N = 5000; initialtau1 = -4.0*pi; double t = 0.; D = (double *)calloc(N,sizeof(double)); if(initial_impulse){ D[0] = 200.; }else{ D[0] = 0.; } printf("init,X:%.2lf ShearRate:%.2lf tau20:%.3lf\n",X,ShearRate,initialtau1); while(1){ beta = 0.535*Q/X; printf("X:%.2lf ShearRate:%.2lf tau20:%.3lf\n",X,ShearRate,initialtau1); FILE *fp; char filename[256]; sprintf(filename,"./data/wavelet_SR%.2lf_tau20_%.3lf_X%.2lf_Q%.2lf_impulse%.1lfperturber%.1lf.dat", ShearRate,initialtau1,X,Q,D[0],Dimp); if((fp=fopen(filename,"w"))==NULL){ exit(1); } printf("output filename:%s\n",filename); fprintf(fp,"# perturbation mass(Dimp): %lf\n",Dimp); fprintf(fp,"# t, D[i]\n"); int i; for(i=1;i<N;i++){ t = i_to_time(i); D[i] = compute_D(i); } for(i=0;i<N;i++){ t = i_to_time(i); fprintf(fp,"%lf %lf\n",t,D[i]); } fclose(fp); X_change(); /* shearrate_change(); */ /* tau20_change(); */ if(simulation_end){exit(0);} } return 0; }
int main(){ int N = 3000; beta = 0.535*Q/X; double t = 0.; D = (double *)calloc(N,sizeof(double)); if(initial_impulse){ D[0] = 100.; }else{ D[0] = 0.; } FILE *fp; char filename[256]; sprintf(filename,"impDtime_from%lf.dat",initialtime); if((fp=fopen(filename,"w"))==NULL){ exit(1); } fprintf(fp,"# perturbation mass(Dimp): %lf\n",Dimp); fprintf(fp,"# t, D[i]\n"); int i; for(i=1;i<N;i++){ t = i_to_time(i); D[i] = compute_D(i); /* fprintf(stderr,"D[%d]:%lf\n",i,D[i]); */ /* fprintf(fp,"%lf %lf\n",t,D[i]); */ } for(i=0;i<N;i++){ t = i_to_time(i); fprintf(fp,"%lf %lf\n",t,D[i]); } fclose(fp); return 0; }
void compute_single_D( DOUBLE* _D ) { compute_D( _D ); }
void compute_Rf( DOUBLE** _Rf, DOUBLE* _D ) { INT i; DOUBLE pre = curr_dt / (kB * T); INT LD = size*DIMS0; #if USE_MPI if ( hydro == DIFF_CHOLESKY ) { compute_Rf_cholesky_mpi( _Rf, _D ); return; } #endif if( geyer_on_the_fly ) { compute_Rf_geyer_in_fly( _Rf ); return; } compute_D( _D ); if ( !hydro ) { for ( i = 0; i < size; ++i ) { _Rf[0][ i * DIMS0 ] = pre * diag_D[ i * DIMS0 ] * F[0][ i * DIMS0 ]; _Rf[0][ i * DIMS0 + 1 ] = pre * diag_D[ i * DIMS0 + 1 ] * F[0][ i * DIMS0 + 1 ]; _Rf[0][ i * DIMS0 + 2 ] = pre * diag_D[ i * DIMS0 + 2 ] * F[0][ i * DIMS0 + 2 ]; } return; } for ( i = 0; i < g_threads; ++i ) { memset( _Rf[i], 0, sizeof (DOUBLE) * DIMS0 * size ); } #if USE_LAPACK && !USE_MPI { DOUBLE dzero = 0; DOUBLE done = 1; int ione = 1; const char* uplo = "U"; SYMVD( uplo, &LD, &done, _D, &LD, F[0], &ione, &dzero, _Rf[0], &ione ); } #else #ifdef _OPENMP #pragma omp parallel for schedule( dynamic ) #endif for ( i = 0; i < size; ++i ) { INT k, j, l; INT tid = 0; #ifdef _OPENMP tid = omp_get_thread_num( ); #endif for ( j = 0; j < 3; ++j ) { for ( k = g_id; k < i; k += g_numprocs ) { for ( l = 0; l < 3; ++l ) { _Rf[tid][ i * DIMS0 + j ] += F[0][ k * DIMS0 + l ] * _D[ (i * DIMS0 + j) * LD + k * DIMS0 + l ]; _Rf[tid][ k * DIMS0 + l ] += F[0][ i * DIMS0 + j ] * _D[ (i * DIMS0 + j) * LD + k * DIMS0 + l ]; } } } if ( g_id == 0 ) { _Rf[tid][ i * DIMS0 ] += F[0][ i * DIMS0 ] * _D[ i * DIMS0 * LD + i * DIMS0 ]; _Rf[tid][ i * DIMS0 + 1] += F[0][ i * DIMS0 + 1] * _D[ i * DIMS0 * LD + i * DIMS0 ]; _Rf[tid][ i * DIMS0 + 2] += F[0][ i * DIMS0 + 2] * _D[ i * DIMS0 * LD + i * DIMS0 ]; } } /* Reduce forces */ for ( i = 1; i < g_threads; ++i ) { INT j; for ( j = 0; j < size * DIMS0; ++j ) { _Rf[0][j] += _Rf[i][j]; } } #endif for ( i = 0; i < size * DIMS0; ++i ) { _Rf[0][ i ] *= pre; } #if USE_MPI MPI_Reduce( _Rf[0], _Rf[1], size*DIMS0, MPI_VALUE_TYPE, MPI_SUM, 0, MPI_COMM_WORLD ); if ( g_id == 0 ) { memcpy( _Rf[0], _Rf[1], sizeof (DOUBLE)*(size * DIMS0) ); } MPI_Bcast( _Rf[0], size*DIMS0, MPI_VALUE_TYPE, 0, MPI_COMM_WORLD ); #endif }
int sscf (basis_set_t *basis, erd_t *erd_inp, double *H, double * S, double *S_sinv, int n, int n_ele, int maxit, int diis_lim, double *D_old, double *D_new, double *F) { double *int_buffer; double *tmp; double *tmp2; double *F_tt; double *F_t; double *D_t; double *delta_D; double err; int conv = 0; int iter = 0; double trace; double s; double c; double lambda; int i; int max_funcs; int max_buffer_dim; max_funcs = 2 * basis->max_momentum + 1; max_buffer_dim = max_funcs * max_funcs * max_funcs * max_funcs; int_buffer = (double *)malloc (max_buffer_dim * sizeof(double)); tmp = (double *)malloc (n * n * sizeof(double)); F_t = (double *)malloc (n * n * sizeof(double)); D_t = (double *)malloc (n * n * sizeof(double)); delta_D = (double *)malloc (n * n * sizeof(double)); tmp2 = (double *)malloc (n * n * sizeof(double)); F_tt = (double *)malloc (n * n * sizeof(double)); memset (int_buffer, 0, max_buffer_dim * sizeof(double)); memset (tmp, 0, n * n * sizeof(double)); memset (F_t, 0, n * n * sizeof(double)); memset (D_old, 0, n * n * sizeof(double)); memset (D_new, 0, n * n * sizeof(double)); memset (D_t, 0, n * n * sizeof(double)); memset (delta_D, 0, n * n * sizeof(double)); memset (tmp2, 0, n * n * sizeof(double)); memset (F_tt, 0, n * n * sizeof(double)); memcpy (F, H, n * n * sizeof(double)); memcpy (F_t, H, n * n * sizeof(double)); do { #if ODA /*1. D <- Diagonalize(F_t) */ cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, 1.0, S_sinv, n, F_t, n, 0.0, tmp, n); cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, 1.0, tmp, n, S_sinv, n, 0.0, F_tt, n); /*Compute D*/ compute_D (n, n_ele, F_tt, D_new); /*Transform D*/ cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, 1.0, S_sinv, n, D_new, n, 0.0, tmp, n); cblas_dgemm (CblasColMajor, CblasNoTrans, CblasTrans, n, n, n, 1.0, tmp, n, S_sinv, n, 0.0, D_new, n); /*2. conv = Check (D-D') */ /*3. F = Fock (D)*/ memcpy (F, H, n * n * sizeof(double)); build_fock (basis, erd_inp, int_buffer, D_new, F); /* delta_D = D - D_t*/ memset (delta_D, 0, n * n * sizeof(double)); cblas_daxpy (n * n, -1.0, D_t, 1, delta_D, 1); cblas_daxpy (n * n, 1.0, D_new, 1, delta_D, 1); /* s = trace(F_t * delta_D) */ cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, 1.0, F_t, n, delta_D, n, 0.0, tmp, n); s = compute_trace (tmp, n); /*tmp = F - F_t*/ memset (tmp, 0, n * n * sizeof(double)); cblas_daxpy (n * n, -1.0, F_t, 1, tmp, 1); cblas_daxpy (n * n, 1.0, F, 1, tmp, 1); /* c = trace (tmp * delta_D) */ cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, 1.0, tmp, n, delta_D, n, 0.0, tmp2, n); c = compute_trace (tmp2, n); /* set lambda */ if (c < -s/2.0) { lambda = 1.0; } else { lambda = -s / (2.0 * c); } memcpy (D_old, D_t, n * n * sizeof (double)); memcpy (F_tt, F_t, n * n * sizeof (double)); /* D_t = (1-lambda) * D_t + lambda * D */ memset (tmp, 0, n * n * sizeof(double)); cblas_daxpy (n * n, (1.0 - lambda), D_t, 1, tmp, 1); cblas_daxpy (n * n, lambda, D_new, 1, tmp, 1); memset (D_t, 0, n * n * sizeof(double)); cblas_daxpy (n * n, 1.0, tmp, 1, D_t, 1); /* F_t = (1-lambda) * F_t + lambda * F */ memset (tmp, 0, n * n * sizeof(double)); cblas_daxpy (n * n, (1.0 - lambda), F_t, 1, tmp, 1); cblas_daxpy (n * n, lambda, F, 1, tmp, 1); memset (F_t, 0, n * n * sizeof(double)); cblas_daxpy (n * n, 1.0, tmp, 1, F_t, 1); /* print energy at each iteration */ err = fabs (calc_hf_ene (D_new, F, H, n) - calc_hf_ene (D_old, F_tt, H, n)); /* fprintf (stderr, "\n iteration ene %d: %lf", iter, calc_hf_ene(D_new, F, H, n)); */ /* fprintf (stderr, "\n iteration %d: %10.6e", iter, err); */ /* fprintf (stderr, "\n lambda %d: %lf",iter, lambda); */ fprintf (stdout, "\n %d, %lf, %10.6e", iter, calc_hf_ene(D_new, F, H, n), err); iter++; #endif #if NORM memcpy (D_old, D_new, n * n * sizeof(double)); /*Build F*/ memcpy (F, H, n * n * sizeof(double)); build_fock (basis, erd_inp, int_buffer, D_new, F); /*Transform F*/ cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, 1.0, S_sinv, n, F, n, 0.0, tmp, n); cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, 1.0, tmp, n, S_sinv, n, 0.0, F_t, n); /*Compute D*/ compute_D (n, n_ele, F_t, D_new); /*Transform D*/ cblas_dgemm (CblasColMajor, CblasNoTrans, CblasNoTrans, n, n, n, 1.0, S_sinv, n, D_new, n, 0.0, tmp, n); cblas_dgemm (CblasColMajor, CblasNoTrans, CblasTrans, n, n, n, 1.0, tmp, n, S_sinv, n, 0.0, D_new, n); iter++; /*Check energy convergence*/ err = fabs (calc_hf_ene (D_new, F, H, n) - calc_hf_ene (D_old, F, H, n)); /* fprintf (stderr, "\n iteration ene %d: %lf", iter, calc_hf_ene(D_new, F, H, n)); */ /* fprintf (stderr, "\n iteration %d: %10.6e", iter, err); */ fprintf (stdout, "\n %d, %lf, %10.6e", iter, calc_hf_ene(D_new, F, H, n), err); #endif } while ((iter < maxit)); fprintf (stderr, "\n Final Energy: %lf \n", calc_hf_ene (D_new, F, H, n)); /* printmatCM ("Final D", D_new, n, n); */ /* printmatCM ("Final F", F, n, n); */ free (D_t); free (delta_D); free (tmp2); free (tmp); free (F_t); free (F_tt); free (int_buffer); return 0; }