Skip to content

Commit 602b918

Browse files
committed
regression test for thermal diffusion
1 parent 3cf16ab commit 602b918

File tree

5 files changed

+206
-0
lines changed

5 files changed

+206
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#define COMPONENTS 3
2+
#define DIMENSIONS 3
3+
4+
#define GEOMETRY CARTESIAN
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[Grid]
2+
3+
X1-grid 1 -0.5 500 u 0.5
4+
X2-grid 1 0.0 1 u 1.0
5+
X3-grid 1 0.0 1 u 1.0
6+
7+
8+
9+
[TimeIntegrator]
10+
11+
CFL 0.8
12+
CFL_max_var 1.1
13+
tstop 0.2
14+
nstages 2
15+
16+
[Hydro]
17+
18+
solver hllc
19+
gamma 1.4
20+
TDiffusion rkl constant 0.1
21+
22+
[Setup]
23+
amplitude 1e-6
24+
25+
[Boundary]
26+
27+
X1-beg periodic
28+
X1-end periodic
29+
X2-beg periodic
30+
X2-end periodic
31+
X3-beg periodic
32+
X3-end periodic
33+
34+
[Output]
35+
analysis 0.01
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[Grid]
2+
3+
X1-grid 1 -0.5 500 u 0.5
4+
X2-grid 1 0.0 1 u 1.0
5+
X3-grid 1 0.0 1 u 1.0
6+
7+
8+
9+
[TimeIntegrator]
10+
11+
CFL 0.8
12+
CFL_max_var 1.1
13+
tstop 0.2
14+
nstages 2
15+
16+
[Hydro]
17+
18+
solver hllc
19+
gamma 1.4
20+
TDiffusion explicit constant 0.1
21+
22+
[Setup]
23+
amplitude 1e-6
24+
25+
[Boundary]
26+
27+
X1-beg periodic
28+
X1-end periodic
29+
X2-beg periodic
30+
X2-end periodic
31+
X3-beg periodic
32+
X3-end periodic
33+
34+
[Output]
35+
analysis 0.01
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import sys
2+
import numpy as np
3+
import argparse
4+
import matplotlib.pyplot as plt
5+
from scipy.signal import argrelextrema
6+
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument("-noplot",
9+
default=False,
10+
help="disable plotting",
11+
action="store_true")
12+
13+
14+
args=parser.parse_args()
15+
16+
17+
# values from the setup to compute the decay rate
18+
kappa=0.1
19+
gamma=1.4
20+
rho0=1.0
21+
22+
#diffusion coefficient
23+
D=kappa*(gamma-1)/rho0
24+
25+
k=2.0*np.pi
26+
27+
# decay rate of the temperature perturbation
28+
gamma=-k**2*D
29+
30+
raw=np.loadtxt('../analysis.dat',skiprows=1)
31+
t=raw[:,0]
32+
Tidfx=raw[:,1]
33+
34+
Tth=Tidfx[0]*np.exp(gamma*t)
35+
error=np.mean(Tidfx/Tth-1.0)
36+
37+
if(not args.noplot):
38+
39+
plt.close('all')
40+
plt.figure()
41+
plt.plot(t,Tidfx/Tth-1.0)
42+
43+
print("Error=%e"%error)
44+
plt.ioff()
45+
plt.show()
46+
47+
if(error<2.5e-6):
48+
print("SUCCESS")
49+
sys.exit(0)
50+
else:
51+
print("Failed")
52+
sys.exit(1)

test/HD/thermalDiffusion/setup.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#include "idefix.hpp"
2+
#include "setup.hpp"
3+
4+
5+
#define FILENAME "analysis.dat"
6+
real amplitude;
7+
// Analyse data to get the amplitude of the k=1 temperature perturbation
8+
void Analysis(DataBlock & data) {
9+
DataBlockHost d(data);
10+
d.SyncFromDevice();
11+
real Tmode = 0;
12+
for(int i = d.beg[IDIR]; i < d.end[IDIR] ; i++) {
13+
real T = d.Vc(PRS,d.beg[KDIR],d.beg[JDIR],i) / d.Vc(RHO,d.beg[KDIR],d.beg[JDIR],i);
14+
Tmode += T * sin(2.0*M_PI*d.x[IDIR](i));
15+
}
16+
Tmode = 2*Tmode/d.np_int[JDIR];
17+
18+
std::ofstream f;
19+
f.open(FILENAME,std::ios::app);
20+
f.precision(10);
21+
f << std::scientific << data.t << "\t" << Tmode << std::endl;
22+
f.close();
23+
24+
}
25+
26+
void InternalBoundary(DataBlock& data, const real t) {
27+
IdefixArray4D<real> Vc = data.hydro.Vc;
28+
idefix_for("InternalBoundary",0,data.np_tot[KDIR],0,data.np_tot[JDIR],0,data.np_tot[IDIR],
29+
KOKKOS_LAMBDA (int k, int j, int i) {
30+
// Cancel any motion that could be happening
31+
Vc(VX1,k,j,i) = 0.0;
32+
Vc(VX2,k,j,i) = 0.0;
33+
Vc(VX3,k,j,i) = 0.0;
34+
});
35+
}
36+
37+
38+
// Initialisation routine. Can be used to allocate
39+
// Arrays or variables which are used later on
40+
Setup::Setup(Input &input, Grid &grid, DataBlock &data, Output &output) {
41+
output.EnrollAnalysis(&Analysis);
42+
data.hydro.EnrollInternalBoundary(&InternalBoundary);
43+
44+
amplitude = input.GetReal("Setup","amplitude",0);
45+
// Initialise the output file
46+
std::ofstream f;
47+
f.open(FILENAME,std::ios::trunc);
48+
f << "t\t\t T" << std::endl;
49+
f.close();
50+
}
51+
52+
// This routine initialize the flow
53+
// Note that data is on the device.
54+
// One can therefore define locally
55+
// a datahost and sync it, if needed
56+
void Setup::InitFlow(DataBlock &data) {
57+
// Create a host copy
58+
DataBlockHost d(data);
59+
60+
61+
for(int k = 0; k < d.np_tot[KDIR] ; k++) {
62+
for(int j = 0; j < d.np_tot[JDIR] ; j++) {
63+
for(int i = 0; i < d.np_tot[IDIR] ; i++) {
64+
65+
d.Vc(RHO,k,j,i) = 1 - amplitude*sin(2.0*M_PI*d.x[IDIR](i));
66+
d.Vc(VX1,k,j,i) = ZERO_F;
67+
d.Vc(PRS,k,j,i) = 1.0;
68+
69+
}
70+
}
71+
}
72+
73+
// Send it all, if needed
74+
d.SyncToDevice();
75+
}
76+
77+
// Analyse data to produce an output
78+
void MakeAnalysis(DataBlock & data) {
79+
80+
}

0 commit comments

Comments
 (0)