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

Public Member Functions

def __init__ (self)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __hash__ (self)
 
def get_units_element (self)
 
def get_multiplicative_factor (self)
 
def get_multiplier (self)
 
def get_exponent (self)
 
def get_offset (self)
 
def clone (self)
 
- 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 Attributes

dictionary SI_PREFIXES
 

Private Member Functions

def _hash_tup (self)
 
def _set_units_element (self, obj, override=False)
 

Private Attributes

 _cml_units_obj
 

Additional Inherited Members

- Public Attributes inherited from CellMLToNektar.pycml.element_base
 xml_attributes
 

Detailed Description

Specialised class for <unit> elements.

Maintains a reference to the object representing the units definition
it references, provides some helpful accessor type methods, and allows
safe, easy cloning of <unit> elements.

Definition at line 3228 of file pycml.py.

Constructor & Destructor Documentation

◆ __init__()

def CellMLToNektar.pycml.cellml_unit.__init__ (   self)

Definition at line 3236 of file pycml.py.

3236  def __init__(self):
3237  element_base.__init__(self)
3238  self._cml_units_obj = None
3239  return
3240 

Member Function Documentation

◆ __eq__()

def CellMLToNektar.pycml.cellml_unit.__eq__ (   self,
  other 
)
Compare two <unit> elements.

Two <unit> elements are equal if they reference the same <units>
element, and have the same prefix, multiplier, etc.

Definition at line 3247 of file pycml.py.

References CellMLToNektar.pycml.cellml_unit._hash_tup().

Referenced by CellMLToNektar.pycml.cellml_unit.__ne__().

3247  def __eq__(self, other):
3248  """Compare two <unit> elements.
3249 
3250  Two <unit> elements are equal if they reference the same <units>
3251  element, and have the same prefix, multiplier, etc.
3252  """
3253  eq = False
3254  if isinstance(other, cellml_unit):
3255  eq = self._hash_tup() == other._hash_tup()
3256  return eq

◆ __hash__()

def CellMLToNektar.pycml.cellml_unit.__hash__ (   self)
Richer hashing function than the default based on object id.

Returns the hash of a tuple of relevant attributes.

Definition at line 3260 of file pycml.py.

References CellMLToNektar.pycml.cellml_unit._hash_tup().

3260  def __hash__(self):
3261  """Richer hashing function than the default based on object id.
3262 
3263  Returns the hash of a tuple of relevant attributes."""
3264  return hash(self._hash_tup())
3265 

◆ __ne__()

def CellMLToNektar.pycml.cellml_unit.__ne__ (   self,
  other 
)
The inverse of self.__eq__(other).

Definition at line 3257 of file pycml.py.

References CellMLToNektar.pycml.cellml_unit.__eq__().

3257  def __ne__(self, other):
3258  """The inverse of self.__eq__(other)."""
3259  return not self.__eq__(other)

◆ _hash_tup()

def CellMLToNektar.pycml.cellml_unit._hash_tup (   self)
private
Create a tuple to be used for hashing/equality tests.

Definition at line 3241 of file pycml.py.

References CellMLToNektar.pycml.cellml_unit.get_exponent(), CellMLToNektar.pycml.cellml_unit.get_multiplier(), CellMLToNektar.pycml.cellml_unit.get_offset(), and CellMLToNektar.pycml.cellml_unit.get_units_element().

Referenced by CellMLToNektar.pycml.cellml_unit.__eq__(), and CellMLToNektar.pycml.cellml_unit.__hash__().

3241  def _hash_tup(self):
3242  """Create a tuple to be used for hashing/equality tests."""
3243  return (self.get_units_element(), getattr(self, u'prefix_', ''),
3244  self.get_multiplier(), self.get_exponent(),
3245  self.get_offset())
3246 

◆ _set_units_element()

def CellMLToNektar.pycml.cellml_unit._set_units_element (   self,
  obj,
  override = False 
)
private
Set the object representing the <units> element that this <unit> element references.

Don't use unless you know what you're doing.

Definition at line 3274 of file pycml.py.

References CellMLToNektar.pycml.cellml_unit._cml_units_obj.

3274  def _set_units_element(self, obj, override=False):
3275  """
3276  Set the object representing the <units> element that this <unit> element references.
3277 
3278  Don't use unless you know what you're doing.
3279  """
3280  assert override or self._cml_units_obj is None
3281  self._cml_units_obj = obj
3282  return
3283 

◆ clone()

def CellMLToNektar.pycml.cellml_unit.clone (   self)
Clone this object.

Return a new <unit> element that has the same attributes as this
one.

Definition at line 3321 of file pycml.py.

References CellMLToNektar.pycml.cellml_unit._cml_units_obj, and CellMLToNektar.pycml.element_base.xml_attributes.

3321  def clone(self):
3322  """Clone this object.
3323 
3324  Return a new <unit> element that has the same attributes as this
3325  one.
3326  """
3327  attrs = {}
3328  for apyname, aname in self.xml_attributes.iteritems():
3329  attrs[aname] = getattr(self, apyname)
3330  new = self.xml_create_element(u'unit', NSS[u'cml'], attributes=attrs)
3331  if self._cml_units_obj:
3332  new._set_units_element(self._cml_units_obj)
3333  new.xml_parent = self.xml_parent
3334  return new
3335 
3336 

◆ get_exponent()

def CellMLToNektar.pycml.cellml_unit.get_exponent (   self)
Return the exponent of this units reference, as a float.

Definition at line 3313 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_unit._hash_tup(), and CellMLToNektar.pycml.cellml_unit.get_multiplicative_factor().

3313  def get_exponent(self):
3314  """Return the exponent of this units reference, as a float."""
3315  return float(getattr(self, u'exponent', 1))
3316 

◆ get_multiplicative_factor()

def CellMLToNektar.pycml.cellml_unit.get_multiplicative_factor (   self)
Return the factor this units reference is multiplied by.

Return the quantity m.p^e as a floating point number, where:
  m is the multiplier (default value 1.0)
  p is the multiplicative factor due to the prefix (default 10^0=1)
  e is the exponent (default 1)

Definition at line 3291 of file pycml.py.

References CellMLToNektar.pycml.cellml_unit.get_exponent(), CellMLToNektar.pycml.cellml_unit.get_multiplier(), and CellMLToNektar.pycml.cellml_unit.SI_PREFIXES.

3291  def get_multiplicative_factor(self):
3292  """Return the factor this units reference is multiplied by.
3293 
3294  Return the quantity m.p^e as a floating point number, where:
3295  m is the multiplier (default value 1.0)
3296  p is the multiplicative factor due to the prefix (default 10^0=1)
3297  e is the exponent (default 1)
3298  """
3299  m = self.get_multiplier()
3300  e = self.get_exponent()
3301  p = getattr(self, u'prefix_', 0) # Since prefix is a method :(
3302  if p in self.SI_PREFIXES:
3303  p = self.SI_PREFIXES[p]
3304  else:
3305  p = int(p) # RELAX NG schema says it's an integer
3306  p = 10**p
3307  return m * (p**e)
3308 
def get_multiplicative_factor(self)
Definition: pycml.py:2876

◆ get_multiplier()

def CellMLToNektar.pycml.cellml_unit.get_multiplier (   self)
Return the multiplier of this units reference, as a float.

Definition at line 3309 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_unit._hash_tup(), and CellMLToNektar.pycml.cellml_unit.get_multiplicative_factor().

3309  def get_multiplier(self):
3310  """Return the multiplier of this units reference, as a float."""
3311  return float(getattr(self, u'multiplier', 1))
3312 
def get_multiplier(self)
Definition: pycml.py:2888

◆ get_offset()

def CellMLToNektar.pycml.cellml_unit.get_offset (   self)
Return the offset of this units reference, as a float.

Definition at line 3317 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_unit._hash_tup().

3317  def get_offset(self):
3318  """Return the offset of this units reference, as a float."""
3319  return float(getattr(self, u'offset', 0))
3320 
def get_offset(self)
Definition: pycml.py:2899

◆ get_units_element()

def CellMLToNektar.pycml.cellml_unit.get_units_element (   self)
Return the object representing the <units> element that this <unit> element references.

Definition at line 3266 of file pycml.py.

References CellMLToNektar.pycml.cellml_unit._cml_units_obj, and CellMLToNektar.pycml.get_units_by_name().

Referenced by CellMLToNektar.pycml.cellml_unit._hash_tup().

3266  def get_units_element(self):
3267  """
3268  Return the object representing the <units> element that this <unit> element references.
3269  """
3270  if self._cml_units_obj is None:
3271  # Chase the reference and cache it
3272  self._cml_units_obj = self.xml_parent.get_units_by_name(self.units)
3273  return self._cml_units_obj
def get_units_by_name(self, uname)
Definition: pycml.py:2725

Member Data Documentation

◆ _cml_units_obj

CellMLToNektar.pycml.cellml_unit._cml_units_obj
private

◆ SI_PREFIXES

dictionary CellMLToNektar.pycml.cellml_unit.SI_PREFIXES
static
Initial value:
= {"yotta": 24, "zetta": 21, "exa": 18, "peta": 15,
"tera": 12, "giga": 9, "mega": 6, "kilo": 3,
"hecto": 2, "deka": 1,
"deci": -1, "centi": -2,
"milli": -3, "micro": -6, "nano": -9, "pico": -12,
"femto": -15, "atto": -18, "zepto": -21, "yocto": -24}

Definition at line 3284 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_unit.get_multiplicative_factor().