Skip to content

Commit f8c15e4

Browse files
author
Michael Zingale
committed
elimiinate vars.py -- there is now a Variables class in simulation.py
that handles the role
1 parent bd209f4 commit f8c15e4

File tree

3 files changed

+50
-41
lines changed

3 files changed

+50
-41
lines changed

compressible/simulation.py

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,29 @@
99
from unsplitFluxes import *
1010
from util import profile
1111

12+
13+
class Variables:
14+
"""
15+
a container class for easy access to the different compressible
16+
variable by an integer key
17+
"""
18+
def __init__(self, idens=-1, ixmom=-1, iymom=-1, iener=-1):
19+
self.nvar = 4
20+
21+
# conserved variables -- we set these when we initialize for
22+
# they match the CellCenterData2d object
23+
self.idens = idens
24+
self.ixmom = ixmom
25+
self.iymom = iymom
26+
self.iener = iener
27+
28+
# primitive variables
29+
self.irho = 0
30+
self.iu = 1
31+
self.iv = 2
32+
self.ip = 3
33+
34+
1235
class Simulation:
1336

1437
def __init__(self, problem_name, rp):
@@ -17,13 +40,15 @@ def __init__(self, problem_name, rp):
1740
self.cc_data = None
1841
self.problem_name = problem_name
1942

43+
self.vars = None
44+
2045
self.SMALL = 1.e-12
2146

47+
2248
def initialize(self):
2349
"""
2450
initialize the grid and variables for compressible flow
2551
"""
26-
import vars
2752

2853
# setup the grid
2954
nx = self.rp.get_param("mesh.nx")
@@ -94,10 +119,11 @@ def initialize(self):
94119

95120
self.cc_data = my_data
96121

97-
vars.idens = my_data.vars.index("density")
98-
vars.ixmom = my_data.vars.index("x-momentum")
99-
vars.iymom = my_data.vars.index("y-momentum")
100-
vars.iener = my_data.vars.index("energy")
122+
self.vars = Variables(idens = my_data.vars.index("density"),
123+
ixmom = my_data.vars.index("x-momentum"),
124+
iymom = my_data.vars.index("y-momentum"),
125+
iener = my_data.vars.index("energy"))
126+
101127

102128
# initial conditions for the problem
103129
exec self.problem_name + '.init_data(self.cc_data, self.rp)'
@@ -166,7 +192,7 @@ def evolve(self, dt):
166192

167193
myg = self.cc_data.grid
168194

169-
Flux_x, Flux_y = unsplitFluxes(self.cc_data, self.rp, dt)
195+
Flux_x, Flux_y = unsplitFluxes(self.cc_data, self.rp, self.vars, dt)
170196

171197
old_dens = dens.copy()
172198
old_ymom = ymom.copy()
@@ -177,43 +203,43 @@ def evolve(self, dt):
177203

178204
dens[myg.ilo:myg.ihi+1,myg.jlo:myg.jhi+1] += \
179205
dtdx*(Flux_x[myg.ilo :myg.ihi+1,
180-
myg.jlo :myg.jhi+1,vars.idens] - \
206+
myg.jlo :myg.jhi+1,self.vars.idens] - \
181207
Flux_x[myg.ilo+1:myg.ihi+2,
182-
myg.jlo :myg.jhi+1,vars.idens]) + \
208+
myg.jlo :myg.jhi+1,self.vars.idens]) + \
183209
dtdy*(Flux_y[myg.ilo :myg.ihi+1,
184-
myg.jlo :myg.jhi+1,vars.idens] - \
210+
myg.jlo :myg.jhi+1,self.vars.idens] - \
185211
Flux_y[myg.ilo :myg.ihi+1,
186-
myg.jlo+1:myg.jhi+2,vars.idens])
212+
myg.jlo+1:myg.jhi+2,self.vars.idens])
187213

188214
xmom[myg.ilo:myg.ihi+1,myg.jlo:myg.jhi+1] += \
189215
dtdx*(Flux_x[myg.ilo :myg.ihi+1,
190-
myg.jlo :myg.jhi+1,vars.ixmom] - \
216+
myg.jlo :myg.jhi+1,self.vars.ixmom] - \
191217
Flux_x[myg.ilo+1:myg.ihi+2,
192-
myg.jlo :myg.jhi+1,vars.ixmom]) + \
218+
myg.jlo :myg.jhi+1,self.vars.ixmom]) + \
193219
dtdy*(Flux_y[myg.ilo :myg.ihi+1,
194-
myg.jlo :myg.jhi+1,vars.ixmom] - \
220+
myg.jlo :myg.jhi+1,self.vars.ixmom] - \
195221
Flux_y[myg.ilo :myg.ihi+1,
196-
myg.jlo+1:myg.jhi+2,vars.ixmom])
222+
myg.jlo+1:myg.jhi+2,self.vars.ixmom])
197223

198224
ymom[myg.ilo:myg.ihi+1,myg.jlo:myg.jhi+1] += \
199225
dtdx*(Flux_x[myg.ilo :myg.ihi+1,
200-
myg.jlo :myg.jhi+1,vars.iymom] - \
226+
myg.jlo :myg.jhi+1,self.vars.iymom] - \
201227
Flux_x[myg.ilo+1:myg.ihi+2,
202-
myg.jlo :myg.jhi+1,vars.iymom]) + \
228+
myg.jlo :myg.jhi+1,self.vars.iymom]) + \
203229
dtdy*(Flux_y[myg.ilo :myg.ihi+1,
204-
myg.jlo :myg.jhi+1,vars.iymom] - \
230+
myg.jlo :myg.jhi+1,self.vars.iymom] - \
205231
Flux_y[myg.ilo :myg.ihi+1,
206-
myg.jlo+1:myg.jhi+2,vars.iymom])
232+
myg.jlo+1:myg.jhi+2,self.vars.iymom])
207233

208234
ener[myg.ilo:myg.ihi+1,myg.jlo:myg.jhi+1] += \
209235
dtdx*(Flux_x[myg.ilo :myg.ihi+1,
210-
myg.jlo :myg.jhi+1,vars.iener] - \
236+
myg.jlo :myg.jhi+1,self.vars.iener] - \
211237
Flux_x[myg.ilo+1:myg.ihi+2,
212-
myg.jlo :myg.jhi+1,vars.iener]) + \
238+
myg.jlo :myg.jhi+1,self.vars.iener]) + \
213239
dtdy*(Flux_y[myg.ilo :myg.ihi+1,
214-
myg.jlo :myg.jhi+1,vars.iener] - \
240+
myg.jlo :myg.jhi+1,self.vars.iener] - \
215241
Flux_y[myg.ilo :myg.ihi+1,
216-
myg.jlo+1:myg.jhi+2,vars.iener])
242+
myg.jlo+1:myg.jhi+2,self.vars.iener])
217243

218244

219245
# gravitational source terms
@@ -234,8 +260,6 @@ def dovis(self, n):
234260
ymom = self.cc_data.get_var("y-momentum")
235261
ener = self.cc_data.get_var("energy")
236262

237-
nvar = 4
238-
239263
# get the velocities
240264
u = xmom/dens
241265
v = ymom/dens
@@ -278,7 +302,7 @@ def dovis(self, n):
278302
if (L_x > 4*L_y):
279303
shrink = 0.75
280304

281-
onLeft = list(range(nvar))
305+
onLeft = list(range(self.vars.nvar))
282306

283307

284308
elif (L_y > 2*L_x):

compressible/unsplitFluxes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,8 @@
130130
import interface_f
131131
import mesh.reconstruction_f as reconstruction_f
132132
from util import profile
133-
import vars
134133

135-
def unsplitFluxes(my_data, rp, dt):
134+
def unsplitFluxes(my_data, rp, vars, dt):
136135
"""
137136
unsplitFluxes returns the fluxes through the x and y interfaces by
138137
doing an unsplit reconstruction of the interface values and then

compressible/vars.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)