Esempio n. 1
0
void build_graph(double *x,VTYPE &y,double (*fun)(double,double*),double x0,double x1,int nx,VTYPE &par)
{
  double dx=(x1-x0)/nx;
#ifdef JACK
  VTYPE xj(nx+1,par.njack);
  y=VTYPE(nx+1,par.njack);
#else
  VTYPE xj(nx+1,par.nboot,par.njack);
  y=VTYPE(nx+1,par.nboot,par.njack);
#endif
  
  for(int i=0;i<=nx;i++) xj.data[i]=x[i]=x0+dx*i;
  
  y=par_single_fun(fun,xj,par);
} 
Esempio n. 2
0
void cnbint(
		int i,
		const double pos[][3],
		const double vel[][3],
		const double mass[],
		int nnb,
		int list[],
		double f[3],
		double fdot[3]){
	const int NBMAX = 512;
	assert(nnb <= NBMAX);

	double xbuf[NBMAX] __attribute__ ((aligned(16)));
	double ybuf[NBMAX] __attribute__ ((aligned(16)));
	double zbuf[NBMAX] __attribute__ ((aligned(16)));
	float vxbuf[NBMAX] __attribute__ ((aligned(16)));
	float vybuf[NBMAX] __attribute__ ((aligned(16)));
	float vzbuf[NBMAX] __attribute__ ((aligned(16)));
	float mbuf[NBMAX] __attribute__ ((aligned(16)));
	for(int k=0; k<nnb; k++){
		int j = list[k];
		xbuf[k] = pos[j][0];
		ybuf[k] = pos[j][1];
		zbuf[k] = pos[j][2];
		vxbuf[k] = vel[j][0];
		vybuf[k] = vel[j][1];
		vzbuf[k] = vel[j][2];
		mbuf[k] = mass[j];
	}
	for(int k=nnb; k%4; k++){
		xbuf[k] = 16.0;
		ybuf[k] = 16.0;
		zbuf[k] = 16.0;
		vxbuf[k] = 0.0f;
		vybuf[k] = 0.0f;
		vzbuf[k] = 0.0f;
		mbuf[k] = 0.0f;
	}

	v4df xi(pos[i][0]);
	v4df yi(pos[i][1]);
	v4df zi(pos[i][2]);
	v4sf vxi(vel[i][0]);
	v4sf vyi(vel[i][1]);
	v4sf vzi(vel[i][2]);
	v4df ax(0.0), ay(0.0), az(0.0);
	v4sf jx(0.0), jy(0.0), jz(0.0);

	for(int k=0; k<nnb; k+=4){
		v4df xj(xbuf + k);
		v4df yj(ybuf + k);
		v4df zj(zbuf + k);
		v4sf vxj(vxbuf + k);
		v4sf vyj(vybuf + k);
		v4sf vzj(vzbuf + k);
		v4sf mj(mbuf + k);

		v4sf dx = v4sf::_v4sf(xj - xi);
		v4sf dy = v4sf::_v4sf(yj - yi);
		v4sf dz = v4sf::_v4sf(zj - zi);
		v4sf dvx = vxj - vxi;
		v4sf dvy = vyj - vyi;
		v4sf dvz = vzj - vzi;

		v4sf r2 = dx*dx + dy*dy + dz*dz;
		v4sf rv = dx*dvx + dy*dvy + dz*dvz;
		rv *= v4sf(-3.0f);
		// v4sf rinv1 = r2.rsqrt() & v4sf(mask);
		v4sf rinv1 = r2.rsqrt();
		v4sf rinv2 = rinv1 * rinv1;
		rv *= rinv2;
		v4sf rinv3 = mj * rinv1 * rinv2;
		 
		dx *= rinv3; ax += v4df(dx);
		dy *= rinv3; ay += v4df(dy);
		dz *= rinv3; az += v4df(dz);
		dvx *= rinv3; jx += dvx;
		dvy *= rinv3; jy += dvy;
		dvz *= rinv3; jz += dvz;
		dx *= rv; jx += dx;
		dy *= rv; jy += dy;
		dz *= rv; jz += dz;
	}
	f[0] = ax.sum();
	f[1] = ay.sum();
	f[2] = az.sum();
	fdot[0] = (v4df(jx)).sum();
	fdot[1] = (v4df(jy)).sum();
	fdot[2] = (v4df(jz)).sum();
	assert(f[0] == f[0]);
	assert(f[1] == f[1]);
	assert(f[2] == f[2]);
	assert(fdot[0] == fdot[0]);
	assert(fdot[1] == fdot[1]);
	assert(fdot[2] == fdot[2]);
}
Esempio n. 3
0
  //--------------------------------------------------------
  //  apply local coulomb forces 
  //  -- due to image charges
  //--------------------------------------------------------
  void ChargeRegulatorMethodImageCharge::apply_local_forces()
  {

    int inum = lammpsInterface_->neighbor_list_inum();
    int * ilist = lammpsInterface_->neighbor_list_ilist();
    int * numneigh = lammpsInterface_->neighbor_list_numneigh();
    int ** firstneigh = lammpsInterface_->neighbor_list_firstneigh();

    const int *mask = lammpsInterface_->atom_mask();
///..............................................
    double ** x = lammpsInterface_->xatom(); 
    double ** f = lammpsInterface_->fatom(); 
    double *  q = lammpsInterface_->atom_charge();

    // loop over neighbor list
    for (int ii = 0; ii < inum; ii++) {
      int i = ilist[ii];
      double qi = q[i];
      if ((mask[i] & atomGroupBit_) && qi != 0.) {
        double* fi = f[i];
        DENS_VEC xi(x[i],nsd_); 
        // distance to surface
        double dn = reflect(xi);
        // all ions near the interface/wall
        // (a) self image
        if (dn < rC_) { // close enough to wall to have explicit image charges
          double factor_coul = 1; 
          double dx = 2.*dn; // distance to image charge
          double fn = factor_coul*qi*qi*permittivityRatio_/dx;
          fi[0] += fn*normal_[0];
          fi[1] += fn*normal_[1];
          fi[2] += fn*normal_[2];
          sum_ += fn*normal_;
        // (b) neighbor images
        int * jlist = firstneigh[i];
        int jnum = numneigh[i];
        for (int jj = 0; jj < jnum; jj++) {
          int j = jlist[jj];
          // this changes j
          double factor_coul = lammpsInterface_->coulomb_factor(j);
          double qj = q[j];
          if (qj != 0.) { // all charged neighbors
            DENS_VEC xj(x[j],nsd_);
            dn = reflect(xj);
            DENS_VEC dx = xi-xj;
            double r2 = dx.norm_sq();
            // neighbor image j' inside cutoff from i 
            if (r2 < rCsq_) { 
              double fm = factor_coul*qi*qj*permittivityRatio_/r2;
              fi[0] += fm*dx(0);
              fi[1] += fm*dx(1);
              fi[2] += fm*dx(2);
              sum_ += fm*dx;
              }
            }
          }
        } // end i < rC if
      }
    }
    // update managed data
    (interscaleManager_->fundamental_atom_quantity(LammpsInterface::ATOM_FORCE))->force_reset();
  }
Esempio n. 4
0
void Matrix::test(void)
{
        int i,j;
        //Matrix *A,*B,*C,*AT,*K;
        /*test matrix mult*/
//        A = new Matrix(3,2);
//        B = new Matrix(2,3);
//        C = new Matrix(3,3);
//        AT = new Matrix(2,3);
//        K = new Matrix(2*3,3*2);
        Matrix A(3,2),B(2,3),C(3,3),AT(2,3),K(2*3,3*2);
        Matrix M(3,3),x(3,1),b(3,1);

        A[0][0] = 0;
        A[0][1] = 1;
        A[1][0] = 3;
        A[1][1] = 1;
        A[2][0] = 2;
        A[2][1] = 0;

        B[0][0] = 4;
        B[0][1] = 1;
        B[0][2] = 0;
        B[1][0] = 2;
        B[1][1] = 1;
        B[1][2] = 2;

        std::cout << A.mat[1][0] << std::endl;

        C = Matrix::matrix_mult(A,B);

        for(i=0;i<3;i++)
                {
                        for(j=0;j<3;j++)
                                std::cout << C[i][j] << " ";
                        std::cout << std::endl;
                }

        std::cout << "now A transposed" << std::endl;

        A.transpose(AT);

        for(i=0;i<2;i++)
                {
                        for(j=0;j<3;j++)
                                std::cout << AT[i][j] << " ";
                        std::cout << std::endl;
                }

        std::cout << "now Kronecker product" << std::endl;

        K = Matrix::kron_(A,B);

        std::cout << "product calced " << K.getM() << " " << K.getN()  << std::endl;

        for(i=0;i<2*3;i++)
                {
                        for(j=0;j<3*2;j++)
                                std::cout << K.mat[i][j] << " ";
                        std::cout << std::endl;
                }

        cv::Mat_<double> a(3,2), l(2,3);
        a(0,0) = 0;
        a(0,1) = 1;
        a(1,0) = 3;
        a(1,1) = 1;
        a(2,0) = 2;
        a(2,1) = 0;

        l(0,0) = 4;
        l(0,1) = 1;
        l(0,2) = 0;
        l(1,0) = 2;
        l(1,1) = 1;
        l(1,2) = 2;

        cv::Mat_<double> k = Matrix::kronecker(a,l);

        std::cout << "mat cv Kronecker" << std::endl << Matrix(k);


        Matrix sub(3,6);
        sub = submatrix_(K,2,4);
        std::cout << "Submatix of K rows 2 to 4 is : \n" << sub;

        std::cout << "now test solving a linear system using SVD: " << std::endl;
        std::cout << "A*x = b; A = U*D*V', inv(A) = V*inv(D)*U', x = V*inv(D)*U'*b" << std::endl;
        //if element in diagonal of D is 0 set element in inv(D) to 0 proof in numerical recipies
        M[0][0] = 4;
        M[0][1] = 1.5;
        M[0][2] = 2;
        M[1][0] = 3;
        M[1][1] = 3;
        M[1][2] = 1;
        M[2][0] = 2;
        M[2][1] = 1;
        M[2][2] = 5;

        b[0][0] = 10.6;
        b[1][0] = 11.3;
        b[2][0] = 9;
        //x should be 1.5, 2, 0.8
        Matrix result = solveLinSysSvd(M,b);
        std::cout << " The result of the linear system is : " << std::endl;
        std::cout << result;

        A = Matrix::matrix_mult(Matrix::eye(2),Matrix::matrix_mult(Matrix::eye(2),Matrix::eye(2)));

        cv::Mat_<double> aj(2,2);
        cv::Mat_<double> bj(2,1);
        aj(0,0) = 2;
        aj(0,1) = 1;
        aj(1,0) = 5;
        aj(1,1) = 7;
        bj(0,0) = 11;
        bj(1,0) = 13;
        cv::Mat_<double> xj(2,1);
        Matrix::jacobi(aj,bj,xj);
        std::cout << "jacobi " << Matrix(xj);
    }