Commit 3f9a316d authored by breuera's avatar breuera

Merge branch 'master' of github.com:TUM-I5/SWE

parents 2bd1c3d8 aca161d1
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{88B845B4-569C-49D1-9C07-967D2E58EAC9}</ProjectGuid>
<RootNamespace>SWEOpenGL</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 4.2.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ReferencePath>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.2\lib;$(ReferencePath)</ReferencePath>
<LibraryPath>$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>SDL\include;$(CudaToolkitIncludeDir)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalLibraryDirectories>SDL\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>opengl32.lib;glu32.lib;sdl.lib;sdlmain.lib;cudart.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<CudaCompile>
<Runtime>MD</Runtime>
<CodeGeneration>compute_20,sm_20</CodeGeneration>
</CudaCompile>
<PostBuildEvent>
<Command>xcopy /y "$(ProjectDir)SDL\lib\SDL.dll" "$(OutDir)" </Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>SDL\include;$(CudaToolkitIncludeDir)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>opengl32.lib;glu32.lib;sdl.lib;sdlmain.lib;cudart.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>SDL\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<SubSystem>Windows</SubSystem>
</Link>
<PostBuildEvent>
<Command>xcopy /y $(ProjectDir)SDL\lib\SDL.dll $(OutDir) </Command>
</PostBuildEvent>
<ProjectReference>
<UseLibraryDependencyInputs>true</UseLibraryDependencyInputs>
</ProjectReference>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="src\opengl\camera.h" />
<ClInclude Include="src\opengl\controller.h" />
<ClInclude Include="src\opengl\shader.h" />
<ClInclude Include="src\opengl\simulation.h" />
<ClInclude Include="src\opengl\visualization.h" />
<ClInclude Include="src\scenarios\SWE_simple_scenarios_vis.h" />
<ClInclude Include="src\scenarios\SWE_VisInfo.h" />
<ClInclude Include="src\scenarios\SWE_VtkScenario.h" />
<ClInclude Include="src\scenarios\SWE_VtkScenarioVisInfo.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\examples\swe_opengl.cpp" />
<ClCompile Include="src\opengl\camera.cpp" />
<ClCompile Include="src\opengl\controller.cpp" />
<ClCompile Include="src\opengl\shader.cpp" />
<ClCompile Include="src\opengl\visualization.cpp" />
<ClCompile Include="src\scenarios\SWE_VtkScenario.cpp" />
<ClCompile Include="src\scenarios\SWE_VtkScenarioVisInfo.cpp" />
<ClCompile Include="src\SWE_Block.cpp" />
<ClCompile Include="src\SWE_WavePropagationBlock.cpp" />
</ItemGroup>
<ItemGroup>
<CudaCompile Include="src\opengl\simulation.cu">
<FileType>Document</FileType>
</CudaCompile>
<CudaCompile Include="src\SWE_BlockCUDA.cu" />
<CudaCompile Include="src\SWE_BlockCUDA_kernels.cu" />
<CudaCompile Include="src\SWE_RusanovBlockCUDA.cu" />
<CudaCompile Include="src\SWE_RusanovBlockCUDA_kernels.cu" />
<CudaCompile Include="src\SWE_WavePropagationBlockCuda.cu" />
<CudaCompile Include="src\SWE_WavePropagationBlockCuda_kernels.cu" />
</ItemGroup>
<ItemGroup>
<None Include="src\SWE_Block.hh" />
<None Include="src\SWE_BlockCUDA.hh" />
<None Include="src\SWE_BlockCUDA_kernels.hh" />
<None Include="src\SWE_RusanovBlockCUDA.hh" />
<None Include="src\SWE_RusanovBlockCUDA_kernels.hh" />
<None Include="src\SWE_WavePropagationBlock.hh" />
<None Include="src\SWE_WavePropagationBlockCuda.hh" />
<None Include="src\SWE_WavePropagationBlockCuda_kernels.hh" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 4.2.targets" />
</ImportGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Quelldateien">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Headerdateien">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Ressourcendateien">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\opengl\camera.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\opengl\controller.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\opengl\shader.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\opengl\simulation.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\opengl\visualization.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\scenarios\SWE_simple_scenarios_vis.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\scenarios\SWE_VisInfo.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\scenarios\SWE_VtkScenario.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\scenarios\SWE_VtkScenarioVisInfo.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\examples\swe_opengl.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\opengl\camera.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\opengl\controller.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\opengl\shader.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\opengl\visualization.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\scenarios\SWE_VtkScenario.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\scenarios\SWE_VtkScenarioVisInfo.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\SWE_Block.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="src\SWE_WavePropagationBlock.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CudaCompile Include="src\opengl\simulation.cu">
<Filter>Quelldateien</Filter>
</CudaCompile>
<CudaCompile Include="src\SWE_RusanovBlockCUDA_kernels.cu">
<Filter>Quelldateien</Filter>
</CudaCompile>
<CudaCompile Include="src\SWE_BlockCUDA.cu">
<Filter>Quelldateien</Filter>
</CudaCompile>
<CudaCompile Include="src\SWE_BlockCUDA_kernels.cu">
<Filter>Quelldateien</Filter>
</CudaCompile>
<CudaCompile Include="src\SWE_RusanovBlockCUDA.cu">
<Filter>Quelldateien</Filter>
</CudaCompile>
<CudaCompile Include="src\SWE_WavePropagationBlockCuda.cu">
<Filter>Quelldateien</Filter>
</CudaCompile>
<CudaCompile Include="src\SWE_WavePropagationBlockCuda_kernels.cu">
<Filter>Quelldateien</Filter>
</CudaCompile>
</ItemGroup>
<ItemGroup>
<None Include="src\SWE_RusanovBlockCUDA_kernels.hh">
<Filter>Headerdateien</Filter>
</None>
<None Include="src\SWE_RusanovBlockCUDA.hh">
<Filter>Headerdateien</Filter>
</None>
<None Include="src\SWE_BlockCUDA_kernels.hh">
<Filter>Headerdateien</Filter>
</None>
<None Include="src\SWE_BlockCUDA.hh">
<Filter>Headerdateien</Filter>
</None>
<None Include="src\SWE_Block.hh">
<Filter>Headerdateien</Filter>
</None>
<None Include="src\SWE_WavePropagationBlock.hh">
<Filter>Headerdateien</Filter>
</None>
<None Include="src\SWE_WavePropagationBlockCuda.hh">
<Filter>Headerdateien</Filter>
</None>
<None Include="src\SWE_WavePropagationBlockCuda_kernels.hh">
<Filter>Headerdateien</Filter>
</None>
</ItemGroup>
</Project>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
\ No newline at end of file
...@@ -3,6 +3,10 @@ Microsoft Visual Studio Solution File, Format Version 11.00 ...@@ -3,6 +3,10 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# Visual C++ Express 2010 # Visual C++ Express 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SWE for Windows", "SWE for Windows.vcxproj", "{2582913D-07C3-6F6B-46E0-6B3942A726C4}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SWE for Windows", "SWE for Windows.vcxproj", "{2582913D-07C3-6F6B-46E0-6B3942A726C4}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SWE OpenGL", "SWE OpenGL.vcxproj", "{88B845B4-569C-49D1-9C07-967D2E58EAC9}"
EndProject
#Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SWE OpenGL", "..\..\..\visual studio 2010\Projects\SWE #OpenGL\SWE OpenGL.vcxproj", "{88B845B4-569C-49D1-9C07-967D2E58EAC9}"
#EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
CUDA|Win32 = CUDA|Win32 CUDA|Win32 = CUDA|Win32
...@@ -16,6 +20,16 @@ Global ...@@ -16,6 +20,16 @@ Global
{2582913D-07C3-6F6B-46E0-6B3942A726C4}.Debug|Win32.Build.0 = Debug|Win32 {2582913D-07C3-6F6B-46E0-6B3942A726C4}.Debug|Win32.Build.0 = Debug|Win32
{2582913D-07C3-6F6B-46E0-6B3942A726C4}.Release|Win32.ActiveCfg = Release|Win32 {2582913D-07C3-6F6B-46E0-6B3942A726C4}.Release|Win32.ActiveCfg = Release|Win32
{2582913D-07C3-6F6B-46E0-6B3942A726C4}.Release|Win32.Build.0 = Release|Win32 {2582913D-07C3-6F6B-46E0-6B3942A726C4}.Release|Win32.Build.0 = Release|Win32
{88B845B4-569C-49D1-9C07-967D2E58EAC9}.Debug|Win32.ActiveCfg = Debug|Win32
{88B845B4-569C-49D1-9C07-967D2E58EAC9}.Debug|Win32.Build.0 = Debug|Win32
{88B845B4-569C-49D1-9C07-967D2E58EAC9}.Release|Win32.ActiveCfg = Release|Win32
{88B845B4-569C-49D1-9C07-967D2E58EAC9}.Release|Win32.Build.0 = Release|Win32
# {88B845B4-569C-49D1-9C07-967D2E58EAC9}.CUDA|Win32.ActiveCfg = Release|Win32
# {88B845B4-569C-49D1-9C07-967D2E58EAC9}.CUDA|Win32.Build.0 = Release|Win32
# {88B845B4-569C-49D1-9C07-967D2E58EAC9}.Debug|Win32.ActiveCfg = Debug|Win32
# {88B845B4-569C-49D1-9C07-967D2E58EAC9}.Debug|Win32.Build.0 = Debug|Win32
# {88B845B4-569C-49D1-9C07-967D2E58EAC9}.Release|Win32.ActiveCfg = Release|Win32
# {88B845B4-569C-49D1-9C07-967D2E58EAC9}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
......
...@@ -102,6 +102,9 @@ ...@@ -102,6 +102,9 @@
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>cudart.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>cudart.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
<CudaCompile>
<CodeGeneration>compute_20,sm_20</CodeGeneration>
</CudaCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\examples\swe_wavepropagation.cpp" /> <ClCompile Include="src\examples\swe_wavepropagation.cpp" />
...@@ -113,6 +116,12 @@ ...@@ -113,6 +116,12 @@
<ClInclude Include="src\scenarios\SWE_AsagiScenario.hpp" /> <ClInclude Include="src\scenarios\SWE_AsagiScenario.hpp" />
<ClInclude Include="src\scenarios\SWE_Scenario.h" /> <ClInclude Include="src\scenarios\SWE_Scenario.h" />
<ClInclude Include="src\scenarios\SWE_simple_scenarios.h" /> <ClInclude Include="src\scenarios\SWE_simple_scenarios.h" />
<ClInclude Include="src\solvers\augrie.hpp" />
<ClInclude Include="src\solvers\augriegeoclaw.hpp" />
<ClInclude Include="src\solvers\fwave.hpp" />
<ClInclude Include="src\solvers\FWaveCuda.h" />
<ClInclude Include="src\solvers\hybrid.hpp" />
<ClInclude Include="src\solvers\wavepropagation.hpp" />
<ClInclude Include="src\tools\Logger.hpp" /> <ClInclude Include="src\tools\Logger.hpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
...@@ -144,6 +153,15 @@ ...@@ -144,6 +153,15 @@
<FileType>Document</FileType> <FileType>Document</FileType>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="src\swe_block.hh" />
<None Include="src\swe_blockcuda.hh" />
<None Include="src\SWE_BlockCUDA_kernels.hh" />
<None Include="src\swe_rusanovblock.hh" />
<None Include="src\SWE_RusanovBlockCUDA.hh" />
<None Include="src\SWE_RusanovBlockCUDA_kernels.hh" />
<None Include="src\swe_wavepropagationblock.hh" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 4.2.targets" /> <Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 4.2.targets" />
......
...@@ -43,6 +43,24 @@ ...@@ -43,6 +43,24 @@
</ClInclude> </ClInclude>
<ClInclude Include="src\SWE_WavePropagationBlockCuda.hh" /> <ClInclude Include="src\SWE_WavePropagationBlockCuda.hh" />
<ClInclude Include="src\SWE_WavePropagationBlockCuda_kernels.hh" /> <ClInclude Include="src\SWE_WavePropagationBlockCuda_kernels.hh" />
<ClInclude Include="src\solvers\augrie.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\solvers\augriegeoclaw.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\solvers\fwave.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\solvers\FWaveCuda.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\solvers\hybrid.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\solvers\wavepropagation.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CudaCompile Include="src\SWE_BlockCUDA.cu" /> <CudaCompile Include="src\SWE_BlockCUDA.cu" />
...@@ -52,4 +70,13 @@ ...@@ -52,4 +70,13 @@
<CudaCompile Include="src\SWE_WavePropagationBlockCuda.cu" /> <CudaCompile Include="src\SWE_WavePropagationBlockCuda.cu" />
<CudaCompile Include="src\SWE_WavePropagationBlockCuda_kernels.cu" /> <CudaCompile Include="src\SWE_WavePropagationBlockCuda_kernels.cu" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="src\swe_blockcuda.hh" />
<None Include="src\swe_rusanovblock.hh" />
<None Include="src\SWE_BlockCUDA_kernels.hh" />
<None Include="src\swe_block.hh" />
<None Include="src\SWE_RusanovBlockCUDA.hh" />
<None Include="src\SWE_RusanovBlockCUDA_kernels.hh" />
<None Include="src\swe_wavepropagationblock.hh" />
</ItemGroup>
</Project> </Project>
\ No newline at end of file
...@@ -4,4 +4,7 @@ ...@@ -4,4 +4,7 @@
<LocalDebuggerCommandArguments>160 160 swe_output</LocalDebuggerCommandArguments> <LocalDebuggerCommandArguments>160 160 swe_output</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project> </Project>
\ No newline at end of file
...@@ -122,14 +122,6 @@ SWE_BlockCUDA::SWE_BlockCUDA(float _offsetX, float _offsetY, const int i_cudaDev ...@@ -122,14 +122,6 @@ SWE_BlockCUDA::SWE_BlockCUDA(float _offsetX, float _offsetY, const int i_cudaDev
cudaMalloc((void**)&bd, size); cudaMalloc((void**)&bd, size);
checkCUDAError("allocate device memory for bd"); checkCUDAError("allocate device memory for bd");
//----> COULD BE IMPLEMENTED AS (INEFFICIENT) REFERENCE IMPLEMENTATION
// // allocate CUDA unknowns: maxmimum height and velocity
// size = (nx/TILE_SIZE)*(ny/TILE_SIZE)*sizeof(float);
// cudaMalloc((void**)&maxhd, size);
// checkCUDAError("allocate device memory for maxhd");
// cudaMalloc((void**)&maxvd, size);
// checkCUDAError("allocate device memory for maxvd");
// allocate consecutive memory for 2 columns with three unknowns each // allocate consecutive memory for 2 columns with three unknowns each
// (h, hu, hv, excluding b) for copy/ghost layer at bottom/top boundary // (h, hu, hv, excluding b) for copy/ghost layer at bottom/top boundary
size = nx+2; size = nx+2;
......
...@@ -205,27 +205,3 @@ void kernelTopCopyLayer(float* hd, float* hud, float* hvd, ...@@ -205,27 +205,3 @@ void kernelTopCopyLayer(float* hd, float* hud, float* hvd,
} }
// //******************************************************************
// // kernels to implement boundary conditions
// //******************************************************************
//
//
// /**
// * CUDA kernel for maximum reduction
// * required to compute maximum water height and velocities to determine
// * allow time step
// */
// __global__
// void kernelMaximum(float* maxhd, float* maxvd, int start, int size) {
// int tx = start+threadIdx.x;
// for (int i=size>>1; i>0; i>>=1) {
// __syncthreads();
// if (tx < i) {
// if( maxhd[tx] < maxhd[tx+i] ) maxhd[tx] = maxhd[tx+i];
// if( maxvd[tx] < maxvd[tx+i] ) maxvd[tx] = maxvd[tx+i];
// };
// };
// }
//
//
...@@ -168,6 +168,35 @@ void SWE_WavePropagationBlockCuda::simulateTimestep(float i_dT) { ...@@ -168,6 +168,35 @@ void SWE_WavePropagationBlockCuda::simulateTimestep(float i_dT) {
updateUnknowns(i_dT); updateUnknowns(i_dT);
} }
/**
* perform forward-Euler time steps, starting with simulation time tStart,:
* until simulation time tEnd is reached;
* device-global variables hd, hud, hvd are updated;
* unknowns h, hu, hv in main memory are not updated.
* Ghost layers and bathymetry sources are updated between timesteps.
* intended as main simulation loop between two checkpoints
*/
__host__
float SWE_WavePropagationBlockCuda::simulate(float tStart, float tEnd) {
float t = tStart;
do {
// set values in ghost cells:
setGhostLayer();
// Compute the numerical fluxes/net-updates in the wave propagation formulation.
computeNumericalFluxes();
// Update the unknowns with the net-updates.
updateUnknowns(maxTimestep);
t += maxTimestep;
// cout << "Simulation at time " << t << endl << flush;
} while(t < tEnd);
return t;
}
/** /**
* Compute the numerical fluxes (net-update formulation here) on all edges. * Compute the numerical fluxes (net-update formulation here) on all edges.
* *
......
...@@ -74,11 +74,8 @@ class SWE_WavePropagationBlockCuda: public SWE_BlockCUDA { ...@@ -74,11 +74,8 @@ class SWE_WavePropagationBlockCuda: public SWE_BlockCUDA {
// compute a single time step (net-updates + update of the cells). // compute a single time step (net-updates + update of the cells).
void simulateTimestep( float i_dT ); void simulateTimestep( float i_dT );
// TODO: Not implemented // simulate multiple time steps (start and end time provided as parameters)
float simulate(float, float) { float simulate(float, float);
assert(false);
return 0;
};
// TODO: not implemented, max time step reduction is done in each call of computeNumericalFluxes(...) // TODO: not implemented, max time step reduction is done in each call of computeNumericalFluxes(...)
void computeMaxTimestep() { void computeMaxTimestep() {
......
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cpp for details).
//
// Copyright (C) 2010,2011 Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
// Project files
#include "SDL.h"
#include "../opengl/simulation.h"
#include "../opengl/visualization.h"
#include "../opengl/controller.h"
#include "../scenarios/SWE_Scenario.h"
#include "../scenarios/SWE_simple_scenarios_vis.h"
#include "../scenarios/SWE_VtkScenarioVisInfo.h"
#include "../SWE_BlockCUDA.hh"
// #include "../SWE_RusanovBlockCUDA.hh"
#include "../SWE_WavePropagationBlockCUDA.hh"
// For SDL compatibility
#undef main
// Display settings
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
// Number of nodes (not cells) of grid
#define GRID_XSIZE 401
#define GRID_YSIZE 401
#define WINDOW_TITLE "Shallow Water Equations v1.2"
/**
Main routine.
Takes 1 command line parameter, which specifies optional input file
Control keys:
- [ESC]: quit
- [SPACE]: pause/resume simulation
- [RIGHT]: advance single step (only when paused)
- [s]: save current simulation
- [r]: reset simulation
- [w]: toggle rendering mode
Mouse:
- Left button: rotating
- Right button: panning
- Scroll wheel: zooming
The class concept relies on the Model-View-Controller (MVC)
architecture.
The controller class handles all user input and updates the
visualization and simulation correspondingly.
The simulation (model) advances stepwise, the visualization (view)
displays then the updated data.
*/
int main(int argc, char *argv[])
{
int done = 0;
int gridx = GRID_XSIZE;
int gridy = GRID_YSIZE;
int nx = gridx-1;
int ny = gridy-1;
printf("Starting up...\n");
// Initialize visualization
Visualization visualization(SCREEN_WIDTH, SCREEN_HEIGHT, WINDOW_TITLE, gridx, gridy);
printf("Initialized OpenGL window...\n\n");
// Initialize scenario:
SWE_Scenario* scene = NULL;
SWE_VisInfo* visInfo = NULL;
SWE_BlockCUDA* splash = NULL;
// If input file specified, then read from VTK file:
if (argc > 1) {
SWE_VtkScenarioVisInfo* newScene = SWE_VtkScenarioVisInfo::readVtkFile(argv[1]);
// NOTE: Simulation uses a fixed resolution (independent of VTK file)
scene = newScene;
visInfo = newScene;
printf("Scenario read from input file %s\n\n", argv[1]);
};
if (scene == NULL) {
// ... if VTK file not specified (or was not read successfully)
// use splashing pool scenario ...
SWE_SplashingPoolScenarioVisInfo* newScene = new SWE_SplashingPoolScenarioVisInfo();
scene = newScene;
visInfo = newScene;
};
// define grid size and initial time step
float dx = (scene->getBoundaryPos(BND_RIGHT) - scene->getBoundaryPos(BND_LEFT) )/nx;
float dy = (scene->getBoundaryPos(BND_TOP) - scene->getBoundaryPos(BND_BOTTOM) )/ny;
SWE_Block::initGridData(nx,ny,dx,dy);
// splash = new SWE_RusanovBlockCUDA();
splash = new SWE_WavePropagationBlockCuda();
// define boundary type at all four domain boundaries:
splash->setWallBoundaries(); // walls at all boundaries
// Initialize simulation
printf("Init simulation\n\n");
Simulation sim(nx,ny,dx,dy, scene, visInfo, splash);
printf("Init visualisation\n\n");
visualization.init(&sim);
// Initialize controller
Controller controller(&sim, &visualization);
printf("Start simulation\n\n");
// sim.saveToFile();
// Enter the main loop
while ( ! done )
{
// Handle events
done = controller.handleEvents();
if (controller.isPaused()) {
// We're paused, only render new display
visualization.renderDisplay();
}
else if (controller.hasFocus()) {
// Simulate, update visualization data
sim.runCuda(visualization.getCudaWaterSurfacePtr(), visualization.getCudaNormalsPtr());
// Render new data
visualization.renderDisplay();
}
}
// Clean everything up
visualization.cleanUp();
// delete scene;
// delete splash;
return 0;
}
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#include "camera.h"
#include <sstream>
/**
Constructor
@param view_distance initial view distance from the origin
@param window_title title of the current window
*/
Camera::Camera(float view_distance, const char* window_title) {
// Initialize member variables
cameraX = -0.3f;
cameraY = 1.0f;
cameraZ = 2.0f;
objectX = 0.0f;
objectY = 0.0f;
objectZ = 0.0f;
angleX = 0.0f;
angleY = 0.0f;
zoomfactor = 0.85f*view_distance;
win_title = window_title;
frames = 0;
lastTime = 0;
oldMouseX = 0;
oldMouseY = 0;
// Reset framebuffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/**
Set the camera via gluLookAt and set the light position afterwards
*/
void Camera::setCamera() {
// Clear our buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Set camera position, center of scene and up vector
gluLookAt(cameraX*zoomfactor, cameraY*zoomfactor, cameraZ*zoomfactor,
0,0,0, // center of scene
0, 1, 0); // up vector
// Translate and rotate our object
glTranslated(objectX, objectY, objectZ);
this->rotateObject();
glScalef(1.0f, 1.0f, -1.0f);
// Position the light source
// Note: Coordinates are multiplied by current modelview-matrix
// by OpenGL
GLfloat LightPosition[]= { 1.0f, 1.0f, 0.0f, 0.0f };
glLightfv(GL_LIGHT0, GL_POSITION,LightPosition);
}
/**
Rotate camera
*/
void Camera::rotateObject() {
glRotatef(angleX, 1.0, 0.0f, 0.0f);
glRotatef(angleY, 0.0f, 1.0f, 0.0f);
}
/**
Increment viewing orientation of the camera
@param angle_dX angle relative to the x-axis
@param angle_dY angle relative to the rotated y-axis
*/
void Camera::orient( float angle_dX, float angle_dY )
{
angleX += angle_dX;
angleY += angle_dY;
}
/**
Zoom in
@param scaleFactor factor which is used for zooming
*/
void Camera::zoomIn( float scaleFactor )
{
if (zoomfactor > 3.0f) {
zoomfactor /= scaleFactor;
}
}
/**
Zoom out
@param scaleFactor factor which is used for zooming
*/
void Camera::zoomOut( float scaleFactor )
{
zoomfactor *= scaleFactor;
}
/**
Calculates the current framerate, updates the window title and
swaps framebuffers to display the new image
*/
void Camera::displayImage() {
// Set up stringstream for window title
std::stringstream ss;
ss.setf(std::ios::fixed, std::ios::floatfield);
ss.setf(std::ios::showpoint);
ss.precision(1);
// Calculate framerate
float fps;
frames++;
if (lastTime == 0) {
lastTime = SDL_GetTicks();
} else if( (SDL_GetTicks() - lastTime) >= 500) {
fps = (float)frames/(SDL_GetTicks() - lastTime)*1000.0f;
ss << win_title << " (" << fps << " fps)";
SDL_WM_SetCaption(ss.str().c_str(), NULL);
frames = 0;
lastTime = SDL_GetTicks();
}
// Swap frame buffer
SDL_GL_SwapBuffers();
}
/**
User starts dragging.
Remember the old mouse coordinates.
*/
void Camera::startPanning(int xPos, int yPos) {
oldMouseX = xPos;
oldMouseY = yPos;
}
/**
User drags our object.
Transform screen coordinates into world coordinates
and update the objects position
*/
void Camera::panning(int newX, int newY) {
GLint viewport[4];
GLdouble modelview[16];
GLdouble projection[16];
GLfloat winX, winY, winZ;
GLdouble posX, posY, posZ;
GLdouble pos2X, pos2Y, pos2Z;
GLdouble dX, dY, dZ;
// Draw invisible fake plane
setCamera();
glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
GLfloat dim = 100000.0f;
glBegin(GL_QUADS);
glColor3f(1.0f, 1.0f, 0.3f);
glVertex3f( dim,0.0f, dim);
glVertex3f(-dim,0.0f, dim);
glVertex3f(-dim,0.0f, -dim);
glVertex3f( dim,0.0f, -dim);
glEnd();
glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE);
// Get projection matrices
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
glGetDoublev( GL_PROJECTION_MATRIX, projection );
glGetIntegerv( GL_VIEWPORT, viewport );
// Get drag positions in object coordinates
winX = (GLfloat)newX;
winY = (GLfloat)viewport[3] - (GLfloat)newY;
glReadPixels( newX, GLint(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
gluUnProject( winX, winY, winZ, modelview, projection, viewport, &posX, &posY, &posZ);
winX = (GLfloat)oldMouseX;
winY = (GLfloat)viewport[3] - (GLfloat)oldMouseY;
glReadPixels( oldMouseX, GLint(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
gluUnProject( winX, winY, winZ, modelview, projection, viewport, &pos2X, &pos2Y, &pos2Z);
glClear(GL_DEPTH_BUFFER_BIT);
// Calculate drag distances
dX = (posX-pos2X);
dY = (posY-pos2Y);
dZ = (posZ-pos2Z);
// Convert drag distances to world coordinates
glPushMatrix();
glLoadIdentity();
rotateObject();
glScalef(1.0f, 1.0f, -1.0f);
glGetDoublev( GL_MODELVIEW_MATRIX, modelview );
GLdouble x = modelview[0]*dX + modelview[4]*dY + modelview[8]*dZ;
GLdouble y = modelview[1]*dX + modelview[5]*dY + modelview[9]*dZ;
GLdouble z = modelview[2]*dX + modelview[6]*dY + modelview[10]*dZ;
glPopMatrix();
// Set the new world coordinates of our object
objectX += x;
objectY += y;
objectZ += z;
// Save our current mouse position
oldMouseX = newX;
oldMouseY = newY;
}
\ No newline at end of file
#ifndef CAMERA_H
#define CAMERA_H
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#include <SDL.h>
#include <SDL_opengl.h>
class Camera {
public:
Camera(float view_distance, const char* window_title);
// Set modelview matrix
void setCamera ();
// Change viewing properties
void orient( float angX, float angY );
void zoomIn( float scaleFactor );
void zoomOut( float scaleFactor );
void startPanning(int xPos, int yPos);
void panning(int newX, int newY);
// Update framebuffer
void displayImage();
private:
// Position of the camera
float cameraX;
float cameraY;
float cameraZ;
// Position of the object
GLdouble objectX;
GLdouble objectY;
GLdouble objectZ;
// Zoom factor
float zoomfactor;
float angleX, angleY;
// Helper variables
unsigned int frames;
unsigned int lastTime;
unsigned int oldMouseX, oldMouseY;
unsigned int newMouseX, newMouseY;
// Window title
const char* win_title;
void rotateObject();
};
#endif
\ No newline at end of file
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#include "controller.h"
#include "../scenarios/SWE_simple_scenarios_vis.h"
/**
Constructor
@param sim instance of simulation class
@param vis instance of visualization class
*/
Controller::Controller(Simulation* sim, Visualization* vis) {
simulation = sim;
visualization = vis;
isActive = true;
done = false;
paused = false;
allowStep = false;
}
/**
Process all user events in a loop
Returns true, when user wants to quit
*/
bool Controller::handleEvents() {
// Handle events
SDL_Event event;
allowStep = false;
while ( SDL_PollEvent(&event) )
{
switch( event.type )
{
case SDL_MOUSEMOTION:
if (event.motion.state & SDL_BUTTON(SDL_BUTTON_LEFT)) {
// Left mouse button dragging
visualization->camera->orient(0.5f*event.motion.yrel, 0.5f*event.motion.xrel);
}
else if (event.motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT)) {
// Panning happens here
visualization->camera->panning(event.motion.x, event.motion.y);
}
break;
case SDL_MOUSEBUTTONDOWN:
// Scroll wheel down
if ( event.button.button == SDL_BUTTON_WHEELDOWN ) {
// Zoom out
visualization->camera->zoomOut(1.2f);
} else if (event.button.button == SDL_BUTTON_RIGHT) {
visualization->camera->startPanning(event.button.x, event.button.y);
}
break;
case SDL_MOUSEBUTTONUP:
// Scroll wheel up
if ( event.button.button == SDL_BUTTON_WHEELUP ) {
// Zoom in
visualization->camera->zoomIn(1.15f);
}
break;
case SDL_ACTIVEEVENT:
// Don't draw anything if we're getting minimized
if ( event.active.state & SDL_APPACTIVE ) {
isActive = (event.active.gain != 0);
}
break;
case SDL_VIDEORESIZE:
// Our window was resized
visualization->resizeWindow(event.resize.w, event.resize.h);
break;
case SDL_KEYDOWN:
// User has pressed a key
done = handleKeyPress( &event.key.keysym);
break;
case SDL_QUIT:
// Window close request
done = true;
break;
default:
break;
}
}
return done;
}
/**
Returns true, when window has focus
*/
bool Controller::hasFocus() {
return isActive && !done;
}
/**
Return whether program is currently paused
*/
bool Controller::isPaused() {
return paused && !allowStep;
}
/**
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;
}
#ifndef CONTROLLER_H
#define CONTROLLER_H
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#include <SDL.h>
#include "simulation.h"
#include "visualization.h"
class Controller {
public:
Controller(Simulation* sim, Visualization* vis);
// Process new events
bool handleEvents();
// Return if window is enabled
bool hasFocus();
// Return if program is paused
bool isPaused();
private:
// Internal functions
bool isActive;
bool done;
bool paused;
bool allowStep;
// References to other classes
Simulation* simulation;
Visualization* visualization;
// Handle keyboard events
bool handleKeyPress( SDL_keysym *keysym);
};
#endif
\ No newline at end of file
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
varying vec3 V;
varying vec3 N;
varying vec4 ambient;
/* Shading of water surfaces with fresnel effect */
void main()
{
// Helper variable for color
vec4 color = ambient;
// Get normal and view vector
vec3 view = normalize(V);
vec3 normal = normalize(N); ;
if (!gl_FrontFacing) {
// Handle backface rendering
normal = -normal;
}
// Compute fresnel factor
float fresnelFactor = 0.1+0.1*pow(1+dot(normal,view), 3.0);
// Combine color with fresnel factor
color += gl_LightSource[0].specular * fresnelFactor;
color = mix(color, vec4(0.2, 0.4, 0.9, 1.0), 0.2);
// Set constant transparency
gl_FragColor = vec4(color.xyz, 0.7);
}
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#include "shader.h"
/**
Constructor.
Check whether shaders are supported. If yes, load vertex and fragment
shader from textfile into memory and compile
@param vertexShaderFile name of the text file containing the vertex
shader code
@param fragmentShaderFile name of the text file containing the fragment
shader code
*/
Shader::Shader(char const * vertexShaderFile, char const * fragmentShaderFile) {
shdrSupport = isExtensionSupported("GL_ARB_vertex_shader")
&& isExtensionSupported("GL_ARB_shader_objects")
&& isExtensionSupported("GL_ARB_fragment_shader");
shdrLoaded = false;
if (shdrSupport) {
// Load extensions
glCreateShader = (PFNGLCREATESHADERPROC) SDL_GL_GetProcAddress("glCreateShader");
glCreateProgram = (PFNGLCREATEPROGRAMPROC) SDL_GL_GetProcAddress("glCreateProgram");
glAttachShader = (PFNGLATTACHSHADERPROC)SDL_GL_GetProcAddress("glAttachShader");
glCompileShader = (PFNGLCOMPILESHADERPROC)SDL_GL_GetProcAddress("glCompileShader");
glUseProgram = (PFNGLUSEPROGRAMPROC)SDL_GL_GetProcAddress("glUseProgram");
glDetachShader = (PFNGLDETACHSHADERPROC)SDL_GL_GetProcAddress("glDetachShader");
glDeleteShader = (PFNGLDELETESHADERPROC) SDL_GL_GetProcAddress("glDeleteShader");
glLinkProgram = (PFNGLLINKPROGRAMPROC)SDL_GL_GetProcAddress("glLinkProgram");
glShaderSource = (PFNGLSHADERSOURCEPROC)SDL_GL_GetProcAddress("glShaderSource");
glDeleteProgram = (PFNGLDELETEPROGRAMPROC)SDL_GL_GetProcAddress("glDeleteProgram");
glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) SDL_GL_GetProcAddress("glGetObjectParameterivARB");
glGetShaderiv = (PFNGLGETSHADERIVPROC) SDL_GL_GetProcAddress("glGetShaderiv");
glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC) SDL_GL_GetProcAddress("glGetShaderInfoLog");
glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC) SDL_GL_GetProcAddress("glGetProgramInfoLog");
// Read shader files
bool readSuccess = false;
vertexShaderSource = NULL;
fragmentShaderSource = NULL;
readSuccess = readShaderFile(vertexShaderFile, vertexShaderSource, vertexShaderLength);
readSuccess &= readShaderFile(fragmentShaderFile, fragmentShaderSource, fragmentShaderLength);
// Check if reading was completed
if (readSuccess) {
// Create Vertex-Shader
vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, const_cast<GLchar const **>(&vertexShaderSource), &vertexShaderLength);
glCompileShader(vertexShader);
// Create Fragment-Shader
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, const_cast<GLchar const **>(&fragmentShaderSource), &fragmentShaderLength);
glCompileShader(fragmentShader);
if (isShaderCompiled(vertexShader, "Vertex-Shader")
&& isShaderCompiled(fragmentShader, "Fragment-Shader"))
{
// Create Shader program
program = glCreateProgram();
glAttachShader(program, vertexShader);
glAttachShader(program, fragmentShader);
glLinkProgram(program);
shdrLoaded = true;
} else {
// Errors while compiling shaders
shdrSupport = false;
glDeleteShader(vertexShader);
delete[] vertexShaderSource;
glDeleteShader(fragmentShader);
delete[] fragmentShaderSource;
}
} else {
if (vertexShaderSource != NULL) delete[] vertexShaderSource;
if (fragmentShaderSource != NULL) delete[] fragmentShaderSource;
}
}
}
/**
Destructor.
Unload shaders and free resources.
*/
Shader::~Shader() {
// Unload Shaders
if (shdrLoaded) {
glUseProgram(0);
glDeleteProgram(program);
glDetachShader(program, vertexShader);
glDeleteShader(vertexShader);
delete[] vertexShaderSource;
glDetachShader(program, fragmentShader);
glDeleteShader(fragmentShader);
delete[] fragmentShaderSource;
}
}
/**
Replaces OpenGL shaders by our custom shaders
*/
void Shader::enableShader() {
if (shdrLoaded) {
glUseProgram(program);
}
}
/**
Restores OpenGL default shaders
*/
void Shader::disableShader() {
if (shdrLoaded) {
glUseProgram(0);
}
}
/**
Returns, whether shaders are supported by graphics hardware
*/
bool Shader::shadersSupported() {
return shdrSupport;
}
/**
Returns, whether shaders could by loaded successfully
*/
bool Shader::shadersLoaded() {
return shdrLoaded;
}
/**
Returns, whether a special extension is supported by the current
graphics card
@param szTargetExtention string describing the extension to look for
*/
bool Shader::isExtensionSupported(const char* szTargetExtension )
{
const unsigned char *pszExtensions = NULL;
const unsigned char *pszStart;
unsigned char *pszWhere, *pszTerminator;
// Extension names should not have spaces
pszWhere = (unsigned char *) strchr( szTargetExtension, ' ' );
if( pszWhere || *szTargetExtension == '\0' )
return false;
// Get Extensions String
pszExtensions = glGetString( GL_EXTENSIONS );
// Search The Extensions String For An Exact Copy
pszStart = pszExtensions;
for(;;)
{
pszWhere = (unsigned char *) strstr( (const char *) pszStart, szTargetExtension );
if( !pszWhere )
break;
pszTerminator = pszWhere + strlen( szTargetExtension );
if( pszWhere == pszStart || *( pszWhere - 1 ) == ' ' )
if( *pszTerminator == ' ' || *pszTerminator == '\0' )
return true;
pszStart = pszTerminator;
}
return false;
}
/**
Returns, whether a special extension is supported by the current
graphics card
@param filename shader file
@return shaderSource file content
@return length length of the file
@returns bool true, if file has been read successfully
*/
bool Shader::readShaderFile(char const * filename, GLchar * & shaderSource, GLint & length)
{
using namespace std;
string fullFileName = "";
// On unix: determine directory of exec
#ifdef __unix__
// Code taken from:
// http://www.gamedev.net/community/forums/topic.asp?topic_id=459511
std::string path = "";
pid_t pid = getpid();
char buf[20] = {0};
sprintf(buf,"%d",pid);
std::string _link = "/proc/";
_link.append( buf );
_link.append( "/exe");
char proc[512];
int ch = readlink(_link.c_str(),proc,512);
if (ch != -1) {
proc[ch] = 0;
path = proc;
std::string::size_type t = path.find_last_of("/");
path = path.substr(0,t);
}
fullFileName = path + string("/");
#endif
fullFileName.append(filename);
ifstream file(fullFileName.c_str(), ios::in);
length = 0;
if (!file.good())
{
return false;
}
file.seekg(0, ios::end);
length = file.tellg();
file.seekg(ios::beg);
if (length == 0 )
{
return false;
}
shaderSource = new GLchar[length];
if (shaderSource == 0)
{
return false;
}
memset(shaderSource, 0, length);
file.read(shaderSource, length);
file.close();
return true;
}
/**
Returns, whether a shader has been compiled with success
@param shader shader id
@param prefix custom error message
*/
bool Shader::isShaderCompiled(GLuint shader, char const * prefix)
{
using namespace std;
GLint compiled(0);
glGetObjectParameterivARB(shader, GL_COMPILE_STATUS, &compiled);
if (!compiled)
{
GLint maxLength(0);
glGetShaderiv(shader, GL_INFO_LOG_LENGTH , &maxLength);
cerr << prefix
<< " -- Compiler Log: "
<< endl
;
if (maxLength > 1)
{
GLchar * log = new GLchar[maxLength];
glGetShaderInfoLog(shader, maxLength, 0, log);
cerr << log
;
delete[] log;
}
}
return (compiled != 0);
}
/**
Returns, whether a shader has been linked with success
@param shader shader id
@param prefix custom error message
*/
bool Shader::isProgramLinked(GLuint program, char const * prefix)
{
using namespace std;
GLint linked(0);
glGetObjectParameterivARB(program, GL_LINK_STATUS, &linked);
if (!linked)
{
GLint maxLength(0);
glGetShaderiv(program, GL_INFO_LOG_LENGTH , &maxLength);
cerr << prefix
<< " -- Linker Log: "
<< endl
;
if (maxLength > 1)
{
GLchar * log = new GLchar[maxLength];
glGetProgramInfoLog(program, maxLength, 0, log);
cerr << log
;
delete[] log;
}
}
return (linked != 0);
}
#ifndef SHADER_H
#define SHADER_H
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#include <SDL.h>
#include <SDL_opengl.h>
#include <iostream>
#include <fstream>
class Shader {
public:
// Constructor and Destructor
// Load vertex shader file and fragment shader file
Shader(char const * vertexShaderFile, char const * fragmentShaderFile) ;
~Shader();
// Check if shaders are supported
bool shadersSupported();
bool shadersLoaded();
// Shader control
void enableShader();
void disableShader();
private:
// State flags
bool shdrSupport;
bool shdrLoaded;
// Helper functions
bool readShaderFile(char const * filename, GLchar * & shaderSource, GLint & length);
bool isExtensionSupported(const char* szTargetExtension );
bool isShaderCompiled(GLuint shader, char const * prefix);
bool isProgramLinked(GLuint program, char const * prefix);
// Vertex-Shader
GLuint vertexShader;
GLchar * vertexShaderSource;
GLint vertexShaderLength;
// Fragment-Shader
GLuint fragmentShader;
GLchar * fragmentShaderSource;
GLint fragmentShaderLength;
// Shaders id
GLuint program;
// Shader extension function pointers
PFNGLCREATESHADERPROC glCreateShader;
PFNGLCREATEPROGRAMPROC glCreateProgram;
PFNGLATTACHSHADERPROC glAttachShader;
PFNGLCOMPILESHADERPROC glCompileShader;
PFNGLUSEPROGRAMPROC glUseProgram;
PFNGLDETACHSHADERPROC glDetachShader;
PFNGLDELETESHADERPROC glDeleteShader;
PFNGLLINKPROGRAMPROC glLinkProgram;
PFNGLSHADERSOURCEPROC glShaderSource;
PFNGLDELETEPROGRAMPROC glDeleteProgram;
// Shader objects extension pointers
PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB;
PFNGLGETSHADERIVPROC glGetShaderiv;
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
};
#endif
This diff is collapsed.
#ifndef SIMULATION_H
#define SIMULATION_H
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Michael Bader, Kaveh Rahnema, Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#include <math.h>
#include <cuda_runtime.h>
#include "../SWE_BlockCUDA.hh"
#include "../scenarios/SWE_Scenario.h"
#include "../scenarios/SWE_VisInfo.h"
void checkCUDAError(const char *msg);
class Simulation {
public:
// Constructor + Destructor
Simulation (int nx, int ny, float dx, float dy,
SWE_Scenario* scene, SWE_VisInfo* visInfo, SWE_BlockCUDA* init_splash);
~Simulation();
// Restart simulation
void restart();
// Load new scenario after initialization
void loadNewScenario(SWE_Scenario* scene, SWE_VisInfo* visInfo);
// Save simulation state to file
void saveToFile();
// Return the bathymetry data
void setBathBuffer(float* output);
// Simulate single timestep on graphics card
void runCuda(struct cudaGraphicsResource **vbo_resource, struct cudaGraphicsResource **vbo_normals);
// Debugging
void writeDebugOutput(float3* destBuffer = NULL);
protected:
// Instance of SWE_BlockCUDA
SWE_BlockCUDA* splash;
// Current scenario
SWE_Scenario* myScenario;
// Current simulation time
float curTime;
// Is this our first simulation step?
int isFirstStep;
// Maximum of cell sizes
float maxCellSize;
// Scaling factors used by visualization
float bOffset, bScale, wOffset, wScale, bAverage, wAverage;
// Initalize boundaries defined by the scene
void initBoundaries(SWE_Scenario* scene);
// Initalize boundaries defined by an input file
int fileNumber;
// Use file input as boundary data
bool useFileInput;
// Holds maximum dimension
int maxDim;
// Compute new water surface
void calculateWaterSurface(float3* destBuffer);
// Compute normals of the water surface for shading
void calculateNormals(float3* vertexBuffer, float3* destBuffer);
void getScalingApproximation(const Float2D& h, const Float2D& b);
void updateVisBuffer(float3* _visBuffer);
void debugVisBuffer(float3* _visBuffer);
/**
Scale function used for visualization
*/
__device__ __host__
static float scaleFunction(float val, float average, float scale, float offset) {
return (val - average)*scale + offset;
}
static void calculateNormal(float fVert1[], float fVert2[],
float fVert3[], float fNormal[]);
};
#endif
This diff is collapsed.
#ifndef VISUALIZATION_H
#define VISUALIZATION_H
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#include <SDL.h>
#include <SDL_opengl.h>
#include <cuda_runtime.h>
#include <cuda_gl_interop.h>
#include "camera.h"
#include "simulation.h"
#include "shader.h"
void checkCUDAError(const char *msg);
typedef enum RenderMode {
SHADED, WIREFRAME, WATERSHADER
} RenderMode;
class Visualization {
public:
// Constructor and Destructor
Visualization(int windowWidth, int windowHeight, const char* window_title, int _grid_xsize, int _grid_ysize);
~Visualization();
void init(Simulation* sim);
void cleanUp();
Camera* camera;
// Access to CUDA VBO pointers
cudaGraphicsResource** getCudaNormalsPtr();
cudaGraphicsResource** getCudaWaterSurfacePtr();
// Main rendering function
void renderDisplay();
// Helper functions
void setRenderingMode(RenderMode mode);
void updateBathymetryVBO(Simulation* sim);
void toggleRenderingMode();
int resizeWindow(int newWidth, int newHeight);
private:
// Init helper functions
void initSDL(int windowWidth, int windowHeight);
void initGLWindow(int width, int height);
void initGLDefaults();
void initCUDA();
bool IsExtensionSupported(const char* szTargetExtension );
// Drawing functions
void DrawWaterSurface(GLuint vboID, GLuint vboNormals, GLuint verticesIndex);
void DrawBathymetry(GLuint vboID, GLuint verticesIndex);
void DrawBottom();
int grid_xsize;
int grid_ysize;
// Vertex Buffer objects
GLuint vboBathymetry;
GLuint verticesIndex;
GLuint vboWaterSurface;
GLuint vboNormals;
struct cudaGraphicsResource* cuda_vbo_watersurface;
struct cudaGraphicsResource* cuda_vbo_normals;
// VBO management functions
void createIndicesVBO(GLuint* vboID, int xsize, int ysize);
void createVertexVBO(GLuint* vboID, int size);
void createBathymetryVBO(GLuint* vboID, int size, Simulation* sim);
void createVertexVBO(GLuint* vboID, int size, struct cudaGraphicsResource **vbo_res,
unsigned int vbo_res_flags);
void deleteVBO(GLuint* vbo);
void deleteVBO(GLuint* vbo, struct cudaGraphicsResource *vbo_res);
// Rendering mode
RenderMode renderMode;
// Shader helper class
Shader* shaders;
// Helper function
int coord(int x, int y, int width = -1);
// VBO Extension Function Pointers
PFNGLGENBUFFERSARBPROC glGenBuffers; // VBO Name Generation Procedure
PFNGLBINDBUFFERARBPROC glBindBuffer; // VBO Bind Procedure
PFNGLBUFFERDATAARBPROC glBufferData; // VBO Data Loading Procedure
PFNGLDELETEBUFFERSARBPROC glDeleteBuffers; // VBO Deletion Procedure
};
#endif
#ifndef __SWE_VISINFO_H
#define __SWE_VISINFO_H
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Michael Bader, Kaveh Rahnema, Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
/**
* SWE_VisInfo defines an interface that can be used for online
* visualisation of a shallow water simulation.
* In particular, it provides information required for proper
* scaling of the involved variables.
*/
class SWE_VisInfo {
public:
// Scaling factors for custom visualization
// virtual bool useCustomScaling() { return false; };
virtual float waterHeightAtRest() { return 10.0f; };
virtual float waterDistanceFromGround() { return 10.0f; };
virtual float waterVerticalScaling() { return 10.0f; };
virtual float bathyVerticalCenter() { return 0.0f; };
virtual float bathyDistanceFromGround() { return 0.0f; };
virtual float bathyVerticalScaling() { return 10.0f; };
};
#endif
This diff is collapsed.
#ifndef __SWE_VTK_SCENARIO_H
#define __SWE_VTK_SCENARIO_H
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Michael Bader, Kaveh Rahnema, Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <vector>
#include "../tools/help.hh"
#include "SWE_Scenario.h"
using namespace std;
/**
* Scenario "VTK File":
* the object will read the values stored in a VTK file
* (i.e., use such a visualisation file as checkpoint for restarting a simulation)
*
* Note: - Boundary Conditions are NOT stored in a VTK file;
* OUTFLOW conditions are assumed at all boundaries
* - similar, 0.1 is always returnedby function endSimulation()
*
* TODO: Option to read a VTK container file
* (for example: read by different MPI processes, such that each MPI process
* will represent one of the container's VTK files)
*/
class SWE_VtkScenario : public SWE_Scenario {
public:
// SWE_VtkScenario does not offer a public constructor
// -> use this method to create a SWE_VtkScenario object
static SWE_VtkScenario* readVtkFile(char const * filename);
virtual float getWaterHeight(float x, float y);
virtual float getVeloc_u(float x, float y);
virtual float getVeloc_v(float x, float y);
virtual float getBathymetry(float x, float y);
virtual float waterHeightAtRest() { return heightAtRest; };
virtual void setWaterHeightAtRest(float whar) { heightAtRest = whar; };
virtual BoundaryType getBoundaryType(BoundaryEdge edge) { return OUTFLOW; };
virtual float getBoundaryPos(BoundaryEdge edge) { return bndPos[edge]; };
protected:
SWE_VtkScenario(int nx, int ny);
Float2D h;
Float2D u;
Float2D v;
Float2D b;
float heightAtRest;
float bndPos[4];
float dx;
float dy;
void computeHeightAtRest();
static void stringExplode(string str, string separator, vector<string>* results);
friend ostream& operator<< (ostream& os, SWE_VtkScenario& scene);
};
ostream& operator<< (ostream& os, const SWE_VtkScenario& scene);
#endif
#include "SWE_VtkScenarioVisInfo.h"
#include <fstream>
#include <algorithm>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
/**
* Protected Constructor for class SWE_VtkScenarioVisInfo:
* called by readVtkFile to create an object of correct size;
* only calls constructor of SWE_VtkScenario
* NOTE: the provided number of cells in x and y direction includes ghost cells
* @param nx cells in x direction
* @param ny cells in y direction
*/
SWE_VtkScenarioVisInfo::SWE_VtkScenarioVisInfo(int nx, int ny)
: SWE_VtkScenario(nx,ny)
{
}
/**
* Read VTK file which was written by SWE_Block.
* Use finite state automaton to parse input data.
* @param filename input filename
*/
SWE_VtkScenarioVisInfo* SWE_VtkScenarioVisInfo::readVtkFile(char const * filename)
{
// Helper variables
string line;
int state = 0;
int lineCount = 0;
int totalLines = 0;
int offsetCount = 0;
int dimx, dimy;
SWE_VtkScenarioVisInfo* scene;
float* h = NULL;
float* u = NULL;
float* v = NULL;
float* b = NULL;
size_t found;
vector<string> values;
// Open file
ifstream file(filename, ios::in);
if (!file.good()) {
std::cout << "Couldn't open file: " << filename << "\n";
return NULL;
}
// Count lines
totalLines = std::count(std::istreambuf_iterator<char>(file),
std::istreambuf_iterator<char>(), '\n');
file.seekg (0, ios::beg);
// Read line by line
while (std::getline(file,line)) {
// Skip empty lines
lineCount++;
if (! line.length()) continue;
// Convert to lower case
offsetCount++;
std::transform(line.begin(), line.end(),line.begin(), ::tolower);
// Output progress
if (lineCount % 10000 == 0 || lineCount == totalLines) {
std::cout << "\r" << "Reading input file: " <<
(lineCount*100)/totalLines << "% completed. " << flush;
}
switch(state)
{
// Header part
case 0:
found = line.find("# vtk datafile");
if (found!=string::npos) {
state = 1;
}
break;
case 1:
state = 2;
break;
case 2:
if (line.find("ascii") == 0) {
state = 3;
}
break;
case 3:
if (line.find("dataset structured_grid") == 0) {
state = 4;
}
break;
case 4:
found = line.find("dimensions");
if (found!=string::npos) {
stringExplode(line," ", &values);
if (values.size() != 4) {
state = -1;
} else {
dimx = atoi(values[1].c_str());
dimy = atoi(values[2].c_str());
scene = new SWE_VtkScenarioVisInfo(dimx,dimy);
h = scene->h.elemVector();
u = scene->u.elemVector();
v = scene->v.elemVector();
b = scene->b.elemVector();
state = 5;
}
}
break;
// Data part
case 5:
// read grid data stored in VTK file
found = line.find(" 0 ");
if (found != string::npos && scene->dx <= 0.0f) {
stringExplode(line," ", &values);
scene->dx = (float) atof(values[0].c_str());
// TODO:
// --> this will change, if VTK files can have other origins than (0,0)
scene->bndPos[BND_LEFT] = 0.0;
scene->bndPos[BND_RIGHT] = dimx*scene->dx;
}
if (line.substr(0,2) == "0 " && scene->dy <= 0.0f) {
stringExplode(line," ", &values);
scene->dy = (float) atof(values[1].c_str());
// TODO:
// --> this will change, if VTK files can have other origins than (0,0)
scene->bndPos[BND_BOTTOM] = 0.0;
scene->bndPos[BND_TOP] = dimy*scene->dy;
}
found = line.find("scalars h");
if (found != string::npos) {
state = 10;
}
break;
case 10:
found = line.find("lookup_table");
if (found!=string::npos) {
state = 11;
offsetCount = 0;
}
break;
case 11:
// Read h-values
h[offsetCount - 1] = (float) atof(line.c_str());
if (offsetCount >= (dimx - 1)*(dimy - 1)) {
state = 12;
}
break;
case 12:
found = line.find("scalars u");
if (found!=string::npos) {
state = 20;
}
break;
case 20:
found = line.find("lookup_table");
if (found!=string::npos) {
state = 21;
offsetCount = 0;
}
break;
case 21:
// Read u-values
u[offsetCount - 1] = (float) atof(line.c_str());
if (offsetCount >= (dimx - 1)*(dimy - 1)) {
state = 22;
}
break;
case 22:
found = line.find("scalars v");
if (found!=string::npos) {
state = 30;
}
break;
case 30:
found = line.find("lookup_table");
if (found!=string::npos) {
state = 31;
offsetCount = 0;
}
break;
case 31:
// Read v-values
v[offsetCount - 1] = (float) atof(line.c_str());
if (offsetCount >= (dimx - 1)*(dimy - 1)) {
state = 32;
}
break;
case 32:
found = line.find("scalars b");
if (found!=string::npos) {
state = 40;
}
break;
case 40:
found = line.find("lookup_table");
if (found!=string::npos) {
state = 41;
offsetCount = 0;
}
break;
case 41:
// Read b-values
b[offsetCount - 1] = (float) atof(line.c_str());
h[offsetCount - 1] = h[offsetCount - 1] - b[offsetCount - 1];
if (offsetCount >= (dimx - 1)*(dimy - 1)) {
state = 42;
}
break;
default:
break;
}
}
std::cout << std::endl;
// Close file
file.close();
// delete allocated scene object
if (state >= 5 && state < 42)
delete scene;
// return NULL pointer in case of error
if (state < 42) {
std::cout << "Parsing Error. Omitting input file." << std::endl;
return NULL;
}
// std::cout << "Compute scaling Info for read file\n" << flush;
scene->computeHeightAtRest();
scene->computeScalingApproximation();
// return pointer to scene, if everything went OK
return scene;
}
/**
Computes a first approximation of the scaling values needed
for visualization.
Gets called after variables have been read from VTK file;
determines the average, mininimum and maximum values of the
bathymetry and water surface data.
Uses latter values to estimate the scaling factors.
*/
void SWE_VtkScenarioVisInfo::computeScalingApproximation() {
// Averages of B and (B + H)
float avgB, avgH;
// Minimum values
float minB, minH;
// Maximum values
float maxB, maxH;
int nx = h.getRows();
int ny = h.getCols();
int maxDim = (nx > ny) ? nx : ny;
// first, compute averages:
avgH = 0.0f;
avgB = 0.0f;
int cnt = 0;
for(int i=0; i<nx; i++)
for(int j=0; j<ny; j++)
if (h[i][j]> 0) {
// Update averages
avgH += (h[i][j] + b[i][j]);
avgB += b[i][j];
cnt++;
};
bAverage = avgB/cnt;
hAverage = avgH/cnt;
// then, conpute min and max values, using average values as initial guess
minB = bAverage;
maxB = bAverage;
minH = hAverage;
maxH = hAverage;
for(int i=0; i<nx; i++)
for(int j=0; j<ny; j++)
if (h[i][j]> 0) {
float bij = b[i][j];
float hbij = h[i][j] + bij;
// Update minima
minH = (hbij < minH) ? hbij : minH;
minB = (bij < minB) ? bij : minB;
// Update maxima
maxH = (hbij > maxH) ? hbij : maxH;
maxB = (bij > maxB) ? bij : maxB;
};
std::cout << "Computed min and max values for visualisation info: \n"
<< "h: max: " << maxH << ", min: " << minH << endl
<< "b: max: " << maxB << ", min: " << minB << endl
<< flush;
if (fabs(maxB - minB) > 0.0001f) {
bScale = (maxDim/20.0f)/(maxB - minB);
} else {
bScale = (maxDim/20.0f);
}
bOffset = bScale*(bAverage - minB) + maxDim/15.0f;
// alternative values
bScale = minB;
bOffset = bAverage;
if ((maxH - minH) < 0.0001f) {
hScale = 1.0f/(maxH- minH);
} else {
hScale = 1.0f;
}
hScale = maxDim*(hScale);
hOffset = bOffset + (maxDim/5.0f);
bScale = minH;
hOffset = hAverage;
std::cout << "Computed values for visualisation info: "
<< "average h: " << hAverage << "( bOffset:" << hOffset << ", scale: " << hScale << ");"
<< "average b: " << bAverage << "( bOffset:" << bOffset << ", scale: " << bScale << ");"
<< endl << flush;
}
#ifndef __SWE_VTK_SCENARIO_VISINFO_H
#define __SWE_VTK_SCENARIO_VISINFO_H
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Michael Bader, Kaveh Rahnema, Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#include "../tools/help.hh"
#include "SWE_VtkScenario.h"
#include "SWE_VisInfo.h"
/**
* Scenario "VTK File" incl. info for visualisation:
* extends Scenario SWE_VtkScenario
*/
class SWE_VtkScenarioVisInfo : public SWE_VtkScenario, public SWE_VisInfo {
public:
// SWE_VtkScenario does not offer a public constructor
// -> use this method to create a SWE_VtkScenario object
static SWE_VtkScenarioVisInfo* readVtkFile(char const * filename);
// Scaling factors for custom visualization
virtual float waterHeightAtRest() { return hAverage; };
virtual float waterDistanceFromGround() { return hOffset; };
virtual float waterVerticalScaling() { return hScale; };
virtual float bathyVerticalCenter() { return bAverage; };
virtual float bathyDistanceFromGround() { return bOffset; };
virtual float bathyVerticalScaling() { return bScale; };
protected:
SWE_VtkScenarioVisInfo(int nx, int ny);
void computeScalingApproximation();
float bAverage;
float hAverage;
float bScale;
float hScale;
float bOffset;
float hOffset;
};
#endif
...@@ -41,7 +41,7 @@ class SWE_RadialDamBreakScenario : public SWE_Scenario { ...@@ -41,7 +41,7 @@ class SWE_RadialDamBreakScenario : public SWE_Scenario {
public: public:
float getWaterHeight(float x, float y) { float getWaterHeight(float x, float y) {
return ( sqrt( (x-0.5f)*(x-0.5f) + (y-0.5f)*(y-0.5f) ) < 0.1f ) ? 12.0f: 10.0f; return ( sqrt( (x-0.5f)*(x-0.5f) + (y-0.5f)*(y-0.5f) ) < 0.1f ) ? 10.5f: 10.0f;
}; };
virtual BoundaryType getBoundaryType(BoundaryEdge edge) { return OUTFLOW; }; virtual BoundaryType getBoundaryType(BoundaryEdge edge) { return OUTFLOW; };
...@@ -58,7 +58,8 @@ class SWE_BathymetryDamBreakScenario : public SWE_Scenario { ...@@ -58,7 +58,8 @@ class SWE_BathymetryDamBreakScenario : public SWE_Scenario {
float getBathymetry(float x, float y) { float getBathymetry(float x, float y) {
return ( std::sqrt( (x-500.f)*(x-500.f) + (y-500.f)*(y-500.f) ) < 50.f ) ? -250.f: -260.f; return ( std::sqrt( (x-500.f)*(x-500.f) + (y-500.f)*(y-500.f) ) < 50.f ) ? -250.f: -260.f;
}; };
virtual float endSimulation() { return (float) 15; };
virtual float endSimulation() { return (float) 15; };
virtual BoundaryType getBoundaryType(BoundaryEdge edge) { return OUTFLOW; }; virtual BoundaryType getBoundaryType(BoundaryEdge edge) { return OUTFLOW; };
......
#ifndef __SWE_SIMPLE_SCENARIOS_VIS_H
#define __SWE_SIMPLE_SCENARIOS_VIS_H
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Michael Bader, Kaveh Rahnema, Tobias Schnabel
//
// SWE_CUDA is free software: you can redristribute 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_CUDA 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_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#include <math.h>
#include "SWE_simple_scenarios.h"
#include "SWE_VisInfo.h"
/**
* Scenario "Radial Dam Break":
* elevated water in the center of the domain
*/
class SWE_RadialDamBreakScenarioVisInfo
: public SWE_RadialDamBreakScenario,
public SWE_VisInfo {
virtual float waterVerticalScaling() { return 5.0f; };
/* use inherited default implementations */
};
/**
* Scenario "Splashing Pool with custom scaling":
* intial water surface has a fixed slope (diagonal to x,y)
* shows how to use custom scaling to enhance visualization
* results
*/
class SWE_SplashingPoolScenarioVisInfo
: public SWE_SplashingPoolScenario,
public SWE_VisInfo {
public:
float waterDistanceFromGround() { return 9.0f; };
float waterVerticalScaling() { return 5.0f; };
float bathyVerticalCenter() { return 0.0f; };
float bathyDistanceFromGround() { return 0.0f; };
float bathyVerticalScaling() { return 0.0f; };
virtual BoundaryType getBoundaryType(BoundaryEdge edge) { return OUTFLOW; };
};
#endif
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