Skip to content

Commit 001318e

Browse files
authored
add initialize() instead of using parent class) (#188)
1 parent 3edc9fe commit 001318e

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

pyro/viscous_burgers/simulation.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,49 @@
1+
import importlib
2+
13
from pyro.burgers import Simulation as burgers_sim
24
from pyro.burgers import burgers_interface
3-
from pyro.mesh import reconstruction
5+
from pyro.mesh import patch, reconstruction
6+
from pyro.particles import particles
7+
from pyro.simulation_null import bc_setup, grid_setup
48
from pyro.viscous_burgers import interface
59

610

711
class Simulation(burgers_sim):
812

13+
def initialize(self):
14+
"""
15+
Initialize the grid and variables for advection and set the initial
16+
conditions for the chosen problem.
17+
"""
18+
19+
# create grid, self.rp contains mesh.nx and mesh.ny
20+
my_grid = grid_setup(self.rp, ng=4)
21+
22+
# create the variables
23+
my_data = patch.CellCenterData2d(my_grid)
24+
25+
# outputs: bc, bc_xodd and bc_yodd for reflection boundary cond
26+
bc = bc_setup(self.rp)[0]
27+
28+
# register variables in the data
29+
# burgers equation advects velocity
30+
31+
my_data.register_var("x-velocity", bc)
32+
my_data.register_var("y-velocity", bc)
33+
my_data.create()
34+
35+
# holds various data, like time and registered variable.
36+
self.cc_data = my_data
37+
38+
if self.rp.get_param("particles.do_particles") == 1:
39+
n_particles = self.rp.get_param("particles.n_particles")
40+
particle_generator = self.rp.get_param("particles.particle_generator")
41+
self.particles = particles.Particles(self.cc_data, bc, n_particles, particle_generator)
42+
43+
# now set the initial conditions for the problem
44+
problem = importlib.import_module(f"pyro.viscous_burgers.problems.{self.problem_name}")
45+
problem.init_data(self.cc_data, self.rp)
46+
947
def evolve(self):
1048
"""
1149
Evolve the viscous burgers equation through one timestep.

0 commit comments

Comments
 (0)