Beispiel #1
0
void	init_space( void )
{
	long	i;

	g_frame = 0;

	/* 宇宙 */

	g_cui_star_n = CUI_STAR_DFLT_N;

	g_space.zv = Z_SPEED;
	for( i = 0; i < CUI_STAR_MAX_N; i++ ){
		g_space.star[i].x = randm( XR * 2 ) - XR;
		g_space.star[i].y = randm( YR * 2 ) - YR;
		g_space.star[i].z = randm( ZR );
	}

	/* スタッフ・ロール */

	staff_roll_y = -SCREEN_HEIGHT;

	staff_roll_max_len = 1;
	for( i = 0; i < LOOP_MAX_1000; i++ ){
		long	len;

		if( g_str_staff_roll[i] == NULL )
			break;
		if( g_str_staff_roll[i][0] == '\0' )
			break;

		len = str_len_draw( g_str_staff_roll[i] );
		if( staff_roll_max_len < len )
			staff_roll_max_len = len;
	}
}
Beispiel #2
0
/*
 * returns the number of banks we're going to fire
 * it also sets them up to fire.
 */
int
e_phasers(struct ship *sp, struct ship *fed)
{
	int i;
	int banks;
	int hit;
	int howmany;
	float bear;

	banks = 0;
	howmany = randm(sp->num_phasers / 2) + sp->num_phasers / 2;
	sp->p_spread = 10 + randm(12);
	for (i=0; i<sp->num_phasers; i++) {
		if ((sp->phasers[i].status & P_DAMAGED) ||
		    (sp->phasers[i].load == 0))
			continue;
		if (fed != NULL) {
			if (sp->phasers[i].target == NULL)
				continue;
			bear = bearing(sp->x, fed->x, sp->y, fed->y);
			hit = phaser_hit(sp, fed->x, fed->y, &sp->phasers[i], bear);
			if (hit <= 0)
				continue;
		}
		banks++;
		sp->phasers[i].status |= P_FIRING;
		if (banks >= howmany)
			break;
	}
	return banks;
}
Beispiel #3
0
void SynPNP::random_point(double & Xw, double & Yw, double & Zw)
{
  double theta = randm(0, 3.14159), phi = randm(0, 2 * 3.14159), R = randm(0, +2);

  Xw = sin(theta) * sin(phi) * R;
  Yw = -sin(theta) * cos(phi) * R;
  Zw =  cos(theta) * R;
}
Beispiel #4
0
double randm_normal(void) {
	double v1, v2;
	double rsq=1.0;
	
	while(rsq>=1. || rsq==0.0) {
		v1=2.*randm()-1.0;
		v2=2.*randm()-1.0;
		rsq=v1*v1+v2*v2;
	}
	
	return( v1*sqrt(-2.0 * log(rsq) / rsq));
}
Beispiel #5
0
void SynPNP::project_with_noise(double R[3][3], double t[3], double noise,
								    						double Xw, double Yw, double Zw,
														    double & u, double & v) {
  double Xc = R[0][0] * Xw + R[0][1] * Yw + R[0][2] * Zw + t[0];
  double Yc = R[1][0] * Xw + R[1][1] * Yw + R[1][2] * Zw + t[1];
  double Zc = R[2][0] * Xw + R[2][1] * Yw + R[2][2] * Zw + t[2];

  double nu = randm(-noise, +noise);
  double nv = randm(-noise, +noise);
  u = uc_ + fu_ * Xc / Zc + nu;
  v = vc_ + fv_ * Yc / Zc + nv;
}
Beispiel #6
0
UniqueSnowFlake::UniqueSnowFlake() : 
	myImage( new byte[WIDTH*DEPTH*4] ),
	myBMP( new bool[BMP_SIZE] )
{
  int done=0;
  int x,y,i,n,dx,dy,dp;
  bool *p,*p2;

  memset(myImage,0,WIDTH*DEPTH*4*sizeof(byte));
  memset(myBMP,0,BMP_SIZE*sizeof(bool));

  //seed factal
  point(BMP_WIDTH-1,BMP_DEPTH-1);
  myBMP[(BMP_SIZE-1)]=true;

  //shooting particle algorithm with 8 way reflection
  n=0;
  do{    
    y=(BMP_WIDTH-1)-randm(n);
    if (randm(2)==1){
      x=y; y=0;
      dy=1;dx=0;dp=BMP_WIDTH;
    }
    else{
      x=0;
      dy=0;dx=1;dp=1;
    }
    p=myBMP+x+BMP_WIDTH*y;
    i=0;
    do{
     p2=p+dp;
      if (*p2){

		point(x+dx,y+dy);
		point(y+dy,x+dx);

		++*p;
		++*(myBMP+y+BMP_WIDTH*x);

		point(x,y);
		point(y,x);

		if (i==0) done = 1;

        break;
      }
      x=x+dx;y=y+dy;p=p2;
    }while(++i<(BMP_WIDTH-1));
    if (n<(BMP_WIDTH-1)) n++;
  }while(!done);	
}
Beispiel #7
0
void init_LargeScale2DNoise(struct Field fldi) {
	int i,j,k;
	int num_force=0;
	int total_num_force;
	double fact;
	
	for( i = 0; i < NX_COMPLEX/NPROC; i++) {
		for( j = 0; j < NY_COMPLEX; j++) {
			k=0;
			if(kz[ IDX3D ] == 0.0) {
				if(pow(k2t[ IDX3D ], 0.5) / ( 2.0*M_PI ) < 1.0 / param.noise_cut_length_2D) {
					fldi.vx[ IDX3D ] += param.per_amplitude_large_2D * mask[IDX3D] * randm() * cexp( I * 2.0*M_PI*randm() ) * NTOTAL;
					fldi.vy[ IDX3D ] += param.per_amplitude_large_2D * mask[IDX3D] * randm() * cexp( I * 2.0*M_PI*randm() ) * NTOTAL;
#ifdef MHD
					fldi.bx[ IDX3D ] += param.per_amplitude_large_2D * mask[IDX3D] * randm() * cexp( I * 2.0*M_PI*randm() ) * NTOTAL;
					fldi.by[ IDX3D ] += param.per_amplitude_large_2D * mask[IDX3D] * randm() * cexp( I * 2.0*M_PI*randm() ) * NTOTAL;
#endif
					if(mask[IDX3D] > 0) num_force++;
				}
			}
		}
	}
	
	// Get the total number of forced scales.
#ifdef MPI_SUPPORT
	MPI_Allreduce( &num_force, &total_num_force, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
#else
	total_num_force=num_force;
#endif
	
	fact=pow(total_num_force,0.5);
	
	// Divide by the total number of modes
	for( i = 0; i < NX_COMPLEX/NPROC; i++) {
		for( j = 0; j < NY_COMPLEX; j++) {
			k=0;
			if(kz[ IDX3D ] == 0.0) {
				fldi.vx[ IDX3D ] = fldi.vx[ IDX3D ] / fact;
				fldi.vy[ IDX3D ] = fldi.vy[ IDX3D ] / fact;
#ifdef MHD
				fldi.bx[ IDX3D ] = fldi.bx[ IDX3D ] / fact;
				fldi.by[ IDX3D ] = fldi.by[ IDX3D ] / fact;
#endif
			}
		}
	}
	
  enforce_complex_symm(fldi);  
}
Beispiel #8
0
void
check_locks(struct ship *ep, int percent, struct ship *fed)
{
	int i, j = 0;

	for (i=0; i<ep->num_phasers; i++) {
		if ((ep->phasers[i].target != NULL)
		    && (randm(100) <= percent)) {
			ep->phasers[i].target = NULL;
			if (ep != fed)
				continue;
			if (!j)
				printf("Computer: Phaser(s) %d", i+1);
			else
				printf(", %d", i+1);
			j++;
		}
	}
	if (j > 1)
		puts(" have lost their target locks.");
	else if (j == 1)
		puts(" has lost its target lock.");
	j = 0;
	for (i=0; i<ep->num_tubes; i++) {
		if ((ep->tubes[i].target != NULL)
		    && (randm(100) <= percent)) {
			ep->tubes[i].target = NULL;
			if (ep != fed)
				continue;
			if (!j)
				printf("Computer: Tube(s) %d", i+1);
			else
				printf(", %d", i+1);
			j++;
		}
	}
	if (j > 1)
		puts(" have lost their target locks.");
	else if (j == 1)
		puts(" has lost its target lock.");
	if ((ep->target != NULL) && (randm(100) <= percent)) {
		ep->target = NULL;
		ep->relbear = 0;
		if (ep == fed)
			printf("Computer: %s has lost helm lock\n",
			    shipname);
	}
}
Beispiel #9
0
 void HMM::sample(uint32_t nseq, uint32_t* slen, uint32_t* x, uint32_t* y){
     int s_ind = 0;
     int x_, y_;
     for(int s = 0; s < nseq; s++) {
         x_ = randm(hs, nu);
         y_ = randm(os, g + x_*os);
         x[s_ind] = x_;
         y[s_ind] = y_;
         for(int t = 1; t < slen[s]; t++){
             x_ = randm(hs, Q + x[s_ind + t - 1]*hs);
             y_ = randm(os, g + x_*os);
             x[s_ind + t] = x_;
             y[s_ind + t] = y_;
         }
         s_ind += slen[s];
     }
 }
uint64_t generate_uuid() {
        struct timeval t_start;
        gettimeofday(&t_start, NULL);
        uint64_t ms = ((uint64_t)t_start.tv_sec * 1000) + (uint64_t)t_start.tv_usec/1000;
        uint64_t id = ms << (64 - 41);
	id |= (uint64_t)(randm(16) % (unsigned long long int)(pow(2, (64 - 41))));
        return id;
}
Beispiel #11
0
/*
 * Returns 1 if a probe was launched
 */
int
e_launchprobe(struct ship *sp, struct ship *fed)
{
	int i;
	struct list *lp;
	struct torpedo *tp;

	if (!syswork(sp, S_PROBE) || sp->energy <= 10 || cantsee(sp))
		return 0;
	/*
	 * fed ship has to be going slow before we'll launch
	 * a probe at it.
	 */
	if (fabs(fed->warp) > 1.0)
		return 0;
	lp = newitem(I_PROBE);
	tp = lp->data.tp = MKNODE(struct torpedo, *, 1);
	if (tp == (struct torpedo *)NULL) {
		fprintf(stderr, "e_launchprobe: malloc failed\n");
		exit(2);
	}
	tp->from = sp;
	tp->speed = sp->warp;
	tp->newspeed = 3.0;
	tp->target = fed;
	tp->course = bearing(sp->x, fed->x, sp->y, fed->y);
	tp->x = sp->x;
	tp->y = sp->y;
	tp->prox = 200 + randm(200);
	tp->timedelay = 15.;
	tp->id = new_slot();
	if ((i = randm(15) + 10) > sp->energy)
		i = sp->energy;
	tp->fuel = i;
	tp->type = TP_PROBE;
	sp->energy -= i;
	sp->pods -= i;
	printf("%s launching probe #%d\n", sp->name, tp->id);
	return 1;
}
Beispiel #12
0
void init_WhiteNoise(struct Field fldi) {
	int i,j,k;
	double fact;
	
	// Excite (2/3)^3*NTOTAL modes
	fact = pow(27.0/8.0*NTOTAL, 0.5);
	
	for( i = 0; i < NX_COMPLEX/NPROC; i++) {
		for( j = 0; j < NY_COMPLEX; j++) {
			for( k = 0; k < NZ_COMPLEX; k++) {
				fldi.vx[ IDX3D ] += param.per_amplitude_noise * mask[IDX3D] * randm() * cexp( I * 2.0*M_PI*randm() ) * fact;
				fldi.vy[ IDX3D ] += param.per_amplitude_noise * mask[IDX3D] * randm() * cexp( I * 2.0*M_PI*randm() ) * fact;
				fldi.vz[ IDX3D ] += param.per_amplitude_noise * mask[IDX3D] * randm() * cexp( I * 2.0*M_PI*randm() ) * fact;
#ifdef MHD
				fldi.bx[ IDX3D ] += param.per_amplitude_noise * mask[IDX3D] * randm() * cexp( I * 2.0*M_PI*randm() ) * fact;
				fldi.by[ IDX3D ] += param.per_amplitude_noise * mask[IDX3D] * randm() * cexp( I * 2.0*M_PI*randm() ) * fact;
				fldi.bz[ IDX3D ] += param.per_amplitude_noise * mask[IDX3D] * randm() * cexp( I * 2.0*M_PI*randm() ) * fact;
#endif
			}
		}
	}
	
	enforce_complex_symm(fldi);
  
}
Beispiel #13
0
void SynPNP::random_pose(double R[3][3], double t[3])
{
  const double range = 1;

  double phi   = randm(0, range * 3.14159 * 2);
  double theta = randm(0, range * 3.14159);
  double psi   = randm(0, range * 3.14159 * 2);

  R[0][0] = cos(psi) * cos(phi) - cos(theta) * sin(phi) * sin(psi);
  R[0][1] = cos(psi) * sin(phi) + cos(theta) * cos(phi) * sin(psi);
  R[0][2] = sin(psi) * sin(theta);

  R[1][0] = -sin(psi) * cos(phi) - cos(theta) * sin(phi) * cos(psi);
  R[1][1] = -sin(psi) * sin(phi) + cos(theta) * cos(phi) * cos(psi);
  R[1][2] = cos(psi) * sin(theta);

  R[2][0] = sin(theta) * sin(phi);
  R[2][1] = -sin(theta) * cos(phi);
  R[2][2] = cos(theta);

  //t[0] = 0.0f;  t[1] = 0.0f;  t[2] = randm(0.0f, 6.0f);
  t[0] = 0.0f;  t[1] = 0.0f;  t[2] = 6.0f;
}
Beispiel #14
0
/*
 * Advance to the rear! (Always returns 1)
 */
int
e_evade(struct ship *sp, int x, int y, int type)
{
	float newcourse = 0.0;
	float	bear;

	bear = bearing(sp->x, x, sp->y, y);
	if (cansee(sp) && syswork(shiplist[0], S_SENSOR))
		printf("%s taking evasive action!\n", sp->name);
	switch (randm(3)) {
		case 1:
			newcourse = rectify(bear - 90.0);
			break;
		case 2:
			newcourse = rectify(bear + 90.0);
			break;
		case 3:
			newcourse = rectify(bear + 180.0);
			break;
		default:
			printf("error in evade()\n");
			break;
	}
	sp->target = NULL;
	sp->newcourse = newcourse;
	sp->newwarp = 2 + randm((int)(sp->max_speed - 3));
	if (is_dead(sp, S_WARP))
		sp->newwarp = 1.0;
#ifdef TRACE
	if (trace) {
		printf("*** Evade: Newcourse = %3.0f\n", newcourse);
		printf("*** Evade: Newwarp = %.2f\n", sp->newwarp);
	}
#endif
	type = type;	/* LINT */
	return 1;
}
Beispiel #15
0
/* Set the program parameters from the command-line arguments */
void parameters(int argc, char **argv) {
  int submit = 0;  /* = 1 if submission parameters should be used */
  int seed = 0;  /* Random seed */
  char uid[L_cuserid + 2]; /*User name */

  /* Read command-line arguments */
  //  if (argc != 3) {
  if ( argc == 1 && !strcmp(argv[1], "submit") ) {
    /* Use submission parameters */
    submit = 1;
    N = 4;
    procs = 2;
    printf("\nSubmission run for \"%s\".\n", cuserid(uid));
      /*uid = ID;*/
    strcpy(uid,ID);
    srand(randm());
  }
  else {
    if (argc == 3) {
      seed = atoi(argv[3]);
      srand(seed);
      printf("Random seed = %i\n", seed);
    }
    else {
      printf("Usage: %s <matrix_dimension> <num_procs> [random seed]\n",
	     argv[0]);
      printf("       %s submit\n", argv[0]);
      exit(0);
    }
  }
    //  }
  /* Interpret command-line args */
  if (!submit) {
    N = atoi(argv[1]);
    if (N < 1 || N > MAXN) {
      printf("N = %i is out of range.\n", N);
      exit(0);
    }
    procs = atoi(argv[2]);
    if (procs < 1) {
      printf("Warning: Invalid number of processors = %i.  Using 1.\n", procs);
      procs = 1;
    }
  }

  /* Print parameters */
  printf("\nMatrix dimension N = %i.\n", N);
  printf("Number of processors = %i.\n", procs);
}
Beispiel #16
0
/*
 * This routine turns the ship at speed towards its target
 */
int
e_attack(struct ship *sp, struct ship *fed)
{
	float	speed;
	float	tmpf;

	tmpf = fabs(fed->warp);
	if (fabs(sp->warp) >= tmpf + 2.0 || (is_dead(sp, S_WARP)))
		return 0;
	if ((speed = tmpf + randm(2) + 2.0) > sp->max_speed)
		speed = sp->max_speed;
	(void) e_pursue(sp, fed, speed);
	if (cansee(sp) && syswork(fed, S_SENSOR))
		printf("%s:  %s attacking.\n", helmsman, sp->name);
	return 1;
}
void get_new_direction(double (*nx_new)[N], double (*ny_new)[N],
                       double (*nx_temp)[N], double (*ny_temp)[N],
                       double (*sumnx)[N], double (*sumny)[N],
                       int first_particle, double m, double strength) {
  double norm = 1 / sqrt(pow((*sumnx)[first_particle], 2) +
                         pow((*sumny)[first_particle], 2));
  double s = randm(m, strength); // random noise
  (*nx_new)[first_particle] =
      (*sumnx)[first_particle] * norm; // standardization of the velocity
  (*ny_new)[first_particle] = (*sumny)[first_particle] * norm;
  (*nx_temp)[first_particle] = (*nx_new)[first_particle];
  (*ny_temp)[first_particle] = (*ny_new)[first_particle];
  (*nx_new)[first_particle] =
      (*nx_temp)[first_particle] * cos(s) - (*ny_temp)[first_particle] * sin(s);
  (*ny_new)[first_particle] =
      (*nx_temp)[first_particle] * sin(s) + (*ny_temp)[first_particle] * cos(s);
}
	void generateTerrain()
	{
		//fill the grond with grass
		for(int x=0; x<WIDTH; ++x){
			for(int y=0; z<HEIGHT; ++y){//Sprinkle some Hills 
				if(randm(10) == 0){
					tiles_[x][y] = &hillTerrain_;
				}else{
					tiles_[x][y] = &grassTerrain_;
				}
			}
		}
		//Lay a River.
		int x = random(WIDTH);
		for(int y =0; y<HEIGHT; ++y){
			tiles_[x][y] = &riverTerrain_;
		}
	}
Beispiel #19
0
/*
 * Returns the number of tubes we're going to fire
 * Also sets them up to fire
 */
int
e_torpedo(struct ship *sp)
{
	int i;
	int tubes;
	int howmany;
	struct ship *sp1;
	int range;

	/*
	 * don't shoot if someone might be in the way
	 * (i.e. proximity fuse will go off right as the
	 * torps leave the tubes!)
	 */
	for (i=1; i <= shipnum; i++) {
		sp1 = shiplist[i];
		/* This must check for dead ships too! */
		if (sp1 == sp)
			continue;
		range = rangefind(sp->x, sp1->x, sp->y, sp1->y);
		if (range <= 400)
			return 0;
	}
	tubes = 0;
	/* This is not and should not be dependent on the
	   number of tubes one has */
	howmany = randm(2) + 1;		
	for (i=0; i<sp->num_tubes; i++) {
		if ((sp->tubes[i].status & T_DAMAGED)
		    || (sp->tubes[i].load == 0))
			continue;
		if (sp->tubes[i].target == NULL)
			continue;
		tubes++;
		sp->tubes[i].status |= T_FIRING;
		if (tubes >= howmany)
			break;
	}
	return tubes;
}
Beispiel #20
0
int
damage(int hit, struct ship *ep, int s, struct damage *dam, int flag)
{
	int i;
	int j;
	int k;
	float	f1;		/* Damage factor except for shields */
	float	f2 = 1.0;	/* Shield damage factor */
	int percent;
	struct ship *fed;

	fed = shiplist[0];
	printf("hit %d on %s's shield %d\n", hit, ep->name, s);
	s--;
	/*
	 * Note that if the shield is at 100% efficiency, no
	 * damage at all will be taken (except to the shield itself)
	 */
	f1 = hit * (1.0 - ep->shields[s].eff * ep->shields[s].drain);
	if (f1 < 0)
		return 0;
	/* Calculate shield damage */
	if (flag == D_ANTIMATTER)
		f2 = ep->tu_damage * 100;
	else if (flag == D_PHASER)
		f2 = ep->ph_damage * 100;
	if (s == 0)
		f2 *= SHIELD1;
	ep->shields[s].eff -= max(hit/f2, 0);
	if (ep->shields[s].eff < 0.0)
		ep->shields[s].eff = 0.0;
	/* Calculate loss of fuel, regeneration, etc. */
	ep->eff += f1/dam->eff;
	ep->pods -= f1/dam->fuel;
	ep->energy -= f1/dam->fuel;
	ep->regen -= f1/dam->regen;
	if (ep->regen < 0.0)
		ep->regen = 0.0;
	if (ep->pods < 0.0)
		ep->pods = 0.0;
	if (ep->energy < 0.0)
		ep->energy = 0.0;
	if (ep->pods < ep->energy)
		ep->energy = ep->pods;
	/* Kill some crew */
	if (ep->complement > 0) {
		j = f1 * dam->crew;
		if (j > 0)
			ep->complement -= randm(j);
		if (ep->complement < 0)
			ep->complement = 0;
	}
	/* Damage some weapons */
	j = f1/dam->weapon;
	for(i=0; i<j; i++) {
		k = randm(ep->num_phasers + ep->num_tubes) - 1;
		if (k < ep->num_phasers) {
			if (ep->phasers[k].status & P_DAMAGED)
				continue;
			ep->phasers[k].status |= P_DAMAGED;
			ep->phasers[k].target = NULL;
			/*
			 * Reroute the energy
			 * back to the engines
			 */
			ep->energy = min(ep->pods, ep->energy
			    + ep->phasers[k].load);
			ep->phasers[k].load = 0;
			ep->phasers[k].drain = 0;
			k++;
			if (ep == fed)
				printf("   phaser %d damaged\n", k);
		} else {
			k -= ep->num_phasers;
			if (ep->tubes[k].status & T_DAMAGED)
				continue;
			/*
			 * If tubes are damaged, reroute the pods
			 * back to the engines
			 */
			ep->pods += ep->tubes[k].load;
			ep->energy += ep->tubes[k].load;
			ep->tubes[k].load = 0;
			ep->tubes[k].status |= T_DAMAGED;
			ep->tubes[k].target = NULL;
			k++;
			if (ep == fed)
				printf("   tube %d damaged\n", k);
		}
	}
	/* Damage the different systems */
	for (i=0; i<S_NUMSYSTEMS; i++) {
		if (is_dead(ep, i))	/* Don't damage a dead system */
			continue;
		percent = 0;
		if (randm(dam->stats[i].roll) < f1) {
			/* A better method should be found */
			percent = (int) randm((int) f1);
/*
 * The expected value for the percent damage to each system is roughly
 * equal to:
 *	f1 * f1 / (2 * dam->stats[i].roll)
 * Only these damages are proportional to hit squared.  All others are
 * linearly proportional.  This includes shield damage, ship's fuel
 * supply, consumption and regeneration rates, casualties, and weapons.
 * (When weapons are damaged, they are 100% damaged - the number of
 * weapons damaged is proportional to hit).  I think the old way
 * decided whether or not to completely damage a system based on the
 * comparison "randm(dam->stats[i].roll) < f1".  This is almost like
 * the weapons are still handled.  Another possibility is to always
 * damage each system by:
 *	100 * randm((int)f1) / dam->stats[i].roll
 * percent.  This adds some randomness and makes the approx. expected
 * value of the damage to each system:
 *	100 * f1 / (2 * dam->stats[i].roll)
 * percent.  Perhaps this isn't such a good idea after all; this is
 * 100/f1 times the current expected value, often > 2.  And it is
 * actually somewhat less random since each system gets damaged each
 * time.  I had thought that the damage should be directly proportional
 * to f1, not to its square.  But perhaps it makes sense that a hit
 * twice as big has an expected value of damage four times as big as
 * that from a smaller hit.  The actual damage any given time is still
 * proportional to the hit, but the probability that any damage will be
 * done at all is also directly proportional to the hit.  This is a
 * pretty good system after all. [RJN]
 */
			ep->status[i] += percent;
			if (ep->status[i] > 100)
				ep->status[i] = 100;
			if (ep == fed) {
				if (is_dead(ep, i))
					printf("   %s\n",
				    	    dam->stats[i].mesg);
				else
					printf("   %s damaged.\n",
					    sysname[i]);
			}
			/* Now check for the effects of the damage */
			/* Do the effects of a totally destroyed system */
			if (is_dead(ep, i)) {
				switch(i) {
				case S_SENSOR:
				case S_PROBE:
					/* No bookkeeping needed */
					break;
				case S_WARP:
					/* Reduce max speed */
					ep->max_speed = 1.0;
					break;
				case S_COMP:
					check_locks(ep, 100, fed);
					break;
				default:
					printf("How'd we get here?\n");
				}
			} else {
				/* Now check partially damaged systems */
				switch(i) {
				case S_SENSOR:
				case S_PROBE:
					/* No bookkeeping needed */
					break;
				case S_WARP:
					f2 = percent * ep->orig_max / 100;
					ep->max_speed -= f2;
					if (ep->max_speed < 1.0) {
						ep->max_speed = 1.0;
						ep->status[S_WARP] = 100;
					}
					break;
				case S_COMP:
					check_locks(ep, percent, fed);
					break;
				default:
					printf("Oh, oh....\n");
				}
			}
		}
	}
#ifdef HISTORICAL
	/*
	 * Historically, if more than 43 points of damage were done
	 * to the ship, it would destroy itself.  This led to much
	 * abuse of probes and thus has been enclosed inside of
	 * an #ifdef
	 */
	if (f1 > 43)
		ep->delay = 1.;
#endif
	return 0;
}
void forcing(struct Field fldi,
			 double dt) {
			 
// Force random velocity field
	const double kf = 3.0 * M_PI * 2.0;
	const double deltakf = kf * 0.2;
	const double amplitude_forcing = 0.1;

	// Force all the vector
	
	
	int i,j,k;
	int num_force=0;
	int total_num_force;
	double fact;
	double q0;
	
	q0=pow(dt,0.5);
	
	for( i = 0; i < NX_COMPLEX/NPROC; i++) {
		for( j = 0; j < NY_COMPLEX; j++) {
			for( k = 0; k < NZ_COMPLEX; k++) {
				if( (k2t[ IDX3D ]>(kf-deltakf)*(kf-deltakf)) && (k2t[ IDX3D ]<(kf+deltakf)*(kf+deltakf))) {
					w4[ IDX3D ] = amplitude_forcing * mask[IDX3D] * randm() * cexp( I * 2.0*M_PI*randm() ) * NTOTAL*q0;
					w5[ IDX3D ] = amplitude_forcing * mask[IDX3D] * randm() * cexp( I * 2.0*M_PI*randm() ) * NTOTAL*q0;
					w6[ IDX3D ] = amplitude_forcing * mask[IDX3D] * randm() * cexp( I * 2.0*M_PI*randm() ) * NTOTAL*q0;

					if(mask[IDX3D] > 0) num_force++;
				}
				else {
					w4[ IDX3D ] = 0.0;
					w5[ IDX3D ] = 0.0;
					w6[ IDX3D ] = 0.0;
				}
			}
		}
	}
	
  symmetrize_complex(w4);
  if(rank==0) w4[0]=0.0;
  symmetrize_complex(w5);
  if(rank==0) w5[0]=0.0;
  symmetrize_complex(w6);
  if(rank==0) w6[0]=0.0;
  
	// Get the total number of forced scales.
#ifdef MPI_SUPPORT
	MPI_Allreduce( &num_force, &total_num_force, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
#else
	total_num_force=num_force;
#endif
	
	fact=pow(total_num_force,0.5);

	for( i = 0; i < NX_COMPLEX/NPROC; i++) {
		for( j = 0; j < NY_COMPLEX; j++) {
			for( k = 0; k < NZ_COMPLEX; k++) {
				fldi.vx[ IDX3D ] += w4[ IDX3D ] / fact;
				fldi.vy[ IDX3D ] += w5[ IDX3D ] / fact;
				fldi.vz[ IDX3D ] += w6[ IDX3D ] / fact;
			}
		}
	}
	
	projector(fldi.vx,fldi.vy,fldi.vz);
	
	return;
}
Beispiel #22
0
{
     char *tmp, *XXXX;
     uint64_t val;
     int fd, xcnt, cnt, pos,
         tries = pow(62, 3);
     pid_t pid;
     char *wp = strdup(template);
     size_t len = strlen(wp);
     /* characters used to fill in the X's in template names */
     const char filler[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

     tmp = XXXX = NULL;
     xcnt = cnt = pos = 0;
     pid = getpid();
     srand(time(NULL));
     val = getrandom() * rand() * randm(RAND_MAX) ^ pid;

/* The number of times to attempt to generate a temporary file.
 * POSIX demands that this must be no smaller than TMP_MAX.
 */
# if ((62*62*62) < TMP_MAX)
     tries = TMP_MAX;
# endif

     COINT_DBG("tries: '%d'\n", tries);

     /* find the last X in wp */
     char *sp = strrchr(wp, 'X');
     /* make sure that we at least have one template X */
     if (sp == NULL) {
          /* no period was found in template string */
Beispiel #23
0
/* Initialization of neurons parameters */
int initialization(neuron **nrn, int numNeurons, int simTime)
{
    int i, j, idj, size=0;
    char *fname;
    double tmp;
    FILE *fp, *fq;

    srand (time(NULL));
        
    for(i = 0; i < numNeurons; ++i){
        (*nrn)[i].numPreSyn = 0;
        (*nrn)[i].E = 0.0;
        for(j = 0; j < simTime; ++j){
            (*nrn)[i].V[j] = randm(0.01, 0.1);
            (*nrn)[i].Z[j] = randm(0.01, 0.05);
            (*nrn)[i].S[j] = randm(0.01, 0.05);
            (*nrn)[i].N[j] = randm(0.01, 0.05);
        }
    }

    if(!(fp = fopen("stimuli.dat", "r"))){
        fname = "stimuli.dat";
        goto fail;
    }

    for(i = 0; i < numNeurons; ++i){
        for(j = 0; j < simTime; ++j){
            fscanf(fp, "%lf", &(*nrn)[i].Iext[j]);
        }
    }
    
    fclose(fp);

    if(!(fq = fopen("synapses.dat", "r"))){
        fname = "synapses.dat";
        goto fail;
    }

    for(i = 0; i < numNeurons; ++i){
        idj = 0;
        for(j = 0; j < numNeurons; ++j){
            fscanf(fp, "%lf", &tmp);
            if (tmp != 0){
                if (j == 0){
                    (*nrn)[i].W[0] = tmp;
                    (*nrn)[i].pre_id[0] = j;
                }else{
                    size++;
                    (*nrn)[i].W = (double *)realloc((*nrn)[i].W, size*sizeof(double));
                    (*nrn)[i].W[idj] = tmp;

                    (*nrn)[i].pre_id = (int *)realloc((*nrn)[i].pre_id,
                                size*sizeof(int));
                    (*nrn)[i].pre_id[idj] = j;
                    idj++;
                }
                (*nrn)[i].numPreSyn++;
            }
        }
    }

    fclose(fp);

    return 0;

fail:
    printf("File %s cannot be opened!\n", fname);
    exit(-1);
}