Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
content badge Iframe embedding
swh:1:cnt:68bd6815910d0e569e0ea7e516d7499bfc1414b0

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
# Embedded Python

## Build with embedded Python support

To enable the embedded Python support just activate the CMake option USE_EMBEDDED_PYTHON which is by default turned off. Please ensure that CMake finds the Python interpreter. This can be achieved by setting the PYTHON_EXECUTABLE to the file path of the python interpreter.

## Run simulator with embedded Python support

Make sure that the environment variables PYTHONHOME and PYTHONPATH are set to the directory of your Python installation. Also make sure that the pythonXX.dll (where XX defines the version) is in your path.

When running the simulator with embedded Python support, the new tab 'Scripts' should appear in the GUI. Here you can load a script file or reload it. 

Alternatively, you can load the Python script directly in a scene. Just use the json key ```scriptFile``` in the scene file to define the location of the script. If a relative path is used, the simulator assumes that it is relative to the scene file. 

## Writing a script

First, you have to import the module ```splishsplash```, e.g. by: ```import splishsplash as sph ```

When the script is loaded, the simulator will call the function ```init()``` automatically. If you defined a function ```step()```, it will be called in each simulation step. If you defined a function ```reset()```, it will be called when the simulation is reset. Moreover, you can define additional functions that can be called using the GUI.  

### init(base)

If this function is defined, it is called automatically when the script is loaded or reloaded. The parameter base contains the current SimulationBase object.

### step()

If this function is defined, it is called automatically in each simulation step. 

### reset()

If this function is defined, it is called automatically in each simulation reset. 

### Additional commands

Additional commands that can be executed via the GUI (buttons will be added) can be defined by a list of strings. The list must be called ```function_list``` and must contain the names of functions that should be called, e.g.
```python
function_list = ['command', 'command2']
```

## Example 

This is a simple example script which prints the current simulation time, the position of particle 0 and a counter value in each step:

```python
import splishsplash as sph
import numpy as np

counter = 0
function_list = ['command', 'command2']

def init():
    global counter
    print("init test")
    counter = 1
    
def step():
    global counter
    sim = sph.Simulation.getCurrent()
    fluid = sim.getFluidModel(0)
    tm = sph.TimeManager.getCurrent()
    print(fluid.getPosition(0))
    print(tm.getTime())
    print(counter)
    counter += 1
    print("---")
    
def reset():
    print("reset test")
    
def command():
    print("tst cmd")
        
def command2():
    print("tst cmd2")
```

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API