Class representing the MathML <power> operator.
Definition at line 5692 of file pycml.py.
def CellMLToNektar.pycml.mathml_power._reduce |
( |
|
self | ) |
|
|
private |
Reduce this expression by evaluating its static parts.
If the whole expression is static, proceed as normal for an <apply>.
Otherwise check if the exponent is static and the expression being exponentiated
is a <ci>. If so, and the exponent is equal to 2, 3, or 4, convert the expression
to a multiplication.
Definition at line 5728 of file pycml.py.
5729 """Reduce this expression by evaluating its static parts.
5731 If the whole expression is static, proceed as normal for an <apply>.
5732 Otherwise check if the exponent is static and the expression being exponentiated
5733 is a <ci>. If so, and the exponent is equal to 2, 3, or 4, convert the expression
5734 to a multiplication.
5736 app = self.xml_parent
5737 bt = app._get_binding_time()
5739 if bt != BINDING_TIMES.static
and self.model.get_option(
'pe_convert_power'):
5740 base, expt = list(app.operands())
5741 expt_bt = app._get_element_binding_time(expt)
5742 if expt_bt == BINDING_TIMES.static
and isinstance(base, mathml_ci):
5743 expt_val = self.eval(expt)
5744 if expt_val
in [2,3,4]:
5746 app.safe_remove_child(base)
5748 for _
in range(1, expt_val):
5749 operands.append(base.clone_self())
5750 base.variable._used()
5751 new_app = mathml_apply.create_new(app,
u'times', operands)
5752 app.replace_child(app, new_app, app.xml_parent)
5758 app._reduce(check_operator=
False)
References CellMLToNektar.pycml.mathml.eval(), CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.pycml.cellml_variable.model(), CellMLToNektar.pycml.mathml.model(), and CellMLToNektar.translators.CellMLTranslator.model.
def CellMLToNektar.pycml.mathml_power._set_in_units |
( |
|
self, |
|
|
|
units, |
|
|
|
no_act = False |
|
) |
| |
|
private |
Set the units of the application of this operator.
Set the exponent to have units of dimensionless, and the operand to
have an arbitrary member of its possible units set.
Where these mean the <apply> doesn't have the given units, wrap it
in suitable units conversion mathematics.
Definition at line 5694 of file pycml.py.
5694 def _set_in_units(self, units, no_act=False):
5695 """Set the units of the application of this operator.
5697 Set the exponent to have units of dimensionless, and the operand to
5698 have an arbitrary member of its possible units set.
5700 Where these mean the <apply> doesn't have the given units, wrap it
5701 in suitable units conversion mathematics.
5703 app = self.xml_parent
5704 defn_units_set = app.get_units()
5705 defn_units = defn_units_set.extract()
5706 app._add_units_conversion(app, defn_units, units, no_act)
5709 app._cml_units = defn_units
5711 dimensionless = app.model.get_units_by_name(
'dimensionless')
5712 ops = list(app.operands())
5713 self._set_element_in_units(ops[1], dimensionless, no_act)
5715 for src_units_set, src_units
in defn_units_set._get_sources(defn_units):
5716 expr = src_units_set.get_expression()
5717 self._set_element_in_units(expr, src_units, no_act)
References CellMLToNektar.pycml.mathml_units_mixin._set_element_in_units().