Выч.физ / include
.doc#include<conio.h> #include<stdio.h> #include<math.h> #include<time.h> #include "randomc.h" #include "mersenne.cpp"
FILE *OUT, *IN, *END;
double T;
long start_configuration_max, mks_max; long N; long seed, counter;
int sp[1000];
int SOSEDY ( int i )
{ int rez;
if(i==0) { rez=sp[N-1]; } else { rez=sp[i-1]; }
if(i==N-1) { rez=rez+sp[0]; } else { rez=rez+sp[i+1]; }
return rez; }
double MAGNETIC ( )
{ long i; double rez=0.0;
for(i=0;i<N;i++) { rez=rez+sp[i]; }
return rez/N; }
double ENERGY ( )
{ long i; double rez=0.0;
for(i=0;i<N;i++) { rez=rez - sp[i]*SOSEDY(i); }
return rez/N; }
void INITIAL ( )
{ long i;
for(i=0;i<N;i++)
{ sp[i]=1; }
}
int main ( void )
{
IN = fopen("CONFIGURATION.dat","r"); OUT = fopen("OUT.dat","w+"); END = fopen("END.dat","w+");
if((OUT==NULL)||(IN==NULL)) { printf("\n ERROR!"); getch(); return 0; }
double r, w;
long i, a, start_configuration, start_configuration_real=0, mks, ss;
int sp_new, dE;
fscanf(IN,"%lf",&T); fscanf(IN,"%ld",&start_configuration_max); fscanf(IN,"%ld",&mks_max);
fscanf(IN,"%ld",&N); fscanf(IN,"%ld",&ss);
printf("T = %4.3lf\n",T); printf("start_configuration_max = %ld\n",start_configuration_max);
printf("mks_max = %ld\n",mks_max); printf("N = %ld\n",N); printf("ss = %ld\n",ss);
fclose(IN);
seed = time(0);
CRandomMersenne Mersenne(seed);
INITIAL( );
for(start_configuration=0;start_configuration<start_configuration_max;start_configuration++)
{
if(start_configuration%ss==0)
{ printf("\n End %d configuration",start_configuration); }
for(mks=0;mks<mks_max;mks++)
{
seed = time(0) + (start_configuration%100) + (mks%1000);
Mersenne.RandomInit(seed);
for(a=0;a<N;a++)
{
i = Mersenne.IRandomX(0,N-1);
r=Mersenne.IRandomX(0,999)/1000.0;
if(r>0.5) { sp_new=sp[i]; }
else { sp_new=-sp[i]; }
dE = (sp[i] - sp_new) * SOSEDY(i);
if(dE<0)
{
sp[i]=sp_new;
continue;
}
w=1.0/exp(-dE/T);
r=Mersenne.IRandomX(0,999)/1000.0;
if(w>=r)
{ sp[i]=sp_new; }
}
r=MAGNETIC( );
fprintf(OUT,"%15.14lf\n",r);
r=ENERGY( );
fprintf(OUT,"%15.14lf\n",r);
}
END = fopen("END.dat","w+");
start_configuration_real++;
fprintf(END,"%ld",start_configuration_real);
fclose(END);
}
fclose(OUT);
}