Skip to content

Commit

Permalink
Merge pull request #155 from csdms/mcflugen/add-sidl-and-python-tabs
Browse files Browse the repository at this point in the history
Add sidl and python tabs for the BMI spec
  • Loading branch information
mcflugen authored Nov 7, 2024
2 parents 7b5bb08 + 37c59b0 commit 7c25129
Show file tree
Hide file tree
Showing 7 changed files with 645 additions and 126 deletions.
70 changes: 58 additions & 12 deletions docs/source/bmi.control_funcs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,22 @@ updating.
*initialize*
^^^^^^^^^^^^

.. code-block:: java
.. tab-set::
:sync-group: lang

/* SIDL */
int initialize(in string config_file);
.. tab-item:: SIDL
:sync: sidl

.. code-block:: java
int initialize(in string config_file);
.. tab-item:: Python
:sync: python

.. code-block:: python
def initialize(self, config_file: str) -> None:
The `initialize` function accepts a string argument that gives the
path to its :term:`configuration file`.
Expand Down Expand Up @@ -48,10 +59,22 @@ formatted.
*update*
^^^^^^^^

.. code-block:: java
.. tab-set::
:sync-group: lang

.. tab-item:: SIDL
:sync: sidl

.. code-block:: java
int update();
.. tab-item:: Python
:sync: python

.. code-block:: python
/* SIDL */
int update();
def update(self) -> None:
The `update` function advances the model by a single time step. This
is the model's own internal time step (as returned by the BMI
Expand All @@ -75,10 +98,22 @@ function can just return without doing anything.
*update_until*
^^^^^^^^^^^^^^

.. code-block:: java
.. tab-set::
:sync-group: lang

/* SIDL */
int update_until(in double time);
.. tab-item:: SIDL
:sync: sidl

.. code-block:: java
int update_until(in double time);
.. tab-item:: Python
:sync: python

.. code-block:: python
def update_until(self, time: float) -> None:
The `update_until` function updates the model to a particular time,
as provided by its *time* argument.
Expand All @@ -101,11 +136,22 @@ to reflect that the model was updated to the requested time.
*finalize*
^^^^^^^^^^

.. code-block:: java
.. tab-set::
:sync-group: lang

.. tab-item:: SIDL
:sync: sidl

.. code-block:: java
int finalize();
.. tab-item:: Python
:sync: python

/* SIDL */
int finalize();
.. code-block:: python
def finalize(self) -> None:
The `finalize` function should perform all tasks that take place
after exiting the model's time loop. This typically includes
Expand Down
94 changes: 79 additions & 15 deletions docs/source/bmi.getter_setter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,22 @@ state variable can be changed or check the new data for validity.
*get_value*
^^^^^^^^^^^

.. code-block:: java
.. tab-set::
:sync-group: lang

/* SIDL */
int get_value(in string name, in array<> dest);
.. tab-item:: SIDL
:sync: sidl

.. code-block:: java
int get_value(in string name, in array<> dest);
.. tab-item:: Python
:sync: python

.. code-block:: python
def get_value(self, name: str, dest: NDArray[Any]) -> NDArray[Any]:
The `get_value` function takes a variable name and copies values into a
provided array parameter.
Expand Down Expand Up @@ -54,10 +66,22 @@ even if the model uses dimensional variables.
*get_value_ptr*
^^^^^^^^^^^^^^^

.. code-block:: java
.. tab-set::
:sync-group: lang

.. tab-item:: SIDL
:sync: sidl

.. code-block:: java
/* SIDL */
int get_value_ptr(in string name, out array<> dest_ptr);
int get_value_ptr(in string name, out array<> dest_ptr);
.. tab-item:: Python
:sync: python

.. code-block:: python
def get_value_ptr(self, name: str) -> NDArray[Any]:
The `get_value_ptr` function takes a variable name and returns a reference
to a variable.
Expand All @@ -81,10 +105,24 @@ even if the model's state has changed.
*get_value_at_indices*
^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: java
.. tab-set::
:sync-group: lang

.. tab-item:: SIDL
:sync: sidl

.. code-block:: java
int get_value_at_indices(in string name, in array<> dest, in array<int, 1> inds);
/* SIDL */
int get_value_at_indices(in string name, in array<> dest, in array<int, 1> inds);
.. tab-item:: Python
:sync: python

.. code-block:: python
def get_value_at_indices(
self, name: str, dest: NDArray[Any], inds: NDArray[np.int_]
) -> NDArray[Any]:
Use the `get_value_at_indices` function to get a copy of a variable's values
at the locations specified by the one-dimensional array indices
Expand All @@ -105,10 +143,22 @@ Additionally,
*set_value*
^^^^^^^^^^^

.. code-block:: java
.. tab-set::
:sync-group: lang

.. tab-item:: SIDL
:sync: sidl

.. code-block:: java
int set_value(in string name, in array<> src);
.. tab-item:: Python
:sync: python

/* SIDL */
int set_value(in string name, in array<> src);
.. code-block:: python
def set_value(self, name: str, src: NDArray[Any]) -> None:
The `set_value` function takes a variable name and an array of values,
*src*,
Expand Down Expand Up @@ -138,10 +188,24 @@ even if the model uses dimensional variables.
*set_value_at_indices*
^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: java
.. tab-set::
:sync-group: lang

.. tab-item:: SIDL
:sync: sidl

.. code-block:: java
int set_value_at_indices(in string name, in array<int, 1> inds, in array<> src);
.. tab-item:: Python
:sync: python

.. code-block:: python
/* SIDL */
int set_value_at_indices(in string name, in array<int, 1> inds, in array<> src);
def set_value_at_indices(
self, name: str, inds: NDArray[np.int_], src: NDArray[Any]
) -> None:
Use the `set_value_at_indices` function to set a variable's values
at the locations specified by the one-dimensional array indices
Expand Down
Loading

0 comments on commit 7c25129

Please sign in to comment.