예제 #1
0
void input_coef( )
{	
	int i,value;
	
	if ( get_degree( ) == -1 )
  	return ;
  else  
		printf("Please enter the coefficients: ");
		
	for( i = degree; i >= 0; i-- )
   {
       scanf("%d",&value);
       set_coef(i, value);
   } 
}
예제 #2
0
파일: read_lp.c 프로젝트: hensc/appfs
/* parses a line of the file
 * tries to set the corresponding row in the matrix
 * returns false on error
 */
bool parse_row(char* s, int row, LinearProgram* lp) {
    assert(lp_is_valid(lp));
    assert(row >= 0);
    assert(row < get_rows(lp));

    char* end_ptr;
    int cols = get_cols(lp);

    int i;
    for (i = 0; i < cols; i++) {
        num_t num = parse_num(s, &end_ptr);

        if (!is_num_valid(num, s, end_ptr)) {
            return false;
        }

        set_coef(lp, row, i, num);
        s = end_ptr;
    }


    s = parse_type(s, row, lp);

    if (NULL == s) {
        return false;
    }

    num_t num = parse_num(s, &end_ptr);
    if (!is_num_valid(num, s, end_ptr)) {
        return false;
    }
    s = end_ptr;

    s = skip_spaces(s);

    if ('\0' != *s) {
        return false;
    }

    set_rhs(lp, row, num);

    assert(lp_is_valid(lp));
    return true;
}
예제 #3
0
void efp_st_int_deriv(size_t n_atoms_i, const struct xr_atom *atoms_i,
		      size_t n_atoms_j, const struct xr_atom *atoms_j,
		      const vec_t *com_i, size_t size_i, size_t size_j,
		      six_t *ds, six_t *dt)
{
	static const size_t shift_x[] = { 0, 1, 0, 0, 2, 0, 0, 1, 1, 0,
					  3, 0, 0, 2, 2, 1, 0, 1, 0, 1 };

	static const size_t shift_y[] = { 0, 0, 1, 0, 0, 2, 0, 1, 0, 1,
					  0, 3, 0, 1, 0, 2, 2, 0, 1, 1 };

	static const size_t shift_z[] = { 0, 0, 0, 1, 0, 0, 2, 0, 1, 1,
					  0, 0, 3, 0, 1, 0, 1, 2, 2, 1 };

	double dij[100];
	double xs[5][6], ys[5][6], zs[5][6];
	double xt[5][4], yt[5][4], zt[5][4];
	double dxs[4][4], dys[4][4], dzs[4][4];
	double dxt[4][4], dyt[4][4], dzt[4][4];

	memset(ds, 0, size_i * size_j * sizeof(six_t));
	memset(dt, 0, size_i * size_j * sizeof(six_t));

	for (size_t iii = 0, loc_i = 0; iii < n_atoms_i; iii++) {
		const struct xr_atom *at_i = atoms_i + iii;

	/* shell i */
	for (size_t ii = 0; ii < at_i->n_shells; ii++) {
		const struct shell *sh_i = at_i->shells + ii;

		size_t type_i = get_shell_idx(sh_i->type);
		size_t start_i = get_shell_start(type_i);
		size_t end_i = get_shell_end(type_i);
		size_t sl_i = get_shell_sl(type_i);
		size_t count_i = end_i - start_i;

		for (size_t jjj = 0, loc_j = 0; jjj < n_atoms_j; jjj++) {
			const struct xr_atom *at_j = atoms_j + jjj;

		/* shell j */
		for (size_t jj = 0; jj < at_j->n_shells; jj++) {
			const struct shell *sh_j = at_j->shells + jj;

			size_t type_j = get_shell_idx(sh_j->type);
			size_t start_j = get_shell_start(type_j);
			size_t end_j = get_shell_end(type_j);
			size_t sl_j = get_shell_sl(type_j);
			size_t count_j = end_j - start_j;

			double rr = vec_dist_2(CVEC(at_i->x), CVEC(at_j->x));

			const double *coef_i = sh_i->coef;

			/* primitive i */
			for (size_t ig = 0; ig < sh_i->n_funcs; ig++) {
				double ai = *coef_i++;

				double con_i[20];
				set_coef(con_i, sh_i->type, coef_i);

				coef_i++;
				if (sh_i->type == 'L')
					coef_i++;

				const double *coef_j = sh_j->coef;

				/* primitive j */
				for (size_t jg = 0; jg < sh_j->n_funcs; jg++) {
					double aj = *coef_j++;

					double aa = 1.0 / (ai + aj);
					double tmp = ai * aj * rr * aa;

					if (tmp > int_tol) {
						coef_j++;
						if (sh_j->type == 'L')
							coef_j++;

						continue;
					}

					double con_j[20];
					set_coef(con_j, sh_j->type, coef_j);

					coef_j++;
					if (sh_j->type == 'L')
						coef_j++;

					double fac = exp(-tmp);

					for (size_t i = start_i, idx = 0; i < end_i; i++)
						for (size_t j = start_j; j < end_j; j++, idx++)
							dij[idx] = fac * con_i[i] * int_norm[i] * con_j[j] * int_norm[j];

					double taa = sqrt(aa);

					vec_t a = {
						(ai * at_i->x + aj * at_j->x) * aa,
						(ai * at_i->y + aj * at_j->y) * aa,
						(ai * at_i->z + aj * at_j->z) * aa
					};

					for (size_t i = 0; i < sl_i + 1; i++) {
						for (size_t j = 0; j < sl_j + 2; j++) {
							vec_t iout;
							make_int(i, j, taa, &a, CVEC(at_i->x), CVEC(at_j->x), &iout);
							xs[i][j] = iout.x * taa;
							ys[i][j] = iout.y * taa;
							zs[i][j] = iout.z * taa;
						}
					}

					double ai2 = 2.0 * ai;
					double aj2 = 2.0 * aj;

					for (size_t i = 0; i < sl_i + 1; i++) {
						xt[i][0] = (xs[i][0] - xs[i][2] * aj2) * aj;
						yt[i][0] = (ys[i][0] - ys[i][2] * aj2) * aj;
						zt[i][0] = (zs[i][0] - zs[i][2] * aj2) * aj;
					}

					if (sl_j > 1) {
						for (size_t i = 0; i < sl_i + 1; i++) {
							xt[i][1] = (xs[i][1] * 3.0 - xs[i][3] * aj2) * aj;
							yt[i][1] = (ys[i][1] * 3.0 - ys[i][3] * aj2) * aj;
							zt[i][1] = (zs[i][1] * 3.0 - zs[i][3] * aj2) * aj;
						}

						for (size_t j = 2; j < sl_j; j++) {
							for (size_t i = 0; i < sl_i + 1; i++) {
								size_t n1 = 2 * j + 1;
								size_t n2 = j * (j - 1) / 2;
								xt[i][j] = (xs[i][j] * n1 - xs[i][j + 2] * aj2) * aj - xs[i][j - 2] * n2;
								yt[i][j] = (ys[i][j] * n1 - ys[i][j + 2] * aj2) * aj - ys[i][j - 2] * n2;
								zt[i][j] = (zs[i][j] * n1 - zs[i][j + 2] * aj2) * aj - zs[i][j - 2] * n2;
							}
						}
					}

					for (size_t j = 0; j < sl_j; j++) {
						dxs[0][j] = xs[1][j] * ai2;
						dys[0][j] = ys[1][j] * ai2;
						dzs[0][j] = zs[1][j] * ai2;

						dxt[0][j] = xt[1][j] * ai2;
						dyt[0][j] = yt[1][j] * ai2;
						dzt[0][j] = zt[1][j] * ai2;
					}

					for (size_t i = 1; i < sl_i; i++) {
						for (size_t j = 0; j < sl_j; j++) {
							dxs[i][j] = xs[i + 1][j] * ai2 - xs[i - 1][j] * i;
							dys[i][j] = ys[i + 1][j] * ai2 - ys[i - 1][j] * i;
							dzs[i][j] = zs[i + 1][j] * ai2 - zs[i - 1][j] * i;

							dxt[i][j] = xt[i + 1][j] * ai2 - xt[i - 1][j] * i;
							dyt[i][j] = yt[i + 1][j] * ai2 - yt[i - 1][j] * i;
							dzt[i][j] = zt[i + 1][j] * ai2 - zt[i - 1][j] * i;
						}
					}

					for (size_t i = start_i, idx = 0; i < end_i; i++) {
						size_t ix = shift_x[i];
						size_t iy = shift_y[i];
						size_t iz = shift_z[i];

						for (size_t j = start_j; j < end_j; j++, idx++) {
							size_t jx = shift_x[j];
							size_t jy = shift_y[j];
							size_t jz = shift_z[j];

							double txs = dxs[ix][jx] * ys[iy][jy] * zs[iz][jz];
							double tys = xs[ix][jx] * dys[iy][jy] * zs[iz][jz];
							double tzs = xs[ix][jx] * ys[iy][jy] * dzs[iz][jz];

							double txt = dxt[ix][jx] * ys[iy][jy] * zs[iz][jz] +
								     dxs[ix][jx] * yt[iy][jy] * zs[iz][jz] +
								     dxs[ix][jx] * ys[iy][jy] * zt[iz][jz];
							double tyt = xt[ix][jx] * dys[iy][jy] * zs[iz][jz] +
								     xs[ix][jx] * dyt[iy][jy] * zs[iz][jz] +
								     xs[ix][jx] * dys[iy][jy] * zt[iz][jz];
							double tzt = xt[ix][jx] * ys[iy][jy] * dzs[iz][jz] +
								     xs[ix][jx] * yt[iy][jy] * dzs[iz][jz] +
								     xs[ix][jx] * ys[iy][jy] * dzt[iz][jz];

							size_t idx2 = (loc_i + i - start_i) * size_j + (loc_j + j - start_j);

							ds[idx2].x += txs * dij[idx];
							ds[idx2].y += tys * dij[idx];
							ds[idx2].z += tzs * dij[idx];
							ds[idx2].a += (tys * (at_i->z - com_i->z) - tzs * (at_i->y - com_i->y)) * dij[idx];
							ds[idx2].b += (tzs * (at_i->x - com_i->x) - txs * (at_i->z - com_i->z)) * dij[idx];
							ds[idx2].c += (txs * (at_i->y - com_i->y) - tys * (at_i->x - com_i->x)) * dij[idx];

							dt[idx2].x += txt * dij[idx];
							dt[idx2].y += tyt * dij[idx];
							dt[idx2].z += tzt * dij[idx];
							dt[idx2].a += (tyt * (at_i->z - com_i->z) - tzt * (at_i->y - com_i->y)) * dij[idx];
							dt[idx2].b += (tzt * (at_i->x - com_i->x) - txt * (at_i->z - com_i->z)) * dij[idx];
							dt[idx2].c += (txt * (at_i->y - com_i->y) - tyt * (at_i->x - com_i->x)) * dij[idx];
						}
					}
				}
			}
			loc_j += count_j;
		}}
		loc_i += count_i;
	}}
}
예제 #4
0
void efp_st_int(size_t n_atoms_i, const struct xr_atom *atoms_i,
		size_t n_atoms_j, const struct xr_atom *atoms_j,
		size_t stride, double *s, double *t)
{
	double xin[90];
	double yin[90];
	double zin[90];

	double ft[100], dij[100];
	double sblk[100], tblk[100];

	for (size_t iii = 0, loc_i = 0; iii < n_atoms_i; iii++) {
		const struct xr_atom *at_i = atoms_i + iii;

	/* shell i */
	for (size_t ii = 0; ii < at_i->n_shells; ii++) {
		const struct shell *sh_i = at_i->shells + ii;

		size_t type_i = get_shell_idx(sh_i->type);
		size_t start_i = get_shell_start(type_i);
		size_t end_i = get_shell_end(type_i);
		size_t sl_i = get_shell_sl(type_i);
		size_t count_i = end_i - start_i;

		for (size_t jjj = 0, loc_j = 0; jjj < n_atoms_j; jjj++) {
			const struct xr_atom *at_j = atoms_j + jjj;

		/* shell j */
		for (size_t jj = 0; jj < at_j->n_shells; jj++) {
			const struct shell *sh_j = at_j->shells + jj;

			size_t type_j = get_shell_idx(sh_j->type);
			size_t start_j = get_shell_start(type_j);
			size_t end_j = get_shell_end(type_j);
			size_t sl_j = get_shell_sl(type_j);
			size_t count_j = end_j - start_j;

			size_t count = count_i * count_j;

			memset(sblk, 0, count * sizeof(double));
			memset(tblk, 0, count * sizeof(double));

			init_ft(count_i, sh_j->type, ft);

			double rr = vec_dist_2(CVEC(at_i->x), CVEC(at_j->x));

			const size_t *shift_x = shift_table_x[type_i * 5 + type_j];
			const size_t *shift_y = shift_table_y[type_i * 5 + type_j];
			const size_t *shift_z = shift_table_z[type_i * 5 + type_j];

			const double *coef_i = sh_i->coef;

			/* primitive i */
			for (size_t ig = 0; ig < sh_i->n_funcs; ig++) {
				double ai = *coef_i++;

				double con_i[20];
				set_coef(con_i, sh_i->type, coef_i);

				coef_i++;
				if (sh_i->type == 'L')
					coef_i++;

				const double *coef_j = sh_j->coef;

				/* primitive j */
				for (size_t jg = 0; jg < sh_j->n_funcs; jg++) {
					double aj = *coef_j++;

					double aa = 1.0 / (ai + aj);
					double tmp = aj * ai * rr * aa;

					if (tmp > int_tol) {
						coef_j++;
						if (sh_j->type == 'L')
							coef_j++;

						continue;
					}

					double con_j[20];
					set_coef(con_j, sh_j->type, coef_j);

					coef_j++;
					if (sh_j->type == 'L')
						coef_j++;

					vec_t a = {
						(ai * at_i->x + aj * at_j->x) * aa,
						(ai * at_i->y + aj * at_j->y) * aa,
						(ai * at_i->z + aj * at_j->z) * aa
					};

					double fac = exp(-tmp);

					for (size_t i = start_i, idx = 0; i < end_i; i++)
						for (size_t j = start_j; j < end_j; j++, idx++)
							dij[idx] = fac * con_i[i] * int_norm[i] * con_j[j] * int_norm[j];

					double taa = sqrt(aa);
					double t1 = -2.0 * aj * aj * taa;
					double t2 = -0.5 * taa;

					for (size_t i = 0, idx = 0; i < sl_i; i++, idx += 5) {
						for (size_t j = 0; j < sl_j; j++) {
							vec_t iout;

							make_int(i, j, taa, &a, CVEC(at_i->x), CVEC(at_j->x), &iout);
							xin[idx + j] = iout.x * taa;
							yin[idx + j] = iout.y * taa;
							zin[idx + j] = iout.z * taa;

							make_int(i, j + 2, taa, &a, CVEC(at_i->x), CVEC(at_j->x), &iout);
							xin[idx + j + 30] = iout.x * t1;
							yin[idx + j + 30] = iout.y * t1;
							zin[idx + j + 30] = iout.z * t1;

							if (j >= 2) {
								make_int(i, j - 2, taa, &a, CVEC(at_i->x), CVEC(at_j->x), &iout);
								double t3 = j * (j - 1) * t2;
								xin[idx + j + 60] = iout.x * t3;
								yin[idx + j + 60] = iout.y * t3;
								zin[idx + j + 60] = iout.z * t3;
							}
							else {
								xin[idx + j + 60] = 0.0;
								yin[idx + j + 60] = 0.0;
								zin[idx + j + 60] = 0.0;
							}
						}
					}
					for (size_t i = 0; i < count; i++) {
						size_t nx = shift_x[i];
						size_t ny = shift_y[i];
						size_t nz = shift_z[i];
						double xyz = xin[nx] * yin[ny] * zin[nz];
						double add = (xin[nx + 30] + xin[nx + 60]) * yin[ny] * zin[nz] +
							     (yin[ny + 30] + yin[ny + 60]) * xin[nx] * zin[nz] +
							     (zin[nz + 30] + zin[nz + 60]) * xin[nx] * yin[ny];
						sblk[i] = sblk[i] + dij[i] * xyz;
						tblk[i] = tblk[i] + dij[i] * (xyz * aj * ft[i] + add);
					}
				}
			}

			/* store integrals */
			for (size_t i = 0, idx = 0; i < count_i; i++) {
				size_t idx2 = (loc_i + i) * stride + loc_j;

				for (size_t j = 0; j < count_j; j++, idx++, idx2++) {
					s[idx2] = sblk[idx];
					t[idx2] = tblk[idx];
				}
			}
			loc_j += count_j;
		}}
		loc_i += count_i;
	}}
}