bag.mdao.core

This module defines core BAG openmdao classes.

Module Contents

Classes

GroupBuilder

A class that builds new OpenMDAO groups.

class bag.mdao.core.GroupBuilder[source]

Bases: object

A class that builds new OpenMDAO groups.

This class provides a simple interface to define new variables as function of other variables, and it tracks the variable dependencies using a directed acyclic graph.

_add_node(name, ndim, **kwargs)[source]

Helper method to add a node and keep track of input variables.

_add_edge(parent, child)[source]

Helper method to add an edge and update input variables.

get_inputs()[source]

Returns a set of current input variable names.

Returns:

input_vars – a set of input variable names.

Return type:

set[str]

get_variables()[source]

Returns a list of variables.

Returns:

var_list – a list of variables.

Return type:

list[str]

get_variable_info(name)[source]

Returns the range and dimension of the given variable.

Parameters:

name (str) – variable name.

Returns:

  • min (float) – minimum value.

  • max (float) – maximum value.

  • ndim (int) – variable dimension.

add_fun(var_name, fun_list, params, param_ranges, vector_params=None)[source]

Add a new variable defined by the given list of functions.

Parameters:
  • var_name (str) – variable name.

  • fun_list (list[bag.math.interpolate.Interpolator]) – list of functions, one for each dimension.

  • params (list[str]) – list of parameter names. Parameter names may repeat, in which case the same parameter will be used for multiple arguments of the function.

  • param_ranges (dict[str, (float, float)]) – a dictionary of parameter valid range.

  • vector_params (set[str]) – set of parameters that are vector instead of scalar. If a parameter is a vector, it will be the same size as the output, and each function only takes in the corresponding element of the parameter.

add_var(variable, vmin, vmax, ndim=1)[source]

Adds a new independent variable.

Parameters:
  • variable (str) – the variable to add

  • vmin (float) – the minimum allowable value.

  • vmax (float) – the maximum allowable value.

  • ndim (int) – the dimension of the variable. Defaults to 1.

set_input_limit(var, equals=None, lower=None, upper=None)[source]

Sets the limit on the given input variable.

Parameters:
  • var (str) – name of the variable.

  • equals (float or None) – if given, the equality value.

  • lower (float or None) – if given, the minimum.

  • upper (float or None) – if given, the maximum.

add_expr(eqn, ndim)[source]

Adds a new variable with the given expression.

Parameters:
  • eqn (str) – An equation of the form “<var> = <expr>”, where var is the output variable name, and expr is the expression. All variables in expr must be already added.

  • ndim (int) – the dimension of the output variable.

build(debug=False)[source]

Returns a OpenMDAO Group from the variable graph.

Parameters:

debug (bool) – True to print debug messages.

Returns:

  • grp (omdao.Group) – the OpenMDAO group that computes all variables.

  • input_bounds (dict[str, any]) – a dictionary from input variable name to (min, max, ndim) tuple.