int gen_randphicplx(doublecomplex *pmat[], int MATRIX_SIZE)
{
	int i,m, n;
	double lastel;

	for(i=0; i<NUMMAT; i++)
	{
		lastel=0.0;
		for(m = 0; m < (MATRIX_SIZE-1) ;m++)
		{
			for(n=m; n < MATRIX_SIZE ; n++)
			{
				if(m == n)
				{
					(pmat[i]+(m*MATRIX_SIZE + n))->r = mt_ldrand();
					lastel += (pmat[i]+(m*MATRIX_SIZE + n))->r;
				}
				else
				{
					(pmat[i]+(m*MATRIX_SIZE + n))->r = mt_ldrand();
					(pmat[i]+(m*MATRIX_SIZE + n))->i = mt_ldrand();

					(pmat[i]+(n*MATRIX_SIZE + m))->r = (pmat[i]+(m*MATRIX_SIZE + n))->r;
					(pmat[i]+(n*MATRIX_SIZE + m))->i = -(pmat[i]+(m*MATRIX_SIZE + n))->i;
				}
			}
		}
		(pmat[i]+(MATRIX_SIZE-1)*MATRIX_SIZE + (MATRIX_SIZE-1))->r = -lastel;
		(pmat[i]+(MATRIX_SIZE-1)*MATRIX_SIZE + (MATRIX_SIZE-1))->i = 0.0;

	}

	return 0;
}
Example #2
0
/* n must be > 0 */
double rand_dbl(const double n) {
  assert(n == n);  /* check for NaN */
  assert(n > 0);
  assert(n <= DBL_MAX);  /* check for inf */
  double r = mt_ldrand() * n;
  return r;
}
int gen_randphicplxtrace(double pmat[], int MATRIX_SIZE, double mult)
{
	int m;

	for(m = 0; m < MATRIX_SIZE ; m++)
	{
		pmat[m] = mult*mt_ldrand()+1.0;
	}

	return 0;
}
int gen_randphicplx(double pmat[], int MATRIX_SIZE)
{
	int m;
	double lastel=0.0;

	for(m = 0; m < (MATRIX_SIZE-1) ; m++)
	{
		pmat[m] = mt_ldrand();
		lastel += pmat[m];
	}
	pmat[MATRIX_SIZE-1] = -lastel;

	return 0;
}
Example #5
0
int main(){
    //srand(42424242);
    mt_seed();
    int n = 10000;
    struct Particle particles[n];
    struct Force acc = {0.,0.,0.};

    for (int i = 0; i < n; ++i)
    {
        // particles[i].position.x = (double)rand() / (double)RAND_MAX ;
        // particles[i].position.y = (double)rand() / (double)RAND_MAX ;
        // particles[i].position.z = (double)rand() / (double)RAND_MAX ;
        // particles[i].velocity.x = (double)rand() / (double)RAND_MAX ;
        // particles[i].velocity.y = (double)rand() / (double)RAND_MAX ;
        // particles[i].velocity.z = (double)rand() / (double)RAND_MAX ;
        // particles[i].acceleration.x = 0.;
        // particles[i].acceleration.y = 0.;
        // particles[i].acceleration.z = 0.;
        particles[i].position.x = mt_ldrand()-.5;
        particles[i].position.y = mt_ldrand()-.5;
        particles[i].position.z = mt_ldrand()-.5;
        particles[i].velocity.x = mt_ldrand()-.5;
        particles[i].velocity.y = mt_ldrand()-.5;
        particles[i].velocity.z = mt_ldrand()-.5;
        particles[i].acceleration.x = 0.;
        particles[i].acceleration.y = 0.;
        particles[i].acceleration.z = 0.;
        particles[i].mass = mt_ldrand() ;
    }

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if(i!=j){
                calcforce(&particles[i], particles[j]);
            }
        }
    }

    for (int i = 0; i < n; ++i)
    {
        acc.x += particles[i].acceleration.x;
        acc.y += particles[i].acceleration.y;
        acc.z += particles[i].acceleration.z;
    }

    printf("%1.16e %1.16e %1.16e\n", acc.x, acc.y, acc.z);
}
Example #6
0
struct Particle* randomsystem(const int n){
    mt_seed32(42424242);
    struct Particle* particles;

    particles = (struct Particle *)malloc(n*sizeof(struct Particle));
    for (int i = 0; i < n; ++i)
    {
        particles[i].position.x = mt_ldrand()-.5;
        particles[i].position.y = mt_ldrand()-.5;
        particles[i].position.z = mt_ldrand()-.5;
        particles[i].velocity.x = mt_ldrand()-.5;
        particles[i].velocity.y = mt_ldrand()-.5;
        particles[i].velocity.z = mt_ldrand()-.5;
        particles[i].acceleration.x = 0.;
        particles[i].acceleration.y = 0.;
        particles[i].acceleration.z = 0.;
        particles[i].mass = mt_ldrand();
        // particles[i].mass = 1.;
    }
    printf("Setup done\n");

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if(i!=j){
                calculateForcePP(&particles[i], &particles[j]);
            }
        }
    }

    struct Force acc = {0.,0.,0.};
    for (int i = 0; i < n; ++i)
    {
        acc.x += particles[i].acceleration.x;
        acc.y += particles[i].acceleration.y;
        acc.z += particles[i].acceleration.z;
    }

    printf("%1.16e %1.16e %1.16e\n", acc.x, acc.y, acc.z);

    return particles;
}
Example #7
0
struct Particle* randomsystemtree(const int n){
    mt_seed32(42424242);
    struct Particle* particles;

    particles = (struct Particle *)malloc(n*sizeof(struct Particle));
    for (int i = 0; i < n; ++i)
    {
        particles[i].position.x = mt_ldrand()-.5;
        particles[i].position.y = mt_ldrand()-.5;
        particles[i].position.z = mt_ldrand()-.5;
        particles[i].velocity.x = mt_ldrand()-.5;
        particles[i].velocity.y = mt_ldrand()-.5;
        particles[i].velocity.z = mt_ldrand()-.5;
        particles[i].acceleration.x = 0.;
        particles[i].acceleration.y = 0.;
        particles[i].acceleration.z = 0.;
        particles[i].mass = mt_ldrand();
        // particles[i].mass = 1.;
    }

    struct Tree* tree = maketree(particles, n, .3);
    generateMultipole(tree->root);

    int interactions = 0;
    for (int i = 0; i < n; ++i)
    {
        interactions += calculateForcePN(&particles[i], tree->root);
    }
    printf("%d / %d\n", interactions, n*n);

    struct Force acc = {0.,0.,0.};
    for (int i = 0; i < n; ++i)
    {
        acc.x += particles[i].acceleration.x;
        acc.y += particles[i].acceleration.y;
        acc.z += particles[i].acceleration.z;
    }

    printf("%1.16e %1.16e %1.16e\n", acc.x, acc.y, acc.z);
    return particles;
}
Example #8
0
void display_map(coord * current, coord * prev, int colors[4], char * time, int ee){
    int i, col;
    chtype names[4][10]={{'B','l','u','e','b','e','l','l',0},{'G','r','e','e','n','l','e','e',0},{'F','r','e','d',0},{'G','r','e','y','d','o','n',0}};

    int color_options[]={BLUE_BLACK,GREEN_BLACK,RED_BLACK,WHITE_BLACK, MAGENTA_BLACK, DBLUE_BLACK};
    chtype * timech=strtoch(time);
    add_chstring(4, MAP_SIZE+6,timech,YELLOW_BLACK,1);
    update_score(names,colors, current, color_options);
    free(timech);
    if (prev[0].x==prev[1].x && prev[0].x==0){
        for (i=0;i<4;i++) {
            if (current[i].x==-1) continue;
            col=color_options[(ee)?(int)(rintl((mt_ldrand() * 5))):colors[i]];
            switch (current[i].dir) {
                case 0:
                    mvaddch(current[i].x + OFFX+1, current[i].y + OFFY, ACS_VLINE | COLOR_PAIR(col) | A_BOLD);
                    mvaddch(current[i].x + OFFX, current[i].y + OFFY, ACS_DIAMOND | COLOR_PAIR((ee)?color_options[(int)(rintl((mt_ldrand() * 5)))]:3) | A_BOLD);
                    break;
                case 1:
                    mvaddch(current[i].x + OFFX, current[i].y + OFFY-1, ACS_HLINE | COLOR_PAIR(col) | A_BOLD);
                    mvaddch(current[i].x + OFFX, current[i].y + OFFY, ACS_DIAMOND | COLOR_PAIR((ee)?color_options[(int)(rintl((mt_ldrand() * 5)))]:3) | A_BOLD);
                    break;
                case 2:
                    mvaddch(current[i].x + OFFX-1, current[i].y + OFFY, ACS_VLINE | COLOR_PAIR(col) | A_BOLD);
                    mvaddch(current[i].x + OFFX, current[i].y + OFFY, ACS_DIAMOND | COLOR_PAIR((ee)?color_options[(int)(rintl((mt_ldrand() * 5)))]:3) | A_BOLD);
                    break;
                case 3:
                    mvaddch(current[i].x + OFFX, current[i].y + OFFY+1, ACS_HLINE | COLOR_PAIR(col) | A_BOLD);
                    mvaddch(current[i].x + OFFX, current[i].y + OFFY, ACS_DIAMOND | COLOR_PAIR((ee)?color_options[(int)(rintl((mt_ldrand() * 5)))]:3) | A_BOLD);
                    break;
                default:
                    break;
            }
            refresh();
        }
    }
    else{
        chtype next=ACS_DIAMOND;
        for(i=0;i<4;i++){
            if (current[i].x==-1) continue;
            int a=(int)(rintl((mt_ldrand() * 4)));
            col=color_options[(ee)?a : colors[i]];
            if (prev[i].blank!=1) switch(current[i].dir){
                    case 0:{
                        switch(prev[i].dir){
                            case 0: next=ACS_VLINE; break;
                            case 1: next=ACS_LRCORNER; break;
                            case 3: next=ACS_LLCORNER; break;
                            default: exit(462);
                        }
                        break;
                    }
                    case 1:{
                        switch(prev[i].dir){
                            case 0: next=ACS_ULCORNER; break;
                            case 1: next=ACS_HLINE; break;
                            case 2: next=ACS_LLCORNER; break;
                            default: exit(462);
                        }
                        break;
                    }
                    case 2:{
                        switch(prev[i].dir){
                            case 1: next=ACS_URCORNER; break;
                            case 2: next=ACS_VLINE; break;
                            case 3: next=ACS_ULCORNER; break;
                            default: exit(462);
                        }
                        break;
                    }
                    case 3:{
                        switch(prev[i].dir){
                            case 0: next=ACS_URCORNER; break;
                            case 2: next=ACS_LRCORNER; break;
                            case 3: next=ACS_HLINE; break;
                            default: exit(462);
                        }
                        break;
                        default: exit(462);
                    }
                }
            if (prev[i].blank!=1) mvaddch(prev[i].x+OFFX, prev[i].y+OFFY, next|COLOR_PAIR(col)|A_BOLD);
            else mvaddch(prev[i].x+OFFX, prev[i].y+OFFY, ' '|COLOR_PAIR(col)|A_BOLD);
            mvaddch(current[i].x+OFFX,current[i].y+OFFX,ACS_DIAMOND|COLOR_PAIR((ee)?color_options[(int)(rintl((mt_ldrand() * 5)) + 1)]:3)|A_BOLD);


        }
    }
    refresh();
}
Example #9
0
/* n must be > 0 and <= RAND_MAX+1 */
int rand_int(const unsigned n) {  /* from C FAQ */
  assert(n > 0);
  assert(n <= RAND_MAX + 1u);
  unsigned r = mt_ldrand() * n;
  return r;
}
Example #10
0
/* Uses program-wide state. */
double drand_mt() {
  return mt_ldrand();
}