Skip to content

Commit bd79659

Browse files
author
Michael Zingale
committed
simplify the conservative update as a loop
1 parent 55628af commit bd79659

File tree

2 files changed

+30
-39
lines changed

2 files changed

+30
-39
lines changed

compressible/simulation.py

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ def preevolve(self):
179179

180180

181181
def evolve(self, dt):
182+
"""
183+
Evolve the equations of compressible hydrodynamics through a timestep dt
184+
"""
182185

183186
pf = profile.timer("evolve")
184187
pf.begin()
@@ -201,46 +204,14 @@ def evolve(self, dt):
201204
dtdx = dt/myg.dx
202205
dtdy = dt/myg.dy
203206

204-
dens[myg.ilo:myg.ihi+1,myg.jlo:myg.jhi+1] += \
205-
dtdx*(Flux_x[myg.ilo :myg.ihi+1,
206-
myg.jlo :myg.jhi+1,self.vars.idens] - \
207-
Flux_x[myg.ilo+1:myg.ihi+2,
208-
myg.jlo :myg.jhi+1,self.vars.idens]) + \
209-
dtdy*(Flux_y[myg.ilo :myg.ihi+1,
210-
myg.jlo :myg.jhi+1,self.vars.idens] - \
211-
Flux_y[myg.ilo :myg.ihi+1,
212-
myg.jlo+1:myg.jhi+2,self.vars.idens])
213-
214-
xmom[myg.ilo:myg.ihi+1,myg.jlo:myg.jhi+1] += \
215-
dtdx*(Flux_x[myg.ilo :myg.ihi+1,
216-
myg.jlo :myg.jhi+1,self.vars.ixmom] - \
217-
Flux_x[myg.ilo+1:myg.ihi+2,
218-
myg.jlo :myg.jhi+1,self.vars.ixmom]) + \
219-
dtdy*(Flux_y[myg.ilo :myg.ihi+1,
220-
myg.jlo :myg.jhi+1,self.vars.ixmom] - \
221-
Flux_y[myg.ilo :myg.ihi+1,
222-
myg.jlo+1:myg.jhi+2,self.vars.ixmom])
223-
224-
ymom[myg.ilo:myg.ihi+1,myg.jlo:myg.jhi+1] += \
225-
dtdx*(Flux_x[myg.ilo :myg.ihi+1,
226-
myg.jlo :myg.jhi+1,self.vars.iymom] - \
227-
Flux_x[myg.ilo+1:myg.ihi+2,
228-
myg.jlo :myg.jhi+1,self.vars.iymom]) + \
229-
dtdy*(Flux_y[myg.ilo :myg.ihi+1,
230-
myg.jlo :myg.jhi+1,self.vars.iymom] - \
231-
Flux_y[myg.ilo :myg.ihi+1,
232-
myg.jlo+1:myg.jhi+2,self.vars.iymom])
233-
234-
ener[myg.ilo:myg.ihi+1,myg.jlo:myg.jhi+1] += \
235-
dtdx*(Flux_x[myg.ilo :myg.ihi+1,
236-
myg.jlo :myg.jhi+1,self.vars.iener] - \
237-
Flux_x[myg.ilo+1:myg.ihi+2,
238-
myg.jlo :myg.jhi+1,self.vars.iener]) + \
239-
dtdy*(Flux_y[myg.ilo :myg.ihi+1,
240-
myg.jlo :myg.jhi+1,self.vars.iener] - \
241-
Flux_y[myg.ilo :myg.ihi+1,
242-
myg.jlo+1:myg.jhi+2,self.vars.iener])
207+
for n in range(self.vars.nvar):
208+
var = self.cc_data.get_var_by_index(n)
243209

210+
var[myg.ilo:myg.ihi+1,myg.jlo:myg.jhi+1] += \
211+
dtdx*(Flux_x[myg.ilo :myg.ihi+1,myg.jlo :myg.jhi+1,n] - \
212+
Flux_x[myg.ilo+1:myg.ihi+2,myg.jlo :myg.jhi+1,n]) + \
213+
dtdy*(Flux_y[myg.ilo :myg.ihi+1,myg.jlo :myg.jhi+1,n] - \
214+
Flux_y[myg.ilo :myg.ihi+1,myg.jlo+1:myg.jhi+2,n])
244215

245216
# gravitational source terms
246217
ymom += 0.5*dt*(dens + old_dens)*grav

mesh/patch.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,26 @@ def get_var(self, name):
486486
n = self.vars.index(name)
487487
return self.data[n,:,:]
488488

489+
490+
def get_var_by_index(self, n):
491+
"""
492+
Return a data array for the variable with index n in the
493+
data array. Any changes made to this are automatically
494+
reflected in the CellCenterData2d object.
495+
496+
Parameters
497+
----------
498+
n : int
499+
The index of the variable to access
500+
501+
Returns
502+
-------
503+
out : ndarray
504+
The array of data corresponding to the index
505+
506+
"""
507+
return self.data[n,:,:]
508+
489509

490510
def get_aux(self, keyword):
491511
"""

0 commit comments

Comments
 (0)