Running#
Pyro can be run in two ways:
from the commandline, using the
pyro_sim.py
script (this will be installed into your search path)by using the
Pyro
class directly in ipython or Jupyter
Commandline#
The pyro_sim.py
script takes 3
arguments: the solver name, the problem setup to run with that solver
(this is defined in the solver’s problems/
sub-directory), and the
inputs file (again, usually from the solver’s problems/
directory).
For example, to run the Sedov problem with the compressible solver we would do:
pyro_sim.py compressible sedov inputs.sedov
This knows to look for inputs.sedov
in compressible/problems/
(alternately, you can specify the full path for the inputs file).
To run the smooth Gaussian advection problem with the advection solver, we would do:
pyro_sim.py advection smooth inputs.smooth
Any runtime parameter can also be specified on the command line, after the inputs file. For example, to disable runtime visualization for the above run, we could do:
pyro_sim.py advection smooth inputs.smooth vis.dovis=0
Note
Quite often, the slowest part of the runtime is the visualization, so disabling
vis as shown above can dramatically speed up the execution. You can always
plot the results after the fact using the plot.py
script, as discussed
in Analysis routines.
Pyro class#
Alternatively, pyro can be run using the Pyro
class. This provides
an interface that enables simulations to be set up and run in a Jupyter notebook. A simulation can be set up and run
by carrying out the following steps:
create a
Pyro
object, initializing it with a specific solverinitialize the problem, passing in runtime parameters and inputs
run the simulation
For example, if we wished to use the compressible
solver to run the
Kelvin-Helmholtz problem kh
, we would do the following:
from pyro import Pyro
p = Pyro("compressible")
p.initialize_problem("kh")
p.run_sim()
This will use the default set of parameters for the problem specified
in the inputs file defined by DEFAULT_INPUTS
in the problem
initialization module.
Note
By default, I/O, visualization, and verbosity are disabled when we run in Jupyter.
Instead of using an inputs file to define the problem parameters, we can define a
dictionary of parameters and pass them into the initialize_problem
function using the keyword argument inputs_dict
.
If an inputs file is also passed into the function, the parameters in the dictionary
will override any parameters in the file.
Tip
If you want to see all of the runtime parameters and their current values, you can
simply print the Pyro
object:
print(p)
For example, if we wished to turn on verbosity for the previous example, we would do:
parameters = {"driver.verbose": 1}
p.initialize_problem("kh", inputs_dict=parameters)
It’s possible to evolve the simulation forward timestep by timestep manually using
the single_step
function (rather than allowing
run_sim
to do this for us). To evolve our example
simulation forward by a single step, we’d run
p.single_step()
This will fill the boundary conditions, compute the timestep dt
, evolve a
single timestep and do output/visualization (if required).
Runtime options#
The behavior of the main driver, the solver, and the problem setup can
be controlled by runtime parameters specified in the inputs file (or
via the command line or passed into the initialize_problem
function).
Runtime parameters are grouped into sections,
with the heading of that section enclosed in [ .. ]
. The list of
parameters are stored in three places:
the
pyro/_defaults
filethe solver’s
_defaults
fileproblem-specific parameters: each problem module provides a dictionary called
PROBLEM_PARAMS
that is used to define the problem-specific parameters and their defaults.
These defaults are parsed at runtime to define the list of valid
parameters. The inputs file is read next and used to override the
default value of any of these previously defined
parameters. Then any parameters passed to Pyro
via a dictionary
or added to the commandline when using pyro_sim.py
are parsed
and override the current values.
The collection of runtime parameters is stored in a
RuntimeParameters
object.
The runparams.py
module in util/
controls access to the runtime
parameters. You can setup the runtime parameters, parse an inputs
file, and access the value of a parameter (hydro.cfl
in this example)
as:
rp = RuntimeParameters()
rp.load_params("inputs.test")
...
cfl = rp.get_param("hydro.cfl")
Tip
When pyro is run, the file inputs.auto
is output containing the
full list of runtime parameters, their value for the simulation, and
the comment that was associated with them from the _defaults
files. This is a useful way to see what parameters are in play for a
given simulation.
All solvers use the following parameters:
section:
[driver]
option
value
description
tmax
1.0
maximum simulation time to evolve
max_steps
10000
maximum number of steps to take
fix_dt
-1.0
init_tstep_factor
0.01
first timestep = init_tstep_factor * CFL timestep
max_dt_change
2.0
max amount the timestep can change between steps
verbose
1.0
verbosity
section:
[io]
option
value
description
basename
pyro_
basename for output files
dt_out
0.1
simulation time between writing output files
n_out
10000
number of timesteps between writing output files
do_io
1
do we output at all?
force_final_output
0
regardless of do_io, do we output when the simulation ends?
section:
[mesh]
option
value
description
grid_type
Cartesian2d
Geometry of the Grid (‘Cartesian2d’ or ‘SphericalPolar’)
xmin
0.0
domain minimum x-coordinate
xmax
1.0
domain maximum x-coordinate
ymin
0.0
domain minimum y-coordinate
ymax
1.0
domain maximum y-coordinate
xlboundary
reflect
minimum x BC (‘reflect’, ‘outflow’, or ‘periodic’)
xrboundary
reflect
maximum x BC (‘reflect’, ‘outflow’, or ‘periodic’)
ylboundary
reflect
minimum y BC (‘reflect’, ‘outflow’, or ‘periodic’)
yrboundary
reflect
maximum y BC (‘reflect’, ‘outflow’, or ‘periodic’)
nx
25
number of zones in the x-direction
ny
25
number of zones in the y-direction
section:
[particles]
option
value
description
do_particles
0
include particles? (1=yes, 0=no)
n_particles
100
number of particles
particle_generator
random
how do we generate particles? (random, grid)
section:
[vis]
option
value
description
dovis
1
runtime visualization? (1=yes, 0=no)
store_images
0
store vis images to files (1=yes, 0=no)