A small package including a one-dimensional well-balanced Shallow Water Equations solver.
Project description
Shallow Water Equations Solver
This package provides a well-balanced solver for the one-dimensional Saint-Venant equations, based on the principles outlined in this paper.
Usage
To utilize this package, you can call the plotSWE
function with the following parameters:
h, u = plotSWE(B, h0, u0, Nx, tEnd, timePoints, g=1, method='C')
Parameters:
- B (callable): Bottom topography function. This function defines the topographic profile and should take spatial coordinates as input and return the bottom elevation at those coordinates. In case of
method='A'
, should be an array of two callables, representing B and its derivative. - h0 (array): Initial water height profile. This should be an array of length
Nx
, representing the initial water height at different spatial locations. - u0 (array): Initial water velocity profile. Similar to h0, this should be an array of length
Nx
, representing the initial water velocity at different spatial locations. - Nx (int): Number of spatial grid points.
- tEnd (float): End time of the simulation. The simulation starts at time t=0.
- timePoints (list): List of time points at which you want to visualize the results.
- g (float, optional): Gravitational constant. Default is
1
. - method (str, optional): Method selection (
'A'
,'B'
or'C'
). Default is'C'
.
Returns:
- h (array): Array containing the water height profile at the final time point.
- u (array): Array containing the water velocity profile at the final time point.
Example:
from SWE_Solver import plotSWE
from math import sqrt
from scipy.special import erf
Nx = 100
B = lambda x: 1
f = lambda T: 1 + sqrt(3) / (1 - erf(-0.5 / 0.1)) * (erf((T - 0.5) / 0.1) - erf (-0.5 / 0.1))
h0 = [f(_/ (Nx-1)) for _ in range(Nx)]
u0 = [2.0 / h0[_] for _ in range(Nx)]
_ = plotSWE(B, h0, u0, Nx, tEnd=1.0, timePoints=[0.0, 0.1, 0.5, 1.0])
In this example, we're using a spatial grid with 100 points, running the simulation up to t=1
seconds, and visualizing the results at times 0.0
, 0.1
, 0.5
and 1.0
seconds, with gravitational constant g=1
(default value) and using method='C'
(default value).
This produces the result in the following figure.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
SWE_Solver-0.0.6.tar.gz
(7.4 kB
view hashes)
Built Distribution
Close
Hashes for SWE_Solver-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 390eea6d096f40c8539e55aed836e2d8db48000b00ecef9c6e39b131add1bad2 |
|
MD5 | cf0f652dd710da3d75aabca494e893f4 |
|
BLAKE2b-256 | b11f3cf5594c415d0c1006e96fbe68d6c177889800fdd881e7441146024df88b |