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

Public Member Functions

def independent_variable
 
def dependent_variable
 
- Public Member Functions inherited from CellMLToNektar.pycml.mathml_operator
def wrong_number_of_operands
 
- Public Member Functions inherited from CellMLToNektar.pycml.mathml
def __init__
 
def __repr__
 
def __deepcopy__
 
def clone_self
 
def get_original_of_clone
 
def get_component
 
def model
 
def eval
 
- Public Member Functions inherited from CellMLToNektar.pycml.element_base
def __init__
 
def __delattr__
 
def __setattr__
 
def rootNode
 
def cmeta_id
 
def xml_remove_child_at
 
def xml_doc
 
def xml_properties
 

Static Public Member Functions

def create_new
 
- Static Public Member Functions inherited from CellMLToNektar.pycml.mathml
def clone
 

Private Member Functions

def _set_var_types
 
def _get_binding_time
 
def _reduce
 

Additional Inherited Members

- Public Attributes inherited from CellMLToNektar.pycml.element_base
 xml_attributes
 
- Properties inherited from CellMLToNektar.pycml.mathml
 component = property(get_component)
 

Detailed Description

Class representing the diff element, containing some useful methods.

Definition at line 5416 of file pycml.py.

Member Function Documentation

def CellMLToNektar.pycml.mathml_diff._get_binding_time (   self)
private
Return the binding time of the enclosing <apply> element.

This is the binding time of the expression defining this ODE.

Definition at line 5483 of file pycml.py.

References CellMLToNektar.pycml.mathml_diff.independent_variable().

5484  def _get_binding_time(self):
5485  """Return the binding time of the enclosing <apply> element.
5486 
5487  This is the binding time of the expression defining this ODE.
5488  """
5489  expr = self.dependent_variable.get_ode_dependency(
5490  self.independent_variable)
5491  return expr._get_binding_time()
def CellMLToNektar.pycml.mathml_diff._reduce (   self)
private
Reduce this expression by evaluating its static parts.

If the whole expression is static, proceed as normal for an
<apply>.  Otherwise just rename the variable references.  We
can't instantiate the definition, because there will always be
another user - external code.

This operator is special cased because we need to alter its
qualifier, but mathml_apply only considers operands.  MathML
data binding can be annoying at times!

Definition at line 5492 of file pycml.py.

5493  def _reduce(self):
5494  """Reduce this expression by evaluating its static parts.
5495 
5496  If the whole expression is static, proceed as normal for an
5497  <apply>. Otherwise just rename the variable references. We
5498  can't instantiate the definition, because there will always be
5499  another user - external code.
5500 
5501  This operator is special cased because we need to alter its
5502  qualifier, but mathml_apply only considers operands. MathML
5503  data binding can be annoying at times!
5504  """
5505  app = self.xml_parent
5506  bt = app._get_binding_time()
5507  if bt == BINDING_TIMES.static:
5508  # Evaluate this expression as normal
5509  app._reduce(check_operator=False)
5510  else:
5511  # Just update names to be canonical.
5512  for ci in [app.ci, app.bvar.ci]:
5513  ci._set_variable_obj(ci.variable.get_source_variable(recurse=True))
5514  ci._rename()
def CellMLToNektar.pycml.mathml_diff._set_var_types (   self)
private
Set the types of the dependent & independent variables: State for
the dependent variable and Free for the independent variable.
Gives a validation warning if they already have 'incompatible'
types.

Definition at line 5441 of file pycml.py.

References CellMLToNektar.pycml.mathml_diff.dependent_variable(), and CellMLToNektar.pycml.mathml_diff.independent_variable().

5442  def _set_var_types(self):
5443  """
5444  Set the types of the dependent & independent variables: State for
5445  the dependent variable and Free for the independent variable.
5446  Gives a validation warning if they already have 'incompatible'
5447  types.
5448  """
5449  dep, indep = self.dependent_variable, self.independent_variable
5450  model = self.xml_parent.model
5451 
5452  # The dependent variable should have an initial value
5453  if not dep.get_type() == VarTypes.Mapped and \
5454  not hasattr(dep, u'initial_value'):
5455  model.validation_warning(u' '.join([
5456  u'The state variable',dep.fullname(),
5457  u'does not have an initial value given.']),
5458  level=logging.WARNING_TRANSLATE_ERROR)
5459  # It doesn't make sense to compute a state variable
5460  if dep.get_type(follow_maps=True) == VarTypes.Computed:
5461  model.validation_warning(u' '.join([
5462  u'The state variable',dep.fullname(),
5463  u'is also assigned to directly.']),
5464  level=logging.WARNING_TRANSLATE_ERROR)
5465  dep._set_type(VarTypes.State)
5466 
5467  t = indep.get_type(follow_maps=True)
5468  if t != VarTypes.Free:
5469  if t != VarTypes.Unknown:
5470  if t == VarTypes.Computed:
5471  reason = u'is computed in an expression.'
5472  elif t == VarTypes.State:
5473  reason = u'is a state variable itself.'
5474  else:
5475  reason = u'has an initial value specified.'
5476  model.validation_warning(u' '.join([
5477  u'The derivative of',dep.fullname(),
5478  u'is taken with respect to',indep.fullname(),
5479  u'but the latter', reason]),
5480  level=logging.WARNING_TRANSLATE_ERROR)
5481  # TODO: Add to list of independent vars?
5482  indep._set_type(VarTypes.Free)
def CellMLToNektar.pycml.mathml_diff.create_new (   elt,
  bvar,
  state_var,
  rhs 
)
static
Construct an ODE expression: d(state_var)/d(bvar) = rhs.

Definition at line 5516 of file pycml.py.

5517  def create_new(elt, bvar, state_var, rhs):
5518  """Construct an ODE expression: d(state_var)/d(bvar) = rhs."""
5519  bvar_elt = elt.xml_create_element(u'bvar', NSS[u'm'])
5520  bvar_elt.xml_append(mathml_ci.create_new(elt, bvar))
5521  diff = mathml_apply.create_new(elt, u'diff', [state_var], [bvar_elt])
5522  ode = mathml_apply.create_new(elt, u'eq', [diff, rhs])
5523  return ode
def CellMLToNektar.pycml.mathml_diff.dependent_variable (   self)
Return the variable object being differentiated.

Definition at line 5431 of file pycml.py.

Referenced by CellMLToNektar.pycml.mathml_diff._set_var_types().

5432  def dependent_variable(self):
5433  """
5434  Return the variable object being differentiated.
5435  """
5436  apply_elt = self.xml_parent
5437  operand = apply_elt.operands().next()
5438  if not operand.localName == u'ci':
5439  raise MathsError(apply_elt, u'Derivatives of non-variables are not supported.')
5440  return operand.variable
def CellMLToNektar.pycml.mathml_diff.independent_variable (   self)
Return the variable object w.r.t which we are differentiating.

Definition at line 5419 of file pycml.py.

Referenced by CellMLToNektar.pycml.mathml_diff._get_binding_time(), and CellMLToNektar.pycml.mathml_diff._set_var_types().

5420  def independent_variable(self):
5421  """
5422  Return the variable object w.r.t which we are differentiating.
5423  """
5424  # Note that after units checking the <bvar> qualifier can be
5425  # assumed to exist.
5426  apply_elt = self.xml_parent
5427  if not hasattr(apply_elt.bvar, u'ci'):
5428  raise MathsError(apply_elt, u'Differential operator does not have a variable element as bound variable.')
5429  return apply_elt.bvar.ci.variable