Nektar++
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:
[legend]

Public Member Functions

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)
 

Static Public Member Functions

def clone (expr)
 

Properties

 component = property(get_component)
 

Private Member Functions

def _unset_cached_links (self, elt=None)
 
def _ensure_units_exist (self, units=None, no_act=False)
 

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

◆ __init__()

def CellMLToNektar.pycml.mathml.__init__ (   self)

Reimplemented from CellMLToNektar.pycml.element_base.

Reimplemented in CellMLToNektar.pycml.mathml_math, CellMLToNektar.pycml.mathml_constructor, CellMLToNektar.pycml.mathml_cn, CellMLToNektar.pycml.mathml_ci, CellMLToNektar.pycml.mathml_apply, CellMLToNektar.pycml.mathml_piecewise, and CellMLToNektar.pycml.mathml_plus.

Definition at line 3684 of file pycml.py.

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

References CellMLToNektar.pycml.mathml.__init__().

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

Member Function Documentation

◆ __deepcopy__()

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.

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

◆ __repr__()

def CellMLToNektar.pycml.mathml.__repr__ (   self)

Definition at line 3691 of file pycml.py.

3691 def __repr__(self):
3692 return '<%s (%s) at 0x%x>' % (self.__class__.__name__, str(self), id(self))
3693

◆ _ensure_units_exist()

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.

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

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

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

◆ _unset_cached_links()

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.

Reimplemented in CellMLToNektar.pycml.mathml_ci.

Definition at line 3767 of file pycml.py.

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

References CellMLToNektar.pycml.mathml._unset_cached_links(), and CellMLToNektar.pycml.mathml_ci._unset_cached_links().

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

◆ clone()

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.

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

References CellMLToNektar.utilities.prid().

◆ clone_self()

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.

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

◆ eval()

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.

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

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_power._reduce(), CellMLToNektar.pycml.mathml_piecewise._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().

◆ get_component()

def CellMLToNektar.pycml.mathml.get_component (   self)

Definition at line 3747 of file pycml.py.

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

References CellMLToNektar.pycml.mathml._cml_component, CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.pycml.cellml_variable.model(), CellMLToNektar.pycml.mathml.model(), and CellMLToNektar.translators.CellMLTranslator.model.

◆ get_original_of_clone()

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.

3740 def get_original_of_clone(self):
3741 """
3742 If this is a clone with a registered original expression, return it.
3743 Otherwise returns None.
3744 """
3745 return self._cml_source_expr_for_clone
3746

References CellMLToNektar.pycml.mathml._cml_source_expr_for_clone.

◆ model()

def CellMLToNektar.pycml.mathml.model (   self)
Cache & return the enclosing model element.

Definition at line 3785 of file pycml.py.

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

References CellMLToNektar.pycml.mathml._cml_model, and CellMLToNektar.pycml.element_base.rootNode().

Referenced by CellMLToNektar.processors.InterfaceGenerator._add_all_odes_to_interface(), CellMLToNektar.processors.ModelModifier._clear_model_caches(), CellMLToNektar.processors.ModelModifier._create_connection_element(), CellMLToNektar.processors.ModelModifier._find_connection_element(), CellMLToNektar.processors.ModelModifier._find_or_create_variable(), CellMLToNektar.processors.ModelModifier._process_operator(), CellMLToNektar.pycml.reduce_commutative_nary._reduce(), CellMLToNektar.pycml.mathml_power._reduce(), CellMLToNektar.pycml.mathml_piecewise._set_in_units(), CellMLToNektar.pycml.cellml_variable._set_source_variable(), CellMLToNektar.processors.InterfaceGenerator._split_ode(), CellMLToNektar.processors.InterfaceGenerator._transform_derivatives_on_rhs(), CellMLToNektar.processors.ModelModifier._update_connections(), CellMLToNektar.processors.UnitsConverter.add_all_conversions(), CellMLToNektar.processors.UnitsConverter.add_conversions_for_component(), CellMLToNektar.processors.ModelModifier.add_expr_to_comp(), CellMLToNektar.processors.InterfaceGenerator.add_output_function(), CellMLToNektar.pycml.cellml_variable.add_rdf_annotation(), CellMLToNektar.processors.ModelModifier.add_units(), CellMLToNektar.processors.ModelModifier.add_variable(), CellMLToNektar.translators.CellMLTranslator.calculate_extended_dependencies(), CellMLToNektar.pycml.mathml_apply.classify_variables(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.processors.ModelModifier.connect_variables(), CellMLToNektar.processors.UnitsConverter.convert_assignments(), CellMLToNektar.processors.UnitsConverter.convert_connections(), CellMLToNektar.processors.UnitsConverter.convert_constant(), CellMLToNektar.processors.UnitsConverter.convert_mapping(), CellMLToNektar.processors.ModelModifier.create_new_component(), CellMLToNektar.processors.ModelModifier.finalize(), CellMLToNektar.pycml.mathml.get_component(), CellMLToNektar.processors.InterfaceGenerator.get_interface_component(), CellMLToNektar.pycml.cellml_variable.get_rdf_annotation(), CellMLToNektar.pycml.cellml_variable.get_rdf_annotations(), CellMLToNektar.pycml.mathml_apply.get_units(), CellMLToNektar.pycml.mathml_piecewise.get_units(), CellMLToNektar.pycml.cellml_variable.is_statically_const(), CellMLToNektar.processors.InterfaceGenerator.make_var_computed_constant(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_default_stimulus(), CellMLToNektar.translators.CellMLTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_includes(), CellMLToNektar.translators.CellMLTranslator.output_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_model_attributes(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_top_boilerplate(), CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_verify_state_variables(), CellMLToNektar.processors.ModelModifier.remove_connections(), CellMLToNektar.pycml.cellml_variable.remove_rdf_annotations(), CellMLToNektar.translators.CellMLTranslator.var_display_name(), and CellMLToNektar.translators.CellMLTranslator.varobj().

Member Data Documentation

◆ _cml_component

CellMLToNektar.pycml.mathml._cml_component
private

Definition at line 3686 of file pycml.py.

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

◆ _cml_model

CellMLToNektar.pycml.mathml._cml_model
private

Definition at line 3687 of file pycml.py.

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

◆ _cml_source_expr_for_clone

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

◆ component

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