Nektar++
|
Public Member Functions | |
def | __init__ |
def | __del__ |
def | try_convert |
def | add_special_conversion |
def | modify_rhs |
def | times_rhs_by |
def | divide_rhs_by |
def | convert_assignments |
def | convert_constant |
def | convert_mapping |
def | convert_connections |
def | add_conversions_for_component |
def | add_all_conversions |
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 |
Public Attributes | |
warn_only | |
show_xml_context_only | |
special_conversions | |
Public Attributes inherited from CellMLToNektar.processors.ModelModifier | |
model | |
connections_made | |
Private Member Functions | |
def | _setup_logger |
def | _cleanup_logger |
def | _apply_special_conversion_for_nested_expr |
def | _check_special_conversion |
Private Attributes | |
_converted_mappings | |
_log_handler | |
Top-level interface to the units conversion code in PyCml.
Definition at line 749 of file processors.py.
def CellMLToNektar.processors.UnitsConverter.__init__ | ( | self, | |
model, | |||
warn_only = None , |
|||
show_xml_context_only = False |
|||
) |
Definition at line 752 of file processors.py.
def CellMLToNektar.processors.UnitsConverter.__del__ | ( | self | ) |
Definition at line 762 of file processors.py.
References CellMLToNektar.processors.UnitsConverter._cleanup_logger().
|
private |
Apply a special conversion to the given (sub-)expression. This will get called by mathml_units_mixin._add_units_conversion if a special conversion is required by a nested sub-expression.
Definition at line 792 of file processors.py.
References CellMLToNektar.utilities.DEBUG(), and CellMLToNektar.processors.UnitsConverter.special_conversions.
Referenced by CellMLToNektar.processors.UnitsConverter.add_conversions_for_component().
|
private |
Check whether a special conversion applies to the given assignment. Special conversions allow us to do units conversion between dimensionally non-equivalent quantities, by utilising biological knowledge. Available special conversions are added using the add_special_conversion method.
Definition at line 808 of file processors.py.
References CellMLToNektar.utilities.DEBUG(), and CellMLToNektar.processors.UnitsConverter.special_conversions.
Referenced by CellMLToNektar.processors.UnitsConverter.convert_assignments(), and CellMLToNektar.processors.UnitsConverter.convert_constant().
|
private |
Flush logger & remove handler.
Definition at line 774 of file processors.py.
References CellMLToNektar.processors.UnitsConverter._log_handler.
Referenced by CellMLToNektar.processors.UnitsConverter.__del__().
|
private |
Definition at line 765 of file processors.py.
def CellMLToNektar.processors.UnitsConverter.add_all_conversions | ( | self | ) |
Add all units conversions required in the given model.
Definition at line 1011 of file processors.py.
References CellMLToNektar.processors.UnitsConverter.convert_assignments(), CellMLToNektar.processors.UnitsConverter.convert_mapping(), and CellMLToNektar.processors.ModelModifier.model.
def CellMLToNektar.processors.UnitsConverter.add_conversions_for_component | ( | self, | |
comp | |||
) |
Add all units conversions required by the given component. This allows us to only apply the conversions required by an interface component created by an InterfaceGenerator.
Definition at line 987 of file processors.py.
References CellMLToNektar.processors.UnitsConverter._apply_special_conversion_for_nested_expr(), CellMLToNektar.processors.UnitsConverter.convert_assignments(), CellMLToNektar.processors.UnitsConverter.convert_mapping(), CellMLToNektar.processors.ModelModifier.model, and CellMLToNektar.processors.UnitsConverter.special_conversions.
def CellMLToNektar.processors.UnitsConverter.add_special_conversion | ( | self, | |
from_units, | |||
to_units, | |||
converter | |||
) |
Add a new special conversion to the list available. Special conversions allow us to do units conversion between dimensionally non-equivalent quantities, by utilising biological knowledge. The function "converter" will be called with an assignment (top-level mathml_apply instance) that has RHS units equivalent to from_units, and LHS units equivalent to to_units. It should alter the equation in-place (i.e. the object passed to it must contain the final equation) to do an appropriate units conversion, at least so that LHS and RHS dimensions match.
Definition at line 829 of file processors.py.
References CellMLToNektar.processors.UnitsConverter.special_conversions.
def CellMLToNektar.processors.UnitsConverter.convert_assignments | ( | self, | |
exprs | |||
) |
Apply conversions to any assignments in the given iterable.
Definition at line 889 of file processors.py.
References CellMLToNektar.processors.UnitsConverter._check_special_conversion(), CellMLToNektar.processors.UnitsConverter.special_conversions, and CellMLToNektar.processors.UnitsConverter.try_convert().
Referenced by CellMLToNektar.processors.UnitsConverter.add_all_conversions(), CellMLToNektar.processors.UnitsConverter.add_conversions_for_component(), and CellMLToNektar.processors.UnitsConverter.convert_mapping().
def CellMLToNektar.processors.UnitsConverter.convert_connections | ( | self, | |
connections | |||
) |
Add units conversions for all connections in the given set. :param connections: a set of variable pairs representing connections. For each pair of variables a units conversion will be added if needed and not already performed.
Definition at line 971 of file processors.py.
References CellMLToNektar.processors.UnitsConverter.convert_mapping(), and CellMLToNektar.processors.ModelModifier.model.
def CellMLToNektar.processors.UnitsConverter.convert_constant | ( | self, | |
value, | |||
from_units, | |||
to_units, | |||
comp | |||
) |
Convert a constant value into desired units.
Definition at line 899 of file processors.py.
References CellMLToNektar.processors.UnitsConverter._check_special_conversion(), CellMLToNektar.processors.ModelModifier.add_expr_to_comp(), CellMLToNektar.processors.ModelModifier.add_units(), CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.processors.ModelModifier.remove_expr(), CellMLToNektar.processors.UnitsConverter.special_conversions, and CellMLToNektar.processors.UnitsConverter.try_convert().
def CellMLToNektar.processors.UnitsConverter.convert_mapping | ( | self, | |
mapping, | |||
comp1, | |||
comp2, | |||
var1, | |||
var2 | |||
) |
Apply conversions to a mapping between two variables.
Definition at line 914 of file processors.py.
References CellMLToNektar.processors.UnitsConverter._converted_mappings, CellMLToNektar.processors.ModelModifier.add_expr_to_comp(), CellMLToNektar.processors.ModelModifier.add_variable(), CellMLToNektar.processors.UnitsConverter.convert_assignments(), CellMLToNektar.utilities.DEBUG(), and CellMLToNektar.processors.ModelModifier.model.
Referenced by CellMLToNektar.processors.UnitsConverter.add_all_conversions(), CellMLToNektar.processors.UnitsConverter.add_conversions_for_component(), and CellMLToNektar.processors.UnitsConverter.convert_connections().
def CellMLToNektar.processors.UnitsConverter.divide_rhs_by | ( | self, | |
expr, | |||
var | |||
) |
Helper method of use to special units conversions. Will modify the given expr in-place, post-dividing the RHS by a reference to the given variable object. Connections and variables will be added to ensure that the given variable is available in the component in which expr appears. Returns expr, for ease of chaining expressions.
Definition at line 877 of file processors.py.
References CellMLToNektar.processors.UnitsConverter.modify_rhs().
def CellMLToNektar.processors.UnitsConverter.modify_rhs | ( | self, | |
expr, | |||
operator, | |||
var | |||
) |
Helper method of use to special units conversions. Will modify the given expr in-place, replacing the RHS by an application of the given operator. The operands will be the existing RHS and a ci element referencing the supplied variable object. Connections and variables will be added to ensure that the given variable is available in the component in which expr appears. Returns expr, for ease of chaining expressions.
Definition at line 841 of file processors.py.
References CellMLToNektar.processors.ModelModifier.connect_variables().
Referenced by CellMLToNektar.processors.UnitsConverter.divide_rhs_by(), and CellMLToNektar.processors.UnitsConverter.times_rhs_by().
def CellMLToNektar.processors.UnitsConverter.times_rhs_by | ( | self, | |
expr, | |||
var | |||
) |
Helper method of use to special units conversions. Will modify the given expr in-place, post-multiplying the RHS by a reference to the given variable object. Connections and variables will be added to ensure that the given variable is available in the component in which expr appears. Returns expr, for ease of chaining expressions.
Definition at line 866 of file processors.py.
References CellMLToNektar.processors.UnitsConverter.modify_rhs().
def CellMLToNektar.processors.UnitsConverter.try_convert | ( | self, | |
func, | |||
args, | |||
kwargs | |||
) |
Call the given function, and log any units errors produced.
Definition at line 780 of file processors.py.
References encode, CellMLToNektar.processors.UnitsConverter.show_xml_context_only, and CellMLToNektar.processors.UnitsConverter.warn_only.
Referenced by CellMLToNektar.processors.UnitsConverter.convert_assignments(), and CellMLToNektar.processors.UnitsConverter.convert_constant().
|
private |
Definition at line 760 of file processors.py.
Referenced by CellMLToNektar.processors.UnitsConverter.convert_mapping().
|
private |
Definition at line 772 of file processors.py.
Referenced by CellMLToNektar.processors.UnitsConverter._cleanup_logger().
CellMLToNektar.processors.UnitsConverter.show_xml_context_only |
Definition at line 757 of file processors.py.
Referenced by CellMLToNektar.processors.UnitsConverter.try_convert().
CellMLToNektar.processors.UnitsConverter.special_conversions |
Definition at line 758 of file processors.py.
Referenced by CellMLToNektar.processors.UnitsConverter._apply_special_conversion_for_nested_expr(), CellMLToNektar.processors.UnitsConverter._check_special_conversion(), CellMLToNektar.processors.UnitsConverter.add_conversions_for_component(), CellMLToNektar.processors.UnitsConverter.add_special_conversion(), CellMLToNektar.processors.UnitsConverter.convert_assignments(), and CellMLToNektar.processors.UnitsConverter.convert_constant().
CellMLToNektar.processors.UnitsConverter.warn_only |
Definition at line 756 of file processors.py.
Referenced by CellMLToNektar.processors.UnitsConverter.try_convert().