src/vpic/diagnostics.cc
double vpic_simulation::poynting_flux(double e0) {
	double  psum = 0.0;
        double gpsum = 0.0;
	int stride = (grid->ny-1)*(grid->nz-1);

	float * pvec = new float[stride];

	if(!pvec) {
		ERROR(("Failed pvec allocation in poynting flux diagnostic"));
	} // if

	memset(pvec, 0, stride);

	int ix, k1, k2;
	RANK_TO_INDEX( int(rank()), ix);

	// Compute Poynting for domains on left of box
	if(ix==0) {
		for(int j(1); j<grid->ny; j++) {
			for(int k(1); k<grid->nz; k++) {
				k1 = INDEX_FORTRAN_3(1, j+1, k+1, 0, grid->nx+1,
					0, grid->ny+1, 0, grid->nz+1);
				k2 = INDEX_FORTRAN_3(2, j+1, k+1, 0, grid->nx+1,
					0, grid->ny+1, 0, grid->nz+1);

				pvec[(j-1)*(grid->nz-1)+k-1] =
					(field(k2).ey*0.5*(field(k1).cbz+field(k2).cbz) -
					field(k2).ez*0.5*(field(k1).cby+field(k2).cby)) /
					(grid->cvac*grid->cvac*e0*e0);
			} // for
		} // for
	} // if

	// Sum flux contributions
	for(int i(0); i<stride; i++) {
		psum += pvec[i];
	} // for

	// Collect sums over all ranks
	mp_allsum_d( &psum, &gpsum, 1 );

	// Normalize flux
	gpsum /= stride*py*pz;

	delete[] pvec;

	return gpsum;
}
// FIXME: THIS COULD BE WRITTEN MUCH CLEANER NOW
THIS COULD BE WRITTEN MUCH CLEANER NOW
THIS COULD BE WRITTEN MUCH CLEANER NOW
double vpic_simulation::poynting_flux(double e0) {
	double  psum = 0.0;
        double gpsum = 0.0;
	int stride = (grid->ny-1)*(grid->nz-1);
	float * pvec = new float[stride];
	if(!pvec) {
		ERROR(("Failed pvec allocation in poynting flux diagnostic"));
	} 
	memset(pvec, 0, stride);
	int ix, k1, k2;
	RANK_TO_INDEX( int(rank()), ix);
	if(ix==0) {
		for(int j(1); j<grid->ny; j++) {
			for(int k(1); k<grid->nz; k++) {
				k1 = INDEX_FORTRAN_3(1, j+1, k+1, 0, grid->nx+1,
					0, grid->ny+1, 0, grid->nz+1);
				k2 = INDEX_FORTRAN_3(2, j+1, k+1, 0, grid->nx+1,
					0, grid->ny+1, 0, grid->nz+1);
				pvec[(j-1)*(grid->nz-1)+k-1] =
					(field(k2).ey*0.5*(field(k1).cbz+field(k2).cbz) -
					field(k2).ez*0.5*(field(k1).cby+field(k2).cby)) /
					(grid->cvac*grid->cvac*e0*e0);
			} 
		} 
	} 
	for(int i(0); i<stride; i++) {
		psum += pvec[i];
	} 
	mp_allsum_d( &psum, &gpsum, 1 );
	gpsum /= stride*py*pz;
	delete[] pvec;
	return gpsum;
}
double vpic_simulation :: poynting_flux ( double e0 ) { double psum = 0.0 ; double gpsum = 0.0 ; int stride = ( grid -> ny - 1 ) * ( grid -> nz - 1 ) ; float * pvec = new float [ stride ] ; if ( ! pvec ) { ERROR ( ( " " ) ) ; } memset ( pvec , 0 , stride ) ; int ix , k1 , k2 ; RANK_TO_INDEX ( int ( rank ( ) ) , ix ) ; if ( ix == 0 ) { for ( int j ( 1 ) ; j < grid -> ny ; j ++ ) { for ( int k ( 1 ) ; k < grid -> nz ; k ++ ) { k1 = INDEX_FORTRAN_3 ( 1 , j + 1 , k + 1 , 0 , grid -> nx + 1 , 0 , grid -> ny + 1 , 0 , grid -> nz + 1 ) ; k2 = INDEX_FORTRAN_3 ( 2 , j + 1 , k + 1 , 0 , grid -> nx + 1 , 0 , grid -> ny + 1 , 0 , grid -> nz + 1 ) ; pvec [ ( j - 1 ) * ( grid -> nz - 1 ) + k - 1 ] = ( field ( k2 ) . ey * 0.5 * ( field ( k1 ) . cbz + field ( k2 ) . cbz ) - field ( k2 ) . ez * 0.5 * ( field ( k1 ) . cby + field ( k2 ) . cby ) ) / ( grid -> cvac * grid -> cvac * e0 * e0 ) ; } } } for ( int i ( 0 ) ; i < stride ; i ++ ) { psum += pvec [ i ] ; } mp_allsum_d ( & psum , & gpsum , 1 ) ; gpsum /= stride * py * pz ; delete [ ] pvec ; return gpsum ; }
FIXME: THIS COULD BE WRITTEN MUCH CLEANER NOW
FIXME : THIS COULD BE WRITTEN MUCH CLEANER NOW
// if // Compute Poynting for domains on left of box // for // for // if // Sum flux contributions // for // Collect sums over all ranks // Normalize flux