Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Public Member Functions | Private Member Functions | List of all members
CellMLToNektar.pycml.mathml_power Class Reference
Inheritance diagram for CellMLToNektar.pycml.mathml_power:
Inheritance graph
[legend]
Collaboration diagram for CellMLToNektar.pycml.mathml_power:
Collaboration graph
[legend]

Public Member Functions

def evaluate
 
- Public Member Functions inherited from CellMLToNektar.pycml.mathml_operator
def wrong_number_of_operands
 
- Public Member Functions inherited from CellMLToNektar.pycml.mathml
def __init__
 
def __repr__
 
def __deepcopy__
 
def clone_self
 
def get_original_of_clone
 
def get_component
 
def model
 
def eval
 
- Public Member Functions inherited from CellMLToNektar.pycml.element_base
def __init__
 
def __delattr__
 
def __setattr__
 
def rootNode
 
def cmeta_id
 
def xml_remove_child_at
 
def xml_doc
 
def xml_properties
 

Private Member Functions

def _set_in_units
 
def _reduce
 

Additional Inherited Members

- Static Public Member Functions inherited from CellMLToNektar.pycml.mathml
def clone
 
- Public Attributes inherited from CellMLToNektar.pycml.element_base
 xml_attributes
 
- Properties inherited from CellMLToNektar.pycml.mathml
 component = property(get_component)
 

Detailed Description

Class representing the MathML <power> operator.

Definition at line 5692 of file pycml.py.

Member Function Documentation

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.

References CellMLToNektar.pycml.mathml.eval().

5729  def _reduce(self):
5730  """Reduce this expression by evaluating its static parts.
5731 
5732  If the whole expression is static, proceed as normal for an <apply>.
5733  Otherwise check if the exponent is static and the expression being exponentiated
5734  is a <ci>. If so, and the exponent is equal to 2, 3, or 4, convert the expression
5735  to a multiplication.
5736  """
5737  app = self.xml_parent
5738  bt = app._get_binding_time()
5739  converted = False
5740  if bt != BINDING_TIMES.static and self.model.get_option('pe_convert_power'):
5741  base, expt = list(app.operands())
5742  expt_bt = app._get_element_binding_time(expt)
5743  if expt_bt == BINDING_TIMES.static and isinstance(base, mathml_ci):
5744  expt_val = self.eval(expt)
5745  if expt_val in [2,3,4]:
5746  # Do the conversion
5747  app.safe_remove_child(base)
5748  operands = [base]
5749  for _ in range(1, expt_val):
5750  operands.append(base.clone_self())
5751  base.variable._used()
5752  new_app = mathml_apply.create_new(app, u'times', operands)
5753  app.replace_child(app, new_app, app.xml_parent)
5754  # Finally, reduce the new expression, just to be safe!
5755  new_app._reduce()
5756  converted = True
5757  if not converted:
5758  # Evaluate this expression as normal
5759  app._reduce(check_operator=False)
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.

References CellMLToNektar.pycml.mathml_units_mixin._set_element_in_units().

5695  def _set_in_units(self, units, no_act=False):
5696  """Set the units of the application of this operator.
5697 
5698  Set the exponent to have units of dimensionless, and the operand to
5699  have an arbitrary member of its possible units set.
5700 
5701  Where these mean the <apply> doesn't have the given units, wrap it
5702  in suitable units conversion mathematics.
5703  """
5704  app = self.xml_parent
5705  defn_units_set = app.get_units()
5706  defn_units = defn_units_set.extract()
5707  app._add_units_conversion(app, defn_units, units, no_act)
5708  # Record which member of the set we used
5709  if not no_act:
5710  app._cml_units = defn_units
5711  # Set exponent units
5712  dimensionless = app.model.get_units_by_name('dimensionless')
5713  ops = list(app.operands())
5714  self._set_element_in_units(ops[1], dimensionless, no_act)
5715  # Set operand units
5716  for src_units_set, src_units in defn_units_set._get_sources(defn_units):
5717  expr = src_units_set.get_expression()
5718  self._set_element_in_units(expr, src_units, no_act)
5719  return
def CellMLToNektar.pycml.mathml_power.evaluate (   self)
Return the first operand to the power of the second.

Definition at line 5720 of file pycml.py.

References CellMLToNektar.pycml.mathml.eval(), and CellMLToNektar.pycml.mathml_operator.wrong_number_of_operands().

Referenced by CellMLToNektar.pycml.mathml_constructor._eval_self().

5721  def evaluate(self):
5722  """Return the first operand to the power of the second."""
5723  app = self.xml_parent
5724  ops = list(app.operands())
5725  if len(ops) != 2:
5726  self.wrong_number_of_operands(len(ops), [2])
5727  return self.eval(ops[0]) ** self.eval(ops[1])