HyPar
1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
|
Initialize all solvers. More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <tridiagLU.h>
#include <timeintegration.h>
#include <interpolation.h>
#include <firstderivative.h>
#include <secondderivative.h>
#include <mpivars.h>
#include <simulation_object.h>
#include <Python.h>
Go to the source code of this file.
Functions | |
int | ApplyBoundaryConditions (void *, void *, double *, double *, double) |
Applies the boundary conditions specified for each boundary zone. More... | |
int | ApplyIBConditions (void *, void *, double *, double) |
int | HyperbolicFunction (double *, double *, void *, void *, double, int, int(*)(double *, double *, int, void *, double), int(*)(double *, double *, double *, double *, double *, double *, int, void *, double)) |
int | ParabolicFunctionNC1Stage (double *, double *, void *, void *, double) |
int | ParabolicFunctionNC2Stage (double *, double *, void *, void *, double) |
int | ParabolicFunctionNC1_5Stage (double *, double *, void *, void *, double) |
int | ParabolicFunctionCons1Stage (double *, double *, void *, void *, double) |
int | SourceFunction (double *, double *, void *, void *, double) |
int | VolumeIntegral (double *, double *, void *, void *) |
int | BoundaryIntegral (void *, void *) |
int | CalculateConservationError (void *, void *) |
void | IncrementFilenameIndex (char *, int) |
int | NonLinearInterpolation (double *, void *, void *, double, int(*)(double *, double *, int, void *, double)) |
int | gpuHyperbolicFunction (double *, double *, void *, void *, double, int, int(*)(double *, double *, int, void *, double), int(*)(double *, double *, double *, double *, double *, double *, int, void *, double)) |
int | InitializeSolvers (void *s, int nsims) |
Initialize all solvers.
Definition in file InitializeSolvers.c.
int ApplyBoundaryConditions | ( | void * | s, |
void * | m, | ||
double * | x, | ||
double * | xref, | ||
double | waqt | ||
) |
Applies the boundary conditions specified for each boundary zone.
The solver object (of type HyPar) contains an oject of type DomainBoundary that contains all the boundary information (dimension, extent, face, type, etc). This function iterates through each of the boundary zones (HyPar::boundary[HyPar::nBoundaryZones]) and calls the corresponding boundary condition function.
The variable flag indicates if the array x is the solution, or a delta-solution (from implicit time-integration methods).
s | Object of type HyPar containing solver-related variables |
m | Object of type MPIVariables containing MPI-related variables |
x | The solution vector on which the boundary conditions are to be applied |
xref | Reference solution vector, if needed |
waqt | Current simulation time |
Definition at line 28 of file ApplyBoundaryConditions.c.
int ApplyIBConditions | ( | void * | s, |
void * | m, | ||
double * | x, | ||
double | waqt | ||
) |
Call the physics-specific function that applies the immersed boundary conditions on the immersed boundary points.
s | Object of type HyPar containing solver-related variables |
m | Object of type MPIVariables containing MPI-related variables |
x | The solution vector to apply immersed BCs on |
waqt | Current simulation time |
Definition at line 14 of file ApplyIBConditions.c.
int HyperbolicFunction | ( | double * | hyp, |
double * | u, | ||
void * | s, | ||
void * | m, | ||
double | t, | ||
int | LimFlag, | ||
int(*)(double *, double *, int, void *, double) | FluxFunction, | ||
int(*)(double *, double *, double *, double *, double *, double *, int, void *, double) | UpwindFunction | ||
) |
This function computes the hyperbolic term of the governing equations, expressed as follows:-
\begin{equation} {\bf F} \left({\bf u}\right) = \sum_{d=0}^{D-1} \frac {\partial {\bf f}_d\left({\bf u}\right)} {\partial x_d} \end{equation}
using a conservative finite-difference discretization is space:
\begin{equation} \hat{\bf F} \left({\bf u}\right) = \sum_{d=0}^{D-1} \frac {1} {\Delta x_d} \left[ \hat{\bf f}_{d,j+1/2} - \hat{\bf f}_{d,j-1/2} \right] \end{equation}
where \(d\) denotes the spatial dimension, \(D\) denotes the total number of spatial dimensions, the hat denotes the discretized quantity, and \(j\) is the grid coordinate along dimension \(d\). The approximation to the flux function \({\bf f}_d\) at the interfaces \(j\pm1/2\), denoted by \(\hat{\bf f}_{d,j\pm 1/2}\), are computed using the function ReconstructHyperbolic().
hyp | Array to hold the computed hyperbolic term (shares the same layout as u |
u | Solution array |
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
t | Current simulation time |
LimFlag | Flag to indicate if the nonlinear coefficients for solution-dependent interpolation method should be recomputed (see ReconstructHyperbolic() for an explanation on why this is needed) |
FluxFunction | Function pointer to the flux function for the hyperbolic term |
UpwindFunction | Function pointer to the upwinding function for the hyperbolic term |
Definition at line 31 of file HyperbolicFunction.c.
int ParabolicFunctionNC1Stage | ( | double * | par, |
double * | u, | ||
void * | s, | ||
void * | m, | ||
double | t | ||
) |
Evaluate the parabolic term using a conservative finite-difference spatial discretization: The parabolic term is assumed to be of the form:
\begin{equation} {\bf P}\left({\bf u}\right) = \sum_{d=0}^{D-1} \frac {\partial^2 {\bf g}_d\left(\bf u\right)} {\partial x_d^2}, \end{equation}
which is discretized at a grid point as:
\begin{equation} \left.{\bf P}\left({\bf u}\right)\right|_j = \sum_{d=0}^{D-1} \frac { \mathcal{L}_d \left[ {\bf g}_d \right] } {\Delta x_d^2}, \end{equation}
where \(d\) is the spatial dimension index, \(D\) is the total number of spatial dimensions (HyPar::ndims), and \(j\) is the grid index along \(d\). \(\mathcal{L}_d\) represents the finite-difference approximation to the Laplacian along the \(d\) spatial dimension, computed using HyPar::SecondDerivativePar.
Note: this form of the parabolic term does not allow for cross-derivatives.
To use this form of the parabolic term:
par | array to hold the computed parabolic term |
u | solution |
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
t | Current simulation time |
Definition at line 31 of file ParabolicFunctionNC1Stage.c.
int ParabolicFunctionNC2Stage | ( | double * | par, |
double * | u, | ||
void * | s, | ||
void * | m, | ||
double | t | ||
) |
Evaluate the parabolic term using a "1.5"-stage finite-difference spatial discretization: The parabolic term is assumed to be of the form:
\begin{equation} {\bf P}\left({\bf u}\right) = \sum_{d1=0}^{D-1}\sum_{d2=0}^{D-1} \frac {\partial^2 h_{d1,d2}\left(\bf u\right)} {\partial x_{d1} \partial x_{d2}}, \end{equation}
where \(d1\) and \(d2\) are spatial dimension indices, and \(D\) is the total number of spatial dimensions (HyPar::ndims). This term is discretized at a grid point as:
\begin{equation} \left.{\bf P}\left({\bf u}\right)\right|_j = \sum_{d1=0}^{D-1} \sum_{d2=0}^{D-1} \frac { \mathcal{D}_{d1}\mathcal{D}_{d2} \left[ {\bf h}_{d1,d2} \right] } {\Delta x_{d1} \Delta x_{d2}}, \end{equation}
where \(\mathcal{D}\) denotes the finite-difference approximation to the first derivative. Each of the first derivative approximations are \(\mathcal{D}_{d1}\) and \(\mathcal{D}_{d2}\) are computed separately, and thus the cross-derivative is evaluated in two steps using HyPar::FirstDerivativePar.
Notes:
To use this form of the parabolic term:
par | array to hold the computed parabolic term |
u | solution |
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
t | Current simulation time |
Definition at line 40 of file ParabolicFunctionNC2Stage.c.
int ParabolicFunctionNC1_5Stage | ( | double * | par, |
double * | u, | ||
void * | s, | ||
void * | m, | ||
double | t | ||
) |
Evaluate the parabolic term using a "1.5"-stage finite-difference spatial discretization: The parabolic term is assumed to be of the form:
\begin{equation} {\bf P}\left({\bf u}\right) = \sum_{d1=0}^{D-1}\sum_{d2=0}^{D-1} \frac {\partial^2 h_{d1,d2}\left(\bf u\right)} {\partial x_{d1} \partial x_{d2}}, \end{equation}
where \(d1\) and \(d2\) are spatial dimension indices, and \(D\) is the total number of spatial dimensions (HyPar::ndims). This term is discretized at a grid point as:
\begin{equation} \left.{\bf P}\left({\bf u}\right)\right|_j = \sum_{d1=0}^{D-1} \sum_{d2=0}^{D-1} \frac { \mathcal{D}_{d1}\mathcal{D}_{d2} \left[ {\bf h}_{d1,d2} \right] } {\Delta x_{d1} \Delta x_{d2}}, \end{equation}
where \(\mathcal{D}\) denotes the finite-difference approximation to the first derivative.
Note: this form of the parabolic term does allow for cross-derivatives ( \( d1 \ne d2 \)).
To use this form of the parabolic term:
par | array to hold the computed parabolic term |
u | solution |
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
t | Current simulation time |
Definition at line 35 of file ParabolicFunctionNC1.5Stage.c.
int ParabolicFunctionCons1Stage | ( | double * | par, |
double * | u, | ||
void * | s, | ||
void * | m, | ||
double | t | ||
) |
Evaluate the parabolic term using a conservative finite-difference spatial discretization: The parabolic term is assumed to be of the form:
\begin{equation} {\bf P}\left({\bf u}\right) = \sum_{d=0}^{D-1} \frac {\partial^2 {\bf g}_d\left(\bf u\right)} {\partial x_d^2}, \end{equation}
which is discretized at a grid point as:
\begin{equation} \left.{\bf P}\left({\bf u}\right)\right|_j = \sum_{d=0}^{D-1} \frac { \hat{\bf g}_{j+1/2} - \hat{\bf g}_{j-1/2} } {\Delta x_d^2}, \end{equation}
where \(d\) is the spatial dimension index, \(D\) is the total number of spatial dimensions (HyPar::ndims), and \(j\) is the grid index along \(d\). \(\hat{\bf g}_d\) is the numerical approximation to the second primitive of \({\bf g}_d\left({\bf u}\right)\), computed using HyPar::InterpolateInterfacesPar.
Note: this form of the parabolic term does not allow for cross-derivatives.
To use this form of the parabolic term:
Reference: Liu, Y., Shu, C.-W., Zhang, M., "High order finite difference WENO schemes for nonlinear degenerate parabolic equations", SIAM J. Sci. Comput., 33 (2), 2011, pp. 939-965, http://dx.doi.org/10.1137/100791002
par | array to hold the computed parabolic term |
u | solution |
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
t | Current simulation time |
Definition at line 34 of file ParabolicFunctionCons1Stage.c.
int SourceFunction | ( | double * | source, |
double * | u, | ||
void * | s, | ||
void * | m, | ||
double | t | ||
) |
Evaluate the source term \({\bf S}\left({\bf u}\right)\) in the governing equation, if the physical model specifies one. In addition, if the simulation requires a sponge boundary treatment, the sponge BC function is called.
source | the computed source term |
u | solution |
s | solver object of type HyPar |
m | MPI object of type MPIVariables |
t | Current simulation time |
Definition at line 22 of file SourceFunction.c.
int VolumeIntegral | ( | double * | VolumeIntegral, |
double * | u, | ||
void * | s, | ||
void * | m | ||
) |
Compute the volume integral of the solution.
VolumeIntegral | The computed volume integral |
u | Solution |
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
Definition at line 14 of file VolumeIntegral.c.
int BoundaryIntegral | ( | void * | s, |
void * | m | ||
) |
Computes the flux integral over the boundary. The local flux integral (on this processor) is computed for physical as well as MPI boundaries. The global boundary integral is computed by summing the local integrals over all the processors, since the contributions from the MPI boundaries cancel out.
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
Definition at line 17 of file BoundaryIntegral.c.
int CalculateConservationError | ( | void * | s, |
void * | m | ||
) |
Calculates the error (L2) in conservation by computing the difference between the initial volume integral of the solution, and the sum of the current volume integral and the time integral of the boundary flux from the start of the simulation to the current simulation time.
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
Definition at line 16 of file CalculateConservationError.c.
void IncrementFilenameIndex | ( | char * | f, |
int | len | ||
) |
Increment the output filename of the form op_nnnnn.dat by 1, i.e., the number represented by the string nnnnn is incremented by 1.
Increment a character string representing an integer by 1. For example: "00002" -> "00003"; "3421934" -> "3421935"; "999" -> "000". The string can be of arbitrary length.
f | Character string representing the integer |
len | Length of the string |
Definition at line 46 of file IncrementFilename.c.
int NonLinearInterpolation | ( | double * | u, |
void * | s, | ||
void * | m, | ||
double | t, | ||
int(*)(double *, double *, int, void *, double) | FluxFunction | ||
) |
Compute the interpolation coefficients of a nonlinear interpolation method, based on the smoothness of the flux function of the solution passed as an argument. This function is provided separately so that these coefficients can be pre-computed and stored for future use.
In the implementation of non-linear methods (such as WENO5), the calculation of the non-linear coefficients, and the actual evaluation of the interpolant are separated into different functions. This provides flexibility on when the nonlinear coefficients are evaluated. Some scenarios are as follows:
u | Solution array |
s | Solver object of type HyPar |
m | MPI object of type MPIVariables |
t | Current solution time |
FluxFunction | The flux function \({\bf f}_d\left({\bf u}\right)\), whose properties (typically smoothness) is used to evaluate the nonlinear coefficients |
Definition at line 28 of file NonLinearInterpolation.c.
int gpuHyperbolicFunction | ( | double * | , |
double * | , | ||
void * | , | ||
void * | , | ||
double | , | ||
int | , | ||
int(*)(double *, double *, int, void *, double) | , | ||
int(*)(double *, double *, double *, double *, double *, double *, int, void *, double) | |||
) |
int InitializeSolvers | ( | void * | s, |
int | nsims | ||
) |
This function initializes all solvers-specific function pointers depending on user input. The specific functions used for spatial discretization, time integration, and solution output are set here.
s | Array of simulation objects of type SimulationObject |
nsims | number of simulation objects |
Definition at line 52 of file InitializeSolvers.c.