|
| 1 | +# Usage |
| 2 | + |
| 3 | +Given a collection of atoms, their initial positions, and their velocities, |
| 4 | +MyWrapperName uses MySimulationEngine to calculate their future positions, |
| 5 | +under the assumption that atoms do not exert any kind of force among themselves |
| 6 | +neither there are any external forces acting on them. |
| 7 | + |
| 8 | +To use MyWrapperName, start by importing it from the `simphony_osp.wrappers` |
| 9 | +module, as well as by importing the `ontology_namespace` namespace. |
| 10 | + |
| 11 | +```python |
| 12 | +from simphony_osp.namespaces import ontology_namespace |
| 13 | +from simphony_osp.wrappers import SimulationWrapper |
| 14 | +``` |
| 15 | + |
| 16 | +The next step is to call `SimulationWrapper` to create a SimPhoNy session |
| 17 | + |
| 18 | +```python |
| 19 | +session = SimulationWrapper() |
| 20 | +session.locked = True # prevent session from closing after with statement |
| 21 | +``` |
| 22 | + |
| 23 | +and populate it with your input data. |
| 24 | + |
| 25 | +```python |
| 26 | +with session: |
| 27 | + for i in range(3): |
| 28 | + atom = ontology_namespace.Atom() |
| 29 | + atom[ontology_namespace.hasPart] = { |
| 30 | + ontology_namespace.Position(value=[i, i, i], unit="m"), |
| 31 | + ontology_namespace.Velocity(value=[i, -i, i], unit="m/s"), |
| 32 | + } |
| 33 | +``` |
| 34 | + |
| 35 | +MyWrapperName uses individuals belonging to classes from MyOntology to |
| 36 | +represent atoms, their positions and velocities. MyWrapperName expects to find |
| 37 | +the following pattern in the session's knowledge graph. |
| 38 | + |
| 39 | +<figure style="display: table; text-align:center; margin-left: auto; margin-right:auto"> |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +<figcaption style="display: table-caption; caption-side: bottom; text-align:center"> |
| 44 | + |
| 45 | +_Pattern that MyWrapperName interprets in the session's knowledge graph in |
| 46 | +order to recognize the atoms, their positions and their velocities._ |
| 47 | + |
| 48 | +</figcaption> |
| 49 | + |
| 50 | +</figure> |
| 51 | + |
| 52 | +Finally, use SimPhoNy's `compute` command to run the simulation, optionally |
| 53 | +specifying the number of time steps to consider in seconds (defaults to `1`). |
| 54 | +Negative values can be provided in order to run the simulation backwards in |
| 55 | +time. |
| 56 | + |
| 57 | +```python |
| 58 | +session.compute() |
| 59 | +# session.compute(time_steps=5) |
| 60 | +``` |
| 61 | + |
| 62 | +After running the simulation, all the same atom, position and velocity ontology |
| 63 | +individuals will still be available in the session, but their positions will |
| 64 | +have changed. As there are no forces acting on the atoms, their velocities |
| 65 | +will remain constant. |
| 66 | + |
0 commit comments