-
Notifications
You must be signed in to change notification settings - Fork 0
/
piastra2D_main_mhd.py
133 lines (103 loc) · 3.84 KB
/
piastra2D_main_mhd.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
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 17 13:04:01 2024
The main code --
grid construction,
initial data filling,
simulation control and visualization live here
@author: mrkondratyev
"""
from grid_setup import Grid
from init_cond_mhd import *
from MHD_state import MHDState
from CFL_condition import CFLcondition_mhd
from aux_routines import auxData
from one_step_mhd import oneStep_MHD_RK
import matplotlib.pyplot as plt
import numpy as np
import time
from visualization import visual
#here we introduce the grid cell numbers in each direction + the number of ghost cells
Nx1 = 128
Nx2 = 128
Ngc = 3
#here we initialize the grid
grid = Grid(Nx1, Nx2, Ngc)
#coordinate range in each direction, by default x and y are in range [0..1]
x1ini, x1fin = 0.0, 1.0
x2ini, x2fin = 0.0, 1.0
#filling the grid arrays with grid data (by now it is only uniform Cartesian grid)
grid.uniCartGrid(x1ini, x1fin, x2ini, x2fin)
#obtaining auxilary data (timestep, final time and so on)
aux = auxData(grid)
#initialize fluid state
mhd = MHDState(grid)
#fill the fluid state arrays with initial data
#see "init_cond.py" for different examples/tests
###############################################################
mhd, aux, eos = init_cond_orszag_tang_cart_2D(grid, mhd, aux)
###############################################################
print("grid resolution = ", grid.Nx1, grid.Nx2)
#here we adjust the solver parameters and print them
aux.rec_type = 'PPM'
aux.flux_type = 'HLL'
aux.RK_order = 'RK3'
print("reconstruction type = ", aux.rec_type)
print("Riemann flux = ", aux.flux_type)
print("Temporal integration = ", aux.RK_order)
#print final phys time
print("final phys time = ", aux.Tfin)
#set the start timer to check the elapsed time
start_time1 = time.time()
print("START OF SIMULATION")
#cycle over time
i_time = 0
while aux.time < aux.Tfin:
#current timestep
i_time = i_time + 1
#calculate the avaliable timestep according to Courant-Friedrichs-Lewy condition
dt = CFLcondition_mhd(grid, mhd, eos, aux.CFL)
dt = min(dt, aux.Tfin - aux.time)
#fluid state variables update
mhd = oneStep_MHD_RK(grid, mhd, eos, dt, aux.rec_type, aux.flux_type, aux.RK_order)
#"real time" output (animated)
aux.time = aux.time + dt
if grid.Nx2 == 1:
# 1D plot along x1 axis
plt.plot(grid.cx1[Ngc:-Ngc, Ngc], mhd.dens[Ngc:-Ngc, Ngc])
plt.xlabel('x1')
plt.ylabel('adv')
elif grid.Nx1 == 1:
# 1D plot along x2 axis
plt.plot(grid.cx2[Ngc, Ngc:-Ngc], mhd.dens[Ngc, Ngc:-Ngc])
plt.xlabel('x2')
plt.ylabel('adv')
else:
# 2D plot
rhomin = np.min(mhd.dens[Ngc:-Ngc, Ngc:-Ngc])
rhomax = np.max(mhd.dens[Ngc:-Ngc, Ngc:-Ngc])
plt.imshow(mhd.dens[Ngc:-Ngc, Ngc:-Ngc], cmap='jet')
plt.clim(rhomin, rhomax)
ax = plt.gca()
ax.invert_yaxis()
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
ax.set_aspect('equal')
plt.pause(0.03)
#plt.clim(0.0, 1.0)
#print final physical time
print("final phys time = ", aux.time)
print("END OF SIMULATION")
##calculate and the elapsed time of the simulation
end_time1 = time.time()
print("time of simulation = ", end_time1 - start_time1, " secs")
# Show the plot
plt.show()
plt.plot(grid.cx1[Ngc:-Ngc,Ngc], mhd.dens[Ngc:-Ngc,Ngc])
#plt.plot(grid.cx2[Ngc,Ngc:-Ngc], mhd.dens[Ngc,Ngc:-Ngc])
#plt.imshow(fluid.dens, extent=(grid.cx1.min(), grid.cx1.max(), grid.cx2.min(), grid.cx2.max()), origin='lower', cmap='viridis', interpolation='nearest', aspect='auto')
# Add labels and a colorbar
#plt.colorbar(label='Colorbar Label')
#plt.xlabel('X Label')
#plt.ylabel('Y Label')
#plt.title('2D Plot of Data')