grpc4bmi.bmi_optionaldest module
- class grpc4bmi.bmi_optionaldest.OptionalDestBmi(origin: Bmi)[source]
Bases:
Bmi
Proxy around Bmi object that makes the output argument (dest) optional.
Some Bmi methods accept a numpy array as argument (dest) that must be filled by the model. This class makes that argument optional.
For example to get the value of a heat model:
from heat import BmiHeat import numpy as np orig_model = BmiHeat() orig_model.initialize() dest = np.empty((200,), dtype=np.float64) dest2 = orig_model.get_value('plate_surface__temperature', dest)
A dest variable must created and passed to the get_value method. It must be set to a Numpy array with the shape and type the model requires. The returned numpy array (dest2) is the same as the dest numpy array. By using this class we no longer need do create and pass it.
from grpc4bmi.bmi_optionaldest import OptionalDestBmi model = OptionalDestBmi(orig_model) dest3 = model.get_value('plate_surface__temperature')
This class will create dest variables by calling other Bmi methods for its shape. When using a slow model it is strongly suggested to wrap the BmiClient with
grpc4bmi.bmi_memoized.MemoizedBmi
first to prevent a lot of calls.The dest in bmipy.Bmi.get_value_at_indices(self, name, dest, inds) method can not be made optional so it has been changed to
OptionalDestBmi.get_value_at_indices(self, name, inds)
.- finalize() None [source]
Perform tear-down tasks for the model.
Perform all tasks that take place after exiting the model’s time loop. This typically includes deallocating memory, closing files and printing reports.
- get_component_name() str [source]
Name of the component.
- Returns:
The name of the component.
- Return type:
- get_current_time() float [source]
Return the current time of the model.
- Returns:
The current model time.
- Return type:
- get_grid_edge_nodes(grid: int, edge_nodes: ndarray | None = None) ndarray [source]
Get the edge-node connectivity.
- Parameters:
grid (int) – A grid identifier.
edge_nodes (ndarray of int, shape (2 x nnodes,)) – A numpy array to place the edge-node connectivity. For each edge, connectivity is given as node at edge tail, followed by node at edge head.
- Returns:
The input numpy array that holds the edge-node connectivity.
- Return type:
ndarray of int
- get_grid_face_edges(grid: int, face_edges: ndarray | None = None) ndarray [source]
Get the face-edge connectivity.
- get_grid_face_nodes(grid: int, face_nodes: ndarray | None = None) ndarray [source]
Get the face-node connectivity.
- Parameters:
- Returns:
The input numpy array that holds the face-node connectivity.
- Return type:
ndarray of int
- get_grid_nodes_per_face(grid: int, nodes_per_face: ndarray | None = None) ndarray [source]
Get the number of nodes for each face.
- get_grid_origin(grid: int, origin: ndarray | None = None) ndarray [source]
Get coordinates for the lower-left corner of the computational grid.
- get_grid_shape(grid: int, shape: ndarray | None = None) ndarray [source]
Get dimensions of the computational grid.
- get_grid_spacing(grid: int, spacing: ndarray | None = None) ndarray [source]
Get distance between nodes of the computational grid.
- get_grid_x(grid: int, x: ndarray | None = None) ndarray [source]
Get coordinates of grid nodes in the x direction.
- get_grid_y(grid: int, y: ndarray | None = None) ndarray [source]
Get coordinates of grid nodes in the y direction.
- get_grid_z(grid: int, z: ndarray | None = None) ndarray [source]
Get coordinates of grid nodes in the z direction.
- get_input_item_count() int [source]
Count of a model’s input variables.
- Returns:
The number of input variables.
- Return type:
- get_input_var_names() Tuple[str] [source]
List of a model’s input variables.
Input variable names must be CSDMS Standard Names, also known as long variable names.
Notes
Standard Names enable the CSDMS framework to determine whether an input variable in one model is equivalent to, or compatible with, an output variable in another model. This allows the framework to automatically connect components.
Standard Names do not have to be used within the model.
- get_output_item_count() int [source]
Count of a model’s output variables.
- Returns:
The number of output variables.
- Return type:
- get_output_var_names() Tuple[str] [source]
List of a model’s output variables.
Output variable names must be CSDMS Standard Names, also known as long variable names.
- get_start_time() float [source]
Start time of the model.
Model times should be of type float.
- Returns:
The model start time.
- Return type:
- get_time_step() float [source]
Return the current time step of the model.
The model time step should be of type float.
- Returns:
The time step used in model.
- Return type:
- get_time_units() str [source]
Time units of the model.
- Returns:
The model time unit; e.g., days or s.
- Return type:
Notes
CSDMS uses the UDUNITS standard from Unidata.
- get_value(name, dest: ndarray | None = None) ndarray [source]
Get a copy of values of the given variable.
This is a getter for the model, used to access the model’s current state. It returns a copy of a model variable, with the return type, size and rank dependent on the variable.
- Parameters:
name (str) – An input or output variable name, a CSDMS Standard Name.
dest (ndarray) – A numpy array into which to place the values.
- Returns:
The same numpy array that was passed as an input buffer.
- Return type:
ndarray
- get_value_at_indices(name: str, inds: ndarray) ndarray [source]
Get values at particular indices.
- Parameters:
name (str) – An input or output variable name, a CSDMS Standard Name.
inds (array_like) – The indices into the variable array.
- Returns:
Value of the model variable at the given location.
- Return type:
array_like
- get_value_ptr(name: str) ndarray [source]
Get a reference to values of the given variable.
This is a getter for the model, used to access the model’s current state. It returns a reference to a model variable, with the return type, size and rank dependent on the variable.
- Parameters:
name (str) – An input or output variable name, a CSDMS Standard Name.
- Returns:
A reference to a model variable.
- Return type:
array_like
- get_var_location(name: str) str [source]
Get the grid element type that the a given variable is defined on.
The grid topology can be composed of nodes, edges, and faces.
- node
A point that has a coordinate pair or triplet: the most basic element of the topology.
- edge
A line or curve bounded by two nodes.
- face
A plane or surface enclosed by a set of edges. In a 2D horizontal application one may consider the word “polygon”, but in the hierarchy of elements the word “face” is most common.
- Parameters:
name (str) – An input or output variable name, a CSDMS Standard Name.
- Returns:
The grid location on which the variable is defined. Must be one of “node”, “edge”, or “face”.
- Return type:
Notes
CSDMS uses the ugrid conventions to define unstructured grids.
- get_var_units(name: str) str [source]
Get units of the given variable.
Standard unit names, in lower case, should be used, such as
meters
orseconds
. Standard abbreviations, likem
for meters, are also supported. For variables with compound units, each unit name is separated by a single space, with exponents other than 1 placed immediately after the name, as inm s-1
for velocity,W m-2
for an energy flux, orkm2
for an area.- Parameters:
name (str) – An input or output variable name, a CSDMS Standard Name.
- Returns:
The variable units.
- Return type:
Notes
CSDMS uses the UDUNITS standard from Unidata.
- initialize(config_file: str | None) None [source]
Perform startup tasks for the model.
Perform all tasks that take place before entering the model’s time loop, including opening files and initializing the model state. Model inputs are read from a text-based configuration file, specified by config_file.
- Parameters:
config_file (str, optional) – The path to the model configuration file.
Notes
Models should be refactored, if necessary, to use a configuration file. CSDMS does not impose any constraint on how configuration files are formatted, although YAML is recommended. A template of a model’s configuration file with placeholder values is used by the BMI.
- set_value(name: str, values: ndarray) None [source]
Specify a new value for a model variable.
This is the setter for the model, used to change the model’s current state. It accepts, through src, a new value for a model variable, with the type, size and rank of src dependent on the variable.
- Parameters:
name (str) – An input or output variable name, a CSDMS Standard Name.
src (array_like) – The new value for the specified variable.
- set_value_at_indices(name: str, inds: ndarray, src: ndarray) None [source]
Specify a new value for a model variable at particular indices.
- Parameters:
name (str) – An input or output variable name, a CSDMS Standard Name.
inds (array_like) – The indices into the variable array.
src (array_like) – The new value for the specified variable.
- update() None [source]
Advance model state by one time step.
Perform all tasks that take place within one pass through the model’s time loop. This typically includes incrementing all of the model’s state variables. If the model’s state variables don’t change in time, then they can be computed by the
initialize()
method and this method can return with no action.