예제 #1
0
    def kernel(self):
        """
        Returns a kernel class for the potential.
        """

        kernel_code = '''

        const double R0 = P.j[0] - P.i[0];
        const double R1 = P.j[1] - P.i[1];
        const double R2 = P.j[2] - P.i[2];

        const double r2 = R0*R0 + R1*R1 + R2*R2;

        const double r_m2 = sigma2/r2;
        const double r_m4 = r_m2*r_m2;

        const double f_tmp = CF*(r_m4*r_m2 - 0.5)*r_m4*r_m4;

        A.i[0]+= (r2 < rc2) ? f_tmp*R0 : 0.0;
        A.i[1]+= (r2 < rc2) ? f_tmp*R1 : 0.0;
        A.i[2]+= (r2 < rc2) ? f_tmp*R2 : 0.0;

        '''
        constants = (kernel.Constant('sigma2', self._sigma**2),
                     kernel.Constant('rc2', self._rc**2),
                     kernel.Constant('internalshift', self._shift_internal),
                     kernel.Constant('CF', self._C_F),
                     kernel.Constant('CV', self._C_V))

        return kernel.Kernel('LJ_accel', kernel_code, constants,
                             [kernel.Header('stdio.h')])
예제 #2
0
    def kernel(self):
        """
        Returns a kernel class for the potential.
        """

        kernel_code = '''

        const double R0 = P(1, 0) - P(0, 0);
        const double R1 = P(1, 1) - P(0, 1);
        const double R2 = P(1, 2) - P(0, 2);

        const double r2 = R0*R0 + R1*R1 + R2*R2;

        const double r_m2 = sigma2/r2;
        const double r_m4 = r_m2*r_m2;
        const double r_m6 = r_m4*r_m2;

        u(0)+= (r2 < rc2) ? 0.5*CV*((r_m6-1.0)*r_m6 + internalshift) : 0.0;

        const double r_m8 = r_m4*r_m4;
        const double f_tmp = CF*(r_m6 - 0.5)*r_m8;

        A(0, 0)+= (r2 < rc2) ? f_tmp*R0 : 0.0;
        A(0, 1)+= (r2 < rc2) ? f_tmp*R1 : 0.0;
        A(0, 2)+= (r2 < rc2) ? f_tmp*R2 : 0.0;

        '''
        constants = (kernel.Constant('sigma2', self._sigma**2),
                     kernel.Constant('rc2', self._rc**2),
                     kernel.Constant('internalshift', self._shift_internal),
                     kernel.Constant('CF', self._C_F),
                     kernel.Constant('CV', self._C_V))

        return kernel.Kernel('LJ_accel_U', kernel_code, constants,
                             [kernel.Header('stdio.h')])
예제 #3
0
    def kernel(self):
        """
        Returns a kernel class for the potential.
        """

        kernel_code = '''

        OUTCOUNT(0)++;

        const double R0 = P(1, 0) - P(0, 0);
        const double R1 = P(1, 1) - P(0, 1);
        const double R2 = P(1, 2) - P(0, 2);


        //printf("Positions P(0) = %f, P(1) = %f |", P(0, 1), P(1, 1));


        const double r2 = R0*R0 + R1*R1 + R2*R2;

        if (r2 < rc2){

            COUNT(0)++;

            const double r_m2 = sigma2/r2;
            const double r_m4 = r_m2*r_m2;
            const double r_m6 = r_m4*r_m2;

            u(0)+= CV*((r_m6-1.0)*r_m6 + internalshift);

            const double r_m8 = r_m4*r_m4;
            const double f_tmp = CF*(r_m6 - 0.5)*r_m8;


            A(0, 0)+=f_tmp*R0;
            A(0, 1)+=f_tmp*R1;
            A(0, 2)+=f_tmp*R2;

            A(1, 0)-=f_tmp*R0;
            A(1, 1)-=f_tmp*R1;
            A(1, 2)-=f_tmp*R2;

        }

        '''
        constants = (kernel.Constant('sigma2', self._sigma**2),
                     kernel.Constant('rc2', self._rc**2),
                     kernel.Constant('internalshift', self._shift_internal),
                     kernel.Constant('CF', self._C_F),
                     kernel.Constant('CV', self._C_V))

        reductions = (kernel.Reduction('u', 'u[0]', '+'), )

        return kernel.Kernel('LJ_accel_U', kernel_code, constants,
                             [kernel.Header('stdio.h')], reductions)
예제 #4
0
    def kernel(self):
        """
        Returns a kernel class for the potential.
        """

        kernel_code = '''

        const double R[3] = {P[1][0] - P[0][0], P[1][1] - P[0][1], P[1][2] - P[0][2]};

        double r2 = R[0]*R[0] + R[1]*R[1] + R[2]*R[2];

        if (r2 < rc2){

            r2=1./r2;

            A[0][0]+=r2;
            A[0][1]+=r2;
            A[0][2]+=r2;

            A[1][0]+=r2;
            A[1][1]+=r2;
            A[1][2]+=r2;

        }
        '''
        constants = (kernel.Constant('rc2', self._rc**2), )

        return kernel.Kernel('TestPotential1', kernel_code, constants,
                             ['stdio.h'], None)
예제 #5
0
    def integrate(self, dt=None, t=None):
        """
        Integrate state forward in time.
        
        :arg double dt: Time step size.
        :arg double t: End time.
        """
        print("starting integration")
        if dt is not None:
            self._dt = dt
        if t is not None:
            self._T = t

        self._max_it = int(math.ceil(self._T / self._dt))

        self._constants = [
            kernel.Constant('dt', self._dt),
            kernel.Constant('dht', 0.5 * self._dt),
        ]

        self._kernel1 = kernel.Kernel('vv1', self._kernel1_code,
                                      self._constants)
        self._p1 = loop.ParticleLoop(
            self._kernel1, {
                'P': self._P(access.W),
                'V': self._V(access.W),
                'A': self._A(access.R),
                'M': self._M(access.R)
            })

        self._kernel2 = kernel.Kernel('vv2', self._kernel2_code,
                                      self._constants)
        self._p2 = loop.ParticleLoop(self._kernel2, {
            'V': self._V(access.W),
            'A': self._A(access.R),
            'M': self._M(access.R)
        })

        self._update_controller.execute_boundary_conditions()

        self._sim.forces_update()

        self.timer.start()
        self._velocity_verlet_integration()
        self.timer.pause()
예제 #6
0
    def kernel(self):
        """
        Returns a kernel class for the potential.
        """

        kernel_code = '''

        const double R0 = P(1,0) - P(0,0);
        const double R1 = P(1,1) - P(0,1);
        const double R2 = P(1,2) - P(0,2);

        const double r2 = R0*R0 + R1*R1 + R2*R2;

        if (r2 < rc2) {
            const double r = sqrt(r2);
            // \\exp{-B*r}
            const double exp_mbr = exp(_MB*r);

            // r^{-2, -4, -6}
            const double r_m1 = 1.0/r;
            const double r_m2 = r_m1*r_m1;
            const double r_m4 = r_m2*r_m2;
            const double r_m6 = r_m4*r_m2;

            // \\frac{C}{r^6}
            const double crm6 = _C*r_m6;

            // A \\exp{-Br} - \\frac{C}{r^6}
            u(0)+= _A*exp_mbr - crm6 + internalshift;

            // AB \\exp{-Br} - \\frac{C}{r^6}*\\frac{6}{r}
            const double term2 = crm6*(-6.0)*r_m1;
            const double f_tmp = _AB * exp_mbr + term2;

            A(0,0)+=f_tmp*R0;
            A(0,1)+=f_tmp*R1;
            A(0,2)+=f_tmp*R2;

            A(1,0)-=f_tmp*R0;
            A(1,1)-=f_tmp*R1;
            A(1,2)-=f_tmp*R2;
        }
        '''
        constants = (kernel.Constant('_A',
                                     self.a), kernel.Constant('_AB', self.ab),
                     kernel.Constant('_B',
                                     self.b), kernel.Constant('_MB', self.mb),
                     kernel.Constant('_C', self.c),
                     kernel.Constant('rc2', self.rc**2),
                     kernel.Constant('internalshift', self._shift_internal))

        return kernel.Kernel(
            'BuckinghamV', kernel_code, constants,
            [kernel.Header('stdio.h'),
             kernel.Header('math.h')])
예제 #7
0
    def kernel(self):
        """
        Returns a kernel class for the potential.
        """

        kernel_code = '''
        //N_f = 27
        const double R0 = P.j[0] - P.i[0];
        const double R1 = P.j[1] - P.i[1];
        const double R2 = P.j[2] - P.i[2];

        const double r2 = R0*R0 + R1*R1 + R2*R2;

        if (r2 < rc2){

            const double r_m2 = sigma2/r2;
            const double r_m4 = r_m2*r_m2;
            const double r_m6 = r_m4*r_m2;

            u[0] += 0.5*CV*((r_m6-1.0)*r_m6 + internalshift);

            const double r_m8 = r_m4*r_m4;
            const double f_tmp = CF*(r_m6 - 0.5)*r_m8;

            A.i[0] +=  f_tmp*R0;
            A.i[1] +=  f_tmp*R1;
            A.i[2] +=  f_tmp*R2;

        }
        '''
        constants = (kernel.Constant('sigma2', self._sigma**2),
                     kernel.Constant('rc2', self._rc**2),
                     kernel.Constant('internalshift', self._shift_internal),
                     kernel.Constant('CF', self._C_F),
                     kernel.Constant('CV', self._C_V))

        return kernel.Kernel('LJ_accel_U', kernel_code, constants,
                             [kernel.Header('stdio.h')])
예제 #8
0
    def _build_libs(self, dt):
        kernel1_code = '''
        const double M_tmp = 1.0/M(0);
        V(0) += dht*F(0)*M_tmp;
        V(1) += dht*F(1)*M_tmp;
        V(2) += dht*F(2)*M_tmp;
        P(0) += dt*V(0);
        P(1) += dt*V(1);
        P(2) += dt*V(2);
        '''

        kernel2_code = '''
        const double M_tmp = 1.0/M(0);
        V(0) += dht*F(0)*M_tmp;
        V(1) += dht*F(1)*M_tmp;
        V(2) += dht*F(2)*M_tmp;
        '''
        constants = [
            kernel.Constant('dt', dt),
            kernel.Constant('dht', 0.5 * dt),
        ]

        kernel1 = kernel.Kernel('vv1', kernel1_code, constants)
        self._p1 = self._looping_method(kernel=kernel1,
                                        dat_dict={
                                            'P': self._p(access.W),
                                            'V': self._v(access.W),
                                            'F': self._f(access.R),
                                            'M': self._m(access.R)
                                        })

        kernel2 = kernel.Kernel('vv2', kernel2_code, constants)
        self._p2 = self._looping_method(kernel=kernel2,
                                        dat_dict={
                                            'V': self._v(access.W),
                                            'F': self._f(access.R),
                                            'M': self._m(access.R)
                                        })
예제 #9
0
    def kernel(self):
        """
        Returns a kernel class for the potential.
        """

        kernel_code = '''

        const double R0 = P.j[0] - P.i[0];
        const double R1 = P.j[1] - P.i[1];
        const double R2 = P.j[2] - P.i[2];

        const double r2 = R0*R0 + R1*R1 + R2*R2;

        const double r = sqrt(r2);
        // \\exp{-B*r}
        const double exp_mbr = exp(_MB*r);

        // r^{-2, -4, -6}
        const double r_m1 = 1.0/r;
        const double r_m2 = r_m1*r_m1;
        const double r_m4 = r_m2*r_m2;
        const double r_m6 = r_m4*r_m2;

        // \\frac{C}{r^6}
        const double crm6 = _C*r_m6;

        // A \\exp{-Br} - \\frac{C}{r^6}
        u[0]+= (r2 < rc2) ? 0.5*(_A*exp_mbr - crm6 + internalshift) : 0.0;

        // = AB \\exp{-Br} - \\frac{C}{r^6}*\\frac{6}{r}
        const double term2 = crm6*(-6.0)*r_m1;
        const double f_tmp = _AB * exp_mbr + term2;

        A.i[0]+= (r2 < rc2) ? f_tmp*R0 : 0.0;
        A.i[1]+= (r2 < rc2) ? f_tmp*R1 : 0.0;
        A.i[2]+= (r2 < rc2) ? f_tmp*R2 : 0.0;

        '''
        constants = (kernel.Constant('_A',
                                     self.a), kernel.Constant('_AB', self.ab),
                     kernel.Constant('_B',
                                     self.b), kernel.Constant('_MB', self.mb),
                     kernel.Constant('_C', self.c),
                     kernel.Constant('rc2', self.rc**2),
                     kernel.Constant('internalshift', self._shift_internal))

        return kernel.Kernel(
            'BuckinghamV', kernel_code, constants,
            [kernel.Header('stdio.h'),
             kernel.Header('math.h')])
예제 #10
0
    def kernel(self):
        """
        Returns a kernel class for the potential.
        """

        kernel_code = '''

        const double R0 = P[1][0] - P[0][0];
        const double R1 = P[1][1] - P[0][1];
        const double R2 = P[1][2] - P[0][2];

        const double r2 = R0*R0 + R1*R1 + R2*R2;


            double xn = 0.01;
            for(int ix = 0; ix < 2; ix++){
                xn = xn*(2.0 - r2*xn);
            }


            const double r_m2 = sigma2*xn;
            const double r_m4 = r_m2*r_m2;
            const double r_m6 = r_m4*r_m2;

            const double _ex = r_m6;
            double _et = 1.0, _ep = 1.0, _ef = 1.0, _epx = 1.0;

            /*
            #pragma novector
            for(int _etx = 1; _etx < 21; _etx++){
                _epx *= _ex;
                _ef *= _ep;
                _ep++;

                xn = 0.01;

            #pragma novector
                for(int ix = 0; ix < 10; ix++){
                    xn = xn*(2.0 - _ef*xn);
                }


                _et += _epx*xn;
            }
            */

            u[0]+=CV*((r_m6-1.0)*r_m6 + internalshift);

            const double r_m8 = r_m4*r_m4;
            const double f_tmp = CF*(r_m6 - 0.5)*r_m8;

            A[0][0]+=f_tmp*R0;
            A[0][1]+=f_tmp*R1;
            A[0][2]+=f_tmp*R2;

            A[1][0]-=f_tmp*R0;
            A[1][1]-=f_tmp*R1;
            A[1][2]-=f_tmp*R2;


        '''
        constants = (kernel.Constant('sigma2', self._sigma**2),
                     kernel.Constant('rc2', self._rc**2),
                     kernel.Constant('internalshift', self._shift_internal),
                     kernel.Constant('CF', self._C_F),
                     kernel.Constant('CV', self._C_V))

        reductions = (kernel.Reduction('u', 'u[0]', '+'), )

        return kernel.Kernel('LJ_accel_U', kernel_code, constants,
                             [kernel.Header('stdio.h')], reductions)
예제 #11
0
    def kernel(self):
        """
        Returns a kernel class for the potential.
        """

        kernel_code = '''

        const double R0 = P(1, 0) - P(0, 0);
        const double R1 = P(1, 1) - P(0, 1);
        const double R2 = P(1, 2) - P(0, 2);

        const double r2 = R0*R0 + R1*R1 + R2*R2;

            double xn = 0.01;
            for(int ix = 0; ix < 10; ix++){
                xn = xn*(2.0 - r2*xn);
            }



            const double r_m2 = sigma2*xn;
            const double r_m4 = r_m2*r_m2;
            const double r_m6 = r_m4*r_m2;

            const double _ex = r_m6;
            double _et = 1.0, _ep = 1.0, _ef = 1.0, _epx = 1.0;
            for(int _etx = 1; _etx < 21; _etx++){
                _epx *= _ex;
                _ef *= _ep;
                _ep++;

                xn = 0.01;
                for(int ix = 0; ix < 10; ix++){
                    xn = xn*(2.0 - _ef*xn);
                }


                _et += _epx*xn;
            }

            u(0)+=CV*((r_m6-1.0)*r_m6 + internalshift) + _et;

            const double r_m8 = r_m4*r_m4;
            const double f_tmp = CF*(r_m6 - 0.5)*r_m8;

            A(0, 0)+=f_tmp*R0;
            A(0, 1)+=f_tmp*R1;
            A(0, 2)+=f_tmp*R2;

            A(1, 0)-=f_tmp*R0;
            A(1, 1)-=f_tmp*R1;
            A(1, 2)-=f_tmp*R2;


        '''
        constants = (kernel.Constant('sigma2', self._sigma**2),
                     kernel.Constant('rc2', self._rc**2),
                     kernel.Constant('internalshift', self._shift_internal),
                     kernel.Constant('CF', self._C_F),
                     kernel.Constant('CV', self._C_V))

        reductions = (kernel.Reduction('u', 'u[0]', '+'), )

        return kernel.Kernel('LJ_accel_U', kernel_code, constants, ['stdio.h'],
                             reductions)
예제 #12
0
    def __init__(self, state, rmax=None, rsteps=100):

        self._count = 0
        self._state = state
        self._extent = self._state.domain.extent
        self._P = self._state.positions
        self._N = self._state.npart_local
        self._rmax = rmax

        if self._rmax is None:
            self._rmax = 0.5 * np.min(self._extent.data)

        self._rsteps = rsteps

        self._gr = data.ScalarArray(ncomp=self._rsteps, dtype=ctypes.c_int)
        self._gr.scale(0.0)

        _headers = ['math.h', 'stdio.h']
        _kernel = '''
        
        
        double R0 = P(1, 0) - P(0, 0);
        double R1 = P(1, 1) - P(0, 1);
        double R2 = P(1, 2) - P(0, 2);
        
        if (abs_md(R0) > exto20 ) { R0 += isign(R0) * extent0 ; }
        if (abs_md(R1) > exto21 ) { R1 += isign(R1) * extent1 ; }
        if (abs_md(R2) > exto22 ) { R2 += isign(R2) * extent2 ; }
        
        const double r2 = R0*R0 + R1*R1 + R2*R2;
        
        if (r2 < rmax2){
            
            double r20=0.0, r21 = r2;
            
            r21 = sqrt(r2);
            #pragma omp atomic
            GR[(int) (abs_md(r21* rstepsoverrmax))]++;
            
        }
        '''

        _constants = (kernel.Constant('rmaxoverrsteps',
                                      0.2 * self._rmax / self._rsteps),
                      kernel.Constant('rstepsoverrmax',
                                      self._rsteps / self._rmax),
                      kernel.Constant('rmax2', self._rmax**2),
                      kernel.Constant('extent0', self._extent[0]),
                      kernel.Constant('extent1', self._extent[1]),
                      kernel.Constant('extent2', self._extent[2]),
                      kernel.Constant('exto20', 0.5 * self._extent[0]),
                      kernel.Constant('exto21', 0.5 * self._extent[1]),
                      kernel.Constant('exto22', 0.5 * self._extent[2]))

        _grkernel = kernel.Kernel('radial_distro_periodic_static',
                                  _kernel,
                                  _constants,
                                  headers=_headers)
        _datdict = {'P': self._P, 'GR': self._gr}

        self._p = pairloop.DoubleAllParticleLoop(self._N,
                                                 kernel=_grkernel,
                                                 dat_dict=_datdict)

        self.timer = ppmd.opt.Timer(runtime.TIMER, 0)
예제 #13
0
    def integrate_thermostat(self, dt=None, t=None, temp=273.15, nu=1.0):
        """
        Integrate state forward in time.
        
        :arg double dt: Time step size.
        :arg double t: End time.
        :arg double temp: Temperature of heat bath.
        """

        self._Temp = temp
        self._nu = nu

        if dt is not None:
            self._dt = dt
        if t is not None:
            self._T = t

        self._max_it = int(math.ceil(self._T / self._dt))

        self._constants1 = [
            kernel.Constant('dt', self._dt),
            kernel.Constant('dht', 0.5 * self._dt),
        ]
        self._kernel1 = kernel.Kernel('vv1', self._kernel1_code,
                                      self._constants1)
        self._p1 = loop.ParticleLoop(self._kernel1, {
            'P': self._P,
            'V': self._V,
            'A': self._A,
            'M': self._M
        })

        self._kernel2_thermostat_code = '''

        //Anderson thermostat here.
        //probably horrific random code.

        const double tmp_rand_max = 1.0/RAND_MAX;

        if (rand()*tmp_rand_max < rate) {

            //Box-Muller method.


            const double scale = sqrt(temperature/M(0));
            const double stmp = scale*sqrt(-2.0*log(rand()*tmp_rand_max));

            const double V0 = 2.0*M_PI*rand()*tmp_rand_max;
            V(0) = stmp*cos(V0);
            V(1) = stmp*sin(V0);
            V(2) = scale*sqrt(-2.0*log(rand()*tmp_rand_max))*cos(2.0*M_PI*rand()*tmp_rand_max);

        }
        else {
            const double M_tmp = 1./M(0);
            V(0) += dht*A(0)*M_tmp;
            V(1) += dht*A(1)*M_tmp;
            V(2) += dht*A(2)*M_tmp;
        }

        '''

        self._constants2_thermostat = [
            kernel.Constant('rate', self._dt * self._nu),
            kernel.Constant('dt', self._dt),
            kernel.Constant('dht', 0.5 * self._dt),
            kernel.Constant('temperature', self._Temp),
        ]

        self._kernel2_thermostat = kernel.Kernel(
            'vv2_thermostat',
            self._kernel2_thermostat_code,
            self._constants2_thermostat,
            headers=['math.h', 'stdlib.h', 'time.h', 'stdio.h'])
        self._p2_thermostat = loop.ParticleLoop(self._kernel2_thermostat, {
            'V': self._V,
            'A': self._A,
            'M': self._M
        })

        _t = ppmd.opt.Timer(runtime.TIMER, 0, start=True)
        self._velocity_verlet_integration_thermostat()
        _t.stop("VelocityVerletAnderson")