Пример #1
0
/*
 * Print particle x
 */
static void print_particle(particle_t x) {
  particle_tuple_t *tup;
  uint32_t i, n;

  switch (particle_kind(&store, x)) {
  case LABEL_PARTICLE:
    printf("(lab %"PRId32")", particle_label(&store, x));
    break;
  case FRESH_PARTICLE:
    printf("(fresh tau!%"PRId32")", fresh_particle_type(&store, x));
    break;
  case TUPLE_PARTICLE:
    tup = tuple_particle_desc(&store, x);
    printf("(tuple");
    n = tup->nelems;
    for (i=0; i<n; i++) {
      if (is_fresh_particle(&store, tup->elem[i])) {
	printf(" p!%"PRId32, tup->elem[i]);
      } else {
	printf(" ");
	print_particle(tup->elem[i]);
      }
    }
    printf(")");
    break;
  }
}
Пример #2
0
static
void print_quadtree_node (Node * root, int bare)
{
  fprintf (log_file, "\n*****Quadtree Node (leaf = %d)******\n", root->is_leaf);
  fprintf (log_file, "Top Left Coordinates (%lf, %lf); Bottom Right Coordinates (%lf, %lf)\n", 
	  root->tl.x, root->tl.y,root->br.x, root->br.y);
  fprintf (log_file, "Center of Mass (%lf, %lf), Total Mass = %lf\n", root->cm.x, root->cm.y, root->total_mass);
  fprintf (log_file, "\n");
  if (root->is_leaf && root->particle)
    {
      if (!bare)
	print_particle (root->particle);
      else
	print_particle_bare (root->particle);
    }
}
Пример #3
0
string print_particle_vector(vector<Particle> &p) {
	std::stringstream ss;
	ss << fixed;
//ss << setw(8) << "#pid" << " " << setw(8) << "cid" << " " << setw(8) << "r[0]" << " " << setw(8) << "r[1]" << " " << setw(8) << "theta" << " " << setw(8) << "f[0]" << " "
//		<< setw(8) << "f[1]" << " " << '\n';

	for (uint i = 0; i < p.size(); i++) {
//		ss << setprecision(3) << setw(8) << p[i].part_id << " " << setprecision(3) << setw(8) << p[i].cell_id << " {" << p[i].cell_id_axis[0] << "," << p[i].cell_id_axis[1] << "} "
//				<< setprecision(3) << setw(8) << p[i].r[0] << " " << setprecision(3) << setw(8) << p[i].r[1] << " " << setprecision(3) << setw(8) << p[i].theta << " "
//				<< setprecision(3) << setw(8) << p[i].f[0] << " " << setprecision(3) << setw(8) << p[i].f[1] << " " << '\n';
		ss << print_particle(p[i]);
	}
	ss << setw(30) << "#-----x-----" << '\n';

	return ss.str();
}
Пример #4
0
void print_header(char *file_name)
{
    struct gadget_header_t *header = read_gadget_header(file_name);

    uint64_t total = ((((uint64_t)header->npart_total[0]) << 32) +
                      header->npart_total[1]);

    printf("%20s: %u/%"PRIu64"\n", "Particles", header->npart[1], total);
    printf("%20s: %g\n", "Mass", header->mass[1]);
    printf("%20s: %g\n", "Redshift", header->redshift);
    printf("%20s: %g\n", "Box Size", header->box_size);
    printf("%20s: %d\n", "Snapshot Files", header->num_files);

    struct gadget_particle_t *ps = read_gadget_particles(file_name);

    for (int i = 0; i < 20; i++) print_particle(ps + i);

    free(header);
    free(ps);
}
Пример #5
0
void bogoman_map_dump(struct bogoman_map *map)
{
	unsigned int x, y;

	for (y = 0; y < map->h; y++) {
		for (x = 0; x < map->w; x++) {
			struct bogoman_map_elem *elem;

			elem = bogoman_get_map_elem(map, x, y);

			switch (elem->id) {
			case BOGOMAN_NONE:
				printf(" ");
			break;
			case BOGOMAN_PLAYER:
				printf("@");
			break;
			case BOGOMAN_DIAMOND:
				printf("$");
			break;
			case BOGOMAN_MOVEABLE:
				printf("M");
			break;
			case BOGOMAN_EDIBLE:
				printf("E");
			break;
			case BOGOMAN_WALL:
				print_wall(elem);
			break;
			case BOGOMAN_PARTICLE:
				print_particle(elem);
			break;
			}
		}

		printf("\n");
	}

	printf("Player at %ux%u diamonds total %u\n",
	       map->player_x, map->player_y, map->diamonds_total);
}
Пример #6
0
particle *MakeParticle(particle *P, REAL ENE, REAL ANG, REAL AZI, unsigned int *seed) {
    REAL	angle, azimuth;
    P->type = PROTON;
    P->energy = ENE;
    angle = ANG * M_PI / AS_REAL(180.0);
    azimuth = AZI * M_PI / AS_REAL(180.0);
    position_particle(azimuth, angle, P);
#if DO_ELASTIC
    GenerateElasticDistances(P, seed);
#endif
#if MIN_TRACE
    P->eloss = AS_REAL(0.0);
    P->where = WhereAmI(P->pos[CX], P->pos[CY], P->pos[CZ]);
#endif
#if GOM_DEBUG
    if (VERBOSE) {
	print_particle("Made particle:", P);
    }
#endif
    return(P);
}
Пример #7
0
/*
 ** Driver routine for direct. With support for check points!
 */
void Grav(KD kd,int lBlock,int kBlock,int iSoftType,int bPeriodic,
		  int bVerbose)
{
	PARTICLE *p,*q;
#if defined(ENABLE_OCL)
	position_t * h_p = kd->h_p;
	acceleration_t * h_a = kd->h_a;
#endif
	int k,l,n,nk,nb,nbk,bs,rs,rsk,iStride,bc,i;

// FIXME: bVerbose
bVerbose = 0;

	p = kd->p;
	n = kd->nMark;
	q = &kd->p[n];
	nk = kd->nActive - kd->nMark;
	bs = kd->iBlockSize;
	nb = n/bs;
	rs = n%bs;
	nbk = nk/bs;
	rsk = nk%bs;
	iStride = 16384/bs;
	if (bPeriodic) iStride = iStride/100;
	if (!iStride) iStride = 1;
	if (lBlock || kBlock) {
		l = lBlock;
		k = kBlock;
		bc = 1;
		if (k < nb) goto Restart1;
		else {
			k -= nb;
			goto Restart2;
			}
		}
	for (i=0;i<n;++i) {
		p[i].a[0] = 0.0;
		p[i].a[1] = 0.0;
		p[i].a[2] = 0.0;
		p[i].dPot = 0.0;

#if defined(ENABLE_OCL)
		h_a[i].x = 0.0;
		h_a[i].y = 0.0;
		h_a[i].z = 0.0;
		h_a[i].p = 0.0;
#endif
		}

#if defined(ENABLE_OCL)
	ocl_event_t event;
	ocl_initialize_event(&event);

	ocl_host_initialize_timer("aggregate");
	ocl_host_start_timer("aggregate");

	// write particle data to device
	ocl_enqueue_write_buffer_raw(OCL_DEFAULT_DEVICE, kd->d_p,
		OCL_SYNCHRONOUS, 0, n*sizeof(position_t), h_p, &event);

	ocl_add_timer("write", &event);

	kd->global_offset = 0;
	kd->global_size = n;

	// update particles
	ocl_enqueue_kernel_ndrange(OCL_DEFAULT_DEVICE, "direct",
		"grav", 1, &kd->global_offset, &kd->global_size,
		&kd->local_size, &event);

	ocl_finish(OCL_DEFAULT_DEVICE);

	ocl_add_timer("execute", &event);

	// read particle data from device
	ocl_enqueue_read_buffer_raw(OCL_DEFAULT_DEVICE, kd->d_a,
		OCL_SYNCHRONOUS, 0, n*sizeof(acceleration_t), h_a, &event);

	ocl_add_timer("read", &event);
	ocl_host_stop_timer("aggregate");
#if 0
	printf("post\n");
	for(k=0; k<4; ++k) {
		print_particle(&h_p[k], &h_a[k]);
	} // for
#endif

	ocl_report_timer("write");
	ocl_report_timer("execute");
	ocl_report_timer("read");
	ocl_host_report_timer("aggregate");

	exit(1);
#endif

	/*
	 ** First do all the diagonal blocks.
	 */
	bc = 1;

	for (k=0;k<nb;++k,++bc) {
		if (bVerbose) {
			if (!(bc%iStride)) {
				printf("Block:(%d,%d)\n",k,k);
				fflush(stdout);
				bc = 0;
				}
			}
		if (bPeriodic) {
			diaEwald(&p[k*bs],bs,iSoftType,kd->fPeriod[0]);
			}
		else {
			diaGrav(&p[k*bs],bs,iSoftType);
			}
		} // for

	if (bVerbose && rs) {
		printf("Block:(%d,%d)\n",k,k);
		fflush(stdout);
		}
	if (bPeriodic) {
		diaEwald(&p[k*bs],rs,iSoftType,kd->fPeriod[0]);
		}
	else {
		diaGrav(&p[k*bs],rs,iSoftType);
		}
	/*
	 ** Now do the off-diagonal blocks.
	 */
	bc = 1;
	for (l=1;l<nb;++l) {
		for (k=l;k<nb;++k,++bc) {
			if (bc == kd->iChkptInterval) {
				WriteChkpt(kd,l,k);
				if (bVerbose) {
					printf("Check point (%d,%d) written\n",l-1,k);
					fflush(stdout);
					}
				bc = 1;
				}
		Restart1:
			if (bVerbose) {
				if (!(bc%iStride)) {
					printf("Block:(%d,%d)\n",l-1,k);
					fflush(stdout);
					}
				}
			if (bPeriodic) {
				blkEwald(&p[(l-1)*bs],bs,&p[k*bs],bs,iSoftType,kd->fPeriod[0]);
				}
			else {
				blkGrav(&p[(l-1)*bs],bs,&p[k*bs],bs,iSoftType);
				}
			}
		}
	bc = 1;
	for (l=0;l<nb;++l,++bc) {
		if (!rs) break;
		if (bPeriodic) {
			blkEwald(&p[l*bs],bs,&p[nb*bs],rs,iSoftType,kd->fPeriod[0]);
			}	
		else {
			blkGrav(&p[l*bs],bs,&p[nb*bs],rs,iSoftType);
			}
		}
	/*
	 ** We are now done the mutual interactions now we need to do the
	 ** interactions due to the unmarked particles on the marked ones.
	 */
	bc = 1;
	if (nk) {
		if (bVerbose) {
			printf("Now doing unmarked particle interactions\n");
			fflush(stdout);
			}
		for (l=0;l<nb;++l) {
			for (k=0;k<nbk;++k,++bc) {
				if (bc == kd->iChkptInterval) {
					WriteChkpt(kd,l,k+nb);
					if (bVerbose) {
						printf("Check point (%d,%d) written\n",l,k+nb);
						fflush(stdout);
						}
					bc = 1;
					}
			Restart2:
				if (bVerbose) {
					if (!(bc%iStride)) {
						printf("Block:(%d,%d)\n",l,k+nb);
						fflush(stdout);
						}
					}
				if (bPeriodic) {
					umkEwald(&p[l*bs],bs,&q[k*bs],bs,iSoftType,kd->fPeriod[0]);
					}
				else {
					umkGrav(&p[l*bs],bs,&q[k*bs],bs,iSoftType);
					}
				}
			if (bPeriodic) {
				umkEwald(&p[l*bs],bs,&q[k*bs],rsk,iSoftType,kd->fPeriod[0]);
				}
			else {
				umkGrav(&p[l*bs],bs,&q[k*bs],rsk,iSoftType);
				}
			}
		for (k=0;k<nbk;++k,++bc) {
			if (bPeriodic) {
				umkEwald(&p[l*bs],rs,&q[k*bs],bs,iSoftType,kd->fPeriod[0]);
				}
			else {
				umkGrav(&p[l*bs],rs,&q[k*bs],bs,iSoftType);
				}
			}
		if (bPeriodic) {
			umkEwald(&p[l*bs],rs,&q[k*bs],rsk,iSoftType,kd->fPeriod[0]);
			}
		else {
			umkGrav(&p[l*bs],rs,&q[k*bs],rsk,iSoftType);
			}
		}

#if 0
	printf("post normal\n");
	for(i=0; i<4; ++i) {
		printf("%f %f %f\n", p[i].a[0], p[i].a[1], p[i].a[2]);
		printf("%f\n", p[i].dPot);
	} // for
#endif

#if defined(ENABLE_OCL)
	double rms = 0.0;
#endif

	for (i=0;i<n;++i) {
		p[i].a[0] *= kd->G;
		p[i].a[1] *= kd->G;
		p[i].a[2] *= kd->G;
		p[i].dPot *= kd->G;
#if defined(ENABLE_OCL)
		const double dx = p[i].a[0] - h_a[i].x;
		const double dy = p[i].a[1] - h_a[i].y;
		const double dz = p[i].a[2] - h_a[i].z;
		//const double dp = p[i].dPot - h_a[i].p;
		//rms += dx*dx + dy*dy + dz*dz + dp*dp;
		rms += dx*dx + dy*dy + dz*dz;
#endif
		}
	
#if defined(ENABLE_OCL)
	rms /= n;
	rms = sqrt(rms);
	printf("rms: %e\n", rms);
#endif
	}
Пример #8
0
/*
 * Print p[x] = ...
 */
static void print_particle_def(particle_t x) {
  printf(" p!%"PRId32" = ", x);
  print_particle(x);
  printf("\n");
}
Пример #9
0
void print_system(System *system) {
    for (int i = 0; i < system->nr_particles; i++)
        print_particle(system->particle[i]); 
}