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

Public Member Functions

def independent_variable (self)
 
def dependent_variable (self)
 
- Public Member Functions inherited from CellMLToNektar.pycml.mathml_operator
def wrong_number_of_operands (self, found, wanted)
 
- Public Member Functions inherited from CellMLToNektar.pycml.mathml
def __init__ (self)
 
def __repr__ (self)
 
def __deepcopy__ (self, memo)
 
def clone_self (self, register=False)
 
def get_original_of_clone (self)
 
def get_component (self)
 
def model (self)
 
def eval (self, elt)
 
- Public Member Functions inherited from CellMLToNektar.pycml.element_base
def __init__ (self)
 
def __delattr__ (self, key)
 
def __setattr__ (self, key, value)
 
def rootNode (self)
 
def cmeta_id (self)
 
def xml_remove_child_at (self, index=-1)
 
def xml_doc (self)
 
def xml_properties (self)
 

Static Public Member Functions

def create_new (elt, bvar, state_var, rhs)
 
- Static Public Member Functions inherited from CellMLToNektar.pycml.mathml
def clone (expr)
 

Private Member Functions

def _set_var_types (self)
 
def _get_binding_time (self)
 
def _reduce (self)
 

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

◆ _get_binding_time()

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.

5483 def _get_binding_time(self):
5484 """Return the binding time of the enclosing <apply> element.
5485
5486 This is the binding time of the expression defining this ODE.
5487 """
5488 expr = self.dependent_variable.get_ode_dependency(
5489 self.independent_variable)
5490 return expr._get_binding_time()
5491

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

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

◆ _reduce()

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.

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

◆ _set_var_types()

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.

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

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

◆ create_new()

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.

5516 def create_new(elt, bvar, state_var, rhs):
5517 """Construct an ODE expression: d(state_var)/d(bvar) = rhs."""
5518 bvar_elt = elt.xml_create_element(u'bvar', NSS[u'm'])
5519 bvar_elt.xml_append(mathml_ci.create_new(elt, bvar))
5520 diff = mathml_apply.create_new(elt, u'diff', [state_var], [bvar_elt])
5521 ode = mathml_apply.create_new(elt, u'eq', [diff, rhs])
5522 return ode
5523
def create_new(parent, name, bases, add_to_parent=False, standard=False)
Definition: pycml.py:2912

◆ dependent_variable()

def CellMLToNektar.pycml.mathml_diff.dependent_variable (   self)
Return the variable object being differentiated.

Definition at line 5431 of file pycml.py.

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

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

◆ independent_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.

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

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