HyPar
1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
|
Initialize the 1D shallow water equations module. More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <physicalmodels/shallowwater1d.h>
#include <mpivars.h>
#include <hypar.h>
Go to the source code of this file.
Functions | |
double | ShallowWater1DComputeCFL (void *, void *, double, double) |
int | ShallowWater1DFlux (double *, double *, int, void *, double) |
int | ShallowWater1DSource (double *, double *, void *, void *, double) |
int | ShallowWater1DUpwindRoe (double *, double *, double *, double *, double *, double *, int, void *, double) |
int | ShallowWater1DUpwindLLF (double *, double *, double *, double *, double *, double *, int, void *, double) |
int | ShallowWater1DJacobian (double *, double *, void *, int, int, int) |
int | ShallowWater1DRoeAverage (double *, double *, double *, void *) |
int | ShallowWater1DLeftEigenvectors (double *, double *, void *, int) |
int | ShallowWater1DRightEigenvectors (double *, double *, void *, int) |
int | ShallowWater1DTopography (void *, void *, int, int, int *) |
int | ShallowWater1DSourceUpwindLLF (double *, double *, double *, double *, int, void *, double) |
int | ShallowWater1DSourceUpwindRoe (double *, double *, double *, double *, int, void *, double) |
int | ShallowWater1DModifiedSolution (double *, double *, int, void *, void *, double) |
int | ShallowWater1DWriteTopography (void *, void *, double) |
int | ShallowWater1DInitialize (void *s, void *m) |
Initialize the 1D shallow water equations module.
Definition in file ShallowWater1DInitialize.c.
double ShallowWater1DComputeCFL | ( | void * | s, |
void * | m, | ||
double | dt, | ||
double | t | ||
) |
Computes the maximum CFL number over the domain. Note that the CFL is computed over the local domain on this processor only.
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
dt | Time step size for which to compute the CFL |
t | Time |
Definition at line 17 of file ShallowWater1DComputeCFL.c.
int ShallowWater1DFlux | ( | double * | f, |
double * | u, | ||
int | dir, | ||
void * | s, | ||
double | t | ||
) |
Compute the hyperbolic flux over the local domain.
\begin{equation} {\bf F}\left({\bf u}\right) = \left[\begin{array}{c} hu \\ hu^2 + \frac{1}{2} gh^2 \end{array}\right] \end{equation}
f | Array to hold the computed flux (same size and layout as u) |
u | Array containing the conserved solution |
dir | Spatial dimension (unused since this is a 1D system) |
s | Solver object of type HyPar |
t | Current time |
Definition at line 16 of file ShallowWater1DFlux.c.
int ShallowWater1DSource | ( | double * | source, |
double * | u, | ||
void * | s, | ||
void * | m, | ||
double | t | ||
) |
Compute the source terms for the 1D shallow water equations. The source term is computed according to the balanced formulation introduced in the reference below. The source term is reformulated and "discretized" in a similar fashion as the hyperbolic flux to ensure that the hydrostatic balance is maintained to machine precision.
source | Computed source terms (array size & layout same as u) |
u | Solution (conserved variables) |
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
t | Current solution time |
Definition at line 25 of file ShallowWater1DSource.c.
int ShallowWater1DUpwindRoe | ( | double * | fI, |
double * | fL, | ||
double * | fR, | ||
double * | uL, | ||
double * | uR, | ||
double * | u, | ||
int | dir, | ||
void * | s, | ||
double | t | ||
) |
Roe's upwinding scheme.
\begin{equation} {\bf f}_{j+1/2} = \frac{1}{2}\left[ {\bf f}_{j+1/2}^L + {\bf f}_{j+1/2}^R - \left| A\left({\bf u}_{j+1/2}^L,{\bf u}_{j+1/2}^R\right) \right| \left( {\bf u}_{j+1/2}^R - {\bf u}_{j+1/2}^L \right)\right] \end{equation}
This upwinding scheme is modified for the balanced discretization of the 1D shallow water equations. See the following reference:
fI | Computed upwind interface flux |
fL | Left-biased reconstructed interface flux |
fR | Right-biased reconstructed interface flux |
uL | Left-biased reconstructed interface solution |
uR | Right-biased reconstructed interface solution |
u | Cell-centered solution |
dir | Spatial dimension (unused since this is a 1D system) |
s | Solver object of type HyPar |
t | Current solution time |
Definition at line 31 of file ShallowWater1DUpwind.c.
int ShallowWater1DUpwindLLF | ( | double * | fI, |
double * | fL, | ||
double * | fR, | ||
double * | uL, | ||
double * | uR, | ||
double * | u, | ||
int | dir, | ||
void * | s, | ||
double | t | ||
) |
Characteristic-based local Lax-Friedrich upwinding scheme.
\begin{align} \alpha_{j+1/2}^{k,L} &= \sum_{k=1}^2 {\bf l}_{j+1/2}^k \cdot {\bf f}_{j+1/2}^{k,L}, \\ \alpha_{j+1/2}^{k,R} &= \sum_{k=1}^2 {\bf l}_{j+1/2}^k \cdot {\bf f}_{j+1/2}^{k,R}, \\ v_{j+1/2}^{k,L} &= \sum_{k=1}^2 {\bf l}_{j+1/2}^k \cdot {\bf u}_{j+1/2}^{k,L}, \\ v_{j+1/2}^{k,R} &= \sum_{k=1}^2 {\bf l}_{j+1/2}^k \cdot {\bf u}_{j+1/2}^{k,R}, \\ \alpha_{j+1/2}^k &= \frac{1}{2}\left[ \alpha_{j+1/2}^{k,L} + \alpha_{j+1/2}^{k,R} - \left(\max_{\left[j,j+1\right]} \lambda\right) \left( v_{j+1/2}^{k,R} - v_{j+1/2}^{k,L} \right) \right], \\ {\bf f}_{j+1/2} &= \sum_{k=1}^2 \alpha_{j+1/2}^k {\bf r}_{j+1/2}^k \end{align}
where \({\bf l}\), \({\bf r}\), and \(\lambda\) are the left-eigenvectors, right-eigenvectors and eigenvalues. The subscripts denote the grid locations.
This upwinding scheme is modified for the balanced discretization of the 1D shallow water equations. See the following reference:
fI | Computed upwind interface flux |
fL | Left-biased reconstructed interface flux |
fR | Right-biased reconstructed interface flux |
uL | Left-biased reconstructed interface solution |
uR | Right-biased reconstructed interface solution |
u | Cell-centered solution |
dir | Spatial dimension (unused since this is a 1D system) |
s | Solver object of type HyPar |
t | Current solution time |
Definition at line 114 of file ShallowWater1DUpwind.c.
int ShallowWater1DJacobian | ( | double * | Jac, |
double * | u, | ||
void * | p, | ||
int | dir, | ||
int | nvars, | ||
int | upw | ||
) |
Function to compute the flux Jacobian of the 1D shallow water equations, given the solution at a grid point. The Jacobian is square matrix of size nvar=2, and is returned as a 1D array (double) of 4 elements in row-major format.
Jac | Jacobian matrix: 1D array of size nvar^2 = 4 |
u | solution at a grid point (array of size nvar = 2) |
p | object containing the physics-related parameters |
dir | dimension (x/y/z) (not used, since this is 1D system) |
nvars | number of vector components |
upw | 0 -> send back complete Jacobian, 1 -> send back Jacobian of right(+)-moving flux, -1 -> send back Jacobian of left(-)-moving flux |
Definition at line 14 of file ShallowWater1DJacobian.c.
int ShallowWater1DRoeAverage | ( | double * | uavg, |
double * | uL, | ||
double * | uR, | ||
void * | p | ||
) |
Compute the Roe-averaged state for the 1D shallow water equations. This function just calls the macro _ShallowWater1DRoeAverage_ and is not used by any functions within the 1D shallow water module. However, it's necessary to define it and provide it to the the solver object (HyPar) so that it can then send it to interpolation functions for a characteristic-based reconstruction.
uavg | The computed Roe-averaged state |
uL | Left state (conserved variables) |
uR | Right state (conserved variables) |
p | Object of type ShallowWater1D with physics-related variables |
Definition at line 16 of file ShallowWater1DFunctions.c.
int ShallowWater1DLeftEigenvectors | ( | double * | u, |
double * | L, | ||
void * | p, | ||
int | dir | ||
) |
Compute the left eigenvections for the 1D shallow water equations. This function just calls the macro _ShallowWater1DLeftEigenvectors_ and is not used by any functions within the 1D shallow water module. However, it's necessary to define it and provide it to the the solver object (HyPar) so that it can then send it to interpolation functions for a characteristic-based reconstruction.
u | Conserved solution at a grid point |
L | Array of size nvar^2 = 2^2 to save the matrix of left eigenvectors in (row-major format). |
p | Object of type ShallowWater1D with physics-related variables |
dir | Spatial dimension (not used, since this is a 1D system) |
Definition at line 19 of file ShallowWater1DEigen.c.
int ShallowWater1DRightEigenvectors | ( | double * | u, |
double * | R, | ||
void * | p, | ||
int | dir | ||
) |
Compute the right eigenvections for the 1D shallow water equations. This function just calls the macro _ShallowWater1DRightEigenvectors_ and is not used by any functions within the 1D shallow water module. However, it's necessary to define it and provide it to the the solver object (HyPar) so that it can then send it to interpolation functions for a characteristic-based reconstruction.
u | Conserved solution at a grid point |
R | Array of size nvar^2 = 2^2 to save the matrix of right eigenvectors in (row-major format). |
p | Object of type ShallowWater1D with physics-related variables |
dir | Spatial dimension (not used, since this is a 1D system) |
Definition at line 38 of file ShallowWater1DEigen.c.
int ShallowWater1DTopography | ( | void * | s, |
void * | m, | ||
int | idx, | ||
int | nsims, | ||
int * | dim_topo | ||
) |
Set the bottom topography over the domain - reads the topography data from a file, if available, else sets it to a constant
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
idx | Index of this simulation |
nsims | Total number of simulations |
dim_topo | Grid dimensions of the advection field stored in file |
Definition at line 20 of file ShallowWater1DTopography.c.
int ShallowWater1DSourceUpwindLLF | ( | double * | fI, |
double * | fL, | ||
double * | fR, | ||
double * | u, | ||
int | dir, | ||
void * | s, | ||
double | t | ||
) |
Compute the "upwind" source term in the balanced formulation introduced in the reference below. The "upwind" state is just the arithmetic average of the left and right states.
fI | Computed interface source term ("upwinded") |
fL | Left-biased interface source term |
fR | Right-biased interface source term |
u | Solution (conserved variables) |
dir | Spatial dimension (unused since this is a 1D case) |
s | Solver object of type HyPar |
t | Current solution time |
Definition at line 22 of file ShallowWater1DSourceUpwind.c.
int ShallowWater1DSourceUpwindRoe | ( | double * | fI, |
double * | fL, | ||
double * | fR, | ||
double * | u, | ||
int | dir, | ||
void * | s, | ||
double | t | ||
) |
Compute the "upwind" source term in the balanced formulation introduced in the reference below. The "upwind" state is just the arithmetic average of the left and right states.
fI | Computed interface source term ("upwinded") |
fL | Left-biased interface source term |
fR | Right-biased interface source term |
u | Solution (conserved variables) |
dir | Spatial dimension (unused since this is a 1D case) |
s | Solver object of type HyPar |
t | Current solution time |
Definition at line 64 of file ShallowWater1DSourceUpwind.c.
int ShallowWater1DModifiedSolution | ( | double * | uC, |
double * | u, | ||
int | d, | ||
void * | s, | ||
void * | m, | ||
double | waqt | ||
) |
Compute the modified solution for the upwinding step in a balanced conservative finite-difference algorithm for the 1D shallow water equations.
Refer to:
uC | The modified solution (same array size and layout as u) |
u | The solution (conserved variables) |
d | Spatial dimension (unused since this is a 1D system) |
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
waqt | Current solution time |
Definition at line 21 of file ShallowWater1DModifiedSolution.c.
int ShallowWater1DWriteTopography | ( | void * | s, |
void * | m, | ||
double | a_t | ||
) |
Write out the topography data to file
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
a_t | Current simulation time |
Definition at line 17 of file ShallowWater1DWriteTopography.c.
int ShallowWater1DInitialize | ( | void * | s, |
void * | m | ||
) |
Function to initialize the 1D shallow water equations (ShallowWater1D) module: Sets the default parameters, read in and set physics-related parameters, and set the physics-related function pointers in HyPar.
s | Solver object of type HyPar |
m | Object of type MPIVariables containing MPI-related info |
Definition at line 37 of file ShallowWater1DInitialize.c.