landlab.bmi.bmi_bridge¶
Wrap landlab component with the Basic Modeling Interface
The wrap_as_bmi function wraps a landlab component class so that it exposes a Basic Modeling Interface.
|
Wrap a landlab class so it exposes a BMI. |
Section author: Eric Hutton
- class TimeStepper[source]¶
Bases:
object
Step through time.
- Parameters:
Examples
>>> from landlab.bmi import TimeStepper >>> time_stepper = TimeStepper() >>> time_stepper.start 0.0 >>> time_stepper.stop is None True >>> time_stepper.step 1.0 >>> time_stepper.time 0.0 >>> for _ in range(10): ... time_stepper.advance() ... >>> time_stepper.time 10.0 >>> time_stepper = TimeStepper(1.0, 13.0, 2.0) >>> [time for time in time_stepper] [1.0, 3.0, 5.0, 7.0, 9.0, 11.0]
- __new__(**kwargs)¶
- property start¶
Start time.
- property step¶
Time Step.
- property stop¶
Stop time.
- property time¶
Current time.
- property units¶
Time units.
- wrap_as_bmi(cls)[source]¶
Wrap a landlab class so it exposes a BMI.
Give a landlab component a Basic Model Interface (BMI). Since landlab components have an interface that is already in the style of BMI, this function adds just a light wrapping to landlab components. There are a number of differences that may cause some confusion to landlab users.
Because BMI doesn’t have a concept of a dual grid, it only defines nodes (points), edges (vectors), and faces (areas). The dual-graph of landlab is considered as two separate grids by BMI.
It is important to note that BMI has only three grid elements (node, edge, and face) while landlab has 6. The names used by landlab and BMI are also different.
Thus, a BMI-wrapped landlab component will always have two grids with grid identifiers 0, and 1. Grid 0 will contain the landlab nodes, links, and patches while grid 1 will contain corners, faces, and cells.landlab and BMI refer to grid elements by different names. The mapping from landlab to BMI nomenclature is the following:
Grid 0 (Primal)
Grid 1 (Dual)
Landlab
BMI
Landlab
BMI
node
node
corner
node
link
edge
face
edge
patch
face
cell
face
In BMI, the initialize method requires an input file that is used to create and setup the model for time-stepping. landlab components generally do not have anything like this; instead this task is usually done programmatically. Thus, the input file that is used by the BMI initialize method is a standard landlab input file as used by the landlab
create_grid
function.
- Parameters:
cls (class) – A landlab class that inherits from
Component
.- Returns:
A wrapped class that exposes a BMI.
- Return type:
class
Examples
>>> from landlab.bmi import wrap_as_bmi >>> from landlab.components.flexure import Flexure
>>> BmiFlexure = wrap_as_bmi(Flexure) >>> flexure = BmiFlexure() >>> sorted(flexure.get_input_var_names()) ['boundary_condition_flag', 'lithosphere__overlying_pressure_increment'] >>> flexure.get_var_units("lithosphere__overlying_pressure_increment") 'Pa'
>>> config = ''' ... flexure: ... eet: 10.e+3 ... method: flexure ... clock: ... start: 0. ... stop: 10. ... step: 2. ... grid: ... RasterModelGrid: ... - [20, 40] ... - xy_spacing: [2000., 1000.] ... - fields: ... node: ... lithosphere__overlying_pressure_increment: ... constant: ... - value: 0.0 ... ''' >>> flexure.initialize(config) >>> sorted(flexure.get_output_var_names()) ['boundary_condition_flag', 'lithosphere_surface__elevation_increment'] >>> flexure.get_var_grid("lithosphere_surface__elevation_increment") 0 >>> flexure.get_grid_shape(0, np.empty(flexure.get_grid_rank(0), dtype=int)) array([20, 40]) >>> dz = np.empty(flexure.get_grid_size(0)) >>> _ = flexure.get_value("lithosphere_surface__elevation_increment", dz)
>>> np.all(dz == 0.0) True >>> flexure.get_current_time() 0.0
>>> sorted(flexure.get_input_var_names()) ['boundary_condition_flag', 'lithosphere__overlying_pressure_increment'] >>> load = np.zeros((20, 40), dtype=float) >>> load[0, 0] = 1.0 >>> flexure.set_value("lithosphere__overlying_pressure_increment", load) >>> flexure.update() >>> flexure.get_current_time() 2.0 >>> _ = flexure.get_value("lithosphere_surface__elevation_increment", dz) >>> np.all(dz == 0.0) False