Parameters

Projects and components keep their parameters in a Parameter_container. Every parameter is read and changed through its value:

space = pro.component("space_1")
space.parameter("volume").value = 129.6

Parameter_container

Parameter_container(sim)

Class to manage a list of Parameters

Superclass for Projects and Components

Default parameters included:

  • name (string)
  • description (string)

Create the container with the parameters name and description

Parameters:

Name Type Description Default
sim Simulation

simulation environment, used to report messages

required

add_parameter

add_parameter(param)

Add a parameter

Parameters:

Name Type Description Default
param Parameter

parameter to add, replaces any parameter with the same key

required

del_parameter

del_parameter(param)

Delete a parameter

Parameters:

Name Type Description Default
param Parameter

parameter to delete

required

parameter

parameter(key)

Find and return a parameter using its key

Parameters:

Name Type Description Default
key str

key of the parameter, e.g. "name"

required

Returns:

Type Description
Parameter

the parameter (KeyError if it does not exist); read or change its value with .value

parameter_dict

parameter_dict()

Parameters of the container

Returns:

Type Description
dict

{key: Parameter}

set_parameters

set_parameters(dictonary)

Set parameter values from a dictionary

Parameters:

Name Type Description Default
dictonary dict

{key: value}; unknown keys are reported as errors

required

parameter_dataframe

parameter_dataframe(string_format=False)

Parameters as a table

Parameters:

Name Type Description Default
string_format bool

Convert every value to string. Defaults to False.

False

Returns:

Type Description
DataFrame

key, type, value and unit of each parameter

check_parameters

check_parameters()

Check if all is correct

Returns:

Type Description
list of Message

errors found

Parameter types

Parameter

Parameter(key, value=0)

Bases: Child

Elements with key-value pair

Base class of all the parameters. Each subclass converts the values it receives (also from strings, as read from Excel or a form) to its type in the value setter, reporting an error message if it cannot, and validates them in check(). The _list subclasses hold a list of values; a single value is accepted and stored as a one-element list.

Create new parameter

Parameters:

Name Type Description Default
key str

key of the parameter in its container

required
value optional

initial value. Defaults to 0.

0

key property writable

key

str: key of the parameter in its container

value property writable

value

Value of the parameter, converted to its type when set

type property

type

str: class name of the parameter, e.g. "Parameter_float"

info

info()

Key and value as text

Returns:

Type Description
str

"key: value", with the unit for numeric parameters

check

check()

Check if the value is correct

Returns:

Type Description
list of Message

errors found

Parameter_boolean

Parameter_boolean(key, value=False)

Bases: Parameter

Boolean parameter (also accepts the strings "True" and "False")

Parameter_boolean_list

Parameter_boolean_list(key, value=[False])

Bases: Parameter

List of booleans

Parameter_string

Parameter_string(key, value='')

Bases: Parameter

String parameter

Parameter_string_list

Parameter_string_list(key, value=[''])

Bases: Parameter

List of strings (also accepts a string "[a, b, c]")

Parameter_int

Parameter_int(key, value=0, unit='', min=0, max=sys.maxsize)

Bases: Parameter

Integer parameter with unit and allowed range

Parameters:

Name Type Description Default
key str

key of the parameter

required
value int

initial value. Defaults to 0.

0
unit str

unit. Defaults to "".

''
min int

minimum value, checked by check(). Defaults to 0.

0
max int

maximum value, checked by check(). Defaults to sys.maxsize.

maxsize

Parameter_int_list

Parameter_int_list(key, value=[0], unit='', min=0, max=sys.maxsize)

Bases: Parameter

List of integers with unit and allowed range (same arguments as Parameter_int)

Parameter_float

Parameter_float(key, value=0.0, unit='', min=float('-inf'), max=float('inf'))

Bases: Parameter_int

Float parameter with unit and allowed range

Parameters:

Name Type Description Default
key str

key of the parameter

required
value float

initial value. Defaults to 0.0.

0.0
unit str

unit, e.g. "W/m²". Defaults to "".

''
min float

minimum value, checked by check(). Defaults to -inf.

float('-inf')
max float

maximum value, checked by check(). Defaults to inf.

float('inf')

Parameter_float_list

Parameter_float_list(key, value=[0.0], unit='', min=float('-inf'), max=float('inf'))

Bases: Parameter_int_list

List of floats with unit and allowed range (same arguments as Parameter_float)

Parameter_options

Parameter_options(key, value='', options=[])

Bases: Parameter

String parameter that must be one of a list of options

Parameters:

Name Type Description Default
key str

key of the parameter

required
value str

initial value. Defaults to "".

''
options list of str

allowed values, checked by check(). Defaults to [].

[]

Parameter_options_list

Parameter_options_list(key, value=[''], options=[])

Bases: Parameter

List of strings, each one of a list of options

Parameter_component

Parameter_component(key, value='not_defined', allowed_types=[])

Bases: Parameter

Reference to another component, by its name

The value is the name of the component in the same project, or "project_name->component_name" for a component of another project of the simulation. "not_defined" means no reference.

Parameters:

Name Type Description Default
key str

key of the parameter

required
value str

name of the component. Defaults to "not_defined".

'not_defined'
allowed_types list of str

component types allowed, checked by check(); empty allows any. Defaults to [].

[]

component property

component

Component: referenced component, None if not found

Parameter_component_list

Parameter_component_list(key, value=['not_defined'], allowed_types=[])

Bases: Parameter

List of references to components (same format as Parameter_component)

component property

component

list of Component: referenced components, None for those not found

Parameter_variable

Parameter_variable(key, value='not_defined = component.variable')

Bases: Parameter

Variable of another component, with the symbol used for it in expressions

The value has the format "symbol = component.variable" (or "symbol = project->component.variable"). The component that holds the parameter gets a variable named symbol with a copy of the values, and the symbol can be used in its Parameter_math_exp expressions.

variable property

variable

Variable: referenced variable, None if not found

Parameter_variable_list

Parameter_variable_list(key, value=['not_defined = component.variable'])

Bases: Parameter

List of variables of other components (same format as Parameter_variable)

variable property

variable

list of Variable: referenced variables, None for those not found

Parameter_math_exp

Parameter_math_exp(key, value='0.0', unit='')

Bases: Parameter

Mathematical expression, evaluated during the simulation

Python expression (the math module is available) in which the symbols of the component's Parameter_variable parameters can be used, e.g. "0.5 * t_ext + 10".

Parameters:

Name Type Description Default
key str

key of the parameter

required
value str

expression. Defaults to "0.0".

'0.0'
unit str

unit of the result. Defaults to "".

''

evaluate

evaluate(values_dic)

Evaluate the expression

Parameters:

Name Type Description Default
values_dic dict

{symbol: value} of the symbols used in the expression

required

Returns:

Type Description
float

result, 0 (and an error message) if the expression cannot be evaluated

Parameter_math_exp_list

Parameter_math_exp_list(key, value=['0.0'], unit='')

Bases: Parameter

List of mathematical expressions (same format as Parameter_math_exp)

evaluate

evaluate(i, values_dic)

Evaluate one of the expressions

Parameters:

Name Type Description Default
i int

index of the expression in the list

required
values_dic dict

{symbol: value} of the symbols used in the expression

required

Returns:

Type Description
float

result, 0 (and an error message) if the expression cannot be evaluated