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

Public Member Functions

def __init__
 
def ignore_component_name
 
def parent
 
def get_units_by_name
 
def add_units
 
def get_all_units
 
def get_variable_by_name
 
- 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 Member Functions

def create_new
 

Public Attributes

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

Private Member Functions

def _clear_hierarchy
 
def _set_parent_component
 
def _add_child_component
 
def _has_child_components
 
def _build_units_dictionary
 
def _add_variable
 
def _del_variable
 

Private Attributes

 _cml_parents
 
 _cml_children
 
 _cml_units
 
 _cml_created_by_pe
 

Detailed Description

Specialised component class, with additional helper methods.

Definition at line 1509 of file pycml.py.

Constructor & Destructor Documentation

def CellMLToNektar.pycml.cellml_component.__init__ (   self)

Member Function Documentation

def CellMLToNektar.pycml.cellml_component._add_child_component (   self,
  reln_key,
  child 
)
private
Add child to our list of children in the relationship hierarchy indexed by reln_key.

Definition at line 1566 of file pycml.py.

References CellMLToNektar.pycml.cellml_component._cml_children.

1567  def _add_child_component(self, reln_key, child):
1568  """Add child to our list of children in the relationship hierarchy indexed by reln_key."""
1569  if not reln_key in self._cml_children:
1570  self._cml_children[reln_key] = []
1571  self._cml_children[reln_key].append(child)
def CellMLToNektar.pycml.cellml_component._add_variable (   self,
  var 
)
private
Add a variable to this component.

Definition at line 1622 of file pycml.py.

References CellMLToNektar.pycml.cellml_component.name.

1623  def _add_variable(self, var):
1624  """Add a variable to this component."""
1625  # Add element
1626  self.xml_append(var)
1627  # Add to dictionary
1628  self.xml_parent._add_variable(var, var.name, self.name)
return
def CellMLToNektar.pycml.cellml_component._build_units_dictionary (   self)
private
Create a dictionary mapping units names to objects, for all units definitions in this element.

Definition at line 1577 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._cml_units, CellMLToNektar.pycml.cellml_component._cml_units, CellMLToNektar.pycml.cellml_component.name, and CellMLToNektar.pycml.cellml_model.validation_error().

Referenced by CellMLToNektar.pycml.cellml_component.add_units(), CellMLToNektar.pycml.cellml_component.get_all_units(), and CellMLToNektar.pycml.cellml_component.get_units_by_name().

1578  def _build_units_dictionary(self):
1579  """Create a dictionary mapping units names to objects, for all units definitions in this element."""
1580  self._cml_units = {}
1581  for units in getattr(self, u'units', []):
1582  if units.name in self._cml_units:
1583  self.validation_error("Units names must be unique within the parent component (5.4.1.2)."
1584  " The name '%s' in component '%s' is duplicated."
1585  % (units.name, self.name))
1586  try:
1587  if self.xml_parent.get_units_by_name(units.name).standard == u'yes':
1588  self.validation_error("Units definitions must not redefine the standard units (5.4.1.2)."
1589  " The name '%s' in component '%s' is not allowed."
1590  % (units.name, self.name))
1591  except:
1592  pass
1593  self._cml_units[units.name] = units
self.xml_parent._add_units_obj(units)
def CellMLToNektar.pycml.cellml_component._clear_hierarchy (   self,
  reln_key 
)
private
Unset our parent & children in the given hierarchy.

Definition at line 1546 of file pycml.py.

References CellMLToNektar.pycml.cellml_component._cml_children, and CellMLToNektar.pycml.cellml_component._cml_parents.

1547  def _clear_hierarchy(self, reln_key):
1548  """Unset our parent & children in the given hierarchy."""
1549  self._cml_parents[reln_key] = None
1550  self._cml_children[reln_key] = []
def CellMLToNektar.pycml.cellml_component._del_variable (   self,
  var,
  keep_annotations = False 
)
private
Remove a variable from this component.

Definition at line 1629 of file pycml.py.

References CellMLToNektar.pycml.cellml_component.name.

1630  def _del_variable(self, var, keep_annotations=False):
1631  """Remove a variable from this component."""
1632  if not keep_annotations:
1633  # Remove metadata about the variable
1634  var.remove_rdf_annotations()
1635  # Remove the element
1636  self.xml_remove_child(var)
1637  # Remove from dictionary
1638  self.xml_parent._del_variable(var.name, self.name)
1639  return
def CellMLToNektar.pycml.cellml_component._has_child_components (   self,
  reln_key 
)
private
Determine whether we have any children in the given relationship hierarchy.

Definition at line 1572 of file pycml.py.

1573  def _has_child_components(self, reln_key):
1574  """Determine whether we have any children in the given relationship hierarchy."""
1575  return self._cml_children.get(reln_key, []) != []
1576 
def CellMLToNektar.pycml.cellml_component._set_parent_component (   self,
  reln_key,
  parent 
)
private
Set the parent of this component in the relationship hierarchy indexed by reln_key to parent.
Trigger a validation error if we already have a parent in this hierarchy.
Also add ourselves to parent's children.

Definition at line 1551 of file pycml.py.

References CellMLToNektar.pycml.cellml_component._cml_parents, and CellMLToNektar.pycml.cellml_component.name.

1552  def _set_parent_component(self, reln_key, parent):
1553  """Set the parent of this component in the relationship hierarchy indexed by reln_key to parent.
1554  Trigger a validation error if we already have a parent in this hierarchy.
1555  Also add ourselves to parent's children.
1556  """
1557  if not reln_key in self._cml_parents or self._cml_parents[reln_key] is None:
1558  # Only set parent if we don't already have one
1559  self._cml_parents[reln_key] = parent
1560  else:
1561  self.xml_parent.validation_error("In a given hierarchy, a component may not be a child more"
1562  " than once (6.4.3.2). Component '%s' has multiple parents."
1563  % self.name)
1564  if not parent is None:
1565  parent._add_child_component(reln_key, self)
def CellMLToNektar.pycml.cellml_component.add_units (   self,
  name,
  units 
)
Add an entry in our units dictionary for units named `name' with element object `units'.

Definition at line 1604 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._build_units_dictionary(), CellMLToNektar.pycml.cellml_component._build_units_dictionary(), CellMLToNektar.pycml.cellml_model._cml_units, and CellMLToNektar.pycml.cellml_component._cml_units.

1605  def add_units(self, name, units):
1606  """Add an entry in our units dictionary for units named `name' with element object `units'."""
1607  if self._cml_units is None:
1609  self._cml_units[name] = units
1610  self.xml_parent._add_units_obj(units)
1611  return
def CellMLToNektar.pycml.cellml_component.create_new (   elt,
  name 
)
static
Create a new component with the given name.

Definition at line 1641 of file pycml.py.

1642  def create_new(elt, name):
1643  """Create a new component with the given name."""
1644  new_comp = elt.xml_create_element(u'component', NSS[u'cml'],
1645  attributes={u'name': unicode(name)})
1646  return new_comp
1647 
def CellMLToNektar.pycml.cellml_component.get_all_units (   self)
Get a list of all units objects defined in this component.

Definition at line 1612 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._build_units_dictionary(), CellMLToNektar.pycml.cellml_component._build_units_dictionary(), CellMLToNektar.pycml.cellml_model._cml_units, and CellMLToNektar.pycml.cellml_component._cml_units.

1613  def get_all_units(self):
1614  """Get a list of all units objects defined in this component."""
1615  if self._cml_units is None:
1617  return self._cml_units.values()
def CellMLToNektar.pycml.cellml_component.get_units_by_name (   self,
  uname 
)
Return an object representing the element that defines the units named `uname'.

Definition at line 1594 of file pycml.py.

References CellMLToNektar.pycml.cellml_model._build_units_dictionary(), CellMLToNektar.pycml.cellml_component._build_units_dictionary(), CellMLToNektar.pycml.cellml_model._cml_units, and CellMLToNektar.pycml.cellml_component._cml_units.

1595  def get_units_by_name(self, uname):
1596  """Return an object representing the element that defines the units named `uname'."""
1597  if self._cml_units is None:
1599  if uname in self._cml_units:
1600  # Units are defined in this component
1601  return self._cml_units[uname]
1602  else:
1603  # Look up units in model element instead
return self.xml_parent.get_units_by_name(uname)
def CellMLToNektar.pycml.cellml_component.get_variable_by_name (   self,
  varname 
)
Return the variable object with name `varname' in this component.

Definition at line 1618 of file pycml.py.

References CellMLToNektar.pycml.cellml_component.name.

1619  def get_variable_by_name(self, varname):
1620  """Return the variable object with name `varname' in this component."""
1621  return self.xml_parent.get_variable_by_name(self.name, varname)
def CellMLToNektar.pycml.cellml_component.ignore_component_name (   self)
Whether to not include the component name in the full names of contained variables.

Definition at line 1522 of file pycml.py.

1523  def ignore_component_name(self):
1524  """Whether to not include the component name in the full names of contained variables."""
1525  return self._cml_created_by_pe or self.name == u''
1526 
def CellMLToNektar.pycml.cellml_component.parent (   self,
  relationship = u'encapsulation',
  namespace = None,
  name = None,
  reln_key = None 
)
Find the parent of this component in the given hierarchy.

We default to the encapsulation hierarchy.

relationship gives the type of the hierarchy. If it is not one
of the CellML types (i.e. encapsulation or containment) then
the namespace URI must be specified.  Multiple non-encapsulation
hierarchies of the same type can be specified by giving the name
argument.

Results are cached for efficiency.

Definition at line 1527 of file pycml.py.

References CellMLToNektar.pycml.cellml_component._cml_parents.

1528  def parent(self, relationship=u'encapsulation', namespace=None, name=None, reln_key=None):
1529  """Find the parent of this component in the given hierarchy.
1530 
1531  We default to the encapsulation hierarchy.
1532 
1533  relationship gives the type of the hierarchy. If it is not one
1534  of the CellML types (i.e. encapsulation or containment) then
1535  the namespace URI must be specified. Multiple non-encapsulation
1536  hierarchies of the same type can be specified by giving the name
1537  argument.
1538 
1539  Results are cached for efficiency.
1540  """
1541  key = reln_key or (relationship, namespace, name)
1542  if not key in self._cml_parents:
1543  assert(reln_key is None)
1544  self.xml_parent.build_component_hierarchy(relationship, namespace, name)
1545  return self._cml_parents[key]

Member Data Documentation

CellMLToNektar.pycml.cellml_component._cml_children
private

Definition at line 1517 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_component._add_child_component(), and CellMLToNektar.pycml.cellml_component._clear_hierarchy().

CellMLToNektar.pycml.cellml_component._cml_created_by_pe
private

Definition at line 1519 of file pycml.py.

CellMLToNektar.pycml.cellml_component._cml_parents
private

Definition at line 1516 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_component._clear_hierarchy(), CellMLToNektar.pycml.cellml_component._set_parent_component(), and CellMLToNektar.pycml.cellml_component.parent().

CellMLToNektar.pycml.cellml_component._cml_units
private

Definition at line 1518 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_component._build_units_dictionary(), CellMLToNektar.pycml.mathml_apply._set_in_units(), CellMLToNektar.pycml.mathml_piecewise._set_in_units(), CellMLToNektar.pycml.cellml_component.add_units(), CellMLToNektar.pycml.cellml_component.get_all_units(), CellMLToNektar.pycml.mathml_ci.get_units(), CellMLToNektar.pycml.mathml_apply.get_units(), CellMLToNektar.pycml.mathml_piecewise.get_units(), and CellMLToNektar.pycml.cellml_component.get_units_by_name().

CellMLToNektar.pycml.cellml_component.name

Definition at line 1524 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_units.__repr__(), CellMLToNektar.pycml.cellml_component._add_variable(), CellMLToNektar.pycml.cellml_component._build_units_dictionary(), CellMLToNektar.pycml.cellml_component._del_variable(), CellMLToNektar.pycml.cellml_units._hash_tuple(), CellMLToNektar.pycml.cellml_component._set_parent_component(), CellMLToNektar.pycml.cellml_variable.fullname(), and CellMLToNektar.pycml.cellml_component.get_variable_by_name().