Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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:
Inheritance graph
[legend]
Collaboration diagram for CellMLToNektar.pycml.mathml_units_mixin_choose_nearest:
Collaboration graph
[legend]

Private Member Functions

def _set_in_units
 

Detailed Description

Definition at line 3618 of file pycml.py.

Member Function Documentation

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.

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

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