and in the file ```./ExaHyPE/Makefile``` comment out all lines containing a ```-lrt```
and in the file ```./ExaHyPE/Makefile``` comment out all lines containing a ```-lrt```
There currently is no support for Windows, please use a virtual machine like [VirtualBox](https://www.virtualbox.org/)
There currently is no support for Windows, please use a virtual machine like [VirtualBox](https://www.virtualbox.org/)
## SWE Tutorial ##
# The Shallow Water Equations
The system of hyperbolic PDEs we regard are the Shallow Water Equations ([wiki](https://en.wikipedia.org/wiki/Shallow_water_equations))
The Shallow Water Equations (SWE)model the flow of flat water. The equations neglect any vertical velocities, which is as sufficient approximation as long as the the height of the water is significantly smaller than the regarded domain. We thus only need to consider the water height $`h`$ and velocities in $`x`$ any $`y`$ dimension, $`u`$ and $`v`$.
The flux models the conservation of mass and momentum and considers hydrostatic pressure. The gravitational constant g will be set to 1.
The eigenvalues of the PDE system are needed later on for the computation of an admissible time step size. For the SWE in two dimension they are:
```math
u\textrm{, }u-\sqrt{g\cdot h}\textrm{ and } u+\sqrt{g\cdot h}
```
# Setting up the specification file
After the equation is defined we need to set up the specification file which for all applications carries the suffix \*.exahype. Start from the following template for an application that is solved by the ADER-DG method.
disable-metadata-exchange-in-batched-time-steps = off
double-compression = 0.0
spawn-double-compression-as-background-thread = off
end global-optimisation
/*Defines the hyperbolic PDE*/
solver ADER-DG ADERSolver
variables const = h:1,p:2
order const = ##polynomial order of the simulation
/* 27 points: 0.05, 9 points: 0.15 */
maximum-mesh-size = ##mesh size
time-stepping = globalfixed
type const = nonlinear
terms const = ##PDE terms, ie fluxes, sources etc
optimisation const = generic
language const = C
/*##Add plotters here */
/*plot vtk::Cartesian::vertices::ascii VtkWriter
variables const = ##Number of variables to be plotted
time = ##Start time of the plotter
repeat = ##Plotting interval
output = ##File suffix
end plot */
end solver
end exahype-project
```
Set up a new directory *SWE_Test* in ApplicationExamples and copy the template there and name it SWE_ADERDG.exahype.
In this file all place holders are marked by ## and need to be filled to get a working application. (All other options are only used for optimizations and don't need to be touched or understood):
## `exahype-project`
* The name of the project. We use SWE.
```javascript
exahype-project SWE
```
## `output-directory const`
* Defines where the the code body will be generated relative to the root directory
* In our case we use *./ApplicationExamples/SWE_Test*
* Here we define the number of dimensions, the simulated domain and the physical end time of the application
* The SWE are defined in two dimensions we want to do our simulation on the cube $`[-0.5,0.5]^2`$ and for one second:
```javascript
computational-domain
dimension const = 2
width = 1.0, 1.0
offset = -0.5, -0.5
end-time = 1.0
end computational-domain
```
## `solver ADER-DG` ...
* This region defines the characteristics of the simulated PDE and the used solver.
* `variables const` By lokking at the formula you see that the SWE consist of 3 quantities $'h,hu,hv'$ which we will denote with h and a vector p of length 2.
* `order const` The polynomial degreee of the high order representation. We'll use order 3.
* `maximum-mesh-size` The maximum size of a single cell. ExaHyPE always has to hold a power of 3 cells in one dimension<sup>1</sup>. By setting this value you define an lower limit for the number of cells which is the rounded up to the next power of 3. For our example setting `maximum-mesh-size` to 0.05 gives us a theoretical number of 20 cells in one dimension. The next power of three is 27, so our mesh will end up with 27 cells in each dimension and a mesh size of $`\frac{1}{27}`$.
* `type const` Here you can choose between a linear or nonlinear PDE. SWE are nonlinear (as the flux is).
* `terms const` The type of terms that occur in the PDE system. SWE only hold a flux.
```javascript
solver ADER-DG SWE_ADERDG
variables const = h:1,p:2
order const = 3
/* 27 points: 0.05, 9 points: 0.15 */
maximum-mesh-size = 0.05
time-stepping = globalfixed
type const = nonlinear
terms const = flux
optimisation const = generic
language const = C
end solver
```
<sup>1</sup> The explanation for this takes too long at this point, but believe me there is a reason.
## Adding a plotter
* In this example we add a simple vtk output plotter which is sufficient for our needs.
* Uncomment the plotter lines after `language const` and before `end solver` and fill in the missing information:
```javascript
plot vtk::Cartesian::vertices::ascii VtkWriter
variables const = 3
time = 0.0
repeat = 1e-2
output = ./swe
end plot
```
* This results in a writer plotting all 3 variables every 0.02 seconds starting at time 0. The files will have a prefix swe and be placed in the project directory.
# Run the Toolkit
To generate the code body apply the toolkit to the specification file we just created. Go back to the ExaHyPE root directory and hit :
The eigenvalues can directly be taken from upper mathematical formulation. They need to passed with respect to the dimension defined by the argument `const int d`. For $`d=0`$ in x and $`d=1`$ in y (in 3D we additionally get $`d=2`$ in z).
In our case d defines the considered velocity field.
```c++
void SWE::SWE_ADERDG::eigenvalues(const double* const Q,const int d,double* lambda) {
This method implements conditions that are applied along the boundary of the domain.
The engine passes the fields `stateIn` and `fluxIn` which hold the respective state and flux of the simulated domain.
In this short example we implement reflecting boundary conditions. For SWE this means we have to invert the velocity vector along the normal of the interface. As our mesh is Cartesian, the normal can be defined by the single index where it is one `const int normalNonZero`.
The state can then be inverted by:
```c++
void SWE::SWE_ADERDG::boundaryValues(const double* const x,const double t,const double dt,const int faceIndex,const int direction,