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

Location: hypar/Examples/2D/NavierStokes2D/Riemann2DCase6 (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 6 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 300
time_scheme rk
time_scheme_type ssprk3
hyp_space_scheme muscl3
hyp_interp_type characteristic
dt 0.001
screen_op_iter 10
file_op_iter 30
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

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.0;
P = 1.0;
u = -0.75;
v = 0.5;
} else if ((x[i] >= 0) && (y[j] < 0)) {
rho = 3.0;
P = 1.0;
u = -0.75;
v = -0.5;
} else if ((x[i] < 0) && (y[j] >= 0)) {
rho = 2.0;
P = 1.0;
u = 0.75;
v = 0.5;
} else if ((x[i] >= 0) && (y[j] >= 0)) {
rho = 1.0;
P = 1.0;
u = 0.75;
v = -0.5;
}
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.3\). 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.3, obtained from plotting op_00010.dat:

Solution_2DNavStokRiemann6.png

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. : 300
Restart iteration : 0
Time integration scheme : rk (ssprk3)
Spatial discretization scheme (hyperbolic) : muscl3
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 : no
Screen output iterations : 10
File output iterations : 30
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: 1.7675250000000300E+00
1: -1.8560624999983255E-01
2: -1.2876250000008585E-01
3: 3.2431195312496186E+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.
Initializing physics. Model = "navierstokes2d"
Reading physical model inputs from file "physics.inp".
Setting up time integration.
Solving in time (from 0 to 300 iterations)
Writing solution file op_00000.dat.
Iteration: 10 Time: 1.000E-02 Max CFL: 3.888E-01 Max Diff. No.: -1.000E+00 Norm: 2.3871E-02
Iteration: 20 Time: 2.000E-02 Max CFL: 3.912E-01 Max Diff. No.: -1.000E+00 Norm: 2.1054E-02
Iteration: 30 Time: 3.000E-02 Max CFL: 3.915E-01 Max Diff. No.: -1.000E+00 Norm: 1.9601E-02
Writing solution file op_00001.dat.
Iteration: 40 Time: 4.000E-02 Max CFL: 3.916E-01 Max Diff. No.: -1.000E+00 Norm: 1.8580E-02
Iteration: 50 Time: 5.000E-02 Max CFL: 3.921E-01 Max Diff. No.: -1.000E+00 Norm: 1.7784E-02
Iteration: 60 Time: 6.000E-02 Max CFL: 3.922E-01 Max Diff. No.: -1.000E+00 Norm: 1.7163E-02
Writing solution file op_00002.dat.
Iteration: 70 Time: 7.000E-02 Max CFL: 3.922E-01 Max Diff. No.: -1.000E+00 Norm: 1.6663E-02
Iteration: 80 Time: 8.000E-02 Max CFL: 3.920E-01 Max Diff. No.: -1.000E+00 Norm: 1.6223E-02
Iteration: 90 Time: 9.000E-02 Max CFL: 3.919E-01 Max Diff. No.: -1.000E+00 Norm: 1.5853E-02
Writing solution file op_00003.dat.
Iteration: 100 Time: 1.000E-01 Max CFL: 3.919E-01 Max Diff. No.: -1.000E+00 Norm: 1.5505E-02
Iteration: 110 Time: 1.100E-01 Max CFL: 3.917E-01 Max Diff. No.: -1.000E+00 Norm: 1.5197E-02
Iteration: 120 Time: 1.200E-01 Max CFL: 3.917E-01 Max Diff. No.: -1.000E+00 Norm: 1.4904E-02
Writing solution file op_00004.dat.
Iteration: 130 Time: 1.300E-01 Max CFL: 3.916E-01 Max Diff. No.: -1.000E+00 Norm: 1.4633E-02
Iteration: 140 Time: 1.400E-01 Max CFL: 3.915E-01 Max Diff. No.: -1.000E+00 Norm: 1.4375E-02
Iteration: 150 Time: 1.500E-01 Max CFL: 3.915E-01 Max Diff. No.: -1.000E+00 Norm: 1.4129E-02
Writing solution file op_00005.dat.
Iteration: 160 Time: 1.600E-01 Max CFL: 3.915E-01 Max Diff. No.: -1.000E+00 Norm: 1.3895E-02
Iteration: 170 Time: 1.700E-01 Max CFL: 3.914E-01 Max Diff. No.: -1.000E+00 Norm: 1.3668E-02
Iteration: 180 Time: 1.800E-01 Max CFL: 3.914E-01 Max Diff. No.: -1.000E+00 Norm: 1.3451E-02
Writing solution file op_00006.dat.
Iteration: 190 Time: 1.900E-01 Max CFL: 3.914E-01 Max Diff. No.: -1.000E+00 Norm: 1.3238E-02
Iteration: 200 Time: 2.000E-01 Max CFL: 3.913E-01 Max Diff. No.: -1.000E+00 Norm: 1.3033E-02
Iteration: 210 Time: 2.100E-01 Max CFL: 3.913E-01 Max Diff. No.: -1.000E+00 Norm: 1.2832E-02
Writing solution file op_00007.dat.
Iteration: 220 Time: 2.200E-01 Max CFL: 3.912E-01 Max Diff. No.: -1.000E+00 Norm: 1.2636E-02
Iteration: 230 Time: 2.300E-01 Max CFL: 3.912E-01 Max Diff. No.: -1.000E+00 Norm: 1.2442E-02
Iteration: 240 Time: 2.400E-01 Max CFL: 3.912E-01 Max Diff. No.: -1.000E+00 Norm: 1.2252E-02
Writing solution file op_00008.dat.
Iteration: 250 Time: 2.500E-01 Max CFL: 3.912E-01 Max Diff. No.: -1.000E+00 Norm: 1.2057E-02
Iteration: 260 Time: 2.600E-01 Max CFL: 3.911E-01 Max Diff. No.: -1.000E+00 Norm: 1.1863E-02
Iteration: 270 Time: 2.700E-01 Max CFL: 3.908E-01 Max Diff. No.: -1.000E+00 Norm: 1.1678E-02
Writing solution file op_00009.dat.
Iteration: 280 Time: 2.800E-01 Max CFL: 3.898E-01 Max Diff. No.: -1.000E+00 Norm: 1.1485E-02
Iteration: 290 Time: 2.900E-01 Max CFL: 3.898E-01 Max Diff. No.: -1.000E+00 Norm: 1.1293E-02
Iteration: 300 Time: 3.000E-01 Max CFL: 3.900E-01 Max Diff. No.: -1.000E+00 Norm: 1.1095E-02
Writing solution file op_00010.dat.
Completed time integration (Final time: 0.300000).
Computed errors:
L1 Error : 0.0000000000000000E+00
L2 Error : 0.0000000000000000E+00
Linfinity Error : 0.0000000000000000E+00
Conservation Errors:
0.0000000000000000E+00
0.0000000000000000E+00
0.0000000000000000E+00
0.0000000000000000E+00
Solver runtime (in seconds): 4.7562420000000003E+01
Total runtime (in seconds): 4.7617989999999999E+01
Deallocating arrays.
Finished.