コード例 #1
0
ファイル: phimain.c プロジェクト: Antoinehoff/CP3_UE7
  int main (int argc, char **argv)
  {
    	  int k;
	  /* Intializes random number generator */
	  time_t t;
	  srand((unsigned) time(&t));
	  
	  // Parameter
	  ndim = 2;
	  kappa = 1.;
	  lambda =1.;
	  int N = 10;  
	  
	 // Set fuer geom_pbc
	  lsize = (int *) malloc((ndim+1)*sizeof(int));
	  for (k=1; k <= ndim; k++)
	  {
		  lsize[k] = N;
	  }
	  
	  geom_pbc();
	  
	  double complex *phi;
	  phi = (double complex*) malloc(nvol*sizeof(double complex));
	  double *p_old;
	  p_old = (double *) malloc(nvol*sizeof(double));
	  double *p_new;
	  p_new = (double *) malloc(nvol*sizeof(double));	  
	  
	  double randreal, randim;
	for(k=0; k<nvol; k++)
	{
		randreal = (double)(rand() & 0xFF ) * .01;
		randim = (double)(rand() & 0xFF ) * .01;
		phi[k] = (double complex)randreal + randim*I;
	}
	
	int randpos = (rand() & 0xFF) % nvol;
	printf("Changed Position: %d\n", randpos);
	
	double S_old = S(phi,0.);
	calc_local_dist(phi,0.,p_old);
	printf("Phi(x)=%f+i*%f  S=%f  p(x)=%e\n", creal(phi[randpos]),cimag(phi[randpos]), S_old, p_old[randpos]);
	randreal = (double)(rand() & 0xFF ) * .01;
	randim = (double)(rand() & 0xFF ) * .01;
	phi[randpos] = (double complex)randreal + randim*I;
	double S_new = S(phi,0.);
	calc_local_dist(phi,0.,p_new);
	printf("Phi'(x)=%f+i*%f  S'=%f  p'(x)=%e\n", creal(phi[randpos]),cimag(phi[randpos]), S_new, p_new[randpos]);
	
	printf("P'/P=%e  p'(x)/p(x)=%e\n",exp(S_old-S_new),(p_new[randpos]/p_old[randpos]));
	double complex M_new = M(phi);
	printf("M=%f + i*%f\n",creal(M_new),cimag(M_new));
	
	free(lsize);
	free(nn);
	free(phi);
	free(p_old);
	free(p_new);
  }
コード例 #2
0
ファイル: Mc_test.cpp プロジェクト: micgro42/MC
BOOST_FIXTURE_TEST_CASE(MagnetizationTest1,F1Point){
	double lambda = 4;
	double kappa=0.5;
	double h=0.3;
	ndim=2;
	int steps=6;
	lsize = (int *) malloc((ndim+1) * sizeof(int));
	for (int i=1; i<=ndim; ++i){
		lsize[i]=steps;
	}
	geom_pbc();
	BOOST_REQUIRE_EQUAL(nvol,36);
	vector<double> fieldReal,fieldIm;
	for (int i=1;i<=nvol;++i){
		fieldReal.push_back(testMc.getRandomUni());
		fieldIm.push_back(testMc.getRandomUni());
	}


	BOOST_REQUIRE_EQUAL(testMc.setFields(fieldReal,fieldIm),0);
	testMc.setLambda(lambda);
	testMc.setKappa(kappa);
	testMc.setHReal(h);
	testMc.setHIm(0.0);
	testMc.thermalizeField();


	int numUpdates = 100000;//0;
	vector<double> results;
	testMc.calculateMeanMagnetization(numUpdates, results);
	double tol=0.0002;
	BOOST_CHECK_CLOSE(testMc.getMeanRealMagnetisation(),0.8616,tol*100);
	BOOST_CHECK(abs(testMc.getMeanImMagnetisation())<testMc.getMeanImMagnetisationError()); // test that the imaginary part is 0 within the error



	free(lsize);


}