Skip to content

Commit 439d863

Browse files
elswitAndreyAPopovSteven-Roberts
authored
Docs/usage (#131)
* added draft for usage page * Create paper.rst Added a draft for the ``usage`` page in documentation * up usade docs page * temp commit to save changes to sphinx conf, need to fix path for animations * pulling changes to docs on master (#124) * First draft of lorenz 96 docs * started ascher DAE doc writeup * docs for Ascher linear DAE * up Ascher docs, added presets * fixes based on past conversations * constructor for lorenz 63 presets * fixes * changed variable names to unicode * Sort presents alphabetically * Feature/oregonator docs (#119) * Start Oregonator docs * Add Canonical constructor docs * Fix Jacobian * Fix sphinx warning * Update python packages * up Ascher docs re code review * up Ascher docs, line width and unicode characters fixed * Make superclass for params (#118) * Make superclass for params * Fix param capitalization * Add docs * Update Ascher Linear DAE * Update CUSP * Update L'96 * Update Oregonator * Update PR * Update Robertson * Typo fixes * Fix Greek letters * Doc consistency fixes * Fix capitalization * fixes for the project file (#123) * Bumb version * Update DESCRIPTION --------- Co-authored-by: Andrey A Popov <apopov@vt.edu> Co-authored-by: Andrey A Popov <54905478+AndreyAPopov@users.noreply.github.com> Co-authored-by: Steven Roberts <sroberts994@gmail.com> * updated conf.py to copy webms from /images/animations dir to the /docs/_static dir * Update usage.rst --------- Co-authored-by: Andrey A Popov <apopov@vt.edu> Co-authored-by: Andrey A Popov <54905478+AndreyAPopov@users.noreply.github.com> Co-authored-by: Steven Roberts <sroberts994@gmail.com>
1 parent 525812b commit 439d863

File tree

7 files changed

+174
-2
lines changed

7 files changed

+174
-2
lines changed

docs/conf.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
from datetime import datetime
22
from yaml import safe_load
33

4+
import os
5+
import shutil
6+
7+
def copy_webm_files(source_dir, destination_dir):
8+
# Get a list of all files in the source directory
9+
files = os.listdir(source_dir)
10+
11+
if not os.path.exists(destination_directory):
12+
os.makedirs(destination_directory)
13+
14+
# Iterate over each file
15+
for file in files:
16+
# Check if the file is a .webm file
17+
if file.endswith(".webm"):
18+
# Create the full path of the source file
19+
source_file = os.path.join(source_dir, file)
20+
21+
# Create the full path of the destination file
22+
destination_file = os.path.join(destination_dir, file)
23+
24+
# Copy the file to the destination directory
25+
shutil.copy2(source_file, destination_file)
26+
27+
28+
source_directory = "../images/animations/"
29+
destination_directory = "../docs/build/_static"
30+
copy_webm_files(source_directory, destination_directory)
31+
432
with open('../DESCRIPTION') as stream:
533
otp = safe_load(stream)
634

@@ -18,6 +46,7 @@
1846
'sphinx_math_dollar',
1947
'sphinxcontrib.bibtex',
2048
'sphinx_rtd_theme',
49+
'sphinxcontrib.video',
2150
'myst_parser'
2251
]
2352

@@ -49,3 +78,5 @@
4978
html_theme_options = {
5079
'logo_only': True
5180
}
81+
82+

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ sphinxcontrib-matlabdomain==0.21.4
55
sphinxcontrib-napoleon==0.7
66
sphinx-math-dollar==1.2.1
77
sphinxcontrib-bibtex==2.6.2
8+
sphinxcontrib-video==0.2.0
89
setuptools==70.0.0 # Now required in python 3.12+
910
myst-parser==2.0.0
1011
pyyaml==6.0.1

docs/usage.rst

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,144 @@
1-
Usage
1+
Getting Started
22
================================================================================
3+
This guide shows you how to create, solve and visualize different problems in ODE Test Problems (``OTP``).
34

4-
TODO
5+
Mathematical formulation
6+
-----------------------------
7+
8+
All test problems in ``OTP`` are considered as a first-order
9+
differential-algebraic equation of the form
10+
11+
.. math::
12+
13+
14+
M(t, y)\;y'(t) = f(t, y), \qquad
15+
y(t_0) = y_0,
16+
17+
where :math:`y(t)` is the time-dependent solution to the problem,
18+
:math:`f(t, y)` is the right-hand-side function corresponding to the
19+
time-derivative of the system, and :math:`t` is the independent variable. :math:`M(t,y)` is
20+
the mass-matrix for the differential-algebraic system. When the test
21+
problem is an ordinary differential equation, :math:`M` is the Identity
22+
matrix. The initial condition :math:`y_0` specifies the value of
23+
:math:`y` at the initial time :math:`t = t_0`.
24+
25+
26+
Creating problems
27+
---------------------
28+
29+
Any problem in ``OTP`` can be initialized using a *problem name* and a
30+
*preset* that defines a set of specific parameters and initial
31+
conditions. The ``Canonical`` preset is available for all problems.
32+
33+
34+
35+
>>> problem = otp.lorenz63.presets.Canonical
36+
<BLANKLINE>
37+
Canonical with properties:
38+
<BLANKLINE>
39+
Name: 'Lorenz Equations'
40+
RHS: [1×1 otp.RHS]
41+
TimeSpan: [0 60]
42+
Y0: [3×1 double]
43+
Parameters: [1×1 otp.lorenz63.Lorenz63Parameters]
44+
NumVars: 3
45+
46+
The ``problem`` object contains a number of useful properties including:
47+
48+
- ``Name``: The name of the problem.
49+
- ``NumVars``: Number of variables in the state vector.
50+
- ``Parameters``: Vector of problem-specific parameters that can be
51+
modified.
52+
- ``RHS`` : A Right-hand-side structure that includes the ODE
53+
right-hand-side function and possibly Jacobians, splittings, etc.
54+
(depending on the test problem)
55+
- ``TimeSpan``: Time span of the integration.
56+
- ``Y0``: Initial condition of the problem.
57+
58+
Solving problems
59+
---------------------
60+
61+
Problems can be solved by calling the ``solve()`` method.
62+
63+
64+
>>> sol = problem.solve()
65+
<BLANKLINE>
66+
sol =
67+
<BLANKLINE>
68+
struct with fields:
69+
solver: 'ode45'
70+
extdata: [1×1 struct]
71+
x: [0 2.0095e-05 1.2057e-04 6.2295e-04 0.0031 0.0157 0.0401 0.0752 0.1224 0.1830 0.2582 0.3382 0.3853 0.4325 0.4758 0.5125 0.5552 0.6130 0.6764 … ] (1×820 double)
72+
y: [3×820 double]
73+
stats: [1×1 struct]
74+
idata: [1×1 struct]
75+
76+
``sol.x`` contains the time points at which the solver has calculated the solution and ``sol.y`` contains the solution at these times.
77+
Optional parameters can be passed to the ``solve()`` method to control the behaviour of the solver. For example:
78+
79+
>>> sol = problem.solve('MaxStep', 1e-6, 'RelTol', 1e-3 , 'AbsTol', 1e-6);
80+
81+
Visualizing solutions
82+
---------------------
83+
84+
OTP has built-in plotting capabilities for visualizing the computed
85+
solution. The ``plot()`` method can be used to plot the solution
86+
trajectory. The ``plotPhaseSpace()`` method creates a phase-space
87+
diagram by visualizing all spatial-components of the state vector. OTP
88+
also supports animations for the computed solution.
89+
90+
.. code:: matlab
91+
92+
% Plot the solution trajectory
93+
problem.plot(sol);
94+
95+
% Plot the Phase-Space solution
96+
problem.plotPhaseSpace(sol);
97+
98+
% Create a movie of the solution
99+
problem.movie(sol);
100+
101+
.. video:: ../_static/Lorenz-Original-Canonical.webm
102+
:loop:
103+
:width: 200
104+
105+
106+
107+
Changing the parameters
108+
------------------------
109+
You can change the parameters of the problem by modifying the
110+
``Parameters`` property of the problem object. The solution should be recalculated after updating a parameter.
111+
For example, changing the parameter :math:`\rho` in the Lorenz system leads to a different solution:
112+
113+
.. code:: matlab
114+
115+
% Change a parameter in the Lorenz system
116+
problem.Parameters.Rho = 10
117+
118+
% Solve the problem again
119+
sol = problem.solve('MaxStep' , 1e-4);
120+
problem.movie(sol);
121+
122+
.. video:: ../_static/Lorenz-Alternate-Canonical.webm
123+
:loop:
124+
:width: 200
125+
Changing the solver
126+
-------------------
127+
128+
OTP uses appropriate internal solvers to integrate each problem.
129+
However, you can plug-in your specific solvers to integrate any test problem by passing the right-hand-side
130+
function, time span, initial condition and other parameters to
131+
the solver. As an example, to use the *Implicit* ``ode23s`` time-stepping method for the Lorenz system, you can use the
132+
following code:
133+
134+
.. code:: matlab
135+
136+
sol = ode23s(problem.RHS.F, problem.TimeSpan, problem.Y0, ...
137+
odeset('Jacobian', problem.RHS.Jacobian));
138+
This is particularly useful when you want to compare the performance of different solvers on the same problem.
139+
140+
Next Steps
141+
------------------------
142+
Explore different problems available in OTP by browsing the Problems Gallery in the sidebar. You can define your custom
143+
problems by creating a new class that inherits from the ``otp.Problem`` class.
144+
See the `Contributing Guide <../contributing>`_ for more details.

images/Lorenz-Phase-plot.png

353 KB
Loading

images/Lorenz-solution-plot.png

188 KB
Loading
301 KB
Binary file not shown.
433 KB
Binary file not shown.

0 commit comments

Comments
 (0)