C

Export to a simple Ansi-C format is provided based on the sundials ODE solver.

Limitations:

  • No plots or other post-processing are included

API

The standard interface for exporting and accessing expression writers is provided:

myokit.formats.ansic.exporters()

Returns a dict of all exporters available in this module.

class myokit.formats.ansic.AnsiCExporter

This Exporter generates a runnable ansic C model implementation and integrator. The integration is based on the Sundials CVODE library, which is required to run the program.

Both the model definition and pacing protocol are exported and the file is set up ready to run a simulation. No post-processing is included.

Provides the following external variables:

time

The current simulation time

pace

The current value of the pacing system, implemented using the given protocol.

post_export_info()

Optional method that returns a string containing information about this exporter, to be shown after the export is completed.

class myokit.formats.ansic.AnsiCCableExporter

This Exporter generates a 1d cable simulation using a simple forward-Euler scheme in ansi-C.

Both the model definition and pacing protocol are exported and the file is set up ready to run a simulation. No post-processing is included.

Provides the following external variables:

time

The simulation time

pace

The value of the pacing variable, implemented using the given protocol.

diffusion_current

The current flowing from each cell to its neighbors. This will be positive if the cell is acting as a source, negative when it’s acting as a sink.

Requires the following labels to be set in the model:

membrane_potential

The membrane potential.

Variables are linked using diffusion_current, this is calculated from the membrane potentials as:

i = g * ((V - V_next) - (V_last - V))

At the boundaries, V is substituted for V_last or V_next.

post_export_info()

Optional method that returns a string containing information about this exporter, to be shown after the export is completed.

class myokit.formats.ansic.AnsiCEulerExporter

This Exporter generates an ansic C implementation using a simple explicit forward-Euler scheme.

Both the model definition and pacing protocol are exported and the file is set up ready to run a simulation. No post-processing is included.

Provides the following external variables:

time

The simulation time

pace

The value of the pacing variable, implemented using the given protocol.

No labeled variables are required.

post_export_info()

Optional method that returns a string containing information about this exporter, to be shown after the export is completed.

myokit.formats.ansic.ewriters()

Returns a dict of all expression writers available in this module.

class myokit.formats.ansic.AnsiCExpressionWriter

This ExpressionWriter writes equations for variables in a C-style syntax.

eq(q)

Converts an equation to a string

ex(e)

Converts an Expression to a string.

set_condition_function(func=None)

Sets a function name to use for if statements

By setting func to None you can revert back to the default behavior

(the ternary operator). Any other value will be interpreted as the name of a C function taking arguments (condition, value_if_true, value_if_false).

set_lhs_function(f)
Sets a naming function, will be called to get the variable name from a

myokit.LhsExpression object.

The argument f should be a function that takes an LhsExpression as input and returns a string.