-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathsimulation.py
More file actions
42 lines (29 loc) · 1.24 KB
/
simulation.py
File metadata and controls
42 lines (29 loc) · 1.24 KB
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
import pyro.advection.advective_fluxes as flx
from pyro import advection
from pyro.advection_ppm.interface import ppm_interface
class Simulation(advection.Simulation):
def evolve(self):
"""
Evolve the linear advection equation through one timestep. We only
consider the "density" variable in the CellCenterData2d object that
is part of the Simulation.
"""
tm_evolve = self.tc.timer("evolve")
tm_evolve.begin()
dtdx = self.dt/self.cc_data.grid.dx
dtdy = self.dt/self.cc_data.grid.dy
Fx, Fy = flx.unsplit_fluxes(self.cc_data, self.rp, self.dt, "density", ppm_interface)
dens = self.cc_data.get_var("density")
dens.v()[:, :] = dens.v() + dtdx*(Fx.v() - Fx.ip(1)) + \
dtdy*(Fy.v() - Fy.jp(1))
if self.particles is not None:
myg = self.cc_data.grid
u = self.rp.get_param("advection.u")
v = self.rp.get_param("advection.v")
u2d = myg.scratch_array() + u
v2d = myg.scratch_array() + v
self.particles.update_particles(self.dt, u2d, v2d)
# increment the time
self.cc_data.t += self.dt
self.n += 1
tm_evolve.end()