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_eq Class Reference
Inheritance diagram for CellMLToNektar.pycml.mathml_eq:
Inheritance graph
[legend]
Collaboration diagram for CellMLToNektar.pycml.mathml_eq:
Collaboration graph
[legend]

Public Member Functions

def evaluate
 
def rhs
 
def lhs
 
- 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 _is_top_level
 
def _set_in_units
 
def _get_binding_time
 
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 <eq> operator.

Definition at line 5946 of file pycml.py.

Member Function Documentation

def CellMLToNektar.pycml.mathml_eq._get_binding_time (   self)
private
Return the binding time of the enclosing <apply> element.

If this is a top-level expression, then only recurse into the RHS,
otherwise proceed as normal for an apply.

There is one further special case: if this is a top-level
expression and the variable assigned to is annotated to be
kept in the specialised model, then the expression is dynamic.

Definition at line 6002 of file pycml.py.

References CellMLToNektar.pycml.mathml_eq._is_top_level(), CellMLToNektar.utilities.DEBUG(), and CellMLToNektar.pycml.mathml_operator.wrong_number_of_operands().

6003  def _get_binding_time(self):
6004  """Return the binding time of the enclosing <apply> element.
6005 
6006  If this is a top-level expression, then only recurse into the RHS,
6007  otherwise proceed as normal for an apply.
6008 
6009  There is one further special case: if this is a top-level
6010  expression and the variable assigned to is annotated to be
6011  kept in the specialised model, then the expression is dynamic.
6012  """
6013  app = self.xml_parent
6014  if self._is_top_level():
6015  annotated_as_kept = False
6016  if app.is_ode():
6017  DEBUG('partial-evaluator', "BT ODE",
6018  map(lambda v: v.fullname(), app.assigned_variable()))
6019  else:
6020  DEBUG('partial-evaluator', "BT expr",
6021  app.assigned_variable().fullname())
6022  if app.assigned_variable().pe_keep:
6023  annotated_as_kept = True
6024  ops = list(app.operands())
6025  if len(ops) != 2:
6026  self.wrong_number_of_operands(len(ops), [2])
6027  rhs = ops[1]
6028  bt = app._get_element_binding_time(rhs)
6029  if annotated_as_kept:
6030  bt = BINDING_TIMES.dynamic
6031  else:
6032  bt = app._get_binding_time(check_operator=False)
6033  return bt
def CellMLToNektar.pycml.mathml_eq._is_top_level (   self)
private
Return True iff the enclosing <apply> is a top-level expression.

Definition at line 5948 of file pycml.py.

Referenced by CellMLToNektar.pycml.mathml_eq._get_binding_time(), CellMLToNektar.pycml.mathml_eq._reduce(), CellMLToNektar.pycml.mathml_eq._set_in_units(), CellMLToNektar.pycml.mathml_eq.evaluate(), CellMLToNektar.pycml.mathml_eq.lhs(), and CellMLToNektar.pycml.mathml_eq.rhs().

5949  def _is_top_level(self):
5950  """Return True iff the enclosing <apply> is a top-level expression."""
5951  return self.xml_parent.is_top_level()
def CellMLToNektar.pycml.mathml_eq._reduce (   self)
private
Reduce this expression by evaluating its static parts.

If this is a top-level assignment, then just reduce the RHS.
Otherwise proceed as normal for an <apply>.

Definition at line 6034 of file pycml.py.

References CellMLToNektar.pycml.mathml_eq._is_top_level(), and CellMLToNektar.pycml.mathml_operator.wrong_number_of_operands().

6035  def _reduce(self):
6036  """Reduce this expression by evaluating its static parts.
6037 
6038  If this is a top-level assignment, then just reduce the RHS.
6039  Otherwise proceed as normal for an <apply>.
6040  """
6041  app = self.xml_parent
6042  if self._is_top_level():
6043  ops = list(app.operands())
6044  if len(ops) != 2:
6045  self.wrong_number_of_operands(len(ops), [2])
6046  rhs = ops[1]
6047  app._reduce_elt(rhs)
6048  else:
6049  app._reduce(check_operator=False)
def CellMLToNektar.pycml.mathml_eq._set_in_units (   self,
  units,
  no_act = False 
)
private
Set the units of the application of this operator.

If this is a top-level <eq/>, then force the RHS to take the units
of the LHS.  Otherwise, behave as for other relational operators.

Definition at line 5952 of file pycml.py.

References CellMLToNektar.pycml.mathml_eq._is_top_level(), CellMLToNektar.pycml.mathml_units_mixin._set_element_in_units(), and CellMLToNektar.pycml.extract().

5953  def _set_in_units(self, units, no_act=False):
5954  """Set the units of the application of this operator.
5955 
5956  If this is a top-level <eq/>, then force the RHS to take the units
5957  of the LHS. Otherwise, behave as for other relational operators.
5958  """
5959  if self._is_top_level():
5960  ops = self.xml_parent.operands()
5961  lhs = ops.next()
5962  lhs_units = lhs.get_units().extract()
5963  self._set_element_in_units(lhs, lhs_units, no_act)
5964  self._set_element_in_units(ops.next(), lhs_units, no_act)
5965  if not no_act:
5966  self.xml_parent._cml_units = units
5967  else:
5968  super(mathml_eq, self)._set_in_units(units, no_act)
def CellMLToNektar.pycml.mathml_eq.evaluate (   self)
Evaluate the enclosing <apply> element.

The behaviour depends on whether the enclosing <apply> is a
top-level expression or not, i.e. whether this is an
assignment or a comparison.

If an assignment, evaluate the RHS, assign the value to
the variable on the LHS, and return it.

If a comparison, return True iff the 2 operands are equal.

Definition at line 5969 of file pycml.py.

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

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

5970  def evaluate(self):
5971  """Evaluate the enclosing <apply> element.
5972 
5973  The behaviour depends on whether the enclosing <apply> is a
5974  top-level expression or not, i.e. whether this is an
5975  assignment or a comparison.
5976 
5977  If an assignment, evaluate the RHS, assign the value to
5978  the variable on the LHS, and return it.
5979 
5980  If a comparison, return True iff the 2 operands are equal.
5981  """
5982  app = self.xml_parent
5983  ops = list(app.operands())
5984  if len(ops) != 2:
5985  self.wrong_number_of_operands(len(ops), [2])
5986 
5987  if self._is_top_level():
5988  # This is a top-level assignment or ODE
5989  value = self.eval(ops[1])
5990  var = app.assigned_variable()
5991  if app.is_assignment():
5992  var.set_value(value)
5993  elif app.is_ode():
5994  indepvar = var[1].get_source_variable(recurse=True)
5995  var[0].set_value(value, ode=indepvar)
5996  else:
5997  raise EvaluationError("Weird sort of assignment expression.")
5998  else:
5999  # This is a comparison
6000  value = (self.eval(ops[0]) == self.eval(ops[1]))
6001  return value
def CellMLToNektar.pycml.mathml_eq.lhs (   self)
Return the left hand side of this expression.

Should only be called if we're actually an assignment.

Definition at line 6063 of file pycml.py.

References CellMLToNektar.pycml.mathml_eq._is_top_level().

6064  def lhs(self):
6065  """Return the left hand side of this expression.
6066 
6067  Should only be called if we're actually an assignment.
6068  """
6069  if self._is_top_level():
6070  ops = self.xml_parent.operands()
6071  return ops.next()
6072  else:
6073  raise ValueError("Not an assignment expression.")
def CellMLToNektar.pycml.mathml_eq.rhs (   self)
Return the right hand side of this expression.

Should only be called if we're actually an assignment.

Definition at line 6051 of file pycml.py.

References CellMLToNektar.pycml.mathml_eq._is_top_level().

6052  def rhs(self):
6053  """Return the right hand side of this expression.
6054 
6055  Should only be called if we're actually an assignment.
6056  """
6057  if self._is_top_level():
6058  ops = self.xml_parent.operands()
6059  ops.next()
6060  return ops.next()
6061  else:
raise ValueError("Not an assignment expression.")