# Scripting Ocellaris¶

There are three main ways of scripting Ocellaris:

1. Generate input files by a script and run Ocellaris on these

2. Include Python code in the input file (see the User Guide for details)

3. Use the Python programming interface

A brief example of the first would be something like this that runs Ocellaris with two different time steps by producing input files and starting Ocellaris as a command line application:

import yaml, subprocess

# Load the template input file
with open('template.inp', 'rt') as inp:

for dt in [0.1, 0.05]:
# Modify the input file
prefix = 'test_dt_%.3f' % dt
input_dict['time']['dt'] = dt
input_dict['output']['prefix'] = prefix

# Save the modified input file
new_inp_file = prefix + '.inp'
with open(new_inp_file, 'wt') as out:
yaml.dump(input_dict, out)

# Run Ocellaris with the modified input file
p = subprocess.Popen(['python', '-m', 'ocellaris', new_inp_file],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = p.communicate()


The same can be accomplished from a script which uses the Ocellaris Python API:

from ocellaris import Simulation, setup_simulation, run_simulation

for dt in [0.1, 0.05]:
prefix = 'test_dt_%.3f' % dt

# Create a simulation object, load an input file and modify the time step
sim = Simulation()

Examples of this can be seen in the convergence scripts which can be found in the cases/ subdirectory of the Ocellaris repository.