HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
2D Euler Equations - Riemann Problem Case 4

Location: hypar/Examples/2D/NavierStokes2D/Riemann2DCase4 (This directory contains all the input files needed to run this case. If there is a Run.m, run it in MATLAB to quickly set up, run, and visualize the example).

Governing equations: 2D Euler Equations (navierstokes2d.h - By default, NavierStokes2D::Re is set to -1 which makes the code skip the parabolic terms, i.e., the 2D Euler equations are solved.)

Reference:

  • P. Lax and X.-D. Liu, "Solution of two-dimensional Riemann problems of gas dynamics by positive schemes," SIAM J Sci Comp 19 (1998), 319–340.

Domain: \(-0.5 \le x,y \le 0.5\), "extrapolate" (_EXTRAPOLATE_) boundary conditions.

Initial solution: see Case 4 in the reference.

Numerical method:

Input files required:

solver.inp

begin
ndims 2
nvars 4
size 201 201
iproc 2 2
ghost 3
n_iter 250
time_scheme rk
time_scheme_type ssprk3
hyp_space_scheme weno5
hyp_interp_type characteristic
conservation_check yes
dt 0.001
screen_op_iter 5
file_op_iter 25
op_file_format tecplot2d
op_overwrite no
model navierstokes2d
end

boundary.inp

4
extrapolate 0 1 0 0 -0.5 0.5
extrapolate 0 -1 0 0 -0.5 0.5
extrapolate 1 1 -0.5 0.5 0 0
extrapolate 1 -1 -0.5 0.5 0 0

physics.inp

begin
gamma 1.4
upwinding rf-char
end

weno.inp (optional)

begin
mapped 1
borges 0
yc 0
no_limiting 0
epsilon 0.000001
p 2.0
rc 0.3
xi 0.001
end

To generate initial.inp, compile and run the following code in the run directory.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main(){
double GAMMA = 1.4;
int NI=101,NJ=101,ndims=2;
char ip_file_type[50];
strcpy(ip_file_type,"ascii");
FILE *in, *out;
printf("Reading file \"solver.inp\"...\n");
in = fopen("solver.inp","r");
if (!in) printf("Error: Input file \"solver.inp\" not found. Default values will be used.\n");
else {
char word[500];
fscanf(in,"%s",word);
if (!strcmp(word, "begin")){
while (strcmp(word, "end")){
fscanf(in,"%s",word);
if (!strcmp(word, "ndims")) fscanf(in,"%d",&ndims);
else if (!strcmp(word, "size")) {
fscanf(in,"%d",&NI);
fscanf(in,"%d",&NJ);
} else if (!strcmp(word, "ip_file_type")) fscanf(in,"%s",ip_file_type);
}
} else printf("Error: Illegal format in solver.inp. Crash and burn!\n");
}
fclose(in);
if (ndims != 2) {
printf("ndims is not 2 in solver.inp. this code is to generate 2D initial conditions\n");
return(0);
}
printf("Grid:\t\t\t%d X %d\n",NI,NJ);
int i,j;
double dx = 1.0 / ((double)(NI-1));
double dy = 1.0 / ((double)(NJ-1));
double *x, *y, *u0, *u1, *u2, *u3;
x = (double*) calloc (NI , sizeof(double));
y = (double*) calloc (NJ , sizeof(double));
u0 = (double*) calloc (NI*NJ, sizeof(double));
u1 = (double*) calloc (NI*NJ, sizeof(double));
u2 = (double*) calloc (NI*NJ, sizeof(double));
u3 = (double*) calloc (NI*NJ, sizeof(double));
for (i = 0; i < NI; i++){
for (j = 0; j < NJ; j++){
x[i] = -0.5 + i*dx;
y[j] = -0.5 + j*dy;
int p = NJ*i + j;
double rho, u, v, P;
if ((x[i] < 0) && (y[j] < 0)) {
rho = 1.1;
P = 1.1;
u = 0.8939;
v = 0.8939;
} else if ((x[i] >= 0) && (y[j] < 0)) {
rho = 0.5065;
P = 0.35;
u = 0.0;
v = 0.8939;
} else if ((x[i] < 0) && (y[j] >= 0)) {
rho = 0.5065;
P = 0.35;
u = 0.8939;
v = 0.0;
} else if ((x[i] >= 0) && (y[j] >= 0)) {
rho = 1.1;
P = 1.1;
u = 0.0;
v = 0.0;
}
u0[p] = rho;
u1[p] = rho*u;
u2[p] = rho*v;
u3[p] = P/(GAMMA-1.0) + 0.5*rho*(u*u+v*v);
}
}
if (!strcmp(ip_file_type,"ascii")) {
out = fopen("initial.inp","w");
for (i = 0; i < NI; i++) fprintf(out,"%lf ",x[i]);
fprintf(out,"\n");
for (j = 0; j < NJ; j++) fprintf(out,"%lf ",y[j]);
fprintf(out,"\n");
for (j = 0; j < NJ; j++) {
for (i = 0; i < NI; i++) {
int p = NJ*i + j;
fprintf(out,"%lf ",u0[p]);
}
}
fprintf(out,"\n");
for (j = 0; j < NJ; j++) {
for (i = 0; i < NI; i++) {
int p = NJ*i + j;
fprintf(out,"%lf ",u1[p]);
}
}
fprintf(out,"\n");
for (j = 0; j < NJ; j++) {
for (i = 0; i < NI; i++) {
int p = NJ*i + j;
fprintf(out,"%lf ",u2[p]);
}
}
fprintf(out,"\n");
for (j = 0; j < NJ; j++) {
for (i = 0; i < NI; i++) {
int p = NJ*i + j;
fprintf(out,"%lf ",u3[p]);
}
}
fprintf(out,"\n");
fclose(out);
} else if ((!strcmp(ip_file_type,"binary")) || (!strcmp(ip_file_type,"bin"))) {
printf("Error: Writing binary initial solution file not implemented. ");
printf("Please choose ip_file_type in solver.inp as \"ascii\".\n");
}
free(x);
free(y);
free(u0);
free(u1);
free(u2);
free(u3);
return(0);
}

Output:

Note that iproc is set to

  2 2

in solver.inp (i.e., 2 processors along x, and 2 processors along y). Thus, this example should be run with 4 MPI ranks (or change iproc).

After running the code, there should be 11 output files op_00000.dat, op_00001.dat, ... op_00010.dat; the first one is the solution at \(t=0\) and the final one is the solution at \(t=0.25\). Since HyPar::op_overwrite is set to no in solver.inp, separate files are written for solutions at each output time.

HyPar::op_file_format is set to tecplot2d in solver.inp, and thus, all the files are in a format that Tecplot (http://www.tecplot.com/) or other visualization software supporting the Tecplot format (e.g. VisIt - https://wci.llnl.gov/simulation/computer-codes/visit/) can read. In these files, the first two lines are the Tecplot headers, after which the data is written out as: the first two columns are grid indices, the next two columns are x and y coordinates, and the remaining columns are the solution components. HyPar::op_file_format can be set to text to get the solution files in plain text format (which can be read in and visualized in MATLAB for example).

The following plot shows the density contours at the final time t=0.25, obtained from plotting op_00010.dat:

Solution_2DNavStokRiemann4.png

Since HyPar::ConservationCheck is set to yes in solver.inp, the code checks for conservation error and prints it to screen, as well as the file conservation.dat:

201 201 2 2 1.0000000000000000E-03 1.2800871473928055E-13 6.3171690101171407E-14 6.2616578588858829E-14 6.2096621604076680E-14

The numbers are: number of grid points in each dimension (HyPar::dim_global), number of processors in each dimension (MPIVariables::iproc), time step size (HyPar::dt), and conservation error (HyPar::ConservationError) for each component.

Expected screen output:

HyPar - Parallel (MPI) version with 4 processes
Compiled with PETSc time integration.
Reading solver inputs from file "solver.inp".
No. of dimensions : 2
No. of variables : 4
Domain size : 201 201
Processes along each dimension : 2 2
No. of ghosts pts : 3
No. of iter. : 250
Restart iteration : 0
Time integration scheme : rk (ssprk3)
Spatial discretization scheme (hyperbolic) : weno5
Split hyperbolic flux term? : no
Interpolation type for hyperbolic term : characteristic
Spatial discretization type (parabolic ) : nonconservative-1stage
Spatial discretization scheme (parabolic ) : 2
Time Step : 1.000000E-03
Check for conservation : yes
Screen output iterations : 5
File output iterations : 25
Initial solution file type : ascii
Initial solution read mode : serial
Solution file write mode : serial
Solution file format : tecplot2d
Overwrite solution file : no
Physical model : navierstokes2d
Partitioning domain.
Allocating data arrays.
Reading array from ASCII file initial.inp (Serial mode).
Volume integral of the initial solution:
0: 8.1131000000013331E-01
1: 3.6014439999993508E-01
2: 3.6014439999993508E-01
3: 2.1526268049998598E+00
Reading boundary conditions from "boundary.inp".
Boundary extrapolate: Along dimension 0 and face +1
Boundary extrapolate: Along dimension 0 and face -1
Boundary extrapolate: Along dimension 1 and face +1
Boundary extrapolate: Along dimension 1 and face -1
4 boundary condition(s) read.
Initializing solvers.
Reading WENO parameters from weno.inp.
Initializing physics. Model = "navierstokes2d"
Reading physical model inputs from file "physics.inp".
Setting up time integration.
Solving in time (from 0 to 250 iterations)
Writing solution file op_00000.dat.
Iteration: 5 Time: 5.000E-03 Max CFL: 4.160E-01 Max Diff. No.: -1.000E+00 Norm: 5.0377E-02 Conservation loss: 5.9869E-14
Iteration: 10 Time: 1.000E-02 Max CFL: 4.194E-01 Max Diff. No.: -1.000E+00 Norm: 4.7008E-02 Conservation loss: 6.6354E-14
Iteration: 15 Time: 1.500E-02 Max CFL: 4.184E-01 Max Diff. No.: -1.000E+00 Norm: 4.5886E-02 Conservation loss: 7.3149E-14
Iteration: 20 Time: 2.000E-02 Max CFL: 4.178E-01 Max Diff. No.: -1.000E+00 Norm: 4.7100E-02 Conservation loss: 8.6996E-14
Iteration: 25 Time: 2.500E-02 Max CFL: 4.250E-01 Max Diff. No.: -1.000E+00 Norm: 4.6940E-02 Conservation loss: 8.8679E-14
Writing solution file op_00001.dat.
Iteration: 30 Time: 3.000E-02 Max CFL: 4.326E-01 Max Diff. No.: -1.000E+00 Norm: 4.7200E-02 Conservation loss: 9.0913E-14
Iteration: 35 Time: 3.500E-02 Max CFL: 4.368E-01 Max Diff. No.: -1.000E+00 Norm: 4.8881E-02 Conservation loss: 8.8229E-14
Iteration: 40 Time: 4.000E-02 Max CFL: 4.419E-01 Max Diff. No.: -1.000E+00 Norm: 4.8287E-02 Conservation loss: 8.8415E-14
Iteration: 45 Time: 4.500E-02 Max CFL: 4.490E-01 Max Diff. No.: -1.000E+00 Norm: 4.8415E-02 Conservation loss: 8.9519E-14
Iteration: 50 Time: 5.000E-02 Max CFL: 4.544E-01 Max Diff. No.: -1.000E+00 Norm: 5.0128E-02 Conservation loss: 9.9562E-14
Writing solution file op_00002.dat.
Iteration: 55 Time: 5.500E-02 Max CFL: 4.550E-01 Max Diff. No.: -1.000E+00 Norm: 5.0085E-02 Conservation loss: 9.8334E-14
Iteration: 60 Time: 6.000E-02 Max CFL: 4.620E-01 Max Diff. No.: -1.000E+00 Norm: 4.9969E-02 Conservation loss: 9.9773E-14
Iteration: 65 Time: 6.500E-02 Max CFL: 4.691E-01 Max Diff. No.: -1.000E+00 Norm: 5.1315E-02 Conservation loss: 1.0401E-13
Iteration: 70 Time: 7.000E-02 Max CFL: 4.731E-01 Max Diff. No.: -1.000E+00 Norm: 5.1266E-02 Conservation loss: 8.4296E-14
Iteration: 75 Time: 7.500E-02 Max CFL: 4.732E-01 Max Diff. No.: -1.000E+00 Norm: 5.2002E-02 Conservation loss: 1.0117E-13
Writing solution file op_00003.dat.
Iteration: 80 Time: 8.000E-02 Max CFL: 4.809E-01 Max Diff. No.: -1.000E+00 Norm: 5.2821E-02 Conservation loss: 1.0733E-13
Iteration: 85 Time: 8.500E-02 Max CFL: 4.870E-01 Max Diff. No.: -1.000E+00 Norm: 5.2476E-02 Conservation loss: 9.9258E-14
Iteration: 90 Time: 9.000E-02 Max CFL: 4.893E-01 Max Diff. No.: -1.000E+00 Norm: 5.3056E-02 Conservation loss: 1.0426E-13
Iteration: 95 Time: 9.500E-02 Max CFL: 4.876E-01 Max Diff. No.: -1.000E+00 Norm: 5.4406E-02 Conservation loss: 1.0013E-13
Iteration: 100 Time: 1.000E-01 Max CFL: 4.929E-01 Max Diff. No.: -1.000E+00 Norm: 5.3954E-02 Conservation loss: 1.1062E-13
Writing solution file op_00004.dat.
Iteration: 105 Time: 1.050E-01 Max CFL: 4.976E-01 Max Diff. No.: -1.000E+00 Norm: 5.4555E-02 Conservation loss: 1.1799E-13
Iteration: 110 Time: 1.100E-01 Max CFL: 4.989E-01 Max Diff. No.: -1.000E+00 Norm: 5.5292E-02 Conservation loss: 1.1726E-13
Iteration: 115 Time: 1.150E-01 Max CFL: 5.044E-01 Max Diff. No.: -1.000E+00 Norm: 5.5373E-02 Conservation loss: 1.2118E-13
Iteration: 120 Time: 1.200E-01 Max CFL: 5.072E-01 Max Diff. No.: -1.000E+00 Norm: 5.5926E-02 Conservation loss: 1.2860E-13
Iteration: 125 Time: 1.250E-01 Max CFL: 5.066E-01 Max Diff. No.: -1.000E+00 Norm: 5.6541E-02 Conservation loss: 1.2459E-13
Writing solution file op_00005.dat.
Iteration: 130 Time: 1.300E-01 Max CFL: 5.125E-01 Max Diff. No.: -1.000E+00 Norm: 5.6235E-02 Conservation loss: 1.1606E-13
Iteration: 135 Time: 1.350E-01 Max CFL: 5.165E-01 Max Diff. No.: -1.000E+00 Norm: 5.7527E-02 Conservation loss: 1.2932E-13
Iteration: 140 Time: 1.400E-01 Max CFL: 5.172E-01 Max Diff. No.: -1.000E+00 Norm: 5.7790E-02 Conservation loss: 1.2203E-13
Iteration: 145 Time: 1.450E-01 Max CFL: 5.154E-01 Max Diff. No.: -1.000E+00 Norm: 5.7671E-02 Conservation loss: 1.3001E-13
Iteration: 150 Time: 1.500E-01 Max CFL: 5.199E-01 Max Diff. No.: -1.000E+00 Norm: 5.8341E-02 Conservation loss: 1.4060E-13
Writing solution file op_00006.dat.
Iteration: 155 Time: 1.550E-01 Max CFL: 5.234E-01 Max Diff. No.: -1.000E+00 Norm: 5.9076E-02 Conservation loss: 1.3663E-13
Iteration: 160 Time: 1.600E-01 Max CFL: 5.240E-01 Max Diff. No.: -1.000E+00 Norm: 5.8772E-02 Conservation loss: 1.3482E-13
Iteration: 165 Time: 1.650E-01 Max CFL: 5.244E-01 Max Diff. No.: -1.000E+00 Norm: 5.9843E-02 Conservation loss: 1.4704E-13
Iteration: 170 Time: 1.700E-01 Max CFL: 5.253E-01 Max Diff. No.: -1.000E+00 Norm: 5.9751E-02 Conservation loss: 1.3714E-13
Iteration: 175 Time: 1.750E-01 Max CFL: 5.262E-01 Max Diff. No.: -1.000E+00 Norm: 6.0037E-02 Conservation loss: 1.4040E-13
Writing solution file op_00007.dat.
Iteration: 180 Time: 1.800E-01 Max CFL: 5.291E-01 Max Diff. No.: -1.000E+00 Norm: 6.0943E-02 Conservation loss: 1.4753E-13
Iteration: 185 Time: 1.850E-01 Max CFL: 5.310E-01 Max Diff. No.: -1.000E+00 Norm: 6.0898E-02 Conservation loss: 1.5150E-13
Iteration: 190 Time: 1.900E-01 Max CFL: 5.311E-01 Max Diff. No.: -1.000E+00 Norm: 6.0664E-02 Conservation loss: 1.5721E-13
Iteration: 195 Time: 1.950E-01 Max CFL: 5.314E-01 Max Diff. No.: -1.000E+00 Norm: 6.1977E-02 Conservation loss: 1.6374E-13
Iteration: 200 Time: 2.000E-01 Max CFL: 5.329E-01 Max Diff. No.: -1.000E+00 Norm: 6.2021E-02 Conservation loss: 1.6680E-13
Writing solution file op_00008.dat.
Iteration: 205 Time: 2.050E-01 Max CFL: 5.333E-01 Max Diff. No.: -1.000E+00 Norm: 6.2052E-02 Conservation loss: 1.5924E-13
Iteration: 210 Time: 2.100E-01 Max CFL: 5.329E-01 Max Diff. No.: -1.000E+00 Norm: 6.2901E-02 Conservation loss: 1.7125E-13
Iteration: 215 Time: 2.150E-01 Max CFL: 5.326E-01 Max Diff. No.: -1.000E+00 Norm: 6.2774E-02 Conservation loss: 1.6480E-13
Iteration: 220 Time: 2.200E-01 Max CFL: 5.325E-01 Max Diff. No.: -1.000E+00 Norm: 6.3254E-02 Conservation loss: 1.6943E-13
Iteration: 225 Time: 2.250E-01 Max CFL: 5.340E-01 Max Diff. No.: -1.000E+00 Norm: 6.3712E-02 Conservation loss: 1.6679E-13
Writing solution file op_00009.dat.
Iteration: 230 Time: 2.300E-01 Max CFL: 5.346E-01 Max Diff. No.: -1.000E+00 Norm: 6.4044E-02 Conservation loss: 1.6922E-13
Iteration: 235 Time: 2.350E-01 Max CFL: 5.338E-01 Max Diff. No.: -1.000E+00 Norm: 6.4045E-02 Conservation loss: 1.6770E-13
Iteration: 240 Time: 2.400E-01 Max CFL: 5.345E-01 Max Diff. No.: -1.000E+00 Norm: 6.5335E-02 Conservation loss: 1.7623E-13
Iteration: 245 Time: 2.450E-01 Max CFL: 5.349E-01 Max Diff. No.: -1.000E+00 Norm: 6.4700E-02 Conservation loss: 1.6334E-13
Iteration: 250 Time: 2.500E-01 Max CFL: 5.338E-01 Max Diff. No.: -1.000E+00 Norm: 6.5624E-02 Conservation loss: 1.6779E-13
Writing solution file op_00010.dat.
Completed time integration (Final time: 0.250000).
Computed errors:
L1 Error : 0.0000000000000000E+00
L2 Error : 0.0000000000000000E+00
Linfinity Error : 0.0000000000000000E+00
Conservation Errors:
1.2800871473928055E-13
6.3171690101171407E-14
6.2616578588858829E-14
6.2096621604076680E-14
Solver runtime (in seconds): 2.1451701399999999E+02
Total runtime (in seconds): 2.1456781300000000E+02
Deallocating arrays.
Finished.