latticeEinfuehrung_UebungToFill/0000755000175000017500000000000012713355405017245 5ustar jvolmerjvolmerlatticeEinfuehrung_UebungToFill/init.h0000755000175000017500000000102512712421516020356 0ustar jvolmerjvolmer/************************************************************************** * * File: init.h * * This is a: header file for init.c * * * Author/s: Jenifer Gonzalez Lopez * Andreas Nube * * * Berlin...Summer_2008 * **************************************************************************/ #ifndef INIT_H #define INIT_H /* initialize paths cold */ void init_cold(); /* initialize paths hot */ void init_hot(double a); /* initizlize momentum gaussian */ void init_momentum(double *P); #endif /*INIT_H*/ latticeEinfuehrung_UebungToFill/ho.R0000644000175000017500000000264712712411350017776 0ustar jvolmerjvolmerlibrary(boot) ######### analysis ################### hodata <- read.table("Routput", skip=1, col.names=c("npath","x","x2","acceptance"),colClasses =c("integer","double","double","double")) xmean <- mean(hodata$x) xse <- sqrt(var(hodata$x)/length((hodata$x-1))) print(paste0(" = ", xmean)) #sprintf(" = %14.7e\n", xmean) print(paste0("d = ", xse)) xmean2 <- mean(hodata$x2) xse2 <- sqrt(var(hodata$x2)/length((hodata$x2-1))) print(paste0(" = ", xmean2)) print(paste0("d = ", xse2)) accmean <- mean(hodata$acceptance) accse <- sqrt(var(hodata$acceptance)/length((hodata$acceptance-1))) print(paste0("Acceptance= ", accmean)) print(paste0("dAcceptance= ", accse)) # set.seed(1717) # bmeanx <- function(data,indices){ d <- data[indices,] average <- mean(d$x) return(average) } xboot <- boot(data=hodata, statistic=bmeanx, R=1000) #print(xboot) #print(xboot$t0) #print(xboot$t) cat(" = ",xboot$t0," Standard deviation = ", sd(xboot$t[,1]), "\n") ci <- boot.ci(xboot, type="basic") cat("95% CI from ", ci$basic[1,4], " - ", ci$basic[1,5],"\n") bmeanx2 <- function(data,indices){ d <- data[indices,] average <- mean(d$x2) return(average) } xboot <- boot(data=hodata, statistic=bmeanx2, R=1000) cat(" = ",xboot$t0," Standard deviation = ", sd(xboot$t[,1]), "\n") ci = boot.ci(xboot, type="basic") cat("95% CI from ", ci$basic[1,4], " - ", ci$basic[1,5], "\n") latticeEinfuehrung_UebungToFill/Makefile0000755000175000017500000000067112713355255020717 0ustar jvolmerjvolmerVPATH=. SF_HEADER=funcHO.h C_MATH_LIB=-lm CC=gcc CFLAGS=-Wall -pedantic run: harm_osc harm_osc : harm_osc.o funcHO.o init.o Makefile ${CC} -o harm_osc harm_osc.o funcHO.o init.o $(C_MATH_LIB) harm_osc.o : harm_osc.c Makefile ${CC} ${CFLAGS} -c harm_osc.c init.o : init.c init.h Makefile ${CC} ${CFLAGS} -c init.c funcHO.o : funcHO.c funcHO.h Makefile ${CC} ${CFLAGS} -c funcHO.c clean : rm harm_osc.o funcHO.o init.o latticeEinfuehrung_UebungToFill/harm_osc.c0000755000175000017500000001376212713354706021223 0ustar jvolmerjvolmer/************************************************************************** * * File: harm_osc.c * * * It calculates: generates trajectories and calculates observables on the fly * * Author Karl Jansen * adopted from a HMC code by Gonzalez Lopez, Jenifer, Nube, Andreas and Renner, Dru * * * Berlin Summer ... 2015 * **************************************************************************/ #define MAINPROGRAM #include #include #include #include #include #include #include "init.h" #include "funcHO.h" #include "global.h" int main( int argc, char* argv[] ){ /* "argc" is the number of arguments you pass to the programm: integer number */ /* "argv[]" are the arguments you pass to the programm: string */ /* argv[0] is always the name of the programm so if you pass "n" arguments then "argc = n+1" */ int n_MCsteps; int n_MCmeas=0; int seed; /* used for generating the random number */ double x2_CF; double x_N,R; double acceptance=0.0; double total_x=0.0; double total_sdx=0.0; double total_x2=0.0; double total_sdx2=0.0; double total_acc=0.0; double total_sdacc=0.0; double error=0.0; double x1=0.0; double x2=0.0; FILE *cfout; FILE *Rout; int t; /* the next if checks the number of arguments that have been passed to the program when calling it */ /* if the number of arguments is different from the one expected then it finishes and prints the error message */ /* for calling the program we use the script file: "run.sh" */ if( argc != 9 ) { printf( "%s \n", argv[0] ); return 1; } /** define arguments whose value will be asigned in the call of the programm in the "run.sh" script file **/ N = atoi(argv[1]); seed = atoi(argv[2]); g_num_MCsteps = atoi(argv[3]); g_init_method = atoi(argv[4]); /* 0 = cold ; 1 = hot */ /* (global) parameters for HO (Creutz) action */ g_a = atof(argv[5]); g_M_0= atof(argv[6]); g_mu2= atof(argv[7]); /* number of skipped trajetories */ g_num_MCskip = atoi(argv[8]); printf( "N = %i\n", N ); printf( "seed = %i\n", seed ); printf( "Numb_skip = %i\n", g_num_MCskip ); printf( "Numb_MCsteps = %i\n", g_num_MCsteps ); printf( "g_init_method = %i\n", g_init_method ); printf( "g_a = %f\n", g_a ); printf( "g_M_0 = %f\n", g_M_0 ); printf( "g_mu2 = %f\n", g_mu2 ); /** initialize random number generator **/ srand(seed); /************************ * allocation of memory ***********************/ /** allocation of memory for PATHS **/ /** g_X is global **/ /** g_X[i] with i in 0 ... (N-1) are entries of g_X **/ g_X=(double*)malloc(sizeof(double)*N); if(g_X==NULL) { fprintf(stderr,"allocation of memory failed"); exit(-1); } /*****************************************/ /* Compute theoretical value of harmonic */ /* oscillator from Creutz-Freedman */ /*****************************************/ x_N=(double) N; R=1. + 0.50*g_a*g_a*g_mu2 - g_a*sqrt(g_mu2) * sqrt(1.0 + 0.25 *g_a*g_a*g_mu2); x2_CF=(1.0 + pow(R,x_N))/(1-pow(R,x_N)); x2_CF=x2_CF/(2.0*g_M_0*sqrt(g_mu2)*sqrt(1.0 + 0.25*g_a*g_a*g_mu2)); cfout=fopen("cfoutput","w"); fprintf(cfout," X^2= %14.7e\n",x2_CF); fclose(cfout); /***********************/ /* initialize path g_X */ /***********************/ if(g_init_method==0){ init_cold(); /* for all i: g_X[i] = 1 */ } else if(g_init_method==1){ init_hot(1); /* all g_X[i] are set randomly */ } /********************************/ /********************************/ /* Main Loop over MC steps (MD) */ /********************************/ /********************************/ Rout=fopen("Routput","w"); fprintf(Rout,"No. of path, , , Acceptance\n"); for(n_MCsteps=1; n_MCsteps <= g_num_MCsteps; n_MCsteps++){ ///////* TO DO *///////// /* change path g_X according to the harmonic oscillator action: modify function S_ho() in file funcH0.c */ acceptance = S_ho(); /**********************************************************/ /** perform measurements, calculate observables on g_X **/ /**********************************************************/ ///////* TO DO *////////// /* Initialization */ x1 = ; x2 = ; for( t=0; t g_num_MCskip ) { /* print observables to file */ fprintf(Rout," %i %14.7e %14.7e %14.7e\n", n_MCsteps, x1, x2, acceptance); /* sum observables over all measuring MC steps */ total_x = total_x + x1; total_sdx = total_sdx + x1*x1; total_x2 = total_x2 + x2; total_sdx2 = total_sdx2 + x2*x2; total_acc = total_acc + acceptance; total_sdacc = total_sdacc + acceptance*acceptance; n_MCmeas = n_MCmeas + 1; } } /* end of loop over trajectories */ fclose(Rout); printf( "total number of measurements %i \n", n_MCmeas ); /****************************************************/ /* Calculate and print final results of observables */ /****************************************************/ ///////* TO DO *////////// /* Compute total average of x,x^2 and acceptance including errors and print values */ printf( " = %14.7e d( )= %14.7e \n", total_x, error ); printf( " = %14.7e d( )= %14.7e theor= %14.7e \n", total_x2, error, x2_CF ); printf( " = %14.7e d( )= %14.7e \n", total_acc, error ); /***************/ /* free memory */ /***************/ /** free memory for path **/ free(g_X); return 0; } latticeEinfuehrung_UebungToFill/funcHO.c0000755000175000017500000000761112713355201020575 0ustar jvolmerjvolmer/********************************************************************************** * * File: funcHO.c * * * It contains: all the needed EXTERNAL FUNCTIONS (except the initialization ones) * * Author: Karl Jansen * Adopted from a HMC programm by Jenifer Gonzalez Lopez, Andreas Nube and Dru Renner * * * Berlin...Summer_2015 * ********************************************************************************/ #include #include #include #include #include "init.h" #include "funcHO.h" #include "global.h" /************************************************* * MATHEMATICAL functions needed for the action ************************************************/ /* return random number in the interval [0,1] */ double random_number(){ return ((double)rand())/((double)RAND_MAX); } /* generates one gaussian distributed random number (taken from the Swinger code of Andreas) */ double gauss(){ return (sqrt(-2.*log(random_number()))*cos(2.*M_PI*random_number())); } /* calculates the sum of the square == square norm of a vector ==> returns a scalar*/ double square_norm (double *path){ int i; double sum=0; for(i=0;i returns a scalar */ double scalar_product (double *path_1,double *path_2){ int i; double sum=0; for(i=0;i returns a vector */ void scalar_times_vector ( double *vec_out, double scal,double *vec_in){ int i; for(i=0;i returns a vector */ void add_vectors (double *vec_out,double *vec_in2,double *vec_in1){ int i; for(i=0;i returns a vector */ void v_eq_v_p_s_t_v(double *A,double *B,double c,double *D){ int i; for(i=0;i #include #include #include "global.h" #include "init.h" #include "funcHO.h" /** Paths initialization **/ /* initialize paths with zeroes */ void init_cold(){ int i; for(i=0;i
Baidu
map