Skip to content

Commit

Permalink
Merge 63c0720 into af8efff
Browse files Browse the repository at this point in the history
  • Loading branch information
mdpiper committed Nov 22, 2019
2 parents af8efff + 63c0720 commit 1fa1c48
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
52 changes: 51 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,54 @@
bmi-example-python
==================

An example BMI implementation written in Python
An example of implementing the `Python bindings`_
for the CSDMS `Basic Model Interface`_ (BMI).

Overview
--------

This is an example of implementing a BMI for a simple model
that solves the diffusion equation
on a uniform rectangular plate
with Dirichlet boundary conditions.
The model and its BMI are written in Python 3.
Tests of the BMI are provided.

This repository is organized with the following directories:

*heat*
Holds the model and the BMI for the model

*tests*
Tests that cover the BMI of the model

Build/Install
-------------

This example can be built and installed on Linux, macOS, and Windows.

**Prerequisites:**

* Python 3
* The Python BMI bindings. Follow the build and install directions
given in the `README`_ in that repository. You can choose to install
them from source, or through pip, or conda.

To build/install this example from source,
using the current Python BMI version, run

.. code-block:: bash
$ make install
To run the tests,

.. code-block:: bash
$ pip install -r requirements.txt
$ make test
.. _Python bindings: https://github.com/csdms/bmi-python
.. _Basic Model Interface: https://bmi-spec.readthedocs.io
.. _README: https://github.com/csdms/bmi-python/blob/master/README.rst
11 changes: 11 additions & 0 deletions heat/bmi_heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ def get_component_name(self):
"""Name of the component."""
return self._name

def get_input_item_count(self):
"""Get names of input variables."""
return len(self._input_var_names)

def get_output_item_count(self):
"""Get names of output variables."""
return len(self._output_var_names)

def get_input_var_names(self):
"""Get names of input variables."""
return self._input_var_names
Expand Down Expand Up @@ -323,6 +331,9 @@ def get_grid_node_count(self, grid):
def get_grid_nodes_per_face(self, grid, nodes_per_face):
raise NotImplementedError("get_grid_nodes_per_face")

def get_grid_face_edges(self, grid, face_edges):
raise NotImplementedError("get_grid_face_edges")

def get_grid_x(self, grid, x):
raise NotImplementedError("get_grid_x")

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering :: Physics",
],
Expand Down
11 changes: 11 additions & 0 deletions tests/test_grid_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ def test_grid_var_names():
assert names == ("plate_surface__temperature",)


def test_grid_var_item_count():
model = BmiHeat()
model.initialize()

count = model.get_input_item_count()
assert count == 1

count = model.get_output_item_count()
assert count == 1


def test_grid_var_units():
model = BmiHeat()
model.initialize()
Expand Down

0 comments on commit 1fa1c48

Please sign in to comment.