Nektar++
Public Member Functions | Private Member Functions | List of all members
CellMLToNektar.pycml.mathml_eq Class Reference
Inheritance diagram for CellMLToNektar.pycml.mathml_eq:
[legend]

Public Member Functions

def evaluate (self)
 
def rhs (self)
 
def lhs (self)
 
- Public Member Functions inherited from CellMLToNektar.pycml.mathml_operator
def wrong_number_of_operands (self, found, wanted)
 
- Public Member Functions inherited from CellMLToNektar.pycml.mathml
def __init__ (self)
 
def __repr__ (self)
 
def __deepcopy__ (self, memo)
 
def clone_self (self, register=False)
 
def get_original_of_clone (self)
 
def get_component (self)
 
def model (self)
 
def eval (self, elt)
 
- Public Member Functions inherited from CellMLToNektar.pycml.element_base
def __init__ (self)
 
def __delattr__ (self, key)
 
def __setattr__ (self, key, value)
 
def rootNode (self)
 
def cmeta_id (self)
 
def xml_remove_child_at (self, index=-1)
 
def xml_doc (self)
 
def xml_properties (self)
 

Private Member Functions

def _is_top_level (self)
 
def _set_in_units (self, units, no_act=False)
 
def _get_binding_time (self)
 
def _reduce (self)
 

Additional Inherited Members

- Static Public Member Functions inherited from CellMLToNektar.pycml.mathml
def clone (expr)
 
- 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

◆ _get_binding_time()

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.

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

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

Referenced by CellMLToNektar.pycml.mathml_ci._reduce(), CellMLToNektar.pycml.mathml_apply._reduce(), CellMLToNektar.pycml.mathml_piecewise._reduce(), CellMLToNektar.pycml.cellml_variable.get_value(), and CellMLToNektar.pycml.cellml_variable.is_statically_const().

◆ _is_top_level()

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.

5948 def _is_top_level(self):
5949 """Return True iff the enclosing <apply> is a top-level expression."""
5950 return self.xml_parent.is_top_level()
5951

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().

◆ _reduce()

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.

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

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

◆ _set_in_units()

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.

Reimplemented from CellMLToNektar.pycml.mathml_units_mixin_equalise_operands.

Definition at line 5952 of file pycml.py.

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

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

Referenced by CellMLToNektar.pycml.mathml_eq._set_in_units().

◆ evaluate()

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.

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

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(), and CellMLToNektar.pycml.mathml_ci._reduce().

◆ lhs()

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.

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

References CellMLToNektar.pycml.mathml_eq._is_top_level().

◆ rhs()

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.

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

References CellMLToNektar.pycml.mathml_eq._is_top_level().