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

Public Member Functions

def writeln_hpp
 
def translate
 
def final_configuration_hook
 
def output_includes
 
def set_access
 
def output_method_start
 
def output_derived_quantities
 
def output_serialize_method
 
def output_cell_parameters
 
def output_default_stimulus
 
def output_intracellular_calcium
 
def code_name
 
def output_top_boilerplate
 
def unsigned_v_index
 
def output_verify_state_variables
 
def output_constructor
 
def output_extra_constructor_content
 
def output_chaste_lut_methods
 
def lut_parameters
 
def output_lut_indexing_methods
 
def output_table_index_checking
 
def output_table_index_generation_code
 
def output_lut_class
 
def output_state_assignments
 
def modifier_call
 
def vector_index
 
def vector_create
 
def vector_initialise
 
def output_nonlinear_state_assignments
 
def get_stimulus_assignment
 
def output_equations
 
def output_assignment
 
def output_mathematics
 
def calculate_lookup_table_indices
 
def output_get_i_ionic
 
def output_evaluate_y_derivatives
 
def output_derivative_calculations
 
def output_backward_euler_mathematics
 
def output_rush_larsen_mathematics
 
def output_derivative_calculations_grl
 
def find_grl_partial_derivatives
 
def output_grl_compute_partial
 
def output_grl1_mathematics
 
def output_grl2_mathematics
 
def output_model_attributes
 
def output_bottom_boilerplate
 
def output_lhs
 
def output_variable
 
def output_function
 
- Public Member Functions inherited from CellMLToNektar.translators.CellMLTranslator
def register
 
def __init__
 
def error
 
def config
 
def translate
 
def final_configuration_hook
 
def output_file_name
 
def subsidiary_file_name
 
def send_main_output_to_subsidiary
 
def writeln
 
def write
 
def capture_output
 
def get_captured_output
 
def output_comment
 
def output_doxygen
 
def set_indent
 
def code_name
 
def varobj
 
def var_display_name
 
def include_guard
 
def output_top_boilerplate
 
def output_mathematics
 
def output_bottom_boilerplate
 
def output_assignment
 
def output_lhs
 
def output_variable
 
def output_expr
 
def output_number
 
def eval_number
 
def output_apply
 
def output_function
 
def output_nary_operator
 
def output_unary_operator
 
def output_binary_operator
 
def output_root
 
def output_log
 
def output_minus
 
def output_piecewise
 
def open_paren
 
def close_paren
 
def open_block
 
def close_block
 
def calculate_extended_dependencies
 Dependency related methods #. More...
 
def output_equations
 
def scan_for_lookup_tables
 Lookup table methods #. More...
 
def lut_access_code
 
def lut_parameters
 
def lut_size_calculation
 
def output_lut_generation
 
def output_lut_deletion
 
def output_lut_declarations
 
def output_lut_index_declarations
 
def output_lut_indices
 
def output_lut_methods
 
def output_single_lookup
 
def output_lut_row_lookup_methods
 
def output_lut_row_lookup_memory
 
def is_lookup_table
 
def contained_table_indices
 
def lut_factor
 
def output_table_lookup
 
def output_table_index_generation
 
def output_table_index_checking
 
def output_table_index_generation_code
 

Static Public Member Functions

def get_current_units_options
 
def add_special_conversions
 
def generate_interface
 
- Static Public Member Functions inherited from CellMLToNektar.translators.CellMLTranslator
def generate_interface
 

Public Attributes

 use_backward_euler
 
 include_serialization
 
 lt_class_name
 
 lookup_method_prefix
 
 base_class_name
 
 class_inheritance
 
 cell_parameters
 
 metadata_vars
 
 modifier_vars
 
 use_modifiers
 
 use_lookup_tables
 
 derived_quantities
 
 has_default_stimulus
 
 use_analytic_jacobian
 
 nonlinear_system_size
 
 nonlinear_system_vars
 
 taus
 
 infs
 
 alphas
 
 betas
 
 NODESET
 
 state_var_type
 
 v_index
 
 TYPE_VECTOR_REF
 
 TYPE_DOUBLE
 
 TYPE_CONST_DOUBLE
 
 jacobian_diagonal
 
- Public Attributes inherited from CellMLToNektar.translators.CellMLTranslator
 options
 
 indent_level
 
 indent_char
 
 indent_factor
 
 use_lookup_tables
 
 add_timestamp
 
 doc
 
 model
 
 class_name
 
 free_vars
 
 state_vars
 
 single_component
 
 v_variable
 
 v_variable_name
 
 v_index
 
 lookup_method_prefix
 
 row_lookup_method
 
 lt_index_uses_floor
 
 constrain_table_indices
 
 subsidiary_filename
 
 output_filename
 
 out
 
 out2
 

Static Public Attributes

 USES_SUBSIDIARY_FILE = True
 
string TYPE_VECTOR = 'std::vector<double> '
 
string TYPE_VECTOR_REF = 'std::vector<double>& '
 
list NODESET = []
 
string MEMBRANE_CAPACITANCE_NAME = u'chaste_membrane_capacitance'
 
string INTERFACE_COMPONENT_NAME = u'chaste_interface'
 
- Static Public Attributes inherited from CellMLToNektar.translators.CellMLTranslator
dictionary translators = {}
 
string STMT_END = ';'
 Various language tokens #. More...
 
string EQ_ASSIGN = ' = '
 
string COMMENT_START = '// '
 
string DOXYGEN_COMMENT_START = '//! '
 
string TYPE_DOUBLE = 'NekDouble '
 
string TYPE_VOID = 'void '
 
string TYPE_CONST_DOUBLE = 'const NekDouble '
 
string TYPE_CONST_UNSIGNED = 'const unsigned '
 
string TRUE = 'true'
 
string FALSE = 'false'
 
string PI = 'M_PI'
 
string E = 'M_E'
 
string NOT_A_NUMBER = 'NAN'
 
 USES_SUBSIDIARY_FILE = False
 
dictionary FILE_EXTENSIONS
 
dictionary function_map
 
dictionary recip_trig
 
dictionary nary_ops
 
dictionary binary_ops
 
dictionary special_roots = {2: 'sqrt', 3: 'cbrt'}
 

Private Attributes

 _last_method_access
 

Detailed Description

As CellMLTranslator, but targets more recent Chaste style.

Includes the ability to output a cell that can solve itself using
backward Euler, if the appropriate analyses have been done on the
model.  (See the -J and -j options to translate.py.)

Definition at line 21 of file CellMLToNektarTranslator.py.

Member Function Documentation

def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.add_special_conversions (   converter,
  comp 
)
static
Add special units conversions for ionic currents.

Adds conversions for the two other common conventions to/from the units expected by Chaste,
uA/cm^2.  The cases are:

1. Current in amps/farads.
   In this case we convert to uA/uF then multiply by Chaste's value
   for the membrane capacitance (in uF/cm^2).
2. Current in amps, capacitance in farads.
   We assume the cell model conceptually represents a cell, and hence
   that its membrane capacitance is supposed to represent the same
   thing as Chaste's.  Thus convert current to uA, capacitance to uF,
   and return current/capacitance * Chaste's capacitance.

comp is a component to which we should add any necessary variables, i.e. Chaste's capacitance.

Definition at line 2324 of file CellMLToNektarTranslator.py.

2325  def add_special_conversions(converter, comp):
2326  """Add special units conversions for ionic currents.
2327 
2328  Adds conversions for the two other common conventions to/from the units expected by Chaste,
2329  uA/cm^2. The cases are:
2330 
2331  1. Current in amps/farads.
2332  In this case we convert to uA/uF then multiply by Chaste's value
2333  for the membrane capacitance (in uF/cm^2).
2334  2. Current in amps, capacitance in farads.
2335  We assume the cell model conceptually represents a cell, and hence
2336  that its membrane capacitance is supposed to represent the same
2337  thing as Chaste's. Thus convert current to uA, capacitance to uF,
2338  and return current/capacitance * Chaste's capacitance.
2339 
2340  comp is a component to which we should add any necessary variables, i.e. Chaste's capacitance.
2341  """
2342  klass = CellMLToNektarTranslator
2343  model = converter.model
2344  # Variables needed by some conversions
2345  model_Cm = model.get_config('Cm_variable')
2346  uF_per_cm2 = cellml_units.create_new(model, 'uF_per_cm2',
2347  [{'units': 'farad', 'prefix': 'micro'},
2348  {'units': 'metre', 'prefix': 'centi', 'exponent': '-2'}])
2349  Chaste_Cm = converter.add_variable(comp, klass.MEMBRANE_CAPACITANCE_NAME, uF_per_cm2)
2350  model._cml_Chaste_Cm = Chaste_Cm # Record for use in code_name
2351  # Add the conversions
2352  chaste_units, microamps, A_per_F = klass.get_current_units_options(model)
2353  converter.add_special_conversion(A_per_F, chaste_units,
2354  lambda expr: converter.times_rhs_by(expr, Chaste_Cm))
2355  converter.add_special_conversion(chaste_units, A_per_F,
2356  lambda expr: converter.divide_rhs_by(expr, Chaste_Cm))
2357  if model_Cm:
2358  converter.add_special_conversion(microamps, chaste_units,
2359  lambda expr: converter.times_rhs_by(converter.divide_rhs_by(expr, model_Cm),
2360  Chaste_Cm))
2361  converter.add_special_conversion(chaste_units, microamps,
2362  lambda expr: converter.divide_rhs_by(converter.times_rhs_by(expr, model_Cm),
2363  Chaste_Cm))
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.calculate_lookup_table_indices (   self,
  nodeset,
  time_name = None 
)
Output the lookup table index calculations needed for the given equations, if tables are enabled.

If time_name is given, it may be used in exception messages for tables out of bounds.
Note that it is needed to be passed in, since GetIIonic does not know the time.

Returns the subset of nodeset used in calculating the indices.

Definition at line 1295 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.output_table_index_generation(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_lookup_tables.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations_grl(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl_compute_partial().

1296  def calculate_lookup_table_indices(self, nodeset, time_name=None):
1297  """Output the lookup table index calculations needed for the given equations, if tables are enabled.
1298 
1299  If time_name is given, it may be used in exception messages for tables out of bounds.
1300  Note that it is needed to be passed in, since GetIIonic does not know the time.
1301 
1302  Returns the subset of nodeset used in calculating the indices.
1303  """
1304  if self.use_lookup_tables:
1305  nodes_used = self.output_table_index_generation(time_name, nodeset=nodeset)
1306  else:
1307  nodes_used = set()
1308  return nodes_used
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name (   self,
  var,
  args,
  kwargs 
)
Return the full name of var in a form suitable for inclusion in a source file.

Overrides the base class version to access mParameters for parameters.

Definition at line 445 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.free_vars, CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.translators.CellMLTranslator.model, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_modifiers, and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_index().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.get_stimulus_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.modifier_call(), CellMLToNektar.translators.CellMLTranslator.output_apply(), CellMLToNektar.translators.CellMLTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.translators.CellMLTranslator.output_bottom_boilerplate(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations_grl(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_evaluate_y_derivatives(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl1_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl2_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl_compute_partial(), CellMLToNektar.translators.CellMLTranslator.output_lhs(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), CellMLToNektar.translators.CellMLTranslator.output_lut_generation(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_indexing_methods(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_nonlinear_state_assignments(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_checking(), CellMLToNektar.translators.CellMLTranslator.output_table_index_checking(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_generation_code(), CellMLToNektar.translators.CellMLTranslator.output_table_index_generation_code(), CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate(), CellMLToNektar.translators.CellMLTranslator.output_variable(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_variable().

446  def code_name(self, var, *args, **kwargs):
447  """
448  Return the full name of var in a form suitable for inclusion in a source file.
449 
450  Overrides the base class version to access mParameters for parameters.
451  """
452  #self.writeln(var)
453  if hasattr(var, '_cml_param_index') and not (self.use_modifiers and getattr(var, '_cml_has_modifier', False)):
454  return self.vector_index('mParameters', var._cml_param_index)
455  elif var is getattr(self.model, u'_cml_Chaste_Cm', None):
456  return 'HeartConfig::Instance()->GetCapacitance()'
457  elif hasattr(var, '_cml_code_name'):
458  return var._cml_code_name % {'time': self.code_name(self.free_vars[0])}
459  else:
460  # self.writeln(var)
461  # self.writeln(super(CellMLToNektarTranslator, self).code_name(var, *args, **kwargs))
462  return super(CellMLToNektarTranslator, self).code_name(var, *args, **kwargs)
463 
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.final_configuration_hook (   self)
Set the LT method prefix (requires self.class_name to be set).

Definition at line 65 of file CellMLToNektarTranslator.py.

65 
66  def final_configuration_hook(self):
67  """Set the LT method prefix (requires self.class_name to be set)."""
68  if self.separate_lut_class:
69  self.lt_class_name = self.class_name + '_LookupTables'
70  self.lookup_method_prefix = self.lt_class_name + '::Instance()->'
71  return super(CellMLToNektarTranslator, self).final_configuration_hook()
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.find_grl_partial_derivatives (   self)
If we have analytic Jacobian information available from Maple, find the terms needed for GRL methods.

This caches where the diagonal entries are in the matrix, indexed by the state variable objects currently in use,
since the entries in the matrix may reference non-partially-evaluated variables.

Definition at line 1830 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl1_mathematics(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl2_mathematics().

1831  def find_grl_partial_derivatives(self):
1832  """If we have analytic Jacobian information available from Maple, find the terms needed for GRL methods.
1833 
1834  This caches where the diagonal entries are in the matrix, indexed by the state variable objects currently in use,
1835  since the entries in the matrix may reference non-partially-evaluated variables.
1836  """
1837  if not hasattr(self, 'jacobian_diagonal'):
1838  self.jacobian_diagonal = {}
1839  if self.use_analytic_jacobian and not self.jacobian_diagonal:
1840  for entry in self.model.solver_info.jacobian.entry:
1841  if entry.var_i == entry.var_j:
1842  # It's a diagonal entry
1843  var = self.varobj(entry.var_i).get_source_variable(recurse=True)
1844  assert var in self.state_vars, "Jacobian diagonal entry is not in the state vector: " + entry.xml()
1845  entry_content = list(entry.math.xml_element_children())
1846  assert len(entry_content) == 1, "Malformed Jacobian entry: " + entry.xml()
1847  self.jacobian_diagonal[var] = entry_content[0]
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.generate_interface (   doc,
  solver_info 
)
static
Generate an interface component connecting the model to Chaste.

On return from this method, Chaste code will only need to interact with variables in
the new interface component.  It will contain the transmembrane potential, the ionic
and stimulus currents, the simulation time, and the derivatives.

It may also contain other variables depending on the model, for example the intracellular
calcium concentration (if annotated), modifiable parameters, and derived quantities.

If the --convert-interfaces option has been supplied, units conversion will then be
performed on this component, ensuring that all these variables are in the units expected
by Chaste and linked by suitable conversions to the rest of the model.

Note that if partial evaluation is then performed, the model will be collapsed into a
single component.  However, the interface will still be preserved in the correct units.

Definition at line 2365 of file CellMLToNektarTranslator.py.

References CellMLToNektar.pycml.dimensionally_equivalent(), and CellMLToNektar.pycml.simplify().

2366  def generate_interface(doc, solver_info):
2367  """Generate an interface component connecting the model to Chaste.
2368 
2369  On return from this method, Chaste code will only need to interact with variables in
2370  the new interface component. It will contain the transmembrane potential, the ionic
2371  and stimulus currents, the simulation time, and the derivatives.
2372 
2373  It may also contain other variables depending on the model, for example the intracellular
2374  calcium concentration (if annotated), modifiable parameters, and derived quantities.
2375 
2376  If the --convert-interfaces option has been supplied, units conversion will then be
2377  performed on this component, ensuring that all these variables are in the units expected
2378  by Chaste and linked by suitable conversions to the rest of the model.
2379 
2380  Note that if partial evaluation is then performed, the model will be collapsed into a
2381  single component. However, the interface will still be preserved in the correct units.
2382  """
2383  model = doc.model
2384  config = doc._cml_config
2385  klass = CellMLToNektarTranslator
2386  # Create Chaste units definitions
2387  ms = cellml_units.create_new(model, 'millisecond',
2388  [{'units': 'second', 'prefix': 'milli'}])
2389  mV = cellml_units.create_new(model, 'millivolt',
2390  [{'units': 'volt', 'prefix': 'milli'}])
2391  current_units, microamps = klass.get_current_units_options(model)[0:2]
2392  # The interface generator
2393  generator = processors.InterfaceGenerator(model, name=klass.INTERFACE_COMPONENT_NAME)
2394  iface_comp = generator.get_interface_component()
2395  # In case we need to convert initial values, we create the units converter here
2396  if config.options.convert_interfaces:
2397  warn_only = not config.options.fully_automatic and config.options.warn_on_units_errors
2398  notifier = NotifyHandler(level=logging.WARNING)
2399  logging.getLogger('units-converter').addHandler(notifier)
2400  converter = processors.UnitsConverter(model, warn_only, show_xml_context_only=True)
2401  klass.add_special_conversions(converter, iface_comp)
2402  generator.set_units_converter(converter)
2403  # And now specify the interface
2404  t = model.find_free_vars()[0]
2405  if not ms.dimensionally_equivalent(t.get_units()):
2406  # Oops!
2407  raise TranslationError('Time does not have dimensions of time')
2408  generator.add_input(t, ms)
2409  if doc.model.get_option('backward_euler'):
2410  # Backward Euler code generation requires access to the time step
2411  model_dt = solver_info.create_dt(generator, t.component, t.get_units())
2412  config.dt_variable = generator.add_input(model_dt, ms)
2413  config.dt_variable.set_pe_keep(True)
2414  elif doc.model.get_option('maple_output'):
2415  # CVODE Jacobians need to be able to scale for time too
2416  fake_dt = generator.add_variable(t.component, 'fake_dt', ms, initial_value='1.0')
2417  fake_dt._set_type(VarTypes.Constant)
2418  config.dt_variable = generator.add_input(fake_dt, t.get_units())
2419  config.dt_variable.set_is_modifiable_parameter(False)
2420  config.dt_variable.set_pe_keep(True)
2421 
2422  if config.options.use_chaste_stimulus and config.i_stim_var:
2423  # We need to make it a constant so add_input doesn't complain, then make it computed
2424  # again so that exposing metadata-annotated variables doesn't make it a parameter!
2425  generator.make_var_constant(config.i_stim_var, 0)
2426  config.i_stim_var = generator.add_input(config.i_stim_var, current_units,
2427  annotate=False, convert_initial_value=False)
2428  generator.make_var_computed_constant(config.i_stim_var, 0)
2429  # Also convert variables that make up the default stimulus
2430  # Note: we vary in/out-put primarily to test units conversion of initial values
2431  def add_oxmeta_ioput(oxmeta_name, units, inout):
2432  var = doc.model.get_variable_by_oxmeta_name(oxmeta_name, throw=False)
2433  if var:
2434  meth = getattr(generator, 'add_%sput' % inout)
2435  newvar = meth(var, units, annotate=False)
2436  newvar.set_pe_keep(True)
2437  for n in ['duration', 'period', 'offset', 'end']:
2438  add_oxmeta_ioput('membrane_stimulus_current_'+n, ms, 'in')
2439  add_oxmeta_ioput('membrane_stimulus_current_amplitude', current_units, 'out')
2440 
2441  if config.V_variable:
2442  config.V_variable = generator.add_input(config.V_variable, mV)
2443  ionic_vars = config.i_ionic_vars
2444  if ionic_vars:
2445  i_ionic = generator.add_output_function('i_ionic', 'plus', ionic_vars, current_units)
2446  config.i_ionic_vars = [i_ionic]
2447 
2448  if doc.model.get_option('use_data_clamp'):
2449  assert config.V_variable and ionic_vars
2450  # Create g_clamp
2451  conductance_units = current_units.quotient(mV).simplify()
2452  i_data_clamp_conductance = generator.add_variable(iface_comp, 'membrane_data_clamp_current_conductance', conductance_units, initial_value='0.0')
2453  i_data_clamp_conductance._set_type(VarTypes.Constant)
2454  i_data_clamp_conductance.set_pe_keep(True) # This prevents it becoming 'chaste_interface__membrane_data_clamp_current_conductance'
2455  config.i_data_clamp_conductance = generator.add_input(i_data_clamp_conductance, conductance_units)
2456  # Create V_clamp
2457  data_var = config.i_data_clamp_data = generator.add_variable(iface_comp, 'experimental_data_voltage', mV, initial_value='0.0')
2458  data_var._set_type(VarTypes.Constant)
2459  data_var.set_pe_keep(True)
2460  data_var._cml_code_name = 'GetExperimentalVoltageAtTimeT(%(time)s)'
2461  # Create the current: I = g_clamp * (V - V_clamp)
2462  current_var = config.i_data_clamp_current = generator.add_variable(iface_comp, 'membrane_data_clamp_current', current_units)
2463  current_var._set_type(VarTypes.Computed)
2464  current_var.set_is_derived_quantity(True)
2465  sub = mathml_apply.create_new(model, u'minus', [config.V_variable.name, data_var.name])
2466  times = mathml_apply.create_new(model, u'times', [config.i_data_clamp_conductance.name, sub])
2467  assign = mathml_apply.create_new(model, u'eq', [current_var.name, times])
2468  generator.add_expr_to_comp(iface_comp, assign)
2469  # Make dV/dt use the new current
2470  def process_ci(elt):
2471  # Add reference to new current after first existing ionic current
2472  ref = mathml_ci.create_new(model, local_current_var.name)
2473  elt.xml_parent.xml_insert_after(elt, ref)
2474  if hasattr(ionic_vars[0], '_cml_ref_in_dvdt'):
2475  local_current_var = generator.connect_variables(current_var, (ionic_vars[0]._cml_ref_in_dvdt.component.name, current_var.name))
2476  process_ci(ionic_vars[0]._cml_ref_in_dvdt)
2477  else:
2478  dVdt = config.V_variable.get_all_expr_dependencies()[0]
2479  local_current_var = generator.connect_variables(current_var, (config.V_variable.component.name, current_var.name))
2480  def process_ci_elts(elt):
2481  """Recursively process any ci elements in the tree rooted at elt."""
2482  if isinstance(elt, mathml_ci):
2483  if elt.variable is ionic_vars[0]:
2484  process_ci(elt)
2485  else:
2486  for child in getattr(elt, 'xml_children', []):
2487  process_ci_elts(child)
2488  process_ci_elts(dVdt)
2489 
2490  # Finish up
2491  def errh(errors):
2492  raise TranslationError("Creation of Chaste interface component failed:\n " + str(errors))
2493  generator.finalize(errh, check_units=False)
2494  # Apply units conversions just to the interface, if desired
2495  if config.options.convert_interfaces:
2496  converter.add_conversions_for_component(iface_comp)
2497  converter.finalize(errh, check_units=False)
2498  notifier.flush()
2499  logging.getLogger('units-converter').removeHandler(notifier)
2500  if notifier.messages:
2501  msg = 'Problems occurred converting model variables to Chaste units.\n'
2502  if ionic_vars and ionic_vars[0].get_units().dimensionally_equivalent(microamps):
2503  msg += 'To convert the ionic currents for this model, '\
2504  'the model membrane capacitance needs to be identified.'
2505  if config.options.fully_automatic:
2506  raise TranslationError(msg)
2507  else:
2508  print >>sys.stderr, msg
def dimensionally_equivalent
Definition: pycml.py:3185
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.get_current_units_options (   model)
static
Return a list of units objects that give the possibilities for the dimensions
of transmembrane ionic currents.

Definition at line 2301 of file CellMLToNektarTranslator.py.

2302  def get_current_units_options(model):
2303  """
2304  Return a list of units objects that give the possibilities for the dimensions
2305  of transmembrane ionic currents.
2306  """
2307  chaste_units = cellml_units.create_new(
2308  model, 'uA_per_cm2',
2309  [{'units': 'ampere', 'prefix': 'micro'},
2310  {'units': 'metre', 'prefix': 'centi', 'exponent': '-2'}])
2311  microamps = cellml_units.create_new(model, u'microamps',
2312  [{'units':'ampere', 'prefix':'micro'}])
2313  A_per_F = cellml_units.create_new(model, 'A_per_F',
2314  [{'units': 'ampere'},
2315  {'units': 'farad', 'exponent': '-1'}])
2316  return [chaste_units, microamps, A_per_F]
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.get_stimulus_assignment (   self)
Return code for getting Chaste's stimulus current.

Definition at line 1136 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.translators.CellMLTranslator.free_vars, and CellMLToNektar.translators.CellMLTranslator.STMT_END.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations().

1137  def get_stimulus_assignment(self):
1138  """Return code for getting Chaste's stimulus current."""
1139  expr = self.doc._cml_config.i_stim_var
1140  output = self.code_name(expr) + self.EQ_ASSIGN
1141  get_stim = 'GetIntracellularAreaStimulus(' + self.code_name(self.free_vars[0]) + ')'
1142  if self.doc._cml_config.i_stim_negated:
1143  get_stim = '-' + get_stim
1144  return output + get_stim + self.STMT_END
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.lut_parameters (   self,
  key 
)
Get the bounds and step size for a particular table.

key should be a key into self.lookup_table_indices.
Returns (min, max, step) suitable for putting in generated code.

Definition at line 861 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.translators.CellMLTranslator.output_lut_generation(), CellMLToNektar.translators.CellMLTranslator.output_table_index_checking(), and CellMLToNektar.translators.CellMLTranslator.output_table_index_generation_code().

862  def lut_parameters(self, key):
863  """Get the bounds and step size for a particular table.
864 
865  key should be a key into self.lookup_table_indices.
866  Returns (min, max, step) suitable for putting in generated code.
867  """
868  if self.separate_lut_class:
869  idx = self.doc.lookup_table_indexes[key]
870  return map(lambda s: 'mTable%s[%s]' % (s, idx), ['Mins', 'Maxs', 'Steps', 'StepInverses'])
871  else:
872  return super(CellMLToNektarTranslator, self).lut_parameters(key)
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.modifier_call (   self,
  var,
  current_value 
)
Return code for a call to a modifier function for an oxmeta-annotated variable.

The modifier function takes 2 parameters: the current value of the variable,
and the current time.  It returns a modified value for the variable.

Definition at line 1105 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), and CellMLToNektar.translators.CellMLTranslator.free_vars.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments().

1106  def modifier_call(self, var, current_value):
1107  """Return code for a call to a modifier function for an oxmeta-annotated variable.
1108 
1109  The modifier function takes 2 parameters: the current value of the variable,
1110  and the current time. It returns a modified value for the variable.
1111  """
1112  return ('mp_' + var.oxmeta_name + '_modifier->Calc(' +
1113  current_value + ', ' + self.code_name(self.free_vars[0]) + ')')
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment (   self,
  expr 
)
Output an assignment statement.

Has overrides for various special cases.

Definition at line 1179 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.cell_parameters, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_backward_euler, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_modifiers, CellMLToNektar.translators.CellMLTranslator.v_variable, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.translators.CellMLTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), and CellMLToNektar.translators.CellMLTranslator.output_mathematics().

1180  def output_assignment(self, expr):
1181  """Output an assignment statement.
1182 
1183  Has overrides for various special cases.
1184  """
1185  clear_type = False
1186  writing_data_clamp_current = False
1187  # Figure out what is being assigned to
1188  if isinstance(expr, cellml_variable):
1189  assigned_var = expr
1190  else:
1191  if expr.eq.lhs.localName == 'ci':
1192  assigned_var = expr.eq.lhs.variable
1193  if assigned_var is self.config.i_data_clamp_current:
1194  writing_data_clamp_current = True
1195  self.output_comment('Special handling of data clamp current here (see #2708)')
1196  self.output_comment('(we want to save expense of calling the interpolation method if possible.)')
1197  self.writeln(self.TYPE_DOUBLE, self.code_name(assigned_var), self.EQ_ASSIGN, '0.0' , self.STMT_END)
1198  self.writeln('if (mDataClampIsOn)')
1199  self.open_block()
1200  clear_type = True
1201  else:
1202  assigned_var = None # We don't store derivatives as members
1203  #907: Check if this is the derivative of the transmembrane potential
1204  if not self.use_backward_euler and expr.eq.lhs.diff.dependent_variable == self.v_variable:
1205  clear_type = True
1206 
1207  # Parameters don't need assigning
1208  has_modifier = self.use_modifiers and getattr(assigned_var, '_cml_has_modifier', False)
1209  # self.writeln(has_modifier)
1210  if assigned_var in self.cell_parameters and not has_modifier:
1211  return
1212  # Is the variable declared elsewhere?
1213  if clear_type:
1214  self.TYPE_DOUBLE = self.TYPE_CONST_DOUBLE = ''
1215  elif getattr(assigned_var, '_cml_modifiable', False):
1216  # Override const-ness, e.g. for a lookup table index
1217  self.TYPE_CONST_DOUBLE = self.TYPE_DOUBLE
1218  if (assigned_var and self.use_modifiers and assigned_var in self.modifier_vars
1219  and assigned_var.get_type() != VarTypes.State):
1220  # "Constant" oxmeta-annotated parameters may be modified at run-time
1221  if has_modifier:
1222  # Turn off the modifier to figure out the base value
1223  assigned_var._cml_has_modifier = False
1224  rhs = self.code_name(assigned_var)
1225  assigned_var._cml_has_modifier = True
1226  else:
1227  self.capture_output()
1228  super(CellMLToNektarTranslator, self).output_assignment(expr)
1229  assignment = self.get_captured_output()
1230  eq_pos = assignment.find(self.EQ_ASSIGN)
1231  end_pos = assignment.find(self.STMT_END)
1232  rhs = assignment[eq_pos+len(self.EQ_ASSIGN):end_pos]
1233  if rhs:
1234  # If assigned_var is computed, it'll 'appear' twice - once with expr==assigned_var,
1235  # and once for the assignment mathml_apply. The former will result in an empty rhs.
1236  # self.writeln('Test')
1237  self.writeln(self.TYPE_CONST_DOUBLE, self.code_name(assigned_var), self.EQ_ASSIGN,
1238  self.modifier_call(assigned_var, rhs), self.STMT_END, nl=False)
1239 
1240  self.output_comment(assigned_var.units, indent=False, pad=True)
1241  else:
1242  # self.writeln('Test')
1243  super(CellMLToNektarTranslator, self).output_assignment(expr)
1244 # if assigned_var:
1245 # # Debug
1246 # self.writeln('EXCEPT_IF_NOT(!std::isinf(', self.code_name(assigned_var), '));')
1247 # self.writeln('EXCEPT_IF_NOT(!std::isnan(', self.code_name(assigned_var), '));')
1248  if clear_type:
1249  # Remove the instance attributes, thus reverting to the class members
1250  del self.TYPE_DOUBLE
1251  del self.TYPE_CONST_DOUBLE
1252  elif getattr(assigned_var, '_cml_modifiable', False):
1253  del self.TYPE_CONST_DOUBLE
1254 
1255  if writing_data_clamp_current:
1256  self.close_block(False)
1257 
1258  return
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics (   self)
Output the mathematics methods used in a backward Euler cell.

Outputs ComputeResidual, ComputeJacobian,
UpdateTransmembranePotential and ComputeOneStepExceptVoltage.

Definition at line 1572 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator._vars_in(), CellMLToNektar.translators.CellMLTranslator.calculate_extended_dependencies(), CellMLToNektar.pycml.cellml_model.calculate_extended_dependencies(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.calculate_lookup_table_indices(), CellMLToNektar.translators.CellMLTranslator.class_name, CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.COMMENT_START, CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.translators.CellMLTranslator.free_vars, CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.translators.CellMLTranslator.model, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.nonlinear_system_size, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.nonlinear_system_vars, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.translators.CellMLTranslator.output_expr(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_nonlinear_state_assignments(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.translators.CellMLTranslator.state_vars, CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_CONST_DOUBLE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.v_index, CellMLToNektar.translators.CellMLTranslator.varobj(), CellMLToNektar.translators.CellMLTranslator.write(), CellMLToNektar.translators.CellMLTranslator.writeln(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.writeln_hpp().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_mathematics().

1574  """Output the mathematics methods used in a backward Euler cell.
1575 
1576  Outputs ComputeResidual, ComputeJacobian,
1577  UpdateTransmembranePotential and ComputeOneStepExceptVoltage.
1578  """
1579  dt_name = 'mDt'
1580  #model_dt = self.varobj(self.model.solver_info.dt)
1581  if self.nonlinear_system_size > 0:
1582  # Residual
1583  ##########
1584  argsize = '[' + str(self.nonlinear_system_size) + ']'
1585  self.output_method_start('ComputeResidual',
1586  [self.TYPE_DOUBLE + self.code_name(self.free_vars[0]),
1587  self.TYPE_CONST_DOUBLE + 'rCurrentGuess' + argsize,
1588  self.TYPE_DOUBLE + 'rResidual' + argsize],
1589  'void', access='public')
1590  self.open_block()
1591  # Output mathematics for computing du/dt for each nonlinear state var u
1592  nodes = map(lambda u: (u, self.free_vars[0]), self.nonlinear_system_vars)
1593  nodeset = self.calculate_extended_dependencies(nodes, prune_deps=[self.doc._cml_config.i_stim_var])
1594  self.output_state_assignments(exclude_nonlinear=True, nodeset=nodeset)
1595  self.output_nonlinear_state_assignments(nodeset=nodeset)
1596  table_index_nodes_used = self.calculate_lookup_table_indices(nodeset, self.code_name(self.free_vars[0]))
1597  self.output_equations(nodeset - table_index_nodes_used)
1598  self.writeln()
1599  # Fill in residual
1600  for i, var in enumerate(self.state_vars):
1601  try:
1602  j = self.nonlinear_system_vars.index(var)
1603  except ValueError:
1604  j = -1
1605  if j != -1:
1606  self.writeln('rResidual[', j, '] = rCurrentGuess[', j, '] - rY[', i, '] - ',
1607  dt_name, '*', self.code_name(var, ode=True), self.STMT_END)
1608  self.close_block()
1609 
1610  # Jacobian
1611  ##########
1612  self.output_method_start('ComputeJacobian',
1613  [self.TYPE_DOUBLE + self.code_name(self.free_vars[0]),
1614  self.TYPE_CONST_DOUBLE + 'rCurrentGuess' + argsize,
1615  self.TYPE_DOUBLE + 'rJacobian' + argsize + argsize],
1616  'void', access='public')
1617  self.open_block()
1618  # Mathematics that the Jacobian depends on
1619  used_vars = set()
1620  for entry in self.model.solver_info.jacobian.entry:
1621  used_vars.update(self._vars_in(entry.math))
1622  nodeset = self.calculate_extended_dependencies(used_vars, prune_deps=[self.doc._cml_config.i_stim_var])
1623  self.output_state_assignments(exclude_nonlinear=True, nodeset=nodeset)
1624  self.output_nonlinear_state_assignments(nodeset=nodeset)
1625  self.writeln(self.TYPE_CONST_DOUBLE, self.code_name(self.config.dt_variable), self.EQ_ASSIGN, dt_name, self.STMT_END, '\n')
1626  table_index_nodes_used = self.calculate_lookup_table_indices(nodeset|set(map(lambda e: e.math, self.model.solver_info.jacobian.entry)), self.code_name(self.free_vars[0]))
1627  self.output_equations(nodeset - table_index_nodes_used)
1628  self.writeln()
1629  # Jacobian entries
1630  for entry in self.model.solver_info.jacobian.entry:
1631  var_i, var_j = entry.var_i, entry.var_j
1632  i = self.nonlinear_system_vars.index(self.varobj(var_i))
1633  j = self.nonlinear_system_vars.index(self.varobj(var_j))
1634  self.writeln('rJacobian[', i, '][', j, '] = ', nl=False)
1635  entry_content = list(entry.math.xml_element_children())
1636  assert len(entry_content) == 1, "Malformed Jacobian matrix entry: " + entry.xml()
1637  self.output_expr(entry_content[0], False)
1638  self.writeln(self.STMT_END, indent=False)
1639 # self.output_comment('Debugging')
1640 # self.writeln('#ifndef NDEBUG', indent=False)
1641 # self.writeln('for (unsigned i=0; i<', len(self.nonlinear_system_vars), '; i++)')
1642 # self.writeln('for (unsigned j=0; j<', len(self.nonlinear_system_vars), '; j++)', indent_offset=1)
1643 # self.writeln('EXCEPT_IF_NOT(!std::isnan(rJacobian[i][j]));', indent_offset=2)
1644 # self.writeln('//DumpJacobianToFile(', self.code_name(self.free_vars[0]),
1645 # ', rCurrentGuess, rJacobian, rY);')
1646 # self.writeln('#endif // NDEBUG', indent=False)
1647  self.close_block()
1648  # The other methods are protected
1649  self.writeln_hpp('protected:', indent_offset=-1)
1650 
1651  # UpdateTransmembranePotential
1652  ##############################
1653  self.output_method_start('UpdateTransmembranePotential',
1654  [self.TYPE_DOUBLE + self.code_name(self.free_vars[0])],
1655  'void', access='public')
1656  self.open_block()
1657  self.output_comment('Time units: ', self.free_vars[0].units)
1658  # Output mathematics to compute dV/dt
1659  nodes = [(self.state_vars[self.v_index], self.free_vars[0])]
1660  nodeset = self.calculate_extended_dependencies(nodes, prune_deps=[self.doc._cml_config.i_stim_var])
1661  self.output_state_assignments(nodeset=nodeset)
1662  table_index_nodes_used = self.calculate_lookup_table_indices(nodeset, self.code_name(self.free_vars[0]))
1663  self.output_equations(nodeset - table_index_nodes_used)
1664  # Update V
1665  self.writeln()
1666  self.writeln('rY[', self.v_index, '] += ', dt_name, '*',
1667  self.code_name(self.state_vars[self.v_index], ode=True), self.STMT_END)
1668  self.close_block()
1669 
1670  # ComputeOneStepExceptVoltage
1671  #############################
1672  self.output_method_start('ComputeOneStepExceptVoltage',
1673  [self.TYPE_DOUBLE + self.code_name(self.free_vars[0])],
1674  'void', access='public')
1675  self.open_block()
1676  self.writeln(self.COMMENT_START, 'Time units: ',
1677  self.free_vars[0].units)
1678  # Output mathematics to update linear state variables, using solver_info.linear_odes.
1679  # Also need to use output_equations for variables used in the update equations.
1680  linear_vars, update_eqns = [], {}
1681  used_vars = set() # NB: Also contains update equation if is a mathml_apply so table index generation works
1682  for u, t, update_eqn in SolverInfo(self.model).get_linearised_odes():
1683  assert t == self.free_vars[0]
1684  assert len(update_eqn) == 1
1685  update_eqn = update_eqn[0]
1686  linear_vars.append(u)
1687  update_eqns[id(u)] = update_eqn
1688  if not isinstance(update_eqn, mathml_cn): used_vars.add(update_eqn)
1689  used_vars.update(self._vars_in(update_eqn))
1690  # Output required equations for used variables
1691  nodeset = self.calculate_extended_dependencies(used_vars, prune_deps=[self.doc._cml_config.i_stim_var])
1692  self.output_state_assignments(nodeset=nodeset)
1693  if self.config.dt_variable in nodeset:
1694  self.writeln(self.TYPE_CONST_DOUBLE, self.code_name(self.config.dt_variable), self.EQ_ASSIGN,
1695  dt_name, self.STMT_END, '\n')
1696  table_index_nodes_used = self.calculate_lookup_table_indices(nodeset, self.code_name(self.free_vars[0]))
1697  self.output_equations(nodeset - table_index_nodes_used)
1698  # Update state variables:
1699  # rY[i] = (rY[i] + _g_j*dt) / (1 - _h_j*dt)
1700  self.writeln()
1701  linear_vars.sort(key=lambda v: v.fullname())
1702  for i, u in enumerate(linear_vars):
1703  j = self.state_vars.index(u)
1704  self.writeln('rY[', j, ']', self.EQ_ASSIGN, nl=False)
1705  self.output_expr(update_eqns[id(u)], False)
1706  self.writeln(self.STMT_END, indent=False)
1707  # Set up the Newton iteration, if needed
1708  self.writeln()
1709  if self.nonlinear_system_size > 0:
1710  self.writeln('double _guess[', self.nonlinear_system_size, '] = {', nl=False)
1711  comma = False
1712  idx_map = [0] * self.nonlinear_system_size
1713  for i, var in enumerate(self.state_vars):
1714  try:
1715  j = self.nonlinear_system_vars.index(var)
1716  idx_map[j] = i
1717  except ValueError:
1718  pass
1719  for i in idx_map:
1720  if comma: self.write(',')
1721  else: comma = True
1722  self.write('rY[', i, ']')
1723  self.writeln('};', indent=False)
1724  # Solve
1725  CNS = 'CardiacNewtonSolver<%d,%s>' % (self.nonlinear_system_size, self.class_name)
1726  self.writeln(CNS, '* _p_solver = ', CNS, '::Instance();')
1727  self.writeln('_p_solver->Solve(*this, ', self.code_name(self.free_vars[0]), ', _guess);')
1728  # Update state
1729  for j, i in enumerate(idx_map):
1730  self.writeln('rY[', i, '] = _guess[', j, '];')
1731  self.close_block()
string STMT_END
Various language tokens #.
Definition: translators.py:141
def calculate_extended_dependencies
Dependency related methods #.
Definition: translators.py:899
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_bottom_boilerplate (   self)
Output bottom boilerplate.

End class definition, output ODE system information (to .cpp) and
serialization code (to .hpp), and end the file.

Definition at line 2147 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.cell_parameters, CellMLToNektar.translators.CellMLTranslator.class_name, CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.derived_quantities, CellMLToNektar.translators.CellMLTranslator.NOT_A_NUMBER, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_model_attributes(), CellMLToNektar.translators.CellMLTranslator.set_indent(), CellMLToNektar.translators.CellMLTranslator.state_vars, CellMLToNektar.translators.CellMLTranslator.TYPE_VOID, CellMLToNektar.translators.CellMLTranslator.var_display_name(), and CellMLToNektar.translators.CellMLTranslator.writeln().

2148  def output_bottom_boilerplate(self):
2149  """Output bottom boilerplate.
2150 
2151  End class definition, output ODE system information (to .cpp) and
2152  serialization code (to .hpp), and end the file.
2153  """
2154  # End main class
2155  self.set_indent(offset=0)
2156  # self.writeln_hpp('};\n\n')
2157  # ODE system information
2158 
2159  self.writeln(self.TYPE_VOID, self.class_name, '::v_GenerateSummary(SummaryList& s)')
2160  self.open_block()
2161  self.writeln('SolverUtils::AddSummaryItem(s, "', 'Cell model' , '", "', self.class_name , '");')
2162  self.close_block()
2163 
2164  #self.writeln('template<>')
2165  self.writeln(self.TYPE_VOID, self.class_name,
2166  '::v_SetInitialConditions()')
2167  self.open_block()
2168  # self.writeln('this->mSystemName', self.EQ_ASSIGN, '"', self.model.name, '"', self.STMT_END)
2169  # self.writeln('this->mFreeVariableName', self.EQ_ASSIGN,
2170  # '"', self.var_display_name(self.free_vars[0]), '"', self.STMT_END)
2171  # self.writeln('this->mFreeVariableUnits', self.EQ_ASSIGN,
2172  # '"', self.free_vars[0].units, '"', self.STMT_END)
2173  # self.writeln()
2174  def output_var(vector, var):
2175  self.writeln('this->m', vector, 'Names.push_back("', self.var_display_name(var), '");')
2176  self.writeln('this->m', vector, 'Units.push_back("', var.units, '");')
2177 
2178  for i,var in enumerate(self.state_vars):
2179  #output_var('Variable', var)
2180  init_val = getattr(var, u'initial_value', None)
2181 
2182  if init_val is None:
2183  init_comm = ' // Value not given in model'
2184  # Don't want compiler error, but shouldn't be a real number
2185  init_val = self.NOT_A_NUMBER
2186  else:
2187  init_comm = ''
2188  #21
2189  self.writeln('Vmath::Fill(m_nq, ', float(init_val), ',' , ' '*(21-len(init_val)) , 'm_cellSol[', i ,'], 1);',
2190  init_comm)
2191 
2192  # Model parameters
2193  for var in self.cell_parameters:
2194  if var.get_type() == VarTypes.Constant:
2195  output_var('Parameter', var)
2196  self.writeln()
2197  # Derived quantities
2198  for var in self.derived_quantities:
2199  output_var('DerivedQuantity', var)
2200  self.writeln()
2202  #self.writeln('this->mInitialised = true;')
2203  self.writeln('}',indent_level=1)
2204  #self.writeln()
2205  # Serialization
2206  # if self.include_serialization:
2207  # self.output_comment('Needs to be included last', subsidiary=True)
2208  # self.writeln_hpp('#include "SerializationExportWrapper.hpp"')
2209  # self.writeln_hpp('CHASTE_CLASS_EXPORT(', self.class_name, ')')
2210  # self.output_comment('Serialization for Boost >= 1.36')
2211  # self.writeln('#include "SerializationExportWrapperForCpp.hpp"')
2212  # self.writeln('CHASTE_CLASS_EXPORT(', self.class_name, ')')
2213  # self.writeln_hpp()
2214  # self.writeln_hpp('namespace boost')
2215  # self.open_block(subsidiary=True)
2216  # self.writeln_hpp('namespace serialization')
2217  # self.open_block(subsidiary=True)
2218  # # Save
2219  # self.writeln_hpp('template<class Archive>')
2220  # self.writeln_hpp('inline void save_construct_data(')
2221  # self.writeln_hpp('Archive & ar, const ', self.class_name,
2222  # ' * t, const unsigned int fileVersion)',
2223  # indent_offset=1)
2224  # self.open_block(subsidiary=True)
2225  # self.writeln_hpp('const boost::shared_ptr<AbstractIvpOdeSolver> p_solver = t->GetSolver();')
2226  # self.writeln_hpp('const boost::shared_ptr<AbstractStimulusFunction> p_stimulus = t->GetStimulusFunction();')
2227  # self.writeln_hpp('ar << p_solver;')
2228  # self.writeln_hpp('ar << p_stimulus;')
2229  # self.close_block(subsidiary=True)
2230  # # Load
2231  # self.writeln_hpp('template<class Archive>')
2232  # self.writeln_hpp('inline void load_construct_data(')
2233  # self.writeln_hpp('Archive & ar, ', self.class_name,
2234  # ' * t, const unsigned int fileVersion)',
2235  # indent_offset=1)
2236  # self.open_block(subsidiary=True)
2237  # self.writeln_hpp('boost::shared_ptr<AbstractIvpOdeSolver> p_solver;')
2238  # self.writeln_hpp('boost::shared_ptr<AbstractStimulusFunction> p_stimulus;')
2239  # self.writeln_hpp('ar >> p_solver;')
2240  # self.writeln_hpp('ar >> p_stimulus;')
2241  # self.writeln_hpp('::new(t)', self.class_name, '(p_solver, p_stimulus);')
2242  # self.close_block(subsidiary=True)
2243  # self.close_block(subsidiary=True)
2244  # self.close_block(subsidiary=True)
2245  # if self.dynamically_loadable:
2246  # # Write the C function to create instances of this cell model
2247  # self.writeln('extern "C"')
2248  # self.open_block()
2249  # self.writeln('AbstractCardiacCellInterface* MakeCardiacCell(')
2250  # self.writeln('boost::shared_ptr<AbstractIvpOdeSolver> pSolver,', indent_offset=2)
2251  # self.writeln('boost::shared_ptr<AbstractStimulusFunction> pStimulus)', indent_offset=2)
2252  # self.open_block()
2253  # self.writeln('return new ', self.class_name, '(pSolver, pStimulus);')
2254  # self.close_block()
2255  # self.close_block()
2256  # End file
2257  #self.writeln_hpp('#endif // ', self.include_guard)
2258  self.writeln('}', indent_level=0)
2259  return
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_cell_parameters (   self)
Output declarations, set & get methods for cell parameters.

Sets self.cell_parameters to be those constant variables annotated with
pycml:modifiable-parameter.  These use the mParameters functionality in
Chaste.

Also collects any variables annotated with an RDF oxmeta name into
self.metadata_vars. Only constants and state variables are included.

Definition at line 309 of file CellMLToNektarTranslator.py.

310  def output_cell_parameters(self):
311  """Output declarations, set & get methods for cell parameters.
312 
313  Sets self.cell_parameters to be those constant variables annotated with
314  pycml:modifiable-parameter. These use the mParameters functionality in
315  Chaste.
316 
317  Also collects any variables annotated with an RDF oxmeta name into
318  self.metadata_vars. Only constants and state variables are included.
319  """
320  # Find annotated parameters
321  self.cell_parameters = filter(
322  lambda v: v.is_modifiable_parameter,
323  cellml_metadata.find_variables(self.model,
324  ('pycml:modifiable-parameter', NSS['pycml']),
325  'yes'))
326 
327  # Reduce intra-run variation
328  self.cell_parameters.sort(key=self.var_display_name)
329 
330  for i, var in enumerate(self.cell_parameters):
331  # Remember the var's index
332  var._cml_param_index = i
333 
334  # Create set of all oxmeta-annotated variables
335  vars = cellml_metadata.find_variables(self.model, ('bqbiol:is', NSS[u'bqbiol']))
336  # Keep only the variables with an oxmeta name
337  vars = filter(lambda v: v.oxmeta_name, vars)
338  # We're interested in anything that isn't time or the stimulus
339  self.metadata_vars = set([v for v in vars if v.get_type() != VarTypes.Free])
340  self.metadata_vars.discard(self.doc._cml_config.i_stim_var)
341  self.metadata_vars = list(self.metadata_vars)
342  self.metadata_vars.sort(key=self.var_display_name)
343 
344  # #1464 Create a set of metadata variables that will have modifiers
345  # We want to avoid writing out metadata for stimulus current as it is used once and then discarded.
346  # \todo - use protocol information to put only the required modifiers into this list.
347  self.modifier_vars = [v for v in self.metadata_vars if v.oxmeta_name not in cellml_metadata.STIMULUS_NAMES and v.oxmeta_name != 'membrane_capacitance']
348  self.modifier_vars.sort(key=self.var_display_name)
349 
350  # Generate member variable declarations
351  self.set_access('private')
352  if self.metadata_vars:
353  self.output_comment('\nSettable parameters and readable variables\n', subsidiary=True)
354 
355  # Write out the modifier member variables.
356  if self.use_modifiers:
357  for var in self.modifier_vars:
358  self.writeln_hpp('boost::shared_ptr<AbstractModifier> mp_' + var.oxmeta_name + '_modifier', self.STMT_END)
359 
360  # Methods associated with oxmeta annotated variables
361  # Don't use LT & modifiers for the const methods
362  use_modifiers = self.use_modifiers
363  self.use_modifiers = False
364  use_lt = self.use_lookup_tables
365  self.use_lookup_tables = False
366  for var in self.metadata_vars:
367  if var.is_statically_const(ignore_annotations=True):
368 # self.output_method_start('Get_' + var.oxmeta_name + '_constant', [], self.TYPE_DOUBLE)
369 # self.open_block()
370 # self.output_comment('Constant value given in CellML')
371 # nodeset = self.calculate_extended_dependencies([var])
372 # self.output_equations(nodeset)
373 # self.writeln('return ', self.code_name(var), self.STMT_END)
374 # self.close_block()
375 # self.writeln()
376  if var in self.cell_parameters and var in self.modifier_vars:
377  # 'Forget' its index, so normal code generation occurs (#1647)
378  var._cml_has_modifier = True
379  self.use_lookup_tables = use_lt
380  self.use_modifiers = use_modifiers
383 
384  # Find & store derived quantities, for use elsewhere
385  self.derived_quantities = cellml_metadata.find_variables(self.model,
386  ('pycml:derived-quantity', NSS['pycml']),
387  'yes')
388  # Reduce intra-run variation
389  self.derived_quantities.sort(key=self.var_display_name)
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_chaste_lut_methods (   self)
Output lookup table declarations & methods, if not using a separate class,
or output the method to get a pointer to the lookup table collection.

Definition at line 843 of file CellMLToNektarTranslator.py.

844  def output_chaste_lut_methods(self):
845  """
846  Output lookup table declarations & methods, if not using a separate class,
847  or output the method to get a pointer to the lookup table collection.
848  """
849  if self.use_lookup_tables:
850  if self.separate_lut_class:
851  self.output_method_start('GetLookupTableCollection', [], 'AbstractLookupTableCollection*')
852  self.open_block()
853  self.writeln('return ', self.lt_class_name, '::Instance();')
854  self.close_block()
855  else:
859  self.output_lut_methods()
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor (   self,
  params,
  base_class_params 
)
Output a cell constructor.

params is a list of constructor parameters, entries of which should be strings
including both type and parameter name, which will be included verbatim in the
generated code.

base_class_params is a list of parameters to be supplied to the base class
constructor.  Entries will be converted to strings.

Definition at line 704 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.cell_parameters, CellMLToNektar.translators.CellMLTranslator.class_name, CellMLToNektar.translators.CellMLTranslator.COMMENT_START, CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.has_default_stimulus, CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.translators.CellMLTranslator.model, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.modifier_vars, CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_extra_constructor_content(), CellMLToNektar.translators.CellMLTranslator.output_lut_generation(), CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_lookup_tables, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_modifiers, CellMLToNektar.translators.CellMLTranslator.var_display_name(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_index(), and CellMLToNektar.translators.CellMLTranslator.writeln().

705  def output_constructor(self, params, base_class_params):
706  """Output a cell constructor.
707 
708  params is a list of constructor parameters, entries of which should be strings
709  including both type and parameter name, which will be included verbatim in the
710  generated code.
711 
712  base_class_params is a list of parameters to be supplied to the base class
713  constructor. Entries will be converted to strings.
714  """
715  #self.output_method_start(self.class_name, params, '', access='public')
716  self.writeln('std::string ', self.class_name, '::className')
717  self.writeln('= GetCellModelFactory().RegisterCreatorFunction(', indent_offset=2)
718  #self.writeln(' : ', self.base_class_name, '(')
719 
720  # Filter out empty params, to make backward Euler happy
721  base_class_params = filter(None, map(str, base_class_params))
722  for i, param in enumerate(base_class_params):
723  if i == len(base_class_params)-1: comma = ');'
724  else: comma = ','
725  self.writeln(param, comma, indent_offset=3)
726 
727  #self.open_block()
728  self.writeln()
729  self.writeln('/**')
730  self.writeln('*')
731  self.writeln('*/')
732  # self.writeln('this->mpSystemInfo = OdeSystemInformation<',
733  # self.class_name, '>::Instance();')
734  # if self.v_index == -1 and self.v_variable:
735  # self.writeln('this->mVoltageIndex = GetAnyVariableIndex("',
736  # self.var_display_name(self.v_variable), '");')
737  # if self.config.options.include_dt_in_tables:
738  # self.writeln(self.lt_class_name, '::Instance()->SetTimestep(mDt);')
739  # self.writeln('Init();\n')
740 
741  #1861 - Rush-Larsen
742  if self.options.rush_larsen and not self.doc._cml_rush_larsen:
743  self.writeln('WARNING("No elligible gating variables found for this Rush-Larsen cell model; using normal forward Euler.");')
744 
745  #1463 - default cellML stimulus
746  if self.has_default_stimulus:
747  self.output_comment('We have a default stimulus specified in the CellML file metadata')
748  self.writeln('this->mHasDefaultStimulusFromCellML = true', self.STMT_END)
749 
750  #1464 - cleverer modifiers...
751  if self.use_modifiers and self.modifier_vars:
752  self.output_comment('These will get initialised to DummyModifiers in the base class method.')
753  for var in self.modifier_vars:
754  self.writeln('this->AddModifier("' + var.oxmeta_name + '",')
755  self.writeln(' mp_' + var.oxmeta_name + '_modifier)', self.STMT_END)
756 
757  #666 - initialise parameters
758  for var in self.cell_parameters:
759  if var.get_type() == VarTypes.Constant:
760  self.writeln(self.vector_index('this->mParameters', var._cml_param_index),
761  self.EQ_ASSIGN, var.initial_value, self.STMT_END, ' ',
762  self.COMMENT_START, var.fullname(), ' [', var.units, ']')
763  #1354 - specify protocol outputs
764 
765  if self.use_protocol:
766  outputs = cellml_metadata.find_variables(self.model,
767  ('pycml:output-variable', NSS['pycml']),
768  'yes')
769  def write_output_info(output):
770  if output.get_type() in [VarTypes.Free, VarTypes.Unknown]:
771  self.writeln('UNSIGNED_UNSET, FREE', indent=False, nl=False)
772  elif output.get_type() == VarTypes.State:
773  self.writeln(self.state_vars.index(output), ', STATE', indent=False, nl=False)
774  elif output.is_derived_quantity:
775  self.writeln(self.derived_quantities.index(output), ', DERIVED', indent=False, nl=False)
776  elif output.is_modifiable_parameter:
777  self.writeln(self.cell_parameters.index(output), ', PARAMETER', indent=False, nl=False)
778  else:
779  raise ValueError('Unexpected protocol output: ' + str(output))
780  if outputs:
781  outputs.sort(key=lambda v: self.var_display_name(v))
782  self.output_comment('Protocol outputs')
783  self.writeln('this->mOutputsInfo.resize(', len(outputs), ');')
784  for i, output in enumerate(outputs):
785  self.writeln('this->mOutputsInfo[', i, ']', self.EQ_ASSIGN,
786  'std::make_pair(', nl=False)
787  write_output_info(output)
788  self.writeln(')', self.STMT_END, indent=False)
789  self.writeln()
790  outputs = set(outputs)
791  #1925 - outputs that are vectors
792  prop = ('pycml:output-vector', NSS['pycml'])
793  vector_names = set(cellml_metadata.get_targets(self.model, None,
794  cellml_metadata.create_rdf_node(prop)))
795  self.writeln('this->mVectorOutputsInfo.resize(', len(vector_names), ');')
796  self.writeln('this->mVectorOutputNames.resize(', len(vector_names), ');')
797  for i, name in enumerate(sorted(vector_names)):
798  self.writeln('this->mVectorOutputNames[', i, ']', self.EQ_ASSIGN, '"', name, '"', self.STMT_END)
799  vector_outputs = cellml_metadata.find_variables(self.model, prop, name)
800  assert len(vector_outputs) > 0
801  vector_outputs.sort(key=lambda v: self.var_display_name(v))
802  self.writeln('this->mVectorOutputsInfo[', i, '].resize(', len(vector_outputs), ');')
803  for j, output in enumerate(vector_outputs):
804  self.writeln('this->mVectorOutputsInfo[', i, '][', j, ']', self.EQ_ASSIGN,
805  'std::make_pair(', nl=False)
806  write_output_info(output)
807  self.writeln(')', self.STMT_END, indent=False)
808  self.writeln()
809  outputs.update(vector_outputs)
810  #1910 - SED-ML name mappings
811  prop = ('pycml:alias', NSS['pycml'])
812  aliased_vars = cellml_metadata.find_variables(self.model, prop, None)
813  prop = cellml_metadata.create_rdf_node(prop)
814  for var in aliased_vars:
815  assert var in outputs
816  source = cellml_metadata.create_rdf_node(fragment_id=var.cmeta_id)
817  for alias in cellml_metadata.get_targets(self.model, source, prop):
818  name = self.var_display_name(var)
819  self.writeln('this->mNameMap["', alias, '"] = "', name, '";')
820  #2178 - set up model outputs environment from above info
821  self.writeln()
822  self.writeln('ProcessOutputsInfo();')
823  self.writeln()
824  #2428 - also record protocol inputs
825  inputs = cellml_metadata.find_variables(self.model, ('pycml:input-variable', NSS['pycml']), 'yes')
826  if inputs:
827  inputs.sort(key=lambda v: self.var_display_name(v))
828  self.writeln('this->mInputNames.reserve(', len(inputs), ');')
829  for input in inputs:
830  self.writeln('this->mInputNames.push_back("', self.var_display_name(input), '");')
831 
832  # Lookup table generation, if not in a singleton
833  if self.use_lookup_tables and not self.separate_lut_class:
834  self.output_lut_generation()
836  #self.close_block()
837 
838  return
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_default_stimulus (   self)
Output a default cell stimulus from the metadata specification
as long as the following metadata exists:
 * membrane_stimulus_current_amplitude
 * membrane_stimulus_current_duration
 * membrane_stimulus_current_period
and optionally:
 * membrane_stimulus_current_offset
 * membrane_stimulus_current_end

Ensures that the amplitude of the generated RegularStimulus is negative.

Definition at line 390 of file CellMLToNektarTranslator.py.

391  def output_default_stimulus(self):
392  """
393  Output a default cell stimulus from the metadata specification
394  as long as the following metadata exists:
395  * membrane_stimulus_current_amplitude
396  * membrane_stimulus_current_duration
397  * membrane_stimulus_current_period
398  and optionally:
399  * membrane_stimulus_current_offset
400  * membrane_stimulus_current_end
401 
402  Ensures that the amplitude of the generated RegularStimulus is negative.
403  """
404  vars = dict()
405  for n in ['duration', 'amplitude', 'period', 'offset', 'end']:
406  vars[n] = self.model.get_variable_by_oxmeta_name('membrane_stimulus_current_'+n, throw=False)
407  if not (vars['duration'] and vars['amplitude'] and vars['period']):
408  self.has_default_stimulus = False
409  return
410  self.has_default_stimulus = True
411  nodeset = self.calculate_extended_dependencies(filter(None, vars.values()))
412 
413  self.output_method_start('UseCellMLDefaultStimulus', [], 'boost::shared_ptr<RegularStimulus>', 'public')
414  self.open_block()
415  self.output_comment('Use the default stimulus specified by CellML metadata')
416  self.output_equations(nodeset)
417  self.writeln('boost::shared_ptr<RegularStimulus> p_cellml_stim(new RegularStimulus(')
418  self.writeln(' -fabs(', self.code_name(vars['amplitude']), '),')
419  self.writeln(' ', self.code_name(vars['duration']), ',')
420  self.writeln(' ', self.code_name(vars['period']), ',')
421  if vars['offset']:
422  self.writeln(' ', self.code_name(vars['offset']))
423  else:
424  self.writeln(' 0.0')
425  if vars['end']:
426  self.writeln(' , ', self.code_name(vars['end']))
427  self.writeln(' ))', self.STMT_END)
428  self.writeln('mpIntracellularStimulus = p_cellml_stim', self.STMT_END)
429  self.writeln('return p_cellml_stim', self.STMT_END)
430  self.close_block(blank_line=True)
string STMT_END
Various language tokens #.
Definition: translators.py:141
def calculate_extended_dependencies
Dependency related methods #.
Definition: translators.py:899
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations (   self,
  state_vars,
  assign_rY = False,
  extra_nodes = set(),
  extra_table_nodes = set() 
)
This is used by self.output_evaluate_y_derivatives and self.output_rush_larsen_mathematics
to compute the derivatives (and any extra nodes, if given).  It contains the special logic
to obey the mSetVoltageDerivativeToZero member variable in the generated code.
Returns a nodeset containing the equations output.

Definition at line 1476 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.calculate_extended_dependencies(), CellMLToNektar.pycml.cellml_model.calculate_extended_dependencies(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.calculate_lookup_table_indices(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.free_vars, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.NODESET, CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_CONST_DOUBLE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, CellMLToNektar.translators.CellMLTranslator.v_variable, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_evaluate_y_derivatives(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl1_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl2_mathematics(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics().

1477  extra_table_nodes=set()):
1478  """
1479  This is used by self.output_evaluate_y_derivatives and self.output_rush_larsen_mathematics
1480  to compute the derivatives (and any extra nodes, if given). It contains the special logic
1481  to obey the mSetVoltageDerivativeToZero member variable in the generated code.
1482  Returns a nodeset containing the equations output.
1483  """
1484  # Work out what equations are needed to compute the derivatives
1485 
1486  #this is important and might be where the variables come from
1487  #derivs creates a set of lists of tuples, where each tuple is a state_var with the free_var
1488  derivs = set(map(lambda v: (v, self.free_vars[0]), state_vars))
1489  # for var in derivs:
1490  # self.writeln(var)
1491 
1492 
1493  # self.writeln(derivs) #this line shows that set
1494 
1495  if self.v_variable in state_vars: #what this does is take out the v_variable into its own tuple and calls it dvdt
1496 
1497  dvdt = (self.v_variable, self.free_vars[0])
1498  derivs.remove(dvdt) #907: Consider dV/dt separately
1499  else:
1500  dvdt = None
1501 
1502  #this if function has been outcommented because i think it might not actually be needed in nektar
1503  # if self.use_chaste_stimulus:
1504  # i_stim = [self.doc._cml_config.i_stim_var]
1505  # else:
1506  i_stim = []
1507 
1508 
1509  nonv_nodeset = self.calculate_extended_dependencies(derivs|extra_nodes, prune_deps=i_stim)
1510 
1511  if dvdt:
1512  if self.use_data_clamp:
1513  prune = set([self.config.i_data_clamp_data]) | nonv_nodeset
1514  else:
1515  prune = nonv_nodeset
1516  # self.writeln('uses dvdt')
1517  v_nodeset = self.calculate_extended_dependencies([dvdt], prune=prune, prune_deps=i_stim)
1518  else:
1519  v_nodeset = set()
1520  # State variable inputs
1521  all_nodes = nonv_nodeset|v_nodeset
1522  self.output_state_assignments(assign_rY=assign_rY, nodeset=all_nodes)
1523  self.writeln()
1524  table_index_nodes_used = self.calculate_lookup_table_indices(all_nodes|extra_table_nodes, self.code_name(self.free_vars[0]))
1525  self.output_comment('Mathematics')
1526  #907: Declare dV/dt
1527  if dvdt:
1528  self.writeln(self.TYPE_DOUBLE, self.code_name(self.v_variable, ode=True), self.STMT_END)
1529  # Output mathematics required for non-dV/dt derivatives (which may include dV/dt)
1530  # self.writeln('Test Begin')
1531  self.NODESET = nonv_nodeset - table_index_nodes_used
1532  self.output_equations(nonv_nodeset - table_index_nodes_used)
1533  # self.writeln('Test End')
1534 
1535 
1536 
1537  self.writeln()
1538 
1539  #907: Calculation of dV/dt
1540  # if dvdt:
1541  # self.writeln('if (mSetVoltageDerivativeToZero)')
1542  # self.open_block()
1543  # self.writeln(self.code_name(self.v_variable, ode=True), self.EQ_ASSIGN, '0.0', self.STMT_END)
1544  # self.close_block(blank_line=False)
1545  # self.writeln('else')
1546  # self.open_block()
1547 
1548  # self.writeln('Test')
1549  # self.writeln(v_nodeset)
1550 
1551  # to_remove = set()
1552  # for var in v_nodeset:
1553  # # self.writeln(var)
1554  # if ',stim_' in str(var) or 'membrane,time' in str(var) and not 'membrane,i_st' in str(var):
1555  # to_remove.add(var)
1556 
1557  # # self.writeln(to_remove)
1558 
1559  # for var in to_remove:
1560  # v_nodeset.remove(var)
1561 
1562  self.writeln(self.TYPE_CONST_DOUBLE,'var_chaste_interface__membrane__I_stim = 0.0;')
1563  # self.writeln(self.TYPE_CONST_DOUBLE,'var_membrane__I_stim = var_chaste_interface__membrane__I_stim; // microA_per_cm2')
1564  self.output_equations(v_nodeset - table_index_nodes_used)
1565  # self.writeln('Test End')
1566 
1567  # self.close_block()
1568 
1569  self.writeln()
1570 
1571  return all_nodes | table_index_nodes_used
string STMT_END
Various language tokens #.
Definition: translators.py:141
def calculate_extended_dependencies
Dependency related methods #.
Definition: translators.py:899
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations_grl (   self,
  var,
  assign_rY = False,
  extra_nodes = set(),
  extra_table_nodes = set() 
)
This is used by self.output_grl?_mathematics to get equations for each variable separately.

Returns a node set with the equations output.

Definition at line 1811 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.calculate_extended_dependencies(), CellMLToNektar.pycml.cellml_model.calculate_extended_dependencies(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.calculate_lookup_table_indices(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.free_vars, CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.translators.CellMLTranslator.state_vars, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl1_mathematics(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl2_mathematics().

1812  def output_derivative_calculations_grl(self, var, assign_rY=False, extra_nodes=set(), extra_table_nodes=set()):
1813  """This is used by self.output_grl?_mathematics to get equations for each variable separately.
1814 
1815  Returns a node set with the equations output.
1816  """
1817  # Work out what equations are needed to compute the derivative of var
1818  if var in self.state_vars:
1819  dvardt = (var, self.free_vars[0])
1820  var_nodeset = self.calculate_extended_dependencies([dvardt])
1821  else:
1822  var_nodeset = set()
1823  # State variable inputs
1824  self.output_state_assignments(nodeset=var_nodeset, assign_rY=assign_rY)
1825  self.writeln()
1826  table_index_nodes_used = self.calculate_lookup_table_indices(var_nodeset, self.code_name(self.free_vars[0]))
1827  self.output_comment('Mathematics')
1828  self.output_equations(var_nodeset - table_index_nodes_used)
1829  return var_nodeset | table_index_nodes_used
def calculate_extended_dependencies
Dependency related methods #.
Definition: translators.py:899
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities (   self)
Output a ComputeDerivedQuantities method if any such quantities exist.

Looks for variables annotated with pycml:derived-quantity=yes, and generates
a method to compute all these variables from a given state.

Definition at line 215 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.calculate_extended_dependencies(), CellMLToNektar.pycml.cellml_model.calculate_extended_dependencies(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.calculate_lookup_table_indices(), CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.derived_quantities, CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.translators.CellMLTranslator.free_vars, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_VECTOR, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_create(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_index(), and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_mathematics().

216  def output_derived_quantities(self):
217  """Output a ComputeDerivedQuantities method if any such quantities exist.
218 
219  Looks for variables annotated with pycml:derived-quantity=yes, and generates
220  a method to compute all these variables from a given state.
221  """
222  dqs = self.derived_quantities
223  if dqs:
224  self.output_method_start('ComputeDerivedQuantities',
225  [self.TYPE_DOUBLE + self.code_name(self.free_vars[0]),
226  'const ' + self.TYPE_VECTOR + '& rY'], # We need it to really be a reference
227  self.TYPE_VECTOR, access='public')
228  self.open_block()
229  self.output_comment('Inputs:')
230  self.output_comment('Time units: ', self.free_vars[0].units)
231  # Work out what equations are needed
232  if self.use_chaste_stimulus:
233  i_stim = [self.doc._cml_config.i_stim_var]
234  else:
235  i_stim = []
236  if self.use_data_clamp:
237  prune = [self.config.i_data_clamp_data]
238  else:
239  prune = []
240  nodeset = self.calculate_extended_dependencies(dqs, prune_deps=i_stim, prune=prune)
241 
242 
243  # State variable inputs
244  self.output_state_assignments(assign_rY=False, nodeset=nodeset)
245  self.writeln()
246  table_index_nodes_used = self.calculate_lookup_table_indices(nodeset, self.code_name(self.free_vars[0]))
247  # Output equations
248  self.output_comment('Mathematics')
249  self.output_equations(nodeset - table_index_nodes_used)
250  self.writeln()
251  # Assign to results vector
252  self.writeln(self.vector_create('dqs', len(dqs)))
253  for i, var in enumerate(dqs):
254  self.writeln(self.vector_index('dqs', i), self.EQ_ASSIGN, self.code_name(var), self.STMT_END)
255  self.writeln('return dqs', self.STMT_END)
256  self.close_block(blank_line=True)
string STMT_END
Various language tokens #.
Definition: translators.py:141
def calculate_extended_dependencies
Dependency related methods #.
Definition: translators.py:899
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations (   self,
  nodeset,
  zero_stimulus = False 
)
Output the mathematics described by nodeset.

nodeset represents a subset of the assignments in the model.
Output assignments in the order given by a topological sort,
but only include those in nodeset.

Definition at line 1145 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.get_stimulus_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), and CellMLToNektar.translators.CellMLTranslator.STMT_END.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations_grl(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl_compute_partial(), and CellMLToNektar.translators.CellMLTranslator.output_table_index_generation().

1146  def output_equations(self, nodeset, zero_stimulus=False):
1147  """Output the mathematics described by nodeset.
1148 
1149  nodeset represents a subset of the assignments in the model.
1150  Output assignments in the order given by a topological sort,
1151  but only include those in nodeset.
1152  """
1153  # Special case for the stimulus current
1154 
1155 
1156  if self.doc._cml_config.i_stim_var in nodeset:
1157  if zero_stimulus:
1158  i_stim = self.doc._cml_config.i_stim_var
1159  stim_assignment = self.code_name(i_stim) + self.EQ_ASSIGN + '0.0' + self.STMT_END
1160  else:
1161  stim_assignment = self.get_stimulus_assignment()
1162 
1163  for expr in (e for e in self.model.get_assignments() if e in nodeset):
1164 
1165  # Special-case the stimulus current
1166  # self.writeln(expr)
1167  # if self.use_chaste_stimulus or zero_stimulus:
1168  # if isinstance(expr, cellml_variable) and expr is self.doc._cml_config.i_stim_var:
1169  # self.writeln(self.TYPE_CONST_DOUBLE, stim_assignment)
1170  # elif not (isinstance(expr, mathml_apply) and
1171  # isinstance(expr.operator(), mathml_eq) and
1172  # isinstance(expr.eq.lhs, mathml_ci) and
1173  # expr.eq.lhs.variable is self.doc._cml_config.i_stim_var):
1174  # self.output_assignment(expr)
1175 
1176 
1177  self.output_assignment(expr)
1178  return
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_evaluate_y_derivatives (   self,
  method_name = 'EvaluateYDerivatives' 
)
Output the EvaluateYDerivatives method.

Definition at line 1356 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.alphas, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.betas, CellMLToNektar.translators.CellMLTranslator.class_name, CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.free_vars, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.infs, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.state_var_type, CellMLToNektar.translators.CellMLTranslator.state_vars, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.taus, CellMLToNektar.translators.CellMLTranslator.TYPE_VOID, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_mathematics().

1357  def output_evaluate_y_derivatives(self, method_name='EvaluateYDerivatives'):
1358  """Output the EvaluateYDerivatives method."""
1359  # Start code output
1360 
1361  #write the method start
1362  self.writeln(self.TYPE_VOID, self.class_name, '::v_Update(')
1363  self.writeln('const Array<OneD, const Array<OneD, NekDouble> >&inarray,', indent_offset=4)
1364  self.writeln(' Array<OneD, Array<OneD, NekDouble> >&outarray,', indent_offset=5)
1365  self.writeln(' const NekDouble var_chaste_interface__environment__time)', indent_offset=13)
1366  self.open_block()
1367  self.writeln('for (unsigned int i = 0; i < m_nq; ++i)')
1368 
1369  self.open_block()
1370  if not self.state_vars:
1371  # This isn't an ODE model!
1372  self.close_block()
1373  return
1374  self.output_comment('Inputs:')
1375  self.output_comment('Time units: ', self.free_vars[0].units)
1377 
1378  # debugging help by writing out the arrays of taus, infs, alphas, betas and dictionary of variable types
1379  # self.writeln('Taus: ' + str(self.taus))
1380  # self.writeln('Infs: ' + str(self.infs))
1381  # self.writeln('Alphas: ' + str(self.alphas))
1382  # self.writeln('Betas: ' + str(self.betas))
1383  # self.writeln('Var Types: ' + str(self.state_var_type)+ '\n')
1384 
1385  #write the taus
1386  self.output_comment('Calculating the tau-values:')
1387  for i,var in enumerate(self.state_vars):
1388  var_name = self.code_name(var, True)
1389  var_actual = str(var)[33:str(var).rfind('__')]
1390  if 'gate' in str(var_name):
1391  after_underscore = var_name[var_name.rfind('__')+2:]
1392 
1393 
1394  if 'membrane__V' in var:
1395  continue
1396 
1397  if self.state_var_type[str(var)] == 'm_gates':
1398  if filter(lambda element: var_actual in element,self.taus):
1399  self.output_comment('The tau value for ' + str(var_actual) + ' should already be calculated in the mathematics')
1400  else:
1401  if filter(lambda element: var_actual in element,self.alphas) and filter(lambda element: var_actual in element,self.betas):
1402  alpha = filter(lambda element: var_actual in element,self.alphas)[0]
1403  beta = filter(lambda element: var_actual in element,self.betas)[0]
1404  new_tau = 'var_' + str(var_actual) + '__tau_' + str(after_underscore)
1405  self.writeln('const NekDouble ' + str(new_tau) + ' = 1.0 / (' + str(alpha) + ' + ' + str(beta) + ');')
1406  self.taus.append(new_tau)
1407  elif self.state_var_type[str(var)] == 'm_concentrations':
1408  continue
1409  self.writeln()
1410 
1411  #write the infs
1412  self.output_comment('Calculating the inf-values:')
1413  for i,var in enumerate(self.state_vars):
1414  var_name = self.code_name(var, True)
1415  var_actual = str(var)[33:str(var).rfind('__')]
1416  if 'gate' in str(var_name):
1417  after_underscore = var_name[var_name.rfind('__')+2:]
1418 
1419 
1420  if 'membrane__V' in str(var):
1421  continue
1422 
1423  if self.state_var_type[str(var)] == 'm_gates':
1424  if filter(lambda element: var_actual in element,self.infs):
1425  self.output_comment('The inf value for ' + str(var_actual) + ' should already be calculated in the mathematics')
1426  else:
1427  if filter(lambda element: var_actual in element,self.alphas) and filter(lambda element: var_actual in element,self.betas):
1428  alpha = filter(lambda element: var_actual in element,self.alphas)[0]
1429  beta = filter(lambda element: var_actual in element,self.betas)[0]
1430  new_inf = 'var_' + str(var_actual) + '__' + str(after_underscore) + '_inf'
1431  self.writeln('const NekDouble ' + str(new_inf) + ' = ' + str(alpha) + ' / (' + str(alpha) + ' + ' + str(beta) + ');')
1432  self.infs.append(new_inf)
1433  elif self.state_var_type[str(var)] == 'm_concentrations':
1434  continue
1435  self.writeln()
1436 
1437  #debugging help by writing out the taus, infs and dictionary of variable types
1438  # self.writeln('Taus: ' + str(self.taus))
1439  # self.writeln('Infs: ' + str(self.infs))
1440  # self.writeln('Var Types: ' + str(self.state_var_type)+ '\n')
1441 
1442 
1443  #writing the outarrays
1444  self.output_comment('Writing the outarrays:')
1445  m_gate_tau_counter = 0
1446 
1447  for i,var in enumerate(self.state_vars):
1448  var_name = self.code_name(var, True)
1449  var_actual = str(var)[33:str(var).rfind('__')]
1450  if 'gate' in str(var_name):
1451  after_underscore = var_name[var_name.rfind('__')+2:]
1452 
1453 
1454 
1455  if 'membrane__V' in str(var):
1456  self.writeln('outarray[',i,'][i] = ' + str(var_name) + ';')
1457 
1458  if self.state_var_type[str(var)] == 'm_gates':
1459  inf_value = filter(lambda element: var_actual in element,self.infs)[0]
1460  tau_value = filter(lambda element: var_actual in element,self.taus)[0]
1461  self.writeln('outarray[',i,'][i] = ' + inf_value + ';')
1462  self.writeln('m_gates_tau[',m_gate_tau_counter,'][i] = ' + tau_value + ';')
1463  m_gate_tau_counter += 1
1464 
1465  if self.state_var_type[str(var)] == 'm_concentrations':
1466  self.writeln('outarray[',i,'][i] = ' + str(var_name) + ';')
1467 
1468  # self.writeln()
1469 
1470 
1471 
1472  self.close_block()
1473  self.close_block()
1474 
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_extra_constructor_content (   self)
Hook for subclasses to add further content to the constructor.

Definition at line 839 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor().

841  """Hook for subclasses to add further content to the constructor."""
842  pass
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_function (   self,
  func_name,
  args,
  posargs,
  kwargs 
)
Override base class method for special case of abs with 2 arguments.

This comes from Maple's Jacobians, and should generate signum of the second argument.

Definition at line 2289 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.translators.CellMLTranslator.output_apply(), CellMLToNektar.translators.CellMLTranslator.output_log(), and CellMLToNektar.translators.CellMLTranslator.output_root().

2290  def output_function(self, func_name, args, *posargs, **kwargs):
2291  """Override base class method for special case of abs with 2 arguments.
2292 
2293  This comes from Maple's Jacobians, and should generate signum of the second argument.
2294  """
2295  args = list(args)
2296  if func_name == 'fabs' and len(args) == 2:
2297  super(CellMLToNektarTranslator, self).output_function('Signum', [args[1]], *posargs, **kwargs)
2298  else:
2299  super(CellMLToNektarTranslator, self).output_function(func_name, args, *posargs, **kwargs)
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic (   self)
Output the GetIIonic method.

Definition at line 1309 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.calculate_extended_dependencies(), CellMLToNektar.pycml.cellml_model.calculate_extended_dependencies(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.calculate_lookup_table_indices(), CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.translators.CellMLTranslator.model, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_variable(), CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_CONST_DOUBLE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_modifiers, CellMLToNektar.translators.CellMLTranslator.varobj(), CellMLToNektar.translators.CellMLTranslator.write(), and CellMLToNektar.translators.CellMLTranslator.writeln().

1310  def output_get_i_ionic(self):
1311  """Output the GetIIonic method."""
1312  use_modifiers = self.use_modifiers
1313  self.use_modifiers = False
1314  self.output_method_start('GetIIonic', ['const std::vector<double>* pStateVariables'],
1315  self.TYPE_DOUBLE, access='public', defaults=['NULL'])
1316  self.open_block()
1317  # Output mathematics to calculate ionic current, using solver_info.ionic_current.
1318  if (hasattr(self.model, u'solver_info') and hasattr(self.model.solver_info, u'ionic_current')):
1319  if not hasattr(self.model.solver_info.ionic_current, u'var'):
1320  raise ValueError('No ionic currents found; check your configuration file')
1321  nodes = map(lambda elt: self.varobj(unicode(elt)),
1322  self.model.solver_info.ionic_current.var)
1323  # GetIIonic must not include the stimulus current
1324  i_stim = self.doc._cml_config.i_stim_var
1325  nodeset = self.calculate_extended_dependencies(nodes, prune_deps=[i_stim])
1326  #print map(lambda v: v.fullname(), nodes)
1327  #print filter(lambda p: p[2]>0, map(debugexpr, nodeset))
1328  # Output main part of maths
1329  self.output_state_assignments(nodeset=nodeset, pointer='pStateVariables')
1330  table_index_nodes_used = self.calculate_lookup_table_indices(nodeset)
1331  self.output_equations(nodeset - table_index_nodes_used, zero_stimulus=True)
1332  self.writeln()
1333  # Assign the total current to a temporary so we can check for NaN
1334  self.writeln(self.TYPE_CONST_DOUBLE, 'i_ionic', self.EQ_ASSIGN, nl=False)
1335  if self.doc._cml_config.i_ionic_negated:
1336  self.writeln('-(', nl=False, indent=False)
1337  plus = False
1338  for varelt in self.model.solver_info.ionic_current.var:
1339  if plus: self.write('+')
1340  else: plus = True
1341  self.output_variable(varelt)
1342  if self.doc._cml_config.i_ionic_negated:
1343  self.writeln(')', nl=False, indent=False)
1344  self.writeln(self.STMT_END, indent=False)
1345  """if self.TYPE_VECTOR_REF == CellMLToCvodeTranslator.TYPE_VECTOR_REF:
1346  self.writeln('if (made_new_cvode_vector)')
1347  self.open_block()
1348  self.writeln('DeleteVector(rY);')
1349  self.close_block(False)"""
1350  self.writeln('EXCEPT_IF_NOT(!std::isnan(i_ionic));')
1351  self.writeln('return i_ionic', self.STMT_END)
1352  else:
1353  self.writeln('return 0.0;')
1354  self.close_block()
1355  self.use_modifiers = use_modifiers
string STMT_END
Various language tokens #.
Definition: translators.py:141
def calculate_extended_dependencies
Dependency related methods #.
Definition: translators.py:899
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl1_mathematics (   self)
Output the special methods needed for GRL1 style cell models.

We generate:
 * UpdateTransmembranePotential update V_m
 * ComputeOneStepExceptVoltage  does a GRL1 update for variables except voltage
 * EvaluateYDerivativeI for each variable I

Definition at line 1894 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.find_grl_partial_derivatives(), CellMLToNektar.translators.CellMLTranslator.free_vars, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations_grl(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl_compute_partial(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start(), CellMLToNektar.translators.CellMLTranslator.state_vars, CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.v_index, CellMLToNektar.translators.CellMLTranslator.v_variable, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_mathematics().

1895  def output_grl1_mathematics(self):
1896  """Output the special methods needed for GRL1 style cell models.
1897 
1898  We generate:
1899  * UpdateTransmembranePotential update V_m
1900  * ComputeOneStepExceptVoltage does a GRL1 update for variables except voltage
1901  * EvaluateYDerivativeI for each variable I
1902  """
1904  ########################################################UpdateTransmembranePotential
1905  self.output_method_start('UpdateTransmembranePotential',
1906  [self.TYPE_DOUBLE + self.code_name(self.free_vars[0])],
1907  'void', access='public')
1908  self.open_block()
1909  self.writeln('std::vector<double>& rY = rGetStateVariables();')
1910  self.writeln('unsigned v_index = GetVoltageIndex();')
1911  self.writeln('const double delta = 1e-8;')
1912  self.writeln()
1913  # Compute partial derivative of dV wrt V
1914  self.writeln(self.TYPE_DOUBLE, self.code_name(self.v_variable, ode=True), self.STMT_END)
1916  self.writeln()
1917  self.writeln('double evalF = ', self.code_name(self.v_variable, ode=True), self.STMT_END)
1918  self.writeln('mEvalF[', self.v_index, '] = ', self.code_name(self.v_variable, ode=True), self.STMT_END)
1919  self.writeln('double partialF = EvaluatePartialDerivative', self.v_index, '(', self.code_name(self.free_vars[0]), ', rY, delta, true);')
1920  self.writeln('if (fabs(partialF) < delta)')
1921  self.open_block()
1922  self.writeln('rY[v_index] += evalF*mDt;')
1923  self.close_block(False)
1924  self.writeln('else')
1925  self.open_block()
1926  self.writeln('rY[v_index] += (evalF/partialF)*(exp(partialF*mDt)-1.0);')
1927  self.close_block()
1928  self.close_block()
1929 
1930  #########################################################ComputeOneStepExceptVoltage
1931  self.output_method_start('ComputeOneStepExceptVoltage',
1932  [self.TYPE_DOUBLE + self.code_name(self.free_vars[0])],
1933  'void', access='public')
1934  self.open_block()
1935  # Set up variables
1936  self.writeln('std::vector<double>& rY = rGetStateVariables();')
1937  self.writeln('const double delta = 1e-8;')
1938  self.writeln()
1939 
1940  # Evaluate RHS of equations (except dV/dt)
1941  non_v_vars = self.state_vars[:]
1942  if self.v_variable in non_v_vars:
1943  non_v_vars.remove(self.v_variable)
1944  self.output_derivative_calculations(non_v_vars)
1945 
1946  # Compute partial derivatives (for non-V)
1947  for i, var in enumerate(self.state_vars):
1948  if var is not self.v_variable:
1949  self.writeln('mEvalF[', i, '] = ', self.code_name(var, ode=True), self.STMT_END)
1950  self.writeln('mPartialF[', i, '] = EvaluatePartialDerivative', i, '(', self.code_name(self.free_vars[0]), ', rY, delta);')
1951 
1952  # Do the GRL updates
1953  for i, var in enumerate(self.state_vars):
1954  if var is not self.v_variable:
1955  self.open_block()
1956  self.writeln('if (fabs(mPartialF[', i, ']) < delta)')
1957  self.open_block()
1958  self.writeln('rY[', i, '] += mDt*', self.code_name(var, True), ';')
1959  self.close_block(False)
1960  self.writeln('else')
1961  self.open_block()
1962  self.writeln('rY[', i, '] += (', self.code_name(var, True), '/mPartialF[', i, '])*(exp(mPartialF[', i, ']*mDt)-1.0);')
1963  self.close_block()
1964  self.close_block()
1965  self.close_block()
1966 
1967  #########################################################Evaluate each equation
1968  for i, var in enumerate(self.state_vars):
1969  self.output_method_start('EvaluateYDerivative'+str(i),
1970  [self.TYPE_DOUBLE + self.code_name(self.free_vars[0]),
1971  'std::vector<double>& rY'],
1972  'double', access='public')
1973  self.open_block()
1974  if var is self.v_variable:
1975  self.writeln(self.TYPE_DOUBLE, self.code_name(self.v_variable, ode=True), self.STMT_END)
1977  self.writeln()
1978  self.writeln('return ', self.code_name(var, True), ';')
1979  self.close_block()
1980 
1981  self.output_grl_compute_partial(i, var)
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl2_mathematics (   self)
Output the special methods needed for GRL2 style cell models.

We generate:
 * Update TransmembranePotential update V_m
 * ComputeOneStepExceptVoltage  does a GRL2 update for variables except voltage
 * EvaluateYDerivativeI for each variable I

Definition at line 1990 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.find_grl_partial_derivatives(), CellMLToNektar.translators.CellMLTranslator.free_vars, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations_grl(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl_compute_partial(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start(), CellMLToNektar.translators.CellMLTranslator.state_vars, CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.v_index, CellMLToNektar.translators.CellMLTranslator.v_variable, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_index(), and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_mathematics().

1991  def output_grl2_mathematics(self):
1992  """Output the special methods needed for GRL2 style cell models.
1993 
1994  We generate:
1995  * Update TransmembranePotential update V_m
1996  * ComputeOneStepExceptVoltage does a GRL2 update for variables except voltage
1997  * EvaluateYDerivativeI for each variable I
1998  """
2000  ########################################################UpdateTransmembranePotential
2001  self.output_method_start('UpdateTransmembranePotential',
2002  [self.TYPE_DOUBLE + self.code_name(self.free_vars[0])],
2003  'void', access='public')
2004  self.open_block()
2005  self.writeln('std::vector<double>& rY = rGetStateVariables();')
2006  self.writeln('const unsigned v_index = GetVoltageIndex();')
2007  self.writeln('const double delta = 1e-8;')
2008  self.writeln('const double yinit = rY[v_index];')
2009  self.writeln()
2010 
2011  # Do the first half step
2012  self.writeln(self.TYPE_DOUBLE, self.code_name(self.v_variable, ode=True), self.STMT_END)
2014  self.writeln()
2015  self.writeln('double evalF = ', self.code_name(self.v_variable, ode=True), self.STMT_END)
2016  self.writeln('mEvalF[', self.v_index, '] = ', self.code_name(self.v_variable, ode=True), self.STMT_END)
2017  self.writeln('double partialF = EvaluatePartialDerivative', self.v_index, '(', self.code_name(self.free_vars[0]), ', rY, delta, true);')
2018  self.writeln('if (fabs(partialF) < delta)')
2019  self.open_block()
2020  self.writeln('rY[v_index] += 0.5*evalF*mDt;')
2021  self.close_block(False)
2022  self.writeln('else')
2023  self.open_block()
2024  self.writeln('rY[v_index] += (evalF/partialF)*(exp(partialF*0.5*mDt)-1.0);')
2025  self.close_block()
2026 
2027  # Do the second half step
2028  self.writeln('rY[v_index] = yinit;')
2029  self.writeln('evalF = EvaluateYDerivative', self.v_index, '(', self.code_name(self.free_vars[0]), ', rY);')
2030  self.writeln('mEvalF[', self.v_index, '] = evalF;')
2031  self.writeln('partialF = EvaluatePartialDerivative', self.v_index, '(', self.code_name(self.free_vars[0]), ', rY, delta, true);')
2032  self.writeln('if (fabs(partialF) < delta)')
2033  self.open_block()
2034  self.writeln('rY[v_index] = yinit + evalF*mDt;')
2035  self.close_block(False)
2036  self.writeln('else')
2037  self.open_block()
2038  self.writeln('rY[v_index] = yinit + (evalF/partialF)*(exp(partialF*mDt)-1.0);')
2039  self.close_block()
2040  self.close_block() # End method
2041 
2042  #########################################################ComputeOneStepExceptVoltage
2043  self.output_method_start('ComputeOneStepExceptVoltage',
2044  [self.TYPE_DOUBLE + self.code_name(self.free_vars[0])],
2045  'void', access='public')
2046  self.open_block()
2047  # Set up variables
2048  self.writeln('std::vector<double>& rY = rGetStateVariables();')
2049  self.writeln('const double delta=1e-8;')
2050  self.writeln('const unsigned size = GetNumberOfStateVariables();')
2051  self.writeln('mYInit = rY;')
2052  self.writeln('double y_save;')
2053  self.writeln()
2054 
2055  # Calculate partial derivatives
2057  for i, var in enumerate(self.state_vars):
2058  self.writeln(self.vector_index('mEvalF', i), self.EQ_ASSIGN, self.code_name(var, True), self.STMT_END)
2059  self.writeln()
2060  for i, var in enumerate(self.state_vars):
2061  if var is not self.v_variable:
2062  self.writeln('mPartialF[', i, '] = EvaluatePartialDerivative', i, '(', self.code_name(self.free_vars[0]), ', rY, delta);')
2063 
2064  # Update all variables
2065  self.writeln('for (unsigned var=0; var<size; var++)')
2066  self.open_block()
2067  self.writeln('if (var == ', self.v_index, ') continue;')
2068  self.writeln('if (fabs(mPartialF[var]) < delta)')
2069  self.open_block()
2070  self.writeln('rY[var] = mYInit[var] + 0.5*mDt*mEvalF[var];')
2071  self.close_block(False)
2072  self.writeln('else')
2073  self.open_block()
2074  self.writeln('rY[var] = mYInit[var] + (mEvalF[var]/mPartialF[var])*(exp(mPartialF[var]*0.5*mDt)-1.0);')
2075  self.close_block()
2076  self.close_block()
2077  self.writeln()
2078 
2079  # Determine new partial derivatives
2080  for i, var in enumerate(self.state_vars):
2081  if var is not self.v_variable:
2082  self.writeln()
2083  self.writeln('y_save = rY[', i, '];')
2084  self.writeln('rY[', i, '] = mYInit[', i, '];')
2085  self.writeln('mEvalF[', i, '] = EvaluateYDerivative', i, '(', self.code_name(self.free_vars[0]), ', rY);')
2086  self.writeln('mPartialF[', i, '] = EvaluatePartialDerivative', i, '(', self.code_name(self.free_vars[0]), ', rY, delta);')
2087  self.writeln('rY[', i, '] = y_save;')
2088 
2089  # Update all variables
2090  self.writeln('for (unsigned var=0; var<size; var++)')
2091  self.open_block()
2092  self.writeln('if (var == ', self.v_index, ') continue;')
2093  self.writeln('if (fabs(mPartialF[var]) < delta)')
2094  self.open_block()
2095  self.writeln('rY[var] = mYInit[var] + mDt*mEvalF[var];')
2096  self.close_block(False)
2097  self.writeln('else')
2098  self.open_block()
2099  self.writeln('rY[var] = mYInit[var] + (mEvalF[var]/mPartialF[var])*(exp(mPartialF[var]*mDt)-1.0);')
2100  self.close_block()
2101  self.close_block()
2102  self.writeln()
2103  self.close_block() # End method
2104 
2105  #########################################################Evaluate each equation
2106  for i, var in enumerate(self.state_vars):
2107  self.output_method_start('EvaluateYDerivative'+str(i),
2108  [self.TYPE_DOUBLE + self.code_name(self.free_vars[0]),
2109  'std::vector<double>& rY'],
2110  'double', access='public')
2111  self.open_block()
2112  if var is self.v_variable:
2113  self.writeln(self.TYPE_DOUBLE, self.code_name(self.v_variable, ode=True), self.STMT_END)
2115  self.writeln()
2116  self.writeln('return '+self.code_name(var, True)+';')
2117  self.close_block()
2118 
2119  self.output_grl_compute_partial(i, var)
2120 
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl_compute_partial (   self,
  i,
  var 
)
Compute the partial derivative of f(var) wrt var, the i'th variable in the state vector.

This uses an analytic Jacobian if available; otherwise it approximates using finite differences.

Definition at line 1848 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator._vars_in(), CellMLToNektar.translators.CellMLTranslator.calculate_extended_dependencies(), CellMLToNektar.pycml.cellml_model.calculate_extended_dependencies(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.calculate_lookup_table_indices(), CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.free_vars, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.jacobian_diagonal, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.translators.CellMLTranslator.output_expr(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl1_mathematics(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl2_mathematics().

1849  def output_grl_compute_partial(self, i, var):
1850  """Compute the partial derivative of f(var) wrt var, the i'th variable in the state vector.
1851 
1852  This uses an analytic Jacobian if available; otherwise it approximates using finite differences.
1853  """
1854  self.output_method_start('EvaluatePartialDerivative'+str(i),
1855  [self.TYPE_DOUBLE + self.code_name(self.free_vars[0]),
1856  'std::vector<double>& rY', 'double delta', 'bool forceNumerical'],
1857  'double', access='public', defaults=['', '', '', 'false'])
1858  self.open_block()
1859  self.writeln('double partialF;')
1860  if self.jacobian_diagonal:
1861  # Work out what equations are needed to compute the analytic derivative
1862  self.writeln('if (!forceNumerical && this->mUseAnalyticJacobian)')
1863  self.open_block()
1864  entry = self.jacobian_diagonal[var]
1865  nodeset = self.calculate_extended_dependencies(self._vars_in(entry))
1866  self.output_state_assignments(nodeset=nodeset, assign_rY=False)
1867  table_index_nodes_used = self.calculate_lookup_table_indices(nodeset|set([entry]), self.code_name(self.free_vars[0]))
1868  self.output_equations(nodeset)
1869  # Calculate the derivative
1870  self.writeln('partialF = ', nl=False)
1871  self.output_expr(entry, paren=False)
1872  self.writeln(self.STMT_END, indent=False)
1873  self.close_block(blank_line=False)
1874  self.writeln('else')
1875  self.open_block()
1876  # Numerical approximation
1877  self.writeln('const double y_save = rY[', i, '];')
1878  self.writeln('rY[', i, '] += delta;')
1879  self.writeln('const double temp = EvaluateYDerivative', i, '(', self.code_name(self.free_vars[0]), ', rY);')
1880  self.writeln('partialF = (temp-mEvalF[', i, '])/delta;')
1881  self.writeln('rY[', i, '] = y_save;')
1882  if self.jacobian_diagonal:
1883  self.close_block(blank_line=False)
1884  self.writeln('return partialF;')
1885  self.close_block()
string STMT_END
Various language tokens #.
Definition: translators.py:141
def calculate_extended_dependencies
Dependency related methods #.
Definition: translators.py:899
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_includes (   self,
  base_class = None 
)
Output the start of each output file.

As well as the #include lines, it also outputs the include guard for
the .hpp file, and doxygen comment.

If base_class is not None (and self.use_backward_euler isn't set)
then includes that class' header instead of AbstractCardiacCell.

If self.dynamically_loadable is set, includes extra headers needed
for that case.

Reads self.include_serialization and self.use_backward_euler.
Sets self.base_class_name and self.class_inheritance.

Definition at line 72 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.add_timestamp, CellMLToNektar.translators.CellMLTranslator.output_doxygen(), CellMLToNektar.translators.CellMLTranslator.subsidiary_filename, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_backward_euler, CellMLToNektar.translators.version_comment(), CellMLToNektar.translators.CellMLTranslator.writeln(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.writeln_hpp().

72 
73  def output_includes(self, base_class=None):
74  """Output the start of each output file.
75 
76  As well as the #include lines, it also outputs the include guard for
77  the .hpp file, and doxygen comment.
78 
79  If base_class is not None (and self.use_backward_euler isn't set)
80  then includes that class' header instead of AbstractCardiacCell.
81 
82  If self.dynamically_loadable is set, includes extra headers needed
83  for that case.
84 
85  Reads self.include_serialization and self.use_backward_euler.
86  Sets self.base_class_name and self.class_inheritance.
87  """
88 
89 
90  from translators import version_comment
91  for sub in [False, True]:
92  self.output_doxygen('@file\n\n',
93  'This source file was generated from CellML.\n\n',
94  'Model: ', self.model.name, '\n\n',
96  '\n\n<autogenerated>',
97  subsidiary=sub)
98  self.writeln(subsidiary=sub)
99 
100 
101  self.writeln('#include <iostream>')
102  self.writeln('#include <string>')
103 
104  # .cpp should include .hpp
105  #writes path
106  self.writeln('#include <CardiacEPSolver/CellModels/', os.path.basename(self.subsidiary_filename), '>')
107  # if self.include_serialization:
108  # self.writeln_hpp('#include "ChasteSerialization.hpp"')
109  # self.writeln_hpp('#include <boost/serialization/base_object.hpp>')
110  #self.writeln('#include <cmath>')
111  #self.writeln('#include <cassert>')
112  #self.writeln('#include <memory>')
113 
114  #write the namespace (and the open bracket)
115  self.writeln()
116  self.writeln('namespace Nektar')
117  self.writeln('{')
118 
119 
120  if self.use_backward_euler:
121  self.writeln_hpp('#include "AbstractBackwardEulerCardiacCell.hpp"')
122  self.writeln('#include "CardiacNewtonSolver.hpp"')
123  self.base_class_name = 'AbstractBackwardEulerCardiacCell<' + \
124  str(self.nonlinear_system_size) + '>'
125  elif self.options.rush_larsen:
126  self.base_class_name = 'AbstractRushLarsenCardiacCell'
127  self.writeln_hpp('#include "' + self.base_class_name + '.hpp"')
128  if not self.doc._cml_rush_larsen:
129  self.writeln('#include "Warnings.hpp"')
130  elif self.options.grl1:
131  self.base_class_name = 'AbstractGeneralizedRushLarsenCardiacCell'
132  self.writeln_hpp('#include "' + self.base_class_name + '.hpp"')
133  elif self.options.grl2: #1992 TODO: merge with above case
134  self.base_class_name = 'AbstractGeneralizedRushLarsenCardiacCell'
135  self.writeln_hpp('#include "' + self.base_class_name + '.hpp"')
136  elif base_class:
137  self.base_class_name = base_class
138  self.writeln_hpp('#include "' + self.base_class_name + '.hpp"')
139  else:
140  self.base_class_name = 'AbstractCardiacCell'
141  # self.writeln_hpp('#include "' + self.base_class_name + '.hpp"')
142  if self.use_modifiers:
143  self.writeln_hpp('#include "AbstractCardiacCellWithModifiers.hpp"')
144  self.writeln_hpp('#include "AbstractModifier.hpp"')
145  # Modify the base class name
146  self.base_class_name = 'AbstractCardiacCellWithModifiers<' + self.base_class_name + ' >'
147  self.class_inheritance = ' : public CellModel'# + self.base_class_name
148  if self.dynamically_loadable:
149  self.writeln_hpp('#include "AbstractDynamicallyLoadableEntity.hpp"')
150  self.class_inheritance += ', public AbstractDynamicallyLoadableEntity'
151  if self.use_protocol:
152  self.writeln_hpp('#include "AbstractTemplatedSystemWithOutputs.hpp"')
153  self.class_inheritance += ', public AbstractTemplatedSystemWithOutputs<' + self.TYPE_VECTOR + '>'
154  #self.writeln('#include "Exception.hpp"')
155  #self.writeln('#include "OdeSystemInformation.hpp"')
156  #self.writeln('#include "RegularStimulus.hpp"')
157  # self.writeln_hpp('#include "AbstractStimulusFunction.hpp"')
158  #self.writeln('#include "HeartConfig.hpp"')
159  #self.writeln('#include "IsNan.hpp"')
160  #self.writeln('#include "MathsCustomFunctions.hpp"')
161  #self.writeln()
162 
163  self.writeln_hpp('#ifndef NEKTAR_SOLVERS_ADRSOLVER_EQUATIONSYSTEMS_', self.include_guard)
164  self.writeln_hpp('#define NEKTAR_SOLVERS_ADRSOLVER_EQUATIONSYSTEMS_', self.include_guard, '\n')
165 
166  self.writeln_hpp('#include <CardiacEPSolver/CellModels/CellModel.h>')
167  self.writeln_hpp('namespace Nektar')
168 
169  self.writeln_hpp()
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_intracellular_calcium (   self)
If a (state) variable has been annotated as cytosolic_calcium_concentration,
generate a GetIntracellularCalciumConcentration method.

Definition at line 431 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start(), CellMLToNektar.translators.CellMLTranslator.state_vars, CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_index(), and CellMLToNektar.translators.CellMLTranslator.writeln().

433  """
434  If a (state) variable has been annotated as cytosolic_calcium_concentration,
435  generate a GetIntracellularCalciumConcentration method.
436  """
437  # Find cytosolic_calcium_concentration
438  cai = self.doc.model.get_variable_by_oxmeta_name('cytosolic_calcium_concentration', throw=False)
439  if cai and cai in self.state_vars:
440  i = self.state_vars.index(cai[0])
441  self.output_method_start('GetIntracellularCalciumConcentration', [], self.TYPE_DOUBLE, 'public')
442  self.open_block()
443  self.writeln('return ', self.vector_index('mStateVariables', i), self.STMT_END)
444  self.close_block(blank_line=True)
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lhs (   self,
  expr 
)
Output the left hand side of an assignment expression.

Definition at line 2260 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_variable().

Referenced by CellMLToNektar.translators.CellMLTranslator.output_assignment().

2261  def output_lhs(self, expr):
2262  """Output the left hand side of an assignment expression."""
2263  if expr.localName == 'ci':
2264  self.output_variable(expr)
2265  elif expr.operator().localName == 'diff':
2266  ci_elt = expr.operands().next()
2267  self.output_variable(ci_elt, ode=True)
2268  return
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class (   self)
Output a separate class for lookup tables.

This will live entirely in the .cpp file.

Definition at line 937 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.lt_class_name, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.translators.CellMLTranslator.output_lut_declarations(), CellMLToNektar.translators.CellMLTranslator.output_lut_deletion(), CellMLToNektar.translators.CellMLTranslator.output_lut_generation(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_indexing_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_memory(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.translators.CellMLTranslator.row_lookup_method, CellMLToNektar.translators.CellMLTranslator.set_indent(), CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_CONST_DOUBLE, CellMLToNektar.translators.CellMLTranslator.var_display_name(), and CellMLToNektar.translators.CellMLTranslator.writeln().

938  def output_lut_class(self):
939  """Output a separate class for lookup tables.
940 
941  This will live entirely in the .cpp file."""
942  # Lookup tables class
943  self.writeln('class ', self.lt_class_name, ' : public AbstractLookupTableCollection')
944  self.writeln('{')
945  self.writeln('public:')
946  self.set_indent(1)
947  # Method to get the table instance object
948  self.writeln('static ', self.lt_class_name, '* Instance()')
949  self.open_block()
950  self.writeln('if (mpInstance.get() == NULL)')
951  self.writeln('{')
952  self.writeln('mpInstance.reset(new ', self.lt_class_name, ');', indent_offset=1)
953  self.writeln('}')
954  self.writeln('return mpInstance.get();')
955  self.close_block()
956  # Method to free the table memory
957  self.writeln('void FreeMemory()')
958  self.open_block()
959  self.output_lut_deletion()
960  self.writeln('mNeedsRegeneration.assign(mNeedsRegeneration.size(), true);')
961  self.close_block()
962  # Table lookup methods
963  self.output_lut_methods()
965  # Destructor
966  self.writeln('~', self.lt_class_name, '()')
967  self.open_block()
968  self.output_lut_deletion()
969  self.close_block()
970  # Make the class a singleton
971  self.writeln('protected:', indent_level=0)
972  self.writeln(self.lt_class_name, '(const ', self.lt_class_name, '&);')
973  self.writeln(self.lt_class_name, '& operator= (const ', self.lt_class_name, '&);')
974  # Constructor
975  self.writeln(self.lt_class_name, '()')
976  self.open_block()
977  self.writeln('assert(mpInstance.get() == NULL);')
978  if self.config.options.include_dt_in_tables:
979  self.writeln('mDt = HeartConfig::Instance()->GetOdeTimeStep();')
980  self.writeln('assert(mDt > 0.0);')
981  num_indexes = len(self.doc.lookup_table_indexes)
982  self.writeln('mKeyingVariableNames.resize(', num_indexes, ');')
983  self.writeln('mNumberOfTables.resize(', num_indexes, ');')
984  self.writeln('mTableMins.resize(', num_indexes, ');')
985  self.writeln('mTableSteps.resize(', num_indexes, ');')
986  self.writeln('mTableStepInverses.resize(', num_indexes, ');')
987  self.writeln('mTableMaxs.resize(', num_indexes, ');')
988  self.writeln('mNeedsRegeneration.resize(', num_indexes, ');')
989  for key, idx in self.doc.lookup_table_indexes.iteritems():
990  min, max, step, var = key
991  num_tables = unicode(self.doc.lookup_tables_num_per_index[idx])
992  self.writeln('mKeyingVariableNames[', idx, '] = "', self.var_display_name(var), '";')
993  self.writeln('mNumberOfTables[', idx, '] = ', num_tables, self.STMT_END)
994  self.writeln('mTableMins[', idx, '] = ', min, self.STMT_END)
995  self.writeln('mTableSteps[', idx, '] = ', step, self.STMT_END)
996  self.writeln('mTableStepInverses[', idx, '] = ', str(1/float(step)), self.STMT_END)
997  self.writeln('mTableMaxs[', idx, '] = ', max, self.STMT_END)
998  self.writeln('mNeedsRegeneration[', idx, '] = true;')
999  self.writeln('_lookup_table_', idx, self.EQ_ASSIGN, 'NULL', self.STMT_END)
1000  self.writeln(self.lt_class_name, '::RegenerateTables();')
1001  self.close_block()
1002  # Table (re-)generation
1003  self.writeln('void RegenerateTables()')
1004  self.open_block()
1005  event_handler = 'AbstractLookupTableCollection::EventHandler::'
1006  self.writeln(event_handler, 'BeginEvent(', event_handler, 'GENERATE_TABLES);')
1007  if self.config.options.include_dt_in_tables:
1008  self.writeln(self.TYPE_CONST_DOUBLE, self.code_name(self.config.dt_variable), ' = mDt;')
1009  # Hack: avoid unused variable warning
1010  self.writeln('double _unused = ', self.code_name(self.config.dt_variable), ';')
1011  self.writeln('_unused = _unused;\n')
1012  for idx in self.doc.lookup_table_indexes.itervalues():
1013  self.writeln('if (mNeedsRegeneration[', idx, '])')
1014  self.open_block()
1015  self.output_lut_deletion(only_index=idx)
1016  self.output_lut_generation(only_index=idx)
1017  self.writeln('mNeedsRegeneration[', idx, '] = false;')
1018  self.close_block(blank_line=True)
1019  self.writeln(event_handler, 'EndEvent(', event_handler, 'GENERATE_TABLES);')
1020  self.close_block()
1021  # Private data
1022  self.writeln('private:', indent_level=0)
1023  self.writeln('/** The single instance of the class */')
1024  self.writeln('static std::auto_ptr<', self.lt_class_name, '> mpInstance;\n')
1025  if self.row_lookup_method:
1028  # Close the class
1029  self.set_indent(0)
1030  self.writeln('};\n')
1031  # Define the instance pointer
1032  self.writeln('std::auto_ptr<', self.lt_class_name, '> ', self.lt_class_name, '::mpInstance;')
1033  self.writeln()
1034  return
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_indexing_methods (   self)
Output methods in the LT class for indexing the tables, and checking index bounds.

These will be methods like
    const double * const IndexTable0(double index_var);
if self.row_lookup_method, or like
    void IndexTable0(double index_var, unsigned& index, double& factor);
otherwise, with
    bool CheckIndex0(double& index_var);
for checking the bounds.

Definition at line 873 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.lut_factor(), CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_checking(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_generation_code(), CellMLToNektar.translators.CellMLTranslator.row_lookup_method, CellMLToNektar.translators.CellMLTranslator.STMT_END, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class().

874  def output_lut_indexing_methods(self):
875  """Output methods in the LT class for indexing the tables, and checking index bounds.
876 
877  These will be methods like
878  const double * const IndexTable0(double index_var);
879  if self.row_lookup_method, or like
880  void IndexTable0(double index_var, unsigned& index, double& factor);
881  otherwise, with
882  bool CheckIndex0(double& index_var);
883  for checking the bounds.
884  """
885  for key, idx in self.doc.lookup_table_indexes.iteritems():
886  varname = self.code_name(key[-1])
887  method_name = 'IndexTable' + str(idx)
888  if self.row_lookup_method:
889  method = 'const double * %s(double %s)' % (method_name, varname)
890  else:
891  factor = self.lut_factor(idx)
892  idx_var = '_table_index_' + str(idx)
893  if factor:
894  factor = ', double& ' + factor
895  method = 'void %s(double %s, unsigned& %s%s)' % (method_name, varname, idx_var, factor)
896  self.writeln(method)
897  self.open_block()
898  self.output_table_index_generation_code(key, idx, call_method=False)
899  if self.row_lookup_method:
900  self.writeln('return _lt_', idx, '_row;')
901  self.close_block()
902  # And check the indexes
903  if self.config.options.check_lt_bounds:
904  self.writeln('#define COVERAGE_IGNORE', indent=False)
905  self.writeln('bool CheckIndex', idx, '(double& ', varname, ')')
906  self.open_block()
907  self.output_table_index_checking(key, idx, call_method=False)
908  self.writeln('return _oob_', idx, self.STMT_END)
909  self.close_block(blank_line=False)
910  self.writeln('#undef COVERAGE_IGNORE\n', indent=False)
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_mathematics (   self)
Output the mathematics in this model.

When backward Euler is used, we do so in 5 methods:
 * UpdateTransmembranePotential  does a forward Euler step for V
 * ComputeOneStepExceptVoltage  co-ordinates a backward Euler step
 * ComputeResidual and ComputeJacobian are used in the Newton iteration
 * GetIIonic returns the total ionic current

Rush-Larsen is implemented similarly, with:
 * EvaluateEquations  evaluate the model derivatives and alpha/beta terms
 * ComputeOneStepExceptVoltage  does a Rush-Larsen update for eligible variables,
   and a forward Euler step for other non-V state variables
Generalised Rush-Larsen methods also have specialised handling; see the
individual methods for details.

For other solvers, only 2 methods are needed:
 * EvaluateYDerivatives computes the RHS of the ODE system
 * GetIIonic is as above

Where derived-quantity annotations are present, we also generate a
ComputeDerivedQuantities method.

Definition at line 1259 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_evaluate_y_derivatives(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl1_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl2_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_backward_euler.

1260  def output_mathematics(self):
1261  """Output the mathematics in this model.
1262 
1263  When backward Euler is used, we do so in 5 methods:
1264  * UpdateTransmembranePotential does a forward Euler step for V
1265  * ComputeOneStepExceptVoltage co-ordinates a backward Euler step
1266  * ComputeResidual and ComputeJacobian are used in the Newton iteration
1267  * GetIIonic returns the total ionic current
1268 
1269  Rush-Larsen is implemented similarly, with:
1270  * EvaluateEquations evaluate the model derivatives and alpha/beta terms
1271  * ComputeOneStepExceptVoltage does a Rush-Larsen update for eligible variables,
1272  and a forward Euler step for other non-V state variables
1273  Generalised Rush-Larsen methods also have specialised handling; see the
1274  individual methods for details.
1275 
1276  For other solvers, only 2 methods are needed:
1277  * EvaluateYDerivatives computes the RHS of the ODE system
1278  * GetIIonic is as above
1279 
1280  Where derived-quantity annotations are present, we also generate a
1281  ComputeDerivedQuantities method.
1282  """
1283  #self.output_get_i_ionic()
1284  if self.options.rush_larsen:
1286  elif self.use_backward_euler:
1288  elif self.options.grl1:
1290  elif self.options.grl2:
1292  else:
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start (   self,
  method_name,
  args,
  ret_type,
  access = None,
  defaults = [] 
)
Output the start of a method declaration/definition.

Will write to both the .hpp and .cpp file.

We keep track of the access of the last method, and only output a new
declaration to the header file if it changes.  The default is to use
the same access specification as last time.

Definition at line 182 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.class_name, CellMLToNektar.utilities.DEBUG(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.set_access(), CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.translators.CellMLTranslator.writeln(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.writeln_hpp().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_chaste_lut_methods(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl1_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl2_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl_compute_partial(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_intracellular_calcium(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_verify_state_variables().

183  def output_method_start(self, method_name, args, ret_type, access=None, defaults=[]):
184  """Output the start of a method declaration/definition.
185 
186  Will write to both the .hpp and .cpp file.
187 
188  We keep track of the access of the last method, and only output a new
189  declaration to the header file if it changes. The default is to use
190  the same access specification as last time.
191  """
192  DEBUG('translator', 'Generating code for method', method_name)
193  if access:
194  self.set_access(access)
195  if ret_type:
196  if ret_type[-1] != ' ':
197  ret_type = ret_type + ' '
198  else:
199  ret_type = ''
200  args_string_cpp = ', '.join(filter(None, map(str, args)))
201  if defaults:
202  assert len(defaults) == len(args)
203  args_with_default = []
204  for (arg, default) in zip(map(str, args), map(str, defaults)):
205  if arg:
206  if default:
207  args_with_default.append(arg + '=' + default)
208  else:
209  args_with_default.append(arg)
210  args_string_hpp = ', '.join(args_with_default)
211  else:
212  args_string_hpp = args_string_cpp
213  self.writeln_hpp(ret_type, method_name, '(', args_string_hpp, ')', self.STMT_END)
214  self.writeln(ret_type, self.class_name, '::', method_name, '(', args_string_cpp, ')')
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_model_attributes (   self)
Output any named model attributes defined in metadata.

Such attributes are given by compound RDF annotations:
  model --pycml:named-attribute--> bnode
  bnode --pycml:name--> Literal(Attribute name, string)
  bnode --pycml:value--> Literal(Attribute value, double)

Definition at line 2121 of file CellMLToNektarTranslator.py.

References CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.translators.CellMLTranslator.model, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_bottom_boilerplate().

2122  def output_model_attributes(self):
2123  """Output any named model attributes defined in metadata.
2124 
2125  Such attributes are given by compound RDF annotations:
2126  model --pycml:named-attribute--> bnode
2127  bnode --pycml:name--> Literal(Attribute name, string)
2128  bnode --pycml:value--> Literal(Attribute value, double)
2129  """
2130  model = self.model
2131  meta_id = model.cmeta_id
2132  attrs = []
2133  if meta_id:
2134  property = cellml_metadata.create_rdf_node(('pycml:named-attribute', NSS['pycml']))
2135  name_prop = cellml_metadata.create_rdf_node(('pycml:name', NSS['pycml']))
2136  value_prop = cellml_metadata.create_rdf_node(('pycml:value', NSS['pycml']))
2137  source = cellml_metadata.create_rdf_node(fragment_id=meta_id)
2138  attr_nodes = cellml_metadata.get_targets(model, source, property)
2139  for node in attr_nodes:
2140  name = cellml_metadata.get_target(model, node, name_prop)
2141  value = cellml_metadata.get_target(model, node, value_prop)
2142  attrs.append((name, value))
2143  for name, value in attrs:
2144  self.writeln('this->mAttributes["', name, '"] = ', value, ';')
2145  if attrs:
2146  self.writeln()
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_nonlinear_state_assignments (   self,
  nodeset = None 
)
Output assignments for nonlinear state variables.

Definition at line 1126 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.nonlinear_system_vars, CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_index(), and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics().

1127  def output_nonlinear_state_assignments(self, nodeset=None):
1128  """Output assignments for nonlinear state variables."""
1129  for i, var in enumerate(self.nonlinear_system_vars):
1130  if not nodeset or var in nodeset:
1131  self.writeln(self.TYPE_DOUBLE, self.code_name(var), self.EQ_ASSIGN,
1132  self.vector_index('rCurrentGuess', i), self.STMT_END)
1133  #621 TODO: maybe convert if state var dimensions include time
1134  self.writeln()
1135  return
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics (   self)
Output the special methods needed for Rush-Larsen style cell models.

We generate:
 * EvaluateEquations  evaluate the model derivatives and alpha/beta terms
 * ComputeOneStepExceptVoltage  does a Rush-Larsen update for eligible variables,
   and a forward Euler step for other non-V state variables

Definition at line 1732 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator._vars_in(), CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.translators.CellMLTranslator.free_vars, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.translators.CellMLTranslator.output_expr(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start(), CellMLToNektar.translators.CellMLTranslator.state_vars, CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_CONST_DOUBLE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, CellMLToNektar.translators.CellMLTranslator.v_variable, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_index(), and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_mathematics().

1734  """Output the special methods needed for Rush-Larsen style cell models.
1735 
1736  We generate:
1737  * EvaluateEquations evaluate the model derivatives and alpha/beta terms
1738  * ComputeOneStepExceptVoltage does a Rush-Larsen update for eligible variables,
1739  and a forward Euler step for other non-V state variables
1740  """
1741  rl_vars = self.doc._cml_rush_larsen
1742  # EvaluateEquations
1743  ###################
1744  self.output_method_start('EvaluateEquations',
1745  [self.TYPE_DOUBLE + self.code_name(self.free_vars[0]),
1746  'std::vector<double> &rDY',
1747  'std::vector<double> &rAlphaOrTau',
1748  'std::vector<double> &rBetaOrInf'],
1749  'void', access='public')
1750  self.open_block()
1751  normal_vars = [v for v in self.state_vars if not v in rl_vars]
1752  nodes, table_nodes = set(), set()
1753  for _, alpha_or_tau, beta_or_inf, _ in rl_vars.itervalues():
1754  table_nodes.add(alpha_or_tau)
1755  nodes.update(self._vars_in(alpha_or_tau))
1756  table_nodes.add(beta_or_inf)
1757  nodes.update(self._vars_in(beta_or_inf))
1758  self.output_derivative_calculations(normal_vars, True, nodes, table_nodes)
1759  # Now assign input vectors
1760  for i, var in enumerate(self.state_vars):
1761  if var in rl_vars:
1762  # Fill in rAlphaOrTau & rBetaOrInf
1763  self.writeln(self.vector_index('rAlphaOrTau', i), self.EQ_ASSIGN, nl=False)
1764  self.output_expr(rl_vars[var][1], False)
1765  self.writeln(self.STMT_END, indent=False)
1766  self.writeln(self.vector_index('rBetaOrInf', i), self.EQ_ASSIGN, nl=False)
1767  self.output_expr(rl_vars[var][2], False)
1768  self.writeln(self.STMT_END, indent=False)
1769  else:
1770  # Fill in rDY
1771  self.writeln(self.vector_index('rDY', i), self.EQ_ASSIGN, self.code_name(var, True), self.STMT_END)
1772  self.close_block()
1773 
1774  # ComputeOneStepExceptVoltage
1775  #############################
1776  self.output_method_start('ComputeOneStepExceptVoltage',
1777  ['const std::vector<double> &rDY',
1778  'const std::vector<double> &rAlphaOrTau',
1779  'const std::vector<double> &rBetaOrInf'],
1780  'void', access='public')
1781  self.open_block()
1782  self.writeln('std::vector<double>& rY = rGetStateVariables();')
1783  for i, var in enumerate(self.state_vars):
1784  if var in rl_vars:
1785  # Rush-Larsen update
1786  conv = rl_vars[var][3] or ''
1787  if conv: conv = '*' + str(conv)
1788  if rl_vars[var][0] == 'ab':
1789  # Alpha & beta formulation
1790  self.open_block()
1791  self.writeln(self.TYPE_CONST_DOUBLE, 'tau_inv = rAlphaOrTau[', i, '] + rBetaOrInf[', i, '];')
1792  self.writeln(self.TYPE_CONST_DOUBLE, 'y_inf = rAlphaOrTau[', i, '] / tau_inv;')
1793  self.writeln('rY[', i, '] = y_inf + (rY[', i, '] - y_inf)*exp(-mDt', conv, '*tau_inv);')
1794  self.close_block(blank_line=False)
1795  else:
1796  # Tau & inf formulation
1797  self.writeln('rY[', i, '] = rBetaOrInf[', i, '] + (rY[', i, '] - rBetaOrInf[', i, '])',
1798  '*exp(-mDt', conv, '/rAlphaOrTau[', i, ']);')
1799  elif var is not self.v_variable:
1800  # Forward Euler update
1801  self.writeln('rY[', i, '] += mDt * rDY[', i, '];')
1802  self.close_block()
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_serialize_method (   self)
This method outputs the boost serialize method for the 
header files that need it.

Definition at line 257 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.class_name, CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.include_serialization, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_modifiers, and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.writeln_hpp().

258  def output_serialize_method(self):
259  """This method outputs the boost serialize method for the
260  header files that need it."""
261  # Serialization
262  if self.include_serialization:
263  # self.writeln_hpp('friend class boost::serialization::access;')
264  self.writeln_hpp('public:')
265  # self.writeln_hpp('template<class Archive>')
266  self.writeln_hpp('/// Creates an instance of this class', indent_offset=1)
267  # self.writeln_hpp('void serialize(Archive & archive, const unsigned int version)')
268  self.writeln_hpp('static CellModelSharedPtr create(', indent_offset=1)
269  self.writeln_hpp('const LibUtilities::SessionReaderSharedPtr& pSession,', indent_offset=3)
270  self.writeln_hpp('const MultiRegions::ExpListSharedPtr& pField)', indent_offset=3)
271  self.open_block(subsidiary=True,indent_offset=1)
272  self.writeln_hpp('return MemoryManager<',self.class_name,'>::AllocateSharedPtr(pSession, pField);',indent_offset=1)
273  # self.writeln_hpp('archive & boost::serialization::base_object<', self.base_class_name,
274  # ' >(*this);')
275  if self.dynamically_loadable:
276  self.writeln_hpp('archive & boost::serialization::base_object<AbstractDynamicallyLoadableEntity>(*this);')
277  if self.use_modifiers:
278  self.output_comment('Despite this class having modifier member variables, they are all added to the', subsidiary=True)
279  self.output_comment('abstract class by the constructor, and archived via that, instead of here.', subsidiary=True)
280  self.close_block(subsidiary=True,indent_offset=1)
281 
282  self.writeln_hpp('/// Name of class',indent_offset=1)
283  self.writeln_hpp('static std::string className;\n',indent_offset=1)
284 
285 
286  class_name_length = len(self.class_name)+1
287  self.writeln_hpp('/// Constructor',indent_offset=1)
288  self.writeln_hpp(self.class_name,'(const LibUtilities::SessionReaderSharedPtr& pSession,',indent_offset=1)
289  self.writeln_hpp(' '*class_name_length, 'const MultiRegions::ExpListSharedPtr& pField);\n',indent_offset=1)
290 
291  self.writeln_hpp('/// Destructor',indent_offset=1)
292  self.writeln_hpp('virtual ~',self.class_name,'() {}\n',indent_offset=1)
293 
294  self.writeln_hpp('protected:')
295  self.writeln_hpp('/// Computes the reaction terms $f(u,v)$ and $g(u,v)$.',indent_offset=1)
296  self.writeln_hpp('virtual void v_Update(',indent_offset=1)
297  self.writeln_hpp('const Array<OneD, const Array<OneD, NekDouble> >&inarray,',indent_offset=3)
298  self.writeln_hpp(' Array<OneD, Array<OneD, NekDouble> >&outarray,',indent_offset=3)
299  self.writeln_hpp('const NekDouble var_chaste_interface__environment__time);\n',indent_offset=3)
300 
301  self.writeln_hpp('/// Prints a summary of the model parameters.',indent_offset=1)
302  self.writeln_hpp('virtual void v_GenerateSummary(SummaryList& s);\n',indent_offset=1)
303 
304  self.writeln_hpp('/// Set initial conditions for the cell model',indent_offset=1)
305  self.writeln_hpp('virtual void v_SetInitialConditions();',indent_offset=1)
306  self.writeln_hpp('};')
307  self.close_block(subsidiary=True)
308  self.writeln_hpp('#endif')
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments (   self,
  exclude_nonlinear = False,
  assign_rY = True,
  nodeset = None,
  pointer = '' 
)
Output statements extracting state variables from their vector.

If exclude_nonlinear is set to true, state variables appearing
in the nonlinear system will not be included.

If nodeset is given, only state variables appearing in nodeset
will be included.

If pointer is given, then the state variables actually appear in the
variable given by pointer, which is of type const std::vector<double>*.

Definition at line 1038 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.COMMENT_START, CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.modifier_call(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.modifier_vars, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.nonlinear_system_vars, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.translators.CellMLTranslator.state_vars, CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_VECTOR_REF, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_modifiers, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_index(), and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations_grl(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl_compute_partial(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class().

1039  pointer=''):
1040  """Output statements extracting state variables from their vector.
1041 
1042  If exclude_nonlinear is set to true, state variables appearing
1043  in the nonlinear system will not be included.
1044 
1045  If nodeset is given, only state variables appearing in nodeset
1046  will be included.
1047 
1048  If pointer is given, then the state variables actually appear in the
1049  variable given by pointer, which is of type const std::vector<double>*.
1050  """
1051  used_vars = set()
1052  for var in self.state_vars:
1053  if ((not exclude_nonlinear or var not in self.nonlinear_system_vars)
1054  and (nodeset is None or var in nodeset)):
1055  used_vars.add(var)
1056  if assign_rY and used_vars:
1057  if pointer:
1058  self.output_comment('For state variable interpolation (SVI) we read in interpolated state variables,')
1059  self.output_comment('otherwise for ionic current interpolation (ICI) we use the state variables of this model (node).')
1060  if self.TYPE_VECTOR_REF == CellMLToNektarTranslator.TYPE_VECTOR_REF:
1061  self.writeln('if (!%s) %s = &rGetStateVariables();' % (pointer, pointer))
1062  self.writeln('const ', self.TYPE_VECTOR_REF, 'rY = *', pointer, self.STMT_END)
1063  else:
1064  self.writeln(self.TYPE_VECTOR_REF, 'rY;')
1065  self.writeln('bool made_new_cvode_vector = false;')
1066  self.writeln('if (!%s)' % (pointer))
1067  self.open_block()
1068  self.writeln('rY = rGetStateVariables();')
1069  self.close_block(False)
1070  self.writeln('else')
1071  self.open_block()
1072  self.writeln('made_new_cvode_vector = true;')
1073  self.writeln('rY = MakeNVector(*%s);' % (pointer))
1074  self.close_block()
1075  else:
1076  self.writeln(self.TYPE_VECTOR_REF, 'rY = rGetStateVariables();')
1077  if self.options.protocol:
1078  low_prop = ('pycml:range-low', NSS['pycml'])
1079  high_prop = ('pycml:range-high', NSS['pycml'])
1080  def check_bound(prop, reln, var, value):
1081  prop_value = var.get_rdf_annotation(prop)
1082  if prop_value:
1083  value = '(%s %s %s ? %s : %s)' % (value, reln, prop_value, prop_value, value)
1084  return value
1085  for i, var in enumerate(self.state_vars):
1086  if var in used_vars:
1087  if self.use_modifiers and var in self.modifier_vars:
1088  value = self.modifier_call(var, self.vector_index('rY', i))
1089  else:
1090  value = self.vector_index('inarray', i) + '[i]'
1091  if self.options.protocol:
1092  value = check_bound(low_prop, '<', var, value)
1093  value = check_bound(high_prop, '>', var, value)
1094  #2116 - use supplied fixed voltage if we're clamping
1095  # if var is self.v_variable:
1096  # value = '(mSetVoltageDerivativeToZero ? this->mFixedVoltage : %s)' % value
1097  self.writeln(self.TYPE_DOUBLE, self.code_name(var),
1098  self.EQ_ASSIGN, value, self.STMT_END)
1099  self.writeln(self.COMMENT_START, 'Units: ', var.units,
1100  '; Initial value: ',
1101  getattr(var, u'initial_value', 'Unknown'))
1102  #621 TODO: maybe convert if state var dimensions include time
1103  self.writeln()
1104  return
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_checking (   self,
  key,
  idx,
  call_method = True 
)
Override base class method to call the methods on the lookup table class if needed.

Definition at line 911 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.lt_class_name, CellMLToNektar.translators.CellMLTranslator.STMT_END, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_indexing_methods(), and CellMLToNektar.translators.CellMLTranslator.output_table_index_generation().

912  def output_table_index_checking(self, key, idx, call_method=True):
913  """Override base class method to call the methods on the lookup table class if needed."""
914  if self.separate_lut_class and call_method:
915  if self.config.options.check_lt_bounds:
916  var = key[-1]
917  varname = self.code_name(var)
918  self.writeln('const bool _oob_', idx, self.EQ_ASSIGN, self.lt_class_name,
919  '::Instance()->CheckIndex', idx, '(', varname, ')', self.STMT_END)
920  else:
921  super(CellMLToNektarTranslator, self).output_table_index_checking(key, idx)
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_generation_code (   self,
  key,
  idx,
  call_method = True 
)
Override base class method to call the methods on the lookup table class if needed.

Definition at line 922 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.lt_class_name, CellMLToNektar.translators.CellMLTranslator.lut_factor(), CellMLToNektar.translators.CellMLTranslator.row_lookup_method, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_indexing_methods(), and CellMLToNektar.translators.CellMLTranslator.output_table_index_generation().

923  def output_table_index_generation_code(self, key, idx, call_method=True):
924  """Override base class method to call the methods on the lookup table class if needed."""
925  if self.separate_lut_class and call_method:
926  var = key[-1]
927  varname = self.code_name(var)
928  method_name = self.lt_class_name + '::Instance()->IndexTable' + str(idx)
929  if self.row_lookup_method:
930  self.writeln('const double* const _lt_', idx, '_row = ', method_name, '(', varname, ');')
931  else:
932  factor = self.lut_factor(idx, include_comma=True)
933  idx_var = '_table_index_' + str(idx)
934  self.writeln(method_name, '(', varname, ', ', idx_var, factor, ');')
935  else:
936  super(CellMLToNektarTranslator, self).output_table_index_generation_code(key, idx)
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_top_boilerplate (   self)
Output top boilerplate.

This method outputs the constructor and destructor of the cell
class, and also lookup table declarations and lookup methods.
It also calls output_verify_state_variables.

Definition at line 464 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.include_serialization, and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_backward_euler.

465  def output_top_boilerplate(self):
466  """Output top boilerplate.
467 
468  This method outputs the constructor and destructor of the cell
469  class, and also lookup table declarations and lookup methods.
470  It also calls output_verify_state_variables.
471  """
472  self.include_serialization = True
473 
474  # Check if we're generating a Backward Euler model
475  self.use_backward_euler = self.model.get_option('backward_euler')
476  self.use_analytic_jacobian = (self.model.get_option('maple_output') and hasattr(self.model.solver_info, u'jacobian'))
477  if self.use_backward_euler:
478  assert hasattr(self.model, u'solver_info')
479  # Find the size of the nonlinear system
480  num_linear_odes = len(self.model.solver_info.xml_xpath(u'solver:linear_odes/m:math/m:apply'))
481  self.nonlinear_system_size = len(self.state_vars) - 1 - num_linear_odes
482  nonlinear_entries = self.model.solver_info.xml_xpath(u'solver:jacobian/solver:entry/@var_j')
483  self.nonlinear_system_vars = map(self.varobj, nonlinear_entries[:self.nonlinear_system_size])
484  # Start output
485  self.output_includes()
486 
487  if self.use_backward_euler or self.options.rush_larsen or self.options.grl1 or self.options.grl2:
488  # Keep the same signature as forward cell models, but note that the solver isn't used
489  solver1 = 'boost::shared_ptr<AbstractIvpOdeSolver> /* unused; should be empty */'
490  solver2 = ''
491  #solver1 = solver2 = ''
492  else: #this currently outputs the boilerplate stuff
493  solver1 = 'boost::shared_ptrALPHA<AbstractIvpOdeSolver> pSolverBRAVO'
494  solver2 = '"' + self.class_name + '"'
495 
496  if self.use_lookup_tables and self.separate_lut_class:
497  self.output_lut_class()
498 
499  # Cell model class
500  self.open_block(subsidiary=True)
501  self.writeln_hpp('class ', self.class_name, self.class_inheritance)
502  self.writeln_hpp('{\n')
503 
504  # Put the boost serialize() method in if requested.
506 
507  # Parameter declarations, and set & get methods (#666)
509  # Constructor
510  self.set_access('public')
511 
512  self.output_constructor([solver1, 'boost::shared_ptr<AbstractStimulusFunction> pIntracellularStimulus'],
513  [solver2, self.class_name + '::create','"Description of the model?"'])
514  # Destructor
515  #self.output_method_start(''+self.class_name, [], '')
516  self.writeln(self.class_name + '::' + self.class_name + '(')
517  self.writeln('const LibUtilities::SessionReaderSharedPtr& pSession,' , indent_offset=3)
518  self.writeln('const MultiRegions::ExpListSharedPtr& pField):', indent_offset=3)
519  self.writeln('CellModel(pSession, pField)', indent_offset=2)
520 
521 
522  self.open_block()
523 
524  #writing out all the state variables as a comment
525  self.writeln('/*')
526  self.writeln('State Variables:')
527  for var in self.state_vars:
528  self.writeln(var)
529  self.writeln()
530  self.writeln('Free Variables:')
531  for var in self.free_vars:
532  self.writeln(var)
533  self.writeln()
534  # for var in self.used_vars:
535  # self.writeln(var)
536  self.writeln('*/\n')
537 
538  #outputting the number of variables in the state_vars list
539  self.writeln('m_nq = pField->GetNpoints();\n')
540  self.writeln('m_nvar = ', len(self.state_vars), ';')
541 
542 
543 
544 
545 
546  #create a list of tau and infs, if present
547  #setting up the arrays to contain the taus, infs, alphas and betas
548  self.taus = []
549  self.infs = []
550  self.alphas = []
551  self.betas = []
552 
553  # creating the nodeset that contains the mathematics
554  state_vars = self.doc.model.find_state_vars()
555  derivs = set(map(lambda v: (v, self.free_vars[0]), state_vars))
556  extra_nodes=set()
557  i_stim = []
558 
559  nonv_nodeset = self.calculate_extended_dependencies(derivs|extra_nodes, prune_deps=i_stim)
560  prune = nonv_nodeset
561  dvdt = (self.v_variable, self.free_vars[0])
562  v_nodeset = self.calculate_extended_dependencies([dvdt], prune=prune, prune_deps=i_stim)
563  all_nodes = nonv_nodeset|v_nodeset
564  extra_table_nodes=set()
565  table_index_nodes_used = self.calculate_lookup_table_indices(all_nodes|extra_table_nodes, self.code_name(self.free_vars[0]))
566  self.NODESET = nonv_nodeset - table_index_nodes_used
567 
568  #searching through the nodeset for all the infs, taus, alphas and betas and adding them to their arrays
569  for expr in (e for e in self.model.get_assignments() if e in self.NODESET):
570  # self.writeln('test')
571  if isinstance(expr, cellml_variable):
572  codename = str(self.code_name(expr))
573  # self.writeln(self.code_name(expr))
574  if 'gate' in codename:
575  if '__tau_'in codename:
576  self.taus.append(codename)
577  if '_inf' in codename:
578  self.infs.append(codename)
579  if '_alpha' in codename:
580  self.alphas.append(codename)
581  if '_beta' in codename:
582  self.betas.append(codename)
583 
584  # debugging help to print the arrays
585  # self.writeln('Taus: ' + str(taus))
586  # self.writeln('Infs: ' + str(infs))
587  # self.writeln('Alphas: ' + str(self.alphas))
588  # self.writeln('Betas: ' + str(self.betas) + '\n')
589 
590  #initialising the gate_vars and concentration_vars counters
591  gate_vars = 0
592  concentration_vars = 0
593  self.state_var_type = {}
594 
595  #finding the actual variable name for each of the state variables
596  for var in self.state_vars:
597  # self.writeln()
598  # self.writeln(var)
599  var_actual = str(var)[33:str(var).rfind('__')]
600  # self.writeln(var_actual)
601 
602 
603  #writing the gate and concentration variables
604  if str(var).find('membrane__V') != -1:
605  self.state_var_type[str(var)] = 'voltage'
606  elif filter(lambda element: var_actual in element,self.infs) and filter(lambda element: var_actual in element,self.taus) or filter(lambda element: var_actual in element,self.alphas) and filter(lambda element: var_actual in element,self.betas):
607  gate_vars += 1
608  # self.writeln(var, ' gating variable')
609  self.writeln('m_gates.push_back(',str(gate_vars),');')
610  self.state_var_type[str(var)] = 'm_gates'
611  # self.writeln()
612  else:
613  gate_vars += 1
614  # self.writeln(var, ' concentration variable')
615  self.writeln('m_concentrations.push_back(',str(gate_vars),');')
616  self.state_var_type[str(var)] = 'm_concentrations'
617  # self.writeln()
618 
619  # self.writeln(self.state_var_type)
620 
621  self.close_block()
622 
623 
624 
625 
626 
627 
628  # Other declarations & methods
631  return
def calculate_extended_dependencies
Dependency related methods #.
Definition: translators.py:899
InputIterator find(InputIterator first, InputIterator last, InputIterator startingpoint, const EqualityComparable &value)
Definition: StdRegions.hpp:316
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_variable (   self,
  ci_elt,
  ode = False 
)
Output a ci element, i.e. a variable lookup.

Definition at line 2269 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.varobj(), and CellMLToNektar.translators.CellMLTranslator.write().

Referenced by CellMLToNektar.translators.CellMLTranslator.output_expr(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.translators.CellMLTranslator.output_lhs(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lhs().

2270  def output_variable(self, ci_elt, ode=False):
2271  """Output a ci element, i.e. a variable lookup."""
2272  if hasattr(ci_elt, '_cml_variable') and ci_elt._cml_variable:
2273  self.write(self.code_name(ci_elt.variable, ode=ode))
2274  else:
2275  # This ci element doesn't have all the extra annotations. It is a fully
2276  # qualified name though. This is typically because PE has been done.
2277  prefix = ['var_', 'd_dt_'][ode]
2278  varname = unicode(ci_elt)
2279  try:
2280  var = self.varobj(varname)
2281  except KeyError:
2282  var = None
2283  if var:
2284  self.write(self.code_name(var, ode=ode))
2285  else:
2286  # Assume it's a suitable name
2287  self.write(prefix + varname)
2288  return
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_verify_state_variables (   self)
Output the VerifyStateVariables method.

This will look for state variables annotated with pycml:range-low and/or pycml:range-high,
which specify allowable ranges for these variables.  The generated method will check that
they are within the range.  Both limits are included, i.e. they specify a closed interval.

Definition at line 639 of file CellMLToNektarTranslator.py.

References CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.translators.CellMLTranslator.model, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_modifiers.

641  """Output the VerifyStateVariables method.
642 
643  This will look for state variables annotated with pycml:range-low and/or pycml:range-high,
644  which specify allowable ranges for these variables. The generated method will check that
645  they are within the range. Both limits are included, i.e. they specify a closed interval.
646  """
647 
648  # First work out if there are any constraints on state variables
649 
650  low_prop = ('pycml:range-low', NSS['pycml'])
651  high_prop = ('pycml:range-high', NSS['pycml'])
652  low_range_vars = filter(
653  lambda v: v.get_type() == VarTypes.State,
654  cellml_metadata.find_variables(self.model, low_prop))
655  high_range_vars = filter(
656  lambda v: v.get_type() == VarTypes.State,
657  cellml_metadata.find_variables(self.model, high_prop))
658  nodeset = set(low_range_vars + high_range_vars)
659 
660  # If not, don't bother writing the method, an empty implementation is in the abstract classes.
661  if nodeset:
662  # It's not appropriate to apply modifiers here - we want to check the actual values of the state
663  use_modifiers = self.use_modifiers
664  self.use_modifiers = False
665 
666  self.output_method_start('VerifyStateVariables', [], 'void')
667  self.open_block()
668 
669  using_cvode = (self.TYPE_VECTOR_REF == CellMLToCvodeTranslator.TYPE_VECTOR_REF)
670  if using_cvode:
671  self.writeln('/* We only expect CVODE to keep state variables to within its tolerances,')
672  self.writeln(' * not exactly the bounds prescribed to each variable that are checked here.')
673  self.writeln(' *')
674  self.writeln(' * For 99.99% of paces this->mAbsTol works,')
675  self.writeln(' * For 99.999% of paces 10*this->mAbsTol is fine,')
676  self.writeln(' * but unfortunately 100x seems to be required on rare occasions for upstrokes.')
677  self.writeln(' * This sounds bad, but is probably typically only 1e-5 or 1e-6.')
678  self.writeln(' */')
679  self.writeln('const double tol = 100*this->mAbsTol;')
680 
681  self.output_state_assignments(nodeset=nodeset)
682  error_template = 'EXCEPTION(DumpState("State variable {0} has gone out of range. Check numerical parameters, for example time and space stepsizes, and/or solver tolerances"));'
683  additional_tolerance_adjustment = ''
684  for var in low_range_vars:
685  if using_cvode:
686  additional_tolerance_adjustment = ' - tol'
687  self.writeln('if (', self.code_name(var), ' < ', var.get_rdf_annotation(low_prop), additional_tolerance_adjustment, ')')
688  self.open_block()
689  #self.writeln('std::cout << "Too small: ', self.code_name(var), ' = " << ', self.code_name(var) , ' << std::endl << std::flush;')
690  self.writeln(error_template.format(self.var_display_name(var)))
691  self.close_block(False)
692  for var in high_range_vars:
693  if using_cvode:
694  additional_tolerance_adjustment = ' + tol'
695  self.writeln('if (', self.code_name(var), ' > ', var.get_rdf_annotation(high_prop), additional_tolerance_adjustment, ')')
696  self.open_block()
697  #self.writeln('std::cout << "Too large: ', self.code_name(var), ' = " << ', self.code_name(var) , ' << std::endl << std::flush;')
698  self.writeln(error_template.format(self.var_display_name(var)))
699  self.close_block(False)
700  self.close_block(True)
701 
702  self.use_modifiers = use_modifiers
703 
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.set_access (   self,
  access 
)
Set the access specification for subsequent output.

We keep track of the last access set, either via this method or
output_method_start, and only output a new declaration to the
header file if it changes.

Definition at line 170 of file CellMLToNektarTranslator.py.

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator._last_method_access, and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.writeln_hpp().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start().

171  def set_access(self, access):
172  """Set the access specification for subsequent output.
173 
174  We keep track of the last access set, either via this method or
175  output_method_start, and only output a new declaration to the
176  header file if it changes.
177  """
178  if access != self._last_method_access:
179  self._last_method_access = access
180  self.writeln_hpp()
181  # self.writeln_hpp(access, ':', indent_offset=-1)
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.translate (   self,
  args,
  kwargs 
)
Generate code for the given model.

Definition at line 44 of file CellMLToNektarTranslator.py.

44 
45  def translate(self, *args, **kwargs):
46  """Generate code for the given model."""
47  our_kwargs = {'use_chaste_stimulus': False,
48  'separate_lut_class': True,
49  'convert_interfaces': False,
50  'use_modifiers': False,
51  'use_data_clamp': False,
52  'dynamically_loadable': False,
53  'use_protocol': False
54  }
55  for key, default in our_kwargs.iteritems():
56  setattr(self, key, kwargs.get(key, default))
57  if key in kwargs:
58  del kwargs[key]
59  # Some other default settings
60  self.use_backward_euler = False
61  self.include_serialization = False
62  # Last method's access specification
63  self._last_method_access = 'private'
64  return super(CellMLToNektarTranslator, self).translate(*args, **kwargs)
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.unsigned_v_index (   self)

Definition at line 633 of file CellMLToNektarTranslator.py.

634  def unsigned_v_index(self):
635  if self.v_index == -1:
636  return 'UNSIGNED_UNSET'
637  else:
638  return str(self.v_index)
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_create (   self,
  vector,
  size 
)
Return code for creating a new vector with the given size.

Definition at line 1118 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.STMT_END, and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_VECTOR.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities().

1119  def vector_create(self, vector, size):
1120  """Return code for creating a new vector with the given size."""
1121  return ''.join(map(str, [self.TYPE_VECTOR, vector, '(', size, ')', self.STMT_END]))
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_index (   self,
  vector,
  i 
)
Return code for accessing the i'th index of vector.

Definition at line 1114 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl2_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_intracellular_calcium(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_nonlinear_state_assignments(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments().

1115  def vector_index(self, vector, i):
1116  """Return code for accessing the i'th index of vector."""
1117  return vector + '[' + str(i) + ']'
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_initialise (   self,
  vector,
  size 
)
Return code for creating an already-declared vector with the given size.

Definition at line 1122 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.STMT_END.

1123  def vector_initialise(self, vector, size):
1124  """Return code for creating an already-declared vector with the given size."""
1125  return ''.join(map(str, [vector, '.resize(', size, ')', self.STMT_END]))
string STMT_END
Various language tokens #.
Definition: translators.py:141
def CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.writeln_hpp (   self,
  args,
  kwargs 
)
Convenience wrapper for writing to the header file.

Definition at line 39 of file CellMLToNektarTranslator.py.

References CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_includes(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_serialize_method(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.set_access().

39 
40  def writeln_hpp(self, *args, **kwargs):
41  """Convenience wrapper for writing to the header file."""
42  kwargs['subsidiary'] = True
43  self.writeln(*args, **kwargs)

Member Data Documentation

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator._last_method_access
private

Definition at line 62 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.set_access().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.alphas

Definition at line 549 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_evaluate_y_derivatives().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.base_class_name

Definition at line 122 of file CellMLToNektarTranslator.py.

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.betas

Definition at line 550 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_evaluate_y_derivatives().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.cell_parameters

Definition at line 320 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_bottom_boilerplate(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.class_inheritance

Definition at line 146 of file CellMLToNektarTranslator.py.

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.derived_quantities

Definition at line 384 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_bottom_boilerplate(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.has_default_stimulus

Definition at line 407 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.include_serialization

Definition at line 60 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_serialize_method(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_top_boilerplate().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.infs

Definition at line 548 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_evaluate_y_derivatives().

string CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.INTERFACE_COMPONENT_NAME = u'chaste_interface'
static

Definition at line 2321 of file CellMLToNektarTranslator.py.

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.jacobian_diagonal

Definition at line 1837 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl_compute_partial().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.lookup_method_prefix

Definition at line 69 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.translators.CellMLTranslator.output_table_index_generation_code(), and CellMLToNektar.translators.CellMLTranslator.output_table_lookup().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.lt_class_name

Definition at line 68 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_chaste_lut_methods(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_checking(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_generation_code().

string CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.MEMBRANE_CAPACITANCE_NAME = u'chaste_membrane_capacitance'
static

Definition at line 2318 of file CellMLToNektarTranslator.py.

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.metadata_vars

Definition at line 338 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.translators.ConfigurationStore.annotate_metadata_for_pe(), and CellMLToNektar.translators.ConfigurationStore.expose_variables().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.modifier_vars

Definition at line 346 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments().

list CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.NODESET = []
static

Definition at line 37 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.NODESET

Definition at line 565 of file CellMLToNektarTranslator.py.

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.nonlinear_system_size

Definition at line 480 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.nonlinear_system_vars

Definition at line 482 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_nonlinear_state_assignments(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.state_var_type

Definition at line 592 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_evaluate_y_derivatives().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.taus

Definition at line 547 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_evaluate_y_derivatives().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_CONST_DOUBLE

Definition at line 1213 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.translators.CellMLTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), CellMLToNektar.translators.CellMLTranslator.output_lut_generation(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), CellMLToNektar.translators.CellMLTranslator.output_single_lookup(), and CellMLToNektar.translators.CellMLTranslator.output_table_index_generation_code().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE

Definition at line 1213 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.translators.CellMLTranslator.lut_factor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl1_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl2_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl_compute_partial(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_intracellular_calcium(), CellMLToNektar.translators.CellMLTranslator.output_lut_declarations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_nonlinear_state_assignments(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments().

string CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_VECTOR = 'std::vector<double> '
static

Definition at line 34 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_create().

string CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_VECTOR_REF = 'std::vector<double>& '
static

Definition at line 35 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_VECTOR_REF

Definition at line 668 of file CellMLToNektarTranslator.py.

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_analytic_jacobian

Definition at line 475 of file CellMLToNektarTranslator.py.

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_backward_euler

Definition at line 59 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_includes(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_mathematics(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_top_boilerplate().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_lookup_tables

Definition at line 364 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.translators.CellMLTranslator._vars_in(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.calculate_lookup_table_indices(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_chaste_lut_methods(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.translators.CellMLTranslator.output_expr(), CellMLToNektar.translators.CellMLTranslator.output_lut_generation(), and CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_modifiers

Definition at line 362 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_serialize_method(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_verify_state_variables().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.USES_SUBSIDIARY_FILE = True
static

Definition at line 31 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.translators.CellMLTranslator.subsidiary_file_name(), and CellMLToNektar.translators.CellMLTranslator.writeln().

CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.v_index

Definition at line 634 of file CellMLToNektarTranslator.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl1_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl2_mathematics(), and CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate().