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

Public Member Functions

def __init__ (self)
 
def ignore_component_name (self)
 
def parent (self, relationship=u 'encapsulation', namespace=None, name=None, reln_key=None)
 
def get_units_by_name (self, uname)
 
def add_units (self, name, units)
 
def get_all_units (self)
 
def get_variable_by_name (self, varname)
 
- 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 Member Functions

def create_new (elt, name)
 

Public Attributes

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

Private Member Functions

def _clear_hierarchy (self, reln_key)
 
def _set_parent_component (self, reln_key, parent)
 
def _add_child_component (self, reln_key, child)
 
def _has_child_components (self, reln_key)
 
def _build_units_dictionary (self)
 
def _add_variable (self, var)
 
def _del_variable (self, var, keep_annotations=False)
 

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

◆ __init__()

def CellMLToNektar.pycml.cellml_component.__init__ (   self)

Reimplemented from CellMLToNektar.pycml.element_base.

Definition at line 1514 of file pycml.py.

1514 def __init__(self):
1515 element_base.__init__(self)
1516 self._cml_parents = {}
1517 self._cml_children = {}
1518 self._cml_units = None
1519 self._cml_created_by_pe = False
1520

Member Function Documentation

◆ _add_child_component()

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.

1566 def _add_child_component(self, reln_key, child):
1567 """Add child to our list of children in the relationship hierarchy indexed by reln_key."""
1568 if not reln_key in self._cml_children:
1569 self._cml_children[reln_key] = []
1570 self._cml_children[reln_key].append(child)
1571

References CellMLToNektar.pycml.cellml_component._cml_children.

◆ _add_variable()

def CellMLToNektar.pycml.cellml_component._add_variable (   self,
  var 
)
private
Add a variable to this component.

Definition at line 1622 of file pycml.py.

1622 def _add_variable(self, var):
1623 """Add a variable to this component."""
1624 # Add element
1625 self.xml_append(var)
1626 # Add to dictionary
1627 self.xml_parent._add_variable(var, var.name, self.name)
1628 return

References CellMLToNektar.pycml.cellml_component._add_variable(), and CellMLToNektar.pycml.cellml_component.name.

Referenced by CellMLToNektar.pycml.cellml_component._add_variable().

◆ _build_units_dictionary()

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.

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

References CellMLToNektar.pycml.cellml_model._cml_units, CellMLToNektar.pycml.cellml_component._cml_units, CellMLToNektar.pycml.mathml_units_mixin_tokens._cml_units, CellMLToNektar.pycml.mathml_units_mixin_container._cml_units, CellMLToNektar.pycml.mathml_cn._cml_units, CellMLToNektar.pycml.mathml_ci._cml_units, CellMLToNektar.pycml.mathml_apply._cml_units, CellMLToNektar.pycml.mathml_piecewise._cml_units, CellMLToNektar.pycml.cellml_component.get_units_by_name(), CellMLToNektar.pycml.cellml_component.name, and CellMLToNektar.pycml.cellml_model.validation_error().

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

◆ _clear_hierarchy()

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.

1546 def _clear_hierarchy(self, reln_key):
1547 """Unset our parent & children in the given hierarchy."""
1548 self._cml_parents[reln_key] = None
1549 self._cml_children[reln_key] = []
1550

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

◆ _del_variable()

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.

1629 def _del_variable(self, var, keep_annotations=False):
1630 """Remove a variable from this component."""
1631 if not keep_annotations:
1632 # Remove metadata about the variable
1633 var.remove_rdf_annotations()
1634 # Remove the element
1635 self.xml_remove_child(var)
1636 # Remove from dictionary
1637 self.xml_parent._del_variable(var.name, self.name)
1638 return
1639

References CellMLToNektar.pycml.cellml_component._del_variable(), and CellMLToNektar.pycml.cellml_component.name.

Referenced by CellMLToNektar.pycml.cellml_component._del_variable().

◆ _has_child_components()

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.

1572 def _has_child_components(self, reln_key):
1573 """Determine whether we have any children in the given relationship hierarchy."""
1574 return self._cml_children.get(reln_key, []) != []
1575
1576

References CellMLToNektar.pycml.cellml_component._cml_children.

◆ _set_parent_component()

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.

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

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

◆ add_units()

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.

1604 def add_units(self, name, units):
1605 """Add an entry in our units dictionary for units named `name' with element object `units'."""
1606 if self._cml_units is None:
1607 self._build_units_dictionary()
1608 self._cml_units[name] = units
1609 self.xml_parent._add_units_obj(units)
1610 return
1611

References CellMLToNektar.pycml.cellml_model._build_units_dictionary(), CellMLToNektar.pycml.cellml_component._build_units_dictionary(), CellMLToNektar.pycml.cellml_model._cml_units, CellMLToNektar.pycml.cellml_component._cml_units, CellMLToNektar.pycml.mathml_units_mixin_tokens._cml_units, CellMLToNektar.pycml.mathml_units_mixin_container._cml_units, CellMLToNektar.pycml.mathml_cn._cml_units, CellMLToNektar.pycml.mathml_ci._cml_units, CellMLToNektar.pycml.mathml_apply._cml_units, and CellMLToNektar.pycml.mathml_piecewise._cml_units.

Referenced by CellMLToNektar.processors.ModelModifier.add_units(), CellMLToNektar.processors.ModelModifier.add_variable(), and CellMLToNektar.processors.UnitsConverter.convert_constant().

◆ create_new()

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.

1641 def create_new(elt, name):
1642 """Create a new component with the given name."""
1643 new_comp = elt.xml_create_element(u'component', NSS[u'cml'],
1644 attributes={u'name': unicode(name)})
1645 return new_comp
1646
1647
def create_new(parent, name, bases, add_to_parent=False, standard=False)
Definition: pycml.py:2912

◆ get_all_units()

def CellMLToNektar.pycml.cellml_component.get_all_units (   self)

◆ get_units_by_name()

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.

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

References CellMLToNektar.pycml.cellml_model._build_units_dictionary(), CellMLToNektar.pycml.cellml_component._build_units_dictionary(), CellMLToNektar.pycml.cellml_model._cml_units, CellMLToNektar.pycml.cellml_component._cml_units, CellMLToNektar.pycml.mathml_units_mixin_tokens._cml_units, CellMLToNektar.pycml.mathml_units_mixin_container._cml_units, CellMLToNektar.pycml.mathml_cn._cml_units, CellMLToNektar.pycml.mathml_ci._cml_units, CellMLToNektar.pycml.mathml_apply._cml_units, CellMLToNektar.pycml.mathml_piecewise._cml_units, and CellMLToNektar.pycml.cellml_component.get_units_by_name().

Referenced by CellMLToNektar.pycml.cellml_component._build_units_dictionary(), and CellMLToNektar.pycml.cellml_component.get_units_by_name().

◆ get_variable_by_name()

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.

1618 def get_variable_by_name(self, varname):
1619 """Return the variable object with name `varname' in this component."""
1620 return self.xml_parent.get_variable_by_name(self.name, varname)
1621

References CellMLToNektar.pycml.cellml_component.get_variable_by_name(), and CellMLToNektar.pycml.cellml_component.name.

Referenced by CellMLToNektar.pycml.cellml_model._check_connection_units(), CellMLToNektar.pycml.cellml_model._validate_connection(), and CellMLToNektar.pycml.cellml_component.get_variable_by_name().

◆ ignore_component_name()

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.

1522 def ignore_component_name(self):
1523 """Whether to not include the component name in the full names of contained variables."""
1524 return self._cml_created_by_pe or self.name == u''
1525
1526

◆ parent()

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.

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

References CellMLToNektar.pycml.cellml_component._cml_parents.

Member Data Documentation

◆ _cml_children

CellMLToNektar.pycml.cellml_component._cml_children
private

◆ _cml_created_by_pe

CellMLToNektar.pycml.cellml_component._cml_created_by_pe
private

Definition at line 1519 of file pycml.py.

◆ _cml_parents

CellMLToNektar.pycml.cellml_component._cml_parents
private

◆ _cml_units

CellMLToNektar.pycml.cellml_component._cml_units
private

◆ name

CellMLToNektar.pycml.cellml_component.name