コード例 #1
0
ファイル: SWE_Block.cpp プロジェクト: dianagudu/SWE
/**
 * Initializes the unknowns and bathymetry in all grid cells according to the given SWE_Scenario.
 *
 * In the case of multiple SWE_Blocks at this point, it is not clear how the boundary conditions
 * should be set. This is because an isolated SWE_Block doesn't have any in information about the grid.
 * Therefore the calling routine, which has the information about multiple blocks, has to take care about setting
 * the right boundary conditions.
 * 
 * @param i_scenario scenario, which is used during the setup.
 * @param i_multipleBlocks are the multiple SWE_blocks?
 */
void SWE_Block::initScenario(	SWE_Scenario &i_scenario,
									const bool i_multipleBlocks ) {

  // initialize water height and discharge
  for(int i=nghosts; i<nx+nghosts; i++)
    for(int j=nghosts; j<ny+nghosts; j++) {
      float x = offsetX + (i-nghosts+0.5f)*dx;
      float y = offsetY + (j-nghosts+0.5f)*dy;
      h[i][j] =  i_scenario.getWaterHeight(x,y);
      hu[i][j] = i_scenario.getVeloc_u(x,y) * h[i][j];
      hv[i][j] = i_scenario.getVeloc_v(x,y) * h[i][j];
    };

  // initialise bathymetry
  for(int i=0; i<nx+2*nghosts; i++) {
    for(int j=0; j<ny+2*nghosts; j++) {
      b[i][j] = i_scenario.getBathymetry(offsetX + (i-nghosts+0.5f)*dx,
                                    	 offsetY + (j-nghosts+0.5f)*dy );
    }
  }

  // in the case of multiple blocks the calling routine takes care about proper boundary conditions.
  if (i_multipleBlocks == false) {
	// obtain boundary conditions for all four edges from scenario
	setBoundaryType(BND_LEFT, i_scenario.getBoundaryType(BND_LEFT));
	setBoundaryType(BND_RIGHT, i_scenario.getBoundaryType(BND_RIGHT));
	setBoundaryType(BND_BOTTOM, i_scenario.getBoundaryType(BND_BOTTOM));
	setBoundaryType(BND_TOP, i_scenario.getBoundaryType(BND_TOP));
  }

  // perform update after external write to variables
  synchAfterWrite();

}
コード例 #2
0
ファイル: controller.cpp プロジェクト: dianagudu/SWE
/**
    Process single keyboard event
	@param *keysym			pointer to the sdl keyevent structure

*/	
bool Controller::handleKeyPress( SDL_keysym *keysym) {

	switch ( keysym->sym ) {
		case SDLK_ESCAPE:
			// ESC key was pressed -> exit
			return true;
			break;
		case SDLK_r:
			// Restart simulation
			allowStep = paused;
			simulation->restart();
			break;
		case SDLK_w:
			// Switch rendering mode
			visualization->toggleRenderingMode();
			break;
		case SDLK_s:
			// Save simulation data to file
			simulation->saveToFile();
			break;
		case SDLK_RIGHT:
			// Advance single timestep when paused
			allowStep = paused;
			break;
		case SDLK_SPACE:
			// Pause/Resume
			paused = !paused;
			break;
		case SDLK_1:
			// Load scenario 1
			{
			  allowStep = paused;
                          SWE_RadialDamBreakScenarioVisInfo* 
                            newScene = new SWE_RadialDamBreakScenarioVisInfo();
			  SWE_VisInfo* visInfo = newScene;

			  // define grid size and initial time step
			  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
			  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
			  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

			  simulation->loadNewScenario(newScene, visInfo);
			  visualization->updateBathymetryVBO(simulation);
			}
			break;
		case SDLK_2:
			// Load scenario 2
			{
			  allowStep = paused;
			  SWE_Scenario* newScene = new SWE_BathymetryDamBreakScenario;
			  // define grid size and initial time step
			  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
			  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
			  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

			  simulation->loadNewScenario(newScene, NULL);
			  visualization->updateBathymetryVBO(simulation);
			}
			break;
		case SDLK_3:
			// Load scenario 3
			{
			  allowStep = paused;
			  SWE_SplashingPoolScenarioVisInfo* 
                            newScene = new SWE_SplashingPoolScenarioVisInfo;

			  // define grid size and initial time step
			  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
			  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
			  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

			  simulation->loadNewScenario(newScene, newScene);
			  visualization->updateBathymetryVBO(simulation);
			}
			break;
		default:
			break;
	}
	return false;
}
コード例 #3
0
/**
    Process single keyboard event
	@param *keysym			pointer to the sdl keyevent structure

	@todo Refector!!

*/	
bool Controller::handleKeyPress( SDL_keysym *keysym) {

	switch ( keysym->sym ) {
		case SDLK_ESCAPE:
			// ESC key was pressed -> exit
			return true;
			break;
		case SDLK_r:
			// Restart simulation
			allowStep = paused;
			simulation->restart();
			break;
		case SDLK_w:
			// Switch rendering mode
			visualization->toggleRenderingMode();
			break;
		case SDLK_s:
			// Save simulation data to file
			simulation->saveToFile();
			break;
		case SDLK_RIGHT:
			// Advance single timestep when paused
			allowStep = paused;
			break;
		case SDLK_SPACE:
			// Pause/Resume
			paused = !paused;
			break;
		case SDLK_PLUS:
			// Increase water scaling
			visualization->modifyWaterScaling(1.5);
			break;
		case SDLK_MINUS:
			// Decrease water scaling
			visualization->modifyWaterScaling(1/1.5);
			break;
		case SDLK_1:
			// Load scenario 1
			{
			  allowStep = paused;

			  if (scenarios[0] == 0)
				  scenarios[0] = new SWE_RadialDamBreakScenario;

			  SWE_Scenario* newScene = scenarios[0];

			  // define grid size and initial time step
			  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
			  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
			  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

			  simulation->loadNewScenario(newScene);
			  visualization->init(*simulation);
			}
			break;
		case SDLK_2:
			// Load scenario 2
			{
			  allowStep = paused;

			  if (scenarios[1] == 0) {
				  scenarios[1] = new SWE_BathymetryDamBreakScenario();
				  visInfos[1] = new SWE_BathymetryDamBreakVisInfo();
			  }

			  SWE_Scenario* newScene = scenarios[1];

			  // define grid size and initial time step
			  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
			  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
			  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

			  simulation->loadNewScenario(newScene);
			  visualization->init(*simulation, visInfos[1]);
			}
			break;
		case SDLK_3:
			// Load scenario 3
			{
			  allowStep = paused;

			  if (scenarios[2] == 0)
				  scenarios[2] = new SWE_SplashingPoolScenario();

			  SWE_Scenario* newScene = scenarios[2];

			  // define grid size and initial time step
			  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
			  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
			  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

			  simulation->loadNewScenario(newScene);
			  visualization->init(*simulation);
			}
			break;
#ifdef ASAGI
		case SDLK_4:
			// Load scenario 4
			{
				allowStep = paused;

				if (scenarios[3] == 0) {
					//simulation area
					float simulationArea[4];
					simulationArea[0] = -450000;
					simulationArea[1] = 6450000;
					simulationArea[2] = -2450000;
					simulationArea[3] = 1450000;
					scenarios[3] = new SWE_AsagiScenario(
							ASAGI_INPUT_DIR "tohoku_gebco_ucsb3_500m_hawaii_bath.nc",
				            ASAGI_INPUT_DIR "tohoku_gebco_ucsb3_500m_hawaii_displ.nc",
				            (float) 28800., simulationArea);
				}

				SWE_Scenario* newScene = scenarios[3];

				  // define grid size and initial time step
				  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
				  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
				  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

				  simulation->loadNewScenario(newScene);
				  visualization->init(*simulation);
			}
			break;
		case SDLK_5:
			// Load scenario 5
			{
				allowStep = paused;

				if (scenarios[4] == 0) {
					//simulation area
					float simulationArea[4];
					simulationArea[0] = -450000;
					simulationArea[1] = 700000;
					simulationArea[2] = -1000000;
					simulationArea[3] = 1450000;
					scenarios[4] = new SWE_AsagiScenario(
							ASAGI_INPUT_DIR "tohoku_gebco_ucsb3_500m_hawaii_bath.nc",
				            ASAGI_INPUT_DIR "tohoku_gebco_ucsb3_500m_hawaii_displ.nc",
				            (float) 28800., simulationArea);

					visInfos[4] = new SWE_AsagiJapanSmallVisInfo();
				}

				SWE_Scenario* newScene = scenarios[4];

				  // define grid size and initial time step
				  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
				  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
				  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

				  simulation->loadNewScenario(newScene);
				  visualization->init(*simulation, visInfos[4]);
			}
			break;
		case SDLK_6:
			// Load scenario 6
			{
				allowStep = paused;

				if (scenarios[5] == 0) {
					//simulation area
					float simulationArea[4];
					simulationArea[0] = -13775000;
					simulationArea[1] = 1655000;
					simulationArea[2] = -2765000;
					simulationArea[3] = 8870000;
					scenarios[5] = new SWE_AsagiScenario(
							ASAGI_INPUT_DIR "chile_gebco_usgs_500m_bath.nc",
				            ASAGI_INPUT_DIR "chile_gebco_usgs_500m_displ.nc",
				            (float) 28800., simulationArea);
				}

				SWE_Scenario* newScene = scenarios[5];

				  // define grid size and initial time step
				  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
				  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
				  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

				  simulation->loadNewScenario(newScene);
				  visualization->init(*simulation);
			}
			break;
		case SDLK_7:
			// Load scenario 7
			{
				allowStep = paused;

				if (scenarios[6] == 0) {
					//simulation area
					float simulationArea[4];
					simulationArea[0] = -2275000;
					simulationArea[1] = 1655000;
					simulationArea[2] = -2265000;
					simulationArea[3] = 1870000;
					scenarios[6] = new SWE_AsagiScenario(
							ASAGI_INPUT_DIR "chile_gebco_usgs_500m_bath.nc",
				            ASAGI_INPUT_DIR "chile_gebco_usgs_500m_displ.nc",
				            (float) 28800., simulationArea);
				}

				SWE_Scenario* newScene = scenarios[6];

				  // define grid size and initial time step
				  float dx = (newScene->getBoundaryPos(BND_RIGHT) - newScene->getBoundaryPos(BND_LEFT) )/SWE_Block::getNx();
				  float dy = (newScene->getBoundaryPos(BND_TOP) - newScene->getBoundaryPos(BND_BOTTOM) )/SWE_Block::getNy();
				  SWE_Block::initGridData(SWE_Block::getNx(),SWE_Block::getNy(),dx,dy);

				  simulation->loadNewScenario(newScene);
				  visualization->init(*simulation);
			}
			break;
#endif // ASAGI
		default:
			break;
	}
	return false;
}