Example #1
0
int main(int argc, char** argv)
{
	gridInit(g);							// Initialize the grid
	ezIncInit(g);							// Initialize the sources
	initializeGlobalDevicePointers();		// Initialize all global dev pointers to zero

	runFdtdWithFieldDisplay(argc, argv);

	
}
Example #2
0
int main(int argc, const char * argv[]) {
	unsigned int width = DEFAULT_WIDTH;
	unsigned int workGroupSize = DEFAULT_WORK_GROUP_SIZE;
	unsigned int iterations = DEFAULT_NUM_ITERATIONS;
	int opt;
	bool printResult = false;
	
	while((opt = getopt(argc, (char * const *)argv, "s:w:i:p")) != -1) {
		switch(opt) {
			case 's':
				width = atoi(optarg);
				break;
			case 'w':
				workGroupSize = atoi(optarg);
				break;
			case 'i':
				iterations = atoi(optarg);
				break;
			case 'p':
				printResult = true;
				break;
			default:
				break;
		}
	}
	
	int gridLength = width * width;
	size_t gridSize = gridLength * sizeof(float);

	//OpenCL only supports float by default
	float *grid = malloc(gridSize);
	
	gridInit(grid, width);

	execute(grid, gridSize, width, workGroupSize, iterations, printResult);	

	if(printResult) {
		for(int i = 0; i < width; i++) {
			for(int j = 0; j < width; j++) {
				printf("%8.3f,", grid[getIndex(j, i, width)]);
			}
			printf("\n");
		}
		printf("\n");
	}
	
	free(grid);
	
    return 0;
}
Example #3
0
int main() {
	// Create a drawing grid
	struct winsize terminal;
	ioctl(STDOUT_FILENO, TIOCGWINSZ, &terminal);
	int		w = terminal.ws_col,
			h = terminal.ws_row - 1;

	Grid grid = gridInit(w, h);

	Vector v1 = vectorMake(20, 0, 0);
	Vector v2 = vectorMake(0, 10, 0);
	Vector center = vectorMake((int)w/2, (int)h, 0);
	Vector zero = vectorMake(0, 0, 0);

	Vector v3 = vectorSubtract(v1, v2);

	// A mechanism for delay between draws
	struct timespec t;
	t.tv_sec = 0; //1;
	t.tv_nsec = 1000 * 1000 * 100;

	// Rotation
	int		degrees = 0,
			x = 0,
			y = 0,
			z = 0;
	double	radians;
	Vector	v4;

	int test = 1;
	while (test) {
		// Calculations
		v4 = vectorRotate(v1, degrees);
		degrees += 6;
		// Erase the grid
		//grid = gridInit(w, h);

		// Draw a vector
		drawVectorAtOrigin(v4, center, grid);

		// Flush grid to the terminal
		gridDraw(grid);

		//v1.y++;

		nanosleep(&t, NULL);
	}

	return 0;
}
Example #4
0
void wdResetGrid(World* W)
{
	gridFree(&W->CollisionGrid);
	float CellSize=128.f;
	gridInit(&W->CollisionGrid, W->Width/CellSize+1, W->Height/CellSize+1);
	gridSetCellSize(&W->CollisionGrid, CellSize);

	Node* it = lstFirst(&W->Polygons);
	while(!nodeEnd(it))
	{
		gridAddPolygonByBB(&W->CollisionGrid, (Polygon*)nodeGetData(it));

		it=nodeGetNext(it);
	}
}
Example #5
0
void wdInit(World* W, float Width, float Height)
{
	lstInit(&W->Vertices);
	lstInit(&W->Elastics);
	lstInit(&W->Rigids);
	lstInit(&W->Polygons);

	W->Width = Width;
	W->Height = Height;
	W->prevdt = 0.5f;
	W->dt = 0.5f;
	float CellSize=128.f;
	gridInit(&W->CollisionGrid, Width/CellSize+1, Height/CellSize+1);
	gridSetCellSize(&W->CollisionGrid, CellSize);
}
Example #6
0
int main()
{
	Grid *g;
	ALLOC_1D(g, 1, Grid); // allocate memory for Grid
	gridInit(g); // initialize the grid
	ezIncInit(g);
	snapshotInit2d(g); // initialize snapshots

	/* do time stepping */
	for (Time = 0; Time < MaxTime; Time++) {
		updateH2d(g); // update magnetic field
		updateE2d(g); // update electric field
		Ez(SizeX / 2, SizeY / 2) = ezInc(Time, 0.0); // add a source
		snapshot2d(g); // take a snapshot (if appropriate)
	} // end of time-stepping
	
	return 0;

}
Example #7
0
int main()
{
	Grid *g;

	g = (Grid *)calloc(1, sizeof(Grid));
	gridInit(g);	// initialize 2D grid

	abcInit(g);	// initialize ABC
	tfsfInit(g);	// initialize TFSF boundary
	snapshotInit2d(g);	// initialize snapshots

	/* do time stepping */
	for (Time = 0; Time < MaxTime; Time++) {
		updateH2d(g);	// update magnetic fields
		tfsfUpdate(g);	// apply TFSF boundary
		updateE2d(g);	// update electric fields
		abc(g);	// apply ABC
		snapshot2d(g);	// take a snapshot (if appropriate)
	} // end of time-stepping

	return 0;
}
Example #8
0
int main()
{
  Grid *g;

  ALLOC_1D(g, 1, Grid);  // allocate memory for Grid

  gridInit(g);         // initialize the grid
  abcInit(g);          // initialize ABC  /*@ \label{abcdemo1A} @*/
  tfsfInit(g);         // initialize TFSF boundary
  snapshotInit(g);     // initialize snapshots

  /* do time stepping */
  for (Time = 0; Time < MaxTime; Time++) {

    updateH3(g);   // update magnetic field
    tfsfUpdate(g); // correct field on TFSF boundary
    updateE3(g);   // update electric field
/*b*/    abc(g);/*n*/         // apply ABC -- after E-field update/*@ \label{abcdemo1B} @*/
    snapshot(g);   // take a snapshot (if appropriate)

  } /* end of time-stepping */

  return 0;
}
Example #9
0
int main(void)
{
	unsigned char temp_sqr,temp_dir,temp_diff,temp;
	unsigned int i;
	unsigned char channel=150;
	hardwareInit();
	//FOLD_ARMS;
	/*__delay_ms(50);
	do{
		if(key_UP)
		{
			channel+=10;
			LED_ON;
			__delay_ms(20);
			LED_OFF;
		}
		if(key_DN)
		{
			channel-=10;
			LED_ON;
			__delay_ms(20);
			LED_OFF;
		}
		__delay_ms(300);
		readButtons();
	}	while(!key_GO);
	LED_ON;
	__delay_ms(200);
	LED_OFF;
	CC2500_init();
	CC2500_write_register(CHANNR,channel);
	CC2500_idle_mode();
	CC2500_receive_mode();
	do{
		if(key_UP)
		{
			speed++;
			if(speed>4)
				speed = 4;
			LED_ON;
			__delay_ms(20);
			LED_OFF;
		}
		if(key_DN)
		{
			speed--;
			if(speed<0)
				speed = 0;
			LED_ON;
			__delay_ms(20);
			LED_OFF;
		}
		__delay_ms(300);
		readButtons();
	}while(!key_GO);*/
	LED_ON;
	__delay_ms(150);
	LED_OFF;
	__delay_ms(150);
	LED_ON;
	__delay_ms(150);
	LED_OFF;
	
	#ifdef MACHINE_A
		statusInitA();
	#endif
	#ifdef MACHINE_B
		statusInitB();
	#endif
	assamble_packet();
	CC2500_idle_mode();
	CC2500_clear_rx_fifo();
	CC2500_clear_tx_fifo();
	CC2500_receive_mode();
	__delay_ms(100);
	i = CC2500_read_status_register( RXBYTES);
	i&=0xFF;
	sprintf(outBuf,"\r\n%u\r\n",i);
	putsUART(outBuf);
	if(i)
	{
		CC2500_idle_mode();
		CC2500_clear_rx_fifo();
		CC2500_clear_tx_fifo();
		CC2500_receive_mode();
		while(GDO0==0);
		while(GDO0==1);
		SYSTIM_TMR = 9581;
		__delay_ms(3);
		commCount = 0;
		startSystemTimer();
		noCommCount=0;
		commEnabled = TRUE;
		if(waitDataUpdate())
			my.obzEntrCnt = fellow.obzEntrCnt;
		/*LED_ON;
		__delay_ms(2000);*/
		
	}
	else
	{
		startSystemTimer();
		noCommCount=0;
		commEnabled = TRUE;
	}
	#ifdef MACHINE_A
	while(!key_GO){
		if(noCommCount>100)
		{
			commEnabled = FALSE;
			waitToTick();
			CC2500_init();
			commEnabled = TRUE;
			__delay_ms(40);
			//noCommCount = 0;
		}
	}
	#endif

	if(displayEnabled)
	{
		switch(resetSource())
		{
			case POWER_ON_RESET:
				sprintf(outBuf,"\r\nBattry Voltage : %u",batteryVoltage);
				putsUART(outBuf);
				break;
			
			case EXTERNAL_RESET:
				sprintf(outBuf,"\r\nUser Reset...");
				putsUART(outBuf);
				break;
			
			default:
				sprintf(outBuf,"\r\nUnknown Reset");
				putsUART(outBuf);
				break;
		}
	}
	/*while(TRUE)
	{
		printSensors();
		__delay_ms(500);
	}*/
	
	gridInit();
	#ifdef MACHINE_B
	while(TRUE)
	{
		if(noCommCount>100)
		{
			commEnabled = FALSE;
			waitToTick();
			CC2500_init();
			commEnabled = TRUE;
			__delay_ms(40);
			//noCommCount = 0;
		}
		if(dataUpdated)
		{
			printStatus(&fellow);
			/*rx_buff_temp[0] = rx_buff0;
			rx_buff_temp[1] = rx_buff1;
			rx_buff_temp[2] = rx_buff2;
			rx_buff_temp[3] = rx_buff3;
			rx_buff_temp[4] = rx_buff4;
			rx_buff_temp[5] = rx_buff5;
			sprintf(outBuf,"\r\n\r\n%u,%u,%u,%u,%u,%u",
												rx_buff_temp[0],
												rx_buff_temp[1],
												rx_buff_temp[2],
												rx_buff_temp[3],
												rx_buff_temp[4],
												rx_buff_temp[5]);
			putsUART(outBuf);*/
			dataUpdated = FALSE;
		}		
	}
	//while(!key_GO);
	while(fellow.heading==10&&!key_GO);
	//while(fellow.heading==10);
	#endif
	
	while(TRUE)
	{
		if(noCommCount>100)
		{
			commEnabled = FALSE;
			waitToTick();
			CC2500_init();
			commEnabled = TRUE;
			__delay_ms(40);
			//noCommCount = 0;
		}
		switch(mcState)
		{
			case MC_START:
			{
				cubeSensorsOn();
				waitToTick();
				waitToTick();
				cubeSensorsOff();
				temp_sqr = nextSquare(my.location,my.heading&0x07);
				grid[temp_sqr] |= VISITED;
				if(frontCube)
				{
					myCube[++cubeInd] = temp_sqr;
					mcState=MC_DELIVER;
				}
				else
					mcState=MC_SCAN;
				break;
			}
			case MC_SCAN:
			{
				temp_sqr = scanMap[my.smInd];
				if(my.location==temp_sqr)
				{
					my.smInd++;
					break;
				}
				my.goalSquare = temp_sqr;
				mcNextState = MC_SCAN;
				mcState = MC_GET_M_THR;
				/*temp_dir = nextDirection(my.location,temp_sqr);
				temp_diff = temp_dir - (my.heading&0x07);
					
				if(prState==PR_STR_ACC||prState==PR_STR_DEC)
				{
					if(temp_diff)
						break;
					waitDataUpdate();
					if(commonSquare(temp_sqr))
						break;
					my.heading &= 0x07;
					finalPos += COUNTS_PER_CELL*256;
					if(prState==PR_STR_DEC)
						prState = PR_STR_ACC;
					while(relativeDistance>distance[ORTHO_SENS_DIST]*2);
				}
				else if(prState==PR_FINISHED)
				{
					if(temp_diff)
					{
						commandList[cmlInd++] = getTurnCmd(temp_diff);
						my.heading = temp_dir | NODIR;
					}
					waitDataUpdate();
					if(commonSquare(temp_sqr))
					{
						commandList[cmlInd++] = CMD_STOP;
						getNextMove();
						break;
					}
					my.heading &= 0x07;
					commandList[cmlInd++] = CMD_STRAIGHT | CMD_FORWARD;
					commandList[cmlInd++] = CMD_STOP;
					getNextMove();
				}
				else
					break;
				while(prState!=PR_STR_ACC);
				while(relativeDistance<distance[ORTHO_SENS_DIST]*2);
				my.location = nextSquare(my.location,my.heading);
				grid[my.location] |= ONROUTE;
				my.heading |= NODIR;
				if(scanNeighbours())
				{
					mcState = MC_DELIVER;
				}*/
				my.smInd++;
				if(my.smInd>=17)
				{
					my.smInd = 0;
					#ifdef MACHINE_A
					my.goalSquare = 20;
					#endif
					#ifdef MACHINE_B
					my.goalSquare = 60;
					#endif
					mcNextState = MC_SCAN;
					mcState = MC_GET_M_THR;
				}
			break;
			}
			case MC_GET_M_THR:
			{
				waitDataUpdate();
				updateGrid();
				floodGrid(my.goalSquare);
				/*if(map[my.location] == 0)
				{
					mcState = mcNextState;
					break;
				}*/
				temp_sqr = nextNeighbour(my.location);
				temp_dir = nextDirection(my.location,temp_sqr);
				temp_diff = temp_dir - (my.heading&0x07);
				waitDataUpdate();
				if(commonSquare(temp_sqr))
				{
					break;
				}
				if((!inOBZ(my.location)) && inOBZ(temp_sqr))
				{
					if(!my.obzClear || !my.delivering)
						break;

				}
				if(inOBZ(my.location) && (!inOBZ(temp_sqr)))
				{
					my.obzEntrCnt+=2;
				}
				if(isDipoSquare(temp_sqr)&& my.delivering)
				{
					mcState = MC_DELIVER_FINISH;
					break;
				}
				if(prState==PR_STR_ACC||prState==PR_STR_DEC)
				{
					if(temp_diff)
						break;
					my.heading &= 0x07;
					finalPos += COUNTS_PER_CELL*256;
					if(prState==PR_STR_DEC)
						prState = PR_STR_ACC;
					while(relativeDistance>distance[ORTHO_SENS_DIST]*2);
				}
				else if(prState==PR_FINISHED)
				{
					if(temp_diff)
					{
						commandList[cmlInd++] = getTurnCmd(temp_diff);
						commandList[cmlInd++] = CMD_STOP;
						getNextMove();
						my.heading = temp_dir|NODIR;
						break;
					}
					else
					{
						if(!(grid[temp_sqr]&VISITED));
						{
							cubeSensorsOn();
							waitToTick();
							waitToTick();
							cubeSensorsOff();
							if(!commonSquare(temp_sqr))
							{
								grid[temp_sqr] |= VISITED;
								if(frontCube)
								{
									updateCube(temp_sqr);
									break;
								}
							}
						}
						my.heading &= 0x07;
						commandList[cmlInd++] = CMD_STRAIGHT | CMD_FORWARD;
						commandList[cmlInd++] = CMD_STOP;
						getNextMove();
					}
				}
				else
					break;
				while(prState!=PR_STR_ACC);
				while(relativeDistance<distance[ORTHO_SENS_DIST]*2);
				my.location = nextSquare(my.location,my.heading);
				grid[my.location] |= ONROUTE;
				my.heading |= NODIR;
				if(scanNeighbours()&&(my.delivering==FALSE))
				{
					mcState = MC_DELIVER;
					break;
				}
				if(map[my.location] == 0)
					mcState = mcNextState;
				break;
			}
			case MC_DELIVER:
			{
				temp_sqr = unDipoCube();
				if(temp_sqr)
				{
					waitDataUpdate();
					if(inOBZ(temp_sqr)&&!my.obzClear)
						break;
					temp_dir = nextDirection(my.location,temp_sqr);
					if(temp_dir==NODIR)
					{
						temp_sqr = nearestNeighbourOfCube();
						if(temp_sqr)
						{
							my.goalSquare = temp_sqr;
							mcNextState = MC_DELIVER;
							mcState = MC_GET_M_THR;
						}
						else
						{
							do{
								my.smInd++;
							}while(grid[scanMap[my.smInd]]&ONROUTE);
							my.goalSquare = scanMap[my.smInd];
							mcNextState = MC_SCAN;
							mcState = MC_GET_M_THR;
						}
						break;
					}
					else
					{
						grabCube(temp_dir);
						if(my.delivering)
						{
							temp = temp_sqr;
							my.goalSquare = my.location;
							temp_sqr = getDipoSquare();
							if(temp_sqr)
							{
								for(i=0; i<4; i++)
								{
									if((myCube[i]<81)&&myCube[i]==temp)
										temp = i;
								}
								
								myCube[/*cubeIndForMcDeliver*/temp] = temp_sqr;
								my.goalSquare = temp_sqr;
								mcNextState = MC_DELIVER;
								mcState = MC_GET_M_THR;
								break;
							}
						}
					}
					break;
				}
				do{
					my.smInd++;
				}while(grid[scanMap[my.smInd]]&ONROUTE);
				my.goalSquare = scanMap[my.smInd];
				mcNextState = MC_SCAN;
				mcState = MC_GET_M_THR;
				break;
			}
			case MC_DELIVER_FINISH:
			{
				deliverCube();
				if(unDipoCube())
				{
					mcState = MC_DELIVER;
					break;
				}
				do{
					my.smInd++;
				}while(grid[scanMap[my.smInd]]&ONROUTE);
				my.goalSquare = scanMap[my.smInd];
				mcNextState = MC_SCAN;
				mcState = MC_GET_M_THR;
			}
		}
	}	
	while(TRUE);
	return 0;
}