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

Public Member Functions

def __init__
 
def clear_dependency_info
 
def __hash__
 
def fullname
 
def __str__
 
def __repr__
 
def get_component
 
def model
 
def get_units
 
def get_dependencies
 
def get_ode_dependency
 
def get_all_expr_dependencies
 
def get_source_variable
 
def get_type
 
def get_usage_count
 
def add_rdf_annotation
 
def get_rdf_annotation
 
def get_rdf_annotations
 
def remove_rdf_annotations
 
def set_rdf_annotation_from_boolean
 
def is_statically_const
 
def set_value
 
def unset_values
 
def get_value
 
def is_modifiable_parameter
 
def set_is_modifiable_parameter
 
def is_derived_quantity
 
def set_is_derived_quantity
 
def is_output_variable
 
def set_is_output_variable
 
def pe_keep
 
def set_pe_keep
 
def oxmeta_name
 
def set_oxmeta_name
 
- 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
 

Static Public Member Functions

def split_name
 
def get_variable_object
 
def create_new
 

Public Attributes

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

Properties

 component = property(get_component)
 

Private Member Functions

def _add_dependency
 
def _add_ode_dependency
 
def _update_ode_dependency
 
def _set_source_variable
 
def _set_type
 
def _used
 
def _decrement_usage_count
 
def _set_binding_time
 
def _unset_binding_time
 
def _get_binding_time
 
def _reduce
 

Private Attributes

 _cml_var_type
 
 _cml_source_var
 
 _cml_value
 
 _cml_binding_time
 
 _cml_depends_on
 Move the definition to this component defn._unset_cached_links() defn.xml_parent.xml_remove_child(defn) self.component.math.xml_append(defn) Schedule the LHS of the defining expression for update. More...
 
 _cml_depends_on_ode
 
 _cml_usage_count
 
 _cml_saved_bt
 

Detailed Description

Class representing CellML <variable> elements.

Definition at line 1648 of file pycml.py.

Constructor & Destructor Documentation

def CellMLToNektar.pycml.cellml_variable.__init__ (   self)

Definition at line 1652 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.clear_dependency_info().

1653  def __init__(self):
1654  super(cellml_variable, self).__init__()
1655  self.clear_dependency_info()
1656  return

Member Function Documentation

def CellMLToNektar.pycml.cellml_variable.__hash__ (   self)
Hashing function for variables.

Hash is based on hashing the full name of the variable, as
this must be unique within a model.  Unfortunately, when we do
partial evaluation, the full name changes!

TODO: do we need a hash function?

Definition at line 1673 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.fullname().

1674  def __hash__(self):
1675  """Hashing function for variables.
1676 
1677  Hash is based on hashing the full name of the variable, as
1678  this must be unique within a model. Unfortunately, when we do
1679  partial evaluation, the full name changes!
1680 
1681  TODO: do we need a hash function?
1682  """
1683  return hash(self.fullname(cellml=True))
def CellMLToNektar.pycml.cellml_variable.__repr__ (   self)

Definition at line 1758 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.fullname().

1759  def __repr__(self):
1760  return '<cellml_variable %s @ 0x%x>' % (self.fullname(), id(self))
def CellMLToNektar.pycml.cellml_variable.__str__ (   self)

Definition at line 1755 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.fullname().

1756  def __str__(self):
1757  return 'cellml_variable' + self.fullname()
def CellMLToNektar.pycml.cellml_variable._add_dependency (   self,
  dep 
)
private
Add a dependency of this variable.

This could be an expression defining it, or a variable it's mapped from.
Triggers a validation error if we already have another dependency,
since a variable can't be defined in more than one way.

Definition at line 1773 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_depends_on, and CellMLToNektar.pycml.cellml_variable.fullname().

Referenced by CellMLToNektar.pycml.cellml_variable._set_source_variable().

1774  def _add_dependency(self, dep):
1775  """Add a dependency of this variable.
1776 
1777  This could be an expression defining it, or a variable it's mapped from.
1778  Triggers a validation error if we already have another dependency,
1779  since a variable can't be defined in more than one way.
1780  """
1781  if self._cml_depends_on:
1782  if not dep in self._cml_depends_on:
1783  # Multiple dependencies. TODO: Give more info.
1784  raise MathsError(dep, u' '.join([
1785  u'The variable',self.fullname(),
1786  u'gets its value from multiple locations.']))
1787  else:
1788  self._cml_depends_on.append(dep)
1789  return
_cml_depends_on
Move the definition to this component defn._unset_cached_links() defn.xml_parent.xml_remove_child(def...
Definition: pycml.py:1668
def CellMLToNektar.pycml.cellml_variable._add_ode_dependency (   self,
  independent_var,
  expr 
)
private
Add a dependency of this variable as the dependent variable in an ODE.

independent_var is the corresponding independent variable, and expr is the
expression defining the ODE.
Triggers a validation error if the same ODE is defined by multiple expressions.

Definition at line 1796 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_depends_on_ode, and CellMLToNektar.pycml.cellml_variable.fullname().

1797  def _add_ode_dependency(self, independent_var, expr):
1798  """Add a dependency of this variable as the dependent variable in an ODE.
1799 
1800  independent_var is the corresponding independent variable, and expr is the
1801  expression defining the ODE.
1802  Triggers a validation error if the same ODE is defined by multiple expressions.
1803  """
1804  if independent_var in self._cml_depends_on_ode:
1805  if self._cml_depends_on_ode[independent_var] != expr:
1806  # Multiple definitions. TODO: Give more info.
1807  raise MathsError(expr, u''.join([
1808  u'There are multiple definitions of the ODE d',self.fullname(),
1809  u'/d',independent_var.fullname()]))
1810  else:
1811  self._cml_depends_on_ode[independent_var] = expr
1812  return
def CellMLToNektar.pycml.cellml_variable._decrement_usage_count (   self,
  follow_maps = True 
)
private
Decrement our usage count.

Definition at line 1947 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_usage_count, CellMLToNektar.pycml.cellml_variable._cml_var_type, CellMLToNektar.utilities.DEBUG(), CellMLToNektar.pycml.cellml_variable.fullname(), and CellMLToNektar.pycml.cellml_variable.get_source_variable().

1948  def _decrement_usage_count(self, follow_maps=True):
1949  """Decrement our usage count."""
1950  DEBUG('partial-evaluator', "Dec usage for", self.fullname())
1951  assert self._cml_usage_count > 0
1952  self._cml_usage_count -= 1
1953  if follow_maps and self._cml_var_type == VarTypes.Mapped:
1955  # Note in the model if a usage count has decreased to 1, in
1956  # order to repeat the partial evaluation loop.
1957  if self._cml_usage_count == 1:
1958  model = self.xml_parent.xml_parent
1959  model._pe_repeat = u'yes'
1960  return
def CellMLToNektar.pycml.cellml_variable._get_binding_time (   self)
private
Return the binding time of this variable, as a member of
the BINDING_TIMES Enum.

This method will (try to) compute & cache the binding time if
necessary.

Variables are classified based on their type:
  State, Free -> dynamic
  Constant -> static
  Mapped -> binding time of source variable
  Computed -> binding time of defining expression

Definition at line 2074 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_binding_time, CellMLToNektar.pycml.cellml_variable._cml_depends_on, CellMLToNektar.pycml.cellml_variable._set_binding_time(), CellMLToNektar.utilities.DEBUG(), CellMLToNektar.pycml.cellml_variable.fullname(), CellMLToNektar.pycml.cellml_variable.get_rdf_annotation(), CellMLToNektar.pycml.cellml_variable.get_source_variable(), CellMLToNektar.pycml.cellml_variable.get_type(), and CellMLToNektar.pycml.cellml_variable.pe_keep().

Referenced by CellMLToNektar.pycml.mathml_ci._reduce(), CellMLToNektar.pycml.mathml_apply._reduce(), CellMLToNektar.pycml.mathml_piecewise._reduce(), CellMLToNektar.pycml.cellml_variable.get_value(), and CellMLToNektar.pycml.cellml_variable.is_statically_const().

2075  def _get_binding_time(self):
2076  """Return the binding time of this variable, as a member of
2077  the BINDING_TIMES Enum.
2078 
2079  This method will (try to) compute & cache the binding time if
2080  necessary.
2081 
2082  Variables are classified based on their type:
2083  State, Free -> dynamic
2084  Constant -> static
2085  Mapped -> binding time of source variable
2086  Computed -> binding time of defining expression
2087  """
2088  if self._cml_binding_time is None:
2089  # Check for an annotation setting the BT
2090  bt_annotation = self.get_rdf_annotation(('pe:binding_time', NSS[u'pe']))
2091  if bt_annotation:
2092  bt = getattr(BINDING_TIMES, bt_annotation)
2093  DEBUG('partial-evaluator', "BT var", self.fullname(), "is annotated as", bt)
2094  elif self.pe_keep:
2095  # This variable must appear in the specialised model
2096  bt = BINDING_TIMES.dynamic
2097  DEBUG('partial-evaluator', "BT var", self.fullname(), "is kept")
2098  else:
2099  # Compute BT based on our type
2100  t = self.get_type()
2101  DEBUG('partial-evaluator', "BT var", self.fullname(), "type", str(t))
2102  if t in [VarTypes.State, VarTypes.Free, VarTypes.Unknown]:
2103  bt = BINDING_TIMES.dynamic
2104  elif t == VarTypes.Constant:
2105  bt = BINDING_TIMES.static
2106  elif t == VarTypes.Mapped:
2108  elif t == VarTypes.Computed:
2109  bt = self._cml_depends_on[0]._get_binding_time()
2110  else:
2111  raise TypeError("Unexpected variable type " + str(t) +
2112  " of variable " + self.fullname() +
2113  " in BTA.")
2114  DEBUG('partial-evaluator', "BT var", self.fullname(), "is", bt)
2115  self._set_binding_time(bt)
2116  else:
2117  bt = self._cml_binding_time
2118  return bt
_cml_depends_on
Move the definition to this component defn._unset_cached_links() defn.xml_parent.xml_remove_child(def...
Definition: pycml.py:1668
def CellMLToNektar.pycml.cellml_variable._reduce (   self,
  update_usage = False 
)
private
Reduce this dynamic variable that is being kept.

If it has a static source, then turn it into a constant.
Otherwise make it depend directly on an appropriate source:
either one of its source variables that is also being kept,
or the ultimate defining expression.

If update_usage is True then this variable is used in an equation,
so reduce the usage of any source variables it no longer depends on.

Definition at line 2272 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_var_type, CellMLToNektar.pycml.cellml_variable.get_source_variable(), and CellMLToNektar.pycml.cellml_variable.pe_keep().

2273  def _reduce(self, update_usage=False):
2274  """Reduce this dynamic variable that is being kept.
2275 
2276  If it has a static source, then turn it into a constant.
2277  Otherwise make it depend directly on an appropriate source:
2278  either one of its source variables that is also being kept,
2279  or the ultimate defining expression.
2280 
2281  If update_usage is True then this variable is used in an equation,
2282  so reduce the usage of any source variables it no longer depends on.
2283  """
2284  assert self.pe_keep
2285  src = self.get_source_variable(recurse=True)
2286  if src._get_binding_time() is BINDING_TIMES.static:
2287  # Become a constant
2288  self._cml_var_type = VarTypes.Constant
2289  # Set our value
2290  value = unicode(src.get_value())
2291  self.initial_value = value
2292  # Fix up usage counts
2293  if update_usage:
2295  # We now have no dependencies
2296  self._cml_depends_on = []
2297  self._cml_source_var = None
2298  elif self.get_type() == VarTypes.Mapped:
2299  # Manually recurse down maps to find a suitable source
2300  src = self.get_source_variable()
2301  while not src.pe_keep and src.get_type() == VarTypes.Mapped and src.get_usage_count() == 1:
2302  src = src.get_source_variable()
2303  if src.pe_keep or src.get_usage_count() > 1:
2304  # Depend directly on src
2305  self._cml_depends_on = [src]
2306  self._cml_source_var = src
2307  # Fix up usage counts
2308  if update_usage:
2309  src._used()
2311  else: # src.get_type() != VarTypes.Mapped
2312  # This variable is the only reference to the ultimate defining
2313  # expression, so become computed.
2314  self._cml_var_type = VarTypes.Computed
2315  defn = src.get_dependencies()[0]
2316  assert isinstance(defn, mathml_apply)
2317  ## Move the definition to this component
2318  #defn._unset_cached_links()
2319  #defn.xml_parent.xml_remove_child(defn)
2320  #self.component.math.xml_append(defn)
2321  # Schedule the LHS of the defining expression for update
2322  defn._cml_assigns_to = self
2323  defn._pe_process = u'retarget'
2324  # Fix up usage counts
2325  if update_usage:
2327  # Depend directly on the assignment expression
2328  self._cml_depends_on = [defn]
2329  self._cml_source_var = None
_cml_depends_on
Move the definition to this component defn._unset_cached_links() defn.xml_parent.xml_remove_child(def...
Definition: pycml.py:1668
def CellMLToNektar.pycml.cellml_variable._set_binding_time (   self,
  bt,
  temporary = False 
)
private
Set the binding time of this variable.

Options are members of the BINDING_TIMES Enum.

If temporary is True, then we're temporarily overriding the normal setting,
so save any existing annotation for later replacement.

Definition at line 2042 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_variable._get_binding_time(), and CellMLToNektar.pycml.cellml_variable._unset_binding_time().

2043  def _set_binding_time(self, bt, temporary=False):
2044  """Set the binding time of this variable.
2045 
2046  Options are members of the BINDING_TIMES Enum.
2047 
2048  If temporary is True, then we're temporarily overriding the normal setting,
2049  so save any existing annotation for later replacement.
2050  """
2051  #print "set bt", self, bt, temporary
2052  assert bt in BINDING_TIMES
2053  if temporary and not hasattr(self, '_cml_saved_bt'):
2054  self._cml_saved_bt = self.get_rdf_annotation(('pe:binding_time', NSS[u'pe']))
2055  self.add_rdf_annotation(('pe:binding_time', NSS[u'pe']), str(bt))
2056  self._cml_binding_time = bt
2057  return
def CellMLToNektar.pycml.cellml_variable._set_source_variable (   self,
  src_var 
)
private
Set this to be a mapped variable which imports its value from src_var.
A validation error is generated if we are already mapped.

Definition at line 1851 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._add_dependency(), CellMLToNektar.pycml.cellml_variable._cml_source_var, CellMLToNektar.pycml.cellml_variable._set_type(), CellMLToNektar.pycml.cellml_variable.fullname(), CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.translators.CellMLTranslator.model, and CellMLToNektar.pycml.cellml_variable.model().

1852  def _set_source_variable(self, src_var):
1853  """Set this to be a mapped variable which imports its value from src_var.
1854  A validation error is generated if we are already mapped.
1855  """
1856  if not self._cml_source_var is None:
1857  # Mapping already exists
1858  model = self.model
1859  debug = model.get_option('debug')
1860  model.validation_error(u' '.join([
1861  'A variable with interface "in" may only obtain its',
1862  'value from one location.\nBoth',
1863  self._cml_source_var.fullname(debug=debug), 'and',
1864  src_var.fullname(debug=debug), 'are exported to', self.fullname(debug=debug)]))
1865  else:
1866  self._cml_source_var = src_var
1867  self._set_type(VarTypes.Mapped)
1868  self._add_dependency(src_var)
1869  return
def CellMLToNektar.pycml.cellml_variable._set_type (   self,
  var_type,
  _orig = None 
)
private
Update the type of this variable.

The caller should check that the update makes sense.

If this variable already has type Mapped, then update the type of
our source variable, instead.

Definition at line 1894 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_usage_count, CellMLToNektar.pycml.cellml_variable._cml_var_type, and CellMLToNektar.pycml.cellml_variable.get_source_variable().

Referenced by CellMLToNektar.pycml.cellml_variable._set_source_variable().

1895  def _set_type(self, var_type, _orig=None):
1896  """Update the type of this variable.
1897 
1898  The caller should check that the update makes sense.
1899 
1900  If this variable already has type Mapped, then update the type of
1901  our source variable, instead.
1902  """
1903  # If this is becoming a state variable, increment its usage count
1904  if var_type is VarTypes.State and not self._cml_var_type is VarTypes.State:
1905  self._cml_usage_count += 1
1906  if self._cml_var_type == VarTypes.Mapped and not _orig is self:
1907  # Guard against infinite loops, since we haven't done a cyclic dependency check yet
1908  if _orig is None: _orig = self
1909  self.get_source_variable()._set_type(var_type, _orig=_orig)
1910  else:
1911  self._cml_var_type = var_type
1912  return
def CellMLToNektar.pycml.cellml_variable._unset_binding_time (   self,
  only_temporary = False 
)
private
Unset any stored binding time.

If the stored BT was a temporary setting, replace it with the original value.

Definition at line 2058 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_binding_time, CellMLToNektar.pycml.cellml_variable._cml_saved_bt, CellMLToNektar.pycml.cellml_variable._set_binding_time(), and CellMLToNektar.pycml.cellml_variable.remove_rdf_annotations().

2059  def _unset_binding_time(self, only_temporary=False):
2060  """Unset any stored binding time.
2061 
2062  If the stored BT was a temporary setting, replace it with the original value.
2063  """
2064  #print "unset bt", self, only_temporary
2065  self._cml_binding_time = None
2066  if hasattr(self, '_cml_saved_bt'):
2067  if self._cml_saved_bt:
2068  self._set_binding_time(getattr(BINDING_TIMES, self._cml_saved_bt))
2069  else:
2070  self.remove_rdf_annotations(('pe:binding_time', NSS[u'pe']))
2071  del self._cml_saved_bt
2072  elif not only_temporary:
2073  self.remove_rdf_annotations(('pe:binding_time', NSS[u'pe']))
def CellMLToNektar.pycml.cellml_variable._update_ode_dependency (   self,
  free_var,
  defn 
)
private
Update an ODE dependency due to partial evaluation.

When the PE processes the LHS of a derivative equation, it alters the independent
variable to reference its source directly.  If this new source wasn't originally
our independent variable's source (e.g. due to a units conversion expression) then
this will break lookups of the ODE via _get_ode_dependency, so we need to update
the reference.

Definition at line 1813 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_depends_on_ode, CellMLToNektar.pycml.cellml_variable.get_source_variable(), and CellMLToNektar.pycml.cellml_variable.get_type().

1814  def _update_ode_dependency(self, free_var, defn):
1815  """Update an ODE dependency due to partial evaluation.
1816 
1817  When the PE processes the LHS of a derivative equation, it alters the independent
1818  variable to reference its source directly. If this new source wasn't originally
1819  our independent variable's source (e.g. due to a units conversion expression) then
1820  this will break lookups of the ODE via _get_ode_dependency, so we need to update
1821  the reference.
1822  """
1823  if self.get_type() == VarTypes.Mapped:
1824  return self.get_source_variable()._update_ode_dependency(free_var, defn)
1825  self._cml_depends_on_ode.clear()
1826  self._cml_depends_on_ode[free_var] = defn
def CellMLToNektar.pycml.cellml_variable._used (   self)
private
Note this variable as being used in an expression.

Keep track of the usage count.
If this is a mapped variable, note its source as being used,
as well.

Note that if a variable is used in 2 branches of a conditional
then this counts as 2 uses.

Definition at line 1924 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_usage_count, CellMLToNektar.pycml.cellml_variable._cml_var_type, and CellMLToNektar.pycml.cellml_variable.get_source_variable().

1925  def _used(self):
1926  """Note this variable as being used in an expression.
1927 
1928  Keep track of the usage count.
1929  If this is a mapped variable, note its source as being used,
1930  as well.
1931 
1932  Note that if a variable is used in 2 branches of a conditional
1933  then this counts as 2 uses.
1934  """
1935  self._cml_usage_count += 1
1936  if self._cml_var_type == VarTypes.MaybeConstant:
1937  self._cml_var_type = VarTypes.Constant
1938  elif self._cml_var_type == VarTypes.Mapped:
1939  self.get_source_variable()._used()
1940  return
def CellMLToNektar.pycml.cellml_variable.add_rdf_annotation (   self,
  property,
  target,
  allow_dup = False 
)
Add an RDF annotation about this variable.

property must be a tuple (qname, namespace_uri).
target may either be a tuple as above, or a unicode string, in which
case it is interpreted as a literal RDF node.

If the variable does not already have a cmeta:id, one will be created
for it with value self.fullname(cellml=True).

The actual RDF will be added to the main RDF block in the model, which
will be created if it does not exist.  Any existing annotations of this
variable with the same property will be removed, unless allow_dup=True.

Definition at line 1961 of file pycml.py.

References CellMLToNektar.pycml.element_base.cmeta_id(), CellMLToNektar.pycml.cellml_variable.fullname(), CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.translators.CellMLTranslator.model, and CellMLToNektar.pycml.cellml_variable.model().

Referenced by CellMLToNektar.pycml.cellml_variable.set_oxmeta_name(), and CellMLToNektar.pycml.cellml_variable.set_rdf_annotation_from_boolean().

1962  def add_rdf_annotation(self, property, target, allow_dup=False):
1963  """Add an RDF annotation about this variable.
1964 
1965  property must be a tuple (qname, namespace_uri).
1966  target may either be a tuple as above, or a unicode string, in which
1967  case it is interpreted as a literal RDF node.
1968 
1969  If the variable does not already have a cmeta:id, one will be created
1970  for it with value self.fullname(cellml=True).
1971 
1972  The actual RDF will be added to the main RDF block in the model, which
1973  will be created if it does not exist. Any existing annotations of this
1974  variable with the same property will be removed, unless allow_dup=True.
1975  """
1976  meta_id = self.cmeta_id
1977  if not meta_id:
1978  # Create ID for this variable, so we can refer to it in RDF
1979  meta_id = cellml_metadata.create_unique_id(self.model, unicode(self.fullname(cellml=True)))
1980  self.xml_set_attribute((u'cmeta:id', NSS['cmeta']), meta_id)
1981  property = cellml_metadata.create_rdf_node(property)
1982  target = cellml_metadata.create_rdf_node(target)
1983  source = cellml_metadata.create_rdf_node(fragment_id=meta_id)
1984  if allow_dup:
1985  cellml_metadata.add_statement(self.model, source, property, target)
1986  else:
1987  cellml_metadata.replace_statement(self.model, source, property, target)
def CellMLToNektar.pycml.cellml_variable.clear_dependency_info (   self)
Clear the type, dependency, etc. information for this variable.

This allows us to re-run the type & dependency analysis for the model.

Definition at line 1657 of file pycml.py.

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

1658  def clear_dependency_info(self):
1659  """Clear the type, dependency, etc. information for this variable.
1660 
1661  This allows us to re-run the type & dependency analysis for the model.
1662  """
1663  # The type of this variable is not yet known
1664  self._cml_var_type = VarTypes.Unknown
1665  self._cml_source_var = None
1666  self._cml_value = {}
1667  self._cml_binding_time = None
1668  # Dependency graph edges
1671  self._cml_usage_count = 0
1672  self.clear_colour()
_cml_depends_on
Move the definition to this component defn._unset_cached_links() defn.xml_parent.xml_remove_child(def...
Definition: pycml.py:1668
def CellMLToNektar.pycml.cellml_variable.create_new (   elt,
  name,
  units,
  id = None,
  initial_value = None,
  interfaces = {} 
)
static
Create a new <variable> element with the given name and units.

Optionally id, initial_value, and interfaces may also be given.

elt may be any existing XML element.

Definition at line 2331 of file pycml.py.

2332  def create_new(elt, name, units, id=None, initial_value=None, interfaces={}):
2333  """Create a new <variable> element with the given name and units.
2334 
2335  Optionally id, initial_value, and interfaces may also be given.
2336 
2337  elt may be any existing XML element.
2338  """
2339  attrs = {(u'units', None): unicode(units),
2340  (u'name', None): unicode(name)}
2341  if id:
2342  attrs[(u'cmeta:id', NSS[u'cmeta'])] = unicode(id)
2343  if initial_value is not None and initial_value != u'':
2344  attrs[(u'initial_value', None)] = unicode(initial_value)
2345  for iface, val in interfaces.items():
2346  attrs[(iface + u'_interface', None)] = unicode(val)
2347  new_elt = elt.xml_create_element(u'variable', NSS[u'cml'], attributes=attrs)
2348  return new_elt
def CellMLToNektar.pycml.cellml_variable.fullname (   self,
  cellml = False,
  debug = False 
)
Return the full name of this variable, i.e.
'(component_name,variable_name)'.

If cellml is given as True, return the name in a form compatible with
the CellML spec instead, i.e. component_name__variable_name, unless
the component has its ignore_component_name property set, in which case
just use variable_name.

If debug is True, also give information about the variable object.

Definition at line 1684 of file pycml.py.

References CellMLToNektar.pycml.cellml_component.name.

Referenced by CellMLToNektar.pycml.cellml_variable.__hash__(), CellMLToNektar.pycml.cellml_variable.__repr__(), CellMLToNektar.pycml.cellml_variable.__str__(), CellMLToNektar.pycml.cellml_variable._add_dependency(), CellMLToNektar.pycml.cellml_variable._add_ode_dependency(), CellMLToNektar.pycml.cellml_variable._decrement_usage_count(), CellMLToNektar.pycml.cellml_variable._get_binding_time(), CellMLToNektar.pycml.cellml_variable._set_source_variable(), CellMLToNektar.pycml.cellml_variable.add_rdf_annotation(), CellMLToNektar.pycml.cellml_variable.get_ode_dependency(), CellMLToNektar.pycml.cellml_variable.get_source_variable(), CellMLToNektar.pycml.cellml_variable.get_value(), and CellMLToNektar.pycml.cellml_variable.set_is_modifiable_parameter().

1685  def fullname(self, cellml=False, debug=False):
1686  """
1687  Return the full name of this variable, i.e.
1688  '(component_name,variable_name)'.
1689 
1690  If cellml is given as True, return the name in a form compatible with
1691  the CellML spec instead, i.e. component_name__variable_name, unless
1692  the component has its ignore_component_name property set, in which case
1693  just use variable_name.
1694 
1695  If debug is True, also give information about the variable object.
1696  """
1697  if hasattr(self, 'xml_parent'):
1698  parent_name = self.xml_parent.name
1699  ignore_component = self.component.ignore_component_name
1700  else:
1701  parent_name = '*orphan*'
1702  ignore_component = True
1703  if cellml:
1704  if ignore_component:
1705  vn = self.name
1706  else:
1707  vn = parent_name + u'__' + self.name
1708  else:
1709  vn = u'(' + parent_name + u',' + self.name + u')'
1710  if debug:
1711  vn = '%s@0x%x' % (vn, id(self))
1712  return vn
def CellMLToNektar.pycml.cellml_variable.get_all_expr_dependencies (   self)
Return all expressions this variable depends on, either directly or as an ODE.

Definition at line 1845 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_depends_on.

1846  def get_all_expr_dependencies(self):
1847  """Return all expressions this variable depends on, either directly or as an ODE."""
1848  deps = filter(lambda d: isinstance(d, mathml_apply), self._cml_depends_on)
1849  deps.extend(self._cml_depends_on_ode.values())
1850  return deps
_cml_depends_on
Move the definition to this component defn._unset_cached_links() defn.xml_parent.xml_remove_child(def...
Definition: pycml.py:1668
def CellMLToNektar.pycml.cellml_variable.get_component (   self)

Definition at line 1761 of file pycml.py.

1762  def get_component(self):
return self.xml_parent
def CellMLToNektar.pycml.cellml_variable.get_dependencies (   self)
Return the list of things this variable depends on.

Definition at line 1790 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_depends_on.

1791  def get_dependencies(self):
1792  """
1793  Return the list of things this variable depends on.
1794  """
1795  return self._cml_depends_on
_cml_depends_on
Move the definition to this component defn._unset_cached_links() defn.xml_parent.xml_remove_child(def...
Definition: pycml.py:1668
def CellMLToNektar.pycml.cellml_variable.get_ode_dependency (   self,
  independent_var,
  context = None 
)
Return the expression defining the ODE giving the derivative of this
variable w.r.t. independent_var.
Triggers a validation error if the ODE has not been defined.

Definition at line 1827 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_depends_on_ode, CellMLToNektar.pycml.cellml_variable.fullname(), CellMLToNektar.pycml.cellml_variable.get_source_variable(), and CellMLToNektar.pycml.cellml_variable.get_type().

1828  def get_ode_dependency(self, independent_var, context=None):
1829  """
1830  Return the expression defining the ODE giving the derivative of this
1831  variable w.r.t. independent_var.
1832  Triggers a validation error if the ODE has not been defined.
1833  """
1834  if self.get_type() == VarTypes.Mapped:
1835  return self.get_source_variable().get_ode_dependency(independent_var, context=context)
1836  free_vars = self._cml_depends_on_ode.keys()
1837  free_vars = dict(zip(map(lambda v: v.get_source_variable(recurse=True), free_vars),
1838  free_vars))
1839  independent_src = independent_var.get_source_variable(recurse=True)
1840  if not independent_src in free_vars:
1841  raise MathsError(context or self, u''.join([
1842  u'The ODE d',self.fullname(),u'/d',independent_var.fullname(),
1843  u'is used but not defined.']))
1844  return self._cml_depends_on_ode[free_vars[independent_src]]
def CellMLToNektar.pycml.cellml_variable.get_rdf_annotation (   self,
  property 
)
Get an RDF annotation about this variable.

property must be a tuple (qname, namespace_uri).

Will return the unique annotation found with source being this variable's id,
and the given property.  If no annotation is found (or if the variable does
not have a cmeta:id), returns None.  Throws an error if more than one
annotation is found.

Definition at line 1988 of file pycml.py.

References CellMLToNektar.pycml.element_base.cmeta_id(), CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.translators.CellMLTranslator.model, and CellMLToNektar.pycml.cellml_variable.model().

Referenced by CellMLToNektar.pycml.cellml_variable._get_binding_time(), CellMLToNektar.pycml.cellml_variable.is_derived_quantity(), CellMLToNektar.pycml.cellml_variable.is_modifiable_parameter(), CellMLToNektar.pycml.cellml_variable.is_output_variable(), and CellMLToNektar.pycml.cellml_variable.pe_keep().

1989  def get_rdf_annotation(self, property):
1990  """Get an RDF annotation about this variable.
1991 
1992  property must be a tuple (qname, namespace_uri).
1993 
1994  Will return the unique annotation found with source being this variable's id,
1995  and the given property. If no annotation is found (or if the variable does
1996  not have a cmeta:id), returns None. Throws an error if more than one
1997  annotation is found.
1998  """
1999  meta_id = self.cmeta_id
2000  if not meta_id:
2001  return None
2002  property = cellml_metadata.create_rdf_node(property)
2003  source = cellml_metadata.create_rdf_node(fragment_id=meta_id)
2004  return cellml_metadata.get_target(self.model, source, property)
def CellMLToNektar.pycml.cellml_variable.get_rdf_annotations (   self,
  property 
)
Get all RDF annotations about this variable that use the given property.

property must be a tuple (qname, namespace_uri).

Will return all annotations found with source being this variable's id,
and the given property.  If no annotation is found (or if the variable does
not have a cmeta:id), returns the empty list

Definition at line 2005 of file pycml.py.

References CellMLToNektar.pycml.element_base.cmeta_id(), CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.translators.CellMLTranslator.model, and CellMLToNektar.pycml.cellml_variable.model().

Referenced by CellMLToNektar.pycml.cellml_variable.oxmeta_name().

2006  def get_rdf_annotations(self, property):
2007  """Get all RDF annotations about this variable that use the given property.
2008 
2009  property must be a tuple (qname, namespace_uri).
2010 
2011  Will return all annotations found with source being this variable's id,
2012  and the given property. If no annotation is found (or if the variable does
2013  not have a cmeta:id), returns the empty list
2014  """
2015  meta_id = self.cmeta_id
2016  if not meta_id:
2017  return []
2018  property = cellml_metadata.create_rdf_node(property)
2019  source = cellml_metadata.create_rdf_node(fragment_id=meta_id)
2020  return cellml_metadata.get_targets(self.model, source, property)
def CellMLToNektar.pycml.cellml_variable.get_source_variable (   self,
  recurse = False 
)
Assuming this variable imports its value, return the variable
from which we obtain our value.
If our value is determined within this component, raise a
TypeError.

If recurse is set to True, recursively follow mappings until
a non-mapped variable is found.

Definition at line 1870 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_source_var, and CellMLToNektar.pycml.cellml_variable.fullname().

Referenced by CellMLToNektar.pycml.cellml_variable._decrement_usage_count(), CellMLToNektar.pycml.cellml_variable._get_binding_time(), CellMLToNektar.pycml.cellml_variable._reduce(), CellMLToNektar.pycml.cellml_variable._set_type(), CellMLToNektar.pycml.cellml_variable._update_ode_dependency(), CellMLToNektar.pycml.cellml_variable._used(), CellMLToNektar.pycml.cellml_variable.get_ode_dependency(), CellMLToNektar.pycml.cellml_variable.get_type(), CellMLToNektar.pycml.cellml_variable.get_value(), CellMLToNektar.pycml.cellml_variable.is_statically_const(), CellMLToNektar.pycml.cellml_variable.set_value(), and CellMLToNektar.pycml.cellml_variable.unset_values().

1871  def get_source_variable(self, recurse=False):
1872  """
1873  Assuming this variable imports its value, return the variable
1874  from which we obtain our value.
1875  If our value is determined within this component, raise a
1876  TypeError.
1877 
1878  If recurse is set to True, recursively follow mappings until
1879  a non-mapped variable is found.
1880  """
1881  if self._cml_source_var is None:
1882  if recurse:
1883  src = self
1884  else:
1885  raise TypeError(u' '.join([
1886  'Variable', self.fullname(), u'is not a mapped variable',
1887  '(i.e. does not obtain its value from another component).'
1888  ]))
1889  else:
1890  src = self._cml_source_var
1891  if recurse:
1892  src = src.get_source_variable(recurse=True)
1893  return src
def CellMLToNektar.pycml.cellml_variable.get_type (   self,
  follow_maps = False 
)
Return the type of this variable.

If follow_maps is True and the value of this variable is imported
from another component, then return the type of the variable we
get our value from instead.

Definition at line 1913 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_var_type, and CellMLToNektar.pycml.cellml_variable.get_source_variable().

Referenced by CellMLToNektar.pycml.cellml_variable._get_binding_time(), CellMLToNektar.pycml.cellml_variable._update_ode_dependency(), CellMLToNektar.pycml.cellml_variable.get_ode_dependency(), CellMLToNektar.pycml.cellml_variable.get_value(), CellMLToNektar.pycml.cellml_variable.is_modifiable_parameter(), CellMLToNektar.pycml.cellml_variable.is_statically_const(), CellMLToNektar.pycml.cellml_variable.set_is_modifiable_parameter(), CellMLToNektar.pycml.cellml_variable.set_value(), and CellMLToNektar.pycml.cellml_variable.unset_values().

1914  def get_type(self, follow_maps=False):
1915  """Return the type of this variable.
1916 
1917  If follow_maps is True and the value of this variable is imported
1918  from another component, then return the type of the variable we
1919  get our value from instead.
1920  """
1921  if follow_maps and self._cml_var_type == VarTypes.Mapped:
1922  return self.get_source_variable().get_type(follow_maps=True)
1923  return self._cml_var_type
def CellMLToNektar.pycml.cellml_variable.get_units (   self)
Get the cellml_units object giving this variable's units.

Definition at line 1769 of file pycml.py.

Referenced by CellMLToNektar.pycml.mathml._ensure_units_exist(), CellMLToNektar.pycml.mathml_units_mixin_tokens._set_in_units(), and CellMLToNektar.pycml.mathml_apply._set_in_units().

1770  def get_units(self):
1771  """Get the cellml_units object giving this variable's units."""
1772  return self.component.get_units_by_name(self.units)
def CellMLToNektar.pycml.cellml_variable.get_usage_count (   self)
Return the number of times this variable is used in an expression.

Definition at line 1941 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_usage_count.

1942  def get_usage_count(self):
1943  """
1944  Return the number of times this variable is used in an expression.
1945  """
1946  return self._cml_usage_count
def CellMLToNektar.pycml.cellml_variable.get_value (   self,
  ode = None 
)
Return the value of this variable.

If a value has been set with set_value(), return that.
Otherwise, the behaviour depends on the type of this variable.
If it is Mapped, return the value of the source variable.
If it is Constant or State, return its initial value.
Otherwise, raise an EvaluationError.

If ode is given, it should be an instance of cellml_variable.
In this case, we're getting the value of d(self)/d(ode).

Definition at line 2171 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_depends_on, CellMLToNektar.pycml.cellml_variable._cml_value, CellMLToNektar.pycml.cellml_variable._get_binding_time(), CellMLToNektar.pycml.cellml_variable.fullname(), CellMLToNektar.pycml.cellml_variable.get_source_variable(), CellMLToNektar.pycml.cellml_variable.get_type(), and CellMLToNektar.pycml.cellml_variable.initial_value.

2172  def get_value(self, ode=None):
2173  """Return the value of this variable.
2174 
2175  If a value has been set with set_value(), return that.
2176  Otherwise, the behaviour depends on the type of this variable.
2177  If it is Mapped, return the value of the source variable.
2178  If it is Constant or State, return its initial value.
2179  Otherwise, raise an EvaluationError.
2180 
2181  If ode is given, it should be an instance of cellml_variable.
2182  In this case, we're getting the value of d(self)/d(ode).
2183  """
2184  # TODO: Might want to alter the handling of initial value for an ODE?
2185  if ode in self._cml_value:
2186  val = self._cml_value[ode]
2187  elif self.get_type() == VarTypes.Mapped:
2188  val = self.get_source_variable().get_value(ode=ode)
2189  elif ode is None and self.get_type() in [VarTypes.Unknown,
2190  VarTypes.State, VarTypes.Constant]:
2191  if hasattr(self, 'initial_value'):
2192  val = float(self.initial_value)
2193  else:
2194  raise EvaluationError("Variable " + self.fullname() + " has no initial value set.")
2195  elif self.get_type() == VarTypes.Computed and self._get_binding_time() == BINDING_TIMES.static:
2196  # Evaluate the defining expression
2197  val = self._cml_depends_on[0].evaluate()
2198  else:
2199  raise EvaluationError("Unable to find a suitable value for variable " + self.fullname())
2200  return val
_cml_depends_on
Move the definition to this component defn._unset_cached_links() defn.xml_parent.xml_remove_child(def...
Definition: pycml.py:1668
def CellMLToNektar.pycml.cellml_variable.get_variable_object (   model,
  varname 
)
static
Return the variable object that has name varname.

This method tries to handle various forms of fully qualified variable name, i.e. names which
include the name of the component the variable occurs in, including those created by
CellMLTranslator.code_name.

Definition at line 1730 of file pycml.py.

1731  def get_variable_object(model, varname):
1732  """Return the variable object that has name varname.
1733 
1734  This method tries to handle various forms of fully qualified variable name, i.e. names which
1735  include the name of the component the variable occurs in, including those created by
1736  CellMLTranslator.code_name.
1737  """
1738  varname = unicode(varname)
1739  if varname[:4] == 'var_':
1740  varname = varname[4:]
1741  cname, vname = cellml_variable.split_name(varname)
1742  if len(model.component) == 1 and cname == model.component.name:
1743  var = model.component.get_variable_by_name(vname)
1744  else:
1745  try:
1746  var = model.get_variable_by_name(cname, vname)
1747  except KeyError, e:
1748  try:
1749  if cname:
1750  vname = cname + u'__' + vname
1751  var = model.component.get_variable_by_name(vname)
1752  except KeyError:
1753  raise e
1754  return var
def CellMLToNektar.pycml.cellml_variable.is_derived_quantity (   self)
Whether this variable should be included in reports of derived quantities.

Definition at line 2216 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.get_rdf_annotation().

Referenced by CellMLToNektar.pycml.cellml_variable.pe_keep().

2217  def is_derived_quantity(self):
2218  """Whether this variable should be included in reports of derived quantities."""
return self.get_rdf_annotation(('pycml:derived-quantity', NSS['pycml'])) == 'yes'
def CellMLToNektar.pycml.cellml_variable.is_modifiable_parameter (   self)
Whether this variable is a parameter that should be modifiable at run-time.

Definition at line 2202 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.get_rdf_annotation(), and CellMLToNektar.pycml.cellml_variable.get_type().

Referenced by CellMLToNektar.pycml.cellml_variable.pe_keep().

2203  def is_modifiable_parameter(self):
2204  """Whether this variable is a parameter that should be modifiable at run-time."""
2205  return (self.get_type() == VarTypes.Constant and
self.get_rdf_annotation(('pycml:modifiable-parameter', NSS['pycml'])) == 'yes')
def CellMLToNektar.pycml.cellml_variable.is_output_variable (   self)
Whether a protocol has requested this variable as a model output.

Definition at line 2227 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.get_rdf_annotation().

Referenced by CellMLToNektar.pycml.cellml_variable.pe_keep().

2228  def is_output_variable(self):
2229  """Whether a protocol has requested this variable as a model output."""
return self.get_rdf_annotation(('pycml:output-variable', NSS['pycml'])) == 'yes'
def CellMLToNektar.pycml.cellml_variable.is_statically_const (   self,
  ignore_annotations = False 
)
Determine loosely if this variable is considered constant.

Checks if we're Constant, or Computed with a static binding time (or
of unknown type).

If ignore_annotations is True, will ignore cached binding time values and
pe:keep annotations.  It instead finds all variables we depend on, directly or
indirectly, and gives a dynamic result iff any is a state or free variable.

Definition at line 2119 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._get_binding_time(), CellMLToNektar.pycml.cellml_variable.get_source_variable(), and CellMLToNektar.pycml.cellml_variable.get_type().

2120  def is_statically_const(self, ignore_annotations=False):
2121  """Determine loosely if this variable is considered constant.
2122 
2123  Checks if we're Constant, or Computed with a static binding time (or
2124  of unknown type).
2125 
2126  If ignore_annotations is True, will ignore cached binding time values and
2127  pe:keep annotations. It instead finds all variables we depend on, directly or
2128  indirectly, and gives a dynamic result iff any is a state or free variable.
2129  """
2130  result = False
2131  t = self.get_type()
2132  if t in [VarTypes.Constant, VarTypes.Unknown]:
2133  result = True
2134  elif t == VarTypes.Computed:
2135  if ignore_annotations:
2136  dependencies = self.model.calculate_extended_dependencies([self])
2137  result = True
2138  for node in dependencies:
2139  if isinstance(node, cellml_variable) and node.get_type() in [VarTypes.State, VarTypes.Free]:
2140  result = False
2141  break
2142  else:
2143  result = self._get_binding_time() == BINDING_TIMES.static
2144  elif t == VarTypes.Mapped:
2145  result = self.get_source_variable().is_statically_const(ignore_annotations)
2146  return result
def CellMLToNektar.pycml.cellml_variable.model (   self)

Definition at line 1766 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_variable._set_source_variable(), CellMLToNektar.pycml.cellml_variable.add_rdf_annotation(), CellMLToNektar.pycml.cellml_variable.get_rdf_annotation(), CellMLToNektar.pycml.cellml_variable.get_rdf_annotations(), CellMLToNektar.pycml.mathml_apply.get_units(), and CellMLToNektar.pycml.cellml_variable.remove_rdf_annotations().

1767  def model(self):
1768  return self.component.xml_parent
def CellMLToNektar.pycml.cellml_variable.oxmeta_name (   self)
The canonical name of this variable, as given by Oxford metadata.

Returns the empty string if no annotation is given.

Definition at line 2252 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.get_rdf_annotations().

2253  def oxmeta_name(self):
2254  """The canonical name of this variable, as given by Oxford metadata.
2255 
2256  Returns the empty string if no annotation is given.
2257  """
2258  for annotation in self.get_rdf_annotations(('bqbiol:is', NSS['bqbiol'])):
2259  name = cellml_metadata.namespace_member(annotation, NSS['oxmeta'], wrong_ns_ok=True)
2260  if name:
2261  return name
2262  # No suitable annotation found
return ""
def CellMLToNektar.pycml.cellml_variable.pe_keep (   self)
Whether PE should retain this variable in the specialised model.

Definition at line 2238 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.get_rdf_annotation(), CellMLToNektar.pycml.cellml_variable.is_derived_quantity(), CellMLToNektar.pycml.cellml_variable.is_modifiable_parameter(), and CellMLToNektar.pycml.cellml_variable.is_output_variable().

Referenced by CellMLToNektar.pycml.cellml_variable._get_binding_time(), and CellMLToNektar.pycml.cellml_variable._reduce().

2239  def pe_keep(self):
2240  """Whether PE should retain this variable in the specialised model."""
2241  return (self.get_rdf_annotation(('pe:keep', NSS[u'pe'])) == 'yes' or
2242  self.is_modifiable_parameter or
2243  self.is_derived_quantity or
self.is_output_variable)
def CellMLToNektar.pycml.cellml_variable.remove_rdf_annotations (   self,
  property = None 
)
Remove all RDF annotations about this variable.

If property is given, only remove annotations with the given property.

Definition at line 2021 of file pycml.py.

References CellMLToNektar.pycml.element_base.cmeta_id(), CellMLToNektar.utilities.DEBUG(), CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.translators.CellMLTranslator.model, and CellMLToNektar.pycml.cellml_variable.model().

Referenced by CellMLToNektar.pycml.cellml_variable._unset_binding_time().

2022  def remove_rdf_annotations(self, property=None):
2023  """Remove all RDF annotations about this variable.
2024 
2025  If property is given, only remove annotations with the given property.
2026  """
2027  meta_id = self.cmeta_id
2028  if meta_id:
2029  DEBUG('cellml-metadata', "Removing RDF annotations for", self, "with id", meta_id)
2030  source = cellml_metadata.create_rdf_node(fragment_id=meta_id)
2031  if property:
2032  property = cellml_metadata.create_rdf_node(property)
2033  cellml_metadata.remove_statements(self.model, source, property, None)
def CellMLToNektar.pycml.cellml_variable.set_is_derived_quantity (   self,
  is_dq 
)
Set method for the is_derived_quantity property.

We need a separate method for this to bypass Amara's property setting checks.

Definition at line 2219 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.set_rdf_annotation_from_boolean().

2220  def set_is_derived_quantity(self, is_dq):
2221  """Set method for the is_derived_quantity property.
2222 
2223  We need a separate method for this to bypass Amara's property setting checks.
2224  """
2225  self.set_rdf_annotation_from_boolean(('pycml:derived-quantity', NSS[u'pycml']), is_dq)
def CellMLToNektar.pycml.cellml_variable.set_is_modifiable_parameter (   self,
  is_param 
)
Set method for the is_modifiable_parameter property.

We need a separate method for this to bypass Amara's property setting checks.

Definition at line 2206 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.fullname(), CellMLToNektar.pycml.cellml_variable.get_type(), and CellMLToNektar.pycml.cellml_variable.set_rdf_annotation_from_boolean().

2207  def set_is_modifiable_parameter(self, is_param):
2208  """Set method for the is_modifiable_parameter property.
2209 
2210  We need a separate method for this to bypass Amara's property setting checks.
2211  """
2212  if is_param and self.get_type() != VarTypes.Constant:
2213  raise ValueError("A non-constant variable (%s) cannot be set as a parameter" % (self.fullname(),))
2214  self.set_rdf_annotation_from_boolean(('pycml:modifiable-parameter', NSS[u'pycml']), is_param)
def CellMLToNektar.pycml.cellml_variable.set_is_output_variable (   self,
  is_ov 
)
Set method for the is_output_variable property.

We need a separate method for this to bypass Amara's property setting checks.

Definition at line 2230 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.set_rdf_annotation_from_boolean().

2231  def set_is_output_variable(self, is_ov):
2232  """Set method for the is_output_variable property.
2233 
2234  We need a separate method for this to bypass Amara's property setting checks.
2235  """
2236  self.set_rdf_annotation_from_boolean(('pycml:output-variable', NSS[u'pycml']), is_ov)
def CellMLToNektar.pycml.cellml_variable.set_oxmeta_name (   self,
  name 
)
Set method for the oxmeta_name property.

Sets a bqbiol:is RDF annotation with the name.

We need a separate method for this to bypass Amara's property setting checks.

Definition at line 2263 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.add_rdf_annotation().

2264  def set_oxmeta_name(self, name):
2265  """Set method for the oxmeta_name property.
2266 
2267  Sets a bqbiol:is RDF annotation with the name.
2268 
2269  We need a separate method for this to bypass Amara's property setting checks.
2270  """
2271  self.add_rdf_annotation(('bqbiol:is', NSS['bqbiol']), ('oxmeta:'+name, NSS['oxmeta']))
def CellMLToNektar.pycml.cellml_variable.set_pe_keep (   self,
  keep 
)
Set method for the pe_keep property.

We need a separate method for this to bypass Amara's property setting checks.

Definition at line 2244 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.set_rdf_annotation_from_boolean().

2245  def set_pe_keep(self, keep):
2246  """Set method for the pe_keep property.
2247 
2248  We need a separate method for this to bypass Amara's property setting checks.
2249  """
2250  self.set_rdf_annotation_from_boolean(('pe:keep', NSS[u'pe']), keep)
def CellMLToNektar.pycml.cellml_variable.set_rdf_annotation_from_boolean (   self,
  property,
  is_yes 
)
Set an RDF annotation as 'yes' or 'no' depending on a boolean value.

Definition at line 2034 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.add_rdf_annotation().

Referenced by CellMLToNektar.pycml.cellml_variable.set_is_derived_quantity(), CellMLToNektar.pycml.cellml_variable.set_is_modifiable_parameter(), CellMLToNektar.pycml.cellml_variable.set_is_output_variable(), and CellMLToNektar.pycml.cellml_variable.set_pe_keep().

2035  def set_rdf_annotation_from_boolean(self, property, is_yes):
2036  """Set an RDF annotation as 'yes' or 'no' depending on a boolean value."""
2037  if is_yes:
2038  val = 'yes'
2039  else:
2040  val = 'no'
2041  self.add_rdf_annotation(property, val)
def CellMLToNektar.pycml.cellml_variable.set_value (   self,
  value,
  ode = None,
  follow_maps = True 
)
Set the value of this variable.

Expects a floating point or boolean value.

If ode is given, it should be an instance of cellml_variable.
In this case, we're setting the value of d(self)/d(ode).

If this is a mapped variable, assign the value to its source
variable instead, unless follow_maps is set to False

Definition at line 2147 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable._cml_value, CellMLToNektar.pycml.cellml_variable.get_source_variable(), and CellMLToNektar.pycml.cellml_variable.get_type().

2148  def set_value(self, value, ode=None, follow_maps=True):
2149  """Set the value of this variable.
2150 
2151  Expects a floating point or boolean value.
2152 
2153  If ode is given, it should be an instance of cellml_variable.
2154  In this case, we're setting the value of d(self)/d(ode).
2155 
2156  If this is a mapped variable, assign the value to its source
2157  variable instead, unless follow_maps is set to False
2158  """
2159  #print "set_value", self, ode, value
2160  if follow_maps and self.get_type() == VarTypes.Mapped:
2161  self.get_source_variable().set_value(value, ode=ode)
2162  else:
2163  assert type(value) in [types.FloatType, types.BooleanType]
2164  self._cml_value[ode] = float(value)
return
def CellMLToNektar.pycml.cellml_variable.split_name (   varname)
static
Split a variable name as given by cellml_variable.fullname into constituent parts.

Returns a tuple (component name, local variable name).  If the component name cannot
be identified, it will be returned as the empty string.

Definition at line 1714 of file pycml.py.

1715  def split_name(varname):
1716  """Split a variable name as given by cellml_variable.fullname into constituent parts.
1717 
1718  Returns a tuple (component name, local variable name). If the component name cannot
1719  be identified, it will be returned as the empty string.
1720  """
1721  try:
1722  if varname[0] == u'(':
1723  cname, vname = varname[1:-1].split(u',')
1724  else:
1725  cname, vname = varname.split(u'__', 1)
1726  except ValueError:
1727  cname, vname = u'', varname
1728  return cname, vname
def CellMLToNektar.pycml.cellml_variable.unset_values (   self)
Unset all values for this variable set with set_value.

Definition at line 2165 of file pycml.py.

References CellMLToNektar.pycml.cellml_variable.get_source_variable(), and CellMLToNektar.pycml.cellml_variable.get_type().

2166  def unset_values(self):
2167  """Unset all values for this variable set with set_value."""
2168  #print "unset_values", self
2169  if self.get_type() == VarTypes.Mapped:
self._cml_value.clear()

Member Data Documentation

CellMLToNektar.pycml.cellml_variable._cml_binding_time
private

Definition at line 1666 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_variable._get_binding_time(), CellMLToNektar.pycml.mathml_apply._get_binding_time(), CellMLToNektar.pycml.mathml_piecewise._get_binding_time(), and CellMLToNektar.pycml.cellml_variable._unset_binding_time().

CellMLToNektar.pycml.cellml_variable._cml_depends_on
private

Move the definition to this component defn._unset_cached_links() defn.xml_parent.xml_remove_child(defn) self.component.math.xml_append(defn) Schedule the LHS of the defining expression for update.

Definition at line 1668 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_variable._add_dependency(), CellMLToNektar.pycml.cellml_variable._get_binding_time(), CellMLToNektar.pycml.cellml_variable.get_all_expr_dependencies(), CellMLToNektar.pycml.cellml_variable.get_dependencies(), CellMLToNektar.pycml.mathml_apply.get_dependencies(), and CellMLToNektar.pycml.cellml_variable.get_value().

CellMLToNektar.pycml.cellml_variable._cml_depends_on_ode
private

Definition at line 1669 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_variable._add_ode_dependency(), CellMLToNektar.pycml.cellml_variable._update_ode_dependency(), and CellMLToNektar.pycml.cellml_variable.get_ode_dependency().

CellMLToNektar.pycml.cellml_variable._cml_saved_bt
private

Definition at line 2053 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_variable._unset_binding_time().

CellMLToNektar.pycml.cellml_variable._cml_source_var
private

Definition at line 1664 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_variable._set_source_variable(), and CellMLToNektar.pycml.cellml_variable.get_source_variable().

CellMLToNektar.pycml.cellml_variable._cml_usage_count
private

Definition at line 1670 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_variable._decrement_usage_count(), CellMLToNektar.pycml.cellml_variable._set_type(), CellMLToNektar.pycml.cellml_variable._used(), and CellMLToNektar.pycml.cellml_variable.get_usage_count().

CellMLToNektar.pycml.cellml_variable._cml_value
private

Definition at line 1665 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_variable.get_value(), and CellMLToNektar.pycml.cellml_variable.set_value().

CellMLToNektar.pycml.cellml_variable._cml_var_type
private

Definition at line 1663 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_variable._decrement_usage_count(), CellMLToNektar.pycml.cellml_variable._reduce(), CellMLToNektar.pycml.cellml_variable._set_type(), CellMLToNektar.pycml.cellml_variable._used(), and CellMLToNektar.pycml.cellml_variable.get_type().

CellMLToNektar.pycml.cellml_variable.initial_value

Definition at line 2290 of file pycml.py.

Referenced by CellMLToNektar.pycml.cellml_variable.get_value().

Property Documentation

CellMLToNektar.pycml.cellml_variable.component = property(get_component)
static

Definition at line 1763 of file pycml.py.