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

Public Member Functions

def __init__
 
def __repr__
 
def uniquify_tuple
 
def __hash__
 
def __cmp__
 
- Public Member Functions inherited from CellMLToNektar.utilities.Colourable
def __init__
 
def set_colour
 
def get_colour
 
def clear_colour
 
- 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
 

Private Member Functions

def _hash_tuple
 

Private Attributes

 _cml_expanded
 
 _cml_simplified
 
 _cml_generated
 
 _cml_quotients
 
 _cml_hash
 
 _cml_hash_tup
 

Additional Inherited Members

- Public Attributes inherited from CellMLToNektar.pycml.element_base
 xml_attributes
 

Detailed Description

Specialised units class.
Contains useful methods for defining the standard units dictionary,
and checking for units consistency.

After being defined, a units definition should be regarded as being
immutable, as should individual <unit> elements, so the expansion
and simplification methods create new objects, which don't really
live in the document tree (they're not a child of any element in the
model), although they do have their xml_parent attribute set.

Note that <unit> elements must not be made a child of more than one
<units> element, otherwise the linked lists get tangled up.

Definition at line 2541 of file pycml.py.

Constructor & Destructor Documentation

def CellMLToNektar.pycml.cellml_units.__init__ (   self)

Definition at line 2557 of file pycml.py.

2558  def __init__(self):
2559  super(cellml_units, self).__init__()
2560  self._cml_expanded = None
2562  self._cml_generated = False
2563  self._cml_quotients = {}
2564  self._cml_hash = None
2565  return

Member Function Documentation

def CellMLToNektar.pycml.cellml_units.__cmp__ (   self,
  other 
)
Compare 2 units objects, by comparing their hashes.

Means using units as dictionary keys is more sane.

Definition at line 2607 of file pycml.py.

References CellMLToNektar.pycml.cellml_units._cml_hash_tup.

2608  def __cmp__(self, other):
2609  """Compare 2 units objects, by comparing their hashes.
2610 
2611  Means using units as dictionary keys is more sane."""
2612  if isinstance(other, cellml_units):
2613  if hash(self) == hash(other):
2614  return cmp(self._cml_hash_tup, other._cml_hash_tup)
2615  else:
2616  return cmp(hash(self), hash(other))
2617  else:
2618  return super(cellml_units, self).__cmp__(other)
2619 
# The following currently causes infinite loops/recursions
def CellMLToNektar.pycml.cellml_units.__hash__ (   self)
Generate a hash for these units.

Hashes a tuple, the first element of which is the result of self.is_base_unit(),
the second of which is our name if we are not auto-generated,
and the remaining elements of which are our <unit> elements.

Definition at line 2596 of file pycml.py.

References CellMLToNektar.pycml.cellml_units._cml_hash, and CellMLToNektar.pycml.cellml_units._hash_tuple().

2597  def __hash__(self):
2598  """Generate a hash for these units.
2599 
2600  Hashes a tuple, the first element of which is the result of self.is_base_unit(),
2601  the second of which is our name if we are not auto-generated,
2602  and the remaining elements of which are our <unit> elements.
2603  """
2604  if self._cml_hash is None:
2605  _ = self._hash_tuple
2606  return self._cml_hash
def CellMLToNektar.pycml.cellml_units.__repr__ (   self)

Definition at line 2566 of file pycml.py.

References CellMLToNektar.pycml.cellml_component.name.

2567  def __repr__(self):
2568  return '<cellml_units %s @ 0x%x>' % (self.name, id(self))
def CellMLToNektar.pycml.cellml_units._hash_tuple (   self)
private
Generate a tuple used as the basis for our hash value.

Definition at line 2570 of file pycml.py.

References CellMLToNektar.pycml.cellml_units._cml_generated, CellMLToNektar.pycml.cellml_units._cml_hash, and CellMLToNektar.pycml.cellml_component.name.

Referenced by CellMLToNektar.pycml.cellml_units.__hash__().

2571  def _hash_tuple(self):
2572  """Generate a tuple used as the basis for our hash value."""
2573  if self._cml_hash is None:
2574  hash_list = [self.is_base_unit()]
2575  if not self._cml_generated:
2576  hash_list.append(self.name)
2577  hash_list.extend(list(getattr(self, u'unit', [])))
2578  hash_tup = tuple(hash_list)
2579  self._cml_hash_tup = hash_tup
2580  self._cml_hash = hash(hash_tup)
2581  return self._cml_hash_tup
def CellMLToNektar.pycml.cellml_units.uniquify_tuple (   self)
For avoiding duplicate identical units definitions.

Based on description(cellml=True), since that is what we really want to be unique.
Also includes offset information, since that is omitted in the name given by description.

Definition at line 2583 of file pycml.py.

References Nektar::LibUtilities::CmdLineArg.description, and CellMLToNektar.pycml.UnitsSet.description().

2584  def uniquify_tuple(self):
2585  """For avoiding duplicate identical units definitions.
2586 
2587  Based on description(cellml=True), since that is what we really want to be unique.
2588  Also includes offset information, since that is omitted in the name given by description.
2589  """
2590  l = [self.description(cellml=True)]
2591  if self.is_simple():
2592  # Include offset information
2593  l.append((self.unit.get_units_element().uniquify_tuple,
2594  self.unit.get_offset()))
2595  return tuple(l)

Member Data Documentation

CellMLToNektar.pycml.cellml_units._cml_expanded
private

Definition at line 2559 of file pycml.py.

CellMLToNektar.pycml.cellml_units._cml_generated
private

Definition at line 2561 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_units._hash_tuple().

CellMLToNektar.pycml.cellml_units._cml_hash
private

Definition at line 2563 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_units.__hash__(), and CellMLToNektar.pycml.cellml_units._hash_tuple().

CellMLToNektar.pycml.cellml_units._cml_hash_tup
private

Definition at line 2578 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_units.__cmp__().

CellMLToNektar.pycml.cellml_units._cml_quotients
private

Definition at line 2562 of file pycml.py.

CellMLToNektar.pycml.cellml_units._cml_simplified
private

Definition at line 2560 of file pycml.py.