示例#1
0
int main(void)
{
    FILE *f;

    int i;
    int iteration;

    double x[2];
    double xx[2];
    double t, dt;

    dt = 0.05;
    iteration=1000;

    x[0] = 1.0; // q
    x[1] = 0.0; // p

    f = fopen("trajectory_symp2.dat","w");

    for (i=0; i<iteration; i++) {
        t = i*dt;
        fprintf(f,"%lf %lf %lf %le\n", t, x[0], x[1], Hamiltonian(t,x[0],x[1]));
        Integrator(Symplectic2, t,dt,x,xx);

        x[0] = xx[0];
        x[1] = xx[1];
    }
    fclose(f);
    return 0;
}
示例#2
0
int Trajectory(double* X1, double* X2, double* Phi1, double* Phi2, double* K, int numProcs, int myID)
{
    double* Eta = new double[TOT];
    double* P = new double[TOT];
    double* F = new double[TOT];
    double* temK = new double[TOT];
    double* temBuf = new double[TOT];
    double t = sqrt(0.5);
    int flag;
    MPI_Generate(Eta, t, numProcs, myID);
    M(Eta, Phi1, K, numProcs, myID);
    MPI_Generate(Eta, t, numProcs, myID);
    M(Eta, Phi2, K, numProcs, myID);
    MPI_Setzero(X1, numProcs, myID);
    MPI_Setzero(X2, numProcs, myID);
    MPI_Generate(P, 1.0, numProcs, myID);
    MPI_Assign(K, temK, numProcs, myID);
    double hamStart = Hamiltonian(X1, X2, Phi1, Phi2, P, K, numProcs, myID);
    flag = FermionForce(X1, X2, Phi1, Phi2, F, K, numProcs, myID);
    if(!flag)
    {
        MPI_Assign(temK, K, numProcs, myID);
        return 0;
    }
    MPI_Multiply(F, 0.5*dt, temBuf, numProcs, myID);
    MPI_Add(P, temBuf, P, numProcs, myID);
    for(int i = 0; i<(N_md-1); i++)
    {
        MPI_Multiply(P, dt, temBuf, numProcs, myID);
        MPI_Add(K, temBuf, K, numProcs, myID);
        flag = FermionForce(X1, X2, Phi1, Phi2, F, K, numProcs, myID);
        if(!flag)
        {
            MPI_Assign(temK, K, numProcs, myID);
            return 0;
        }
        MPI_Multiply(F, dt, temBuf, numProcs, myID);
        MPI_Add(P, temBuf, P, numProcs, myID);
    }
    MPI_Multiply(P, dt, temBuf, numProcs, myID);
    MPI_Add(K, temBuf, K, numProcs, myID);
    flag = FermionForce(X1, X2, Phi1, Phi2, F, K, numProcs, myID);
    if(!flag)
    {
        MPI_Assign(temK, K, numProcs, myID);
        return 0;
    }
    MPI_Multiply(F, 0.5*dt, temBuf, numProcs, myID);
    MPI_Add(P, temBuf, P, numProcs, myID);
    double hamEnd = Hamiltonian(X1, X2, Phi1, Phi2, P, K, numProcs, myID);
    double r = 0.0;
    if(myID == ROOT)
    {
        random_device rd;
        mt19937 generator(rd());
        uniform_real_distribution<double> dis(0.0, 1.0);
        r = dis(generator);
    }
    MPI_Bcast(&r, 1, MPI_DOUBLE, ROOT, MPI_COMM_WORLD);
    double s = exp(hamStart-hamEnd);
    if(myID == ROOT)
    {
        ofstream file_log("evolution.log", ios_base::app);
        file_log<<"Hamiltoian: "<<hamStart<<" "<<hamEnd<<" "<<r<<" "<<s<<endl;
        file_log.close();
    }
    delete [] Eta;
    delete [] P;
    delete [] F;
    delete [] temK;
    delete [] temBuf;
    if(r<s)
    {
        return 1;
    }
    else
    {
        MPI_Assign(temK, K, numProcs, myID);
        return 0;
    }
}