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

Public Member Functions

def __init__ (self)
 
def clear_dependency_info (self)
 
def __hash__ (self)
 
def fullname (self, cellml=False, debug=False)
 
def __str__ (self)
 
def __repr__ (self)
 
def get_component (self)
 
def model (self)
 
def get_units (self)
 
def get_dependencies (self)
 
def get_ode_dependency (self, independent_var, context=None)
 
def get_all_expr_dependencies (self)
 
def get_source_variable (self, recurse=False)
 
def get_type (self, follow_maps=False)
 
def get_usage_count (self)
 
def add_rdf_annotation (self, property, target, allow_dup=False)
 
def get_rdf_annotation (self, property)
 
def get_rdf_annotations (self, property)
 
def remove_rdf_annotations (self, property=None)
 
def set_rdf_annotation_from_boolean (self, property, is_yes)
 
def is_statically_const (self, ignore_annotations=False)
 
def set_value (self, value, ode=None, follow_maps=True)
 
def unset_values (self)
 
def get_value (self, ode=None)
 
def is_modifiable_parameter (self)
 
def set_is_modifiable_parameter (self, is_param)
 
def is_derived_quantity (self)
 
def set_is_derived_quantity (self, is_dq)
 
def is_output_variable (self)
 
def set_is_output_variable (self, is_ov)
 
def pe_keep (self)
 
def set_pe_keep (self, keep)
 
def oxmeta_name (self)
 
def set_oxmeta_name (self, name)
 
- 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)
 

Static Public Member Functions

def split_name (varname)
 
def get_variable_object (model, varname)
 
def create_new (elt, name, units, id=None, initial_value=None, interfaces={})
 

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 (self, dep)
 
def _add_ode_dependency (self, independent_var, expr)
 
def _update_ode_dependency (self, free_var, defn)
 
def _set_source_variable (self, src_var)
 
def _set_type (self, var_type, _orig=None)
 
def _used (self)
 
def _decrement_usage_count (self, follow_maps=True)
 
def _set_binding_time (self, bt, temporary=False)
 
def _unset_binding_time (self, only_temporary=False)
 
def _get_binding_time (self)
 
def _reduce (self, update_usage=False)
 

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

◆ __init__()

def CellMLToNektar.pycml.cellml_variable.__init__ (   self)

Reimplemented from CellMLToNektar.pycml.element_base.

Definition at line 1652 of file pycml.py.

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

References CellMLToNektar.pycml.cellml_variable.__init__(), CellMLToNektar.pycml.cellml_variable.clear_dependency_info(), and CellMLToNektar.pycml.mathml_apply.clear_dependency_info().

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

Member Function Documentation

◆ __hash__()

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.

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

References CellMLToNektar.pycml.cellml_variable.fullname().

◆ __repr__()

def CellMLToNektar.pycml.cellml_variable.__repr__ (   self)

Definition at line 1758 of file pycml.py.

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

References CellMLToNektar.pycml.cellml_variable.fullname().

◆ __str__()

def CellMLToNektar.pycml.cellml_variable.__str__ (   self)

Definition at line 1755 of file pycml.py.

1755 def __str__(self):
1756 return 'cellml_variable' + self.fullname()
1757

References CellMLToNektar.pycml.cellml_variable.fullname().

◆ _add_dependency()

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.

1773 def _add_dependency(self, dep):
1774 """Add a dependency of this variable.
1775
1776 This could be an expression defining it, or a variable it's mapped from.
1777 Triggers a validation error if we already have another dependency,
1778 since a variable can't be defined in more than one way.
1779 """
1780 if self._cml_depends_on:
1781 if not dep in self._cml_depends_on:
1782 # Multiple dependencies. TODO: Give more info.
1783 raise MathsError(dep, u' '.join([
1784 u'The variable',self.fullname(),
1785 u'gets its value from multiple locations.']))
1786 else:
1787 self._cml_depends_on.append(dep)
1788 return
1789

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

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

◆ _add_ode_dependency()

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.

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

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

◆ _decrement_usage_count()

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.

1947 def _decrement_usage_count(self, follow_maps=True):
1948 """Decrement our usage count."""
1949 DEBUG('partial-evaluator', "Dec usage for", self.fullname())
1950 assert self._cml_usage_count > 0
1951 self._cml_usage_count -= 1
1952 if follow_maps and self._cml_var_type == VarTypes.Mapped:
1953 self.get_source_variable()._decrement_usage_count()
1954 # Note in the model if a usage count has decreased to 1, in
1955 # order to repeat the partial evaluation loop.
1956 if self._cml_usage_count == 1:
1957 model = self.xml_parent.xml_parent
1958 model._pe_repeat = u'yes'
1959 return
1960
def DEBUG(facility, *args)
Definition: utilities.py:95

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

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

◆ _get_binding_time()

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.

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

References CellMLToNektar.pycml.cellml_variable._cml_binding_time, CellMLToNektar.pycml.mathml_apply._cml_binding_time, CellMLToNektar.pycml.mathml_piecewise._cml_binding_time, CellMLToNektar.pycml.cellml_variable._cml_depends_on, CellMLToNektar.pycml.mathml_apply._cml_depends_on, CellMLToNektar.pycml.cellml_variable._get_binding_time(), 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.cellml_variable._get_binding_time(), 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().

◆ _reduce()

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.

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

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

◆ _set_binding_time()

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.

2042 def _set_binding_time(self, bt, temporary=False):
2043 """Set the binding time of this variable.
2044
2045 Options are members of the BINDING_TIMES Enum.
2046
2047 If temporary is True, then we're temporarily overriding the normal setting,
2048 so save any existing annotation for later replacement.
2049 """
2050 #print "set bt", self, bt, temporary
2051 assert bt in BINDING_TIMES
2052 if temporary and not hasattr(self, '_cml_saved_bt'):
2053 self._cml_saved_bt = self.get_rdf_annotation(('pe:binding_time', NSS[u'pe']))
2054 self.add_rdf_annotation(('pe:binding_time', NSS[u'pe']), str(bt))
2055 self._cml_binding_time = bt
2056 return
2057

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

◆ _set_source_variable()

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.

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

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.pycml.cellml_variable.model(), CellMLToNektar.pycml.mathml.model(), and CellMLToNektar.translators.CellMLTranslator.model.

◆ _set_type()

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.

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

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

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

◆ _unset_binding_time()

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.

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

References CellMLToNektar.pycml.cellml_variable._cml_binding_time, CellMLToNektar.pycml.mathml_apply._cml_binding_time, CellMLToNektar.pycml.mathml_piecewise._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().

◆ _update_ode_dependency()

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.

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

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

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

◆ _used()

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.

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

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

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

◆ add_rdf_annotation()

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.

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

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

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

◆ clear_dependency_info()

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.

1657 def clear_dependency_info(self):
1658 """Clear the type, dependency, etc. information for this variable.
1659
1660 This allows us to re-run the type & dependency analysis for the model.
1661 """
1662 # The type of this variable is not yet known
1663 self._cml_var_type = VarTypes.Unknown
1664 self._cml_source_var = None
1665 self._cml_value = {}
1666 self._cml_binding_time = None
1667 # Dependency graph edges
1668 self._cml_depends_on = []
1669 self._cml_depends_on_ode = {}
1670 self._cml_usage_count = 0
1671 self.clear_colour()
1672

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

◆ create_new()

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.

2331 def create_new(elt, name, units, id=None, initial_value=None, interfaces={}):
2332 """Create a new <variable> element with the given name and units.
2333
2334 Optionally id, initial_value, and interfaces may also be given.
2335
2336 elt may be any existing XML element.
2337 """
2338 attrs = {(u'units', None): unicode(units),
2339 (u'name', None): unicode(name)}
2340 if id:
2341 attrs[(u'cmeta:id', NSS[u'cmeta'])] = unicode(id)
2342 if initial_value is not None and initial_value != u'':
2343 attrs[(u'initial_value', None)] = unicode(initial_value)
2344 for iface, val in interfaces.items():
2345 attrs[(iface + u'_interface', None)] = unicode(val)
2346 new_elt = elt.xml_create_element(u'variable', NSS[u'cml'], attributes=attrs)
2347 return new_elt
2348
def create_new(parent, name, bases, add_to_parent=False, standard=False)
Definition: pycml.py:2912

◆ fullname()

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.

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

References CellMLToNektar.pycml.cellml_variable.component, CellMLToNektar.pycml.mathml.component, and 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().

◆ get_all_expr_dependencies()

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.

1845 def get_all_expr_dependencies(self):
1846 """Return all expressions this variable depends on, either directly or as an ODE."""
1847 deps = filter(lambda d: isinstance(d, mathml_apply), self._cml_depends_on)
1848 deps.extend(self._cml_depends_on_ode.values())
1849 return deps
1850

References CellMLToNektar.pycml.cellml_variable._cml_depends_on, CellMLToNektar.pycml.mathml_apply._cml_depends_on, and CellMLToNektar.pycml.cellml_variable._cml_depends_on_ode.

◆ get_component()

def CellMLToNektar.pycml.cellml_variable.get_component (   self)

Definition at line 1761 of file pycml.py.

1761 def get_component(self):
1762 return self.xml_parent

◆ get_dependencies()

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.

1790 def get_dependencies(self):
1791 """
1792 Return the list of things this variable depends on.
1793 """
1794 return self._cml_depends_on
1795

References CellMLToNektar.pycml.cellml_variable._cml_depends_on, and CellMLToNektar.pycml.mathml_apply._cml_depends_on.

◆ get_ode_dependency()

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.

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

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

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

◆ get_rdf_annotation()

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.

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

References CellMLToNektar.pycml.element_base.cmeta_id(), CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.pycml.cellml_variable.model(), CellMLToNektar.pycml.mathml.model(), and CellMLToNektar.translators.CellMLTranslator.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().

◆ get_rdf_annotations()

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.

2005 def get_rdf_annotations(self, property):
2006 """Get all RDF annotations about this variable that use the given property.
2007
2008 property must be a tuple (qname, namespace_uri).
2009
2010 Will return all annotations found with source being this variable's id,
2011 and the given property. If no annotation is found (or if the variable does
2012 not have a cmeta:id), returns the empty list
2013 """
2014 meta_id = self.cmeta_id
2015 if not meta_id:
2016 return []
2017 property = cellml_metadata.create_rdf_node(property)
2018 source = cellml_metadata.create_rdf_node(fragment_id=meta_id)
2019 return cellml_metadata.get_targets(self.model, source, property)
2020

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

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

◆ get_source_variable()

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.

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

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

◆ get_type()

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.

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

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

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_type(), 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().

◆ get_units()

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.

1769 def get_units(self):
1770 """Get the cellml_units object giving this variable's units."""
1771 return self.component.get_units_by_name(self.units)
1772
def get_units_by_name(self, uname)
Definition: pycml.py:2725

References CellMLToNektar.pycml.cellml_variable.component, CellMLToNektar.pycml.mathml.component, and CellMLToNektar.pycml.get_units_by_name().

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

◆ get_usage_count()

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.

1941 def get_usage_count(self):
1942 """
1943 Return the number of times this variable is used in an expression.
1944 """
1945 return self._cml_usage_count
1946

References CellMLToNektar.pycml.cellml_variable._cml_usage_count.

◆ get_value()

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.

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

References CellMLToNektar.pycml.cellml_variable._cml_depends_on, CellMLToNektar.pycml.mathml_apply._cml_depends_on, CellMLToNektar.pycml.cellml_variable._cml_value, CellMLToNektar.pycml.cellml_variable._get_binding_time(), CellMLToNektar.pycml.mathml_cn._get_binding_time(), CellMLToNektar.pycml.mathml_ci._get_binding_time(), CellMLToNektar.pycml.mathml_piecewise._get_binding_time(), CellMLToNektar.pycml.mathml_diff._get_binding_time(), CellMLToNektar.pycml.mathml_and._get_binding_time(), CellMLToNektar.pycml.mathml_or._get_binding_time(), CellMLToNektar.pycml.mathml_eq._get_binding_time(), CellMLToNektar.pycml.mathml_apply._get_binding_time(), CellMLToNektar.pycml.cellml_variable.fullname(), CellMLToNektar.pycml.cellml_variable.get_source_variable(), CellMLToNektar.pycml.cellml_variable.get_type(), CellMLToNektar.pycml.cellml_variable.get_value(), CellMLToNektar.pycml.cellml_variable.initial_value, and CellMLToNektar.pycml.cellml_variable.set_value().

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

◆ get_variable_object()

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.

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

◆ is_derived_quantity()

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.

2216 def is_derived_quantity(self):
2217 """Whether this variable should be included in reports of derived quantities."""
2218 return self.get_rdf_annotation(('pycml:derived-quantity', NSS['pycml'])) == 'yes'

References CellMLToNektar.pycml.cellml_variable.get_rdf_annotation().

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

◆ is_modifiable_parameter()

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.

2202 def is_modifiable_parameter(self):
2203 """Whether this variable is a parameter that should be modifiable at run-time."""
2204 return (self.get_type() == VarTypes.Constant and
2205 self.get_rdf_annotation(('pycml:modifiable-parameter', NSS['pycml'])) == 'yes')

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

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

◆ is_output_variable()

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.

2227 def is_output_variable(self):
2228 """Whether a protocol has requested this variable as a model output."""
2229 return self.get_rdf_annotation(('pycml:output-variable', NSS['pycml'])) == 'yes'

References CellMLToNektar.pycml.cellml_variable.get_rdf_annotation().

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

◆ is_statically_const()

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.

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

References CellMLToNektar.pycml.cellml_variable._get_binding_time(), CellMLToNektar.pycml.mathml_cn._get_binding_time(), CellMLToNektar.pycml.mathml_ci._get_binding_time(), CellMLToNektar.pycml.mathml_piecewise._get_binding_time(), CellMLToNektar.pycml.mathml_diff._get_binding_time(), CellMLToNektar.pycml.mathml_and._get_binding_time(), CellMLToNektar.pycml.mathml_or._get_binding_time(), CellMLToNektar.pycml.mathml_eq._get_binding_time(), CellMLToNektar.pycml.mathml_apply._get_binding_time(), CellMLToNektar.pycml.cellml_variable.get_source_variable(), CellMLToNektar.pycml.cellml_variable.get_type(), CellMLToNektar.pycml.cellml_variable.is_statically_const(), CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.pycml.cellml_variable.model(), CellMLToNektar.pycml.mathml.model(), and CellMLToNektar.translators.CellMLTranslator.model.

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

◆ model()

def CellMLToNektar.pycml.cellml_variable.model (   self)

Definition at line 1766 of file pycml.py.

1766 def model(self):
1767 return self.component.xml_parent
1768
def model(self)
Definition: pycml.py:2654

References CellMLToNektar.pycml.cellml_variable.component, and CellMLToNektar.pycml.mathml.component.

Referenced by CellMLToNektar.processors.InterfaceGenerator._add_all_odes_to_interface(), CellMLToNektar.processors.ModelModifier._clear_model_caches(), CellMLToNektar.processors.ModelModifier._create_connection_element(), CellMLToNektar.processors.ModelModifier._find_connection_element(), CellMLToNektar.processors.ModelModifier._find_or_create_variable(), CellMLToNektar.processors.ModelModifier._process_operator(), CellMLToNektar.pycml.reduce_commutative_nary._reduce(), CellMLToNektar.pycml.mathml_power._reduce(), CellMLToNektar.pycml.mathml_piecewise._set_in_units(), CellMLToNektar.pycml.cellml_variable._set_source_variable(), CellMLToNektar.processors.InterfaceGenerator._split_ode(), CellMLToNektar.processors.InterfaceGenerator._transform_derivatives_on_rhs(), CellMLToNektar.processors.ModelModifier._update_connections(), CellMLToNektar.processors.UnitsConverter.add_all_conversions(), CellMLToNektar.processors.UnitsConverter.add_conversions_for_component(), CellMLToNektar.processors.ModelModifier.add_expr_to_comp(), CellMLToNektar.processors.InterfaceGenerator.add_output_function(), CellMLToNektar.pycml.cellml_variable.add_rdf_annotation(), CellMLToNektar.processors.ModelModifier.add_units(), CellMLToNektar.processors.ModelModifier.add_variable(), CellMLToNektar.translators.CellMLTranslator.calculate_extended_dependencies(), CellMLToNektar.pycml.mathml_apply.classify_variables(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.processors.ModelModifier.connect_variables(), CellMLToNektar.processors.UnitsConverter.convert_assignments(), CellMLToNektar.processors.UnitsConverter.convert_connections(), CellMLToNektar.processors.UnitsConverter.convert_constant(), CellMLToNektar.processors.UnitsConverter.convert_mapping(), CellMLToNektar.processors.ModelModifier.create_new_component(), CellMLToNektar.processors.ModelModifier.finalize(), CellMLToNektar.pycml.mathml.get_component(), CellMLToNektar.processors.InterfaceGenerator.get_interface_component(), CellMLToNektar.pycml.cellml_variable.get_rdf_annotation(), CellMLToNektar.pycml.cellml_variable.get_rdf_annotations(), CellMLToNektar.pycml.mathml_apply.get_units(), CellMLToNektar.pycml.mathml_piecewise.get_units(), CellMLToNektar.pycml.cellml_variable.is_statically_const(), CellMLToNektar.processors.InterfaceGenerator.make_var_computed_constant(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_default_stimulus(), CellMLToNektar.translators.CellMLTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_includes(), CellMLToNektar.translators.CellMLTranslator.output_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_model_attributes(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_top_boilerplate(), CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_verify_state_variables(), CellMLToNektar.processors.ModelModifier.remove_connections(), CellMLToNektar.pycml.cellml_variable.remove_rdf_annotations(), CellMLToNektar.translators.CellMLTranslator.var_display_name(), and CellMLToNektar.translators.CellMLTranslator.varobj().

◆ oxmeta_name()

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.

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

References CellMLToNektar.pycml.cellml_variable.get_rdf_annotations().

◆ pe_keep()

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.

2238 def pe_keep(self):
2239 """Whether PE should retain this variable in the specialised model."""
2240 return (self.get_rdf_annotation(('pe:keep', NSS[u'pe'])) == 'yes' or
2241 self.is_modifiable_parameter or
2242 self.is_derived_quantity or
2243 self.is_output_variable)

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

◆ remove_rdf_annotations()

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.

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

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

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

◆ set_is_derived_quantity()

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.

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

References CellMLToNektar.pycml.cellml_variable.set_rdf_annotation_from_boolean().

◆ set_is_modifiable_parameter()

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.

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

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

◆ set_is_output_variable()

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.

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

References CellMLToNektar.pycml.cellml_variable.set_rdf_annotation_from_boolean().

◆ set_oxmeta_name()

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.

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

References CellMLToNektar.pycml.cellml_variable.add_rdf_annotation().

◆ set_pe_keep()

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.

2244 def set_pe_keep(self, keep):
2245 """Set method for the pe_keep property.
2246
2247 We need a separate method for this to bypass Amara's property setting checks.
2248 """
2249 self.set_rdf_annotation_from_boolean(('pe:keep', NSS[u'pe']), keep)
2250

References CellMLToNektar.pycml.cellml_variable.set_rdf_annotation_from_boolean().

◆ set_rdf_annotation_from_boolean()

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.

2034 def set_rdf_annotation_from_boolean(self, property, is_yes):
2035 """Set an RDF annotation as 'yes' or 'no' depending on a boolean value."""
2036 if is_yes:
2037 val = 'yes'
2038 else:
2039 val = 'no'
2040 self.add_rdf_annotation(property, val)
2041

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

◆ set_value()

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.

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

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

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

◆ split_name()

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.

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

◆ unset_values()

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.

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

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

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

Member Data Documentation

◆ _cml_binding_time

CellMLToNektar.pycml.cellml_variable._cml_binding_time
private

◆ _cml_depends_on

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

◆ _cml_depends_on_ode

CellMLToNektar.pycml.cellml_variable._cml_depends_on_ode
private

◆ _cml_saved_bt

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

◆ _cml_source_var

CellMLToNektar.pycml.cellml_variable._cml_source_var
private

◆ _cml_usage_count

CellMLToNektar.pycml.cellml_variable._cml_usage_count
private

◆ _cml_value

CellMLToNektar.pycml.cellml_variable._cml_value
private

◆ _cml_var_type

CellMLToNektar.pycml.cellml_variable._cml_var_type
private

◆ initial_value

CellMLToNektar.pycml.cellml_variable.initial_value

Definition at line 2290 of file pycml.py.

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

Property Documentation

◆ component

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