Skip to content

Commit

Permalink
add initialize() instead of using parent class) (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhichen3 authored Jan 30, 2024
1 parent 3edc9fe commit 001318e
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion pyro/viscous_burgers/simulation.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,49 @@
import importlib

from pyro.burgers import Simulation as burgers_sim
from pyro.burgers import burgers_interface
from pyro.mesh import reconstruction
from pyro.mesh import patch, reconstruction
from pyro.particles import particles
from pyro.simulation_null import bc_setup, grid_setup
from pyro.viscous_burgers import interface


class Simulation(burgers_sim):

def initialize(self):
"""
Initialize the grid and variables for advection and set the initial
conditions for the chosen problem.
"""

# create grid, self.rp contains mesh.nx and mesh.ny
my_grid = grid_setup(self.rp, ng=4)

# create the variables
my_data = patch.CellCenterData2d(my_grid)

# outputs: bc, bc_xodd and bc_yodd for reflection boundary cond
bc = bc_setup(self.rp)[0]

# register variables in the data
# burgers equation advects velocity

my_data.register_var("x-velocity", bc)
my_data.register_var("y-velocity", bc)
my_data.create()

# holds various data, like time and registered variable.
self.cc_data = my_data

if self.rp.get_param("particles.do_particles") == 1:
n_particles = self.rp.get_param("particles.n_particles")
particle_generator = self.rp.get_param("particles.particle_generator")
self.particles = particles.Particles(self.cc_data, bc, n_particles, particle_generator)

# now set the initial conditions for the problem
problem = importlib.import_module(f"pyro.viscous_burgers.problems.{self.problem_name}")
problem.init_data(self.cc_data, self.rp)

def evolve(self):
"""
Evolve the viscous burgers equation through one timestep.
Expand Down

0 comments on commit 001318e

Please sign in to comment.