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

Public Member Functions

def __init__ (self)
 
def __repr__ (self)
 
def uniquify_tuple (self)
 
def __hash__ (self)
 
def __cmp__ (self, other)
 
- Public Member Functions inherited from CellMLToNektar.utilities.Colourable
def __init__ (self, *args, **kwargs)
 
def set_colour (self, colour)
 
def get_colour (self)
 
def clear_colour (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)
 

Private Member Functions

def _hash_tuple (self)
 

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

◆ __init__()

def CellMLToNektar.pycml.cellml_units.__init__ (   self)

Reimplemented from CellMLToNektar.pycml.element_base.

Definition at line 2557 of file pycml.py.

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

References CellMLToNektar.pycml.cellml_units.__init__().

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

Member Function Documentation

◆ __cmp__()

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.

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

References CellMLToNektar.pycml.cellml_units.__cmp__(), and CellMLToNektar.pycml.cellml_units._cml_hash_tup.

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

◆ __hash__()

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.

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

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

◆ __repr__()

def CellMLToNektar.pycml.cellml_units.__repr__ (   self)

Definition at line 2566 of file pycml.py.

2566 def __repr__(self):
2567 return '<cellml_units %s @ 0x%x>' % (self.name, id(self))
2568

References CellMLToNektar.pycml.cellml_component.name.

◆ _hash_tuple()

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.

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

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

◆ uniquify_tuple()

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.

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

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

Member Data Documentation

◆ _cml_expanded

CellMLToNektar.pycml.cellml_units._cml_expanded
private

Definition at line 2559 of file pycml.py.

◆ _cml_generated

CellMLToNektar.pycml.cellml_units._cml_generated
private

Definition at line 2561 of file pycml.py.

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

◆ _cml_hash

CellMLToNektar.pycml.cellml_units._cml_hash
private

◆ _cml_hash_tup

CellMLToNektar.pycml.cellml_units._cml_hash_tup
private

Definition at line 2578 of file pycml.py.

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

◆ _cml_quotients

CellMLToNektar.pycml.cellml_units._cml_quotients
private

Definition at line 2562 of file pycml.py.

◆ _cml_simplified

CellMLToNektar.pycml.cellml_units._cml_simplified
private

Definition at line 2560 of file pycml.py.