Skip to content

Commit 59773e8

Browse files
init test file
Signed-off-by: Franklin Zhang <franklinzhang@foxmail.com>
1 parent 12f956a commit 59773e8

29 files changed

+2085
-3
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ Software architecture description.
1010

1111
## Installation
1212

13-
Before install it, please ensure your PC has Python 3.7 and pip already.
13+
Before install it, please ensure your PC has Python 3.7 and pip already. There are two methods to install package.
1414

1515
### 1. Download
1616
Download [pip package](standard-demo/bmi/release/BMI-OpenGMS-Engine-0.1.0.tar.gz)
1717

1818
### 2. Install pip package
1919
Open cmd window in Windows or shell in Linux or MacOS, pip.
2020

21-
Type `pip install bmi-opengms-engine`
21+
Type `pip3 install bmi-opengms-engine`
2222

2323
## Usage
2424

@@ -70,7 +70,24 @@ Type `pip install bmi-opengms-engine`
7070
* Return : Void
7171
The package will be generation in the same folder with BMI component
7272

73-
the package can be deployed in [the wrapper system of OpenGMS (GeoModelServiceContainer)]()
73+
the package can be deployed in [the wrapper system of OpenGMS (GeoModelServiceContainer)](https://github.com/franklinzhanggis/wrappersystem)
74+
75+
### Demo
76+
77+
#### Demo 1 - HeatMap
78+
79+
``` python
80+
81+
def test_for_bmi_opengms_engine():
82+
dirname = os.path.dirname(__file__)
83+
BMIOpenGMSEngine.convertBMI2OpenGMS(dirname + "/heat", "BmiHeat", dirname + "/data/bmi_heat_map_supplement.json")
84+
85+
```
86+
87+
88+
89+
90+
HeatMap is the CSDMS BMI offical demo
7491

7592
## Contributors
7693
### Founders/Designers

test/bmi/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""The Basic Model Interface."""
2+
from .bmi import Bmi
3+
4+
5+
__all__ = ['Bmi']

test/bmi/base.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#! /usr/bin/env python
2+
"""Interface to the basic control functions of a model."""
3+
4+
5+
class BmiBase(object):
6+
7+
"""Functions that control model execution.
8+
9+
These BMI functions are critical to plug-and-play modeling because they
10+
give a calling component fine-grained control over the model execution.
11+
"""
12+
13+
def initialize(self, filename):
14+
"""Perform startup tasks for the model.
15+
16+
Perform all tasks that take place before entering the model's time
17+
loop, including opening files and initializing the model state. Model
18+
inputs are read from a text-based configuration file, specified by
19+
`filename`.
20+
21+
Parameters
22+
----------
23+
filename : str, optional
24+
The path to the model configuration file.
25+
26+
Notes
27+
-----
28+
Models should be refactored, if necessary, to use a
29+
configuration file. CSDMS does not impose any constraint on
30+
how configuration files are formatted, although YAML is
31+
recommended. A template of a model's configuration file
32+
with placeholder values is used by the BMI.
33+
34+
.. code-block:: c
35+
36+
/* C */
37+
int initialize(void *self, char * filename);
38+
"""
39+
pass
40+
41+
def update(self):
42+
"""Advance model state by one time step.
43+
44+
Perform all tasks that take place within one pass through the model's
45+
time loop. This typically includes incrementing all of the model's
46+
state variables. If the model's state variables don't change in time,
47+
then they can be computed by the :func:`initialize` method and this
48+
method can return with no action.
49+
50+
Notes
51+
-----
52+
.. code-block:: c
53+
54+
/* C */
55+
int update(void *self);
56+
"""
57+
pass
58+
59+
def update_until(self, time):
60+
"""Advance model state until the given time.
61+
62+
Parameters
63+
----------
64+
time : float
65+
A model time value.
66+
67+
See Also
68+
--------
69+
update
70+
71+
Notes
72+
-----
73+
.. code-block:: c
74+
75+
/* C */
76+
int update_until(void *self, double time);
77+
"""
78+
pass
79+
80+
def update_frac(self, time_frac):
81+
"""Advance model state by a fraction of a time step.
82+
83+
Parameters
84+
----------
85+
time_frac : float
86+
A fraction of a model time step value.
87+
88+
See Also
89+
--------
90+
update
91+
92+
Notes
93+
-----
94+
.. code-block:: c
95+
96+
/* C */
97+
int update_frac(void *self, double time_frac);
98+
"""
99+
pass
100+
101+
def finalize(self):
102+
"""Perform tear-down tasks for the model.
103+
104+
Perform all tasks that take place after exiting the model's time
105+
loop. This typically includes deallocating memory, closing files and
106+
printing reports.
107+
108+
Notes
109+
-----
110+
.. code-block:: c
111+
112+
/* C */
113+
int finalize(void *self);
114+
"""
115+
pass

test/bmi/bmi.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#! /usr/bin/env python
2+
"""The complete Basic Model Interface."""
3+
4+
5+
from .base import BmiBase
6+
from .info import BmiInfo
7+
from .time import BmiTime
8+
from .vars import BmiVars
9+
from .getter_setter import BmiGetter, BmiSetter
10+
from .grid_rectilinear import BmiGridRectilinear
11+
from .grid_uniform_rectilinear import BmiGridUniformRectilinear
12+
from .grid_structured_quad import BmiGridStructuredQuad
13+
from .grid_unstructured import BmiGridUnstructured
14+
15+
16+
class Bmi(BmiBase, BmiInfo, BmiTime, BmiVars, BmiGetter, BmiSetter,
17+
BmiGridRectilinear, BmiGridUniformRectilinear, BmiGridStructuredQuad,
18+
BmiGridUnstructured):
19+
20+
"""The complete Basic Model Interface.
21+
22+
Defines an interface for converting a standalone model into an
23+
integrated modeling framework component.
24+
"""
25+
26+
pass

test/bmi/getter_setter.py

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#! /usr/bin/env python
2+
"""Interface for getting and setting a model's internal variables."""
3+
4+
5+
class BmiGetter(object):
6+
7+
"""Get values from a component.
8+
9+
Methods that get variables from a model's state. Often a model's state
10+
variables are changing with each time step, so getters are called to get
11+
current values.
12+
"""
13+
14+
def get_value(self, var_name):
15+
"""Get a copy of values of the given variable.
16+
17+
This is a getter for the model, used to access the model's
18+
current state. It returns a *copy* of a model variable, with
19+
the return type, size and rank dependent on the variable.
20+
21+
Parameters
22+
----------
23+
var_name : str
24+
An input or output variable name, a CSDMS Standard Name.
25+
26+
Returns
27+
-------
28+
array_like
29+
The value of a model variable.
30+
31+
Notes
32+
-----
33+
.. code-block:: c
34+
35+
/* C */
36+
int get_value(void * self, const char * var_name, void * buffer);
37+
"""
38+
pass
39+
40+
def get_value_ref(self, var_name):
41+
"""Get a reference to values of the given variable.
42+
43+
This is a getter for the model, used to access the model's
44+
current state. It returns a reference to a model variable,
45+
with the return type, size and rank dependent on the variable.
46+
47+
Parameters
48+
----------
49+
var_name : str
50+
An input or output variable name, a CSDMS Standard Name.
51+
52+
Returns
53+
-------
54+
array_like
55+
A reference to a model variable.
56+
57+
Notes
58+
-----
59+
.. code-block:: c
60+
61+
/* C */
62+
int get_value_ref(void * self, const char * var_name,
63+
void ** buffer);
64+
"""
65+
pass
66+
67+
def get_value_at_indices(self, var_name, indices):
68+
"""Get values at particular indices.
69+
70+
Parameters
71+
----------
72+
var_name : str
73+
An input or output variable name, a CSDMS Standard Name.
74+
indices : array_like
75+
The indices into the variable array.
76+
77+
Returns
78+
-------
79+
array_like
80+
Value of the model variable at the given location.
81+
82+
Notes
83+
-----
84+
.. code-block:: c
85+
86+
/* C */
87+
int get_value_at_indices(void * self, const char * var_name,
88+
void * buffer, int * indices, int len);
89+
"""
90+
pass
91+
92+
93+
class BmiSetter(object):
94+
95+
"""Set values into a component.
96+
97+
Methods that set variables of a model's state.
98+
"""
99+
100+
def set_value(self, var_name, src):
101+
"""Specify a new value for a model variable.
102+
103+
This is the setter for the model, used to change the model's
104+
current state. It accepts, through *src*, a new value for a
105+
model variable, with the type, size and rank of *src*
106+
dependent on the variable.
107+
108+
Parameters
109+
----------
110+
var_name : str
111+
An input or output variable name, a CSDMS Standard Name.
112+
src : array_like
113+
The new value for the specified variable.
114+
115+
Notes
116+
-----
117+
.. code-block:: c
118+
119+
/* C */
120+
int set_value(void * self, const char * var_name, void * src);
121+
"""
122+
pass
123+
124+
def set_value_at_indices(self, var_name, indices, src):
125+
"""Specify a new value for a model variable at particular indices.
126+
127+
Parameters
128+
----------
129+
var_name : str
130+
An input or output variable name, a CSDMS Standard Name.
131+
indices : array_like
132+
The indices into the variable array.
133+
src : array_like
134+
The new value for the specified variable.
135+
136+
Notes
137+
-----
138+
.. code-block:: c
139+
140+
/* C */
141+
int set_value_at_indices(void * self, const char * var_name,
142+
int * indices, int len, void * src);
143+
"""
144+
pass

0 commit comments

Comments
 (0)