Nektar++
Private Member Functions | List of all members
CellMLToNektar.pycml.mathml_units_mixin_choose_nearest Class Reference
Inheritance diagram for CellMLToNektar.pycml.mathml_units_mixin_choose_nearest:
[legend]

Private Member Functions

def _set_in_units (self, desired_units, no_act=False)
 

Detailed Description

Definition at line 3618 of file pycml.py.

Member Function Documentation

◆ _set_in_units()

def CellMLToNektar.pycml.mathml_units_mixin_choose_nearest._set_in_units (   self,
  desired_units,
  no_act = False 
)
private
Set the units of the application of this operator.

This mixin is used for the <times> and <divide> operators.
There are 2 possible strategies here.  One is to pick one of the
operands and convert it so that the overall units match those
required.  The other is to pick units from the set of those
possible for this application, and convert the result to the
desired units.  We go with the latter option, picking the units
that are least in the sense that they have the least multipicative
factor, but where possible that factor is no less than that on the
desired units.

Definition at line 3619 of file pycml.py.

3619 def _set_in_units(self, desired_units, no_act=False):
3620 """Set the units of the application of this operator.
3621
3622 This mixin is used for the <times> and <divide> operators.
3623 There are 2 possible strategies here. One is to pick one of the
3624 operands and convert it so that the overall units match those
3625 required. The other is to pick units from the set of those
3626 possible for this application, and convert the result to the
3627 desired units. We go with the latter option, picking the units
3628 that are least in the sense that they have the least multipicative
3629 factor, but where possible that factor is no less than that on the
3630 desired units.
3631 """
3632 app = self.xml_parent
3633 min_factor, best_factor = None, None
3634 least_units, best_units = None, None
3635 desired_factor = desired_units.expand().get_multiplicative_factor()
3636 DEBUG('validator', '>',self.localName,':',desired_factor,
3637 desired_units.description())
3638 units_set = app.get_units().get_consistent_set(desired_units)
3639 for possible_units in units_set:
3640 f = possible_units.expand().get_multiplicative_factor()
3641 if min_factor is None or f<min_factor:
3642 least_units, min_factor = possible_units, f
3643 if f >= desired_factor and (best_factor is None or f < best_factor):
3644 best_units, best_factor = possible_units, f
3645 if best_units is None:
3646 # All factors were less than that desired, so just go with the least
3647 units = least_units
3648 else:
3649 units = best_units
3650 DEBUG('validator', '\t<-',
3651 units.expand().get_multiplicative_factor(),
3652 units.description())
3653 # Add units conversion code
3654 app._add_units_conversion(app, units, desired_units, no_act)
3655 # Set the operand units
3656 for src_units_set, src_units in app.get_units()._get_sources(units):
3657 expr = src_units_set.get_expression()
3658 DEBUG('validator', '#',self.localName,':',
3659 src_units.description(),expr.localName)
3660 self._set_element_in_units(expr, src_units, no_act)
3661 # Record which units we used
3662 if not no_act:
3663 app._cml_units = units
3664 return
def get_multiplicative_factor(self)
Definition: pycml.py:2876
def DEBUG(facility, *args)
Definition: utilities.py:95

References CellMLToNektar.pycml.mathml_units_mixin._set_element_in_units(), CellMLToNektar.utilities.DEBUG(), and CellMLToNektar.pycml.get_multiplicative_factor().