Nektar++
|
Public Member Functions | |
def | __init__ |
def | add_input |
def | add_output |
def | add_output_function |
def | make_var_constant |
def | make_var_computed_constant |
def | finalize |
def | get_interface_component |
Public Member Functions inherited from CellMLToNektar.processors.ModelModifier | |
def | __init__ |
def | finalize |
def | create_new_component |
def | connect_variables |
def | remove_connection |
def | remove_connections |
def | add_variable |
def | add_units |
def | add_expr_to_comp |
def | remove_expr |
def | remove_definition |
def | del_attr |
def | set_units_converter |
def | get_units_converter |
Private Member Functions | |
def | _transform_derivatives_on_rhs |
def | _transform_derivative_on_rhs |
def | _split_ode |
def | _add_all_odes_to_interface |
Private Attributes | |
_interface_component | |
_interface_component_name | |
Additional Inherited Members | |
Public Attributes inherited from CellMLToNektar.processors.ModelModifier | |
model | |
connections_made | |
Class for generating an interface between a CellML model and external code. This contains functionality for users to describe the interface desired by the external code, i.e. which variables are inputs and/or outputs, and expected units. It will then create a new component within the CellML model containing these variables, and add units conversions where required. The external code then only needs to interact with this new component.
Definition at line 533 of file processors.py.
def CellMLToNektar.processors.InterfaceGenerator.__init__ | ( | self, | |
model, | |||
name = 'interface' , |
|||
units_converter = None |
|||
) |
Definition at line 541 of file processors.py.
|
private |
All the derivatives should be considered as model outputs, and state variables as model inputs. For any that haven't been done explicitly, this method will add the corresponding state variable as an input, with its original units, which has the desired effect.
Definition at line 725 of file processors.py.
References CellMLToNektar.processors.InterfaceGenerator.add_input(), and CellMLToNektar.processors.InterfaceGenerator.get_interface_component().
Referenced by CellMLToNektar.processors.InterfaceGenerator.finalize().
|
private |
Split an ODE definition so the derivative goes into the interface component. The RHS stays where it is, and is assigned to a new variable, which is connected to the interface component and assigned to the new derivative. newVar is the new state variable in the interface component, and oldVar will soon be mapped to it by the caller. Any other equations in the model which use the derivative are transformed to use the new variable instead.
Definition at line 692 of file processors.py.
References CellMLToNektar.processors.ModelModifier._uniquify_var_name(), CellMLToNektar.processors.ModelModifier.add_expr_to_comp(), CellMLToNektar.processors.InterfaceGenerator.add_input(), CellMLToNektar.processors.InterfaceGenerator.add_output(), CellMLToNektar.processors.ModelModifier.add_variable(), CellMLToNektar.pycml.extract(), CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.pycml.quotient(), and CellMLToNektar.processors.ModelModifier.remove_expr().
Referenced by CellMLToNektar.processors.InterfaceGenerator.add_input().
|
private |
Transform a derivative on the RHS of an equation to refer to the defining variable. Helper method used by self._transform_derivatives_on_rhs to do the actual transformation.
Definition at line 675 of file processors.py.
References CellMLToNektar.processors.ModelModifier.connect_variables().
Referenced by CellMLToNektar.processors.InterfaceGenerator._transform_derivatives_on_rhs().
|
private |
Transform any equations with derivatives on the RHS to use the variable defining it instead. self._split_ode must have been used for all derivatives before calling this method. This means that each ODE now has a variable to which the RHS is assigned. Rather than using the derivative directly, which could break the dependency chain if units conversions are used for time, equations should refer to this new variable instead.
Definition at line 664 of file processors.py.
References CellMLToNektar.processors.ModelModifier._process_operator(), and CellMLToNektar.processors.InterfaceGenerator._transform_derivative_on_rhs().
Referenced by CellMLToNektar.processors.InterfaceGenerator.finalize().
def CellMLToNektar.processors.InterfaceGenerator.add_input | ( | self, | |
var, | |||
units, | |||
annotate = True , |
|||
convert_initial_value = True |
|||
) |
Specify a variable as an input to the model. var should be a cellml_variable object already existing in the model. units should be a suitable input to self._get_units_object. If adding both State and Free variables as inputs, make sure to add the Free variable first, otherwise you will not be able to specify units for it. Set annotate to False if you do not wish a Constant variable to be annotated as a modifiable parameter. If a units converter has been supplied, we will also try to units-convert initial values. This may not be possible if special conversions are used, since they may involve variables whose values are not known at this time. If this is the case, set convert_initial_value to False to avoid applying the conversion. A proper solution requires CellML 1.1 features. The new variable added to the interface component is returned.
Definition at line 547 of file processors.py.
References CellMLToNektar.processors.ModelModifier._convert_initial_value(), CellMLToNektar.processors.ModelModifier._get_units_object(), CellMLToNektar.processors.InterfaceGenerator._split_ode(), CellMLToNektar.processors.ModelModifier._update_connections(), CellMLToNektar.processors.ModelModifier.add_variable(), CellMLToNektar.processors.ModelModifier.del_attr(), and CellMLToNektar.processors.InterfaceGenerator.get_interface_component().
Referenced by CellMLToNektar.processors.InterfaceGenerator._add_all_odes_to_interface(), and CellMLToNektar.processors.InterfaceGenerator._split_ode().
def CellMLToNektar.processors.InterfaceGenerator.add_output | ( | self, | |
var, | |||
units, | |||
annotate = True |
|||
) |
Specify a variable as an output of the model. var should be a cellml_variable object already existing in the model. units should be a suitable input to self._get_units_object. The new variable will take the cmeta:id of the original, and hence existing metadata annotations will refer to the new variable. If annotate is set to True, the new variable will also be annotated as a derived quantity. The new variable added to the interface component is returned.
Definition at line 595 of file processors.py.
References CellMLToNektar.processors.ModelModifier._get_units_object(), CellMLToNektar.processors.ModelModifier.add_variable(), CellMLToNektar.processors.ModelModifier.connect_variables(), CellMLToNektar.processors.ModelModifier.del_attr(), and CellMLToNektar.processors.InterfaceGenerator.get_interface_component().
Referenced by CellMLToNektar.processors.InterfaceGenerator._split_ode(), and CellMLToNektar.processors.InterfaceGenerator.add_output_function().
def CellMLToNektar.processors.InterfaceGenerator.add_output_function | ( | self, | |
resultName, | |||
operator, | |||
argVars, | |||
units | |||
) |
Add an output that's defined as a (MathML) function of existing model variables. The desired units are those of the function's result. The function arguments will be imported with their units as given by the model, and the function calculated. This result will then be units-converted if necessary. The new variable added to the interface component is returned.
Definition at line 618 of file processors.py.
References CellMLToNektar.processors.ModelModifier._get_units_object(), CellMLToNektar.processors.ModelModifier.add_expr_to_comp(), CellMLToNektar.processors.InterfaceGenerator.add_output(), CellMLToNektar.processors.ModelModifier.add_variable(), CellMLToNektar.processors.InterfaceGenerator.get_interface_component(), and CellMLToNektar.processors.ModelModifier.model.
def CellMLToNektar.processors.InterfaceGenerator.finalize | ( | self, | |
args, | |||
kwargs | |||
) |
Override finalize to also set up standard interface elements not defined individually.
Definition at line 658 of file processors.py.
References CellMLToNektar.processors.InterfaceGenerator._add_all_odes_to_interface(), and CellMLToNektar.processors.InterfaceGenerator._transform_derivatives_on_rhs().
def CellMLToNektar.processors.InterfaceGenerator.get_interface_component | ( | self | ) |
Get the new component that will contain the interface. The name will be self._interface_component_name, unless a component with that name already exists, in which case underscores will be added to the component name to make it unique.
Definition at line 736 of file processors.py.
References CellMLToNektar.processors.InterfaceGenerator._interface_component, CellMLToNektar.processors.InterfaceGenerator._interface_component_name, and CellMLToNektar.processors.ModelModifier.create_new_component().
Referenced by CellMLToNektar.processors.InterfaceGenerator._add_all_odes_to_interface(), CellMLToNektar.processors.InterfaceGenerator.add_input(), CellMLToNektar.processors.InterfaceGenerator.add_output(), and CellMLToNektar.processors.InterfaceGenerator.add_output_function().
def CellMLToNektar.processors.InterfaceGenerator.make_var_computed_constant | ( | self, | |
var, | |||
value | |||
) |
Turn a variable into a Computed variable with constant value definition.
Definition at line 649 of file processors.py.
References CellMLToNektar.processors.ModelModifier.add_expr_to_comp(), CellMLToNektar.processors.ModelModifier.model, and CellMLToNektar.processors.ModelModifier.remove_definition().
def CellMLToNektar.processors.InterfaceGenerator.make_var_constant | ( | self, | |
var, | |||
value | |||
) |
Turn a variable into a constant.
Definition at line 642 of file processors.py.
References CellMLToNektar.processors.ModelModifier.remove_definition().
|
private |
Definition at line 543 of file processors.py.
Referenced by CellMLToNektar.processors.InterfaceGenerator.get_interface_component().
|
private |
Definition at line 544 of file processors.py.
Referenced by CellMLToNektar.processors.InterfaceGenerator.get_interface_component().