示例#1
0
文件: metric.c 项目: atchekho/harmpi
/* NOTE: parameter hides global variable */
void conn_func(double *X, struct of_geom *geom, double conn[][NDIM][NDIM])
{
	int i,j,k,l ;
	double tmp[NDIM][NDIM][NDIM] ;
	double Xh[NDIM],Xl[NDIM] ;
	double gh[NDIM][NDIM] ;
	double gl[NDIM][NDIM] ;

	for(k=0;k<NDIM;k++) {
		for(l=0;l<NDIM;l++) Xh[l] = X[l] ;
		for(l=0;l<NDIM;l++) Xl[l] = X[l] ;
		Xh[k] += DELTA ;
		Xl[k] -= DELTA ;
		gcov_func(Xh,gh) ;
		gcov_func(Xl,gl) ;

		for(i=0;i<NDIM;i++)
		for(j=0;j<NDIM;j++) 
			conn[i][j][k] = (gh[i][j] - gl[i][j])/(Xh[k] - Xl[k]) ;
	}

	/* now rearrange to find \Gamma_{ijk} */
	for(i=0;i<NDIM;i++)
	for(j=0;j<NDIM;j++)
	for(k=0;k<NDIM;k++) 
		tmp[i][j][k] = 0.5*(conn[j][i][k] + conn[k][i][j] - conn[k][j][i]) ;

	/* finally, raise index */
	for(i=0;i<NDIM;i++)
	for(j=0;j<NDIM;j++)
	for(k=0;k<NDIM;k++)  {
		conn[i][j][k] = 0. ;
		for(l=0;l<NDIM;l++) conn[i][j][k] += geom->gcon[i][l]*tmp[l][j][k] ;
	}

	/* done! */
}
示例#2
0
/* set up all grid functions */
void init_geometry()
{
	int i, j;
	double X[NDIM];

	for (i = 0; i < N1; i++) {
		for (j = 0; j < N2; j++) {

			/* zone-centered */
			coord(i, j, X);

			gcov_func(X, geom[i][j].gcov);

			geom[i][j].g = gdet_func(geom[i][j].gcov);

			gcon_func(X, geom[i][j].gcon);

		}
	}

	/* done! */
}
示例#3
0
void push_photon_ham(double X[NDIM], double Kcon[][NDIM], double dl[])
{
	double dgcon[NDIM][NDIM][NDIM];
	double dKcov[NDIM], Kcov[NDIM];
	double Xh[NDIM], Kconh[NDIM], Kcovh[NDIM];
	double gcon[NDIM][NDIM], gcov[NDIM][NDIM] ;
	int i, j, k;

	/* advance X */

	/* 2nd order: scheme
	   take half-step and then evaluate derivatives 
	   at half-step. */

	//fprintf(stderr,"---> %g %g %g %g %g %g %g %g\n", X[0], X[1], X[2], X[3], Kcon[0], Kcon[1], Kcon[2], Kcon[3]) ;
	/** half-step **/
	dgcon_calc(X, dgcon) ;

	/* advance K */
	gcov_func(X, gcov) ;
	lower(Kcon[0], gcov, Kcov) ;

	for (k = 0; k < 4; k++)
		dKcov[k] = 0.;

	for (i = 1; i < 3; i++)
		for (j = 0; j < 4; j++)
			for (k = 0; k < 4; k++)
				dKcov[i] -= 0.5 * dl[0] * 0.5 * dgcon[i][j][k] * Kcov[j] * Kcov[k];

	for (k = 0; k < 4; k++)
		Kcovh[k] = Kcov[k] + dKcov[k];

	/* advance X */
	for (i = 0; i < 4; i++)
		Xh[i] = X[i] + 0.5 * dl[0] * Kcon[0][i] ;

	/** full step **/
	dgcon_calc(Xh, dgcon) ;

	/* advance K */
	for (k = 0; k < 4; k++)
		dKcov[k] = 0.;
	for (i = 1; i < 3; i++)
		for (j = 0; j < 4; j++)
			for (k = 0; k < 4; k++)
				dKcov[i] -= dl[0] * 0.5 * dgcon[i][j][k] * Kcovh[j] * Kcovh[k];

	for (k = 0; k < 4; k++)
		Kcov[k] += dKcov[k];

	gcon_func(Xh, gcon) ;

	/* lower does the same thing as raise... */
	lower(Kcovh, gcon, Kconh) ;

	/* advance X */
	for (k = 0; k < 4; k++)
		X[k] += dl[0] * Kconh[k];

	gcon_func(X, gcon) ;
	lower(Kcov, gcon, Kcon[0]) ;

	//fprintf(stderr,"---> %g %g %g %g %g %g %g %g\n", X[0], X[1], X[2], X[3], Kcon[0], Kcon[1], Kcon[2], Kcon[3]) ;

	/* done! */
}