forked from clawpack/gitclaw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquadrants.py
executable file
·122 lines (97 loc) · 3.88 KB
/
quadrants.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
#!/usr/bin/env python
# encoding: utf-8
"""
Euler 2D Quadrants example
==========================
Simple example solving the Euler equations of compressible fluid dynamics:
.. math::
\rho_t + (\rho u)_x + (\rho v)_y & = 0 \\
(\rho u)_t + (\rho u^2 + p)_x + (\rho uv)_y & = 0 \\
(\rho v)_t + (\rho uv)_x + (\rho v^2 + p)_y & = 0 \\
E_t + (u (E + p) )_x + (v (E + p))_y & = 0.
Here :math:`\rho` is the density, (u,v) is the velocity, and E is the total energy.
The initial condition is one of the 2D Riemann problems from the paper of
Liska and Wendroff.
"""
from clawpack import riemann
from clawpack.riemann.euler_4wave_2D_constants import density, x_momentum, y_momentum, \
energy, num_eqn
from clawpack.visclaw import colormaps
def setplot(plotdata):
r"""Plotting settings
Should plot two figures both of density.
"""
plotdata.clearfigures() # clear any old figures,axes,items data
# Figure for density - pcolor
plotfigure = plotdata.new_plotfigure(name='Density', figno=0)
# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes()
plotaxes.xlimits = 'auto'
plotaxes.ylimits = 'auto'
plotaxes.scaled = True
plotaxes.title = 'Density'
# Set up for item on these axes:
plotitem = plotaxes.new_plotitem(plot_type='2d_pcolor')
plotitem.plot_var = density
plotitem.pcolor_cmap = colormaps.yellow_red_blue
plotitem.pcolor_cmin = 0.
plotitem.pcolor_cmax = 2.
plotitem.add_colorbar = True
# Figure for density - Schlieren
plotfigure = plotdata.new_plotfigure(name='Schlieren', figno=1)
# Set up for axes in this figure:
plotaxes = plotfigure.new_plotaxes()
plotaxes.xlimits = 'auto'
plotaxes.ylimits = 'auto'
plotaxes.title = 'Density'
plotaxes.scaled = True # so aspect ratio is 1
# Set up for item on these axes:
plotitem = plotaxes.new_plotitem(plot_type='2d_schlieren')
plotitem.schlieren_cmin = 0.0
plotitem.schlieren_cmax = 1.0
plotitem.plot_var = density
plotitem.add_colorbar = False
return plotdata
def setup(use_petsc=False):
if use_petsc:
import clawpack.petclaw as pyclaw
else:
from clawpack import pyclaw
solver = pyclaw.ClawSolver2D(riemann.euler_4wave_2D)
solver.all_bcs = pyclaw.BC.extrap
domain = pyclaw.Domain([0.,0.],[1.,1.],[100,100])
solution = pyclaw.Solution(num_eqn,domain)
gamma = 1.4
solution.problem_data['gamma'] = gamma
solver.dimensional_split = False
solver.transverse_waves = 2
# Set initial data
xx, yy = domain.grid.p_centers
l = xx < 0.8
r = xx >= 0.8
b = yy < 0.8
t = yy >= 0.8
solution.q[density,...] = 1.5 * r * t + 0.532258064516129 * l * t \
+ 0.137992831541219 * l * b \
+ 0.532258064516129 * r * b
u = 0.0 * r * t + 1.206045378311055 * l * t \
+ 1.206045378311055 * l * b \
+ 0.0 * r * b
v = 0.0 * r * t + 0.0 * l * t \
+ 1.206045378311055 * l * b \
+ 1.206045378311055 * r * b
p = 1.5 * r * t + 0.3 * l * t + 0.029032258064516 * l * b + 0.3 * r * b
solution.q[x_momentum,...] = solution.q[density, ...] * u
solution.q[y_momentum,...] = solution.q[density, ...] * v
solution.q[energy,...] = 0.5 * solution.q[density,...]*(u**2 + v**2) + p / (gamma - 1.0)
claw = pyclaw.Controller()
claw.tfinal = 0.8
claw.solution = solution
claw.solver = solver
claw.output_format = 'ascii'
claw.outdir = "./_output"
claw.setplot = setplot
return claw
if __name__ == "__main__":
from clawpack.pyclaw.util import run_app_from_main
output = run_app_from_main(setup, setplot)