Skip to content

Commit 164f71e

Browse files
docs: describe public api in front-page of API docs (#4536)
* docs: describe public api in front-page of API docs * docs: add set_logging_level to docs * docs: move public api description to userguide * fix doctest warnings * fix reference * edit parameters for clarity --------- Co-authored-by: Eric G. Kratz <[email protected]>
1 parent f20a00e commit 164f71e

File tree

5 files changed

+90
-2
lines changed

5 files changed

+90
-2
lines changed

docs/source/api/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ API documentation
99
:Release: |version|
1010
:Date: |today|
1111

12-
This reference manual details functions, modules, and objects
13-
included in PyBaMM, describing what they are and what they do.
12+
This reference manual details the classes, functions, modules, and objects included in PyBaMM, describing what they are and what they do.
1413
For a high-level introduction to PyBaMM, see the :ref:`user guide <user_guide>` and the :ref:`examples <pybamm_examples>`.
1514

15+
1616
.. toctree::
1717
:maxdepth: 2
1818

docs/source/api/util.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ Utility functions
1919
.. autofunction:: pybamm.has_jax
2020

2121
.. autofunction:: pybamm.is_jax_compatible
22+
23+
.. autofunction:: pybamm.set_logging_level
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
----------
2+
Public API
3+
----------
4+
5+
.. module:: pybamm
6+
:noindex:
7+
8+
PyBaMM is a Python package for mathematical modelling and simulation of battery systems. The main classes and functions that are intended to be used by the user are described in this document.
9+
For a more detailed description of the classes and methods, see the :doc:`API reference </source/api/index>`.
10+
11+
Available PyBaMM models
12+
-----------------------
13+
14+
PyBaMM includes a number of pre-implemented models, which can be used as they are or modified to suit your needs. The main models are:
15+
16+
- :class:`lithium_ion.SPM`: Single Particle Model
17+
- :class:`lithium_ion.SPMe`: Single Particle Model with Electrolyte
18+
- :class:`lithium_ion.DFN`: Doyle-Fuller-Newman
19+
20+
The behaviour of the models can be modified by passing in an :class:`BatteryModelOptions` object when creating the model.
21+
22+
Simulations
23+
-----------
24+
25+
:class:`Simulation` is a class that automates the process of setting up a model and solving it, and acts as the highest-level API to PyBaMM.
26+
Pass at least a :class:`BaseModel` object, and optionally the experiment, solver, parameter values, and geometry objects described below to the :class:`Simulation` object.
27+
Any of these optional arguments not provided will be supplied by the defaults specified in the model.
28+
29+
Parameters
30+
----------
31+
32+
PyBaMM models are parameterised by a set of parameters, which are stored in a :class:`ParameterValues` object. This object acts like a Python dictionary with a few extra PyBaMM specific features and methods.
33+
Parameters in a model are represented as either :class:`Parameter` objects or :class:`FunctionParameter` objects, and the values in the :class:`ParameterValues` object replace these objects in the model before it is solved.
34+
The values in the :class:`ParameterValues` object can be scalars, Python functions or expressions of type :class:`Symbol`.
35+
36+
Experiments
37+
-----------
38+
39+
An :class:`Experiment` object represents an experimental protocol that can be used to simulate the behaviour of a battery. The particular protocol can be provided as a Python string, or as a sequences of
40+
:class:`step.BaseStep` objects.
41+
42+
Solvers
43+
-------
44+
45+
The two main solvers in PyBaMM are the :class:`CasadiSolver` and the :class:`IDAKLUSolver`. Both are wrappers around the Sundials suite of solvers, but the :class:`CasadiSolver` uses the CasADi library
46+
whereas the :class:`IDAKLUSolver` is PyBaMM specific. Both solvers have many options that can be set to control the solver behaviour, see the documentation for each solver for more details.
47+
48+
When a model is solved, the solution is returned as a :class:`Solution` object.
49+
50+
Plotting
51+
--------
52+
53+
A solution object can be plotted using the :meth:`Solution.plot` or :meth:`Simulation.plot` methods, which returns a :class:`QuickPlot` object.
54+
Note that the arguments to the plotting methods of both classes are the same as :class:`QuickPlot`.
55+
56+
Other plotting functions are the :func:`plot_voltage_components` and :func:`plot_summary_variables` functions, which correspond to the similarly named methods of the :class:`Solution` and :class:`Simulation` classes.
57+
58+
Writing PyBaMM models
59+
---------------------
60+
61+
Each PyBaMM model, and the custom models written by users, are written as a set of expressions that describe the model. Each of the expressions is a subclass of the :class:`Symbol` class, which represents a mathematical expression.
62+
63+
If you wish to create a custom model, you can use the :class:`BaseModel` class as a starting point.
64+
65+
66+
Discretisation
67+
--------------
68+
69+
Each PyBaMM model contains continuous operators that must be discretised before they can be solved. This is done using a :class:`Discretisation` object, which takes a :class:`Mesh` object and a dictionary of :class:`SpatialMethod` objects.
70+
71+
Logging
72+
-------
73+
74+
PyBaMM uses the Python logging module to log messages at different levels of severity. Use the :func:`pybamm.set_logging_level` function to set the logging level for PyBaMM.

docs/source/user_guide/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ maxdepth: 2
2222
---
2323
fundamentals/index
2424
fundamentals/battery_models
25+
fundamentals/public_api
2526
```
2627

2728
```{toctree}

src/pybamm/logger.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ def func(self, message, *args, **kws):
2424

2525

2626
def set_logging_level(level):
27+
"""
28+
Set the logging level for PyBaMM
29+
30+
Parameters
31+
----------
32+
33+
level: str
34+
The logging level to set. Should be one of 'DEBUG', 'INFO', 'WARNING',
35+
'ERROR', 'CRITICAL'
36+
37+
"""
2738
logger.setLevel(level)
2839

2940

0 commit comments

Comments
 (0)