Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
SWE
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gaurav Kukreja
SWE
Commits
2d03faab
Commit
2d03faab
authored
Jul 18, 2012
by
bader
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added scenarios for SWE-OpenGL version
parent
1ed5fdb6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
1009 additions
and
0 deletions
+1009
-0
SWE_VisInfo.h
src/scenarios/SWE_VisInfo.h
+43
-0
SWE_VtkScenario.cpp
src/scenarios/SWE_VtkScenario.cpp
+426
-0
SWE_VtkScenario.h
src/scenarios/SWE_VtkScenario.h
+91
-0
SWE_VtkScenarioVisInfo.cpp
src/scenarios/SWE_VtkScenarioVisInfo.cpp
+325
-0
SWE_VtkScenarioVisInfo.h
src/scenarios/SWE_VtkScenarioVisInfo.h
+62
-0
SWE_simple_scenarios_vis.h
src/scenarios/SWE_simple_scenarios_vis.h
+62
-0
No files found.
src/scenarios/SWE_VisInfo.h
0 → 100644
View file @
2d03faab
#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
.
0
f
;
};
virtual
float
waterDistanceFromGround
()
{
return
10
.
0
f
;
};
virtual
float
waterVerticalScaling
()
{
return
10
.
0
f
;
};
virtual
float
bathyVerticalCenter
()
{
return
0
.
0
f
;
};
virtual
float
bathyDistanceFromGround
()
{
return
0
.
0
f
;
};
virtual
float
bathyVerticalScaling
()
{
return
10
.
0
f
;
};
};
#endif
src/scenarios/SWE_VtkScenario.cpp
0 → 100644
View file @
2d03faab
This diff is collapsed.
Click to expand it.
src/scenarios/SWE_VtkScenario.h
0 → 100644
View file @
2d03faab
#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
src/scenarios/SWE_VtkScenarioVisInfo.cpp
0 → 100644
View file @
2d03faab
#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.0
f
)
{
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.0
f
)
{
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.0
f
;
avgB
=
0.0
f
;
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.0001
f
)
{
bScale
=
(
maxDim
/
20.0
f
)
/
(
maxB
-
minB
);
}
else
{
bScale
=
(
maxDim
/
20.0
f
);
}
bOffset
=
bScale
*
(
bAverage
-
minB
)
+
maxDim
/
15.0
f
;
// alternative values
bScale
=
minB
;
bOffset
=
bAverage
;
if
((
maxH
-
minH
)
<
0.0001
f
)
{
hScale
=
1.0
f
/
(
maxH
-
minH
);
}
else
{
hScale
=
1.0
f
;
}
hScale
=
maxDim
*
(
hScale
);
hOffset
=
bOffset
+
(
maxDim
/
5.0
f
);
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
;
}
src/scenarios/SWE_VtkScenarioVisInfo.h
0 → 100644
View file @
2d03faab
#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
src/scenarios/SWE_simple_scenarios_vis.h
0 → 100644
View file @
2d03faab
#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
.
0
f
;
};
/* 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
.
0
f
;
};
float
waterVerticalScaling
()
{
return
5
.
0
f
;
};
float
bathyVerticalCenter
()
{
return
0
.
0
f
;
};
float
bathyDistanceFromGround
()
{
return
0
.
0
f
;
};
float
bathyVerticalScaling
()
{
return
0
.
0
f
;
};
virtual
BoundaryType
getBoundaryType
(
BoundaryEdge
edge
)
{
return
OUTFLOW
;
};
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment