Beispiel #1
0
        double dSF()
        {
            Dirac D = new Dirac(this);
            Vector chi = new Vector(Dirac.N, DateTime.Now.Millisecond);
            D.phi = D.MulD(chi);

            return 0;
        }
Beispiel #2
0
 public void Prepare()
 {
     x = phi;
     ri = AXPY(Complex.MinOne, MulD(x0), phi);
     rhat0 = ri;
     alpha = wi = Complex.One;
     roi = V1hermV2(rhat0, rhat0);
 }
Beispiel #3
0
        public void Update(int x, int y, int z, int t, int dir, bool withOR)
        {
            Link A = GetSumOfStaples(x, y, z, t, dir);
            //here A is the sum of staples!

            //heatbath
            //Link W = Mul(U[x, y, z, t, dir], A); double det;
            //Link X = new Link(true);
            ////for heat-bath
            //for (int i = 0; i < d; i++)
            //    for (int j = i + 1; j < d; j++)
            //    {
            //        Complex a = W.A[i, i];
            //        Complex B = W.A[i, j];
            //        Complex C = W.A[j, i];
            //        Complex D = W.A[j, j];

            //        // det = (W.A[i, i] * W.A[j, j] - W.A[i, j] * W.A[j, i]).x;

            //        double x0 = 1 / 2f * (a.x + D.x);
            //        double x1 = 1 / 2f * (B.y + C.y);
            //        double x2 = 1 / 2f * (B.x - C.x);
            //        double x3 = 1 / 2f * (a.y - D.y);

            //        //  det = GetDet(A);
            //        det = x0 * x0 + x1 * x1 + x2 * x2 + x3 * x3;
            //        Link a_ = GetHeatBath(det, i, j);
            //        Link r = new Link(true);

            //        det = Math.Sqrt(det);
            //        x0 /= det;
            //        x1 /= det;
            //        x2 /= det;
            //        x3 /= det;

            //        r.A[i, i] = new Complex(x0, x3);
            //        r.A[i, j] = new Complex(x2, x1);
            //        r.A[j, i] = new Complex(-x2, x1);
            //        r.A[j, j] = new Complex(x0, -x3);

            //        r = Mul(a_, r.HermConj());

            //        W = Mul(r, W);
            //        X = Mul(r, X);
            //    }

            //U[x, y, z, t, dir] = Mul(X, U[x, y, z, t, dir]);
            //

             //for overrelaxation
            //if (GetRandom() < 0.1)
             /*           if (withOR)
            {
                //for (int or = 0; or < 0; or++)
                //{
                    //calculating determinant of SU(2)
                    double det = Math.Pow(GetDet(A),1.0/3.0);
                    for (int i = 0; i < SU3.d; i++)
                        for (int j = 0; j < SU3.d; j++)
                        {
                            A.A[i, j].x /= det;
                            A.A[i, j].y /= det;
                        }

                    A = Mul(A.HermConj(), Mul(U[x, y, z, t, dir].HermConj(), A.HermConj()));
                    Orthogonalize(ref A);
                    U[x, y, z, t, dir]=A;
            }
            else
              {*/
            //for Metropolis

            //for (int hit = 0; hit <= 10; hit++)
            //{
            //    bool accepted = false; double dSG; Link X = new Link(true);
            //    while (!accepted)
            //    {

            //        X = GetRandomMetroLink();
            //        //-I
            //        for (int i = 0; i < d; i++) X.A[i, i].x--;

            //        dSG = -beta / SU3.d * ReTr(Mul(X, Mul(U[x, y, z, t, dir], A)));

            //        double r = GetRandom();
            //        if (r <= Math.Exp(-dSG)) accepted = true;
            //    }

            //    for (int i = 0; i < d; i++) X.A[i, i].x++;
            //    U[x, y, z, t, dir] = Mul(X, U[x, y, z, t, dir]);
            //}

            //for poor dynamical fermions
            for (int hit = 0; hit <= 10; hit++)
            {
                bool accepted = false; double dSG; Link X = new Link(true);
                while (!accepted)
                {

                    X = GetRandomMetroLink();
                    Xsite = new Site(x, y, z, t); Xdir = dir;
                    Uprime = Mul(X, U[x, y, z, t, dir]);

                    Dirac D = new Dirac(this);
                    Vector chi = new Vector(Dirac.N);
                    chi.FillGaussRandom();

                    D.phi = D.MulD(chi);

                    double Fold = Dirac.V1hermV2(chi, chi).x;

                    D.Prepare();
                    D.IterPrime();

                    //here - D.x = D^-1*phi

                    double Fnew = Dirac.V1hermV2(D.x, D.x).x;

                    double dSF =  Fnew - Fold;

                    //X-I
                    for (int i = 0; i < d; i++) X.A[i, i].x--;

                    dSG = -beta / SU3.d * ReTr(Mul(X, Mul(U[x, y, z, t, dir], A)));

                    double r = GetRandom();
                    if (r <= Math.Exp(-(dSG + dSF))) accepted = true;
                }

                for (int i = 0; i < d; i++) X.A[i, i].x++;
                U[x, y, z, t, dir] = Mul(X, U[x, y, z, t, dir]);
            }
        }
Beispiel #4
0
 public Vector MulDold(Vector V)
 {
     Vector res = new Vector(N);
     for (int i = 0; i < N; i++)
         for (byte j = 0; j < 4; j++)
             for (byte k = 0; k < 3; k++)
                 for (int i1 = 0; i1 < N; i1++)
                     for (byte j1 = 0; j1 < 4; j1++)
                         for (byte k1 = 0; k1 < 3; k1++)
                             res[i, j, k] += D(GetSite(i), GetSite(i1), j, j1, k, k1) * V[i1, j1, k1];
     return res;
 }
Beispiel #5
0
        public Vector MulDprime(Vector V)
        {
            Vector res = new Vector(N);
            Site[] AdjacentSites = new Site[9];
            Link[] AdjacentLinks = new Link[9];
            Complex g; double flipsign = 1.0; int mu = 0; Complex c;
            for (int i = 0; i < N; i++)
            {

                AdjacentSites[0] = GetSite(i);
                AdjacentLinks[0] = AdjacentSites[0] == U.Xsite ? U.Uprime : new Link(true);
                for (int ai = 1; ai < 5; ai++)
                {
                    mu = (ai - 1) % 4 + 1;
                    AdjacentSites[ai] = AdjacentSites[0];
                    U.GetNode(ref AdjacentSites[ai].x, ref AdjacentSites[ai].y, ref AdjacentSites[ai].z, ref AdjacentSites[ai].t, ai);
                    AdjacentLinks[ai] = AdjacentSites[ai] == U.Xsite ? U.Uprime : U.U[AdjacentSites[ai].x, AdjacentSites[ai].y, AdjacentSites[ai].z, AdjacentSites[ai].t, mu];
                }
                for (int ai = 5; ai < 9; ai++)
                {
                    mu = (ai - 1) % 4 + 1;
                    AdjacentSites[ai] = AdjacentSites[0];
                    U.GetNode(ref AdjacentSites[ai].x, ref AdjacentSites[ai].y, ref AdjacentSites[ai].z, ref AdjacentSites[ai].t, -(ai - 4));
                    AdjacentLinks[ai] = AdjacentSites[ai] == U.Xsite ? U.Uprime : U.U[AdjacentSites[ai].x, AdjacentSites[ai].y, AdjacentSites[ai].z, AdjacentSites[ai].t, mu];
                }

                for (int ai = 0; ai < 9; ai++)
                {
                    flipsign = ai < 5 ? 1.0 : -1.0;
                    mu = (ai - 1) % 4 + 1;
                    int i1 = GetSiteNumber(AdjacentSites[ai]);
                    for (byte j = 0; j < 4; j++)
                        for (byte j1 = 0; j1 < 4; j1++)
                        {
                            if (ai == 0) g = Complex.One;
                            else
                                g = (flipsign == 1.0) ? OneMinusgamma[mu - 1][j, j1] : OnePlusgamma[mu - 1][j, j1];
                            if (g.x != 0 || g.y != 0)
                            {
                                c = ai == 0 ? Complex.One : new Complex(-kappa, 0) * g;
                                for (byte k = 0; k < 3; k++)
                                    for (byte k1 = 0; k1 < 3; k1++)
                                    {
                                        if (ai == 0 && j == j1 && k == k1) res[i, j, k] += Complex.One * V[i1, j1, k1];
                                        else
                                        {
                                            if (ai != 0)
                                            {
                                                if (flipsign == 1.0)
                                                    res[i, j, k] += c * AdjacentLinks[ai].A[k, k1] * V[i1, j1, k1];
                                                else
                                                    res[i, j, k] += c * AdjacentLinks[ai].A[k1, k].Conj() * V[i1, j1, k1];//u.HermConj().A[k, k1]
                                            }
                                        }
                                    }
                            }
                        }
                }
            }
            return res;
        }
Beispiel #6
0
        //public void Prepare()
        //{
        //    rprev = AXPY(Complex.MinOne, MulD(x0), phi);
        //    rhat0 = rprev;
        //    alpha = wprev = Complex.One;
        //    roprev = V1hermV2(rhat0, rhat0);
        //}
        //public int Iter()
        //{
        //    int Niter = 100;
        //    for (int i = 0; i < Niter; i++)
        //    {
        //        roi = V1hermV2(rhat0, rprev);
        //        if (roi.x == 0)
        //            return -i;
        //        beta = (roi / roprev) * (alpha / wprev);
        //        pi = AXPY(beta, AXPY(-wprev, vprev, pprev), rprev);
        //        vi = MulD(pi);
        //        alpha = roi / V1hermV2(rhat0, vi);//roprev
        //        s = AXPY(-alpha, vi, rprev);
        //        t = MulD(s);
        //        wi = V1hermV2(t, s) / V1hermV2(t, t);
        //        x = AXPY(alpha, pi, AXPY(wi, s, xprev));
        //        ri = AXPY(-wi, t, s);
        //        rprev = ri; pprev = pi; vprev = vi; xprev = x;
        //        roprev = roi; wprev = wi;
        //        if (Dirac.V1hermV2(ri, ri).Module() < 1E-5) return i;
        //    }
        //    return 100;
        //}
        public int IterPrime()
        {
            int Niter = 100; Complex roprev;
            for (int i = 0; i < Niter; i++)
            {
                roprev = roi;
                roi = V1hermV2(rhat0, ri);
                if (roi.x == 0)
                    return -i;
                beta = (roi / roprev) * (alpha / wi);
                pi = AXPY(beta, AXPY(-wi, vi, pi), ri);

                vi = MulDprime(pi);
                alpha = roi / V1hermV2(rhat0, vi);//roprev
                if (alpha.x==1 && alpha.y == 0) break;
                s = AXPY(-alpha, vi, ri);

                t = MulDprime(s);
                wi = V1hermV2(t, s) / V1hermV2(t, t);
                x = AXPY(alpha, pi, AXPY(wi, s, x));
                ri = AXPY(-wi, t, s);

                //rprev = ri; pprev = pi; vprev = vi; xprev = x;
                //roprev = roi; wprev = wi;

                if (Dirac.V1hermV2(ri, ri).Module() < 1E-1) return i;
            }

            return Niter;
        }
Beispiel #7
0
        public Vector MulD(Vector V)
        {
            //Site s = new Site(1, 1, 1, 1);
            //GetNode(s, 1);
            //System.Windows.Forms.MessageBox.Show(s.x.ToString());
            //Vector res = new Vector(N);
            //Site mainsite, adjacentsite; Complex g;
            //for (int i = 0; i < N; i++)
            //{
            //    mainsite = GetSite(i);
            //    for (int ai = 1; ai < 5; ai++)
            //    {
            //        adjacentsite = mainsite;
            //        U.GetNode(ref adjacentsite.x, ref adjacentsite.y, ref adjacentsite.z, ref adjacentsite.t, ai);
            //        int i1 = GetSiteNumber(adjacentsite);
            //        for (byte j = 0; j < 4; j++)
            //            for (byte j1 = 0; j1 < 4; j1++)
            //            {
            //                //g = OneMinusgamma[ai - 1][j, j1];
            //                //if (g.x != 0 || g.y != 0)
            //                //{

            //                    for (byte k = 0; k < 3; k++)
            //                        for (byte k1 = 0; k1 < 3; k1++)
            //                        {

            //                            res[i, j, k] += D(mainsite, adjacentsite, j, j1, k, k1) * V[i1, j1, k1];
            //                        }
            //             //   }
            //            }
            //    }
            //    for (int ai = 1; ai < 5; ai++)
            //    {
            //        adjacentsite = mainsite;
            //        U.GetNode(ref adjacentsite.x, ref adjacentsite.y, ref adjacentsite.z, ref adjacentsite.t, -ai);
            //        int i1 = GetSiteNumber(adjacentsite);
            //        for (byte j = 0; j < 4; j++)
            //            for (byte j1 = 0; j1 < 4; j1++)
            //            {
            //                //g = OneMinusgamma[ai - 1][j, j1];
            //                //if (g.x != 0 || g.y != 0)
            //                //{

            //                    for (byte k = 0; k < 3; k++)
            //                        for (byte k1 = 0; k1 < 3; k1++)
            //                            res[i, j, k] += D(mainsite, adjacentsite, j, j1, k, k1) * V[i1, j1, k1];
            //              //  }
            //            }
            //    }

            //}

            //Site[] AdjacentSites = new Site[9]; Complex g; int mu = 0;
            //for (int i = 0; i < N; i++)
            //{
            //    AdjacentSites[0] = GetSite(i);
            //    for (int ai = 1; ai < 5; ai++)
            //    {
            //        AdjacentSites[ai] = AdjacentSites[0];
            //        U.GetNode(ref AdjacentSites[ai].x, ref AdjacentSites[ai].y, ref AdjacentSites[ai].z, ref AdjacentSites[ai].t, ai);
            //    }
            //    for (int ai = 5; ai < 9; ai++)
            //    {
            //        AdjacentSites[ai] = AdjacentSites[0];
            //        U.GetNode(ref AdjacentSites[ai].x, ref AdjacentSites[ai].y, ref AdjacentSites[ai].z, ref AdjacentSites[ai].t, -(ai - 4));
            //    }

            //    for (int ai = 0; ai < 9; ai++)
            //    {
            //        mu = (ai - 1) % 4;
            //        int i1 = GetSiteNumber(AdjacentSites[ai]);
            //        for (byte j = 0; j < 4; j++)
            //            for (byte j1 = 0; j1 < 4; j1++)
            //            {
            //                if (ai == 0) g = Complex.One;
            //                else
            //                    g = OneMinusgamma[mu][j, j1];
            //                if (g.x != 0 || g.y != 0)
            //                    for (byte k = 0; k < 3; k++)
            //                        for (byte k1 = 0; k1 < 3; k1++)
            //                        {
            //                            res[i, j, k] += D(AdjacentSites[0], AdjacentSites[ai], j, j1, k, k1) * V[i1, j1, k1];
            //                        }

            //            }
            //    }
            //}
            //return res;

            Vector res = new Vector(N);
            Site[] AdjacentSites = new Site[9];
            Link[] AdjacentLinks = new Link[9];
            Complex g; double flipsign = 1.0; int mu = 0; Complex c;
            for (int i = 0; i < N; i++)
            {
                AdjacentSites[0] = GetSite(i);
                AdjacentLinks[0] = new Link(true);
                for (int ai = 1; ai < 5; ai++)
                {
                    mu = (ai - 1) % 4 + 1;
                    AdjacentSites[ai] = AdjacentSites[0];
                    U.GetNode(ref AdjacentSites[ai].x, ref AdjacentSites[ai].y, ref AdjacentSites[ai].z, ref AdjacentSites[ai].t, ai);
                    AdjacentLinks[ai] = U.U[AdjacentSites[ai].x, AdjacentSites[ai].y, AdjacentSites[ai].z, AdjacentSites[ai].t, mu];
                }
                for (int ai = 5; ai < 9; ai++)
                {
                    mu = (ai - 1) % 4 + 1;
                    AdjacentSites[ai] = AdjacentSites[0];
                    U.GetNode(ref AdjacentSites[ai].x, ref AdjacentSites[ai].y, ref AdjacentSites[ai].z, ref AdjacentSites[ai].t, -(ai - 4));
                    AdjacentLinks[ai] = U.U[AdjacentSites[ai].x, AdjacentSites[ai].y, AdjacentSites[ai].z, AdjacentSites[ai].t, mu];
                }

                for (int ai = 0; ai < 9; ai++)
                {
                    flipsign = ai < 5 ? 1.0 : -1.0;
                    mu = (ai - 1) % 4 + 1;
                    int i1 = GetSiteNumber(AdjacentSites[ai]);
                    for (byte j = 0; j < 4; j++)
                        for (byte j1 = 0; j1 < 4; j1++)
                        {
                            if (ai == 0) g = Complex.One;
                            else
                                g = (flipsign == 1.0) ? OneMinusgamma[mu - 1][j, j1] : OnePlusgamma[mu - 1][j, j1];
                            if (g.x != 0 || g.y != 0)
                            {
                                c = ai == 0 ? Complex.One : new Complex(-kappa, 0) * g;
                                for (byte k = 0; k < 3; k++)
                                    for (byte k1 = 0; k1 < 3; k1++)
                                    {
                                        if (ai == 0 && j == j1 && k == k1) res[i, j, k] += Complex.One * V[i1, j1, k1];
                                        else
                                        {
                                            if (ai != 0)
                                            {
                                                if (flipsign == 1.0)
                                                    res[i, j, k] += c * AdjacentLinks[ai].A[k, k1] * V[i1, j1, k1];
                                                else
                                                    res[i, j, k] += c * AdjacentLinks[ai].A[k1, k].Conj() * V[i1, j1, k1];//u.HermConj().A[k, k1]
                                            }
                                        }
                                    }
                            }
                        }
                }
            }
            return res;
        }
Beispiel #8
0
        public Complex D(Site n, Site m, byte alpha, byte beta, byte a, byte b)
        {
            Complex r = new Complex(); int c = 0;
            if (n == m && alpha == beta && a == b) { r += Complex.One; c++; }

            Site t;
            for (int i = 1; i <= 4; i++)
            {
                t = n;
                U.GetNode(ref t.x, ref t.y, ref t.z, ref t.t, i);
                if (t == m) { r += new Complex(-kappa, 0) * OneMinusgamma[i - 1][alpha, beta] * U.U[n.x, n.y, n.z, n.t, i].A[a, b];
                    c++;
                   // if (c > 1)
                   //     System.Windows.Forms.MessageBox.Show("WTF?");
                }
            }
            for (int i = 1; i <= 4; i++)
            {
                t = n;
                U.GetNode(ref t.x, ref t.y, ref t.z, ref t.t, -i);
                if (t == m)
                {
                    r += new Complex(-kappa, 0) * OnePlusgamma[i - 1][alpha, beta] * U.U[t.x, t.y, t.z, t.t, i].A[b, a].Conj();//.HermConj().A[a, b]; - much more efficient!
                    c++; // if (c > 1)
                       // System.Windows.Forms.MessageBox.Show("WTF?");
                }
            }

            return r;
        }
Beispiel #9
0
        public Vector AXPY(Complex A, Vector X, Vector Y)
        {
            Vector res = new Vector(X.N);

            for (int i = 0; i < X.N; i++)
                for (byte j = 0; j < 4; j++)
                    for (byte k = 0; k < 3; k++)
                        res[i, j, k] = A * X[i, j, k] + Y[i, j, k];
            return res;
        }
Beispiel #10
0
 public static Complex V1hermV2(Vector Vector1, Vector Vector2)
 {
     Complex res = Complex.Zero;
     for (int i = 0; i < Vector1.N; i++)
         for (byte j = 0; j<4;j++)
             for (byte k = 0; k<3;k++)
         res += (Vector1[i,j,k]).Conj() * Vector2[i,j,k];
     return res;
 }
Beispiel #11
0
        public Dirac(SU3 GaugeField)
        {
            U = GaugeField;
            OneMinusgamma = new Complex[4][,] { OneMinusGamma1, OneMinusGamma2, OneMinusGamma3, OneMinusGamma4 };
            OnePlusgamma = new Complex[4][,] { OnePlusGamma1, OnePlusGamma2, OnePlusGamma3, OnePlusGamma4 };

            Nx = U.Ns; Nxy = Nx * Nx; Nxyz = Nxy * Nx; N = Nxyz * U.Nt;
            Ny = U.Ns; Nz = U.Ns; Nt = U.Nt;

            phi = new Vector(N);

            r0 = new Vector(N);
            rhat0 = new Vector(N);
            rprev = new Vector(N);
            pi = new Vector(N);
            vi = new Vector(N);
            t = new Vector(N);
            s = new Vector(N);
            xprev = new Vector(N);

            vprev = new Vector(N);
            pprev = new Vector(N);

            ri = new Vector(N);

            x0 = new Vector(N);
            x = new Vector(N);
        }
Beispiel #12
0
        private void button11_Click(object sender, EventArgs e)
        {
            ////check Gaussness
            //Vector v = new Vector(100);
            //int N = 100; double a = 0, b = 10;
            //int[] inters = new int[N];
            //for (int i = 0; i < 10000; i++)
            //{
            //    double r = v.GetGaussRandom()+5;
            //    if (r>a && r < b)
            //    inters[(int)(r * N/(b-a))]++;

            //}

            //for (int i = 0; i < N; i++)
            //    chart1.Series[0].Points.AddXY((double)i / (double)N, inters[i]);

            ////basic delta
            //int K = 100, n = 3;
            //Complex[][] chi = new Complex[K][];
            //for (int i = 0; i < K; i++)
            //{
            //    chi[i] = new Complex[n];
            //    for (int j = 0; j < n; j++)
            //        chi[i][j] = GetGaussRandom();
            //}

            //double[,] delta = new double[n, n];
            //double res1 = 0, res2 = 0;
            //for (int i = 0; i < n; i++)
            //    for (int j = 0; j < n; j++)
            //    {
            //        Complex t = new Complex();
            //        for (int k = 0; k < K; k++)
            //            t += (chi[k][i] * chi[k][j].Conj());
            //        delta[i, j] = 1 / (double)(2 * K) * t.x;// OneOverK;
            //        if (i == j) res1 += delta[i, j]; else res2 += delta[i, j];
            //    }
            //Text = res1.ToString() + "   " + (res2 / n).ToString();

            //real delta
            int K = 1, n = 10;
            Vector[] chi = new Vector[K];
            for (int i = 0; i < K; i++)
            {
                chi[i] = new Vector(n,rand.Next());
                chi[i].FillGaussRandom();

            }
            double[, , , , ,] delta = new double[n, n, 4, 4, 3, 3];
            double res1 = 0, res2 = 0;
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    for (byte alpha = 0; alpha < 4; alpha++)
                        for (byte beta = 0; beta < 4; beta++)
                            for (byte a = 0; a < 3; a++)
                                for (byte b = 0; b < 3; b++)
                                {
                                    Complex OneOverK = new Complex(1 / (double)K, 0);
                                    Complex t = new Complex();
                                    for (int k = 0; k < K; k++)
                                        t += (chi[k][i, alpha, a] * chi[k][j, beta, b].Conj());
                                    delta[i, j, alpha, beta, a, b] = 1 / (double)(K) * t.x;// OneOverK;
                                    if (i == j && alpha == beta && a == b) res1 += delta[i, j, alpha, beta, a, b]; else res2 += delta[i, j, alpha, beta, a, b];
                                }
            Text = res1.ToString() + "   " + (res2 / n / 12).ToString();
        }