Nektar++
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
CellMLToNektar.translators.CellMLTranslator Class Reference
Inheritance diagram for CellMLToNektar.translators.CellMLTranslator:
[legend]

Classes

class  NameAlreadyRegistered
 

Public Member Functions

def register (cls, subclass, name)
 
def __init__ (self, add_timestamp=True, options=None)
 
def error (self, lines, xml=None)
 
def config (self)
 
def translate (self, doc, model_filename, output_filename=None, subsidiary_file_name=None, class_name=None, v_variable=None, continuation=None, lookup_method_prefix='', row_lookup_method=False, lt_index_uses_floor=True, constrain_table_indices=False)
 
def final_configuration_hook (self)
 
def output_file_name (self, model_filename)
 
def subsidiary_file_name (self, output_filename)
 
def send_main_output_to_subsidiary (self, to_subsidiary=True)
 
def writeln (self, *args, **kwargs)
 
def write (self, *args)
 
def capture_output (self)
 
def get_captured_output (self)
 
def output_comment (self, *args, **kwargs)
 
def output_doxygen (self, *args, **kwargs)
 
def set_indent (self, level=None, offset=None)
 
def code_name (self, var, ode=False, prefix=None)
 
def varobj (self, varname)
 
def var_display_name (self, var)
 
def include_guard (self)
 
def output_top_boilerplate (self)
 
def output_mathematics (self)
 
def output_bottom_boilerplate (self)
 
def output_assignment (self, expr)
 
def output_lhs (self, expr)
 
def output_variable (self, ci_elt, ode=False)
 
def output_expr (self, expr, paren)
 
def output_number (self, expr)
 
def eval_number (self, expr)
 
def output_apply (self, expr, paren)
 
def output_function (self, func_name, args, paren, reciprocal=False)
 
def output_nary_operator (self, operator, operands, paren)
 
def output_unary_operator (self, operator, operand, paren)
 
def output_binary_operator (self, operator, operands, paren, expr)
 
def output_root (self, expr, paren)
 
def output_log (self, expr, paren)
 
def output_minus (self, expr, paren)
 
def output_piecewise (self, expr, paren)
 
def open_paren (self, paren)
 
def close_paren (self, paren)
 
def open_block (self, **kwargs)
 
def close_block (self, blank_line=True, **kwargs)
 
def calculate_extended_dependencies (self, nodes, prune=[], prune_deps=[])
 Dependency related methods #. More...
 
def output_equations (self, nodeset)
 
def scan_for_lookup_tables (self)
 Lookup table methods #. More...
 
def lut_access_code (self, table_index, table_name, i)
 
def lut_parameters (self, key)
 
def lut_size_calculation (self, min, max, step)
 
def output_lut_generation (self, only_index=None)
 
def output_lut_deletion (self, only_index=None)
 
def output_lut_declarations (self)
 
def output_lut_index_declarations (self, idx)
 
def output_lut_indices (self)
 
def output_lut_methods (self)
 
def output_single_lookup (self, tidx, tname, result)
 
def output_lut_row_lookup_methods (self)
 
def output_lut_row_lookup_memory (self)
 
def is_lookup_table (self, expr)
 
def contained_table_indices (self, node)
 
def lut_factor (self, idx, include_comma=False, include_type=False)
 
def output_table_lookup (self, expr, paren)
 
def output_table_index_generation (self, time_name, nodeset=set())
 
def output_table_index_checking (self, key, idx)
 
def output_table_index_generation_code (self, key, idx)
 

Static Public Member Functions

def generate_interface (doc, solver_info)
 

Public Attributes

 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
 
 USES_SUBSIDIARY_FILE
 

Static Public Attributes

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'
 
bool 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 Member Functions

def _vars_in (self, expr)
 

Private Attributes

 _main_output_to_subsidiary
 
 _original_out
 

Detailed Description

Base class for translators from CellML to programming languages.

Provides various methods & attributes that can be overridden to
achieve the desired output language and style.

Also contains a registration system for subclasses, so the
command-line client can know what translators are available.  See
the register method for more information.

Definition at line 98 of file translators.py.

Constructor & Destructor Documentation

◆ __init__()

def CellMLToNektar.translators.CellMLTranslator.__init__ (   self,
  add_timestamp = True,
  options = None 
)
Create a translator.

Definition at line 167 of file translators.py.

167 def __init__(self, add_timestamp=True, options=None):
168 """Create a translator."""
169 self.options = options
170 # Initially output should not be indented
171 self.indent_level = 0
172 # Character to indent with
173 self.indent_char = ' '
174 # No. of occurrences of indent_char per indent_level
175 self.indent_factor = 4
176 # Whether to use lookup tables where possible
177 self.use_lookup_tables = True
178 # Whether to add a timestamp comment to generated files
179 self.add_timestamp = add_timestamp
180 # Main output goes to the main file by default
181 self._main_output_to_subsidiary = False
182

Member Function Documentation

◆ _vars_in()

def CellMLToNektar.translators.CellMLTranslator._vars_in (   self,
  expr 
)
private
Return a set of variable objects used in the given expression.

Will include state variables.  If the expression includes a derivative, the defining equation
for that derivative will be included in the set.  Also if an expression is being
replaced by a lookup table, this will only include the table key variable.

Definition at line 928 of file translators.py.

928 def _vars_in(self, expr):
929 """Return a set of variable objects used in the given expression.
930
931 Will include state variables. If the expression includes a derivative, the defining equation
932 for that derivative will be included in the set. Also if an expression is being
933 replaced by a lookup table, this will only include the table key variable.
934 """
935 res = set()
936 if self.use_lookup_tables and isinstance(expr, mathml) and self.is_lookup_table(expr):
937 key_var = self.varobj(expr.getAttributeNS(NSS['lut'], u'var'))
938 key_var = key_var.get_source_variable(recurse=True)
939 res.add(key_var)
940 elif isinstance(expr, mathml_ci):
941 varobj = getattr(expr, '_cml_variable', None)
942 if not varobj:
943 varname = unicode(expr)
944 varobj = self.varobj(varname.strip())
945 if varobj:
946 res.add(varobj)
947 elif isinstance(expr, mathml_apply) and expr.operator().localName == u'diff':
948 dep_varname = unicode(expr.ci)
949 varobj = self.varobj(dep_varname.strip())
950 res.add(varobj.get_ode_dependency(self.free_vars[0]))
951 elif hasattr(expr, 'xml_children'):
952 for child in expr.xml_children:
953 res.update(self._vars_in(child))
954 return res
955
956

References CellMLToNektar.translators.CellMLTranslator._vars_in(), CellMLToNektar.translators.CellMLTranslator.free_vars, CellMLToNektar.translators.CellMLTranslator.is_lookup_table(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_lookup_tables, CellMLToNektar.translators.CellMLTranslator.use_lookup_tables, and CellMLToNektar.translators.CellMLTranslator.varobj().

Referenced by CellMLToNektar.translators.CellMLTranslator._vars_in(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl_compute_partial(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics().

◆ calculate_extended_dependencies()

def CellMLToNektar.translators.CellMLTranslator.calculate_extended_dependencies (   self,
  nodes,
  prune = [],
  prune_deps = [] 
)

Dependency related methods #.

Method moved to cellml_model.

Definition at line 899 of file translators.py.

899 def calculate_extended_dependencies(self, nodes, prune=[], prune_deps=[]):
900 """Method moved to cellml_model."""
901
902 # for var in nodes:
903 # self.writeln(var)
904 # self.writeln()
905
906 # for var in self.model.calculate_extended_dependencies(nodes, prune, prune_deps):
907 # self.writeln(var)
908 # self.writeln()
909
910
911 return self.model.calculate_extended_dependencies(nodes, prune, prune_deps)
912

References CellMLToNektar.translators.CellMLTranslator.calculate_extended_dependencies(), CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.pycml.cellml_variable.model(), CellMLToNektar.pycml.mathml.model(), and CellMLToNektar.translators.CellMLTranslator.model.

Referenced by CellMLToNektar.translators.CellMLTranslator.calculate_extended_dependencies(), CellMLToNektar.pycml.cellml_model.calculate_extended_dependencies(), 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().

◆ capture_output()

def CellMLToNektar.translators.CellMLTranslator.capture_output (   self)
Make subsequent output operations write to a string buffer.

Definition at line 405 of file translators.py.

405 def capture_output(self):
406 """Make subsequent output operations write to a string buffer."""
407 self._original_out = self.out
408 self.out = StringIO()
409

◆ close_block()

def CellMLToNektar.translators.CellMLTranslator.close_block (   self,
  blank_line = True,
**  kwargs 
)
Close a code block and decrease indent.

Definition at line 885 of file translators.py.

885 def close_block(self, blank_line=True, **kwargs):
886 """Close a code block and decrease indent."""
887 self.set_indent(offset=-1)
888 self.writeln('}', **kwargs)
889 if blank_line:
890 self.writeln(**kwargs)
891 return
892

References CellMLToNektar.translators.CellMLTranslator.set_indent(), and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_bottom_boilerplate(), CellMLToNektar.translators.CellMLTranslator.output_bottom_boilerplate(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_evaluate_y_derivatives(), 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_lut_class(), 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_methods(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_serialize_method(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.translators.CellMLTranslator.output_table_index_checking(), and CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate().

◆ close_paren()

def CellMLToNektar.translators.CellMLTranslator.close_paren (   self,
  paren 
)

◆ code_name()

def CellMLToNektar.translators.CellMLTranslator.code_name (   self,
  var,
  ode = False,
  prefix = None 
)
Return the full name of var in a form suitable for inclusion in a
source file.

If ode is True then return the name of the derivative of var
instead.  We go directly to the source variable in this case,
rather than including intermediate assignment statements as is
done for connections.

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 442 of file translators.py.

442 def code_name(self, var, ode=False, prefix=None):
443 """
444 Return the full name of var in a form suitable for inclusion in a
445 source file.
446
447 If ode is True then return the name of the derivative of var
448 instead. We go directly to the source variable in this case,
449 rather than including intermediate assignment statements as is
450 done for connections.
451 """
452 if prefix is None:
453 prefix = ['var_', 'd_dt_'][ode]
454 if ode:
455 var = var.get_source_variable(recurse=True)
456 name = prefix + var.fullname(cellml=True)
457 return name
458

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.get_stimulus_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.modifier_call(), CellMLToNektar.translators.CellMLTranslator.output_apply(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), CellMLToNektar.translators.CellMLTranslator.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.translators.CellMLTranslator.output_table_index_checking(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_checking(), CellMLToNektar.translators.CellMLTranslator.output_table_index_generation_code(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_generation_code(), CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_variable(), and CellMLToNektar.translators.CellMLTranslator.output_variable().

◆ config()

def CellMLToNektar.translators.CellMLTranslator.config (   self)
Get the current document's configuration store.

Definition at line 198 of file translators.py.

198 def config(self):
199 """Get the current document's configuration store."""
200 return getattr(self.doc, '_cml_config', None)
201

References Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, and CellMLToNektar.translators.ConfigurationStore.doc.

Referenced by CellMLToNektar.optimize.LookupTableAnalyser.analyse_for_lut(), CellMLToNektar.optimize.LookupTableAnalyser.get_param(), CellMLToNektar.optimize.LookupTableAnalyser.is_allowed_variable(), CellMLToNektar.optimize.LookupTableAnalyser.is_keying_var(), 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_lut_class(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_indexing_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_methods(), CellMLToNektar.translators.CellMLTranslator.output_single_lookup(), CellMLToNektar.translators.CellMLTranslator.output_table_index_checking(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_checking(), CellMLToNektar.translators.CellMLTranslator.output_table_index_generation(), and CellMLToNektar.translators.CellMLTranslator.output_table_index_generation_code().

◆ contained_table_indices()

def CellMLToNektar.translators.CellMLTranslator.contained_table_indices (   self,
  node 
)
Return all lookup tables used directly in computing this node.

If this is an expression node, checks all its children for table
lookups, and returns the set of table indices used.

Definition at line 1220 of file translators.py.

1220 def contained_table_indices(self, node):
1221 """Return all lookup tables used directly in computing this node.
1222
1223 If this is an expression node, checks all its children for table
1224 lookups, and returns the set of table indices used.
1225 """
1226 result = set()
1227 if isinstance(node, amara.bindery.element_base):
1228 if self.is_lookup_table(node):
1229 result.add(node.table_index)
1230 else:
1231 for child in node.xml_children:
1232 result.update(self.contained_table_indices(child))
1233 return result
1234

References CellMLToNektar.translators.CellMLTranslator.contained_table_indices(), and CellMLToNektar.translators.CellMLTranslator.is_lookup_table().

Referenced by CellMLToNektar.translators.CellMLTranslator.contained_table_indices(), and CellMLToNektar.translators.CellMLTranslator.output_table_index_generation().

◆ error()

def CellMLToNektar.translators.CellMLTranslator.error (   self,
  lines,
  xml = None 
)
Raise a translation error.

lines is a list of strings describing what went wrong.
A TranslationError with that message will be raised.

If xml is given, it should be an element, which will be
pretty-printed and included in the error.

Definition at line 183 of file translators.py.

183 def error(self, lines, xml=None):
184 """Raise a translation error.
185
186 lines is a list of strings describing what went wrong.
187 A TranslationError with that message will be raised.
188
189 If xml is given, it should be an element, which will be
190 pretty-printed and included in the error.
191 """
192 if xml is not None:
193 lines.extend(xml.xml(indent = u'yes',
194 omitXmlDeclaration = u'yes').split('\n'))
195 raise TranslationError('\n'.join(lines))
196

Referenced by CellMLToNektar.translators.CellMLTranslator.output_apply(), CellMLToNektar.translators.CellMLTranslator.output_binary_operator(), CellMLToNektar.translators.CellMLTranslator.output_expr(), and CellMLToNektar.translators.CellMLTranslator.writeln().

◆ eval_number()

def CellMLToNektar.translators.CellMLTranslator.eval_number (   self,
  expr 
)
Evaluate a number.

If a (unicode) string, convert to float.
If a cn element, call its evaluate method.

Definition at line 697 of file translators.py.

697 def eval_number(self, expr):
698 """Evaluate a number.
699
700 If a (unicode) string, convert to float.
701 If a cn element, call its evaluate method.
702 """
703 if isinstance(expr, mathml_cn):
704 return expr.evaluate()
705 else:
706 return float(unicode(expr))
707

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

◆ final_configuration_hook()

def CellMLToNektar.translators.CellMLTranslator.final_configuration_hook (   self)
A hook for subclasses to do some final configuration.

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 320 of file translators.py.

320 def final_configuration_hook(self):
321 """A hook for subclasses to do some final configuration."""
322 return
323

◆ generate_interface()

def CellMLToNektar.translators.CellMLTranslator.generate_interface (   doc,
  solver_info 
)
static
Generate an interface component connecting the model to whatever will use it.

Stub method that subclasses can override to implement this functionality.

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 131 of file translators.py.

131 def generate_interface(doc, solver_info):
132 """Generate an interface component connecting the model to whatever will use it.
133
134 Stub method that subclasses can override to implement this functionality.
135 """
136 pass
137

◆ get_captured_output()

def CellMLToNektar.translators.CellMLTranslator.get_captured_output (   self)
Stop capturing output, and return what was captured as a string.

Definition at line 410 of file translators.py.

410 def get_captured_output(self):
411 """Stop capturing output, and return what was captured as a string."""
412 output = self.out.getvalue()
413 self.out = self._original_out
414 return output
415

References CellMLToNektar.translators.CellMLTranslator._original_out, and CellMLToNektar.translators.CellMLTranslator.out.

◆ include_guard()

def CellMLToNektar.translators.CellMLTranslator.include_guard (   self)
Get the include guard (for C/C++ output) for this cell model,
based on the class name.

Definition at line 488 of file translators.py.

488 def include_guard(self):
489 """
490 Get the include guard (for C/C++ output) for this cell model,
491 based on the class name.
492 """
493 return self.class_name.upper() + '_HPP_'
494

References CellMLToNektar.translators.CellMLTranslator.class_name.

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

◆ is_lookup_table()

def CellMLToNektar.translators.CellMLTranslator.is_lookup_table (   self,
  expr 
)
Return True iff expr can be replaced by a lookup table.

Uses annotations from a previous analysis.

Definition at line 1214 of file translators.py.

1214 def is_lookup_table(self, expr):
1215 """Return True iff expr can be replaced by a lookup table.
1216
1217 Uses annotations from a previous analysis."""
1218 return expr.getAttributeNS(NSS['lut'], u'possible', '') == u'yes'
1219

Referenced by CellMLToNektar.translators.CellMLTranslator._vars_in(), CellMLToNektar.translators.CellMLTranslator.contained_table_indices(), and CellMLToNektar.translators.CellMLTranslator.output_expr().

◆ lut_access_code()

def CellMLToNektar.translators.CellMLTranslator.lut_access_code (   self,
  table_index,
  table_name,
  i 
)
Get the code for accessing the i'th element of the given table.

Definition at line 1062 of file translators.py.

1062 def lut_access_code(self, table_index, table_name, i):
1063 """Get the code for accessing the i'th element of the given table.
1064 """
1065 return '_lookup_table_%s[%s][%s]' % (table_index, i, table_name)
1066

Referenced by CellMLToNektar.translators.CellMLTranslator.output_lut_generation(), and CellMLToNektar.translators.CellMLTranslator.output_single_lookup().

◆ lut_factor()

def CellMLToNektar.translators.CellMLTranslator.lut_factor (   self,
  idx,
  include_comma = False,
  include_type = False 
)
Return code for any extra factor needed to do a table lookup.

Will return the empty string unless linear interpolation is being used.

Definition at line 1235 of file translators.py.

1235 def lut_factor(self, idx, include_comma=False, include_type=False):
1236 """Return code for any extra factor needed to do a table lookup.
1237
1238 Will return the empty string unless linear interpolation is being used.
1239 """
1240 if self.config.options.lookup_type == 'linear-interpolation':
1241 factor = '_factor_' + str(idx)
1242 if include_type: factor = self.TYPE_DOUBLE + factor
1243 if include_comma: factor = ', ' + factor
1244 else:
1245 factor = ''
1246 return factor
1247

References CellMLToNektar.optimize.LookupTableAnalyser.config(), CellMLToNektar.translators.CellMLTranslator.config(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, and CellMLToNektar.translators.CellMLTranslator.TYPE_DOUBLE.

Referenced by CellMLToNektar.translators.CellMLTranslator.output_lut_index_declarations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_indexing_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_methods(), CellMLToNektar.translators.CellMLTranslator.output_single_lookup(), CellMLToNektar.translators.CellMLTranslator.output_table_index_generation_code(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_generation_code(), and CellMLToNektar.translators.CellMLTranslator.output_table_lookup().

◆ lut_parameters()

def CellMLToNektar.translators.CellMLTranslator.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, step_inverse) suitable for putting in generated code.

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 1067 of file translators.py.

1067 def lut_parameters(self, key):
1068 """Get the bounds and step size for a particular table.
1069
1070 key should be a key into self.lookup_table_indices.
1071 Returns (min, max, step, step_inverse) suitable for putting in generated code.
1072 """
1073 return key[0:3] + [unicode(1 / float(key[2]))]
1074

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

◆ lut_size_calculation()

def CellMLToNektar.translators.CellMLTranslator.lut_size_calculation (   self,
  min,
  max,
  step 
)
Return the equivalent of '1 + (unsigned)((max-min)/step+0.5)'.

Definition at line 1075 of file translators.py.

1075 def lut_size_calculation(self, min, max, step):
1076 """Return the equivalent of '1 + (unsigned)((max-min)/step+0.5)'."""
1077 return '1 + (unsigned)((%s-%s)/%s+0.5)' % (max, min, step)
1078

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

◆ open_block()

def CellMLToNektar.translators.CellMLTranslator.open_block (   self,
**  kwargs 
)
Open a new code block and increase indent.

Definition at line 881 of file translators.py.

881 def open_block(self, **kwargs):
882 """Open a new code block and increase indent."""
883 self.writeln('{', **kwargs)
884 self.set_indent(offset=1)

References CellMLToNektar.translators.CellMLTranslator.set_indent(), and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_bottom_boilerplate(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_evaluate_y_derivatives(), 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_lut_class(), 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_methods(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_serialize_method(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.translators.CellMLTranslator.output_table_index_checking(), CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_verify_state_variables().

◆ open_paren()

def CellMLToNektar.translators.CellMLTranslator.open_paren (   self,
  paren 
)

◆ output_apply()

def CellMLToNektar.translators.CellMLTranslator.output_apply (   self,
  expr,
  paren 
)
Output an <apply> expression.

paren is True if the context has requested parentheses.

Definition at line 731 of file translators.py.

731 def output_apply(self, expr, paren):
732 """Output an <apply> expression.
733
734 paren is True if the context has requested parentheses.
735 """
736 op = expr.operator()
737 if op.localName in self.function_map:
738 self.output_function(self.function_map[op.localName],
739 expr.operands(), paren)
740 elif op.localName in self.recip_trig:
741 self.output_function(self.function_map[self.recip_trig[op.localName]],
742 expr.operands(), paren, reciprocal=True)
743 elif op.localName == u'root':
744 self.output_root(expr, paren)
745 elif op.localName == u'log':
746 self.output_log(expr, paren)
747 elif op.localName in self.nary_ops:
748 self.output_nary_operator(self.nary_ops[op.localName],
749 expr.operands(), paren)
750 elif op.localName in self.binary_ops:
751 self.output_binary_operator(self.binary_ops[op.localName],
752 expr.operands(), paren, expr)
753 elif op.localName == u'minus':
754 self.output_minus(expr, paren)
755 elif op.localName == u'diff':
756 # ODE occuring on the RHS
757 self.write(self.code_name(op.dependent_variable, ode=True))
758 else:
759 # Unrecognised operator
760 self.error(["Unsupported operator element " + str(op.localName)], xml=expr)
761

References CellMLToNektar.translators.CellMLTranslator.binary_ops, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.error(), CellMLToNektar.translators.CellMLTranslator.function_map, CellMLToNektar.translators.CellMLTranslator.nary_ops, CellMLToNektar.translators.CellMLTranslator.output_binary_operator(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_function(), CellMLToNektar.translators.CellMLTranslator.output_function(), CellMLToNektar.translators.CellMLTranslator.output_log(), CellMLToNektar.translators.CellMLTranslator.output_minus(), CellMLToNektar.translators.CellMLTranslator.output_nary_operator(), CellMLToNektar.translators.CellMLTranslator.output_root(), CellMLToNektar.translators.CellMLTranslator.recip_trig, and CellMLToNektar.translators.CellMLTranslator.write().

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

◆ output_assignment()

def CellMLToNektar.translators.CellMLTranslator.output_assignment (   self,
  expr 
)
Output an assignment expression.

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 592 of file translators.py.

592 def output_assignment(self, expr):
593 """Output an assignment expression."""
594 if isinstance(expr, cellml_variable):
595 # self.writeln('Test')
596 # This may be the assignment of a mapped variable, or a constant
597 t = expr.get_type()
598 if t == VarTypes.Mapped:
599 # self.writeln(self.code_name(expr))
600 self.writeln(self.TYPE_CONST_DOUBLE, self.code_name(expr),
601 self.EQ_ASSIGN,
602 self.code_name(expr.get_source_variable()),
603 self.STMT_END, nl=False)
604 self.output_comment(expr.units, indent=False, pad=True)
605 elif t == VarTypes.Constant:
606 # self.writeln('Test')
607 # self.writeln(self.code_name(expr))
608
609
610 # setting various stim-parameters to zero, since Nektar uses its own stimulus
611 if 'stim_amplitude' in str(self.code_name(expr)):
612 self.writeln(self.TYPE_CONST_DOUBLE, self.code_name(expr),
613 self.EQ_ASSIGN, nl=False)
614 self.output_number(0)
615 self.writeln(self.STMT_END, indent=False, nl=False)
616 self.output_comment(expr.units, indent=False, pad=True)
617 else:
618 self.writeln(self.TYPE_CONST_DOUBLE, self.code_name(expr),
619 self.EQ_ASSIGN, nl=False)
620 self.output_number(expr.initial_value)
621 self.writeln(self.STMT_END, indent=False, nl=False)
622 self.output_comment(expr.units, indent=False, pad=True)
623 else:
624 # This is a mathematical expression
625 self.writeln(self.TYPE_CONST_DOUBLE, nl=False)
626 opers = expr.operands()
627 self.output_lhs(opers.next())
628 self.write(self.EQ_ASSIGN)
629 self.output_expr(opers.next(), False)
630 self.writeln(self.STMT_END, indent=False, nl=False)
631 #1365: add a comment with the LHS units
632 self.output_comment(expr._get_element_units(expr.eq.lhs, return_set=False).description(),
633 indent=False, pad=True)
634
def description(self, force=False, cellml=False)
Definition: pycml.py:2670

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.code_name(), CellMLToNektar.pycml.description(), CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.translators.CellMLTranslator.output_expr(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lhs(), CellMLToNektar.translators.CellMLTranslator.output_lhs(), CellMLToNektar.translators.CellMLTranslator.output_number(), CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_CONST_DOUBLE, CellMLToNektar.translators.CellMLTranslator.TYPE_CONST_DOUBLE, CellMLToNektar.translators.CellMLTranslator.write(), and CellMLToNektar.translators.CellMLTranslator.writeln().

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

◆ output_binary_operator()

def CellMLToNektar.translators.CellMLTranslator.output_binary_operator (   self,
  operator,
  operands,
  paren,
  expr 
)
Output a binary operator.

As output_nary_operator, but checks that len(list(operands)) == 2.

Definition at line 802 of file translators.py.

802 def output_binary_operator(self, operator, operands, paren, expr):
803 """Output a binary operator.
804
805 As output_nary_operator, but checks that len(list(operands)) == 2.
806 """
807 operands = list(operands)
808 if len(operands) != 2:
809 self.error(["Binary operator" + operator +
810 "does not have 2 operands."], xml=expr)
811 self.output_nary_operator(operator, operands, paren)
812

References CellMLToNektar.translators.CellMLTranslator.error(), and CellMLToNektar.translators.CellMLTranslator.output_nary_operator().

Referenced by CellMLToNektar.translators.CellMLTranslator.output_apply(), and CellMLToNektar.translators.CellMLTranslator.output_minus().

◆ output_bottom_boilerplate()

def CellMLToNektar.translators.CellMLTranslator.output_bottom_boilerplate (   self)
Output bottom boilerplate

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 580 of file translators.py.

580 def output_bottom_boilerplate(self):
581 """Output bottom boilerplate"""
582 self.writeln('\n')
583 for i, var in enumerate(self.state_vars):
584 self.writeln('rDY[', str(i), '] = ', self.code_name(var, True),
585 ';')
586 self.close_block()
587 self.set_indent(offset=-1)
588 self.writeln('};\n')
589 self.writeln('#endif')
590 return
591

References CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.set_indent(), CellMLToNektar.translators.CellMLTranslator.state_vars, and CellMLToNektar.translators.CellMLTranslator.writeln().

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

◆ output_comment()

def CellMLToNektar.translators.CellMLTranslator.output_comment (   self,
args,
**  kwargs 
)
Output a (multi-line) string as a comment.

Definition at line 416 of file translators.py.

416 def output_comment(self, *args, **kwargs):
417 """Output a (multi-line) string as a comment."""
418 start = kwargs.get('start', self.COMMENT_START)
419 if kwargs.get('pad', False):
420 start = ' ' + start
421 comment = ''.join(map(str, args))
422 lines = comment.split('\n')
423 for line in lines:
424 self.writeln(start, line, **kwargs)
425

References CellMLToNektar.translators.CellMLTranslator.COMMENT_START, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), CellMLToNektar.translators.CellMLTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations_grl(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.translators.CellMLTranslator.output_doxygen(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_evaluate_y_derivatives(), CellMLToNektar.translators.CellMLTranslator.output_lut_declarations(), CellMLToNektar.translators.CellMLTranslator.output_lut_indices(), CellMLToNektar.translators.CellMLTranslator.output_lut_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_memory(), CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_methods(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_serialize_method(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.translators.CellMLTranslator.output_table_index_generation(), and CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate().

◆ output_doxygen()

def CellMLToNektar.translators.CellMLTranslator.output_doxygen (   self,
args,
**  kwargs 
)
Output a (multi-line) string as a Doxygen comment.

Definition at line 426 of file translators.py.

426 def output_doxygen(self, *args, **kwargs):
427 """Output a (multi-line) string as a Doxygen comment."""
428 kwargs['start'] = self.DOXYGEN_COMMENT_START
429 self.output_comment(*args, **kwargs)
430

References CellMLToNektar.translators.CellMLTranslator.DOXYGEN_COMMENT_START, and CellMLToNektar.translators.CellMLTranslator.output_comment().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_includes().

◆ output_equations()

def CellMLToNektar.translators.CellMLTranslator.output_equations (   self,
  nodeset 
)
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.

Since a set of assignments is given, this method does not
check whether variables are used - it is assumed that only
assignments that are actually wanted are given in nodeset.

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 913 of file translators.py.

913 def output_equations(self, nodeset):
914 """Output the mathematics described by nodeset.
915
916 nodeset represents a subset of the assignments in the model.
917 Output assignments in the order given by a topological sort,
918 but only include those in nodeset.
919
920 Since a set of assignments is given, this method does not
921 check whether variables are used - it is assumed that only
922 assignments that are actually wanted are given in nodeset.
923 """
924 for expr in (e for e in self.model.get_assignments() if e in nodeset):
925 self.output_assignment(expr)
926 return
927

References CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.pycml.cellml_variable.model(), CellMLToNektar.pycml.mathml.model(), CellMLToNektar.translators.CellMLTranslator.model, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), and CellMLToNektar.translators.CellMLTranslator.output_assignment().

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

◆ output_expr()

def CellMLToNektar.translators.CellMLTranslator.output_expr (   self,
  expr,
  paren 
)
Output the expression expr.

If paren is True then the context has requested parentheses around the
output; if expr requires them then they will be added.

Definition at line 646 of file translators.py.

646 def output_expr(self, expr, paren):
647 """Output the expression expr.
648
649 If paren is True then the context has requested parentheses around the
650 output; if expr requires them then they will be added.
651 """
652 if self.use_lookup_tables and self.is_lookup_table(expr):
653 self.output_table_lookup(expr, paren)
654 elif isinstance(expr, mathml_apply):
655 self.output_apply(expr, paren)
656 elif isinstance(expr, mathml_piecewise):
657 self.output_piecewise(expr, paren)
658 elif isinstance(expr, mathml_ci):
659 self.output_variable(expr)
660 elif expr.localName == u'cn':
661 self.output_number(expr)
662 elif expr.localName == u'degree':
663 # <degree> is just a wrapper around an expression
664 self.output_expr(child_i(expr, 1), paren)
665 elif expr.localName == u'logbase':
666 # <logbase> is just a wrapper around an expression
667 self.output_expr(child_i(expr, 1), paren)
668 elif expr.localName == u'true':
669 self.write(self.TRUE)
670 elif expr.localName == u'false':
671 self.write(self.FALSE)
672 elif expr.localName == u'pi':
673 self.write(self.PI)
674 elif expr.localName == u'exponentiale':
675 self.write(self.E)
676 else:
677 self.error(["Unsupported expression element " + expr.localName],
678 xml=expr)
679
def child_i(elt, i)
Definition: pycml.py:3449

References CellMLToNektar.pycml.child_i(), Nektar::LibUtilities::FractionalInTimeIntegrationScheme::Instance.E, CellMLToNektar.translators.CellMLTranslator.E, CellMLToNektar.translators.CellMLTranslator.error(), CellMLToNektar.translators.CellMLTranslator.FALSE, CellMLToNektar.translators.CellMLTranslator.is_lookup_table(), CellMLToNektar.translators.CellMLTranslator.output_apply(), CellMLToNektar.translators.CellMLTranslator.output_expr(), CellMLToNektar.translators.CellMLTranslator.output_number(), CellMLToNektar.translators.CellMLTranslator.output_piecewise(), CellMLToNektar.translators.CellMLTranslator.output_table_lookup(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_variable(), CellMLToNektar.translators.CellMLTranslator.output_variable(), CellMLToNektar.translators.CellMLTranslator.PI, CellMLToNektar.translators.CellMLTranslator.TRUE, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_lookup_tables, CellMLToNektar.translators.CellMLTranslator.use_lookup_tables, and CellMLToNektar.translators.CellMLTranslator.write().

Referenced by CellMLToNektar.translators.CellMLTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.translators.CellMLTranslator.output_expr(), CellMLToNektar.translators.CellMLTranslator.output_function(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl_compute_partial(), CellMLToNektar.translators.CellMLTranslator.output_log(), CellMLToNektar.translators.CellMLTranslator.output_lut_generation(), CellMLToNektar.translators.CellMLTranslator.output_nary_operator(), CellMLToNektar.translators.CellMLTranslator.output_piecewise(), CellMLToNektar.translators.CellMLTranslator.output_root(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), and CellMLToNektar.translators.CellMLTranslator.output_unary_operator().

◆ output_file_name()

def CellMLToNektar.translators.CellMLTranslator.output_file_name (   self,
  model_filename 
)
Generate a name for our output file, based on the input file.

Definition at line 324 of file translators.py.

324 def output_file_name(self, model_filename):
325 """Generate a name for our output file, based on the input file."""
326 return os.path.splitext(model_filename)[0] + '.cpp'
327

◆ output_function()

def CellMLToNektar.translators.CellMLTranslator.output_function (   self,
  func_name,
  args,
  paren,
  reciprocal = False 
)
Output a function call with name func_name and arguments args.

Parentheses are not required so paren is ignored.
If reciprocal is True then pass the reciprocal of each arg to
func_name.

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 762 of file translators.py.

762 def output_function(self, func_name, args, paren, reciprocal=False):
763 """Output a function call with name func_name and arguments args.
764
765 Parentheses are not required so paren is ignored.
766 If reciprocal is True then pass the reciprocal of each arg to
767 func_name.
768 """
769 self.write(func_name + '(')
770 comma = False
771 for arg in args:
772 if comma: self.write(', ')
773 else: comma = True
774 if reciprocal:
775 self.write('1/')
776 self.output_expr(arg, True)
777 else:
778 self.output_expr(arg, False)
779 self.write(')')
780

References CellMLToNektar.translators.CellMLTranslator.output_expr(), and CellMLToNektar.translators.CellMLTranslator.write().

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

◆ output_lhs()

def CellMLToNektar.translators.CellMLTranslator.output_lhs (   self,
  expr 
)
Output the left hand side of an assignment expression.

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 635 of file translators.py.

635 def output_lhs(self, expr):
636 """Output the left hand side of an assignment expression."""
637 if expr.localName == 'ci':
638 self.output_variable(expr)
639 elif expr.operator().localName == 'diff':
640 self.write(self.code_name(expr.operator().dependent_variable, ode=True))
641

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

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

◆ output_log()

def CellMLToNektar.translators.CellMLTranslator.output_log (   self,
  expr,
  paren 
)
Output a logarithm to the given base, which defaults to base 10.

Definition at line 833 of file translators.py.

833 def output_log(self, expr, paren):
834 """Output a logarithm to the given base, which defaults to base 10."""
835 if hasattr(expr, u'logbase'):
836 # A base is provided. Use the identity log_b(x) = log(x)/log(b)
837 # TODO: Optimise for log2(x)
838 self.open_paren(paren)
839 self.output_function('log', expr.operands(), paren)
840 self.write('/log(')
841 self.output_expr(expr.logbase, False)
842 self.write(')')
843 self.close_paren(paren)
844 else:
845 # Use base 10
846 self.output_function('log10', expr.operands(), paren)
847

References CellMLToNektar.translators.CellMLTranslator.close_paren(), CellMLToNektar.translators.CellMLTranslator.open_paren(), CellMLToNektar.translators.CellMLTranslator.output_expr(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_function(), CellMLToNektar.translators.CellMLTranslator.output_function(), and CellMLToNektar.translators.CellMLTranslator.write().

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

◆ output_lut_declarations()

def CellMLToNektar.translators.CellMLTranslator.output_lut_declarations (   self)
Output declarations for the lookup tables.

Definition at line 1126 of file translators.py.

1126 def output_lut_declarations(self):
1127 """Output declarations for the lookup tables."""
1128 self.output_comment('Lookup tables')
1129 # Allocate memory, per index variable for cache efficiency
1130 for idx in self.doc.lookup_table_indexes.itervalues():
1131 num_tables = unicode(self.doc.lookup_tables_num_per_index[idx])
1132 self.writeln(self.TYPE_DOUBLE, '(*_lookup_table_', idx, ')[', num_tables, ']', self.STMT_END)
1133 self.writeln()
1134

References Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, CellMLToNektar.translators.ConfigurationStore.doc, CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_DOUBLE, CellMLToNektar.translators.CellMLTranslator.TYPE_DOUBLE, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), and CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate().

◆ output_lut_deletion()

def CellMLToNektar.translators.CellMLTranslator.output_lut_deletion (   self,
  only_index = None 
)
Output code to delete memory allocated for lookup tables.

Definition at line 1116 of file translators.py.

1116 def output_lut_deletion(self, only_index=None):
1117 """Output code to delete memory allocated for lookup tables."""
1118 for idx in self.doc.lookup_table_indexes.itervalues():
1119 if only_index is None or only_index == idx:
1120 self.writeln('if (_lookup_table_', idx, ')')
1121 self.open_block()
1122 self.writeln('delete[] _lookup_table_', idx, self.STMT_END)
1123 self.writeln('_lookup_table_', idx, self.EQ_ASSIGN, 'NULL', self.STMT_END)
1124 self.close_block(blank_line=False)
1125

References CellMLToNektar.translators.CellMLTranslator.close_block(), Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, CellMLToNektar.translators.ConfigurationStore.doc, CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.translators.CellMLTranslator.STMT_END, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), and CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate().

◆ output_lut_generation()

def CellMLToNektar.translators.CellMLTranslator.output_lut_generation (   self,
  only_index = None 
)
Output code to generate lookup tables.

There should be a list of suitable expressions available as self.doc.lookup_tables,
to save having to search the whole model.

If only_index is given, only generate tables using the given table index key.

Definition at line 1079 of file translators.py.

1079 def output_lut_generation(self, only_index=None):
1080 """Output code to generate lookup tables.
1081
1082 There should be a list of suitable expressions available as self.doc.lookup_tables,
1083 to save having to search the whole model.
1084
1085 If only_index is given, only generate tables using the given table index key.
1086 """
1087 # Don't use table lookups to generate the tables!
1088 self.use_lookup_tables = False
1089 # Allocate memory for tables
1090 for key, idx in self.doc.lookup_table_indexes.iteritems():
1091 if only_index is None or only_index == idx:
1092 min, max, step, _ = self.lut_parameters(key)
1093 self.writeln(self.TYPE_CONST_UNSIGNED, '_table_size_', idx, self.EQ_ASSIGN,
1094 self.lut_size_calculation(min, max, step), self.STMT_END)
1095 self.writeln('_lookup_table_', idx, self.EQ_ASSIGN, 'new double[_table_size_', idx,
1096 '][', self.doc.lookup_tables_num_per_index[idx], ']', self.STMT_END)
1097 # Generate each table in a separate loop
1098 for expr in self.doc.lookup_tables:
1099 var = expr.component.get_variable_by_name(expr.var)
1100 key = (expr.min, expr.max, expr.step, var.get_source_variable(recurse=True))
1101 idx = self.doc.lookup_table_indexes[key]
1102 if only_index is not None and only_index != idx:
1103 continue
1104 min, max, step, _ = self.lut_parameters(key)
1105 j = expr.table_name
1106 self.writeln('for (unsigned i=0 ; i<_table_size_', idx, '; i++)')
1107 self.open_block()
1108 self.writeln(self.TYPE_CONST_DOUBLE, self.code_name(var), self.EQ_ASSIGN, min,
1109 ' + i*', step, self.STMT_END)
1110 self.writeln(self.lut_access_code(idx, j, 'i'), self.EQ_ASSIGN, nl=False)
1111 self.output_expr(expr, False)
1112 self.writeln(self.STMT_END, indent=False)
1113 self.close_block()
1114 self.use_lookup_tables = True
1115

References CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.code_name(), Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, CellMLToNektar.translators.ConfigurationStore.doc, CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.translators.CellMLTranslator.lut_access_code(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.lut_parameters(), CellMLToNektar.translators.CellMLTranslator.lut_parameters(), CellMLToNektar.translators.CellMLTranslator.lut_size_calculation(), CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.translators.CellMLTranslator.output_expr(), CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_CONST_DOUBLE, CellMLToNektar.translators.CellMLTranslator.TYPE_CONST_DOUBLE, CellMLToNektar.translators.CellMLTranslator.TYPE_CONST_UNSIGNED, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_lookup_tables, CellMLToNektar.translators.CellMLTranslator.use_lookup_tables, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), and CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate().

◆ output_lut_index_declarations()

def CellMLToNektar.translators.CellMLTranslator.output_lut_index_declarations (   self,
  idx 
)
Output declarations the variables used to index this table.

Definition at line 1135 of file translators.py.

1135 def output_lut_index_declarations(self, idx):
1136 """Output declarations the variables used to index this table."""
1137 self.writeln('unsigned _table_index_', idx, self.STMT_END)
1138 factor = self.lut_factor(idx, include_type=True)
1139 if factor:
1140 self.writeln(factor, self.STMT_END)
1141 if self.row_lookup_method:
1142 self.writeln('double* _lt_', idx, '_row', self.STMT_END)
1143

References CellMLToNektar.translators.CellMLTranslator.lut_factor(), CellMLToNektar.translators.CellMLTranslator.row_lookup_method, CellMLToNektar.translators.CellMLTranslator.STMT_END, and CellMLToNektar.translators.CellMLTranslator.writeln().

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

◆ output_lut_indices()

def CellMLToNektar.translators.CellMLTranslator.output_lut_indices (   self)
Output declarations for the lookup table indices.

Definition at line 1144 of file translators.py.

1144 def output_lut_indices(self):
1145 """Output declarations for the lookup table indices."""
1146 self.output_comment('Lookup table indices')
1147 for idx in self.doc.lookup_table_indexes.itervalues():
1148 self.output_lut_index_declarations(idx)
1149 self.writeln()
1150

References Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, CellMLToNektar.translators.ConfigurationStore.doc, CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.translators.CellMLTranslator.output_lut_index_declarations(), and CellMLToNektar.translators.CellMLTranslator.writeln().

◆ output_lut_methods()

def CellMLToNektar.translators.CellMLTranslator.output_lut_methods (   self)
Output the methods which look up values from lookup tables.

Definition at line 1151 of file translators.py.

1151 def output_lut_methods(self):
1152 """Output the methods which look up values from lookup tables."""
1153 if self.row_lookup_method:
1154 self.output_lut_row_lookup_methods()
1155 return
1156 self.output_comment('Methods to look up values from lookup tables')
1157 self.output_comment('using ', self.config.options.lookup_type)
1158 for expr in self.doc.lookup_tables:
1159 j = expr.table_name
1160 idx = expr.table_index
1161 self.writeln('inline double _lookup_', j, '(unsigned i',
1162 self.lut_factor('', include_type=True, include_comma=True), ')')
1163 self.open_block()
1164 self.output_single_lookup(idx, j, 'return ')
1165 self.close_block()
1166 self.writeln()
1167 return
1168

References CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.optimize.LookupTableAnalyser.config(), CellMLToNektar.translators.CellMLTranslator.config(), Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, CellMLToNektar.translators.ConfigurationStore.doc, CellMLToNektar.translators.CellMLTranslator.lut_factor(), CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_methods(), CellMLToNektar.translators.CellMLTranslator.output_single_lookup(), CellMLToNektar.translators.CellMLTranslator.row_lookup_method, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), and CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate().

◆ output_lut_row_lookup_memory()

def CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_memory (   self)
Output declarations for the memory used by the row lookup methods.

Definition at line 1204 of file translators.py.

1204 def output_lut_row_lookup_memory(self):
1205 """Output declarations for the memory used by the row lookup methods."""
1206 self.output_comment('Row lookup methods memory')
1207 for key, idx in self.doc.lookup_table_indexes.iteritems():
1208 min, max, step, var = key
1209 num_tables = unicode(self.doc.lookup_tables_num_per_index[idx])
1210 self.writeln('double _lookup_table_', idx, '_row[', num_tables, '];')
1211 self.writeln()
1212 return
1213

References Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, CellMLToNektar.translators.ConfigurationStore.doc, CellMLToNektar.translators.CellMLTranslator.output_comment(), and CellMLToNektar.translators.CellMLTranslator.writeln().

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

◆ output_lut_row_lookup_methods()

def CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_methods (   self)
Write methods that return a whole row of a lookup table.

Note: assumes that table names are numbered sequentially from 0.

Definition at line 1183 of file translators.py.

1183 def output_lut_row_lookup_methods(self):
1184 """Write methods that return a whole row of a lookup table.
1185
1186 Note: assumes that table names are numbered sequentially from 0.
1187 """
1188 self.output_comment('Row lookup methods')
1189 self.output_comment('using ', self.config.options.lookup_type)
1190 for key, idx in self.doc.lookup_table_indexes.iteritems():
1191 num_tables = unicode(self.doc.lookup_tables_num_per_index[idx])
1192 self.writeln('double* _lookup_', idx, '_row(unsigned i',
1193 self.lut_factor('', include_type=True, include_comma=True), ')')
1194 self.open_block()
1195 self.writeln('for (unsigned j=0; j<', num_tables, '; j++)')
1196 self.open_block()
1197 self.output_single_lookup(idx, 'j', '_lookup_table_%s_row[j] = ' % idx)
1198 self.close_block(False)
1199 self.writeln('return _lookup_table_', idx, '_row;')
1200 self.close_block()
1201 self.writeln()
1202 return
1203

References CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.optimize.LookupTableAnalyser.config(), CellMLToNektar.translators.CellMLTranslator.config(), Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, CellMLToNektar.translators.ConfigurationStore.doc, CellMLToNektar.translators.CellMLTranslator.lut_factor(), CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.translators.CellMLTranslator.output_single_lookup(), and CellMLToNektar.translators.CellMLTranslator.writeln().

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

◆ output_mathematics()

def CellMLToNektar.translators.CellMLTranslator.output_mathematics (   self)
Output the mathematics in this model.

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 566 of file translators.py.

566 def output_mathematics(self):
567 """Output the mathematics in this model."""
568 self.writeln(self.COMMENT_START, 'Mathematics')
569 for expr in self.model.get_assignments():
570 # Check this expression is actually used; don't output if not
571 var = None
572 if isinstance(expr, mathml_apply) and expr.is_assignment():
573 var = expr.assigned_variable()
574 elif isinstance(expr, cellml_variable):
575 var = expr
576 if not (var and var.get_usage_count() == 0):
577 self.output_assignment(expr)
578 return
579

References CellMLToNektar.translators.CellMLTranslator.COMMENT_START, CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.pycml.cellml_variable.model(), CellMLToNektar.pycml.mathml.model(), CellMLToNektar.translators.CellMLTranslator.model, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), CellMLToNektar.translators.CellMLTranslator.output_assignment(), and CellMLToNektar.translators.CellMLTranslator.writeln().

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

◆ output_minus()

def CellMLToNektar.translators.CellMLTranslator.output_minus (   self,
  expr,
  paren 
)
Output either a unary or binary minus.

Which is chosen depends on the number of operands.

Definition at line 848 of file translators.py.

848 def output_minus(self, expr, paren):
849 """Output either a unary or binary minus.
850
851 Which is chosen depends on the number of operands.
852 """
853 operands = list(expr.operands())
854 if len(operands) == 1:
855 self.output_unary_operator('-', operands[0], paren)
856 else:
857 self.output_binary_operator('-', operands, paren, expr)
858

References CellMLToNektar.translators.CellMLTranslator.output_binary_operator(), and CellMLToNektar.translators.CellMLTranslator.output_unary_operator().

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

◆ output_nary_operator()

def CellMLToNektar.translators.CellMLTranslator.output_nary_operator (   self,
  operator,
  operands,
  paren 
)
Output an n-ary operator (using infix notation).

If paren is True, enclose the output in parentheses.

Definition at line 781 of file translators.py.

781 def output_nary_operator(self, operator, operands, paren):
782 """Output an n-ary operator (using infix notation).
783
784 If paren is True, enclose the output in parentheses.
785 """
786 # TODO: Optimise - to use expm1(x) for computing exp(x)-1
787 self.open_paren(paren)
788 op = False
789 for operand in operands:
790 if op: self.write(' ' + operator + ' ')
791 else: op = True
792 self.output_expr(operand, True)
793 self.close_paren(paren)
794

References CellMLToNektar.translators.CellMLTranslator.close_paren(), CellMLToNektar.translators.CellMLTranslator.open_paren(), CellMLToNektar.translators.CellMLTranslator.output_expr(), and CellMLToNektar.translators.CellMLTranslator.write().

Referenced by CellMLToNektar.translators.CellMLTranslator.output_apply(), and CellMLToNektar.translators.CellMLTranslator.output_binary_operator().

◆ output_number()

def CellMLToNektar.translators.CellMLTranslator.output_number (   self,
  expr 
)
Output the plain number expr.

We make all constants parse as doubles to avoid problems with
integer division or numbers too large for the int type.

Negative numbers will be prefixed by a space to avoid unwanted
decrement operations.

Definition at line 680 of file translators.py.

680 def output_number(self, expr):
681 """Output the plain number expr.
682
683 We make all constants parse as doubles to avoid problems with
684 integer division or numbers too large for the int type.
685
686 Negative numbers will be prefixed by a space to avoid unwanted
687 decrement operations.
688 """
689 n = self.eval_number(expr)
690 num = "%.17g" % n
691 if num[0] == '-':
692 num = ' ' + num
693 if not '.' in num and not 'e' in num:
694 num = num + '.0'
695 self.write(num)
696

References CellMLToNektar.translators.CellMLTranslator.eval_number(), and CellMLToNektar.translators.CellMLTranslator.write().

Referenced by CellMLToNektar.translators.CellMLTranslator.output_assignment(), and CellMLToNektar.translators.CellMLTranslator.output_expr().

◆ output_piecewise()

def CellMLToNektar.translators.CellMLTranslator.output_piecewise (   self,
  expr,
  paren 
)
Output the piecewise expression expr.

We use a cascading ternary if expression for simplicity.

Definition at line 859 of file translators.py.

859 def output_piecewise(self, expr, paren):
860 """Output the piecewise expression expr.
861
862 We use a cascading ternary if expression for simplicity.
863 """
864 self.open_paren(paren)
865 for piece in getattr(expr, u'piece', []):
866 self.output_expr(child_i(piece, 2), True) # Condition
867 self.write(' ? ')
868 self.output_expr(child_i(piece, 1), True) # Result
869 self.write(' : ')
870 if hasattr(expr, u'otherwise'):
871 self.output_expr(child_i(expr.otherwise, 1), True) # Default case
872 else:
873 self.write(self.NOT_A_NUMBER)
874 self.close_paren(paren)
875

References CellMLToNektar.pycml.child_i(), CellMLToNektar.translators.CellMLTranslator.close_paren(), CellMLToNektar.translators.CellMLTranslator.NOT_A_NUMBER, CellMLToNektar.translators.CellMLTranslator.open_paren(), CellMLToNektar.translators.CellMLTranslator.output_expr(), and CellMLToNektar.translators.CellMLTranslator.write().

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

◆ output_root()

def CellMLToNektar.translators.CellMLTranslator.output_root (   self,
  expr,
  paren 
)
Output a root taken to some degree.

If a degree qualifier element is not provided, uses default 2.

Definition at line 814 of file translators.py.

814 def output_root(self, expr, paren):
815 """Output a root taken to some degree.
816
817 If a degree qualifier element is not provided, uses default 2.
818 """
819 if hasattr(expr, u'degree'):
820 # A degree is given. Compute x^(1/b)
821 # TODO: Optimise for when b==2 (sqrt) or b==3 (cbrt)
822 # Try to evaluate expr.degree, and if the result is a key
823 # of self.special_roots, use the value as the function to call.
824 self.write('pow(')
825 self.output_expr(expr.operands().next(), False)
826 self.write(', 1/')
827 self.output_expr(expr.degree, True)
828 self.write(')')
829 else:
830 # Compute square root
831 self.output_function('sqrt', expr.operands(), paren)
832

References CellMLToNektar.translators.CellMLTranslator.output_expr(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_function(), CellMLToNektar.translators.CellMLTranslator.output_function(), and CellMLToNektar.translators.CellMLTranslator.write().

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

◆ output_single_lookup()

def CellMLToNektar.translators.CellMLTranslator.output_single_lookup (   self,
  tidx,
  tname,
  result 
)
Write the lookup calculation for a single entry.

Used by output_lut_row_lookup_methods and output_lut_methods.

Definition at line 1169 of file translators.py.

1169 def output_single_lookup(self, tidx, tname, result):
1170 """Write the lookup calculation for a single entry.
1171
1172 Used by output_lut_row_lookup_methods and output_lut_methods.
1173 """
1174 self.writeln(self.TYPE_CONST_DOUBLE, 'y1', self.EQ_ASSIGN,
1175 self.lut_access_code(tidx, tname, 'i'), self.STMT_END)
1176 if self.config.options.lookup_type == 'linear-interpolation':
1177 self.writeln(self.TYPE_CONST_DOUBLE, 'y2', self.EQ_ASSIGN,
1178 self.lut_access_code(tidx, tname, 'i+1'), self.STMT_END)
1179 self.writeln(result, 'y1 + (y2-y1)*', self.lut_factor(''), self.STMT_END)
1180 else:
1181 self.writeln(result, 'y1', self.STMT_END)
1182

References CellMLToNektar.optimize.LookupTableAnalyser.config(), CellMLToNektar.translators.CellMLTranslator.config(), CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.translators.CellMLTranslator.lut_access_code(), CellMLToNektar.translators.CellMLTranslator.lut_factor(), CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_CONST_DOUBLE, CellMLToNektar.translators.CellMLTranslator.TYPE_CONST_DOUBLE, and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.translators.CellMLTranslator.output_lut_methods(), and CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_methods().

◆ output_table_index_checking()

def CellMLToNektar.translators.CellMLTranslator.output_table_index_checking (   self,
  key,
  idx 
)
Check whether a table index is out of bounds.

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 1302 of file translators.py.

1302 def output_table_index_checking(self, key, idx):
1303 """Check whether a table index is out of bounds."""
1304 if self.config.options.check_lt_bounds:
1305 var = key[-1]
1306 min, max, _, _ = self.lut_parameters(key)
1307 varname = self.code_name(var)
1308 self.writeln('bool _oob_', idx, self.EQ_ASSIGN, 'false', self.STMT_END)
1309 self.writeln('if (', varname, '>', max, ' || ', varname, '<', min, ')')
1310 self.open_block()
1311 self.writeln('#define COVERAGE_IGNORE', indent=False)
1312 if self.constrain_table_indices:
1313 self.writeln('if (', varname, '>', max, ') ', varname, self.EQ_ASSIGN, max, self.STMT_END)
1314 self.writeln('else ', varname, self.EQ_ASSIGN, min, self.STMT_END)
1315 else:
1316 self.writeln('_oob_', idx, self.EQ_ASSIGN, 'true', self.STMT_END)
1317 self.writeln('#undef COVERAGE_IGNORE', indent=False)
1318 self.close_block(blank_line=False)
1319

References CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.code_name(), CellMLToNektar.optimize.LookupTableAnalyser.config(), CellMLToNektar.translators.CellMLTranslator.config(), CellMLToNektar.translators.CellMLTranslator.constrain_table_indices, CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.lut_parameters(), CellMLToNektar.translators.CellMLTranslator.lut_parameters(), CellMLToNektar.translators.CellMLTranslator.open_block(), 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().

◆ output_table_index_generation()

def CellMLToNektar.translators.CellMLTranslator.output_table_index_generation (   self,
  time_name,
  nodeset = set() 
)
Output code to calculate indexes into any lookup tables.

If time_name is given and table bounds are being checked, the time value will be included in the
error message.  Note that we need to pass it in, since in some contexts the free variable is not
defined.

If nodeset is given, then filter the table indices calculated so
that only those needed to compute the nodes in nodeset are defined.

A nodeset is required if any table indices are computed variables rather than state variables.
In this case, we use the equations within nodeset to calculate the values of the indices, and
return a set containing just those nodes used, so we can avoid recalculating them later.

Definition at line 1258 of file translators.py.

1258 def output_table_index_generation(self, time_name, nodeset=set()):
1259 """Output code to calculate indexes into any lookup tables.
1260
1261 If time_name is given and table bounds are being checked, the time value will be included in the
1262 error message. Note that we need to pass it in, since in some contexts the free variable is not
1263 defined.
1264
1265 If nodeset is given, then filter the table indices calculated so
1266 that only those needed to compute the nodes in nodeset are defined.
1267
1268 A nodeset is required if any table indices are computed variables rather than state variables.
1269 In this case, we use the equations within nodeset to calculate the values of the indices, and
1270 return a set containing just those nodes used, so we can avoid recalculating them later.
1271 """
1272 tables_to_index = set()
1273 nodes_used = set()
1274 for node in nodeset:
1275 tables_to_index.update(self.contained_table_indices(node))
1276 if tables_to_index or not nodeset:
1277 self.output_comment('Lookup table indexing')
1278 for key, idx in self.doc.lookup_table_indexes.iteritems():
1279 if not nodeset or idx in tables_to_index:
1280 var = key[-1]
1281 if var.get_type() is VarTypes.Computed:
1282 if not nodeset:
1283 raise TranslationError('Unable to generate lookup table indexed on', var, 'as it is a computed variable')
1284 var_nodes = self.calculate_extended_dependencies([var]) & nodeset
1285 self.output_equations(var_nodes)
1286 nodes_used.update(var_nodes)
1287 self.output_table_index_checking(key, idx)
1288 if self.config.options.check_lt_bounds:
1289 self.writeln('#define COVERAGE_IGNORE', indent=False)
1290 self.writeln('if (_oob_', idx, ')')
1291 if time_name is None:
1292 dump_state_args = 'rY'
1293 else:
1294 dump_state_args = 'rY, ' + time_name
1295 self.writeln('EXCEPTION(DumpState("', self.var_display_name(key[-1]),
1296 ' outside lookup table range", ', dump_state_args,'));', indent_offset=1)
1297 self.writeln('#undef COVERAGE_IGNORE', indent=False)
1298 self.output_table_index_generation_code(key, idx)
1299 self.writeln()
1300 return nodes_used
1301

References CellMLToNektar.translators.CellMLTranslator.calculate_extended_dependencies(), CellMLToNektar.pycml.cellml_model.calculate_extended_dependencies(), CellMLToNektar.optimize.LookupTableAnalyser.config(), CellMLToNektar.translators.CellMLTranslator.config(), CellMLToNektar.translators.CellMLTranslator.contained_table_indices(), Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, CellMLToNektar.translators.ConfigurationStore.doc, CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.translators.CellMLTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.translators.CellMLTranslator.output_table_index_checking(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_checking(), CellMLToNektar.translators.CellMLTranslator.output_table_index_generation_code(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_generation_code(), CellMLToNektar.translators.CellMLTranslator.var_display_name(), and CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.calculate_lookup_table_indices(), and CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate().

◆ output_table_index_generation_code()

def CellMLToNektar.translators.CellMLTranslator.output_table_index_generation_code (   self,
  key,
  idx 
)
Method called by output_table_index_generation to output the code for a single table.

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 1320 of file translators.py.

1320 def output_table_index_generation_code(self, key, idx):
1321 """Method called by output_table_index_generation to output the code for a single table."""
1322 index_type = 'const unsigned '
1323 factor_type = 'const double '
1324 row_type = 'const double* const '
1325 var = key[-1]
1326 min, max, _, step_inverse = self.lut_parameters(key)
1327 offset = '_offset_' + idx
1328 offset_over_step = offset + '_over_table_step'
1329 varname = self.code_name(var)
1330 self.writeln(self.TYPE_CONST_DOUBLE, offset, self.EQ_ASSIGN, varname, ' - ', min, self.STMT_END)
1331 self.writeln(self.TYPE_CONST_DOUBLE, offset_over_step, self.EQ_ASSIGN,
1332 offset, ' * ', step_inverse, self.STMT_END)
1333 idx_var = '_table_index_' + str(idx)
1334 if self.config.options.lookup_type == 'nearest-neighbour':
1335 if self.lt_index_uses_floor:
1336 self.writeln(index_type, idx_var, ' = (unsigned) round(', offset_over_step, ');')
1337 else:
1338 self.writeln(index_type, idx_var, ' = (unsigned) (', offset_over_step, '+0.5);')
1339 else:
1340 if self.lt_index_uses_floor:
1341 self.writeln(index_type, idx_var, ' = (unsigned) floor(', offset_over_step, ');')
1342 else:
1343 self.writeln(index_type, idx_var, ' = (unsigned)(', offset_over_step, ');')
1344 factor = self.lut_factor(idx)
1345 if factor:
1346 self.writeln(factor_type, factor, ' = ', offset_over_step, ' - ', idx_var, self.STMT_END)
1347 if self.row_lookup_method:
1348 self.writeln(row_type, '_lt_', idx, '_row = ', self.lookup_method_prefix, '_lookup_', idx,
1349 '_row(', idx_var, self.lut_factor(idx, include_comma=True), ');')
1350
1351
1352
1353

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.code_name(), CellMLToNektar.optimize.LookupTableAnalyser.config(), CellMLToNektar.translators.CellMLTranslator.config(), CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.lookup_method_prefix, CellMLToNektar.translators.CellMLTranslator.lookup_method_prefix, CellMLToNektar.translators.CellMLTranslator.lt_index_uses_floor, CellMLToNektar.translators.CellMLTranslator.lut_factor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.lut_parameters(), CellMLToNektar.translators.CellMLTranslator.lut_parameters(), CellMLToNektar.translators.CellMLTranslator.row_lookup_method, CellMLToNektar.translators.CellMLTranslator.STMT_END, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.TYPE_CONST_DOUBLE, CellMLToNektar.translators.CellMLTranslator.TYPE_CONST_DOUBLE, and CellMLToNektar.translators.CellMLTranslator.writeln().

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

◆ output_table_lookup()

def CellMLToNektar.translators.CellMLTranslator.output_table_lookup (   self,
  expr,
  paren 
)
Output code to look up expr in the appropriate table.

Definition at line 1248 of file translators.py.

1248 def output_table_lookup(self, expr, paren):
1249 """Output code to look up expr in the appropriate table."""
1250 i = expr.table_index
1251 if self.row_lookup_method:
1252 self.write('_lt_', i, '_row[', expr.table_name, ']')
1253 else:
1254 self.write(self.lookup_method_prefix, '_lookup_', expr.table_name,
1255 '(_table_index_', i, self.lut_factor(i, include_comma=True), ')')
1256 return
1257

References CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.lookup_method_prefix, CellMLToNektar.translators.CellMLTranslator.lookup_method_prefix, CellMLToNektar.translators.CellMLTranslator.lut_factor(), CellMLToNektar.translators.CellMLTranslator.row_lookup_method, and CellMLToNektar.translators.CellMLTranslator.write().

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

◆ output_top_boilerplate()

def CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate (   self)
Output top boilerplate.

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 495 of file translators.py.

495 def output_top_boilerplate(self):
496 """Output top boilerplate."""
497 self.writeln('#ifndef _', self.include_guard, '_')
498 self.writeln('#define _', self.include_guard, '_\n')
499 self.output_comment('Model: ', self.model.name)
500 self.output_comment(version_comment(self.add_timestamp))
501 self.writeln()
502 self.writeln('#include <cmath>')
503 self.writeln('#include "AbstractOdeSystem.hpp"')
504 self.writeln('#include "Exception.hpp"')
505 self.writeln('#include "AbstractStimulusFunction.hpp"\n')
506 self.writeln('class ', self.class_name, ' : public AbstractOdeSystem')
507 self.writeln('{')
508 self.writeln('private:')
509 self.writeln('AbstractStimulusFunction *mpStimulus;\n',
510 indent_offset=1)
511 self.writeln('public:')
512 self.set_indent(1)
513 self.writeln('const static unsigned _NB_OF_STATE_VARIABLES_ = ',
514 str(len(self.state_vars)), ';\n')
515 self.writeln('//', ('-'*66))
516 self.writeln('// Methods')
517 self.writeln('//', ('-'*66), '\n')
518 # Constructor
519 self.writeln('', self.class_name,
520 '(AbstractStimulusFunction *stim)')
521 self.writeln(' : AbstractOdeSystem(_NB_OF_STATE_VARIABLES_, ',
522 self.v_index, ')')
523 self.open_block()
524 self.writeln('mpStimulus = stim;\n')
525 for var in self.state_vars:
526 self.writeln('mVariableNames.push_back("', var.name, '");')
527 self.writeln('mVariableUnits.push_back("', var.units, '");')
528 init_val = getattr(var, u'initial_value', None)
529 if init_val is None:
530 init_comm = ' // Value not given in model'
531 # Don't want compiler error, but shouldn't be a real number
532 init_val = self.NOT_A_NUMBER
533 else:
534 init_comm = ''
535 self.writeln('mInitialConditions.push_back(', init_val, ');',
536 init_comm, '\n')
537 if self.use_lookup_tables: self.output_lut_generation()
538 self.close_block()
539 # Destructor
540 self.writeln('~', self.class_name, '(void)')
541 self.open_block()
542 if self.use_lookup_tables: self.output_lut_deletion()
543 self.close_block()
544 # Lookup table declarations & methods
545 if self.use_lookup_tables:
546 self.output_lut_declarations()
547 self.output_lut_methods()
548 # Evaluation function
549 self.writeln('void EvaluateYDerivatives (')
550 self.writeln(' double ', self.code_name(self.free_vars[0]), ',')
551 self.writeln(' const std::vector<double> &rY,')
552 self.writeln(' std::vector<double> &rDY)')
553 self.open_block()
554 self.writeln('// Inputs:')
555 self.writeln('// Time units: ', self.free_vars[0].units)
556 for i, var in enumerate(self.state_vars):
557 self.writeln('double ', self.code_name(var),
558 ' = rY[', str(i), '];')
559 self.writeln('// Units: ', var.units, '; Initial value: ',
560 getattr(var, u'initial_value', 'Unknown'))
561 self.writeln()
562 if self.use_lookup_tables:
563 self.output_table_index_generation()
564 return
565
def version_comment(note_time=True)
Definition: translators.py:62

References CellMLToNektar.translators.CellMLTranslator.add_timestamp, CellMLToNektar.translators.CellMLTranslator.class_name, CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.code_name(), CellMLToNektar.translators.CellMLTranslator.free_vars, CellMLToNektar.translators.CellMLTranslator.include_guard(), CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.pycml.cellml_variable.model(), CellMLToNektar.pycml.mathml.model(), CellMLToNektar.translators.CellMLTranslator.model, CellMLToNektar.translators.CellMLTranslator.NOT_A_NUMBER, CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.translators.CellMLTranslator.output_lut_declarations(), CellMLToNektar.translators.CellMLTranslator.output_lut_deletion(), CellMLToNektar.translators.CellMLTranslator.output_lut_generation(), CellMLToNektar.translators.CellMLTranslator.output_lut_methods(), CellMLToNektar.translators.CellMLTranslator.output_table_index_generation(), CellMLToNektar.translators.CellMLTranslator.set_indent(), CellMLToNektar.translators.CellMLTranslator.state_vars, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.use_lookup_tables, CellMLToNektar.translators.CellMLTranslator.use_lookup_tables, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.v_index, CellMLToNektar.translators.CellMLTranslator.v_index, CellMLToNektar.translators.version_comment(), and CellMLToNektar.translators.CellMLTranslator.writeln().

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

◆ output_unary_operator()

def CellMLToNektar.translators.CellMLTranslator.output_unary_operator (   self,
  operator,
  operand,
  paren 
)
Output a unary operator (using prefix notation).

Definition at line 795 of file translators.py.

795 def output_unary_operator(self, operator, operand, paren):
796 """Output a unary operator (using prefix notation)."""
797 self.open_paren(paren)
798 self.write(operator)
799 self.output_expr(operand, True)
800 self.close_paren(paren)
801

References CellMLToNektar.translators.CellMLTranslator.close_paren(), CellMLToNektar.translators.CellMLTranslator.open_paren(), CellMLToNektar.translators.CellMLTranslator.output_expr(), and CellMLToNektar.translators.CellMLTranslator.write().

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

◆ output_variable()

def CellMLToNektar.translators.CellMLTranslator.output_variable (   self,
  ci_elt,
  ode = False 
)

◆ register()

def CellMLToNektar.translators.CellMLTranslator.register (   cls,
  subclass,
  name 
)
Register a new translator subclass.

Registers the subclass `subclass' with name `name' in the
translators class attribute of CellMLTranslator.  If the name
given is already in use, raises NameAlreadyRegistered.

Definition at line 117 of file translators.py.

117 def register(cls, subclass, name):
118 """Register a new translator subclass.
119
120 Registers the subclass `subclass' with name `name' in the
121 translators class attribute of CellMLTranslator. If the name
122 given is already in use, raises NameAlreadyRegistered.
123 """
124 if name in cls.translators:
125 raise cls.NameAlreadyRegistered(name)
126 cls.translators[name] = subclass
127 return
128
129

References CellMLToNektar.translators.CellMLTranslator.translators.

◆ scan_for_lookup_tables()

def CellMLToNektar.translators.CellMLTranslator.scan_for_lookup_tables (   self)

Lookup table methods #.

Search for lookup tables used in this document.

Store a list of suitable expressions on the document root.
Generate a dictionary mapping tables to their index variables.

Definition at line 980 of file translators.py.

980 def scan_for_lookup_tables(self):
981 """Search for lookup tables used in this document.
982
983 Store a list of suitable expressions on the document root.
984 Generate a dictionary mapping tables to their index variables.
985 """
986 doc = self.doc
987 # Get list of suitable expressions
988 doc.lookup_tables = doc.xml_xpath(u"//*[@lut:possible='yes']")
989 doc.lookup_tables.sort(cmp=element_path_cmp)
990 # Map table keys (min, max, step, var) to an index variable
991 doc.lookup_table_indexes = {}
992 # Count the no. of lookup tables with each index variable
993 doc.lookup_tables_num_per_index = {}
994 if not doc.lookup_tables:
995 # If no suitable expressions, we're done
996 return
997 # Search for table index variables already assigned
998 table_indexes = [int(getattr(expr, u'table_index', -1))
999 for expr in doc.lookup_tables]
1000 tidx = max(table_indexes) + 1
1001 # Search for table names already assigned
1002 table_numbers = {}
1003 for expr in doc.lookup_tables:
1004 if hasattr(expr, u'table_name'):
1005 idx = expr.table_index
1006 table_numbers[idx] = max(table_numbers.get(idx, 0), 1 + int(expr.table_name))
1007 # Now assign new names, and construct mapping from tables to index variables
1008 for expr in doc.lookup_tables:
1009 # Get a suitable table index variable
1010 comp = expr.get_component()
1011 var = comp.get_variable_by_name(expr.var)
1012 var = var.get_source_variable(recurse=True)
1013 key = (expr.min, expr.max, expr.step, var)
1014 if not key in doc.lookup_table_indexes:
1015 var._cml_modifiable = True # Table index variables shouldn't be const, in case we constrain to table bounds
1016 if hasattr(expr, u'table_index'):
1017 doc.lookup_table_indexes[key] = expr.table_index
1018 else:
1019 doc.lookup_table_indexes[key] = unicode(tidx)
1020 tidx += 1
1021 expr.xml_set_attribute((u'lut:table_index', NSS['lut']),
1022 doc.lookup_table_indexes[key])
1023 # Get a table name, unique over all tables with this index variable
1024 if not hasattr(expr, u'table_name'):
1025 tnum = table_numbers.get(doc.lookup_table_indexes[key], 0)
1026 expr.xml_set_attribute((u'lut:table_name', NSS['lut']), unicode(tnum))
1027 table_numbers[doc.lookup_table_indexes[key]] = tnum + 1
1028 # Re-number table indices so they are contiguous starting from 0.
1029 table_index_map = {}
1030 table_name_map = {}
1031 tidx = 0
1032 for key in sorted(doc.lookup_table_indexes.keys()):
1033 idx = unicode(tidx)
1034 table_index_map[doc.lookup_table_indexes[key]] = idx
1035 table_name_map[idx] = {}
1036 doc.lookup_table_indexes[key] = idx
1037 doc.lookup_tables_num_per_index[idx] = 0
1038 tidx += 1
1039 # Make sure each lookup table is only listed once in doc.lookup_tables,
1040 # so we don't get 2 tables for the same expression!
1041 # Also re-number table names so they are contiguous starting from 0 for each table index.
1042 candidates = doc.lookup_tables[:]
1043 doc.lookup_tables = []
1044 listed = set()
1045 for expr in candidates:
1046 tid = (expr.table_index, expr.table_name)
1047 if not tid in listed:
1048 listed.add(tid)
1049 doc.lookup_tables.append(expr)
1050 # Renumber
1051 expr.table_index = table_index_map[expr.table_index]
1052 table_name_map[expr.table_index][expr.table_name] = unicode(doc.lookup_tables_num_per_index[expr.table_index])
1053 expr.table_name = table_name_map[expr.table_index][expr.table_name]
1054 # Increment count for this index variable
1055 doc.lookup_tables_num_per_index[expr.table_index] += 1
1056 else:
1057 # Just renumber to match the new id for this expression
1058 expr.table_index = table_index_map[expr.table_index]
1059 expr.table_name = table_name_map[expr.table_index][expr.table_name]
1060 return
1061

References Nektar::LibUtilities::H5DataSource.doc, CellMLToNektar.optimize.PartialEvaluator.doc, CellMLToNektar.optimize.LookupTableAnalyser.doc, CellMLToNektar.translators.CellMLTranslator.doc, and CellMLToNektar.translators.ConfigurationStore.doc.

◆ send_main_output_to_subsidiary()

def CellMLToNektar.translators.CellMLTranslator.send_main_output_to_subsidiary (   self,
  to_subsidiary = True 
)
Set subsequent main-file writes to go to the subsidiary file instead.

Supplying a False argument reverts this setting.

Has no effect if not using a subsidiary file.

Definition at line 355 of file translators.py.

355 def send_main_output_to_subsidiary(self, to_subsidiary=True):
356 """Set subsequent main-file writes to go to the subsidiary file instead.
357
358 Supplying a False argument reverts this setting.
359
360 Has no effect if not using a subsidiary file.
361 """
362 self._main_output_to_subsidiary = to_subsidiary
363

References CellMLToNektar.translators.CellMLTranslator._main_output_to_subsidiary.

◆ set_indent()

def CellMLToNektar.translators.CellMLTranslator.set_indent (   self,
  level = None,
  offset = None 
)
Set the indentation level for subsequent writes.

If offset is given, adjust the level by that amount, otherwise
set it to an absolute value.

Definition at line 431 of file translators.py.

431 def set_indent(self, level=None, offset=None):
432 """Set the indentation level for subsequent writes.
433
434 If offset is given, adjust the level by that amount, otherwise
435 set it to an absolute value.
436 """
437 if offset is not None:
438 self.indent_level += offset
439 else:
440 self.indent_level = level
441

References CellMLToNektar.translators.CellMLTranslator.indent_level.

Referenced by CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_bottom_boilerplate(), CellMLToNektar.translators.CellMLTranslator.output_bottom_boilerplate(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate(), and CellMLToNektar.translators.CellMLTranslator.writeln().

◆ subsidiary_file_name()

def CellMLToNektar.translators.CellMLTranslator.subsidiary_file_name (   self,
  output_filename 
)
Generate a name for the subsidiary output file, based on the main one.

Returns a pair (main_output_file_name, subsidiary_file_name).  This is in
case the user specifies (e.g.) a .hpp file as the main output - we consider
the main output to be the .cpp file.

Definition at line 328 of file translators.py.

328 def subsidiary_file_name(self, output_filename):
329 """Generate a name for the subsidiary output file, based on the main one.
330
331 Returns a pair (main_output_file_name, subsidiary_file_name). This is in
332 case the user specifies (e.g.) a .hpp file as the main output - we consider
333 the main output to be the .cpp file.
334 """
335 base, ext = os.path.splitext(output_filename)
336 ext = ext[1:] # Remove the '.'
337 try:
338 new_ext = self.FILE_EXTENSIONS[ext]
339 swap = False
340 except KeyError:
341 swap = True
342 for key, val in self.FILE_EXTENSIONS.iteritems():
343 if val == ext:
344 new_ext = key
345 break
346 else:
347 # Turn off usage of subsidiary file
348 self.USES_SUBSIDIARY_FILE = False
349 return output_filename, None
350 subsidiary_filename = base + '.' + new_ext
351 if swap:
352 output_filename, subsidiary_filename = subsidiary_filename, output_filename
353 return output_filename, subsidiary_filename
354

References CellMLToNektar.translators.CellMLTranslator.FILE_EXTENSIONS.

◆ translate()

def CellMLToNektar.translators.CellMLTranslator.translate (   self,
  doc,
  model_filename,
  output_filename = None,
  subsidiary_file_name = None,
  class_name = None,
  v_variable = None,
  continuation = None,
  lookup_method_prefix = '',
  row_lookup_method = False,
  lt_index_uses_floor = True,
  constrain_table_indices = False 
)
Generate code for the given model.

doc should be an instance of cellml_model representing a
valid CellML model, such as might be produced from a call
to
>>> valid, doc = validator.CellMLValidator().validate(
...     model_filename, True)

model_filename is the filename of the input model.
The output program will by default be generated in the same
folder, but with a different extension.  This can be
overridden by supplying the output_filename keyword argument.

By default the name of the class representing the model will
be derived from the model name.  This can be overridden by
passing an alternative as the class_name argument.

The variable representing the transmembrane potential should
be passed in using the v_variable argument.

By default this method will perform some setup and then call
    self.output_top_boilerplate()
    self.output_mathematics()
    self.output_bottom_boilerplate()
To alter this, pass a callable as the continuation parameter;
this will then be called instead.

lookup_method_prefix and row_lookup_method can be used to
customise some aspects of lookup table usage.  The former is
used by the Chaste translator to place lookup tables within a
singleton class, while the latter can improve cache
performance by looking up all tables in a single call, and
returning an array of the results.

lt_index_uses_floor specifies whether to use the floor()
function to calculate the index into the lookup tables, or
just cast to unsigned.

constrain_table_indices specifies whether to throw an
exception if lookup table index variables go outside the
bounds specified (default), or just to cap them at the bounds.

Reimplemented in CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.

Definition at line 202 of file translators.py.

207 lt_index_uses_floor=True, constrain_table_indices=False):
208 """Generate code for the given model.
209
210 doc should be an instance of cellml_model representing a
211 valid CellML model, such as might be produced from a call
212 to
213 >>> valid, doc = validator.CellMLValidator().validate(
214 ... model_filename, True)
215
216 model_filename is the filename of the input model.
217 The output program will by default be generated in the same
218 folder, but with a different extension. This can be
219 overridden by supplying the output_filename keyword argument.
220
221 By default the name of the class representing the model will
222 be derived from the model name. This can be overridden by
223 passing an alternative as the class_name argument.
224
225 The variable representing the transmembrane potential should
226 be passed in using the v_variable argument.
227
228 By default this method will perform some setup and then call
229 self.output_top_boilerplate()
230 self.output_mathematics()
231 self.output_bottom_boilerplate()
232 To alter this, pass a callable as the continuation parameter;
233 this will then be called instead.
234
235 lookup_method_prefix and row_lookup_method can be used to
236 customise some aspects of lookup table usage. The former is
237 used by the Chaste translator to place lookup tables within a
238 singleton class, while the latter can improve cache
239 performance by looking up all tables in a single call, and
240 returning an array of the results.
241
242 lt_index_uses_floor specifies whether to use the floor()
243 function to calculate the index into the lookup tables, or
244 just cast to unsigned.
245
246 constrain_table_indices specifies whether to throw an
247 exception if lookup table index variables go outside the
248 bounds specified (default), or just to cap them at the bounds.
249 """
250 self.doc = doc
251 self.model = doc.model
252 # Name of the class that will represent this model
253 if class_name is None:
254 self.class_name = u'CML_' + doc.model.name.replace('-', '_')
255 else:
256 self.class_name = class_name
257 # Figure out the free & state vars in this model
258 self.free_vars = doc.model.find_free_vars()
259 self.state_vars = doc.model.find_state_vars()
260 if len(self.free_vars) > 1:
261 self.error(["Model has more than one free variable; exiting.",
262 "Free vars:" + str(self.free_vars)])
263 if len(self.free_vars) == 0:
264 if self.model.get_option('protocol'):
265 # We may be dealing with an algebraic model; check for an Unknown variable
266 for var in self.model.get_all_variables():
267 if var.get_type() == VarTypes.Unknown:
268 self.free_vars.append(var)
269 if len(self.free_vars) != 1:
270 self.error(["Model has no free variable; exiting."])
271 # If only a single component, don't add it to variable names
272 self.single_component = (len(getattr(self.model, u'component', [])) == 1)
273 # Find the (index of the) transmembrane potential
274 self.v_variable = v_variable
275 if self.v_variable:
276 self.v_variable_name = (v_variable.component.name, v_variable.name)
277 else:
278 self.v_variable = None
279 for i, var in enumerate(self.state_vars):
280 if var is v_variable:
281 self.v_index = i
282 break
283 else:
284 self.v_index = -1
285 # Check to see if we're using lookup tables
286 self.lookup_method_prefix = lookup_method_prefix
287 self.row_lookup_method = row_lookup_method
288 self.lt_index_uses_floor = lt_index_uses_floor
289 self.constrain_table_indices = constrain_table_indices
290 self.scan_for_lookup_tables()
291 if not doc.lookup_tables:
292 # No tables found
293 self.use_lookup_tables = False
294
295 # Extra configuration hook
296 self.final_configuration_hook()
297
298 # Open the output file(s)
299 if output_filename is None:
300 output_filename = self.output_file_name(model_filename)
301 if self.USES_SUBSIDIARY_FILE:
302 output_filename, self.subsidiary_filename = self.subsidiary_file_name(output_filename)
303 self.output_filename = output_filename
304 self.out = open_output_stream(output_filename)
305 if self.USES_SUBSIDIARY_FILE:
306 self.out2 = open_output_stream(self.subsidiary_filename)
307
308 # Translate
309 if continuation:
310 continuation()
311 else:
312 self.output_top_boilerplate()
313 self.output_mathematics()
314 self.output_bottom_boilerplate()
315 close_output_stream(self.out)
316 if self.USES_SUBSIDIARY_FILE:
317 close_output_stream(self.out2)
318 return
319
def model(self)
Definition: pycml.py:2654
def open_output_stream(fname)
Definition: utilities.py:298
def close_output_stream(stream)
Definition: utilities.py:314
def validate(self, stream)
Definition: validator.py:296

References CellMLToNektar.translators.CellMLTranslator.model, CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_bottom_boilerplate(), CellMLToNektar.translators.CellMLTranslator.output_bottom_boilerplate(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_mathematics(), CellMLToNektar.translators.CellMLTranslator.output_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_top_boilerplate(), CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate(), and CellMLToNektar.validator.validate().

◆ var_display_name()

def CellMLToNektar.translators.CellMLTranslator.var_display_name (   self,
  var 
)
Return a display name for the given variable.

If it has an oxmeta name, uses that.  Otherwise, looks first for a bqbiol:is annotation,
or uses the cmeta:id if present, or the name attribute if not.  If there is an interface
component, strip the name of it out of the display name.

Definition at line 463 of file translators.py.

463 def var_display_name(self, var):
464 """Return a display name for the given variable.
465
466 If it has an oxmeta name, uses that. Otherwise, looks first for a bqbiol:is annotation,
467 or uses the cmeta:id if present, or the name attribute if not. If there is an interface
468 component, strip the name of it out of the display name.
469 """
470 if var.oxmeta_name:
471 name = var.oxmeta_name
472 else:
473 for uri in var.get_rdf_annotations(('bqbiol:is', NSS['bqbiol'])):
474 if '#' in uri:
475 name = uri[1 + uri.rfind('#'):]
476 break
477 else:
478 if hasattr(var, u'id') and var.id:
479 name = var.id
480 else:
481 name = var.name
482 iface = getattr(self.model, 'interface_component_name', '#N/A#')
483 if name.startswith(iface):
484 name = name[len(iface)+2:]
485 return name
486

References CellMLToNektar.processors.ModelModifier.model, CellMLToNektar.pycml.cellml_variable.model(), CellMLToNektar.pycml.mathml.model(), and CellMLToNektar.translators.CellMLTranslator.model.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_bottom_boilerplate(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), and CellMLToNektar.translators.CellMLTranslator.output_table_index_generation().

◆ varobj()

def CellMLToNektar.translators.CellMLTranslator.varobj (   self,
  varname 
)

◆ write()

def CellMLToNektar.translators.CellMLTranslator.write (   self,
args 
)
Write to our output file.

This variant does not indent the output, or add a newline.

Definition at line 398 of file translators.py.

398 def write(self, *args):
399 """Write to our output file.
400
401 This variant does not indent the output, or add a newline.
402 """
403 self.writeln(indent=False, nl=False, *args)
404

References CellMLToNektar.translators.CellMLTranslator.writeln().

Referenced by CellMLToNektar.translators.CellMLTranslator.close_paren(), CellMLToNektar.translators.CellMLTranslator.open_paren(), CellMLToNektar.translators.CellMLTranslator.output_apply(), CellMLToNektar.translators.CellMLTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.translators.CellMLTranslator.output_expr(), CellMLToNektar.translators.CellMLTranslator.output_function(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.translators.CellMLTranslator.output_lhs(), CellMLToNektar.translators.CellMLTranslator.output_log(), CellMLToNektar.translators.CellMLTranslator.output_nary_operator(), CellMLToNektar.translators.CellMLTranslator.output_number(), CellMLToNektar.translators.CellMLTranslator.output_piecewise(), CellMLToNektar.translators.CellMLTranslator.output_root(), CellMLToNektar.translators.CellMLTranslator.output_table_lookup(), CellMLToNektar.translators.CellMLTranslator.output_unary_operator(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_variable(), and CellMLToNektar.translators.CellMLTranslator.output_variable().

◆ writeln()

def CellMLToNektar.translators.CellMLTranslator.writeln (   self,
args,
**  kwargs 
)
Write a line to our output file.

Takes any number of strings as input, and writes them out to file.

Unless the keyword argument indent is given as False, then the
output will be indented to the level set by self.set_indent().
Setting indent_level will override this value.
Setting indent_offset will adjust the current level temporarily.

If nl is set to False then a newline character will not be
appended to the output.

If subsidiary=True, then the line will be written to the subsidiary
output file instead of the main one.  An error will be raised if
there is no subsidiary output file.

Definition at line 364 of file translators.py.

364 def writeln(self, *args, **kwargs):
365 """Write a line to our output file.
366
367 Takes any number of strings as input, and writes them out to file.
368
369 Unless the keyword argument indent is given as False, then the
370 output will be indented to the level set by self.set_indent().
371 Setting indent_level will override this value.
372 Setting indent_offset will adjust the current level temporarily.
373
374 If nl is set to False then a newline character will not be
375 appended to the output.
376
377 If subsidiary=True, then the line will be written to the subsidiary
378 output file instead of the main one. An error will be raised if
379 there is no subsidiary output file.
380 """
381 if kwargs.get('subsidiary', False) or self._main_output_to_subsidiary:
382 if not self.USES_SUBSIDIARY_FILE:
383 self.error('Tried to write to non-existent subsidiary file')
384 else:
385 target = self.out2
386 else:
387 target = self.out
388 indent = kwargs.get('indent', True)
389 nl = kwargs.get('nl', True)
390 if indent:
391 level = kwargs.get('indent_level', self.indent_level)
392 level += kwargs.get('indent_offset', 0)
393 target.write(self.indent_char * self.indent_factor * level)
394 target.write(''.join(map(str, args)))
395 if nl:
396 target.write('\n')
397

References CellMLToNektar.translators.CellMLTranslator._main_output_to_subsidiary, CellMLToNektar.translators.CellMLTranslator.error(), CellMLToNektar.translators.CellMLTranslator.indent_char, CellMLToNektar.translators.CellMLTranslator.indent_factor, CellMLToNektar.translators.CellMLTranslator.indent_level, CellMLToNektar.translators.CellMLTranslator.out, CellMLToNektar.translators.CellMLTranslator.out2, CellMLToNektar.translators.CellMLTranslator.set_indent(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.USES_SUBSIDIARY_FILE, and CellMLToNektar.translators.CellMLTranslator.USES_SUBSIDIARY_FILE.

Referenced by CellMLToNektar.translators.CellMLTranslator.close_block(), CellMLToNektar.translators.CellMLTranslator.open_block(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), CellMLToNektar.translators.CellMLTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_bottom_boilerplate(), CellMLToNektar.translators.CellMLTranslator.output_bottom_boilerplate(), CellMLToNektar.translators.CellMLTranslator.output_comment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations_grl(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_evaluate_y_derivatives(), 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_includes(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_intracellular_calcium(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), CellMLToNektar.translators.CellMLTranslator.output_lut_declarations(), CellMLToNektar.translators.CellMLTranslator.output_lut_deletion(), CellMLToNektar.translators.CellMLTranslator.output_lut_generation(), CellMLToNektar.translators.CellMLTranslator.output_lut_index_declarations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_indexing_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_indices(), CellMLToNektar.translators.CellMLTranslator.output_lut_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_memory(), CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_methods(), CellMLToNektar.translators.CellMLTranslator.output_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_model_attributes(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_nonlinear_state_assignments(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), CellMLToNektar.translators.CellMLTranslator.output_single_lookup(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.translators.CellMLTranslator.output_table_index_checking(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_checking(), CellMLToNektar.translators.CellMLTranslator.output_table_index_generation(), CellMLToNektar.translators.CellMLTranslator.output_table_index_generation_code(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_generation_code(), CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate(), CellMLToNektar.translators.CellMLTranslator.write(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.writeln_hpp().

Member Data Documentation

◆ _main_output_to_subsidiary

CellMLToNektar.translators.CellMLTranslator._main_output_to_subsidiary
private

◆ _original_out

CellMLToNektar.translators.CellMLTranslator._original_out
private

◆ add_timestamp

CellMLToNektar.translators.CellMLTranslator.add_timestamp

◆ binary_ops

dictionary CellMLToNektar.translators.CellMLTranslator.binary_ops
static
Initial value:
= {'divide': '/',
'xor': '!=', 'eq': '==', 'neq': '!=',
'geq': '>=','leq': '<=','gt': '>','lt': '<'}

Definition at line 727 of file translators.py.

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

◆ class_name

CellMLToNektar.translators.CellMLTranslator.class_name

◆ COMMENT_START

string CellMLToNektar.translators.CellMLTranslator.COMMENT_START = '// '
static

◆ constrain_table_indices

CellMLToNektar.translators.CellMLTranslator.constrain_table_indices

◆ doc

CellMLToNektar.translators.CellMLTranslator.doc

Definition at line 250 of file translators.py.

Referenced by CellMLToNektar.optimize.LookupTableAnalyser._determine_duplicate_tables(), CellMLToNektar.optimize.LookupTableAnalyser._determine_unneeded_tables(), CellMLToNektar.optimize.PartialEvaluator._do_reduce_eval_loop(), CellMLToNektar.optimize.LookupTableAnalyser._find_tables(), CellMLToNektar.translators.ConfigurationStore._find_transmembrane_currents_from_voltage_ode(), CellMLToNektar.translators.ConfigurationStore._find_variable(), CellMLToNektar.optimize.PartialEvaluator._get_assignment_exprs(), CellMLToNektar.optimize.LookupTableAnalyser.analyse_model(), CellMLToNektar.optimize.LookupTableAnalyser.annotate_as_suitable(), CellMLToNektar.optimize.LookupTableAnalyser.config(), CellMLToNektar.translators.CellMLTranslator.config(), CellMLToNektar.translators.ConfigurationStore.expose_variables(), CellMLToNektar.translators.ConfigurationStore.find_current_vars(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.get_stimulus_assignment(), CellMLToNektar.optimize.PartialEvaluator.is_instantiable(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.lut_parameters(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_intracellular_calcium(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), 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_indices(), CellMLToNektar.translators.CellMLTranslator.output_lut_methods(), CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_memory(), CellMLToNektar.translators.CellMLTranslator.output_lut_row_lookup_methods(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), CellMLToNektar.translators.CellMLTranslator.output_table_index_generation(), CellMLToNektar.translators.ConfigurationStore.read_configuration_file(), CellMLToNektar.optimize.LookupTableAnalyser.remove_lut_annotations(), CellMLToNektar.translators.CellMLTranslator.scan_for_lookup_tables(), and CellMLToNektar.translators.ConfigurationStore.validate_metadata().

◆ DOXYGEN_COMMENT_START

string CellMLToNektar.translators.CellMLTranslator.DOXYGEN_COMMENT_START = '//! '
static

◆ E

string CellMLToNektar.translators.CellMLTranslator.E = 'M_E'
static

◆ EQ_ASSIGN

string CellMLToNektar.translators.CellMLTranslator.EQ_ASSIGN = ' = '
static

Definition at line 142 of file translators.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.get_stimulus_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), CellMLToNektar.translators.CellMLTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_grl2_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_class(), CellMLToNektar.translators.CellMLTranslator.output_lut_deletion(), CellMLToNektar.translators.CellMLTranslator.output_lut_generation(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_nonlinear_state_assignments(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), CellMLToNektar.translators.CellMLTranslator.output_single_lookup(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.translators.CellMLTranslator.output_table_index_checking(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_checking(), and CellMLToNektar.translators.CellMLTranslator.output_table_index_generation_code().

◆ FALSE

string CellMLToNektar.translators.CellMLTranslator.FALSE = 'false'
static

◆ FILE_EXTENSIONS

dictionary CellMLToNektar.translators.CellMLTranslator.FILE_EXTENSIONS
static
Initial value:
= {'cpp': 'h',
'c': 'h',
'cxx': 'hxx'}

Definition at line 163 of file translators.py.

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

◆ free_vars

CellMLToNektar.translators.CellMLTranslator.free_vars

◆ function_map

dictionary CellMLToNektar.translators.CellMLTranslator.function_map
static
Initial value:
= {'power': 'pow', 'abs': 'fabs', 'ln': 'log', 'exp': 'exp',
'floor': 'floor', 'ceiling': 'ceil',
'factorial': 'factorial', # Needs external definition
'not': '!', 'rem': 'fmod',
'sin': 'sin', 'cos': 'cos', 'tan': 'tan',
'sec': '1/cos', 'csc': '1/sin', 'cot': '1/tan',
'sinh': 'sinh', 'cosh': 'cosh', 'tanh': 'tanh',
'sech': '1/cosh', 'csch': '1/sinh', 'coth': '1/tanh',
'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan',
'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'}

Definition at line 710 of file translators.py.

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

◆ indent_char

CellMLToNektar.translators.CellMLTranslator.indent_char

Definition at line 173 of file translators.py.

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

◆ indent_factor

CellMLToNektar.translators.CellMLTranslator.indent_factor

Definition at line 175 of file translators.py.

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

◆ indent_level

CellMLToNektar.translators.CellMLTranslator.indent_level

◆ lookup_method_prefix

CellMLToNektar.translators.CellMLTranslator.lookup_method_prefix

◆ lt_index_uses_floor

CellMLToNektar.translators.CellMLTranslator.lt_index_uses_floor

◆ model

CellMLToNektar.translators.CellMLTranslator.model

Definition at line 251 of file translators.py.

Referenced by CellMLToNektar.processors.InterfaceGenerator._add_all_odes_to_interface(), CellMLToNektar.processors.ModelModifier._clear_model_caches(), CellMLToNektar.processors.ModelModifier._create_connection_element(), CellMLToNektar.processors.ModelModifier._find_connection_element(), CellMLToNektar.processors.ModelModifier._find_or_create_variable(), CellMLToNektar.processors.ModelModifier._process_operator(), CellMLToNektar.pycml.reduce_commutative_nary._reduce(), CellMLToNektar.pycml.mathml_power._reduce(), CellMLToNektar.pycml.mathml_piecewise._set_in_units(), CellMLToNektar.pycml.cellml_variable._set_source_variable(), CellMLToNektar.processors.InterfaceGenerator._split_ode(), CellMLToNektar.processors.InterfaceGenerator._transform_derivatives_on_rhs(), CellMLToNektar.processors.ModelModifier._update_connections(), CellMLToNektar.processors.UnitsConverter.add_all_conversions(), CellMLToNektar.processors.UnitsConverter.add_conversions_for_component(), CellMLToNektar.processors.ModelModifier.add_expr_to_comp(), CellMLToNektar.processors.InterfaceGenerator.add_output_function(), CellMLToNektar.pycml.cellml_variable.add_rdf_annotation(), CellMLToNektar.processors.ModelModifier.add_units(), CellMLToNektar.processors.ModelModifier.add_variable(), CellMLToNektar.translators.CellMLTranslator.calculate_extended_dependencies(), CellMLToNektar.pycml.mathml_apply.classify_variables(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.code_name(), CellMLToNektar.processors.ModelModifier.connect_variables(), CellMLToNektar.processors.UnitsConverter.convert_assignments(), CellMLToNektar.processors.UnitsConverter.convert_connections(), CellMLToNektar.processors.UnitsConverter.convert_constant(), CellMLToNektar.processors.UnitsConverter.convert_mapping(), CellMLToNektar.processors.ModelModifier.create_new_component(), CellMLToNektar.processors.ModelModifier.finalize(), CellMLToNektar.pycml.mathml.get_component(), CellMLToNektar.processors.InterfaceGenerator.get_interface_component(), CellMLToNektar.pycml.cellml_variable.get_rdf_annotation(), CellMLToNektar.pycml.cellml_variable.get_rdf_annotations(), CellMLToNektar.pycml.mathml_apply.get_units(), CellMLToNektar.pycml.mathml_piecewise.get_units(), CellMLToNektar.pycml.cellml_variable.is_statically_const(), CellMLToNektar.processors.InterfaceGenerator.make_var_computed_constant(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_default_stimulus(), CellMLToNektar.translators.CellMLTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_get_i_ionic(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_includes(), CellMLToNektar.translators.CellMLTranslator.output_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_model_attributes(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_top_boilerplate(), CellMLToNektar.translators.CellMLTranslator.output_top_boilerplate(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_verify_state_variables(), CellMLToNektar.processors.ModelModifier.remove_connections(), CellMLToNektar.pycml.cellml_variable.remove_rdf_annotations(), CellMLToNektar.translators.CellMLTranslator.translate(), CellMLToNektar.translators.CellMLTranslator.var_display_name(), and CellMLToNektar.translators.CellMLTranslator.varobj().

◆ nary_ops

dictionary CellMLToNektar.translators.CellMLTranslator.nary_ops
static
Initial value:
= {'plus': '+', 'times': '*',
'and': '&&', 'or': '||'}

Definition at line 725 of file translators.py.

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

◆ NOT_A_NUMBER

string CellMLToNektar.translators.CellMLTranslator.NOT_A_NUMBER = 'NAN'
static

◆ options

CellMLToNektar.translators.CellMLTranslator.options

◆ out

CellMLToNektar.translators.CellMLTranslator.out

◆ out2

CellMLToNektar.translators.CellMLTranslator.out2

Definition at line 306 of file translators.py.

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

◆ output_filename

CellMLToNektar.translators.CellMLTranslator.output_filename

Definition at line 303 of file translators.py.

◆ PI

string CellMLToNektar.translators.CellMLTranslator.PI = 'M_PI'
static

◆ recip_trig

dictionary CellMLToNektar.translators.CellMLTranslator.recip_trig
static
Initial value:
= {'arcsec': 'arccos', 'arccsc': 'arcsin', 'arccot': 'arctan',
'arcsech': 'arccosh', 'arccsch': 'arcsinh', 'arccoth': 'arctanh'}

Definition at line 722 of file translators.py.

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

◆ row_lookup_method

CellMLToNektar.translators.CellMLTranslator.row_lookup_method

◆ single_component

CellMLToNektar.translators.CellMLTranslator.single_component

Definition at line 272 of file translators.py.

◆ special_roots

dictionary CellMLToNektar.translators.CellMLTranslator.special_roots = {2: 'sqrt', 3: 'cbrt'}
static

Definition at line 813 of file translators.py.

◆ state_vars

CellMLToNektar.translators.CellMLTranslator.state_vars

◆ STMT_END

string CellMLToNektar.translators.CellMLTranslator.STMT_END = ';'
static

Various language tokens #.

Definition at line 141 of file translators.py.

Referenced by CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.get_stimulus_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_assignment(), CellMLToNektar.translators.CellMLTranslator.output_assignment(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_backward_euler_mathematics(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_constructor(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derivative_calculations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_derived_quantities(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_equations(), 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_lut_class(), CellMLToNektar.translators.CellMLTranslator.output_lut_declarations(), CellMLToNektar.translators.CellMLTranslator.output_lut_deletion(), CellMLToNektar.translators.CellMLTranslator.output_lut_generation(), CellMLToNektar.translators.CellMLTranslator.output_lut_index_declarations(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_lut_indexing_methods(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_method_start(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_nonlinear_state_assignments(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_rush_larsen_mathematics(), CellMLToNektar.translators.CellMLTranslator.output_single_lookup(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_state_assignments(), CellMLToNektar.translators.CellMLTranslator.output_table_index_checking(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.output_table_index_checking(), CellMLToNektar.translators.CellMLTranslator.output_table_index_generation_code(), CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_create(), and CellMLToNektar.CellMLToNektarTranslator.CellMLToNektarTranslator.vector_initialise().

◆ subsidiary_filename

CellMLToNektar.translators.CellMLTranslator.subsidiary_filename

◆ translators

dictionary CellMLToNektar.translators.CellMLTranslator.translators = {}
static

◆ TRUE

string CellMLToNektar.translators.CellMLTranslator.TRUE = 'true'
static

◆ TYPE_CONST_DOUBLE

string CellMLToNektar.translators.CellMLTranslator.TYPE_CONST_DOUBLE = 'const NekDouble '
static

◆ TYPE_CONST_UNSIGNED

string CellMLToNektar.translators.CellMLTranslator.TYPE_CONST_UNSIGNED = 'const unsigned '
static

◆ TYPE_DOUBLE

string CellMLToNektar.translators.CellMLTranslator.TYPE_DOUBLE = 'NekDouble '
static

◆ TYPE_VOID

string CellMLToNektar.translators.CellMLTranslator.TYPE_VOID = 'void '
static

◆ use_lookup_tables

CellMLToNektar.translators.CellMLTranslator.use_lookup_tables

◆ USES_SUBSIDIARY_FILE [1/2]

bool CellMLToNektar.translators.CellMLTranslator.USES_SUBSIDIARY_FILE = False
static

Definition at line 161 of file translators.py.

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

◆ USES_SUBSIDIARY_FILE [2/2]

CellMLToNektar.translators.CellMLTranslator.USES_SUBSIDIARY_FILE

Definition at line 348 of file translators.py.

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

◆ v_index

CellMLToNektar.translators.CellMLTranslator.v_index

◆ v_variable

CellMLToNektar.translators.CellMLTranslator.v_variable

◆ v_variable_name

CellMLToNektar.translators.CellMLTranslator.v_variable_name

Definition at line 276 of file translators.py.