Skip to content

Example in tutorials: freezing a mode-switch variable #10

Description

@MichaelClerx

E.g. before fitting you'll want to change statements like

g_Kr = piecewise(cell.type == 0, 1, cell.type == 1, 1.2, cell.type == 2, 1.43) * g_Kr_base
  g_Kr_base = 0.123

to

g_Kr = 0.123

by doing e.g.

# Set the cell type you want
switch = m.get('cell.mode')
switch.set_rhs(1)

# Freeze all the (constant) variables to this mode
for var in switch.refs_by():
    if var.is_constant():
        # Evaluate the variable's RHS, and set its new RHS to the result
        var.set_rhs(var.eval())  # Remove the switch, if unused
        
        # Remove unused child variables, if any
        what's the best way to do this, if they depend on each other?

if not switch.refs_by():
    switch.parent().remove_variable(switch)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions