-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaseCollidingBub3D.py
172 lines (133 loc) · 6.28 KB
/
caseCollidingBub3D.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env python
# coding: utf-8
# ## Configuration of a simulation case (*caseCollidingBub*)
#
# ### Importing required libraries
#
# Some of these are well known libraries such as *numpy* and *matplotlib* (they can be installed using pip). We also need to import the library *utils* containing predefined functionalities for this software.
import os
import math
import numpy as np
import matplotlib.pyplot as plt
import re
from glob import glob
from utils import modify_header_file,write_config,write_initial,write_equilibrium,backup_file,restore_file,compile_program,run_program,initialize_variables,read_data_euler
import imageio
# ### Setting up the paths
#
# First, the name of the folder for this test case must be specified:
#This test case will run in the folder "caseCollidingBub3D/".
#Don't forget the bar (/).
#This directory should have been created prior to the execution to this script, and should also contain an /out folder inside
folder_case="caseCollidingBub3D/"
# Then, all the paths are automatically assigned:
#Do not modify the folders and paths below
script_dir = os.path.dirname(os.path.abspath(__file__))
folder_out="out/"
folder_lib="lib"
fname_config="configure.input"
fname_eq="equilibrium.out"
fname_ini="initial.out"
folder_out = os.path.join(script_dir, "../"+folder_case+"/"+folder_out)
folder_case = os.path.join(script_dir, "../"+folder_case)
folder_lib = os.path.join(script_dir, "../"+folder_lib)
folder_exe = os.path.join(script_dir, "../")
os.makedirs(folder_case, exist_ok=True)
os.makedirs(folder_out, exist_ok=True)
for f in glob(folder_out + "/*.out") + glob(folder_out + "/*.vtk") + glob(folder_out + "/*.png"):
os.remove(f)
# ### Setting up the compilation variables (*definitions.h*)
#
# Here, we can modify those variables that need to be set before compilation and are found in the file *definitions.h*. Don't worry if you mess up things here, a backup of the original file is created before modification and will be restored at the end of this script, after compilation and execution.
#Do not change the line below, it creates a backup of the definitions.h file
backup_file(folder_lib+'/definitions.h')
#Configure the header file for compilation. Add as many lines as desired for the macros you want to modify.
modify_header_file(folder_lib+'/definitions.h', 'NTHREADS', 60) #number of threads
modify_header_file(folder_lib+'/definitions.h', 'EQUATION_SYSTEM', 2) #System of equations solved
modify_header_file(folder_lib+'/definitions.h', 'ST', 3) #Source term type
modify_header_file(folder_lib+'/definitions.h', 'SOLVER', 0) #Riemann solver used
modify_header_file(folder_lib+'/definitions.h', 'READ_INITIAL', 1) #Read or not initial data, this should ALWAYS be 1
modify_header_file(folder_lib+'/definitions.h', 'WRITE_LIST', 0)
# ### Configure the global simulation parameters
#
# We can set the global simulation parameters as desired:
#Simulation setup
FinalTime = 800.0
DumpTime = 50.0 #for file printing
CFL = 0.2
Order = 7
#Mesh setup
xcells = 200
ycells = 200
zcells = 100
SizeX = 20000.0
SizeY = 20000.0
SizeZ = 10000.0
#Boundary conditions
Face_1 = 4 #-y
Face_2 = 4 #+x
Face_3 = 4 #+y
Face_4 = 4 #-x
Face_5 = 4 #-z
Face_6 = 4 #+z
#Linear transport, only if applicable
u_x = 1.0
u_y = 1.0
u_z = 1.0
# ### Define the initial condition
#
# To define the initial condition we first need to create the arrays and initialize some variables:
xc, yc, zc, u, v, w, rho, p, phi, ue, ve, we, rhoe, pe = initialize_variables(xcells, ycells, zcells, SizeX, SizeY, SizeZ)
# Among these, we have:
# - the problem variables: ```u, v, w, rho, p, phi```
# - the equilibrium variables (for atmospheric cases): ```ue, ve, we, rhoe, pe```
#
# Then we can set the initial condition using those variables. To do this, we loop over the three cartesian indexes $(l,m,n)$ and assign the variables, e.g. $\rho(x_l,y_m,z_n)=...$ is set as ```rho[l,m,n]=...```. Cell centers are given by: ```xc[l,m,n]```, ```yc[l,m,n]``` and ```zc[l,m,n]```.
#Some auxiliary parameters (must be equal to those in definitions.h)
tt0=300
p0=1.e5
R=287.058
gamma=1.4
g=9.8
rho0=p0/(R*tt0)
aux2=(gamma-1.0)/gamma*g/(R*tt0)
#Initial condition and equilibrium state
for l in range(0,xcells):
for m in range(0,ycells):
for n in range(0,zcells):
#This is the equilibrium state (in this case, adiabatic equilibrium):
rhoe[l,m,n]=rho0*(1.0-aux2*zc[l,m,n])**(1.0/(gamma-1.0))
pe [l,m,n]=p0* (1.0-aux2*zc[l,m,n])**(gamma/(gamma-1.0))
ue [l,m,n]=0.0
ve [l,m,n]=0.0
we [l,m,n]=0.0
#This is the initial condition
xp=10000;
yp=10000;
zp=2000;
d1=np.sqrt((xc[l,m,n]-xp)*(xc[l,m,n]-xp)+(yc[l,m,n]-yp)*(yc[l,m,n]-yp)+(zc[l,m,n]-zp)*(zc[l,m,n]-zp));
xp=10000;
yp=10000;
zp=8000;
d2=np.sqrt((xc[l,m,n]-xp)*(xc[l,m,n]-xp)+(yc[l,m,n]-yp)*(yc[l,m,n]-yp)+(zc[l,m,n]-zp)*(zc[l,m,n]-zp));
rc=1000;
aux1=20.0*(max(rc-d1/2.0,0.0)+min(d2/2.0-rc,0.0))/1000;
tt=tt0+aux1;
aux2=(gamma-1.0)/gamma*g/(R*tt0);
rho[l,m,n]=p0/(R*tt)*(1.0-aux2*zc[l,m,n])**(1.0/(gamma-1.0)) #density
p [l,m,n]=p0* (1.0-aux2*zc[l,m,n])**(gamma/(gamma-1.0)) #pressure
u [l,m,n]=0.0 #x-velocity
v [l,m,n]=0.0 #y-velocity
w [l,m,n]=0.0 #z-velocity
phi[l,m,n]=0.0 #solute
# Now, the configuration and initial condition (and equilibrium) files are written:
write_config(folder_case, fname_config, FinalTime, DumpTime, CFL, Order, xcells, ycells, zcells, SizeX, SizeY, SizeZ, Face_1, Face_2, Face_3, Face_4, Face_5, Face_6, u_x, u_y, u_z)
write_equilibrium(folder_case, fname_eq, xcells, ycells, zcells, xc, yc, zc, ue, ve, we, rhoe, pe)
write_initial(folder_case, fname_ini, xcells, ycells, zcells, xc, yc, zc, u, v, w, rho, p, phi)
# ### Compilation and execution
#
# The program is compiled and executed:
compile_program()
restore_file(folder_lib+'/definitions.h')
print("Program is running...")
run_program(folder_exe+"./caelum "+folder_case)