Autor: João Medeiros | Publicado: 2014-04-09T12:02:00-03:00



#include 

#include 

#include 



#define NC 10000000

#define dx 0.0001

#define ntime 600

#define nsamples 100000

#define nker 10000

#define ntransient 15000

#define IA 16807

#define IM 2147483647

#define AM (1.0/IM)

#define IQ 127773

#define IR 2836

#define NTAB 32

#define NDIV (1+(IM-1)/NTAB)

#define EPS 1.2e-7

#define RNMX (1.0-EPS)

#define TTT 100



float ran1(long *idum)



{

int j;

long k;

static long iy=0;

static long iv[NTAB];

float temp;

if (*idum &lt;= 0 || !iy) {&nbsp;

if (-(*idum) &lt; 1) *idum=1;&nbsp;

else *idum = -(*idum);

for (j=NTAB+7;j&gt;=0;j--) {&nbsp;

k=(*idum)/IQ;

*idum=IA*(*idum-k*IQ)-IR*k;

if (*idum &lt; 0) *idum += IM;

if (j &lt; NTAB) iv[j] = *idum;

}

iy=iv[0];

}

k=(*idum)/IQ;&nbsp;

*idum=IA*(*idum-k*IQ)-IR*k; if (*idum &lt; 0) *idum += IM;&nbsp;

j=iy/NDIV;

iy=iv[j];&nbsp;

iv[j] = *idum;&nbsp;

if ((temp=AM*iy) &gt; RNMX) return RNMX; else return temp;

}



float gasdev(long *idum)

{

float ran1(long *idum);

static int iset=0;

static float gset;

float fac,rsq,v1,v2;

if (*idum &lt; 0) iset=0;&nbsp;

if (iset == 0) {&nbsp;

do {

v1=2.0*ran1(idum)-1.0;v2=2.0*ran1(idum)-1.0; rsq=v1*v1+v2*v2;&nbsp;

} while (rsq &gt;= 1.0 || rsq == 0.0);&nbsp;

fac=sqrt(-2.0*log(rsq)/rsq);

gset=v1*fac;

iset=1;&nbsp;

return v2*fac;

} else {&nbsp;

iset=0;&nbsp;

return gset;&nbsp;

}

}





int main (void) {

 int i, kn, km, ke, ki, kij;

 float p[NC], ps[NC], xmin, xvmin, xmax, xvmax, jmin, jmax, alfa, sv, gamma, we, ca,cn, cj, xll, tj, dt, dt2, dt3, dts, cam, w, idum;

 float cnm, gammam, cjm, cd, ncoarse, ntimenoise, xm, xm2, xm3, xm4, xv, xv2, xv3,xv4, jam, jam2, jam3, jam4, t1, t2, t3, t4, tk;

 float xx1, xx10, xxv1, xxv10, v1, v10, v101;

 float jitot1[ntime], jdtot1[ntime], energy [ntime], correlacaov1[nsamples][1000], correlacao;

 float xv1[nker];

 for(i=0;i&lt;NC;i++)

 {

 p[i]=0;

 ps[i]=0;

 }

 xmin = - NC * dx /2.0;

 xvmin = - NC * dx /2.0;



 xmax = NC * dx /2.0;

 xvmax = NC * dx /2.0;



 jmin = - NC * dx /2.0;

 jmax = NC * dx /2.0;

&nbsp;&nbsp;

 idum = -798764321;

 

 alfa = 5.0;

&nbsp; &nbsp; &nbsp; sv = 1.0;



 &nbsp; we = 1.0;

 &nbsp; gamma = 1.0;

 &nbsp; ca = 1.0;

 &nbsp; cn = 0.0;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cj = 10.0;





&nbsp; &nbsp; &nbsp; xll = 20.0;

&nbsp; &nbsp; &nbsp; tj =&nbsp; 25.0;

  &nbsp;

 &nbsp; dt = 0.0001;

 &nbsp; dt2 = dt * dt;

&nbsp; &nbsp; &nbsp; dt3 = dt2 * dt;

&nbsp; &nbsp; &nbsp; dts = sqrt(dt);

  &nbsp;

 &nbsp; cam = ca / we;

&nbsp; &nbsp; &nbsp; cnm = cn / we;

&nbsp; &nbsp; &nbsp; gammam = gamma / we;

&nbsp; &nbsp; &nbsp; cjm = cj / we;



&nbsp; &nbsp; &nbsp; cd = (1.0 + gammam * dt / 2.0);&nbsp; &nbsp; &nbsp; &nbsp;



&nbsp; &nbsp; &nbsp; ncoarse = floor(0.005/dt);



&nbsp; &nbsp; &nbsp; ntimenoise = 10 * floor((1.0 / alfa) / 0.005);



 &nbsp; xm = 0.0;

 &nbsp; xm2 = 0.0;

 &nbsp; xm3 = 0.0;

 &nbsp; xm4 = 0.0;



&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xv = 0.0;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xv2 = 0.0;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xv3 = 0.0;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xv4 = 0.0;



&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jam&nbsp; = 0.0;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jam2 = 0.0;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jam3 = 0.0;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jam4 = 0.0;

   &nbsp;

  &nbsp; for(kn=0;kn&lt;nsamples; kn++)

  &nbsp; {

  &nbsp; for(km=0;km&lt;nsamples;km++)

  &nbsp; {

  &nbsp; correlacaov1[kn][km]=0;

  &nbsp; }

  &nbsp; }



 &nbsp; for(i=0;i&lt;ntime;i++)

 &nbsp; {

  jitot1[i] = 0.0;

  jdtot1[i] = 0.0;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; energy[i] = 0.0; &nbsp; &nbsp; &nbsp; &nbsp;

  }

 

 for(i=0; i&lt;nsamples; i++)

 {

 v1 = 0.0;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; for (kn = 0; kn

   {

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(km = 0;km

   &nbsp; {

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w = gasdev(&amp;idum);

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v1 = v1 - alfa * v1 * dt + sv * w * dts;

   &nbsp; &nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }

 }

 

 &nbsp; xxv1 = 0.000;

&nbsp; &nbsp; &nbsp; xxv10 = 0.0;



&nbsp; &nbsp; &nbsp; xx1 =&nbsp; 0.0;

&nbsp; &nbsp; &nbsp; xxv1 = 0.0;



&nbsp; &nbsp; &nbsp; for(ke=0; ke&lt;nker; ke++)

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; xv1[ke] = 0.0;

 

  for(ki = 0; ki&lt; ntransient;ki++)

  {

  for(kij = 0; kij&lt; ncoarse; kij++)

  {

   correlacaov1[ki][kij]=v1;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v10 = v1;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w = gasdev(&amp;idum);

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v1 = v1 - alfa * v1 * dt + sv * w * dts;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v101 = sqrt(dt)*(v10+v1)/(2.0)/we;



&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xxv10 = xxv1;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xxv10 = xv1[0];

  &nbsp; xx10 = xx1;







&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t1 = 0.0;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t2 = 0.0;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t3 = 0.0;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t4 = 0.0;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tk = 0.0;



&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(ke = 0; ke&lt; nker; ke++)

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tk = tk + exp(-(ke-1) * dt * alfa) * xv1[ke];



&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t1 = (1.0 - gammam * dt) * xxv10;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t1 = xxv10 - gammam * dt * tk;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t2 = - (cam + cjm) * xx10 * dt;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t3 = - cnm * xx10 * xx10 * xx10 * dt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t4 = v101; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;



&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xxv1 = t1 + t2 + t3 + t4;



&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(ke = 0; ke&lt; nker-1;ke++)

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xv1[ke+1] = xv1[ke];



&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xv1[1] = xxv1; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;



&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xx1 = xx10 + (xxv1+xxv10)*dt/2.0;



}

}

correlacao=0;



   for(ki = 0; ki&lt; ntransient;ki++) /*dado TTT */

  {

  for(kij = 0; kij&lt; ncoarse; kij++)

  {

  correlacao= correlacao + correlacaov1[ki][kij+TTT]*correlacaov1[ki][kij];

  }

  correlacao= correlacao/ncoarse;

 }

 &nbsp; printf("AAAAAAAA\n\n\n\n %f\n\n\n\n", correlacao);

&nbsp; &nbsp; return 0;

}