Skip to content

Commit

Permalink
Added a Lorenz CellML and SED-ML files, as well as a corresponding Py…
Browse files Browse the repository at this point in the history
…thon script and Jupyter notebook.

The idea of the Python script will be to test all of our Python wrappers.
  • Loading branch information
agarny committed Nov 18, 2019
1 parent 98eeead commit 29f78b7
Show file tree
Hide file tree
Showing 4 changed files with 523 additions and 0 deletions.
112 changes: 112 additions & 0 deletions models/tests/jupyter/lorenz.ipynb
@@ -0,0 +1,112 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import OpenCOR as oc"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s = oc.openSimulation('../sedml/lorenz/lorenz.sedml')\n",
"s"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s.run()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"r = s.results()\n",
"r"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"states = r.states()\n",
"states"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x = states['main/x'].values()\n",
"y = states['main/y'].values()\n",
"z = states['main/z'].values()\n",
"x,y,z"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"from mpl_toolkits import mplot3d\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.axes(projection='3d').plot3D(x, y, z)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "OpenCOR",
"language": "python",
"name": "opencor"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
47 changes: 47 additions & 0 deletions models/tests/python/lorenz.py
@@ -0,0 +1,47 @@
# Open our Lorenz SED-ML document

import os
import OpenCOR as oc

s = oc.openSimulation(os.path.dirname(__file__) + '/../sedml/lorenz/lorenz.sedml')

print('---------------------------------------')
print('Simulation:')
print(s)

# Run our Lorenz simulation

s.run()

# Retrieve our simulation results

r = s.results()

print('---------------------------------------')
print('Results:')
print(r)

# Retrieve our states

states = r.states()

print('---------------------------------------')
print('States:')
print(states)

# Retrieve the values for our states

x = states['main/x'].values()
y = states['main/y'].values()
z = states['main/z'].values()

print('---------------------------------------')
print('x, y and z:')
print(x, y, z)

# Generate a 3D plot for our states

from mpl_toolkits import mplot3d
import matplotlib.pyplot as plt

plt.axes(projection='3d').plot3D(x, y, z)
79 changes: 79 additions & 0 deletions models/tests/sedml/lorenz/lorenz.cellml
@@ -0,0 +1,79 @@
<?xml version='1.0'?>
<model name="Lorenz" xmlns="http://www.cellml.org/cellml/1.0#" xmlns:cellml="http://www.cellml.org/cellml/1.0#">
<component name="main">
<variable initial_value="0" name="t" units="dimensionless"/>
<variable initial_value="1" name="x" units="dimensionless"/>
<variable initial_value="1" name="y" units="dimensionless"/>
<variable initial_value="1" name="z" units="dimensionless"/>
<variable initial_value="10" name="sigma" units="dimensionless"/>
<variable initial_value="28" name="rho" units="dimensionless"/>
<variable initial_value="2.66667" name="beta" units="dimensionless"/>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<apply>
<eq/>
<apply>
<diff/>
<bvar>
<ci>t</ci>
</bvar>
<ci>x</ci>
</apply>
<apply>
<times/>
<ci>sigma</ci>
<apply>
<minus/>
<ci>y</ci>
<ci>x</ci>
</apply>
</apply>
</apply>
<apply>
<eq/>
<apply>
<diff/>
<bvar>
<ci>t</ci>
</bvar>
<ci>y</ci>
</apply>
<apply>
<minus/>
<apply>
<times/>
<ci>x</ci>
<apply>
<minus/>
<ci>rho</ci>
<ci>z</ci>
</apply>
</apply>
<ci>y</ci>
</apply>
</apply>
<apply>
<eq/>
<apply>
<diff/>
<bvar>
<ci>t</ci>
</bvar>
<ci>z</ci>
</apply>
<apply>
<minus/>
<apply>
<times/>
<ci>x</ci>
<ci>y</ci>
</apply>
<apply>
<times/>
<ci>beta</ci>
<ci>z</ci>
</apply>
</apply>
</apply>
</math>
</component>
</model>

0 comments on commit 29f78b7

Please sign in to comment.