Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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:
Inheritance graph
[legend]
Collaboration diagram for CellMLToNektar.pycml.cellml_unit:
Collaboration graph
[legend]

Public Member Functions

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

dictionary SI_PREFIXES
 

Private Member Functions

def _hash_tup
 
def _set_units_element
 

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

def CellMLToNektar.pycml.cellml_unit.__init__ (   self)

Definition at line 3236 of file pycml.py.

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

Member Function Documentation

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

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

3261  def __hash__(self):
3262  """Richer hashing function than the default based on object id.
3263 
3264  Returns the hash of a tuple of relevant attributes."""
3265  return hash(self._hash_tup())
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__().

3258  def __ne__(self, other):
3259  """The inverse of self.__eq__(other)."""
return not self.__eq__(other)
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__().

3242  def _hash_tup(self):
3243  """Create a tuple to be used for hashing/equality tests."""
3244  return (self.get_units_element(), getattr(self, u'prefix_', ''),
3245  self.get_multiplier(), self.get_exponent(),
3246  self.get_offset())
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.

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

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

3314  def get_exponent(self):
3315  """Return the exponent of this units reference, as a float."""
3316  return float(getattr(self, u'exponent', 1))
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.

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

3310  def get_multiplier(self):
3311  """Return the multiplier of this units reference, as a float."""
3312  return float(getattr(self, u'multiplier', 1))
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().

3318  def get_offset(self):
3319  """Return the offset of this units reference, as a float."""
3320  return float(getattr(self, u'offset', 0))
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.

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

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

Member Data Documentation

CellMLToNektar.pycml.cellml_unit._cml_units_obj
private

Definition at line 3238 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_unit._set_units_element(), CellMLToNektar.pycml.cellml_unit.clone(), and CellMLToNektar.pycml.cellml_unit.get_units_element().

dictionary CellMLToNektar.pycml.cellml_unit.SI_PREFIXES
static
Initial value:
1 = {"yotta": 24, "zetta": 21, "exa": 18, "peta": 15,
2  "tera": 12, "giga": 9, "mega": 6, "kilo": 3,
3  "hecto": 2, "deka": 1,
4  "deci": -1, "centi": -2,
5  "milli": -3, "micro": -6, "nano": -9, "pico": -12,
6  "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().