Let asagi scenarios share grid data

Link agains libGL
parent 243d2bfa
...@@ -214,7 +214,7 @@ if env['parallelization'] in ['mpi_with_cuda', 'mpi']: ...@@ -214,7 +214,7 @@ if env['parallelization'] in ['mpi_with_cuda', 'mpi']:
env['LINKERFORPROGRAMS'] = 'mpiCC' env['LINKERFORPROGRAMS'] = 'mpiCC'
if env['openGL'] == True: if env['openGL'] == True:
env.Append(LIBS=['SDL', 'GLU']) env.Append(LIBS=['SDL', 'GL', 'GLU'])
# set the compiler flags for libSDL # set the compiler flags for libSDL
if 'libSDLDir' in env: if 'libSDLDir' in env:
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# This file is part of SWE. # This file is part of SWE.
# #
# @author Alexander Breuer (breuera AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer) # @author Alexander Breuer (breuera AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer)
# @author Sebastian Rettenberger (rettenbs AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc.)
# #
# @section LICENSE # @section LICENSE
# #
...@@ -66,6 +67,10 @@ if env['openGL'] == True: ...@@ -66,6 +67,10 @@ if env['openGL'] == True:
sourceFiles.append( ['opengl/shader.cpp'] ) sourceFiles.append( ['opengl/shader.cpp'] )
sourceFiles.append( ['opengl/visualization.cpp'] ) sourceFiles.append( ['opengl/visualization.cpp'] )
# Asagi scenario
if env['asagi'] == True:
sourceFiles.append( ['scenarios/SWE_AsagiScenario.cpp'] )
# netCDF writer # netCDF writer
if env['writeNetCDF'] == True: if env['writeNetCDF'] == True:
sourceFiles.append( ['tools/NetCdfWriter.cpp'] ) sourceFiles.append( ['tools/NetCdfWriter.cpp'] )
......
/**
* @file
* This file is part of SWE.
*
* @author Sebastian Rettenberger (rettenbs AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc.)
*
* @section LICENSE
*
* SWE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SWE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SWE. If not, see <http://www.gnu.org/licenses/>.
*/
#include "SWE_AsagiScenario.hpp"
std::map<std::string, SWE_AsagiGrid> SWE_AsagiScenario::grids;
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
* This file is part of SWE. * This file is part of SWE.
* *
* @author Alexander Breuer (breuera AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer) * @author Alexander Breuer (breuera AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer)
* @author Sebastian Rettenberger (rettenbs AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc.)
* *
* @section LICENSE * @section LICENSE
* *
...@@ -30,16 +31,71 @@ ...@@ -30,16 +31,71 @@
#include <cassert> #include <cassert>
#include <string> #include <string>
#include <iostream>
#include <map>
#include <asagi.h> #include <asagi.h>
#include "SWE_Scenario.h" #include "SWE_Scenario.h"
class SWE_AsagiGrid
{
private:
/** Pointer to the grid in ASAGI */
asagi::Grid* _grid;
/** Number of scenarios that use this grid */
unsigned int _refCount;
public:
SWE_AsagiGrid()
{
_grid = asagi::Grid::create();
_refCount = 0;
}
void open(const std::string &i_filename)
{
_refCount++;
if (_refCount > 1)
return;
int l_asagiOpen = _grid->open(i_filename.c_str());
//open the grid
if( l_asagiOpen != 0 ) {
std::cout << "Could not open bathymetry file: " << i_filename << std::endl;
std::cout << "Error code: " << l_asagiOpen << std::endl;
assert(false);
}
}
void close()
{
_refCount--;
if (_refCount > 0)
// At least one more scenario is using this grid
// -> do nothing
return;
// This grid is no longer used
delete _grid;
}
asagi::Grid& grid()
{
return *_grid;
}
};
class SWE_AsagiScenario: public SWE_Scenario { class SWE_AsagiScenario: public SWE_Scenario {
//private: //private:
//! pointer to the Asagi bathymetry grid /** All Asagi grids */
asagi::Grid* bathymetryGrid; static std::map<std::string, SWE_AsagiGrid> grids;
//! the bathymetry grid
SWE_AsagiGrid &bathymetryGrid;
//! pointer the the Asagi displacement grid //! the displacement grid
asagi::Grid* displacementGrid; SWE_AsagiGrid &displacementGrid;
//! flag whether the displacement is dynamic or static //! flag whether the displacement is dynamic or static
const bool dynamicDisplacement; const bool dynamicDisplacement;
...@@ -77,46 +133,35 @@ class SWE_AsagiScenario: public SWE_Scenario { ...@@ -77,46 +133,35 @@ class SWE_AsagiScenario: public SWE_Scenario {
const float i_simulationArea[4], const float i_simulationArea[4],
const bool i_dynamicDisplacement = false ): const bool i_dynamicDisplacement = false ):
dynamicDisplacement(i_dynamicDisplacement), dynamicDisplacement(i_dynamicDisplacement),
duration(i_duration) { duration(i_duration),
//create the bathymetry grid bathymetryGrid(grids[i_bathymetryFile]),
bathymetryGrid = asagi::Grid::create( asagi::Grid::FLOAT ); displacementGrid(grids[i_displacementFile])
//create the displacement grid {
displacementGrid = asagi::Grid::create( asagi::Grid::FLOAT );
int l_asagiOpen = bathymetryGrid->open(i_bathymetryFile.c_str());
//open the bathymetry grid
if( l_asagiOpen != 0 ) {
std::cout << "Could not open bathymetry file: " << i_bathymetryFile << std::endl;
std::cout << "Error code: " << l_asagiOpen << std::endl;
assert(false);
}
l_asagiOpen = displacementGrid->open(i_displacementFile.c_str()); // open bathymetry grid
//open the displacement grid bathymetryGrid.open(i_bathymetryFile);
if( l_asagiOpen != 0 ) {
std::cout << "Could not open displacement file: " << i_displacementFile << std::endl; // open displacement grid
std::cout << "Error code: " << l_asagiOpen << std::endl; displacementGrid.open(i_displacementFile);
assert(false);
}
#ifndef NDEBUG #ifndef NDEBUG
//read grid information //read grid information
bathymetryRange[0] = bathymetryGrid->getXMin(); bathymetryRange[0] = bathymetryGrid.grid().getXMin();
bathymetryRange[1] = bathymetryGrid->getXMax(); bathymetryRange[1] = bathymetryGrid.grid().getXMax();
bathymetryRange[2] = bathymetryGrid->getYMin(); bathymetryRange[2] = bathymetryGrid.grid().getYMin();
bathymetryRange[3] = bathymetryGrid->getYMax(); bathymetryRange[3] = bathymetryGrid.grid().getYMax();
#endif #endif
displacementRange[0] = displacementGrid->getXMin(); displacementRange[0] = displacementGrid.grid().getXMin();
displacementRange[1] = displacementGrid->getXMax(); displacementRange[1] = displacementGrid.grid().getXMax();
displacementRange[2] = displacementGrid->getYMin(); displacementRange[2] = displacementGrid.grid().getYMin();
displacementRange[3] = displacementGrid->getYMax(); displacementRange[3] = displacementGrid.grid().getYMax();
if(dynamicDisplacement == false) { if(dynamicDisplacement == false) {
dynamicDisplacementTimeRange[0] = dynamicDisplacementTimeRange[1] = 0; dynamicDisplacementTimeRange[0] = dynamicDisplacementTimeRange[1] = 0;
} }
else { else {
dynamicDisplacementTimeRange[0] = displacementGrid->getZMin(); dynamicDisplacementTimeRange[0] = displacementGrid.grid().getZMin();
dynamicDisplacementTimeRange[1] = displacementGrid->getZMax(); dynamicDisplacementTimeRange[1] = displacementGrid.grid().getZMax();
} }
simulationArea[0] = i_simulationArea[0]; simulationArea[0] = i_simulationArea[0];
...@@ -154,8 +199,8 @@ class SWE_AsagiScenario: public SWE_Scenario { ...@@ -154,8 +199,8 @@ class SWE_AsagiScenario: public SWE_Scenario {
} }
void deleteGrids() { void deleteGrids() {
delete bathymetryGrid; bathymetryGrid.close();
delete displacementGrid; displacementGrid.close();
} }
//methods from SWE_SCENARIO //methods from SWE_SCENARIO
...@@ -174,7 +219,7 @@ class SWE_AsagiScenario: public SWE_Scenario { ...@@ -174,7 +219,7 @@ class SWE_AsagiScenario: public SWE_Scenario {
assert(i_positionY > bathymetryRange[2]); assert(i_positionY > bathymetryRange[2]);
assert(i_positionY < bathymetryRange[3]); assert(i_positionY < bathymetryRange[3]);
float bathymetryValue = bathymetryGrid->getFloat2D(i_positionX, i_positionY); float bathymetryValue = bathymetryGrid.grid().getFloat2D(i_positionX, i_positionY);
if( bathymetryValue > (float)0. ) { if( bathymetryValue > (float)0. ) {
return 0.; return 0.;
...@@ -216,7 +261,7 @@ class SWE_AsagiScenario: public SWE_Scenario { ...@@ -216,7 +261,7 @@ class SWE_AsagiScenario: public SWE_Scenario {
assert(i_positionY > bathymetryRange[2]); assert(i_positionY > bathymetryRange[2]);
assert(i_positionY < bathymetryRange[3]); assert(i_positionY < bathymetryRange[3]);
float bathymetryValue = bathymetryGrid->getFloat2D(i_positionX, i_positionY); float bathymetryValue = bathymetryGrid.grid().getFloat2D(i_positionX, i_positionY);
//bathymetryValue = (float) 0.; //TODO: remove: old file format //bathymetryValue = (float) 0.; //TODO: remove: old file format
...@@ -227,9 +272,9 @@ class SWE_AsagiScenario: public SWE_Scenario { ...@@ -227,9 +272,9 @@ class SWE_AsagiScenario: public SWE_Scenario {
i_positionY > displacementRange[2] && i_positionY > displacementRange[2] &&
i_positionY < displacementRange[3] ) { i_positionY < displacementRange[3] ) {
if(dynamicDisplacement == false) if(dynamicDisplacement == false)
displacementValue = displacementGrid->getFloat2D(i_positionX, i_positionY); displacementValue = displacementGrid.grid().getFloat2D(i_positionX, i_positionY);
else else
displacementValue = displacementGrid->getFloat3D(i_positionX, i_positionY, i_time); displacementValue = displacementGrid.grid().getFloat3D(i_positionX, i_positionY, i_time);
} }
return bathymetryValue + displacementValue; return bathymetryValue + displacementValue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment