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

Public Member Functions

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
 

Static Public Member Functions

def clone
 

Properties

 component = property(get_component)
 

Private Member Functions

def _unset_cached_links
 
def _ensure_units_exist
 

Private Attributes

 _cml_component
 
 _cml_model
 
 _cml_source_expr_for_clone
 

Additional Inherited Members

- Public Attributes inherited from CellMLToNektar.pycml.element_base
 xml_attributes
 

Detailed Description

Base class for MathML elements.

Definition at line 3682 of file pycml.py.

Constructor & Destructor Documentation

def CellMLToNektar.pycml.mathml.__init__ (   self)

Definition at line 3684 of file pycml.py.

3685  def __init__(self):
3686  super(mathml, self).__init__()
3687  self._cml_component = None
3688  self._cml_model = None
3689  self._cml_source_expr_for_clone = None
3690  return

Member Function Documentation

def CellMLToNektar.pycml.mathml.__deepcopy__ (   self,
  memo 
)
Customise copying of MathML expressions.

When copying an expression tree, we only want to deepcopy the
XML, not the additional info that we have attached to it -
these should be copied as references to the originals.

Definition at line 3694 of file pycml.py.

3695  def __deepcopy__(self, memo):
3696  """Customise copying of MathML expressions.
3697 
3698  When copying an expression tree, we only want to deepcopy the
3699  XML, not the additional info that we have attached to it -
3700  these should be copied as references to the originals.
3701  """
3702  new_elt = copy.copy(self)
3703  # Children may refer to us, so need to update memo before copying children
3704  assert id(self) not in memo
3705  memo[id(self)] = new_elt
3706  new_dict = {}
3707  for name, value in self.__dict__.iteritems():
3708  name_copy = copy.deepcopy(name, memo)
3709  if not name.startswith('_cml'):
3710  new_dict[name_copy] = copy.deepcopy(value, memo)
3711  else:
3712  new_dict[name_copy] = value
3713  new_elt.__dict__.update(new_dict)
3714  return new_elt
def CellMLToNektar.pycml.mathml.__repr__ (   self)

Definition at line 3691 of file pycml.py.

3692  def __repr__(self):
3693  return '<%s (%s) at 0x%x>' % (self.__class__.__name__, str(self), id(self))
def CellMLToNektar.pycml.mathml._ensure_units_exist (   self,
  units = None,
  no_act = False 
)
private
Ensure that there is an element in the XML tree giving this
expression's units.

Add a new <units> element if this expression has generated units.

If units is not None, use the given units rather than those of
this expression.

Return an attribute dictionary with the appropriate units
attribute.

Definition at line 3807 of file pycml.py.

References CellMLToNektar.pycml.extract(), CellMLToNektar.pycml.cellml_variable.get_units(), CellMLToNektar.pycml.mathml_cn.get_units(), CellMLToNektar.pycml.mathml_ci.get_units(), CellMLToNektar.pycml.mathml_apply.get_units(), and CellMLToNektar.pycml.mathml_piecewise.get_units().

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

3808  def _ensure_units_exist(self, units=None, no_act=False):
3809  """Ensure that there is an element in the XML tree giving this
3810  expression's units.
3811 
3812  Add a new <units> element if this expression has generated units.
3813 
3814  If units is not None, use the given units rather than those of
3815  this expression.
3816 
3817  Return an attribute dictionary with the appropriate units
3818  attribute."""
3819  if no_act:
3820  # Doesn't matter what we return, as it wont be used
3821  return {(u'cml:units', NSS[u'cml']): u'#UNUSED#'}
3822  try:
3823  if units is None:
units = self.get_units().extract()
def CellMLToNektar.pycml.mathml._unset_cached_links (   self,
  elt = None 
)
private
Forget cached component and variable references in this MathML tree.

Used by partial evaluator when moving maths to a new component, and by
simulation protocols.

Definition at line 3767 of file pycml.py.

References CellMLToNektar.pycml.mathml._unset_cached_links().

Referenced by CellMLToNektar.pycml.mathml._unset_cached_links().

3768  def _unset_cached_links(self, elt=None):
3769  """Forget cached component and variable references in this MathML tree.
3770 
3771  Used by partial evaluator when moving maths to a new component, and by
3772  simulation protocols.
3773  """
3774  if elt is None:
3775  elt = self
3776  if isinstance(elt, mathml):
3777  elt._cml_component = None
3778  for child in self.xml_element_children(elt):
3779  if hasattr(child, '_unset_cached_links'):
3780  child._unset_cached_links()
3781  else:
3782  self._unset_cached_links(child)
3783  return
def CellMLToNektar.pycml.mathml.clone (   expr)
static
Properly clone a MathML sub-expression.

Makes sure siblings and parent don't get copied too.

Definition at line 3716 of file pycml.py.

3717  def clone(expr):
3718  """Properly clone a MathML sub-expression.
3719 
3720  Makes sure siblings and parent don't get copied too.
3721  """
3722 # print "Cloning MathML", prid(expr, True)
3723  next_elem, par = expr.next_elem, getattr(expr, 'xml_parent', None)
3724  expr.next_elem = None # Make sure we don't copy siblings...
3725  expr.xml_parent = None # ...and parent
3726  new_expr = copy.deepcopy(expr) # Do the clone
3727  expr.next_elem = next_elem # Restore siblings...
3728  expr.xml_parent = par # ...and parent to original
3729  return new_expr
def CellMLToNektar.pycml.mathml.clone_self (   self,
  register = False 
)
Properly clone this expression.

If register is True, then keep a link to this expression in the clone.

Definition at line 3730 of file pycml.py.

3731  def clone_self(self, register=False):
3732  """Properly clone this expression.
3733 
3734  If register is True, then keep a link to this expression in the clone.
3735  """
3736  clone = mathml.clone(self)
3737  if register:
3738  clone._cml_source_expr_for_clone = self
3739  return clone
def CellMLToNektar.pycml.mathml.eval (   self,
  elt 
)
Evaluate the given element.

Tries to evaluate the given element, and raises an EvaluationError
if this is not possible.

Definition at line 3791 of file pycml.py.

Referenced by CellMLToNektar.pycml.mathml_piecewise._get_binding_time(), CellMLToNektar.pycml.mathml_and._get_binding_time(), CellMLToNektar.pycml.mathml_or._get_binding_time(), CellMLToNektar.pycml.mathml_piecewise._reduce(), CellMLToNektar.pycml.mathml_power._reduce(), CellMLToNektar.pycml.mathml_piecewise.evaluate(), CellMLToNektar.pycml.mathml_plus.evaluate(), CellMLToNektar.pycml.mathml_minus.evaluate(), CellMLToNektar.pycml.mathml_times.evaluate(), CellMLToNektar.pycml.mathml_divide.evaluate(), CellMLToNektar.pycml.mathml_exp.evaluate(), CellMLToNektar.pycml.mathml_ln.evaluate(), CellMLToNektar.pycml.mathml_log.evaluate(), CellMLToNektar.pycml.mathml_abs.evaluate(), CellMLToNektar.pycml.mathml_power.evaluate(), CellMLToNektar.pycml.mathml_root.evaluate(), CellMLToNektar.pycml.mathml_and.evaluate(), CellMLToNektar.pycml.mathml_or.evaluate(), CellMLToNektar.pycml.mathml_leq.evaluate(), CellMLToNektar.pycml.mathml_lt.evaluate(), CellMLToNektar.pycml.mathml_geq.evaluate(), CellMLToNektar.pycml.mathml_gt.evaluate(), CellMLToNektar.pycml.mathml_neq.evaluate(), CellMLToNektar.pycml.mathml_eq.evaluate(), CellMLToNektar.pycml.mathml_rem.evaluate(), CellMLToNektar.pycml.mathml_logbase.evaluate(), CellMLToNektar.pycml.mathml_degree.evaluate(), CellMLToNektar.pycml.mathml_sin.evaluate(), CellMLToNektar.pycml.mathml_cos.evaluate(), CellMLToNektar.pycml.mathml_tan.evaluate(), CellMLToNektar.pycml.mathml_arcsin.evaluate(), CellMLToNektar.pycml.mathml_arccos.evaluate(), CellMLToNektar.pycml.mathml_arctan.evaluate(), and CellMLToNektar.pycml.mathml_apply.get_units().

3792  def eval(self, elt):
3793  """Evaluate the given element.
3794 
3795  Tries to evaluate the given element, and raises an EvaluationError
3796  if this is not possible.
3797  """
3798  if hasattr(elt, 'evaluate') and callable(elt.evaluate):
3799  return elt.evaluate()
3800  elif elt.localName == u'pi':
3801  return math.pi
3802  else:
3803  # No evaluate() method on elt
3804  raise EvaluationError("Don't know how to evaluate element " +
3805  elt.localName)
3806  return
def CellMLToNektar.pycml.mathml.get_component (   self)

Definition at line 3747 of file pycml.py.

References CellMLToNektar.pycml.mathml._cml_component.

3748  def get_component(self):
3749  "Cache & return the enclosing component element."
3750  if self._cml_component is None:
3751  def get_ancestor(elt, name):
3752  while elt and elt.localName != name:
3753  elt = elt.parentNode
3754  return elt
3755  comp = get_ancestor(self, u'component')
3756  if comp:
3757  self._cml_component = comp
3758  else:
3759  # It may be in the solver_info section, in which case fake a component
3760  solver_info = get_ancestor(self, u'solver_info')
3761  if solver_info:
3762  self._cml_component = self.model.get_component_by_name(u'')
3763  else:
3764  raise ValueError("MathML element " + str(self) + " does not occur in a model component!")
return self._cml_component
def CellMLToNektar.pycml.mathml.get_original_of_clone (   self)
If this is a clone with a registered original expression, return it.
Otherwise returns None.

Definition at line 3740 of file pycml.py.

References CellMLToNektar.pycml.mathml._cml_source_expr_for_clone.

3741  def get_original_of_clone(self):
3742  """
3743  If this is a clone with a registered original expression, return it.
3744  Otherwise returns None.
3745  """
3746  return self._cml_source_expr_for_clone
def CellMLToNektar.pycml.mathml.model (   self)
Cache & return the enclosing model element.

Definition at line 3785 of file pycml.py.

References CellMLToNektar.pycml.mathml._cml_model.

Referenced by CellMLToNektar.pycml.mathml_apply.get_units().

3786  def model(self):
3787  """Cache & return the enclosing model element."""
3788  if self._cml_model is None:
3789  self._cml_model = self.rootNode.model
3790  return self._cml_model

Member Data Documentation

CellMLToNektar.pycml.mathml._cml_component
private

Definition at line 3686 of file pycml.py.

Referenced by CellMLToNektar.pycml.mathml.get_component().

CellMLToNektar.pycml.mathml._cml_model
private

Definition at line 3687 of file pycml.py.

Referenced by CellMLToNektar.pycml.mathml.model().

CellMLToNektar.pycml.mathml._cml_source_expr_for_clone
private

Definition at line 3688 of file pycml.py.

Referenced by CellMLToNektar.pycml.mathml.get_original_of_clone().

Property Documentation

CellMLToNektar.pycml.mathml.component = property(get_component)
static

Definition at line 3765 of file pycml.py.