HyPar
1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
|
Initialize the 2D shallow water equations module. More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <basic.h>
#include <arrayfunctions.h>
#include <physicalmodels/shallowwater2d.h>
#include <mpivars.h>
#include <hypar.h>
Go to the source code of this file.
Functions | |
double | ShallowWater2DComputeCFL (void *, void *, double, double) |
int | ShallowWater2DFlux (double *, double *, int, void *, double) |
int | ShallowWater2DSource (double *, double *, void *, void *, double) |
int | ShallowWater2DUpwindRoe (double *, double *, double *, double *, double *, double *, int, void *, double) |
int | ShallowWater2DUpwindLLF (double *, double *, double *, double *, double *, double *, int, void *, double) |
int | ShallowWater2DJacobian (double *, double *, void *, int, int, int) |
int | ShallowWater2DRoeAverage (double *, double *, double *, void *) |
int | ShallowWater2DLeftEigenvectors (double *, double *, void *, int) |
int | ShallowWater2DRightEigenvectors (double *, double *, void *, int) |
int | ShallowWater2DTopography (void *, void *, int, int, int *) |
int | ShallowWater2DSourceUpwindLLF (double *, double *, double *, double *, int, void *, double) |
int | ShallowWater2DSourceUpwindRoe (double *, double *, double *, double *, int, void *, double) |
int | ShallowWater2DModifiedSolution (double *, double *, int, void *, void *, double) |
int | ShallowWater2DWriteTopography (void *, void *, double) |
int | ShallowWater2DInitialize (void *s, void *m) |
Initialize the 2D shallow water equations module.
Definition in file ShallowWater2DInitialize.c.
double ShallowWater2DComputeCFL | ( | 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 ShallowWater2DComputeCFL.c.
int ShallowWater2DFlux | ( | 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}{cc} \left[\begin{array}{c} hu \\ hu^2 + \frac{1}{2} gh^2 \\ huv \end{array}\right] & {\rm dir} = x \\ \left[\begin{array}{c} hv \\ huv \\ hv^2 + \frac{1}{2} gh^2 \end{array}\right] & {\rm dir} = y \\ \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 |
s | Solver object of type HyPar |
t | Current time |
Definition at line 20 of file ShallowWater2DFlux.c.
int ShallowWater2DSource | ( | double * | source, |
double * | u, | ||
void * | s, | ||
void * | m, | ||
double | t | ||
) |
Compute the source terms for the 2D shallow water equations.
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 33 of file ShallowWater2DSource.c.
int ShallowWater2DUpwindRoe | ( | 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 2D 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 |
s | Solver object of type HyPar |
t | Current solution time |
Definition at line 31 of file ShallowWater2DUpwind.c.
int ShallowWater2DUpwindLLF | ( | 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 |
s | Solver object of type HyPar |
t | Current solution time |
Definition at line 118 of file ShallowWater2DUpwind.c.
int ShallowWater2DJacobian | ( | double * | Jac, |
double * | u, | ||
void * | p, | ||
int | dir, | ||
int | nvars, | ||
int | upw | ||
) |
Function to compute the flux Jacobian of the 2D 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 = 9 |
u | solution at a grid point (array of size nvar = 3) |
p | object containing the physics-related parameters |
dir | spatial dimension (x/y) |
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 ShallowWater2DJacobian.c.
int ShallowWater2DRoeAverage | ( | double * | uavg, |
double * | uL, | ||
double * | uR, | ||
void * | p | ||
) |
Compute the Roe-averaged state for the 2D shallow water equations. This function just calls the macro _ShallowWater2DRoeAverage_ and is not used by any functions within the 2D 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 ShallowWater2D with physics-related variables |
Definition at line 16 of file ShallowWater2DFunctions.c.
int ShallowWater2DLeftEigenvectors | ( | double * | u, |
double * | L, | ||
void * | p, | ||
int | dir | ||
) |
Compute the left eigenvections for the 2D shallow water equations. This function just calls the macro _ShallowWater2DLeftEigenvectors_ and is not used by any functions within the 2D 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 = 3^2 to save the matrix of left eigenvectors in (row-major format). |
p | Object of type ShallowWater2D with physics-related variables |
dir | Spatial dimension |
Definition at line 19 of file ShallowWater2DEigen.c.
int ShallowWater2DRightEigenvectors | ( | double * | u, |
double * | R, | ||
void * | p, | ||
int | dir | ||
) |
Compute the right eigenvections for the 2D shallow water equations. This function just calls the macro _ShallowWater2DRightEigenvectors_ and is not used by any functions within the 2D 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 = 3^2 to save the matrix of right eigenvectors in (row-major format). |
p | Object of type ShallowWater2D with physics-related variables |
dir | Spatial dimension |
Definition at line 38 of file ShallowWater2DEigen.c.
int ShallowWater2DTopography | ( | 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 ShallowWater2DTopography.c.
int ShallowWater2DSourceUpwindLLF | ( | 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 |
s | Solver object of type HyPar |
t | Current solution time |
Definition at line 22 of file ShallowWater2DSourceUpwind.c.
int ShallowWater2DSourceUpwindRoe | ( | 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 |
s | Solver object of type HyPar |
t | Current solution time |
Definition at line 64 of file ShallowWater2DSourceUpwind.c.
int ShallowWater2DModifiedSolution | ( | 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 2D shallow water equations.
Refer to:
uC | The modified solution (same array size and layout as u) |
u | The solution (conserved variables) |
d | Spatial dimension |
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
waqt | Current solution time |
Definition at line 21 of file ShallowWater2DModifiedSolution.c.
int ShallowWater2DWriteTopography | ( | 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 ShallowWater2DWriteTopography.c.
int ShallowWater2DInitialize | ( | void * | s, |
void * | m | ||
) |
Function to initialize the 2D shallow water equations (ShallowWater2D) 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 ShallowWater2DInitialize.c.