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

Public Member Functions

def __init__ (self)
 
def evaluate (self)
 
def get_units (self, return_set=True)
 
- Public Member Functions inherited from CellMLToNektar.pycml.mathml
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 __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 create_new (elt, value, units)
 
- Static Public Member Functions inherited from CellMLToNektar.pycml.mathml
def clone (expr)
 

Public Attributes

 type
 
- Public Attributes inherited from CellMLToNektar.pycml.element_base
 xml_attributes
 

Private Member Functions

def _get_binding_time (self)
 
def _reduce (self)
 

Private Attributes

 _cml_units
 

Additional Inherited Members

- Properties inherited from CellMLToNektar.pycml.mathml
 component = property(get_component)
 

Detailed Description

Definition at line 4145 of file pycml.py.

Constructor & Destructor Documentation

◆ __init__()

def CellMLToNektar.pycml.mathml_cn.__init__ (   self)

Reimplemented from CellMLToNektar.pycml.mathml.

Definition at line 4146 of file pycml.py.

4146  def __init__(self):
4147  super(mathml_cn, self).__init__()
4148  self._cml_units = None
4149  return
4150 

Member Function Documentation

◆ _get_binding_time()

def CellMLToNektar.pycml.mathml_cn._get_binding_time (   self)
private
Return the binding time of this expression.

The binding time of a <cn> element is always static,
unless the CellML is annotated otherwise.

Definition at line 4184 of file pycml.py.

4184  def _get_binding_time(self):
4185  """Return the binding time of this expression.
4186 
4187  The binding time of a <cn> element is always static,
4188  unless the CellML is annotated otherwise.
4189  """
4190  bt = self.getAttributeNS(NSS['pe'], u'binding_time', u'static')
4191  return getattr(BINDING_TIMES, bt)
4192 

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

◆ _reduce()

def CellMLToNektar.pycml.mathml_cn._reduce (   self)
private
Reduce this expression by evaluating its static parts.

Is actually a no-op; we must have been annotated explicitly as dynamic.

Definition at line 4193 of file pycml.py.

4193  def _reduce(self):
4194  """Reduce this expression by evaluating its static parts.
4195 
4196  Is actually a no-op; we must have been annotated explicitly as dynamic.
4197  """
4198  return
4199 

◆ create_new()

def CellMLToNektar.pycml.mathml_cn.create_new (   elt,
  value,
  units 
)
static
Create a new <cn> element with the given value and units.

Definition at line 4211 of file pycml.py.

4211  def create_new(elt, value, units):
4212  """Create a new <cn> element with the given value and units."""
4213  attrs = {(u'cml:units', NSS[u'cml']): unicode(units)}
4214  new_elt = elt.xml_create_element(u'cn', NSS[u'm'],
4215  attributes=attrs,
4216  content=unicode(value))
4217  return new_elt
4218 
def create_new(parent, name, bases, add_to_parent=False, standard=False)
Definition: pycml.py:2912

◆ evaluate()

def CellMLToNektar.pycml.mathml_cn.evaluate (   self)
Convert the text content of this element to a floating point
value and return it.  Will handle the type attribute and, if
relevant to the type, the sep child element, but does not yet
handle the base attribute.

Definition at line 4151 of file pycml.py.

4151  def evaluate(self):
4152  """
4153  Convert the text content of this element to a floating point
4154  value and return it. Will handle the type attribute and, if
4155  relevant to the type, the sep child element, but does not yet
4156  handle the base attribute.
4157  """
4158  if hasattr(self, u'base'):
4159  raise ValueError('pycml does not yet support the base attribute on cn elements')
4160  if hasattr(self, u'type'):
4161  if self.type == u'real':
4162  val = float(unicode(self))
4163  elif self.type == u'integer':
4164  val = int(unicode(self))
4165  elif self.type == u'e-notation':
4166  assert len(self.xml_children) == 3
4167  assert self.xml_children[1] is self.sep
4168  mantissa = unicode(self.xml_children[0]).strip()
4169  exponent = unicode(self.xml_children[2]).strip()
4170  val = float(mantissa + 'e' + exponent)
4171  elif self.type == u'rational':
4172  assert len(self.xml_children) == 3
4173  assert self.xml_children[1] is self.sep
4174  numer = int(unicode(self.xml_children[0]))
4175  denom = int(unicode(self.xml_children[2]))
4176  val = numer / denom
4177  else:
4178  raise ValueError('Unsupported type attribute for cn element: '
4179  + self.type)
4180  else:
4181  val = float(unicode(self))
4182  return val
4183 

Referenced by CellMLToNektar.pycml.mathml_constructor._eval_self(), and CellMLToNektar.pycml.mathml_ci._reduce().

◆ get_units()

def CellMLToNektar.pycml.mathml_cn.get_units (   self,
  return_set = True 
)
Return the units this number is expressed in.

Definition at line 4200 of file pycml.py.

4200  def get_units(self, return_set=True):
4201  """Return the units this number is expressed in."""
4202  if not self._cml_units:
4203  self._cml_units = UnitsSet([self.component.get_units_by_name(self.units)], expression=self)
4204  if not return_set:
4205  u = self._cml_units.extract()
4206  else:
4207  u = self._cml_units
4208  return u
4209 
def get_units_by_name(self, uname)
Definition: pycml.py:2725
def extract(self, check_equality=False)
Definition: pycml.py:2657

Referenced by CellMLToNektar.pycml.mathml._ensure_units_exist(), CellMLToNektar.pycml.mathml_units_mixin_tokens._set_in_units(), and CellMLToNektar.pycml.mathml_apply._set_in_units().

Member Data Documentation

◆ _cml_units

CellMLToNektar.pycml.mathml_cn._cml_units
private

◆ type

CellMLToNektar.pycml.mathml_cn.type

Definition at line 4161 of file pycml.py.