HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
2D Euler Equations - Isentropic Vortex Convection

Location: hypar/Examples/2D/NavierStokes2D/InviscidVortexConvection (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: C.-W. Shu, "Essentially Non-oscillatory and Weighted Essentially Non-oscillatory Schemes for Hyperbolic Conservation Laws", ICASE Report 97-65, 1997

Domain: \(0 \le x,y \le 10\), "periodic" (_PERIODIC_) boundary conditions.

Initial solution: The freestream flow is given by

\begin{equation} \rho_\infty = 1,\ u_\infty = 0.1,\ v_\infty = 0,\ p_\infty = 1 \end{equation}

and a vortex is introduced, specified as

\begin{align} \rho &= \left[ 1 - \frac{\left(\gamma-1\right)b^2}{8\gamma\pi^2} e^{1-r^2} \right]^{\frac{1}{\gamma-1}},\ p = \rho^\gamma, \\ u &= u_\infty - \frac{b}{2\pi} e^{\frac{1}{2}\left(1-r^2\right)} \left(y-y_c\right),\ v = v_\infty + \frac{b}{2\pi} e^{\frac{1}{2}\left(1-r^2\right)} \left(x-x_c\right), \end{align}

where \(b=0.5\) is the vortex strength and \(r = \left[(x-x_c)^2 + (y-y_c)^2 \right]^{1/2}\) is the distance from the vortex center \(\left(x_c,y_c\right) = \left(5,5\right)\).

Numerical method:

Input files required:

solver.inp

begin
ndims 2
nvars 4
size 60 60
iproc 2 2
ghost 3
n_iter 800
restart_iter 0
time_scheme rk
time_scheme_type ssprk3
hyp_space_scheme crweno5
hyp_flux_split no
hyp_interp_type components
par_space_type nonconservative-2stage
par_space_scheme 4
dt 0.025
conservation_check yes
screen_op_iter 20
file_op_iter 80
input_mode serial
ip_file_type binary
output_mode serial
op_file_format tecplot2d
op_overwrite no
model navierstokes2d
end

boundary.inp

4
periodic 0 1 0 0 0 10.0
periodic 0 -1 0 0 0 10.0
periodic 1 1 0 10.0 0 0
periodic 1 -1 0 10.0 0 0

physics.inp

begin
gamma 1.4
upwinding roe
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

lusolver.inp (optional)

begin
reducedsolvetype gather-and-solve
evaluate_norm 1
maxiter 10
atol 1e-12
rtol 1e-10
verbose 0
end

To generate initial.inp (initial solution) and exact.inp (exact solution), compile and run the following code in the run directory.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
double power(double x,double a)
{
return(exp(a*log(x)));
}
int main(){
const double pi = 4.0*atan(1.0);
const double GAMMA = 1.4;
int NI,NJ,ndims,n_iter;
double tf, dt;
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");
return(0);
} 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, "n_iter")) fscanf(in,"%d",&n_iter);
else if (!strcmp(word, "dt")) fscanf(in,"%lf",&dt);
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 exact solution\n");
return(0);
}
printf("Grid:\t\t\t%d X %d\n",NI,NJ);
int i,j;
double dx = 10.0 / ((double)NI);
double dy = 10.0 / ((double)NJ);
tf = (double)n_iter * dt; double tff = tf;
while (tf > 20) tf -= 20; // Time period
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));
double u_inf = 0.5;
double v_inf = 0.0;
double b = u_inf;
double x0, y0;
/* Initial solution */
x0 = 5.0, y0 = 5.0;
for (i = 0; i < NI; i++){
for (j = 0; j < NJ; j++){
x[i] = i*dx;
y[j] = j*dy;
int p = NJ*i + j;
double rx, ry;
rx = (x[i] - x0);
ry = (y[j] - y0);
if (rx < -5) { rx += 10; }
else if (rx > 5) { rx -= 10; }
double rsq = rx*rx + ry*ry;
double rho, u, v, P;
double du, dv;
rho = power(1.0 - ((GAMMA-1.0)*b*b)/(8.0*GAMMA*pi*pi) * exp(1.0-rsq), 1.0/(GAMMA-1.0));
P = power(rho,GAMMA);
du = - b/(2.0*pi) * exp(0.5*(1.0-rsq)) * ry;
dv = b/(2.0*pi) * exp(0.5*(1.0-rsq)) * rx;
u = u_inf + du;
v = v_inf + dv;
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")) {
printf("Writing ASCII initial solution file initial.inp\n");
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("Writing binary initial solution file initial.inp\n");
out = fopen("initial.inp","wb");
fwrite(x,sizeof(double),NI,out);
fwrite(y,sizeof(double),NJ,out);
double *U = (double*) calloc (4*NI*NJ,sizeof(double));
for (i=0; i < NI; i++) {
for (j = 0; j < NJ; j++) {
int p = NJ*i + j;
int q = NI*j + i;
U[4*q+0] = u0[p];
U[4*q+1] = u1[p];
U[4*q+2] = u2[p];
U[4*q+3] = u3[p];
}
}
fwrite(U,sizeof(double),4*NI*NJ,out);
free(U);
fclose(out);
}
/* Exact solution */
x0 = 5.0+tf*u_inf, y0 = 5.0;
if (x0 > 10) x0 -= 10; //periodic domain
printf("Final time: %lf, Vortex center: %lf, %lf\n",tff,x0,y0);
for (i = 0; i < NI; i++){
for (j = 0; j < NJ; j++){
x[i] = i*dx;
y[j] = j*dy;
int p = NJ*i + j;
double rx, ry;
rx = (x[i] - x0);
ry = (y[j] - y0);
if (rx < -5) { rx += 10; }
else if (rx > 5) { rx -= 10; }
double rsq = rx*rx + ry*ry;
double rho, u, v, P;
double du, dv;
rho = power(1.0 - ((GAMMA-1.0)*b*b)/(8.0*GAMMA*pi*pi) * exp(1.0-rsq), 1.0/(GAMMA-1.0));
P = power(rho,GAMMA);
du = - b/(2.0*pi) * exp(0.5*(1.0-rsq)) * ry;
dv = b/(2.0*pi) * exp(0.5*(1.0-rsq)) * rx;
u = u_inf + du;
v = v_inf + dv;
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")) {
printf("Writing ASCII exact solution file exact.inp\n");
out = fopen("exact.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("Writing binary exact solution file exact.inp\n");
out = fopen("exact.inp","wb");
fwrite(x,sizeof(double),NI,out);
fwrite(y,sizeof(double),NJ,out);
double *U = (double*) calloc (4*NI*NJ,sizeof(double));
for (i=0; i < NI; i++) {
for (j = 0; j < NJ; j++) {
int p = NJ*i + j;
int q = NI*j + i;
U[4*q+0] = u0[p];
U[4*q+1] = u1[p];
U[4*q+2] = u2[p];
U[4*q+3] = u3[p];
}
}
fwrite(U,sizeof(double),4*NI*NJ,out);
free(U);
fclose(out);
}
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=20\). 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 animation shows the density contours as the vortex convects over the domain:,

Solution_2DNavStokVortex.gif

Since the exact solution is available at the final time (exact.inp is a copy of initial.inp), the numerical errors are calculated and reported on screen (see below) as well as errors.dat:

60 60 2 2 5.0000000000000003E-02 5.1210254847046790E-07 1.1288616818926130E-06 7.0353441679473522E-06 1.6349111000000001E+01 1.6355046999999999E+01

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), L1, L2, and L-infinity errors (HyPar::error), solver wall time (seconds) (i.e., not accounting for initialization, and cleaning up), and total wall time.

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:

60 60 2 2 5.0000000000000003E-02 3.2691273934866492E-15 1.4213597072594877E-15 1.7763568394002505E-15 6.4974527961510956E-16

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) of 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 : 60 60
Processes along each dimension : 2 2
No. of ghosts pts : 3
No. of iter. : 400
Restart iteration : 0
Time integration scheme : rk (ssprk3)
Spatial discretization scheme (hyperbolic) : crweno5
Split hyperbolic flux term? : no
Interpolation type for hyperbolic term : components
Spatial discretization type (parabolic ) : nonconservative-2stage
Spatial discretization scheme (parabolic ) : 4
Time Step : 5.000000E-02
Check for conservation : yes
Screen output iterations : 10
File output iterations : 40
Initial solution file type : binary
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 binary file initial.inp (Serial mode).
Volume integral of the initial solution:
0: 9.9980704056028983E+01
1: 4.9990353049341181E+01
2: -1.0213269162340222E-06
3: 2.6245709192907299E+02
Reading boundary conditions from "boundary.inp".
Boundary periodic: Along dimension 0 and face +1
Boundary periodic: Along dimension 0 and face -1
Boundary periodic: Along dimension 1 and face +1
Boundary periodic: 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 400 iterations)
Writing solution file op_00000.dat.
Iteration: 10 Time: 5.000E-01 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0257E-04 Conservation loss: 3.3476E-15
Iteration: 20 Time: 1.000E+00 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0257E-04 Conservation loss: 3.3327E-15
Iteration: 30 Time: 1.500E+00 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0257E-04 Conservation loss: 3.3409E-15
Iteration: 40 Time: 2.000E+00 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0257E-04 Conservation loss: 3.1610E-15
Writing solution file op_00001.dat.
Iteration: 50 Time: 2.500E+00 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0256E-04 Conservation loss: 3.2732E-15
Iteration: 60 Time: 3.000E+00 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0256E-04 Conservation loss: 3.3955E-15
Iteration: 70 Time: 3.500E+00 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0256E-04 Conservation loss: 3.5500E-15
Iteration: 80 Time: 4.000E+00 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0256E-04 Conservation loss: 3.8618E-15
Writing solution file op_00002.dat.
Iteration: 90 Time: 4.500E+00 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0256E-04 Conservation loss: 3.0873E-15
Iteration: 100 Time: 5.000E+00 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0255E-04 Conservation loss: 3.9885E-15
Iteration: 110 Time: 5.500E+00 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0255E-04 Conservation loss: 3.4913E-15
Iteration: 120 Time: 6.000E+00 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0255E-04 Conservation loss: 3.8263E-15
Writing solution file op_00003.dat.
Iteration: 130 Time: 6.500E+00 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0255E-04 Conservation loss: 3.8449E-15
Iteration: 140 Time: 7.000E+00 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0255E-04 Conservation loss: 3.3666E-15
Iteration: 150 Time: 7.500E+00 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0254E-04 Conservation loss: 4.1964E-15
Iteration: 160 Time: 8.000E+00 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0254E-04 Conservation loss: 3.6628E-15
Writing solution file op_00004.dat.
Iteration: 170 Time: 8.500E+00 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0254E-04 Conservation loss: 3.1809E-15
Iteration: 180 Time: 9.000E+00 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0254E-04 Conservation loss: 3.1228E-15
Iteration: 190 Time: 9.500E+00 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0254E-04 Conservation loss: 3.1722E-15
Iteration: 200 Time: 1.000E+01 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0253E-04 Conservation loss: 3.4161E-15
Writing solution file op_00005.dat.
Iteration: 210 Time: 1.050E+01 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0253E-04 Conservation loss: 3.3616E-15
Iteration: 220 Time: 1.100E+01 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0253E-04 Conservation loss: 3.8552E-15
Iteration: 230 Time: 1.150E+01 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0253E-04 Conservation loss: 3.1900E-15
Iteration: 240 Time: 1.200E+01 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0252E-04 Conservation loss: 3.4170E-15
Writing solution file op_00006.dat.
Iteration: 250 Time: 1.250E+01 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0252E-04 Conservation loss: 3.4233E-15
Iteration: 260 Time: 1.300E+01 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0252E-04 Conservation loss: 3.5695E-15
Iteration: 270 Time: 1.350E+01 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0252E-04 Conservation loss: 3.5223E-15
Iteration: 280 Time: 1.400E+01 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0252E-04 Conservation loss: 3.3440E-15
Writing solution file op_00007.dat.
Iteration: 290 Time: 1.450E+01 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0251E-04 Conservation loss: 3.8712E-15
Iteration: 300 Time: 1.500E+01 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0251E-04 Conservation loss: 3.8433E-15
Iteration: 310 Time: 1.550E+01 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0251E-04 Conservation loss: 4.2669E-15
Iteration: 320 Time: 1.600E+01 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0251E-04 Conservation loss: 3.7604E-15
Writing solution file op_00008.dat.
Iteration: 330 Time: 1.650E+01 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0251E-04 Conservation loss: 4.2691E-15
Iteration: 340 Time: 1.700E+01 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0251E-04 Conservation loss: 3.8530E-15
Iteration: 350 Time: 1.750E+01 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0250E-04 Conservation loss: 3.2448E-15
Iteration: 360 Time: 1.800E+01 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0250E-04 Conservation loss: 3.6598E-15
Writing solution file op_00009.dat.
Iteration: 370 Time: 1.850E+01 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0250E-04 Conservation loss: 3.8781E-15
Iteration: 380 Time: 1.900E+01 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0250E-04 Conservation loss: 4.6644E-15
Iteration: 390 Time: 1.950E+01 Max CFL: 5.286E-01 Max Diff. No.: -1.000E+00 Norm: 6.0250E-04 Conservation loss: 3.4378E-15
Iteration: 400 Time: 2.000E+01 Max CFL: 5.287E-01 Max Diff. No.: -1.000E+00 Norm: 6.0250E-04 Conservation loss: 4.0355E-15
Writing solution file op_00010.dat.
Completed time integration (Final time: 20.000000).
Reading array from binary file exact.inp (Serial mode).
Computed errors:
L1 Error : 5.1210254847046790E-07
L2 Error : 1.1288616818926130E-06
Linfinity Error : 7.0353441679473522E-06
Conservation Errors:
3.2691273934866492E-15
1.4213597072594877E-15
1.7763568394002505E-15
6.4974527961510956E-16
Solver runtime (in seconds): 1.6349111000000001E+01
Total runtime (in seconds): 1.6355046999999999E+01
Deallocating arrays.
Finished.