diff --git a/src/api/libcellml/issue.h b/src/api/libcellml/issue.h index ff9bcb8f7..fdf283803 100644 --- a/src/api/libcellml/issue.h +++ b/src/api/libcellml/issue.h @@ -222,6 +222,8 @@ class LIBCELLML_EXPORT Issue GENERATOR_EXTERNAL_VARIABLE_NOT_UNTRACKABLE, GENERATOR_NLA_BASED_VARIABLE_ALWAYS_TRACKED, GENERATOR_NLA_BASED_VARIABLE_NOT_UNTRACKABLE, + GENERATOR_EXTERNALLY_NEEDED_VARIABLE_ALWAYS_TRACKED, + GENERATOR_EXTERNALLY_NEEDED_VARIABLE_NOT_UNTRACKABLE, // Placeholder for further references: UNSPECIFIED diff --git a/src/generator.cpp b/src/generator.cpp index 48baa8479..a6abeae60 100644 --- a/src/generator.cpp +++ b/src/generator.cpp @@ -109,6 +109,27 @@ bool Generator::GeneratorImpl::isUntrackedVariable(const AnalyserVariablePtr &va return doIsTrackedVariable(variable, false); } +void Generator::GeneratorImpl::addNeededToComputeExternalVariableIssue(const AnalyserVariablePtr &variable, bool tracked) +{ + auto issue = Issue::IssueImpl::create(); + + issue->mPimpl->setDescription("Variable '" + variable->variable()->name() + + "' in component '" + owningComponent(variable->variable())->name() + + "' is needed to compute an external variable and " + + (tracked ? + "is therefore always tracked." : + "cannot therefore be untracked.")); + issue->mPimpl->setReferenceRule(tracked ? + Issue::ReferenceRule::GENERATOR_EXTERNALLY_NEEDED_VARIABLE_ALWAYS_TRACKED : + Issue::ReferenceRule::GENERATOR_EXTERNALLY_NEEDED_VARIABLE_NOT_UNTRACKABLE); + + if (tracked) { + issue->mPimpl->setLevel(Issue::Level::MESSAGE); + } + + addIssue(issue); +} + bool Generator::GeneratorImpl::trackableVariable(const AnalyserVariablePtr &variable, bool tracked, bool canAddIssue) { // A trackable variable is a variable that is not a variable of integration, a state, or an external variable, which @@ -141,6 +162,50 @@ bool Generator::GeneratorImpl::trackableVariable(const AnalyserVariablePtr &vari } } + // A trackable variable is also not a variable that is needed to compute an external variable. + + for (const auto &external : variable->model()->externals()) { + auto externalEquationPimpl = external->equations().front()->mPimpl; + + // Check whether the variable is a constant dependency. + + for (const auto &constantDependency : externalEquationPimpl->mConstantDependencies) { + if (variable == constantDependency) { + if (canAddIssue) { + addNeededToComputeExternalVariableIssue(variable, tracked); + } + + return false; + } + } + + // Check whether the variable is a computed constant dependency or an algebraic dependency. + + for (const auto &dependency : externalEquationPimpl->mDependencies) { + auto dependencyPimpl = dependency.lock()->mPimpl; + + for (const auto &computedConstant : dependencyPimpl->mComputedConstants) { + if (variable == computedConstant) { + if (canAddIssue) { + addNeededToComputeExternalVariableIssue(variable, tracked); + } + + return false; + } + } + + for (const auto &algebraic : dependencyPimpl->mAlgebraic) { + if (variable == algebraic) { + if (canAddIssue) { + addNeededToComputeExternalVariableIssue(variable, tracked); + } + + return false; + } + } + } + } + return true; } diff --git a/src/generator_p.h b/src/generator_p.h index a5da8f386..de9fff1aa 100644 --- a/src/generator_p.h +++ b/src/generator_p.h @@ -54,6 +54,8 @@ struct Generator::GeneratorImpl: public Logger::LoggerImpl bool isTrackedVariable(const AnalyserVariablePtr &variable); bool isUntrackedVariable(const AnalyserVariablePtr &variable); + void addNeededToComputeExternalVariableIssue(const AnalyserVariablePtr &variable, bool tracked); + bool trackableVariable(const AnalyserVariablePtr &variable, bool tracked, bool canAddIssue = true); bool specialVariable(const AnalyserVariablePtr &variable, const AnalyserVariablePtr &specialVariable, bool tracked, Issue::ReferenceRule trackedReferenceRule, Issue::ReferenceRule untrackedReferenceRule); diff --git a/tests/generator/generatortrackedvariables.cpp b/tests/generator/generatortrackedvariables.cpp index a9addcd8a..a4a5e74c4 100644 --- a/tests/generator/generatortrackedvariables.cpp +++ b/tests/generator/generatortrackedvariables.cpp @@ -452,6 +452,7 @@ void untrack(const libcellml::AnalyserModelPtr &model, const libcellml::Generato { switch (trackingType) { case TrackingType::VARIABLES: + generator->trackAllVariables(model); // For coverage. generator->untrackAllVariables(model); break; @@ -508,17 +509,18 @@ void hodgkinHuxleySquidAxonModel1952CodeGeneration(bool ode, TrackingType tracki EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/" + modelType + ".untracked." + variableType + ".py", generator->implementationCode(analyserModel)); - // With some external variables. + // With an external variable with a dependency on a constant, computed constant, and algebraic variable. - auto potassium_channel_n_gate_alpha_n = model->component("potassium_channel_n_gate")->variable("alpha_n"); + auto membrane_Cm = model->component("membrane")->variable("Cm"); + auto potassium_channel_EK = model->component("potassium_channel")->variable("E_K"); + auto sodium_channel_m_gate_alapha_m = model->component("sodium_channel_m_gate")->variable("alpha_m"); auto external_sodium_channel_i_Na = libcellml::AnalyserExternalVariable::create(model->component("sodium_channel")->variable("i_Na")); - external_sodium_channel_i_Na->addDependency(potassium_channel_n_gate_alpha_n); - external_sodium_channel_i_Na->addDependency(model->component("sodium_channel_h_gate")->variable("h")); + external_sodium_channel_i_Na->addDependency(membrane_Cm); + external_sodium_channel_i_Na->addDependency(potassium_channel_EK); + external_sodium_channel_i_Na->addDependency(sodium_channel_m_gate_alapha_m); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(model->component("membrane")->variable("V"))); analyser->addExternalVariable(external_sodium_channel_i_Na); - analyser->addExternalVariable(libcellml::AnalyserExternalVariable::create(potassium_channel_n_gate_alpha_n)); analyser->analyseModel(model); @@ -544,65 +546,105 @@ void hodgkinHuxleySquidAxonModel1952CodeGeneration(bool ode, TrackingType tracki EXPECT_EQ_FILE_CONTENTS("generator/hodgkin_huxley_squid_axon_model_1952/" + modelType + ".untracked." + variableType + ".with.externals.py", generator->implementationCode(analyserModel)); } +const std::vector noIssues; +const std::vector constantRelatedExternalIssues = { + "Variable 'Cm' in component 'membrane' is needed to compute an external variable and cannot therefore be untracked.", +}; + TEST(GeneratorTrackedVariables, hodgkinHuxleySquidAxonModel1952UntrackedConstants) { - hodgkinHuxleySquidAxonModel1952CodeGeneration(true, TrackingType::CONSTANTS); + hodgkinHuxleySquidAxonModel1952CodeGeneration(true, TrackingType::CONSTANTS, noIssues, constantRelatedExternalIssues); } +const std::vector computedConstantRelatedExternalIssues = { + "Variable 'E_K' in component 'potassium_channel' is needed to compute an external variable and cannot therefore be untracked.", +}; + TEST(GeneratorTrackedVariables, hodgkinHuxleySquidAxonModel1952UntrackedComputedConstants) { - hodgkinHuxleySquidAxonModel1952CodeGeneration(true, TrackingType::COMPUTED_CONSTANTS); + hodgkinHuxleySquidAxonModel1952CodeGeneration(true, TrackingType::COMPUTED_CONSTANTS, noIssues, computedConstantRelatedExternalIssues); } +const std::vector algebraicRelatedExternalIssues = { + "Variable 'alpha_m' in component 'sodium_channel_m_gate' is needed to compute an external variable and cannot therefore be untracked.", +}; + TEST(GeneratorTrackedVariables, hodgkinHuxleySquidAxonModel1952UntrackedAlgebraicVariables) { - hodgkinHuxleySquidAxonModel1952CodeGeneration(true, TrackingType::ALGEBRAIC); + hodgkinHuxleySquidAxonModel1952CodeGeneration(true, TrackingType::ALGEBRAIC, noIssues, algebraicRelatedExternalIssues); } TEST(GeneratorTrackedVariables, hodgkinHuxleySquidAxonModel1952UntrackedVariables) { - hodgkinHuxleySquidAxonModel1952CodeGeneration(true, TrackingType::VARIABLES); + const std::vector variableRelatedExternalIssues = { + "Variable 'Cm' in component 'membrane' is needed to compute an external variable and cannot therefore be untracked.", + "Variable 'E_K' in component 'potassium_channel' is needed to compute an external variable and cannot therefore be untracked.", + "Variable 'alpha_m' in component 'sodium_channel_m_gate' is needed to compute an external variable and cannot therefore be untracked.", + }; + + hodgkinHuxleySquidAxonModel1952CodeGeneration(true, TrackingType::VARIABLES, noIssues, variableRelatedExternalIssues); } TEST(GeneratorTrackedVariables, hodgkinHuxleySquidAxonModel1952DaeUntrackedConstants) { - hodgkinHuxleySquidAxonModel1952CodeGeneration(false, TrackingType::CONSTANTS); + hodgkinHuxleySquidAxonModel1952CodeGeneration(false, TrackingType::CONSTANTS, noIssues, constantRelatedExternalIssues); } TEST(GeneratorTrackedVariables, hodgkinHuxleySquidAxonModel1952DaeUntrackedComputedConstants) { - hodgkinHuxleySquidAxonModel1952CodeGeneration(false, TrackingType::COMPUTED_CONSTANTS); + hodgkinHuxleySquidAxonModel1952CodeGeneration(false, TrackingType::COMPUTED_CONSTANTS, noIssues, computedConstantRelatedExternalIssues); } -const std::vector issues = { +const std::vector daeIssues = { "Variable 'i_Stim' in component 'membrane' is computed using an NLA system and cannot therefore be untracked.", "Variable 'i_L' in component 'leakage_current' is computed using an NLA system and cannot therefore be untracked.", "Variable 'i_K' in component 'potassium_channel' is computed using an NLA system and cannot therefore be untracked.", "Variable 'i_Na' in component 'sodium_channel' is computed using an NLA system and cannot therefore be untracked.", - "Variable 'alpha_m' in component 'sodium_channel_m_gate' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'E_L' in component 'leakage_current' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'E_Na' in component 'sodium_channel' is computed using an NLA system and cannot therefore be untracked.", "Variable 'beta_m' in component 'sodium_channel_m_gate' is computed using an NLA system and cannot therefore be untracked.", "Variable 'alpha_h' in component 'sodium_channel_h_gate' is computed using an NLA system and cannot therefore be untracked.", "Variable 'beta_h' in component 'sodium_channel_h_gate' is computed using an NLA system and cannot therefore be untracked.", "Variable 'alpha_n' in component 'potassium_channel_n_gate' is computed using an NLA system and cannot therefore be untracked.", "Variable 'beta_n' in component 'potassium_channel_n_gate' is computed using an NLA system and cannot therefore be untracked.", }; -const std::vector externalIssues = { - "Variable 'i_Stim' in component 'membrane' is computed using an NLA system and cannot therefore be untracked.", - "Variable 'i_L' in component 'leakage_current' is computed using an NLA system and cannot therefore be untracked.", - "Variable 'i_K' in component 'potassium_channel' is computed using an NLA system and cannot therefore be untracked.", - "Variable 'alpha_m' in component 'sodium_channel_m_gate' is computed using an NLA system and cannot therefore be untracked.", - "Variable 'beta_m' in component 'sodium_channel_m_gate' is computed using an NLA system and cannot therefore be untracked.", - "Variable 'alpha_h' in component 'sodium_channel_h_gate' is computed using an NLA system and cannot therefore be untracked.", - "Variable 'beta_h' in component 'sodium_channel_h_gate' is computed using an NLA system and cannot therefore be untracked.", - "Variable 'beta_n' in component 'potassium_channel_n_gate' is computed using an NLA system and cannot therefore be untracked.", -}; TEST(GeneratorTrackedVariables, hodgkinHuxleySquidAxonModel1952DaeUntrackedAlgebraicVariables) { - hodgkinHuxleySquidAxonModel1952CodeGeneration(false, TrackingType::ALGEBRAIC, issues, externalIssues); + const std::vector daeExternalIssues = { + "Variable 'i_Stim' in component 'membrane' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'i_L' in component 'leakage_current' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'i_K' in component 'potassium_channel' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'E_L' in component 'leakage_current' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'E_Na' in component 'sodium_channel' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'alpha_m' in component 'sodium_channel_m_gate' is needed to compute an external variable and cannot therefore be untracked.", + "Variable 'beta_m' in component 'sodium_channel_m_gate' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'alpha_h' in component 'sodium_channel_h_gate' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'beta_h' in component 'sodium_channel_h_gate' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'alpha_n' in component 'potassium_channel_n_gate' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'beta_n' in component 'potassium_channel_n_gate' is computed using an NLA system and cannot therefore be untracked.", + }; + + hodgkinHuxleySquidAxonModel1952CodeGeneration(false, TrackingType::ALGEBRAIC, daeIssues, daeExternalIssues); } TEST(GeneratorTrackedVariables, hodgkinHuxleySquidAxonModel1952DaeUntrackedVariables) { - hodgkinHuxleySquidAxonModel1952CodeGeneration(false, TrackingType::VARIABLES, issues, externalIssues); + const std::vector daeExternalIssues = { + "Variable 'Cm' in component 'membrane' is needed to compute an external variable and cannot therefore be untracked.", + "Variable 'E_K' in component 'potassium_channel' is needed to compute an external variable and cannot therefore be untracked.", + "Variable 'i_Stim' in component 'membrane' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'i_L' in component 'leakage_current' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'i_K' in component 'potassium_channel' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'E_L' in component 'leakage_current' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'E_Na' in component 'sodium_channel' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'alpha_m' in component 'sodium_channel_m_gate' is needed to compute an external variable and cannot therefore be untracked.", + "Variable 'beta_m' in component 'sodium_channel_m_gate' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'alpha_h' in component 'sodium_channel_h_gate' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'beta_h' in component 'sodium_channel_h_gate' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'alpha_n' in component 'potassium_channel_n_gate' is computed using an NLA system and cannot therefore be untracked.", + "Variable 'beta_n' in component 'potassium_channel_n_gate' is computed using an NLA system and cannot therefore be untracked.", + }; + + hodgkinHuxleySquidAxonModel1952CodeGeneration(false, TrackingType::VARIABLES, daeIssues, daeExternalIssues); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.cellml b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.cellml index 927346231..b7a4386f0 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.cellml +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.cellml @@ -119,12 +119,16 @@ - E_Na - E_R - 115 + E_Na + + + E_R + 115 + + 0 @@ -160,39 +164,35 @@ + alpha_m - - alpha_m + - + + 0.1 - - 0.1 - - - V - 25 - + + V + 25 + + + - + - + - - - - V - 25 - - 10 + + V + 25 + 10 - 1 + 1 - 0 @@ -483,12 +483,16 @@ - E_L - E_R - 10.613 + E_L + + + E_R + 10.613 + + 0 diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.c index 0b7f23697..8a5ddb7bb 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.c @@ -10,8 +10,8 @@ const char LIBCELLML_VERSION[] = "0.6.2"; const size_t STATE_COUNT = 4; const size_t CONSTANT_COUNT = 5; -const size_t COMPUTED_CONSTANT_COUNT = 3; -const size_t ALGEBRAIC_COUNT = 10; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 11; const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; @@ -31,8 +31,6 @@ const VariableInfo CONSTANT_INFO[] = { }; const VariableInfo COMPUTED_CONSTANT_INFO[] = { - {"E_L", "millivolt", "leakage_current"}, - {"E_Na", "millivolt", "sodium_channel"}, {"E_K", "millivolt", "potassium_channel"} }; @@ -41,7 +39,8 @@ const VariableInfo ALGEBRAIC_INFO[] = { {"i_L", "microA_per_cm2", "leakage_current"}, {"i_K", "microA_per_cm2", "potassium_channel"}, {"i_Na", "microA_per_cm2", "sodium_channel"}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, @@ -171,9 +170,9 @@ void objectiveFunction2(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[1] = u[0]; + algebraic[4] = u[0]; - f[0] = algebraic[1]-constants[2]*(states[0]-computedConstants[0])-0.0; + f[0] = algebraic[4]-(constants[1]-10.613)-0.0; } void findRoot2(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -181,11 +180,11 @@ void findRoot2(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[1]; + u[0] = algebraic[4]; nlaSolve(objectiveFunction2, u, 1, &rfi); - algebraic[1] = u[0]; + algebraic[4] = u[0]; } void objectiveFunction3(double *u, double *f, void *data) @@ -197,9 +196,9 @@ void objectiveFunction3(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[3] = u[0]; + algebraic[1] = u[0]; - f[0] = algebraic[3]-constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[1])-0.0; + f[0] = algebraic[1]-constants[2]*(states[0]-algebraic[4])-0.0; } void findRoot3(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -207,11 +206,11 @@ void findRoot3(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[3]; + u[0] = algebraic[1]; nlaSolve(objectiveFunction3, u, 1, &rfi); - algebraic[3] = u[0]; + algebraic[1] = u[0]; } void objectiveFunction4(double *u, double *f, void *data) @@ -223,9 +222,9 @@ void objectiveFunction4(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[4] = u[0]; + algebraic[5] = u[0]; - f[0] = algebraic[4]-0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0)-0.0; + f[0] = algebraic[5]-(constants[1]-115.0)-0.0; } void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -233,11 +232,11 @@ void findRoot4(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[4]; + u[0] = algebraic[5]; nlaSolve(objectiveFunction4, u, 1, &rfi); - algebraic[4] = u[0]; + algebraic[5] = u[0]; } void objectiveFunction5(double *u, double *f, void *data) @@ -249,9 +248,9 @@ void objectiveFunction5(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[5] = u[0]; + algebraic[3] = u[0]; - f[0] = algebraic[5]-4.0*exp(states[0]/18.0)-0.0; + f[0] = algebraic[3]-constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5])-0.0; } void findRoot5(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -259,11 +258,11 @@ void findRoot5(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[5]; + u[0] = algebraic[3]; nlaSolve(objectiveFunction5, u, 1, &rfi); - algebraic[5] = u[0]; + algebraic[3] = u[0]; } void objectiveFunction6(double *u, double *f, void *data) @@ -275,9 +274,9 @@ void objectiveFunction6(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - rates[2] = u[0]; + algebraic[7] = u[0]; - f[0] = rates[2]-(algebraic[4]*(1.0-states[2])-algebraic[5]*states[2])-0.0; + f[0] = algebraic[7]-4.0*exp(states[0]/18.0)-0.0; } void findRoot6(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -285,11 +284,11 @@ void findRoot6(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = rates[2]; + u[0] = algebraic[7]; nlaSolve(objectiveFunction6, u, 1, &rfi); - rates[2] = u[0]; + algebraic[7] = u[0]; } void objectiveFunction7(double *u, double *f, void *data) @@ -301,9 +300,9 @@ void objectiveFunction7(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[6] = u[0]; + rates[2] = u[0]; - f[0] = algebraic[6]-0.07*exp(states[0]/20.0)-0.0; + f[0] = rates[2]-(sodium_channel_m_gate_alpha_m*(1.0-states[2])-algebraic[7]*states[2])-0.0; } void findRoot7(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -311,11 +310,11 @@ void findRoot7(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[6]; + u[0] = rates[2]; nlaSolve(objectiveFunction7, u, 1, &rfi); - algebraic[6] = u[0]; + rates[2] = u[0]; } void objectiveFunction8(double *u, double *f, void *data) @@ -327,9 +326,9 @@ void objectiveFunction8(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[7] = u[0]; + algebraic[8] = u[0]; - f[0] = algebraic[7]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; + f[0] = algebraic[8]-0.07*exp(states[0]/20.0)-0.0; } void findRoot8(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -337,11 +336,11 @@ void findRoot8(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[7]; + u[0] = algebraic[8]; nlaSolve(objectiveFunction8, u, 1, &rfi); - algebraic[7] = u[0]; + algebraic[8] = u[0]; } void objectiveFunction9(double *u, double *f, void *data) @@ -353,9 +352,9 @@ void objectiveFunction9(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - rates[1] = u[0]; + algebraic[9] = u[0]; - f[0] = rates[1]-(algebraic[6]*(1.0-states[1])-algebraic[7]*states[1])-0.0; + f[0] = algebraic[9]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; } void findRoot9(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -363,11 +362,11 @@ void findRoot9(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = rates[1]; + u[0] = algebraic[9]; nlaSolve(objectiveFunction9, u, 1, &rfi); - rates[1] = u[0]; + algebraic[9] = u[0]; } void objectiveFunction10(double *u, double *f, void *data) @@ -379,9 +378,9 @@ void objectiveFunction10(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[2] = u[0]; + rates[1] = u[0]; - f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[2])-0.0; + f[0] = rates[1]-(algebraic[8]*(1.0-states[1])-algebraic[9]*states[1])-0.0; } void findRoot10(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -389,11 +388,11 @@ void findRoot10(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[2]; + u[0] = rates[1]; nlaSolve(objectiveFunction10, u, 1, &rfi); - algebraic[2] = u[0]; + rates[1] = u[0]; } void objectiveFunction11(double *u, double *f, void *data) @@ -405,9 +404,9 @@ void objectiveFunction11(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[8] = u[0]; + algebraic[2] = u[0]; - f[0] = algebraic[8]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; + f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[0])-0.0; } void findRoot11(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -415,11 +414,11 @@ void findRoot11(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[8]; + u[0] = algebraic[2]; nlaSolve(objectiveFunction11, u, 1, &rfi); - algebraic[8] = u[0]; + algebraic[2] = u[0]; } void objectiveFunction12(double *u, double *f, void *data) @@ -431,9 +430,9 @@ void objectiveFunction12(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[9] = u[0]; + algebraic[10] = u[0]; - f[0] = algebraic[9]-0.125*exp(states[0]/80.0)-0.0; + f[0] = algebraic[10]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; } void findRoot12(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -441,11 +440,11 @@ void findRoot12(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[9]; + u[0] = algebraic[10]; nlaSolve(objectiveFunction12, u, 1, &rfi); - algebraic[9] = u[0]; + algebraic[10] = u[0]; } void objectiveFunction13(double *u, double *f, void *data) @@ -457,9 +456,9 @@ void objectiveFunction13(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - rates[3] = u[0]; + algebraic[11] = u[0]; - f[0] = rates[3]-(algebraic[8]*(1.0-states[3])-algebraic[9]*states[3])-0.0; + f[0] = algebraic[11]-0.125*exp(states[0]/80.0)-0.0; } void findRoot13(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -467,10 +466,36 @@ void findRoot13(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = rates[3]; + u[0] = algebraic[11]; nlaSolve(objectiveFunction13, u, 1, &rfi); + algebraic[11] = u[0]; +} + +void objectiveFunction14(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + + rates[3] = u[0]; + + f[0] = rates[3]-(algebraic[10]*(1.0-states[3])-algebraic[11]*states[3])-0.0; +} + +void findRoot14(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; + double u[1]; + + u[0] = rates[3]; + + nlaSolve(objectiveFunction14, u, 1, &rfi); + rates[3] = u[0]; } @@ -495,34 +520,35 @@ void initialiseVariables(double *states, double *rates, double *constants, doubl algebraic[3] = 0.0; algebraic[4] = 0.0; algebraic[5] = 0.0; - algebraic[6] = 0.0; algebraic[7] = 0.0; algebraic[8] = 0.0; algebraic[9] = 0.0; + algebraic[10] = 0.0; + algebraic[11] = 0.0; } void computeComputedConstants(double *constants, double *computedConstants) { - computedConstants[0] = constants[1]-10.613; - computedConstants[1] = constants[1]-115.0; - computedConstants[2] = constants[1]+12.0; + computedConstants[0] = constants[1]+12.0; } void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { findRoot0(voi, states, rates, constants, computedConstants, algebraic); findRoot2(voi, states, rates, constants, computedConstants, algebraic); - findRoot11(voi, states, rates, constants, computedConstants, algebraic); + findRoot3(voi, states, rates, constants, computedConstants, algebraic); findRoot12(voi, states, rates, constants, computedConstants, algebraic); findRoot13(voi, states, rates, constants, computedConstants, algebraic); - findRoot10(voi, states, rates, constants, computedConstants, algebraic); - findRoot7(voi, states, rates, constants, computedConstants, algebraic); + findRoot14(voi, states, rates, constants, computedConstants, algebraic); + findRoot11(voi, states, rates, constants, computedConstants, algebraic); findRoot8(voi, states, rates, constants, computedConstants, algebraic); findRoot9(voi, states, rates, constants, computedConstants, algebraic); + findRoot10(voi, states, rates, constants, computedConstants, algebraic); + double sodium_channel_m_gate_alpha_m = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + findRoot6(voi, states, rates, constants, computedConstants, algebraic); + findRoot7(voi, states, rates, constants, computedConstants, algebraic); findRoot4(voi, states, rates, constants, computedConstants, algebraic); findRoot5(voi, states, rates, constants, computedConstants, algebraic); - findRoot6(voi, states, rates, constants, computedConstants, algebraic); - findRoot3(voi, states, rates, constants, computedConstants, algebraic); findRoot1(voi, states, rates, constants, computedConstants, algebraic); } @@ -530,16 +556,18 @@ void computeVariables(double voi, double *states, double *rates, double *constan { findRoot0(voi, states, rates, constants, computedConstants, algebraic); findRoot2(voi, states, rates, constants, computedConstants, algebraic); - findRoot11(voi, states, rates, constants, computedConstants, algebraic); + findRoot3(voi, states, rates, constants, computedConstants, algebraic); findRoot12(voi, states, rates, constants, computedConstants, algebraic); findRoot13(voi, states, rates, constants, computedConstants, algebraic); - findRoot10(voi, states, rates, constants, computedConstants, algebraic); - findRoot7(voi, states, rates, constants, computedConstants, algebraic); + findRoot14(voi, states, rates, constants, computedConstants, algebraic); + findRoot11(voi, states, rates, constants, computedConstants, algebraic); findRoot8(voi, states, rates, constants, computedConstants, algebraic); findRoot9(voi, states, rates, constants, computedConstants, algebraic); + findRoot10(voi, states, rates, constants, computedConstants, algebraic); + double sodium_channel_m_gate_alpha_m = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + findRoot6(voi, states, rates, constants, computedConstants, algebraic); + findRoot7(voi, states, rates, constants, computedConstants, algebraic); findRoot4(voi, states, rates, constants, computedConstants, algebraic); findRoot5(voi, states, rates, constants, computedConstants, algebraic); - findRoot6(voi, states, rates, constants, computedConstants, algebraic); - findRoot3(voi, states, rates, constants, computedConstants, algebraic); findRoot1(voi, states, rates, constants, computedConstants, algebraic); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.py index 737c5060b..3c5b880b6 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.py @@ -9,8 +9,8 @@ STATE_COUNT = 4 CONSTANT_COUNT = 5 -COMPUTED_CONSTANT_COUNT = 3 -ALGEBRAIC_COUNT = 10 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 11 VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} @@ -30,8 +30,6 @@ ] COMPUTED_CONSTANT_INFO = [ - {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} ] @@ -40,7 +38,8 @@ {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, @@ -134,19 +133,19 @@ def objective_function_2(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[1] = u[0] + algebraic[4] = u[0] - f[0] = algebraic[1]-constants[2]*(states[0]-computed_constants[0])-0.0 + f[0] = algebraic[4]-(constants[1]-10.613)-0.0 def find_root_2(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[1] + u[0] = algebraic[4] u = nla_solve(objective_function_2, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[1] = u[0] + algebraic[4] = u[0] def objective_function_3(u, f, data): @@ -157,19 +156,19 @@ def objective_function_3(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[3] = u[0] + algebraic[1] = u[0] - f[0] = algebraic[3]-constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[1])-0.0 + f[0] = algebraic[1]-constants[2]*(states[0]-algebraic[4])-0.0 def find_root_3(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[3] + u[0] = algebraic[1] u = nla_solve(objective_function_3, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[3] = u[0] + algebraic[1] = u[0] def objective_function_4(u, f, data): @@ -180,19 +179,19 @@ def objective_function_4(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[4] = u[0] + algebraic[5] = u[0] - f[0] = algebraic[4]-0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0)-0.0 + f[0] = algebraic[5]-(constants[1]-115.0)-0.0 def find_root_4(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[4] + u[0] = algebraic[5] u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[4] = u[0] + algebraic[5] = u[0] def objective_function_5(u, f, data): @@ -203,19 +202,19 @@ def objective_function_5(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[5] = u[0] + algebraic[3] = u[0] - f[0] = algebraic[5]-4.0*exp(states[0]/18.0)-0.0 + f[0] = algebraic[3]-constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5])-0.0 def find_root_5(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[5] + u[0] = algebraic[3] u = nla_solve(objective_function_5, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[5] = u[0] + algebraic[3] = u[0] def objective_function_6(u, f, data): @@ -226,19 +225,19 @@ def objective_function_6(u, f, data): computed_constants = data[4] algebraic = data[5] - rates[2] = u[0] + algebraic[7] = u[0] - f[0] = rates[2]-(algebraic[4]*(1.0-states[2])-algebraic[5]*states[2])-0.0 + f[0] = algebraic[7]-4.0*exp(states[0]/18.0)-0.0 def find_root_6(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = rates[2] + u[0] = algebraic[7] u = nla_solve(objective_function_6, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - rates[2] = u[0] + algebraic[7] = u[0] def objective_function_7(u, f, data): @@ -249,19 +248,19 @@ def objective_function_7(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[6] = u[0] + rates[2] = u[0] - f[0] = algebraic[6]-0.07*exp(states[0]/20.0)-0.0 + f[0] = rates[2]-(sodium_channel_m_gate_alpha_m*(1.0-states[2])-algebraic[7]*states[2])-0.0 def find_root_7(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[6] + u[0] = rates[2] u = nla_solve(objective_function_7, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[6] = u[0] + rates[2] = u[0] def objective_function_8(u, f, data): @@ -272,19 +271,19 @@ def objective_function_8(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[7] = u[0] + algebraic[8] = u[0] - f[0] = algebraic[7]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 + f[0] = algebraic[8]-0.07*exp(states[0]/20.0)-0.0 def find_root_8(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[7] + u[0] = algebraic[8] u = nla_solve(objective_function_8, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[7] = u[0] + algebraic[8] = u[0] def objective_function_9(u, f, data): @@ -295,19 +294,19 @@ def objective_function_9(u, f, data): computed_constants = data[4] algebraic = data[5] - rates[1] = u[0] + algebraic[9] = u[0] - f[0] = rates[1]-(algebraic[6]*(1.0-states[1])-algebraic[7]*states[1])-0.0 + f[0] = algebraic[9]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 def find_root_9(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = rates[1] + u[0] = algebraic[9] u = nla_solve(objective_function_9, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - rates[1] = u[0] + algebraic[9] = u[0] def objective_function_10(u, f, data): @@ -318,19 +317,19 @@ def objective_function_10(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[2] = u[0] + rates[1] = u[0] - f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[2])-0.0 + f[0] = rates[1]-(algebraic[8]*(1.0-states[1])-algebraic[9]*states[1])-0.0 def find_root_10(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[2] + u[0] = rates[1] u = nla_solve(objective_function_10, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[2] = u[0] + rates[1] = u[0] def objective_function_11(u, f, data): @@ -341,19 +340,19 @@ def objective_function_11(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[8] = u[0] + algebraic[2] = u[0] - f[0] = algebraic[8]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 + f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[0])-0.0 def find_root_11(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[8] + u[0] = algebraic[2] u = nla_solve(objective_function_11, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[8] = u[0] + algebraic[2] = u[0] def objective_function_12(u, f, data): @@ -364,19 +363,19 @@ def objective_function_12(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[9] = u[0] + algebraic[10] = u[0] - f[0] = algebraic[9]-0.125*exp(states[0]/80.0)-0.0 + f[0] = algebraic[10]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 def find_root_12(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[9] + u[0] = algebraic[10] u = nla_solve(objective_function_12, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[9] = u[0] + algebraic[10] = u[0] def objective_function_13(u, f, data): @@ -387,18 +386,41 @@ def objective_function_13(u, f, data): computed_constants = data[4] algebraic = data[5] - rates[3] = u[0] + algebraic[11] = u[0] - f[0] = rates[3]-(algebraic[8]*(1.0-states[3])-algebraic[9]*states[3])-0.0 + f[0] = algebraic[11]-0.125*exp(states[0]/80.0)-0.0 def find_root_13(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = rates[3] + u[0] = algebraic[11] u = nla_solve(objective_function_13, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) + algebraic[11] = u[0] + + +def objective_function_14(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + + rates[3] = u[0] + + f[0] = rates[3]-(algebraic[10]*(1.0-states[3])-algebraic[11]*states[3])-0.0 + + +def find_root_14(voi, states, rates, constants, computed_constants, algebraic): + u = [nan]*1 + + u[0] = rates[3] + + u = nla_solve(objective_function_14, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) + rates[3] = u[0] @@ -422,47 +444,50 @@ def initialise_variables(states, rates, constants, computed_constants, algebraic algebraic[3] = 0.0 algebraic[4] = 0.0 algebraic[5] = 0.0 - algebraic[6] = 0.0 algebraic[7] = 0.0 algebraic[8] = 0.0 algebraic[9] = 0.0 + algebraic[10] = 0.0 + algebraic[11] = 0.0 def compute_computed_constants(constants, computed_constants): - computed_constants[0] = constants[1]-10.613 - computed_constants[1] = constants[1]-115.0 - computed_constants[2] = constants[1]+12.0 + computed_constants[0] = constants[1]+12.0 def compute_rates(voi, states, rates, constants, computed_constants, algebraic): find_root_0(voi, states, rates, constants, computed_constants, algebraic) find_root_2(voi, states, rates, constants, computed_constants, algebraic) - find_root_11(voi, states, rates, constants, computed_constants, algebraic) + find_root_3(voi, states, rates, constants, computed_constants, algebraic) find_root_12(voi, states, rates, constants, computed_constants, algebraic) find_root_13(voi, states, rates, constants, computed_constants, algebraic) - find_root_10(voi, states, rates, constants, computed_constants, algebraic) - find_root_7(voi, states, rates, constants, computed_constants, algebraic) + find_root_14(voi, states, rates, constants, computed_constants, algebraic) + find_root_11(voi, states, rates, constants, computed_constants, algebraic) find_root_8(voi, states, rates, constants, computed_constants, algebraic) find_root_9(voi, states, rates, constants, computed_constants, algebraic) + find_root_10(voi, states, rates, constants, computed_constants, algebraic) + sodium_channel_m_gate_alpha_m = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + find_root_6(voi, states, rates, constants, computed_constants, algebraic) + find_root_7(voi, states, rates, constants, computed_constants, algebraic) find_root_4(voi, states, rates, constants, computed_constants, algebraic) find_root_5(voi, states, rates, constants, computed_constants, algebraic) - find_root_6(voi, states, rates, constants, computed_constants, algebraic) - find_root_3(voi, states, rates, constants, computed_constants, algebraic) find_root_1(voi, states, rates, constants, computed_constants, algebraic) def compute_variables(voi, states, rates, constants, computed_constants, algebraic): find_root_0(voi, states, rates, constants, computed_constants, algebraic) find_root_2(voi, states, rates, constants, computed_constants, algebraic) - find_root_11(voi, states, rates, constants, computed_constants, algebraic) + find_root_3(voi, states, rates, constants, computed_constants, algebraic) find_root_12(voi, states, rates, constants, computed_constants, algebraic) find_root_13(voi, states, rates, constants, computed_constants, algebraic) - find_root_10(voi, states, rates, constants, computed_constants, algebraic) - find_root_7(voi, states, rates, constants, computed_constants, algebraic) + find_root_14(voi, states, rates, constants, computed_constants, algebraic) + find_root_11(voi, states, rates, constants, computed_constants, algebraic) find_root_8(voi, states, rates, constants, computed_constants, algebraic) find_root_9(voi, states, rates, constants, computed_constants, algebraic) + find_root_10(voi, states, rates, constants, computed_constants, algebraic) + sodium_channel_m_gate_alpha_m = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + find_root_6(voi, states, rates, constants, computed_constants, algebraic) + find_root_7(voi, states, rates, constants, computed_constants, algebraic) find_root_4(voi, states, rates, constants, computed_constants, algebraic) find_root_5(voi, states, rates, constants, computed_constants, algebraic) - find_root_6(voi, states, rates, constants, computed_constants, algebraic) - find_root_3(voi, states, rates, constants, computed_constants, algebraic) find_root_1(voi, states, rates, constants, computed_constants, algebraic) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.with.externals.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.with.externals.c index fe6b5a8ed..e6d8a5214 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.with.externals.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.with.externals.c @@ -8,15 +8,16 @@ const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.2"; -const size_t STATE_COUNT = 3; +const size_t STATE_COUNT = 4; const size_t CONSTANT_COUNT = 5; -const size_t COMPUTED_CONSTANT_COUNT = 3; -const size_t ALGEBRAIC_COUNT = 8; -const size_t EXTERNAL_COUNT = 3; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 11; +const size_t EXTERNAL_COUNT = 1; const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, {"h", "dimensionless", "sodium_channel_h_gate"}, {"m", "dimensionless", "sodium_channel_m_gate"}, {"n", "dimensionless", "potassium_channel_n_gate"} @@ -31,8 +32,6 @@ const VariableInfo CONSTANT_INFO[] = { }; const VariableInfo COMPUTED_CONSTANT_INFO[] = { - {"E_L", "millivolt", "leakage_current"}, - {"E_Na", "millivolt", "sodium_channel"}, {"E_K", "millivolt", "potassium_channel"} }; @@ -40,17 +39,18 @@ const VariableInfo ALGEBRAIC_INFO[] = { {"i_Stim", "microA_per_cm2", "membrane"}, {"i_L", "microA_per_cm2", "leakage_current"}, {"i_K", "microA_per_cm2", "potassium_channel"}, + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, {"beta_n", "per_millisecond", "potassium_channel_n_gate"} }; const VariableInfo EXTERNAL_INFO[] = { - {"V", "millivolt", "membrane"}, - {"i_Na", "microA_per_cm2", "sodium_channel"}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate"} + {"i_Na", "microA_per_cm2", "sodium_channel"} }; double * createStatesArray() @@ -153,7 +153,7 @@ void findRoot0(double voi, double *states, double *rates, double *constants, dou algebraic[0] = u[0]; } -void objectiveFunction2(double *u, double *f, void *data) +void objectiveFunction1(double *u, double *f, void *data) { double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; @@ -163,24 +163,24 @@ void objectiveFunction2(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[1] = u[0]; + rates[0] = u[0]; - f[0] = algebraic[1]-constants[2]*(externals[0]-computedConstants[0])-0.0; + f[0] = rates[0]-(-(-algebraic[0]+externals[0]+algebraic[2]+algebraic[1])/constants[0])-0.0; } -void findRoot2(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +void findRoot1(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[1]; + u[0] = rates[0]; - nlaSolve(objectiveFunction2, u, 1, &rfi); + nlaSolve(objectiveFunction1, u, 1, &rfi); - algebraic[1] = u[0]; + rates[0] = u[0]; } -void objectiveFunction4(double *u, double *f, void *data) +void objectiveFunction2(double *u, double *f, void *data) { double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; @@ -192,22 +192,49 @@ void objectiveFunction4(double *u, double *f, void *data) algebraic[3] = u[0]; - f[0] = algebraic[3]-0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0)-0.0; + f[0] = algebraic[3]-(constants[1]-10.613)-0.0; } -void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +void findRoot2(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; u[0] = algebraic[3]; - nlaSolve(objectiveFunction4, u, 1, &rfi); + nlaSolve(objectiveFunction2, u, 1, &rfi); algebraic[3] = u[0]; } -void objectiveFunction5(double *u, double *f, void *data) +void objectiveFunction3(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[1] = u[0]; + + f[0] = algebraic[1]-constants[2]*(states[0]-algebraic[3])-0.0; +} + +void findRoot3(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[1]; + + nlaSolve(objectiveFunction3, u, 1, &rfi); + + algebraic[1] = u[0]; +} + +void objectiveFunction4(double *u, double *f, void *data) { double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; @@ -219,17 +246,17 @@ void objectiveFunction5(double *u, double *f, void *data) algebraic[4] = u[0]; - f[0] = algebraic[4]-4.0*exp(externals[0]/18.0)-0.0; + f[0] = algebraic[4]-(constants[1]-115.0)-0.0; } -void findRoot5(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; u[0] = algebraic[4]; - nlaSolve(objectiveFunction5, u, 1, &rfi); + nlaSolve(objectiveFunction4, u, 1, &rfi); algebraic[4] = u[0]; } @@ -244,9 +271,9 @@ void objectiveFunction6(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - rates[1] = u[0]; + algebraic[6] = u[0]; - f[0] = rates[1]-(algebraic[3]*(1.0-states[1])-algebraic[4]*states[1])-0.0; + f[0] = algebraic[6]-4.0*exp(states[0]/18.0)-0.0; } void findRoot6(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -254,11 +281,11 @@ void findRoot6(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = rates[1]; + u[0] = algebraic[6]; nlaSolve(objectiveFunction6, u, 1, &rfi); - rates[1] = u[0]; + algebraic[6] = u[0]; } void objectiveFunction7(double *u, double *f, void *data) @@ -271,9 +298,9 @@ void objectiveFunction7(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[5] = u[0]; + rates[2] = u[0]; - f[0] = algebraic[5]-0.07*exp(externals[0]/20.0)-0.0; + f[0] = rates[2]-(algebraic[5]*(1.0-states[2])-algebraic[6]*states[2])-0.0; } void findRoot7(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -281,11 +308,11 @@ void findRoot7(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[5]; + u[0] = rates[2]; nlaSolve(objectiveFunction7, u, 1, &rfi); - algebraic[5] = u[0]; + rates[2] = u[0]; } void objectiveFunction8(double *u, double *f, void *data) @@ -298,9 +325,9 @@ void objectiveFunction8(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[6] = u[0]; + algebraic[7] = u[0]; - f[0] = algebraic[6]-1.0/(exp((externals[0]+30.0)/10.0)+1.0)-0.0; + f[0] = algebraic[7]-0.07*exp(states[0]/20.0)-0.0; } void findRoot8(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -308,11 +335,11 @@ void findRoot8(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[6]; + u[0] = algebraic[7]; nlaSolve(objectiveFunction8, u, 1, &rfi); - algebraic[6] = u[0]; + algebraic[7] = u[0]; } void objectiveFunction9(double *u, double *f, void *data) @@ -325,9 +352,9 @@ void objectiveFunction9(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - rates[0] = u[0]; + algebraic[8] = u[0]; - f[0] = rates[0]-(algebraic[5]*(1.0-states[0])-algebraic[6]*states[0])-0.0; + f[0] = algebraic[8]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; } void findRoot9(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -335,11 +362,11 @@ void findRoot9(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = rates[0]; + u[0] = algebraic[8]; nlaSolve(objectiveFunction9, u, 1, &rfi); - rates[0] = u[0]; + algebraic[8] = u[0]; } void objectiveFunction10(double *u, double *f, void *data) @@ -352,9 +379,9 @@ void objectiveFunction10(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[2] = u[0]; + rates[1] = u[0]; - f[0] = algebraic[2]-constants[4]*pow(states[2], 4.0)*(externals[0]-computedConstants[2])-0.0; + f[0] = rates[1]-(algebraic[7]*(1.0-states[1])-algebraic[8]*states[1])-0.0; } void findRoot10(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -362,10 +389,37 @@ void findRoot10(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[2]; + u[0] = rates[1]; nlaSolve(objectiveFunction10, u, 1, &rfi); + rates[1] = u[0]; +} + +void objectiveFunction11(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[2] = u[0]; + + f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[0])-0.0; +} + +void findRoot11(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[2]; + + nlaSolve(objectiveFunction11, u, 1, &rfi); + algebraic[2] = u[0]; } @@ -379,9 +433,9 @@ void objectiveFunction12(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[7] = u[0]; + algebraic[9] = u[0]; - f[0] = algebraic[7]-0.125*exp(externals[0]/80.0)-0.0; + f[0] = algebraic[9]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; } void findRoot12(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -389,11 +443,11 @@ void findRoot12(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[7]; + u[0] = algebraic[9]; nlaSolve(objectiveFunction12, u, 1, &rfi); - algebraic[7] = u[0]; + algebraic[9] = u[0]; } void objectiveFunction13(double *u, double *f, void *data) @@ -406,9 +460,9 @@ void objectiveFunction13(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - rates[2] = u[0]; + algebraic[10] = u[0]; - f[0] = rates[2]-(externals[2]*(1.0-states[2])-algebraic[7]*states[2])-0.0; + f[0] = algebraic[10]-0.125*exp(states[0]/80.0)-0.0; } void findRoot13(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -416,21 +470,50 @@ void findRoot13(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = rates[2]; + u[0] = algebraic[10]; nlaSolve(objectiveFunction13, u, 1, &rfi); - rates[2] = u[0]; + algebraic[10] = u[0]; +} + +void objectiveFunction14(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + rates[3] = u[0]; + + f[0] = rates[3]-(algebraic[9]*(1.0-states[3])-algebraic[10]*states[3])-0.0; +} + +void findRoot14(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = rates[3]; + + nlaSolve(objectiveFunction14, u, 1, &rfi); + + rates[3] = u[0]; } void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - states[0] = 0.6; - states[1] = 0.05; - states[2] = 0.325; + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; rates[0] = 0.0; rates[1] = 0.0; rates[2] = 0.0; + rates[3] = 0.0; constants[0] = 1.0; constants[1] = 0.0; constants[2] = 0.3; @@ -441,38 +524,51 @@ void initialiseVariables(double *states, double *rates, double *constants, doubl algebraic[2] = 0.0; algebraic[3] = 0.0; algebraic[4] = 0.0; - algebraic[5] = 0.0; algebraic[6] = 0.0; algebraic[7] = 0.0; + algebraic[8] = 0.0; + algebraic[9] = 0.0; + algebraic[10] = 0.0; } void computeComputedConstants(double *constants, double *computedConstants) { - computedConstants[0] = constants[1]-10.613; - computedConstants[1] = constants[1]-115.0; - computedConstants[2] = constants[1]+12.0; + computedConstants[0] = constants[1]+12.0; } void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { + findRoot0(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot2(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot3(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot12(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot13(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot14(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot11(voi, states, rates, constants, computedConstants, algebraic, externals); + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); - findRoot4(voi, states, rates, constants, computedConstants, algebraic, externals); - findRoot5(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot1(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot6(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot7(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot8(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot9(voi, states, rates, constants, computedConstants, algebraic, externals); - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - findRoot12(voi, states, rates, constants, computedConstants, algebraic, externals); - findRoot13(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot10(voi, states, rates, constants, computedConstants, algebraic, externals); } void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - findRoot0(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot3(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot12(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot13(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot14(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot11(voi, states, rates, constants, computedConstants, algebraic, externals); + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); - findRoot2(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot1(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot4(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot6(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot7(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot8(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot9(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot10(voi, states, rates, constants, computedConstants, algebraic, externals); - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.with.externals.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.with.externals.py index a5951dada..b5fdad176 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.with.externals.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.algebraic.variables.with.externals.py @@ -7,15 +7,16 @@ __version__ = "0.5.0" LIBCELLML_VERSION = "0.6.2" -STATE_COUNT = 3 +STATE_COUNT = 4 CONSTANT_COUNT = 5 -COMPUTED_CONSTANT_COUNT = 3 -ALGEBRAIC_COUNT = 8 -EXTERNAL_COUNT = 3 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 11 +EXTERNAL_COUNT = 1 VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} @@ -30,8 +31,6 @@ ] COMPUTED_CONSTANT_INFO = [ - {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} ] @@ -39,17 +38,18 @@ {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} ] EXTERNAL_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane"}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"} ] @@ -112,7 +112,7 @@ def find_root_0(voi, states, rates, constants, computed_constants, algebraic, ex algebraic[0] = u[0] -def objective_function_2(u, f, data): +def objective_function_1(u, f, data): voi = data[0] states = data[1] rates = data[2] @@ -121,22 +121,22 @@ def objective_function_2(u, f, data): algebraic = data[5] externals = data[6] - algebraic[1] = u[0] + rates[0] = u[0] - f[0] = algebraic[1]-constants[2]*(externals[0]-computed_constants[0])-0.0 + f[0] = rates[0]-(-(-algebraic[0]+externals[0]+algebraic[2]+algebraic[1])/constants[0])-0.0 -def find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals): +def find_root_1(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[1] + u[0] = rates[0] - u = nla_solve(objective_function_2, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + u = nla_solve(objective_function_1, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[1] = u[0] + rates[0] = u[0] -def objective_function_4(u, f, data): +def objective_function_2(u, f, data): voi = data[0] states = data[1] rates = data[2] @@ -147,20 +147,44 @@ def objective_function_4(u, f, data): algebraic[3] = u[0] - f[0] = algebraic[3]-0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0)-0.0 + f[0] = algebraic[3]-(constants[1]-10.613)-0.0 -def find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals): +def find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 u[0] = algebraic[3] - u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + u = nla_solve(objective_function_2, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) algebraic[3] = u[0] -def objective_function_5(u, f, data): +def objective_function_3(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[1] = u[0] + + f[0] = algebraic[1]-constants[2]*(states[0]-algebraic[3])-0.0 + + +def find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[1] + + u = nla_solve(objective_function_3, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[1] = u[0] + + +def objective_function_4(u, f, data): voi = data[0] states = data[1] rates = data[2] @@ -171,15 +195,15 @@ def objective_function_5(u, f, data): algebraic[4] = u[0] - f[0] = algebraic[4]-4.0*exp(externals[0]/18.0)-0.0 + f[0] = algebraic[4]-(constants[1]-115.0)-0.0 -def find_root_5(voi, states, rates, constants, computed_constants, algebraic, externals): +def find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 u[0] = algebraic[4] - u = nla_solve(objective_function_5, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) algebraic[4] = u[0] @@ -193,19 +217,19 @@ def objective_function_6(u, f, data): algebraic = data[5] externals = data[6] - rates[1] = u[0] + algebraic[6] = u[0] - f[0] = rates[1]-(algebraic[3]*(1.0-states[1])-algebraic[4]*states[1])-0.0 + f[0] = algebraic[6]-4.0*exp(states[0]/18.0)-0.0 def find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = rates[1] + u[0] = algebraic[6] u = nla_solve(objective_function_6, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - rates[1] = u[0] + algebraic[6] = u[0] def objective_function_7(u, f, data): @@ -217,19 +241,19 @@ def objective_function_7(u, f, data): algebraic = data[5] externals = data[6] - algebraic[5] = u[0] + rates[2] = u[0] - f[0] = algebraic[5]-0.07*exp(externals[0]/20.0)-0.0 + f[0] = rates[2]-(algebraic[5]*(1.0-states[2])-algebraic[6]*states[2])-0.0 def find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[5] + u[0] = rates[2] u = nla_solve(objective_function_7, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[5] = u[0] + rates[2] = u[0] def objective_function_8(u, f, data): @@ -241,19 +265,19 @@ def objective_function_8(u, f, data): algebraic = data[5] externals = data[6] - algebraic[6] = u[0] + algebraic[7] = u[0] - f[0] = algebraic[6]-1.0/(exp((externals[0]+30.0)/10.0)+1.0)-0.0 + f[0] = algebraic[7]-0.07*exp(states[0]/20.0)-0.0 def find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[6] + u[0] = algebraic[7] u = nla_solve(objective_function_8, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[6] = u[0] + algebraic[7] = u[0] def objective_function_9(u, f, data): @@ -265,19 +289,19 @@ def objective_function_9(u, f, data): algebraic = data[5] externals = data[6] - rates[0] = u[0] + algebraic[8] = u[0] - f[0] = rates[0]-(algebraic[5]*(1.0-states[0])-algebraic[6]*states[0])-0.0 + f[0] = algebraic[8]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 def find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = rates[0] + u[0] = algebraic[8] u = nla_solve(objective_function_9, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - rates[0] = u[0] + algebraic[8] = u[0] def objective_function_10(u, f, data): @@ -289,18 +313,42 @@ def objective_function_10(u, f, data): algebraic = data[5] externals = data[6] - algebraic[2] = u[0] + rates[1] = u[0] - f[0] = algebraic[2]-constants[4]*pow(states[2], 4.0)*(externals[0]-computed_constants[2])-0.0 + f[0] = rates[1]-(algebraic[7]*(1.0-states[1])-algebraic[8]*states[1])-0.0 def find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[2] + u[0] = rates[1] u = nla_solve(objective_function_10, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + rates[1] = u[0] + + +def objective_function_11(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[2] = u[0] + + f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[0])-0.0 + + +def find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[2] + + u = nla_solve(objective_function_11, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + algebraic[2] = u[0] @@ -313,19 +361,19 @@ def objective_function_12(u, f, data): algebraic = data[5] externals = data[6] - algebraic[7] = u[0] + algebraic[9] = u[0] - f[0] = algebraic[7]-0.125*exp(externals[0]/80.0)-0.0 + f[0] = algebraic[9]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 def find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[7] + u[0] = algebraic[9] u = nla_solve(objective_function_12, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[7] = u[0] + algebraic[9] = u[0] def objective_function_13(u, f, data): @@ -337,28 +385,54 @@ def objective_function_13(u, f, data): algebraic = data[5] externals = data[6] - rates[2] = u[0] + algebraic[10] = u[0] - f[0] = rates[2]-(externals[2]*(1.0-states[2])-algebraic[7]*states[2])-0.0 + f[0] = algebraic[10]-0.125*exp(states[0]/80.0)-0.0 def find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = rates[2] + u[0] = algebraic[10] u = nla_solve(objective_function_13, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - rates[2] = u[0] + algebraic[10] = u[0] + + +def objective_function_14(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + rates[3] = u[0] + + f[0] = rates[3]-(algebraic[9]*(1.0-states[3])-algebraic[10]*states[3])-0.0 + + +def find_root_14(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = rates[3] + + u = nla_solve(objective_function_14, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + rates[3] = u[0] def initialise_variables(states, rates, constants, computed_constants, algebraic): - states[0] = 0.6 - states[1] = 0.05 - states[2] = 0.325 + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 rates[0] = 0.0 rates[1] = 0.0 rates[2] = 0.0 + rates[3] = 0.0 constants[0] = 1.0 constants[1] = 0.0 constants[2] = 0.3 @@ -369,34 +443,47 @@ def initialise_variables(states, rates, constants, computed_constants, algebraic algebraic[2] = 0.0 algebraic[3] = 0.0 algebraic[4] = 0.0 - algebraic[5] = 0.0 algebraic[6] = 0.0 algebraic[7] = 0.0 + algebraic[8] = 0.0 + algebraic[9] = 0.0 + algebraic[10] = 0.0 def compute_computed_constants(constants, computed_constants): - computed_constants[0] = constants[1]-10.613 - computed_constants[1] = constants[1]-115.0 - computed_constants[2] = constants[1]+12.0 + computed_constants[0] = constants[1]+12.0 def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_14(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals) + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) - find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals) - find_root_5(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_1(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals) - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals) - find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals) def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): - find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_14(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals) + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) - find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_1(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals) - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.c index 9759d65e9..ef9b5f486 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.c @@ -11,7 +11,7 @@ const char LIBCELLML_VERSION[] = "0.6.2"; const size_t STATE_COUNT = 4; const size_t CONSTANT_COUNT = 5; const size_t COMPUTED_CONSTANT_COUNT = 0; -const size_t ALGEBRAIC_COUNT = 10; +const size_t ALGEBRAIC_COUNT = 12; const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; @@ -38,6 +38,8 @@ const VariableInfo ALGEBRAIC_INFO[] = { {"i_L", "microA_per_cm2", "leakage_current"}, {"i_K", "microA_per_cm2", "potassium_channel"}, {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, @@ -168,11 +170,9 @@ void objectiveFunction2(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[1] = u[0]; - - double leakage_current_E_L = constants[1]-10.613; + algebraic[4] = u[0]; - f[0] = algebraic[1]-constants[2]*(states[0]-leakage_current_E_L)-0.0; + f[0] = algebraic[4]-(constants[1]-10.613)-0.0; } void findRoot2(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -180,11 +180,11 @@ void findRoot2(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[1]; + u[0] = algebraic[4]; nlaSolve(objectiveFunction2, u, 1, &rfi); - algebraic[1] = u[0]; + algebraic[4] = u[0]; } void objectiveFunction3(double *u, double *f, void *data) @@ -196,11 +196,9 @@ void objectiveFunction3(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[3] = u[0]; - - double sodium_channel_E_Na = constants[1]-115.0; + algebraic[1] = u[0]; - f[0] = algebraic[3]-constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-sodium_channel_E_Na)-0.0; + f[0] = algebraic[1]-constants[2]*(states[0]-algebraic[4])-0.0; } void findRoot3(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -208,11 +206,11 @@ void findRoot3(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[3]; + u[0] = algebraic[1]; nlaSolve(objectiveFunction3, u, 1, &rfi); - algebraic[3] = u[0]; + algebraic[1] = u[0]; } void objectiveFunction4(double *u, double *f, void *data) @@ -224,9 +222,9 @@ void objectiveFunction4(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[4] = u[0]; + algebraic[5] = u[0]; - f[0] = algebraic[4]-0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0)-0.0; + f[0] = algebraic[5]-(constants[1]-115.0)-0.0; } void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -234,11 +232,11 @@ void findRoot4(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[4]; + u[0] = algebraic[5]; nlaSolve(objectiveFunction4, u, 1, &rfi); - algebraic[4] = u[0]; + algebraic[5] = u[0]; } void objectiveFunction5(double *u, double *f, void *data) @@ -250,9 +248,9 @@ void objectiveFunction5(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[5] = u[0]; + algebraic[3] = u[0]; - f[0] = algebraic[5]-4.0*exp(states[0]/18.0)-0.0; + f[0] = algebraic[3]-constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5])-0.0; } void findRoot5(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -260,11 +258,11 @@ void findRoot5(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[5]; + u[0] = algebraic[3]; nlaSolve(objectiveFunction5, u, 1, &rfi); - algebraic[5] = u[0]; + algebraic[3] = u[0]; } void objectiveFunction6(double *u, double *f, void *data) @@ -276,9 +274,9 @@ void objectiveFunction6(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - rates[2] = u[0]; + algebraic[7] = u[0]; - f[0] = rates[2]-(algebraic[4]*(1.0-states[2])-algebraic[5]*states[2])-0.0; + f[0] = algebraic[7]-4.0*exp(states[0]/18.0)-0.0; } void findRoot6(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -286,11 +284,11 @@ void findRoot6(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = rates[2]; + u[0] = algebraic[7]; nlaSolve(objectiveFunction6, u, 1, &rfi); - rates[2] = u[0]; + algebraic[7] = u[0]; } void objectiveFunction7(double *u, double *f, void *data) @@ -302,9 +300,9 @@ void objectiveFunction7(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[6] = u[0]; + rates[2] = u[0]; - f[0] = algebraic[6]-0.07*exp(states[0]/20.0)-0.0; + f[0] = rates[2]-(algebraic[6]*(1.0-states[2])-algebraic[7]*states[2])-0.0; } void findRoot7(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -312,11 +310,11 @@ void findRoot7(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[6]; + u[0] = rates[2]; nlaSolve(objectiveFunction7, u, 1, &rfi); - algebraic[6] = u[0]; + rates[2] = u[0]; } void objectiveFunction8(double *u, double *f, void *data) @@ -328,9 +326,9 @@ void objectiveFunction8(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[7] = u[0]; + algebraic[8] = u[0]; - f[0] = algebraic[7]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; + f[0] = algebraic[8]-0.07*exp(states[0]/20.0)-0.0; } void findRoot8(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -338,11 +336,11 @@ void findRoot8(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[7]; + u[0] = algebraic[8]; nlaSolve(objectiveFunction8, u, 1, &rfi); - algebraic[7] = u[0]; + algebraic[8] = u[0]; } void objectiveFunction9(double *u, double *f, void *data) @@ -354,9 +352,9 @@ void objectiveFunction9(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - rates[1] = u[0]; + algebraic[9] = u[0]; - f[0] = rates[1]-(algebraic[6]*(1.0-states[1])-algebraic[7]*states[1])-0.0; + f[0] = algebraic[9]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; } void findRoot9(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -364,11 +362,11 @@ void findRoot9(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = rates[1]; + u[0] = algebraic[9]; nlaSolve(objectiveFunction9, u, 1, &rfi); - rates[1] = u[0]; + algebraic[9] = u[0]; } void objectiveFunction10(double *u, double *f, void *data) @@ -380,11 +378,9 @@ void objectiveFunction10(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[2] = u[0]; - - double potassium_channel_E_K = constants[1]+12.0; + rates[1] = u[0]; - f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-potassium_channel_E_K)-0.0; + f[0] = rates[1]-(algebraic[8]*(1.0-states[1])-algebraic[9]*states[1])-0.0; } void findRoot10(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -392,11 +388,11 @@ void findRoot10(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[2]; + u[0] = rates[1]; nlaSolve(objectiveFunction10, u, 1, &rfi); - algebraic[2] = u[0]; + rates[1] = u[0]; } void objectiveFunction11(double *u, double *f, void *data) @@ -408,9 +404,11 @@ void objectiveFunction11(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[8] = u[0]; + algebraic[2] = u[0]; + + double potassium_channel_E_K = constants[1]+12.0; - f[0] = algebraic[8]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; + f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-potassium_channel_E_K)-0.0; } void findRoot11(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -418,11 +416,11 @@ void findRoot11(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[8]; + u[0] = algebraic[2]; nlaSolve(objectiveFunction11, u, 1, &rfi); - algebraic[8] = u[0]; + algebraic[2] = u[0]; } void objectiveFunction12(double *u, double *f, void *data) @@ -434,9 +432,9 @@ void objectiveFunction12(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[9] = u[0]; + algebraic[10] = u[0]; - f[0] = algebraic[9]-0.125*exp(states[0]/80.0)-0.0; + f[0] = algebraic[10]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; } void findRoot12(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -444,11 +442,11 @@ void findRoot12(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[9]; + u[0] = algebraic[10]; nlaSolve(objectiveFunction12, u, 1, &rfi); - algebraic[9] = u[0]; + algebraic[10] = u[0]; } void objectiveFunction13(double *u, double *f, void *data) @@ -460,9 +458,9 @@ void objectiveFunction13(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - rates[3] = u[0]; + algebraic[11] = u[0]; - f[0] = rates[3]-(algebraic[8]*(1.0-states[3])-algebraic[9]*states[3])-0.0; + f[0] = algebraic[11]-0.125*exp(states[0]/80.0)-0.0; } void findRoot13(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -470,10 +468,36 @@ void findRoot13(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = rates[3]; + u[0] = algebraic[11]; nlaSolve(objectiveFunction13, u, 1, &rfi); + algebraic[11] = u[0]; +} + +void objectiveFunction14(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + + rates[3] = u[0]; + + f[0] = rates[3]-(algebraic[10]*(1.0-states[3])-algebraic[11]*states[3])-0.0; +} + +void findRoot14(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; + double u[1]; + + u[0] = rates[3]; + + nlaSolve(objectiveFunction14, u, 1, &rfi); + rates[3] = u[0]; } @@ -498,10 +522,11 @@ void initialiseVariables(double *states, double *rates, double *constants, doubl algebraic[3] = 0.0; algebraic[4] = 0.0; algebraic[5] = 0.0; - algebraic[6] = 0.0; algebraic[7] = 0.0; algebraic[8] = 0.0; algebraic[9] = 0.0; + algebraic[10] = 0.0; + algebraic[11] = 0.0; } void computeComputedConstants(double *constants, double *computedConstants) @@ -511,41 +536,41 @@ void computeComputedConstants(double *constants, double *computedConstants) void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { findRoot0(voi, states, rates, constants, computedConstants, algebraic); - double leakage_current_E_L = constants[1]-10.613; findRoot2(voi, states, rates, constants, computedConstants, algebraic); + findRoot3(voi, states, rates, constants, computedConstants, algebraic); double potassium_channel_E_K = constants[1]+12.0; - findRoot11(voi, states, rates, constants, computedConstants, algebraic); findRoot12(voi, states, rates, constants, computedConstants, algebraic); findRoot13(voi, states, rates, constants, computedConstants, algebraic); - findRoot10(voi, states, rates, constants, computedConstants, algebraic); - double sodium_channel_E_Na = constants[1]-115.0; - findRoot7(voi, states, rates, constants, computedConstants, algebraic); + findRoot14(voi, states, rates, constants, computedConstants, algebraic); + findRoot11(voi, states, rates, constants, computedConstants, algebraic); findRoot8(voi, states, rates, constants, computedConstants, algebraic); findRoot9(voi, states, rates, constants, computedConstants, algebraic); + findRoot10(voi, states, rates, constants, computedConstants, algebraic); + algebraic[6] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + findRoot6(voi, states, rates, constants, computedConstants, algebraic); + findRoot7(voi, states, rates, constants, computedConstants, algebraic); findRoot4(voi, states, rates, constants, computedConstants, algebraic); findRoot5(voi, states, rates, constants, computedConstants, algebraic); - findRoot6(voi, states, rates, constants, computedConstants, algebraic); - findRoot3(voi, states, rates, constants, computedConstants, algebraic); findRoot1(voi, states, rates, constants, computedConstants, algebraic); } void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { findRoot0(voi, states, rates, constants, computedConstants, algebraic); - double leakage_current_E_L = constants[1]-10.613; findRoot2(voi, states, rates, constants, computedConstants, algebraic); + findRoot3(voi, states, rates, constants, computedConstants, algebraic); double potassium_channel_E_K = constants[1]+12.0; - findRoot11(voi, states, rates, constants, computedConstants, algebraic); findRoot12(voi, states, rates, constants, computedConstants, algebraic); findRoot13(voi, states, rates, constants, computedConstants, algebraic); - findRoot10(voi, states, rates, constants, computedConstants, algebraic); - double sodium_channel_E_Na = constants[1]-115.0; - findRoot7(voi, states, rates, constants, computedConstants, algebraic); + findRoot14(voi, states, rates, constants, computedConstants, algebraic); + findRoot11(voi, states, rates, constants, computedConstants, algebraic); findRoot8(voi, states, rates, constants, computedConstants, algebraic); findRoot9(voi, states, rates, constants, computedConstants, algebraic); + findRoot10(voi, states, rates, constants, computedConstants, algebraic); + algebraic[6] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + findRoot6(voi, states, rates, constants, computedConstants, algebraic); + findRoot7(voi, states, rates, constants, computedConstants, algebraic); findRoot4(voi, states, rates, constants, computedConstants, algebraic); findRoot5(voi, states, rates, constants, computedConstants, algebraic); - findRoot6(voi, states, rates, constants, computedConstants, algebraic); - findRoot3(voi, states, rates, constants, computedConstants, algebraic); findRoot1(voi, states, rates, constants, computedConstants, algebraic); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.py index fca190d22..cb5a71ca8 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.py @@ -10,7 +10,7 @@ STATE_COUNT = 4 CONSTANT_COUNT = 5 COMPUTED_CONSTANT_COUNT = 0 -ALGEBRAIC_COUNT = 10 +ALGEBRAIC_COUNT = 12 VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} @@ -37,6 +37,8 @@ {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, @@ -131,21 +133,19 @@ def objective_function_2(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[1] = u[0] - - leakage_current_E_L = constants[1]-10.613 + algebraic[4] = u[0] - f[0] = algebraic[1]-constants[2]*(states[0]-leakage_current_E_L)-0.0 + f[0] = algebraic[4]-(constants[1]-10.613)-0.0 def find_root_2(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[1] + u[0] = algebraic[4] u = nla_solve(objective_function_2, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[1] = u[0] + algebraic[4] = u[0] def objective_function_3(u, f, data): @@ -156,21 +156,19 @@ def objective_function_3(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[3] = u[0] - - sodium_channel_E_Na = constants[1]-115.0 + algebraic[1] = u[0] - f[0] = algebraic[3]-constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-sodium_channel_E_Na)-0.0 + f[0] = algebraic[1]-constants[2]*(states[0]-algebraic[4])-0.0 def find_root_3(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[3] + u[0] = algebraic[1] u = nla_solve(objective_function_3, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[3] = u[0] + algebraic[1] = u[0] def objective_function_4(u, f, data): @@ -181,19 +179,19 @@ def objective_function_4(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[4] = u[0] + algebraic[5] = u[0] - f[0] = algebraic[4]-0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0)-0.0 + f[0] = algebraic[5]-(constants[1]-115.0)-0.0 def find_root_4(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[4] + u[0] = algebraic[5] u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[4] = u[0] + algebraic[5] = u[0] def objective_function_5(u, f, data): @@ -204,19 +202,19 @@ def objective_function_5(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[5] = u[0] + algebraic[3] = u[0] - f[0] = algebraic[5]-4.0*exp(states[0]/18.0)-0.0 + f[0] = algebraic[3]-constants[3]*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5])-0.0 def find_root_5(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[5] + u[0] = algebraic[3] u = nla_solve(objective_function_5, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[5] = u[0] + algebraic[3] = u[0] def objective_function_6(u, f, data): @@ -227,19 +225,19 @@ def objective_function_6(u, f, data): computed_constants = data[4] algebraic = data[5] - rates[2] = u[0] + algebraic[7] = u[0] - f[0] = rates[2]-(algebraic[4]*(1.0-states[2])-algebraic[5]*states[2])-0.0 + f[0] = algebraic[7]-4.0*exp(states[0]/18.0)-0.0 def find_root_6(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = rates[2] + u[0] = algebraic[7] u = nla_solve(objective_function_6, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - rates[2] = u[0] + algebraic[7] = u[0] def objective_function_7(u, f, data): @@ -250,19 +248,19 @@ def objective_function_7(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[6] = u[0] + rates[2] = u[0] - f[0] = algebraic[6]-0.07*exp(states[0]/20.0)-0.0 + f[0] = rates[2]-(algebraic[6]*(1.0-states[2])-algebraic[7]*states[2])-0.0 def find_root_7(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[6] + u[0] = rates[2] u = nla_solve(objective_function_7, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[6] = u[0] + rates[2] = u[0] def objective_function_8(u, f, data): @@ -273,19 +271,19 @@ def objective_function_8(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[7] = u[0] + algebraic[8] = u[0] - f[0] = algebraic[7]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 + f[0] = algebraic[8]-0.07*exp(states[0]/20.0)-0.0 def find_root_8(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[7] + u[0] = algebraic[8] u = nla_solve(objective_function_8, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[7] = u[0] + algebraic[8] = u[0] def objective_function_9(u, f, data): @@ -296,19 +294,19 @@ def objective_function_9(u, f, data): computed_constants = data[4] algebraic = data[5] - rates[1] = u[0] + algebraic[9] = u[0] - f[0] = rates[1]-(algebraic[6]*(1.0-states[1])-algebraic[7]*states[1])-0.0 + f[0] = algebraic[9]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 def find_root_9(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = rates[1] + u[0] = algebraic[9] u = nla_solve(objective_function_9, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - rates[1] = u[0] + algebraic[9] = u[0] def objective_function_10(u, f, data): @@ -319,21 +317,19 @@ def objective_function_10(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[2] = u[0] - - potassium_channel_E_K = constants[1]+12.0 + rates[1] = u[0] - f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-potassium_channel_E_K)-0.0 + f[0] = rates[1]-(algebraic[8]*(1.0-states[1])-algebraic[9]*states[1])-0.0 def find_root_10(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[2] + u[0] = rates[1] u = nla_solve(objective_function_10, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[2] = u[0] + rates[1] = u[0] def objective_function_11(u, f, data): @@ -344,19 +340,21 @@ def objective_function_11(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[8] = u[0] + algebraic[2] = u[0] - f[0] = algebraic[8]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 + potassium_channel_E_K = constants[1]+12.0 + + f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-potassium_channel_E_K)-0.0 def find_root_11(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[8] + u[0] = algebraic[2] u = nla_solve(objective_function_11, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[8] = u[0] + algebraic[2] = u[0] def objective_function_12(u, f, data): @@ -367,19 +365,19 @@ def objective_function_12(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[9] = u[0] + algebraic[10] = u[0] - f[0] = algebraic[9]-0.125*exp(states[0]/80.0)-0.0 + f[0] = algebraic[10]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 def find_root_12(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[9] + u[0] = algebraic[10] u = nla_solve(objective_function_12, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[9] = u[0] + algebraic[10] = u[0] def objective_function_13(u, f, data): @@ -390,18 +388,41 @@ def objective_function_13(u, f, data): computed_constants = data[4] algebraic = data[5] - rates[3] = u[0] + algebraic[11] = u[0] - f[0] = rates[3]-(algebraic[8]*(1.0-states[3])-algebraic[9]*states[3])-0.0 + f[0] = algebraic[11]-0.125*exp(states[0]/80.0)-0.0 def find_root_13(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = rates[3] + u[0] = algebraic[11] u = nla_solve(objective_function_13, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) + algebraic[11] = u[0] + + +def objective_function_14(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + + rates[3] = u[0] + + f[0] = rates[3]-(algebraic[10]*(1.0-states[3])-algebraic[11]*states[3])-0.0 + + +def find_root_14(voi, states, rates, constants, computed_constants, algebraic): + u = [nan]*1 + + u[0] = rates[3] + + u = nla_solve(objective_function_14, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) + rates[3] = u[0] @@ -425,10 +446,11 @@ def initialise_variables(states, rates, constants, computed_constants, algebraic algebraic[3] = 0.0 algebraic[4] = 0.0 algebraic[5] = 0.0 - algebraic[6] = 0.0 algebraic[7] = 0.0 algebraic[8] = 0.0 algebraic[9] = 0.0 + algebraic[10] = 0.0 + algebraic[11] = 0.0 def compute_computed_constants(constants, computed_constants): @@ -437,39 +459,39 @@ def compute_computed_constants(constants, computed_constants): def compute_rates(voi, states, rates, constants, computed_constants, algebraic): find_root_0(voi, states, rates, constants, computed_constants, algebraic) - leakage_current_E_L = constants[1]-10.613 find_root_2(voi, states, rates, constants, computed_constants, algebraic) + find_root_3(voi, states, rates, constants, computed_constants, algebraic) potassium_channel_E_K = constants[1]+12.0 - find_root_11(voi, states, rates, constants, computed_constants, algebraic) find_root_12(voi, states, rates, constants, computed_constants, algebraic) find_root_13(voi, states, rates, constants, computed_constants, algebraic) - find_root_10(voi, states, rates, constants, computed_constants, algebraic) - sodium_channel_E_Na = constants[1]-115.0 - find_root_7(voi, states, rates, constants, computed_constants, algebraic) + find_root_14(voi, states, rates, constants, computed_constants, algebraic) + find_root_11(voi, states, rates, constants, computed_constants, algebraic) find_root_8(voi, states, rates, constants, computed_constants, algebraic) find_root_9(voi, states, rates, constants, computed_constants, algebraic) + find_root_10(voi, states, rates, constants, computed_constants, algebraic) + algebraic[6] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + find_root_6(voi, states, rates, constants, computed_constants, algebraic) + find_root_7(voi, states, rates, constants, computed_constants, algebraic) find_root_4(voi, states, rates, constants, computed_constants, algebraic) find_root_5(voi, states, rates, constants, computed_constants, algebraic) - find_root_6(voi, states, rates, constants, computed_constants, algebraic) - find_root_3(voi, states, rates, constants, computed_constants, algebraic) find_root_1(voi, states, rates, constants, computed_constants, algebraic) def compute_variables(voi, states, rates, constants, computed_constants, algebraic): find_root_0(voi, states, rates, constants, computed_constants, algebraic) - leakage_current_E_L = constants[1]-10.613 find_root_2(voi, states, rates, constants, computed_constants, algebraic) + find_root_3(voi, states, rates, constants, computed_constants, algebraic) potassium_channel_E_K = constants[1]+12.0 - find_root_11(voi, states, rates, constants, computed_constants, algebraic) find_root_12(voi, states, rates, constants, computed_constants, algebraic) find_root_13(voi, states, rates, constants, computed_constants, algebraic) - find_root_10(voi, states, rates, constants, computed_constants, algebraic) - sodium_channel_E_Na = constants[1]-115.0 - find_root_7(voi, states, rates, constants, computed_constants, algebraic) + find_root_14(voi, states, rates, constants, computed_constants, algebraic) + find_root_11(voi, states, rates, constants, computed_constants, algebraic) find_root_8(voi, states, rates, constants, computed_constants, algebraic) find_root_9(voi, states, rates, constants, computed_constants, algebraic) + find_root_10(voi, states, rates, constants, computed_constants, algebraic) + algebraic[6] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + find_root_6(voi, states, rates, constants, computed_constants, algebraic) + find_root_7(voi, states, rates, constants, computed_constants, algebraic) find_root_4(voi, states, rates, constants, computed_constants, algebraic) find_root_5(voi, states, rates, constants, computed_constants, algebraic) - find_root_6(voi, states, rates, constants, computed_constants, algebraic) - find_root_3(voi, states, rates, constants, computed_constants, algebraic) find_root_1(voi, states, rates, constants, computed_constants, algebraic) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.with.externals.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.with.externals.c index 3774a549d..1cf76d302 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.with.externals.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.with.externals.c @@ -8,15 +8,16 @@ const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.2"; -const size_t STATE_COUNT = 3; +const size_t STATE_COUNT = 4; const size_t CONSTANT_COUNT = 5; -const size_t COMPUTED_CONSTANT_COUNT = 0; -const size_t ALGEBRAIC_COUNT = 8; -const size_t EXTERNAL_COUNT = 3; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 11; +const size_t EXTERNAL_COUNT = 1; const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, {"h", "dimensionless", "sodium_channel_h_gate"}, {"m", "dimensionless", "sodium_channel_m_gate"}, {"n", "dimensionless", "potassium_channel_n_gate"} @@ -31,23 +32,25 @@ const VariableInfo CONSTANT_INFO[] = { }; const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"E_K", "millivolt", "potassium_channel"} }; const VariableInfo ALGEBRAIC_INFO[] = { {"i_Stim", "microA_per_cm2", "membrane"}, {"i_L", "microA_per_cm2", "leakage_current"}, {"i_K", "microA_per_cm2", "potassium_channel"}, + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, {"beta_n", "per_millisecond", "potassium_channel_n_gate"} }; const VariableInfo EXTERNAL_INFO[] = { - {"V", "millivolt", "membrane"}, - {"i_Na", "microA_per_cm2", "sodium_channel"}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate"} + {"i_Na", "microA_per_cm2", "sodium_channel"} }; double * createStatesArray() @@ -150,7 +153,7 @@ void findRoot0(double voi, double *states, double *rates, double *constants, dou algebraic[0] = u[0]; } -void objectiveFunction2(double *u, double *f, void *data) +void objectiveFunction1(double *u, double *f, void *data) { double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; @@ -160,26 +163,24 @@ void objectiveFunction2(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[1] = u[0]; - - double leakage_current_E_L = constants[1]-10.613; + rates[0] = u[0]; - f[0] = algebraic[1]-constants[2]*(externals[0]-leakage_current_E_L)-0.0; + f[0] = rates[0]-(-(-algebraic[0]+externals[0]+algebraic[2]+algebraic[1])/constants[0])-0.0; } -void findRoot2(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +void findRoot1(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[1]; + u[0] = rates[0]; - nlaSolve(objectiveFunction2, u, 1, &rfi); + nlaSolve(objectiveFunction1, u, 1, &rfi); - algebraic[1] = u[0]; + rates[0] = u[0]; } -void objectiveFunction4(double *u, double *f, void *data) +void objectiveFunction2(double *u, double *f, void *data) { double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; @@ -191,22 +192,49 @@ void objectiveFunction4(double *u, double *f, void *data) algebraic[3] = u[0]; - f[0] = algebraic[3]-0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0)-0.0; + f[0] = algebraic[3]-(constants[1]-10.613)-0.0; } -void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +void findRoot2(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; u[0] = algebraic[3]; - nlaSolve(objectiveFunction4, u, 1, &rfi); + nlaSolve(objectiveFunction2, u, 1, &rfi); algebraic[3] = u[0]; } -void objectiveFunction5(double *u, double *f, void *data) +void objectiveFunction3(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[1] = u[0]; + + f[0] = algebraic[1]-constants[2]*(states[0]-algebraic[3])-0.0; +} + +void findRoot3(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[1]; + + nlaSolve(objectiveFunction3, u, 1, &rfi); + + algebraic[1] = u[0]; +} + +void objectiveFunction4(double *u, double *f, void *data) { double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; @@ -218,17 +246,17 @@ void objectiveFunction5(double *u, double *f, void *data) algebraic[4] = u[0]; - f[0] = algebraic[4]-4.0*exp(externals[0]/18.0)-0.0; + f[0] = algebraic[4]-(constants[1]-115.0)-0.0; } -void findRoot5(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; u[0] = algebraic[4]; - nlaSolve(objectiveFunction5, u, 1, &rfi); + nlaSolve(objectiveFunction4, u, 1, &rfi); algebraic[4] = u[0]; } @@ -243,9 +271,9 @@ void objectiveFunction6(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - rates[1] = u[0]; + algebraic[6] = u[0]; - f[0] = rates[1]-(algebraic[3]*(1.0-states[1])-algebraic[4]*states[1])-0.0; + f[0] = algebraic[6]-4.0*exp(states[0]/18.0)-0.0; } void findRoot6(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -253,11 +281,11 @@ void findRoot6(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = rates[1]; + u[0] = algebraic[6]; nlaSolve(objectiveFunction6, u, 1, &rfi); - rates[1] = u[0]; + algebraic[6] = u[0]; } void objectiveFunction7(double *u, double *f, void *data) @@ -270,9 +298,9 @@ void objectiveFunction7(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[5] = u[0]; + rates[2] = u[0]; - f[0] = algebraic[5]-0.07*exp(externals[0]/20.0)-0.0; + f[0] = rates[2]-(algebraic[5]*(1.0-states[2])-algebraic[6]*states[2])-0.0; } void findRoot7(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -280,11 +308,11 @@ void findRoot7(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[5]; + u[0] = rates[2]; nlaSolve(objectiveFunction7, u, 1, &rfi); - algebraic[5] = u[0]; + rates[2] = u[0]; } void objectiveFunction8(double *u, double *f, void *data) @@ -297,9 +325,9 @@ void objectiveFunction8(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[6] = u[0]; + algebraic[7] = u[0]; - f[0] = algebraic[6]-1.0/(exp((externals[0]+30.0)/10.0)+1.0)-0.0; + f[0] = algebraic[7]-0.07*exp(states[0]/20.0)-0.0; } void findRoot8(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -307,11 +335,11 @@ void findRoot8(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[6]; + u[0] = algebraic[7]; nlaSolve(objectiveFunction8, u, 1, &rfi); - algebraic[6] = u[0]; + algebraic[7] = u[0]; } void objectiveFunction9(double *u, double *f, void *data) @@ -324,9 +352,9 @@ void objectiveFunction9(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - rates[0] = u[0]; + algebraic[8] = u[0]; - f[0] = rates[0]-(algebraic[5]*(1.0-states[0])-algebraic[6]*states[0])-0.0; + f[0] = algebraic[8]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; } void findRoot9(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -334,11 +362,11 @@ void findRoot9(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = rates[0]; + u[0] = algebraic[8]; nlaSolve(objectiveFunction9, u, 1, &rfi); - rates[0] = u[0]; + algebraic[8] = u[0]; } void objectiveFunction10(double *u, double *f, void *data) @@ -351,11 +379,9 @@ void objectiveFunction10(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[2] = u[0]; - - double potassium_channel_E_K = constants[1]+12.0; + rates[1] = u[0]; - f[0] = algebraic[2]-constants[4]*pow(states[2], 4.0)*(externals[0]-potassium_channel_E_K)-0.0; + f[0] = rates[1]-(algebraic[7]*(1.0-states[1])-algebraic[8]*states[1])-0.0; } void findRoot10(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -363,10 +389,37 @@ void findRoot10(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[2]; + u[0] = rates[1]; nlaSolve(objectiveFunction10, u, 1, &rfi); + rates[1] = u[0]; +} + +void objectiveFunction11(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + algebraic[2] = u[0]; + + f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[0])-0.0; +} + +void findRoot11(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = algebraic[2]; + + nlaSolve(objectiveFunction11, u, 1, &rfi); + algebraic[2] = u[0]; } @@ -380,9 +433,9 @@ void objectiveFunction12(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[7] = u[0]; + algebraic[9] = u[0]; - f[0] = algebraic[7]-0.125*exp(externals[0]/80.0)-0.0; + f[0] = algebraic[9]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; } void findRoot12(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -390,11 +443,11 @@ void findRoot12(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[7]; + u[0] = algebraic[9]; nlaSolve(objectiveFunction12, u, 1, &rfi); - algebraic[7] = u[0]; + algebraic[9] = u[0]; } void objectiveFunction13(double *u, double *f, void *data) @@ -407,9 +460,9 @@ void objectiveFunction13(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - rates[2] = u[0]; + algebraic[10] = u[0]; - f[0] = rates[2]-(externals[2]*(1.0-states[2])-algebraic[7]*states[2])-0.0; + f[0] = algebraic[10]-0.125*exp(states[0]/80.0)-0.0; } void findRoot13(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -417,21 +470,50 @@ void findRoot13(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = rates[2]; + u[0] = algebraic[10]; nlaSolve(objectiveFunction13, u, 1, &rfi); - rates[2] = u[0]; + algebraic[10] = u[0]; +} + +void objectiveFunction14(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + rates[3] = u[0]; + + f[0] = rates[3]-(algebraic[9]*(1.0-states[3])-algebraic[10]*states[3])-0.0; +} + +void findRoot14(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = rates[3]; + + nlaSolve(objectiveFunction14, u, 1, &rfi); + + rates[3] = u[0]; } void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - states[0] = 0.6; - states[1] = 0.05; - states[2] = 0.325; + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; rates[0] = 0.0; rates[1] = 0.0; rates[2] = 0.0; + rates[3] = 0.0; constants[0] = 1.0; constants[1] = 0.0; constants[2] = 0.3; @@ -442,37 +524,51 @@ void initialiseVariables(double *states, double *rates, double *constants, doubl algebraic[2] = 0.0; algebraic[3] = 0.0; algebraic[4] = 0.0; - algebraic[5] = 0.0; algebraic[6] = 0.0; algebraic[7] = 0.0; + algebraic[8] = 0.0; + algebraic[9] = 0.0; + algebraic[10] = 0.0; } void computeComputedConstants(double *constants, double *computedConstants) { + computedConstants[0] = constants[1]+12.0; } void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { + findRoot0(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot2(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot3(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot12(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot13(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot14(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot11(voi, states, rates, constants, computedConstants, algebraic, externals); + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); - findRoot4(voi, states, rates, constants, computedConstants, algebraic, externals); - findRoot5(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot1(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot6(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot7(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot8(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot9(voi, states, rates, constants, computedConstants, algebraic, externals); - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - findRoot12(voi, states, rates, constants, computedConstants, algebraic, externals); - findRoot13(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot10(voi, states, rates, constants, computedConstants, algebraic, externals); } void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - findRoot0(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot3(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot12(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot13(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot14(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot11(voi, states, rates, constants, computedConstants, algebraic, externals); + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); - double leakage_current_E_L = constants[1]-10.613; - findRoot2(voi, states, rates, constants, computedConstants, algebraic, externals); - double potassium_channel_E_K = constants[1]+12.0; + findRoot1(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot4(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot6(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot7(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot8(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot9(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot10(voi, states, rates, constants, computedConstants, algebraic, externals); - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.with.externals.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.with.externals.py index 151971233..b5fdad176 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.with.externals.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.computed.constants.with.externals.py @@ -7,15 +7,16 @@ __version__ = "0.5.0" LIBCELLML_VERSION = "0.6.2" -STATE_COUNT = 3 +STATE_COUNT = 4 CONSTANT_COUNT = 5 -COMPUTED_CONSTANT_COUNT = 0 -ALGEBRAIC_COUNT = 8 -EXTERNAL_COUNT = 3 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 11 +EXTERNAL_COUNT = 1 VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} @@ -30,23 +31,25 @@ ] COMPUTED_CONSTANT_INFO = [ + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} ] ALGEBRAIC_INFO = [ {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} ] EXTERNAL_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane"}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"} ] @@ -109,7 +112,7 @@ def find_root_0(voi, states, rates, constants, computed_constants, algebraic, ex algebraic[0] = u[0] -def objective_function_2(u, f, data): +def objective_function_1(u, f, data): voi = data[0] states = data[1] rates = data[2] @@ -118,24 +121,22 @@ def objective_function_2(u, f, data): algebraic = data[5] externals = data[6] - algebraic[1] = u[0] - - leakage_current_E_L = constants[1]-10.613 + rates[0] = u[0] - f[0] = algebraic[1]-constants[2]*(externals[0]-leakage_current_E_L)-0.0 + f[0] = rates[0]-(-(-algebraic[0]+externals[0]+algebraic[2]+algebraic[1])/constants[0])-0.0 -def find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals): +def find_root_1(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[1] + u[0] = rates[0] - u = nla_solve(objective_function_2, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + u = nla_solve(objective_function_1, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[1] = u[0] + rates[0] = u[0] -def objective_function_4(u, f, data): +def objective_function_2(u, f, data): voi = data[0] states = data[1] rates = data[2] @@ -146,20 +147,44 @@ def objective_function_4(u, f, data): algebraic[3] = u[0] - f[0] = algebraic[3]-0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0)-0.0 + f[0] = algebraic[3]-(constants[1]-10.613)-0.0 -def find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals): +def find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 u[0] = algebraic[3] - u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + u = nla_solve(objective_function_2, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) algebraic[3] = u[0] -def objective_function_5(u, f, data): +def objective_function_3(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[1] = u[0] + + f[0] = algebraic[1]-constants[2]*(states[0]-algebraic[3])-0.0 + + +def find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[1] + + u = nla_solve(objective_function_3, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + algebraic[1] = u[0] + + +def objective_function_4(u, f, data): voi = data[0] states = data[1] rates = data[2] @@ -170,15 +195,15 @@ def objective_function_5(u, f, data): algebraic[4] = u[0] - f[0] = algebraic[4]-4.0*exp(externals[0]/18.0)-0.0 + f[0] = algebraic[4]-(constants[1]-115.0)-0.0 -def find_root_5(voi, states, rates, constants, computed_constants, algebraic, externals): +def find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 u[0] = algebraic[4] - u = nla_solve(objective_function_5, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) algebraic[4] = u[0] @@ -192,19 +217,19 @@ def objective_function_6(u, f, data): algebraic = data[5] externals = data[6] - rates[1] = u[0] + algebraic[6] = u[0] - f[0] = rates[1]-(algebraic[3]*(1.0-states[1])-algebraic[4]*states[1])-0.0 + f[0] = algebraic[6]-4.0*exp(states[0]/18.0)-0.0 def find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = rates[1] + u[0] = algebraic[6] u = nla_solve(objective_function_6, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - rates[1] = u[0] + algebraic[6] = u[0] def objective_function_7(u, f, data): @@ -216,19 +241,19 @@ def objective_function_7(u, f, data): algebraic = data[5] externals = data[6] - algebraic[5] = u[0] + rates[2] = u[0] - f[0] = algebraic[5]-0.07*exp(externals[0]/20.0)-0.0 + f[0] = rates[2]-(algebraic[5]*(1.0-states[2])-algebraic[6]*states[2])-0.0 def find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[5] + u[0] = rates[2] u = nla_solve(objective_function_7, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[5] = u[0] + rates[2] = u[0] def objective_function_8(u, f, data): @@ -240,19 +265,19 @@ def objective_function_8(u, f, data): algebraic = data[5] externals = data[6] - algebraic[6] = u[0] + algebraic[7] = u[0] - f[0] = algebraic[6]-1.0/(exp((externals[0]+30.0)/10.0)+1.0)-0.0 + f[0] = algebraic[7]-0.07*exp(states[0]/20.0)-0.0 def find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[6] + u[0] = algebraic[7] u = nla_solve(objective_function_8, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[6] = u[0] + algebraic[7] = u[0] def objective_function_9(u, f, data): @@ -264,19 +289,19 @@ def objective_function_9(u, f, data): algebraic = data[5] externals = data[6] - rates[0] = u[0] + algebraic[8] = u[0] - f[0] = rates[0]-(algebraic[5]*(1.0-states[0])-algebraic[6]*states[0])-0.0 + f[0] = algebraic[8]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 def find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = rates[0] + u[0] = algebraic[8] u = nla_solve(objective_function_9, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - rates[0] = u[0] + algebraic[8] = u[0] def objective_function_10(u, f, data): @@ -288,20 +313,42 @@ def objective_function_10(u, f, data): algebraic = data[5] externals = data[6] - algebraic[2] = u[0] - - potassium_channel_E_K = constants[1]+12.0 + rates[1] = u[0] - f[0] = algebraic[2]-constants[4]*pow(states[2], 4.0)*(externals[0]-potassium_channel_E_K)-0.0 + f[0] = rates[1]-(algebraic[7]*(1.0-states[1])-algebraic[8]*states[1])-0.0 def find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[2] + u[0] = rates[1] u = nla_solve(objective_function_10, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + rates[1] = u[0] + + +def objective_function_11(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + algebraic[2] = u[0] + + f[0] = algebraic[2]-constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[0])-0.0 + + +def find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = algebraic[2] + + u = nla_solve(objective_function_11, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + algebraic[2] = u[0] @@ -314,19 +361,19 @@ def objective_function_12(u, f, data): algebraic = data[5] externals = data[6] - algebraic[7] = u[0] + algebraic[9] = u[0] - f[0] = algebraic[7]-0.125*exp(externals[0]/80.0)-0.0 + f[0] = algebraic[9]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 def find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[7] + u[0] = algebraic[9] u = nla_solve(objective_function_12, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[7] = u[0] + algebraic[9] = u[0] def objective_function_13(u, f, data): @@ -338,28 +385,54 @@ def objective_function_13(u, f, data): algebraic = data[5] externals = data[6] - rates[2] = u[0] + algebraic[10] = u[0] - f[0] = rates[2]-(externals[2]*(1.0-states[2])-algebraic[7]*states[2])-0.0 + f[0] = algebraic[10]-0.125*exp(states[0]/80.0)-0.0 def find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = rates[2] + u[0] = algebraic[10] u = nla_solve(objective_function_13, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - rates[2] = u[0] + algebraic[10] = u[0] + + +def objective_function_14(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + rates[3] = u[0] + + f[0] = rates[3]-(algebraic[9]*(1.0-states[3])-algebraic[10]*states[3])-0.0 + + +def find_root_14(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = rates[3] + + u = nla_solve(objective_function_14, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + rates[3] = u[0] def initialise_variables(states, rates, constants, computed_constants, algebraic): - states[0] = 0.6 - states[1] = 0.05 - states[2] = 0.325 + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 rates[0] = 0.0 rates[1] = 0.0 rates[2] = 0.0 + rates[3] = 0.0 constants[0] = 1.0 constants[1] = 0.0 constants[2] = 0.3 @@ -370,34 +443,47 @@ def initialise_variables(states, rates, constants, computed_constants, algebraic algebraic[2] = 0.0 algebraic[3] = 0.0 algebraic[4] = 0.0 - algebraic[5] = 0.0 algebraic[6] = 0.0 algebraic[7] = 0.0 + algebraic[8] = 0.0 + algebraic[9] = 0.0 + algebraic[10] = 0.0 def compute_computed_constants(constants, computed_constants): - pass + computed_constants[0] = constants[1]+12.0 def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_14(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals) + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) - find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals) - find_root_5(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_1(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals) - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals) - find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals) def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): - find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_14(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals) + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) - leakage_current_E_L = constants[1]-10.613 - find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals) - potassium_channel_E_K = constants[1]+12.0 + find_root_1(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals) - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.c index 5a8962717..dd872b2e7 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.c @@ -10,8 +10,8 @@ const char LIBCELLML_VERSION[] = "0.6.2"; const size_t STATE_COUNT = 4; const size_t CONSTANT_COUNT = 0; -const size_t COMPUTED_CONSTANT_COUNT = 3; -const size_t ALGEBRAIC_COUNT = 10; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 12; const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; @@ -26,8 +26,6 @@ const VariableInfo CONSTANT_INFO[] = { }; const VariableInfo COMPUTED_CONSTANT_INFO[] = { - {"E_L", "millivolt", "leakage_current"}, - {"E_Na", "millivolt", "sodium_channel"}, {"E_K", "millivolt", "potassium_channel"} }; @@ -36,6 +34,8 @@ const VariableInfo ALGEBRAIC_INFO[] = { {"i_L", "microA_per_cm2", "leakage_current"}, {"i_K", "microA_per_cm2", "potassium_channel"}, {"i_Na", "microA_per_cm2", "sodium_channel"}, + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, @@ -168,11 +168,11 @@ void objectiveFunction2(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[1] = u[0]; + algebraic[4] = u[0]; - double leakage_current_g_L = 0.3; + double membrane_E_R = 0.0; - f[0] = algebraic[1]-leakage_current_g_L*(states[0]-computedConstants[0])-0.0; + f[0] = algebraic[4]-(membrane_E_R-10.613)-0.0; } void findRoot2(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -180,11 +180,11 @@ void findRoot2(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[1]; + u[0] = algebraic[4]; nlaSolve(objectiveFunction2, u, 1, &rfi); - algebraic[1] = u[0]; + algebraic[4] = u[0]; } void objectiveFunction3(double *u, double *f, void *data) @@ -196,11 +196,11 @@ void objectiveFunction3(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[3] = u[0]; + algebraic[1] = u[0]; - double sodium_channel_g_Na = 120.0; + double leakage_current_g_L = 0.3; - f[0] = algebraic[3]-sodium_channel_g_Na*pow(states[2], 3.0)*states[1]*(states[0]-computedConstants[1])-0.0; + f[0] = algebraic[1]-leakage_current_g_L*(states[0]-algebraic[4])-0.0; } void findRoot3(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -208,11 +208,11 @@ void findRoot3(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[3]; + u[0] = algebraic[1]; nlaSolve(objectiveFunction3, u, 1, &rfi); - algebraic[3] = u[0]; + algebraic[1] = u[0]; } void objectiveFunction4(double *u, double *f, void *data) @@ -224,9 +224,11 @@ void objectiveFunction4(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[4] = u[0]; + algebraic[5] = u[0]; + + double membrane_E_R = 0.0; - f[0] = algebraic[4]-0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0)-0.0; + f[0] = algebraic[5]-(membrane_E_R-115.0)-0.0; } void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -234,11 +236,11 @@ void findRoot4(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[4]; + u[0] = algebraic[5]; nlaSolve(objectiveFunction4, u, 1, &rfi); - algebraic[4] = u[0]; + algebraic[5] = u[0]; } void objectiveFunction5(double *u, double *f, void *data) @@ -250,9 +252,11 @@ void objectiveFunction5(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[5] = u[0]; + algebraic[3] = u[0]; - f[0] = algebraic[5]-4.0*exp(states[0]/18.0)-0.0; + double sodium_channel_g_Na = 120.0; + + f[0] = algebraic[3]-sodium_channel_g_Na*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5])-0.0; } void findRoot5(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -260,11 +264,11 @@ void findRoot5(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[5]; + u[0] = algebraic[3]; nlaSolve(objectiveFunction5, u, 1, &rfi); - algebraic[5] = u[0]; + algebraic[3] = u[0]; } void objectiveFunction6(double *u, double *f, void *data) @@ -276,9 +280,9 @@ void objectiveFunction6(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - rates[2] = u[0]; + algebraic[7] = u[0]; - f[0] = rates[2]-(algebraic[4]*(1.0-states[2])-algebraic[5]*states[2])-0.0; + f[0] = algebraic[7]-4.0*exp(states[0]/18.0)-0.0; } void findRoot6(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -286,11 +290,11 @@ void findRoot6(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = rates[2]; + u[0] = algebraic[7]; nlaSolve(objectiveFunction6, u, 1, &rfi); - rates[2] = u[0]; + algebraic[7] = u[0]; } void objectiveFunction7(double *u, double *f, void *data) @@ -302,9 +306,9 @@ void objectiveFunction7(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[6] = u[0]; + rates[2] = u[0]; - f[0] = algebraic[6]-0.07*exp(states[0]/20.0)-0.0; + f[0] = rates[2]-(algebraic[6]*(1.0-states[2])-algebraic[7]*states[2])-0.0; } void findRoot7(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -312,11 +316,11 @@ void findRoot7(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[6]; + u[0] = rates[2]; nlaSolve(objectiveFunction7, u, 1, &rfi); - algebraic[6] = u[0]; + rates[2] = u[0]; } void objectiveFunction8(double *u, double *f, void *data) @@ -328,9 +332,9 @@ void objectiveFunction8(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[7] = u[0]; + algebraic[8] = u[0]; - f[0] = algebraic[7]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; + f[0] = algebraic[8]-0.07*exp(states[0]/20.0)-0.0; } void findRoot8(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -338,11 +342,11 @@ void findRoot8(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[7]; + u[0] = algebraic[8]; nlaSolve(objectiveFunction8, u, 1, &rfi); - algebraic[7] = u[0]; + algebraic[8] = u[0]; } void objectiveFunction9(double *u, double *f, void *data) @@ -354,9 +358,9 @@ void objectiveFunction9(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - rates[1] = u[0]; + algebraic[9] = u[0]; - f[0] = rates[1]-(algebraic[6]*(1.0-states[1])-algebraic[7]*states[1])-0.0; + f[0] = algebraic[9]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; } void findRoot9(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -364,11 +368,11 @@ void findRoot9(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = rates[1]; + u[0] = algebraic[9]; nlaSolve(objectiveFunction9, u, 1, &rfi); - rates[1] = u[0]; + algebraic[9] = u[0]; } void objectiveFunction10(double *u, double *f, void *data) @@ -380,11 +384,9 @@ void objectiveFunction10(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[2] = u[0]; - - double potassium_channel_g_K = 36.0; + rates[1] = u[0]; - f[0] = algebraic[2]-potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computedConstants[2])-0.0; + f[0] = rates[1]-(algebraic[8]*(1.0-states[1])-algebraic[9]*states[1])-0.0; } void findRoot10(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -392,11 +394,11 @@ void findRoot10(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[2]; + u[0] = rates[1]; nlaSolve(objectiveFunction10, u, 1, &rfi); - algebraic[2] = u[0]; + rates[1] = u[0]; } void objectiveFunction11(double *u, double *f, void *data) @@ -408,9 +410,11 @@ void objectiveFunction11(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[8] = u[0]; + algebraic[2] = u[0]; + + double potassium_channel_g_K = 36.0; - f[0] = algebraic[8]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; + f[0] = algebraic[2]-potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computedConstants[0])-0.0; } void findRoot11(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -418,11 +422,11 @@ void findRoot11(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[8]; + u[0] = algebraic[2]; nlaSolve(objectiveFunction11, u, 1, &rfi); - algebraic[8] = u[0]; + algebraic[2] = u[0]; } void objectiveFunction12(double *u, double *f, void *data) @@ -434,9 +438,9 @@ void objectiveFunction12(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[9] = u[0]; + algebraic[10] = u[0]; - f[0] = algebraic[9]-0.125*exp(states[0]/80.0)-0.0; + f[0] = algebraic[10]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; } void findRoot12(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -444,11 +448,11 @@ void findRoot12(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[9]; + u[0] = algebraic[10]; nlaSolve(objectiveFunction12, u, 1, &rfi); - algebraic[9] = u[0]; + algebraic[10] = u[0]; } void objectiveFunction13(double *u, double *f, void *data) @@ -460,9 +464,9 @@ void objectiveFunction13(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - rates[3] = u[0]; + algebraic[11] = u[0]; - f[0] = rates[3]-(algebraic[8]*(1.0-states[3])-algebraic[9]*states[3])-0.0; + f[0] = algebraic[11]-0.125*exp(states[0]/80.0)-0.0; } void findRoot13(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -470,10 +474,36 @@ void findRoot13(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = rates[3]; + u[0] = algebraic[11]; nlaSolve(objectiveFunction13, u, 1, &rfi); + algebraic[11] = u[0]; +} + +void objectiveFunction14(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + + rates[3] = u[0]; + + f[0] = rates[3]-(algebraic[10]*(1.0-states[3])-algebraic[11]*states[3])-0.0; +} + +void findRoot14(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; + double u[1]; + + u[0] = rates[3]; + + nlaSolve(objectiveFunction14, u, 1, &rfi); + rates[3] = u[0]; } @@ -493,18 +523,17 @@ void initialiseVariables(double *states, double *rates, double *constants, doubl algebraic[3] = 0.0; algebraic[4] = 0.0; algebraic[5] = 0.0; - algebraic[6] = 0.0; algebraic[7] = 0.0; algebraic[8] = 0.0; algebraic[9] = 0.0; + algebraic[10] = 0.0; + algebraic[11] = 0.0; } void computeComputedConstants(double *constants, double *computedConstants) { double membrane_E_R = 0.0; - computedConstants[0] = membrane_E_R-10.613; - computedConstants[1] = membrane_E_R-115.0; - computedConstants[2] = membrane_E_R+12.0; + computedConstants[0] = membrane_E_R+12.0; } void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -512,20 +541,23 @@ void computeRates(double voi, double *states, double *rates, double *constants, double membrane_Cm = 1.0; findRoot0(voi, states, rates, constants, computedConstants, algebraic); double leakage_current_g_L = 0.3; + double membrane_E_R = 0.0; findRoot2(voi, states, rates, constants, computedConstants, algebraic); + findRoot3(voi, states, rates, constants, computedConstants, algebraic); double potassium_channel_g_K = 36.0; - findRoot11(voi, states, rates, constants, computedConstants, algebraic); findRoot12(voi, states, rates, constants, computedConstants, algebraic); findRoot13(voi, states, rates, constants, computedConstants, algebraic); - findRoot10(voi, states, rates, constants, computedConstants, algebraic); + findRoot14(voi, states, rates, constants, computedConstants, algebraic); + findRoot11(voi, states, rates, constants, computedConstants, algebraic); double sodium_channel_g_Na = 120.0; - findRoot7(voi, states, rates, constants, computedConstants, algebraic); findRoot8(voi, states, rates, constants, computedConstants, algebraic); findRoot9(voi, states, rates, constants, computedConstants, algebraic); + findRoot10(voi, states, rates, constants, computedConstants, algebraic); + algebraic[6] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + findRoot6(voi, states, rates, constants, computedConstants, algebraic); + findRoot7(voi, states, rates, constants, computedConstants, algebraic); findRoot4(voi, states, rates, constants, computedConstants, algebraic); findRoot5(voi, states, rates, constants, computedConstants, algebraic); - findRoot6(voi, states, rates, constants, computedConstants, algebraic); - findRoot3(voi, states, rates, constants, computedConstants, algebraic); findRoot1(voi, states, rates, constants, computedConstants, algebraic); } @@ -534,19 +566,22 @@ void computeVariables(double voi, double *states, double *rates, double *constan double membrane_Cm = 1.0; findRoot0(voi, states, rates, constants, computedConstants, algebraic); double leakage_current_g_L = 0.3; + double membrane_E_R = 0.0; findRoot2(voi, states, rates, constants, computedConstants, algebraic); + findRoot3(voi, states, rates, constants, computedConstants, algebraic); double potassium_channel_g_K = 36.0; - findRoot11(voi, states, rates, constants, computedConstants, algebraic); findRoot12(voi, states, rates, constants, computedConstants, algebraic); findRoot13(voi, states, rates, constants, computedConstants, algebraic); - findRoot10(voi, states, rates, constants, computedConstants, algebraic); + findRoot14(voi, states, rates, constants, computedConstants, algebraic); + findRoot11(voi, states, rates, constants, computedConstants, algebraic); double sodium_channel_g_Na = 120.0; - findRoot7(voi, states, rates, constants, computedConstants, algebraic); findRoot8(voi, states, rates, constants, computedConstants, algebraic); findRoot9(voi, states, rates, constants, computedConstants, algebraic); + findRoot10(voi, states, rates, constants, computedConstants, algebraic); + algebraic[6] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + findRoot6(voi, states, rates, constants, computedConstants, algebraic); + findRoot7(voi, states, rates, constants, computedConstants, algebraic); findRoot4(voi, states, rates, constants, computedConstants, algebraic); findRoot5(voi, states, rates, constants, computedConstants, algebraic); - findRoot6(voi, states, rates, constants, computedConstants, algebraic); - findRoot3(voi, states, rates, constants, computedConstants, algebraic); findRoot1(voi, states, rates, constants, computedConstants, algebraic); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.py index a496b6b0d..09c88e1fa 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.py @@ -9,8 +9,8 @@ STATE_COUNT = 4 CONSTANT_COUNT = 0 -COMPUTED_CONSTANT_COUNT = 3 -ALGEBRAIC_COUNT = 10 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 12 VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} @@ -25,8 +25,6 @@ ] COMPUTED_CONSTANT_INFO = [ - {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} ] @@ -35,6 +33,8 @@ {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, @@ -131,21 +131,21 @@ def objective_function_2(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[1] = u[0] + algebraic[4] = u[0] - leakage_current_g_L = 0.3 + membrane_E_R = 0.0 - f[0] = algebraic[1]-leakage_current_g_L*(states[0]-computed_constants[0])-0.0 + f[0] = algebraic[4]-(membrane_E_R-10.613)-0.0 def find_root_2(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[1] + u[0] = algebraic[4] u = nla_solve(objective_function_2, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[1] = u[0] + algebraic[4] = u[0] def objective_function_3(u, f, data): @@ -156,21 +156,21 @@ def objective_function_3(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[3] = u[0] + algebraic[1] = u[0] - sodium_channel_g_Na = 120.0 + leakage_current_g_L = 0.3 - f[0] = algebraic[3]-sodium_channel_g_Na*pow(states[2], 3.0)*states[1]*(states[0]-computed_constants[1])-0.0 + f[0] = algebraic[1]-leakage_current_g_L*(states[0]-algebraic[4])-0.0 def find_root_3(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[3] + u[0] = algebraic[1] u = nla_solve(objective_function_3, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[3] = u[0] + algebraic[1] = u[0] def objective_function_4(u, f, data): @@ -181,19 +181,21 @@ def objective_function_4(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[4] = u[0] + algebraic[5] = u[0] - f[0] = algebraic[4]-0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0)-0.0 + membrane_E_R = 0.0 + + f[0] = algebraic[5]-(membrane_E_R-115.0)-0.0 def find_root_4(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[4] + u[0] = algebraic[5] u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[4] = u[0] + algebraic[5] = u[0] def objective_function_5(u, f, data): @@ -204,19 +206,21 @@ def objective_function_5(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[5] = u[0] + algebraic[3] = u[0] - f[0] = algebraic[5]-4.0*exp(states[0]/18.0)-0.0 + sodium_channel_g_Na = 120.0 + + f[0] = algebraic[3]-sodium_channel_g_Na*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5])-0.0 def find_root_5(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[5] + u[0] = algebraic[3] u = nla_solve(objective_function_5, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[5] = u[0] + algebraic[3] = u[0] def objective_function_6(u, f, data): @@ -227,19 +231,19 @@ def objective_function_6(u, f, data): computed_constants = data[4] algebraic = data[5] - rates[2] = u[0] + algebraic[7] = u[0] - f[0] = rates[2]-(algebraic[4]*(1.0-states[2])-algebraic[5]*states[2])-0.0 + f[0] = algebraic[7]-4.0*exp(states[0]/18.0)-0.0 def find_root_6(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = rates[2] + u[0] = algebraic[7] u = nla_solve(objective_function_6, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - rates[2] = u[0] + algebraic[7] = u[0] def objective_function_7(u, f, data): @@ -250,19 +254,19 @@ def objective_function_7(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[6] = u[0] + rates[2] = u[0] - f[0] = algebraic[6]-0.07*exp(states[0]/20.0)-0.0 + f[0] = rates[2]-(algebraic[6]*(1.0-states[2])-algebraic[7]*states[2])-0.0 def find_root_7(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[6] + u[0] = rates[2] u = nla_solve(objective_function_7, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[6] = u[0] + rates[2] = u[0] def objective_function_8(u, f, data): @@ -273,19 +277,19 @@ def objective_function_8(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[7] = u[0] + algebraic[8] = u[0] - f[0] = algebraic[7]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 + f[0] = algebraic[8]-0.07*exp(states[0]/20.0)-0.0 def find_root_8(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[7] + u[0] = algebraic[8] u = nla_solve(objective_function_8, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[7] = u[0] + algebraic[8] = u[0] def objective_function_9(u, f, data): @@ -296,19 +300,19 @@ def objective_function_9(u, f, data): computed_constants = data[4] algebraic = data[5] - rates[1] = u[0] + algebraic[9] = u[0] - f[0] = rates[1]-(algebraic[6]*(1.0-states[1])-algebraic[7]*states[1])-0.0 + f[0] = algebraic[9]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 def find_root_9(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = rates[1] + u[0] = algebraic[9] u = nla_solve(objective_function_9, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - rates[1] = u[0] + algebraic[9] = u[0] def objective_function_10(u, f, data): @@ -319,21 +323,19 @@ def objective_function_10(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[2] = u[0] - - potassium_channel_g_K = 36.0 + rates[1] = u[0] - f[0] = algebraic[2]-potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computed_constants[2])-0.0 + f[0] = rates[1]-(algebraic[8]*(1.0-states[1])-algebraic[9]*states[1])-0.0 def find_root_10(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[2] + u[0] = rates[1] u = nla_solve(objective_function_10, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[2] = u[0] + rates[1] = u[0] def objective_function_11(u, f, data): @@ -344,19 +346,21 @@ def objective_function_11(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[8] = u[0] + algebraic[2] = u[0] - f[0] = algebraic[8]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 + potassium_channel_g_K = 36.0 + + f[0] = algebraic[2]-potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computed_constants[0])-0.0 def find_root_11(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[8] + u[0] = algebraic[2] u = nla_solve(objective_function_11, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[8] = u[0] + algebraic[2] = u[0] def objective_function_12(u, f, data): @@ -367,19 +371,19 @@ def objective_function_12(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[9] = u[0] + algebraic[10] = u[0] - f[0] = algebraic[9]-0.125*exp(states[0]/80.0)-0.0 + f[0] = algebraic[10]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 def find_root_12(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[9] + u[0] = algebraic[10] u = nla_solve(objective_function_12, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[9] = u[0] + algebraic[10] = u[0] def objective_function_13(u, f, data): @@ -390,18 +394,41 @@ def objective_function_13(u, f, data): computed_constants = data[4] algebraic = data[5] - rates[3] = u[0] + algebraic[11] = u[0] - f[0] = rates[3]-(algebraic[8]*(1.0-states[3])-algebraic[9]*states[3])-0.0 + f[0] = algebraic[11]-0.125*exp(states[0]/80.0)-0.0 def find_root_13(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = rates[3] + u[0] = algebraic[11] u = nla_solve(objective_function_13, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) + algebraic[11] = u[0] + + +def objective_function_14(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + + rates[3] = u[0] + + f[0] = rates[3]-(algebraic[10]*(1.0-states[3])-algebraic[11]*states[3])-0.0 + + +def find_root_14(voi, states, rates, constants, computed_constants, algebraic): + u = [nan]*1 + + u[0] = rates[3] + + u = nla_solve(objective_function_14, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) + rates[3] = u[0] @@ -420,37 +447,39 @@ def initialise_variables(states, rates, constants, computed_constants, algebraic algebraic[3] = 0.0 algebraic[4] = 0.0 algebraic[5] = 0.0 - algebraic[6] = 0.0 algebraic[7] = 0.0 algebraic[8] = 0.0 algebraic[9] = 0.0 + algebraic[10] = 0.0 + algebraic[11] = 0.0 def compute_computed_constants(constants, computed_constants): membrane_E_R = 0.0 - computed_constants[0] = membrane_E_R-10.613 - computed_constants[1] = membrane_E_R-115.0 - computed_constants[2] = membrane_E_R+12.0 + computed_constants[0] = membrane_E_R+12.0 def compute_rates(voi, states, rates, constants, computed_constants, algebraic): membrane_Cm = 1.0 find_root_0(voi, states, rates, constants, computed_constants, algebraic) leakage_current_g_L = 0.3 + membrane_E_R = 0.0 find_root_2(voi, states, rates, constants, computed_constants, algebraic) + find_root_3(voi, states, rates, constants, computed_constants, algebraic) potassium_channel_g_K = 36.0 - find_root_11(voi, states, rates, constants, computed_constants, algebraic) find_root_12(voi, states, rates, constants, computed_constants, algebraic) find_root_13(voi, states, rates, constants, computed_constants, algebraic) - find_root_10(voi, states, rates, constants, computed_constants, algebraic) + find_root_14(voi, states, rates, constants, computed_constants, algebraic) + find_root_11(voi, states, rates, constants, computed_constants, algebraic) sodium_channel_g_Na = 120.0 - find_root_7(voi, states, rates, constants, computed_constants, algebraic) find_root_8(voi, states, rates, constants, computed_constants, algebraic) find_root_9(voi, states, rates, constants, computed_constants, algebraic) + find_root_10(voi, states, rates, constants, computed_constants, algebraic) + algebraic[6] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + find_root_6(voi, states, rates, constants, computed_constants, algebraic) + find_root_7(voi, states, rates, constants, computed_constants, algebraic) find_root_4(voi, states, rates, constants, computed_constants, algebraic) find_root_5(voi, states, rates, constants, computed_constants, algebraic) - find_root_6(voi, states, rates, constants, computed_constants, algebraic) - find_root_3(voi, states, rates, constants, computed_constants, algebraic) find_root_1(voi, states, rates, constants, computed_constants, algebraic) @@ -458,18 +487,21 @@ def compute_variables(voi, states, rates, constants, computed_constants, algebra membrane_Cm = 1.0 find_root_0(voi, states, rates, constants, computed_constants, algebraic) leakage_current_g_L = 0.3 + membrane_E_R = 0.0 find_root_2(voi, states, rates, constants, computed_constants, algebraic) + find_root_3(voi, states, rates, constants, computed_constants, algebraic) potassium_channel_g_K = 36.0 - find_root_11(voi, states, rates, constants, computed_constants, algebraic) find_root_12(voi, states, rates, constants, computed_constants, algebraic) find_root_13(voi, states, rates, constants, computed_constants, algebraic) - find_root_10(voi, states, rates, constants, computed_constants, algebraic) + find_root_14(voi, states, rates, constants, computed_constants, algebraic) + find_root_11(voi, states, rates, constants, computed_constants, algebraic) sodium_channel_g_Na = 120.0 - find_root_7(voi, states, rates, constants, computed_constants, algebraic) find_root_8(voi, states, rates, constants, computed_constants, algebraic) find_root_9(voi, states, rates, constants, computed_constants, algebraic) + find_root_10(voi, states, rates, constants, computed_constants, algebraic) + algebraic[6] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + find_root_6(voi, states, rates, constants, computed_constants, algebraic) + find_root_7(voi, states, rates, constants, computed_constants, algebraic) find_root_4(voi, states, rates, constants, computed_constants, algebraic) find_root_5(voi, states, rates, constants, computed_constants, algebraic) - find_root_6(voi, states, rates, constants, computed_constants, algebraic) - find_root_3(voi, states, rates, constants, computed_constants, algebraic) find_root_1(voi, states, rates, constants, computed_constants, algebraic) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.with.externals.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.with.externals.c index 5cd1f97a7..0f5334a62 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.with.externals.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.with.externals.c @@ -8,26 +8,26 @@ const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.2"; -const size_t STATE_COUNT = 3; -const size_t CONSTANT_COUNT = 0; -const size_t COMPUTED_CONSTANT_COUNT = 3; -const size_t ALGEBRAIC_COUNT = 8; -const size_t EXTERNAL_COUNT = 3; +const size_t STATE_COUNT = 4; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 11; +const size_t EXTERNAL_COUNT = 1; const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, {"h", "dimensionless", "sodium_channel_h_gate"}, {"m", "dimensionless", "sodium_channel_m_gate"}, {"n", "dimensionless", "potassium_channel_n_gate"} }; const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"} }; const VariableInfo COMPUTED_CONSTANT_INFO[] = { - {"E_L", "millivolt", "leakage_current"}, - {"E_Na", "millivolt", "sodium_channel"}, {"E_K", "millivolt", "potassium_channel"} }; @@ -35,17 +35,18 @@ const VariableInfo ALGEBRAIC_INFO[] = { {"i_Stim", "microA_per_cm2", "membrane"}, {"i_L", "microA_per_cm2", "leakage_current"}, {"i_K", "microA_per_cm2", "potassium_channel"}, + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, {"beta_n", "per_millisecond", "potassium_channel_n_gate"} }; const VariableInfo EXTERNAL_INFO[] = { - {"V", "millivolt", "membrane"}, - {"i_Na", "microA_per_cm2", "sodium_channel"}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate"} + {"i_Na", "microA_per_cm2", "sodium_channel"} }; double * createStatesArray() @@ -148,6 +149,33 @@ void findRoot0(double voi, double *states, double *rates, double *constants, dou algebraic[0] = u[0]; } +void objectiveFunction1(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + rates[0] = u[0]; + + f[0] = rates[0]-(-(-algebraic[0]+externals[0]+algebraic[2]+algebraic[1])/constants[0])-0.0; +} + +void findRoot1(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = rates[0]; + + nlaSolve(objectiveFunction1, u, 1, &rfi); + + rates[0] = u[0]; +} + void objectiveFunction2(double *u, double *f, void *data) { double voi = ((RootFindingInfo *) data)->voi; @@ -158,11 +186,11 @@ void objectiveFunction2(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[1] = u[0]; + algebraic[3] = u[0]; - double leakage_current_g_L = 0.3; + double membrane_E_R = 0.0; - f[0] = algebraic[1]-leakage_current_g_L*(externals[0]-computedConstants[0])-0.0; + f[0] = algebraic[3]-(membrane_E_R-10.613)-0.0; } void findRoot2(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -170,14 +198,14 @@ void findRoot2(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[1]; + u[0] = algebraic[3]; nlaSolve(objectiveFunction2, u, 1, &rfi); - algebraic[1] = u[0]; + algebraic[3] = u[0]; } -void objectiveFunction4(double *u, double *f, void *data) +void objectiveFunction3(double *u, double *f, void *data) { double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; @@ -187,24 +215,26 @@ void objectiveFunction4(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[3] = u[0]; + algebraic[1] = u[0]; + + double leakage_current_g_L = 0.3; - f[0] = algebraic[3]-0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0)-0.0; + f[0] = algebraic[1]-leakage_current_g_L*(states[0]-algebraic[3])-0.0; } -void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +void findRoot3(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[3]; + u[0] = algebraic[1]; - nlaSolve(objectiveFunction4, u, 1, &rfi); + nlaSolve(objectiveFunction3, u, 1, &rfi); - algebraic[3] = u[0]; + algebraic[1] = u[0]; } -void objectiveFunction5(double *u, double *f, void *data) +void objectiveFunction4(double *u, double *f, void *data) { double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; @@ -216,17 +246,19 @@ void objectiveFunction5(double *u, double *f, void *data) algebraic[4] = u[0]; - f[0] = algebraic[4]-4.0*exp(externals[0]/18.0)-0.0; + double membrane_E_R = 0.0; + + f[0] = algebraic[4]-(membrane_E_R-115.0)-0.0; } -void findRoot5(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; u[0] = algebraic[4]; - nlaSolve(objectiveFunction5, u, 1, &rfi); + nlaSolve(objectiveFunction4, u, 1, &rfi); algebraic[4] = u[0]; } @@ -241,9 +273,9 @@ void objectiveFunction6(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - rates[1] = u[0]; + algebraic[6] = u[0]; - f[0] = rates[1]-(algebraic[3]*(1.0-states[1])-algebraic[4]*states[1])-0.0; + f[0] = algebraic[6]-4.0*exp(states[0]/18.0)-0.0; } void findRoot6(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -251,11 +283,11 @@ void findRoot6(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = rates[1]; + u[0] = algebraic[6]; nlaSolve(objectiveFunction6, u, 1, &rfi); - rates[1] = u[0]; + algebraic[6] = u[0]; } void objectiveFunction7(double *u, double *f, void *data) @@ -268,9 +300,9 @@ void objectiveFunction7(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[5] = u[0]; + rates[2] = u[0]; - f[0] = algebraic[5]-0.07*exp(externals[0]/20.0)-0.0; + f[0] = rates[2]-(algebraic[5]*(1.0-states[2])-algebraic[6]*states[2])-0.0; } void findRoot7(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -278,11 +310,11 @@ void findRoot7(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[5]; + u[0] = rates[2]; nlaSolve(objectiveFunction7, u, 1, &rfi); - algebraic[5] = u[0]; + rates[2] = u[0]; } void objectiveFunction8(double *u, double *f, void *data) @@ -295,9 +327,9 @@ void objectiveFunction8(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[6] = u[0]; + algebraic[7] = u[0]; - f[0] = algebraic[6]-1.0/(exp((externals[0]+30.0)/10.0)+1.0)-0.0; + f[0] = algebraic[7]-0.07*exp(states[0]/20.0)-0.0; } void findRoot8(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -305,11 +337,11 @@ void findRoot8(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[6]; + u[0] = algebraic[7]; nlaSolve(objectiveFunction8, u, 1, &rfi); - algebraic[6] = u[0]; + algebraic[7] = u[0]; } void objectiveFunction9(double *u, double *f, void *data) @@ -322,9 +354,9 @@ void objectiveFunction9(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - rates[0] = u[0]; + algebraic[8] = u[0]; - f[0] = rates[0]-(algebraic[5]*(1.0-states[0])-algebraic[6]*states[0])-0.0; + f[0] = algebraic[8]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; } void findRoot9(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -332,11 +364,11 @@ void findRoot9(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = rates[0]; + u[0] = algebraic[8]; nlaSolve(objectiveFunction9, u, 1, &rfi); - rates[0] = u[0]; + algebraic[8] = u[0]; } void objectiveFunction10(double *u, double *f, void *data) @@ -349,21 +381,48 @@ void objectiveFunction10(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; + rates[1] = u[0]; + + f[0] = rates[1]-(algebraic[7]*(1.0-states[1])-algebraic[8]*states[1])-0.0; +} + +void findRoot10(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = rates[1]; + + nlaSolve(objectiveFunction10, u, 1, &rfi); + + rates[1] = u[0]; +} + +void objectiveFunction11(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + algebraic[2] = u[0]; double potassium_channel_g_K = 36.0; - f[0] = algebraic[2]-potassium_channel_g_K*pow(states[2], 4.0)*(externals[0]-computedConstants[2])-0.0; + f[0] = algebraic[2]-potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computedConstants[0])-0.0; } -void findRoot10(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +void findRoot11(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; u[0] = algebraic[2]; - nlaSolve(objectiveFunction10, u, 1, &rfi); + nlaSolve(objectiveFunction11, u, 1, &rfi); algebraic[2] = u[0]; } @@ -378,9 +437,9 @@ void objectiveFunction12(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[7] = u[0]; + algebraic[9] = u[0]; - f[0] = algebraic[7]-0.125*exp(externals[0]/80.0)-0.0; + f[0] = algebraic[9]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; } void findRoot12(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -388,11 +447,11 @@ void findRoot12(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[7]; + u[0] = algebraic[9]; nlaSolve(objectiveFunction12, u, 1, &rfi); - algebraic[7] = u[0]; + algebraic[9] = u[0]; } void objectiveFunction13(double *u, double *f, void *data) @@ -405,9 +464,9 @@ void objectiveFunction13(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - rates[2] = u[0]; + algebraic[10] = u[0]; - f[0] = rates[2]-(externals[2]*(1.0-states[2])-algebraic[7]*states[2])-0.0; + f[0] = algebraic[10]-0.125*exp(states[0]/80.0)-0.0; } void findRoot13(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -415,61 +474,108 @@ void findRoot13(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = rates[2]; + u[0] = algebraic[10]; nlaSolve(objectiveFunction13, u, 1, &rfi); - rates[2] = u[0]; + algebraic[10] = u[0]; +} + +void objectiveFunction14(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + rates[3] = u[0]; + + f[0] = rates[3]-(algebraic[9]*(1.0-states[3])-algebraic[10]*states[3])-0.0; +} + +void findRoot14(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = rates[3]; + + nlaSolve(objectiveFunction14, u, 1, &rfi); + + rates[3] = u[0]; } void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - states[0] = 0.6; - states[1] = 0.05; - states[2] = 0.325; + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; rates[0] = 0.0; rates[1] = 0.0; rates[2] = 0.0; + rates[3] = 0.0; + constants[0] = 1.0; algebraic[0] = 0.0; algebraic[1] = 0.0; algebraic[2] = 0.0; algebraic[3] = 0.0; algebraic[4] = 0.0; - algebraic[5] = 0.0; algebraic[6] = 0.0; algebraic[7] = 0.0; + algebraic[8] = 0.0; + algebraic[9] = 0.0; + algebraic[10] = 0.0; } void computeComputedConstants(double *constants, double *computedConstants) { double membrane_E_R = 0.0; - computedConstants[0] = membrane_E_R-10.613; - computedConstants[1] = membrane_E_R-115.0; - computedConstants[2] = membrane_E_R+12.0; + computedConstants[0] = membrane_E_R+12.0; } void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { + findRoot0(voi, states, rates, constants, computedConstants, algebraic, externals); + double leakage_current_g_L = 0.3; + double membrane_E_R = 0.0; + findRoot2(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot3(voi, states, rates, constants, computedConstants, algebraic, externals); + double potassium_channel_g_K = 36.0; + findRoot12(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot13(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot14(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot11(voi, states, rates, constants, computedConstants, algebraic, externals); + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); - findRoot4(voi, states, rates, constants, computedConstants, algebraic, externals); - findRoot5(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot1(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot6(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot7(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot8(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot9(voi, states, rates, constants, computedConstants, algebraic, externals); - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - findRoot12(voi, states, rates, constants, computedConstants, algebraic, externals); - findRoot13(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot10(voi, states, rates, constants, computedConstants, algebraic, externals); } void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - findRoot0(voi, states, rates, constants, computedConstants, algebraic, externals); double leakage_current_g_L = 0.3; - externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); - findRoot2(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot3(voi, states, rates, constants, computedConstants, algebraic, externals); double potassium_channel_g_K = 36.0; + findRoot12(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot13(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot14(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot11(voi, states, rates, constants, computedConstants, algebraic, externals); + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + findRoot1(voi, states, rates, constants, computedConstants, algebraic, externals); + double membrane_E_R = 0.0; + findRoot4(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot6(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot7(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot8(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot9(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot10(voi, states, rates, constants, computedConstants, algebraic, externals); - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.with.externals.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.with.externals.py index 0750db9e9..9e1d99ad0 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.with.externals.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.constants.with.externals.py @@ -7,26 +7,26 @@ __version__ = "0.5.0" LIBCELLML_VERSION = "0.6.2" -STATE_COUNT = 3 -CONSTANT_COUNT = 0 -COMPUTED_CONSTANT_COUNT = 3 -ALGEBRAIC_COUNT = 8 -EXTERNAL_COUNT = 3 +STATE_COUNT = 4 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 11 +EXTERNAL_COUNT = 1 VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} ] CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"} ] COMPUTED_CONSTANT_INFO = [ - {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, - {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} ] @@ -34,17 +34,18 @@ {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} ] EXTERNAL_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane"}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"} ] @@ -107,6 +108,30 @@ def find_root_0(voi, states, rates, constants, computed_constants, algebraic, ex algebraic[0] = u[0] +def objective_function_1(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + rates[0] = u[0] + + f[0] = rates[0]-(-(-algebraic[0]+externals[0]+algebraic[2]+algebraic[1])/constants[0])-0.0 + + +def find_root_1(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = rates[0] + + u = nla_solve(objective_function_1, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + rates[0] = u[0] + + def objective_function_2(u, f, data): voi = data[0] states = data[1] @@ -116,24 +141,24 @@ def objective_function_2(u, f, data): algebraic = data[5] externals = data[6] - algebraic[1] = u[0] + algebraic[3] = u[0] - leakage_current_g_L = 0.3 + membrane_E_R = 0.0 - f[0] = algebraic[1]-leakage_current_g_L*(externals[0]-computed_constants[0])-0.0 + f[0] = algebraic[3]-(membrane_E_R-10.613)-0.0 def find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[1] + u[0] = algebraic[3] u = nla_solve(objective_function_2, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[1] = u[0] + algebraic[3] = u[0] -def objective_function_4(u, f, data): +def objective_function_3(u, f, data): voi = data[0] states = data[1] rates = data[2] @@ -142,22 +167,24 @@ def objective_function_4(u, f, data): algebraic = data[5] externals = data[6] - algebraic[3] = u[0] + algebraic[1] = u[0] - f[0] = algebraic[3]-0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0)-0.0 + leakage_current_g_L = 0.3 + f[0] = algebraic[1]-leakage_current_g_L*(states[0]-algebraic[3])-0.0 -def find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals): + +def find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[3] + u[0] = algebraic[1] - u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + u = nla_solve(objective_function_3, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[3] = u[0] + algebraic[1] = u[0] -def objective_function_5(u, f, data): +def objective_function_4(u, f, data): voi = data[0] states = data[1] rates = data[2] @@ -168,15 +195,17 @@ def objective_function_5(u, f, data): algebraic[4] = u[0] - f[0] = algebraic[4]-4.0*exp(externals[0]/18.0)-0.0 + membrane_E_R = 0.0 + + f[0] = algebraic[4]-(membrane_E_R-115.0)-0.0 -def find_root_5(voi, states, rates, constants, computed_constants, algebraic, externals): +def find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 u[0] = algebraic[4] - u = nla_solve(objective_function_5, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) algebraic[4] = u[0] @@ -190,19 +219,19 @@ def objective_function_6(u, f, data): algebraic = data[5] externals = data[6] - rates[1] = u[0] + algebraic[6] = u[0] - f[0] = rates[1]-(algebraic[3]*(1.0-states[1])-algebraic[4]*states[1])-0.0 + f[0] = algebraic[6]-4.0*exp(states[0]/18.0)-0.0 def find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = rates[1] + u[0] = algebraic[6] u = nla_solve(objective_function_6, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - rates[1] = u[0] + algebraic[6] = u[0] def objective_function_7(u, f, data): @@ -214,19 +243,19 @@ def objective_function_7(u, f, data): algebraic = data[5] externals = data[6] - algebraic[5] = u[0] + rates[2] = u[0] - f[0] = algebraic[5]-0.07*exp(externals[0]/20.0)-0.0 + f[0] = rates[2]-(algebraic[5]*(1.0-states[2])-algebraic[6]*states[2])-0.0 def find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[5] + u[0] = rates[2] u = nla_solve(objective_function_7, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[5] = u[0] + rates[2] = u[0] def objective_function_8(u, f, data): @@ -238,19 +267,19 @@ def objective_function_8(u, f, data): algebraic = data[5] externals = data[6] - algebraic[6] = u[0] + algebraic[7] = u[0] - f[0] = algebraic[6]-1.0/(exp((externals[0]+30.0)/10.0)+1.0)-0.0 + f[0] = algebraic[7]-0.07*exp(states[0]/20.0)-0.0 def find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[6] + u[0] = algebraic[7] u = nla_solve(objective_function_8, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[6] = u[0] + algebraic[7] = u[0] def objective_function_9(u, f, data): @@ -262,19 +291,19 @@ def objective_function_9(u, f, data): algebraic = data[5] externals = data[6] - rates[0] = u[0] + algebraic[8] = u[0] - f[0] = rates[0]-(algebraic[5]*(1.0-states[0])-algebraic[6]*states[0])-0.0 + f[0] = algebraic[8]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 def find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = rates[0] + u[0] = algebraic[8] u = nla_solve(objective_function_9, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - rates[0] = u[0] + algebraic[8] = u[0] def objective_function_10(u, f, data): @@ -286,19 +315,43 @@ def objective_function_10(u, f, data): algebraic = data[5] externals = data[6] + rates[1] = u[0] + + f[0] = rates[1]-(algebraic[7]*(1.0-states[1])-algebraic[8]*states[1])-0.0 + + +def find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = rates[1] + + u = nla_solve(objective_function_10, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + rates[1] = u[0] + + +def objective_function_11(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + algebraic[2] = u[0] potassium_channel_g_K = 36.0 - f[0] = algebraic[2]-potassium_channel_g_K*pow(states[2], 4.0)*(externals[0]-computed_constants[2])-0.0 + f[0] = algebraic[2]-potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computed_constants[0])-0.0 -def find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals): +def find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 u[0] = algebraic[2] - u = nla_solve(objective_function_10, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + u = nla_solve(objective_function_11, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) algebraic[2] = u[0] @@ -312,19 +365,19 @@ def objective_function_12(u, f, data): algebraic = data[5] externals = data[6] - algebraic[7] = u[0] + algebraic[9] = u[0] - f[0] = algebraic[7]-0.125*exp(externals[0]/80.0)-0.0 + f[0] = algebraic[9]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 def find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[7] + u[0] = algebraic[9] u = nla_solve(objective_function_12, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[7] = u[0] + algebraic[9] = u[0] def objective_function_13(u, f, data): @@ -336,64 +389,108 @@ def objective_function_13(u, f, data): algebraic = data[5] externals = data[6] - rates[2] = u[0] + algebraic[10] = u[0] - f[0] = rates[2]-(externals[2]*(1.0-states[2])-algebraic[7]*states[2])-0.0 + f[0] = algebraic[10]-0.125*exp(states[0]/80.0)-0.0 def find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = rates[2] + u[0] = algebraic[10] u = nla_solve(objective_function_13, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - rates[2] = u[0] + algebraic[10] = u[0] + + +def objective_function_14(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + rates[3] = u[0] + + f[0] = rates[3]-(algebraic[9]*(1.0-states[3])-algebraic[10]*states[3])-0.0 + + +def find_root_14(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = rates[3] + + u = nla_solve(objective_function_14, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + rates[3] = u[0] def initialise_variables(states, rates, constants, computed_constants, algebraic): - states[0] = 0.6 - states[1] = 0.05 - states[2] = 0.325 + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 rates[0] = 0.0 rates[1] = 0.0 rates[2] = 0.0 + rates[3] = 0.0 + constants[0] = 1.0 algebraic[0] = 0.0 algebraic[1] = 0.0 algebraic[2] = 0.0 algebraic[3] = 0.0 algebraic[4] = 0.0 - algebraic[5] = 0.0 algebraic[6] = 0.0 algebraic[7] = 0.0 + algebraic[8] = 0.0 + algebraic[9] = 0.0 + algebraic[10] = 0.0 def compute_computed_constants(constants, computed_constants): membrane_E_R = 0.0 - computed_constants[0] = membrane_E_R-10.613 - computed_constants[1] = membrane_E_R-115.0 - computed_constants[2] = membrane_E_R+12.0 + computed_constants[0] = membrane_E_R+12.0 def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals) + leakage_current_g_L = 0.3 + membrane_E_R = 0.0 + find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals) + potassium_channel_g_K = 36.0 + find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_14(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals) + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) - find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals) - find_root_5(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_1(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals) - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals) - find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals) def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): - find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals) leakage_current_g_L = 0.3 - externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) - find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals) potassium_channel_g_K = 36.0 + find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_14(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals) + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + find_root_1(voi, states, rates, constants, computed_constants, algebraic, externals) + membrane_E_R = 0.0 + find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals) - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.c index fcb375dad..1fd21d5b9 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.c @@ -11,7 +11,7 @@ const char LIBCELLML_VERSION[] = "0.6.2"; const size_t STATE_COUNT = 4; const size_t CONSTANT_COUNT = 0; const size_t COMPUTED_CONSTANT_COUNT = 0; -const size_t ALGEBRAIC_COUNT = 10; +const size_t ALGEBRAIC_COUNT = 11; const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; @@ -33,7 +33,8 @@ const VariableInfo ALGEBRAIC_INFO[] = { {"i_L", "microA_per_cm2", "leakage_current"}, {"i_K", "microA_per_cm2", "potassium_channel"}, {"i_Na", "microA_per_cm2", "sodium_channel"}, - {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, @@ -165,13 +166,11 @@ void objectiveFunction2(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[1] = u[0]; + algebraic[4] = u[0]; - double leakage_current_g_L = 0.3; double membrane_E_R = 0.0; - double leakage_current_E_L = membrane_E_R-10.613; - f[0] = algebraic[1]-leakage_current_g_L*(states[0]-leakage_current_E_L)-0.0; + f[0] = algebraic[4]-(membrane_E_R-10.613)-0.0; } void findRoot2(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -179,11 +178,11 @@ void findRoot2(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[1]; + u[0] = algebraic[4]; nlaSolve(objectiveFunction2, u, 1, &rfi); - algebraic[1] = u[0]; + algebraic[4] = u[0]; } void objectiveFunction3(double *u, double *f, void *data) @@ -195,13 +194,11 @@ void objectiveFunction3(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[3] = u[0]; + algebraic[1] = u[0]; - double sodium_channel_g_Na = 120.0; - double membrane_E_R = 0.0; - double sodium_channel_E_Na = membrane_E_R-115.0; + double leakage_current_g_L = 0.3; - f[0] = algebraic[3]-sodium_channel_g_Na*pow(states[2], 3.0)*states[1]*(states[0]-sodium_channel_E_Na)-0.0; + f[0] = algebraic[1]-leakage_current_g_L*(states[0]-algebraic[4])-0.0; } void findRoot3(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -209,11 +206,11 @@ void findRoot3(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[3]; + u[0] = algebraic[1]; nlaSolve(objectiveFunction3, u, 1, &rfi); - algebraic[3] = u[0]; + algebraic[1] = u[0]; } void objectiveFunction4(double *u, double *f, void *data) @@ -225,9 +222,11 @@ void objectiveFunction4(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[4] = u[0]; + algebraic[5] = u[0]; + + double membrane_E_R = 0.0; - f[0] = algebraic[4]-0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0)-0.0; + f[0] = algebraic[5]-(membrane_E_R-115.0)-0.0; } void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -235,11 +234,11 @@ void findRoot4(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[4]; + u[0] = algebraic[5]; nlaSolve(objectiveFunction4, u, 1, &rfi); - algebraic[4] = u[0]; + algebraic[5] = u[0]; } void objectiveFunction5(double *u, double *f, void *data) @@ -251,9 +250,11 @@ void objectiveFunction5(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[5] = u[0]; + algebraic[3] = u[0]; + + double sodium_channel_g_Na = 120.0; - f[0] = algebraic[5]-4.0*exp(states[0]/18.0)-0.0; + f[0] = algebraic[3]-sodium_channel_g_Na*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5])-0.0; } void findRoot5(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -261,11 +262,11 @@ void findRoot5(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[5]; + u[0] = algebraic[3]; nlaSolve(objectiveFunction5, u, 1, &rfi); - algebraic[5] = u[0]; + algebraic[3] = u[0]; } void objectiveFunction6(double *u, double *f, void *data) @@ -277,9 +278,9 @@ void objectiveFunction6(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - rates[2] = u[0]; + algebraic[7] = u[0]; - f[0] = rates[2]-(algebraic[4]*(1.0-states[2])-algebraic[5]*states[2])-0.0; + f[0] = algebraic[7]-4.0*exp(states[0]/18.0)-0.0; } void findRoot6(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -287,11 +288,11 @@ void findRoot6(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = rates[2]; + u[0] = algebraic[7]; nlaSolve(objectiveFunction6, u, 1, &rfi); - rates[2] = u[0]; + algebraic[7] = u[0]; } void objectiveFunction7(double *u, double *f, void *data) @@ -303,9 +304,9 @@ void objectiveFunction7(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[6] = u[0]; + rates[2] = u[0]; - f[0] = algebraic[6]-0.07*exp(states[0]/20.0)-0.0; + f[0] = rates[2]-(sodium_channel_m_gate_alpha_m*(1.0-states[2])-algebraic[7]*states[2])-0.0; } void findRoot7(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -313,11 +314,11 @@ void findRoot7(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[6]; + u[0] = rates[2]; nlaSolve(objectiveFunction7, u, 1, &rfi); - algebraic[6] = u[0]; + rates[2] = u[0]; } void objectiveFunction8(double *u, double *f, void *data) @@ -329,9 +330,9 @@ void objectiveFunction8(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[7] = u[0]; + algebraic[8] = u[0]; - f[0] = algebraic[7]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; + f[0] = algebraic[8]-0.07*exp(states[0]/20.0)-0.0; } void findRoot8(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -339,11 +340,11 @@ void findRoot8(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[7]; + u[0] = algebraic[8]; nlaSolve(objectiveFunction8, u, 1, &rfi); - algebraic[7] = u[0]; + algebraic[8] = u[0]; } void objectiveFunction9(double *u, double *f, void *data) @@ -355,9 +356,9 @@ void objectiveFunction9(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - rates[1] = u[0]; + algebraic[9] = u[0]; - f[0] = rates[1]-(algebraic[6]*(1.0-states[1])-algebraic[7]*states[1])-0.0; + f[0] = algebraic[9]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; } void findRoot9(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -365,11 +366,11 @@ void findRoot9(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = rates[1]; + u[0] = algebraic[9]; nlaSolve(objectiveFunction9, u, 1, &rfi); - rates[1] = u[0]; + algebraic[9] = u[0]; } void objectiveFunction10(double *u, double *f, void *data) @@ -381,13 +382,9 @@ void objectiveFunction10(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[2] = u[0]; - - double potassium_channel_g_K = 36.0; - double membrane_E_R = 0.0; - double potassium_channel_E_K = membrane_E_R+12.0; + rates[1] = u[0]; - f[0] = algebraic[2]-potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-potassium_channel_E_K)-0.0; + f[0] = rates[1]-(algebraic[8]*(1.0-states[1])-algebraic[9]*states[1])-0.0; } void findRoot10(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -395,11 +392,11 @@ void findRoot10(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[2]; + u[0] = rates[1]; nlaSolve(objectiveFunction10, u, 1, &rfi); - algebraic[2] = u[0]; + rates[1] = u[0]; } void objectiveFunction11(double *u, double *f, void *data) @@ -411,9 +408,13 @@ void objectiveFunction11(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[8] = u[0]; + algebraic[2] = u[0]; - f[0] = algebraic[8]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; + double potassium_channel_g_K = 36.0; + double membrane_E_R = 0.0; + double potassium_channel_E_K = membrane_E_R+12.0; + + f[0] = algebraic[2]-potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-potassium_channel_E_K)-0.0; } void findRoot11(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -421,11 +422,11 @@ void findRoot11(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[8]; + u[0] = algebraic[2]; nlaSolve(objectiveFunction11, u, 1, &rfi); - algebraic[8] = u[0]; + algebraic[2] = u[0]; } void objectiveFunction12(double *u, double *f, void *data) @@ -437,9 +438,9 @@ void objectiveFunction12(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - algebraic[9] = u[0]; + algebraic[10] = u[0]; - f[0] = algebraic[9]-0.125*exp(states[0]/80.0)-0.0; + f[0] = algebraic[10]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; } void findRoot12(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -447,11 +448,11 @@ void findRoot12(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = algebraic[9]; + u[0] = algebraic[10]; nlaSolve(objectiveFunction12, u, 1, &rfi); - algebraic[9] = u[0]; + algebraic[10] = u[0]; } void objectiveFunction13(double *u, double *f, void *data) @@ -463,9 +464,9 @@ void objectiveFunction13(double *u, double *f, void *data) double *computedConstants = ((RootFindingInfo *) data)->computedConstants; double *algebraic = ((RootFindingInfo *) data)->algebraic; - rates[3] = u[0]; + algebraic[11] = u[0]; - f[0] = rates[3]-(algebraic[8]*(1.0-states[3])-algebraic[9]*states[3])-0.0; + f[0] = algebraic[11]-0.125*exp(states[0]/80.0)-0.0; } void findRoot13(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) @@ -473,10 +474,36 @@ void findRoot13(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; double u[1]; - u[0] = rates[3]; + u[0] = algebraic[11]; nlaSolve(objectiveFunction13, u, 1, &rfi); + algebraic[11] = u[0]; +} + +void objectiveFunction14(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + + rates[3] = u[0]; + + f[0] = rates[3]-(algebraic[10]*(1.0-states[3])-algebraic[11]*states[3])-0.0; +} + +void findRoot14(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic }; + double u[1]; + + u[0] = rates[3]; + + nlaSolve(objectiveFunction14, u, 1, &rfi); + rates[3] = u[0]; } @@ -496,10 +523,11 @@ void initialiseVariables(double *states, double *rates, double *constants, doubl algebraic[3] = 0.0; algebraic[4] = 0.0; algebraic[5] = 0.0; - algebraic[6] = 0.0; algebraic[7] = 0.0; algebraic[8] = 0.0; algebraic[9] = 0.0; + algebraic[10] = 0.0; + algebraic[11] = 0.0; } void computeComputedConstants(double *constants, double *computedConstants) @@ -512,23 +540,23 @@ void computeRates(double voi, double *states, double *rates, double *constants, findRoot0(voi, states, rates, constants, computedConstants, algebraic); double leakage_current_g_L = 0.3; double membrane_E_R = 0.0; - double leakage_current_E_L = membrane_E_R-10.613; findRoot2(voi, states, rates, constants, computedConstants, algebraic); + findRoot3(voi, states, rates, constants, computedConstants, algebraic); double potassium_channel_g_K = 36.0; double potassium_channel_E_K = membrane_E_R+12.0; - findRoot11(voi, states, rates, constants, computedConstants, algebraic); findRoot12(voi, states, rates, constants, computedConstants, algebraic); findRoot13(voi, states, rates, constants, computedConstants, algebraic); - findRoot10(voi, states, rates, constants, computedConstants, algebraic); + findRoot14(voi, states, rates, constants, computedConstants, algebraic); + findRoot11(voi, states, rates, constants, computedConstants, algebraic); double sodium_channel_g_Na = 120.0; - double sodium_channel_E_Na = membrane_E_R-115.0; - findRoot7(voi, states, rates, constants, computedConstants, algebraic); findRoot8(voi, states, rates, constants, computedConstants, algebraic); findRoot9(voi, states, rates, constants, computedConstants, algebraic); + findRoot10(voi, states, rates, constants, computedConstants, algebraic); + double sodium_channel_m_gate_alpha_m = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + findRoot6(voi, states, rates, constants, computedConstants, algebraic); + findRoot7(voi, states, rates, constants, computedConstants, algebraic); findRoot4(voi, states, rates, constants, computedConstants, algebraic); findRoot5(voi, states, rates, constants, computedConstants, algebraic); - findRoot6(voi, states, rates, constants, computedConstants, algebraic); - findRoot3(voi, states, rates, constants, computedConstants, algebraic); findRoot1(voi, states, rates, constants, computedConstants, algebraic); } @@ -538,22 +566,22 @@ void computeVariables(double voi, double *states, double *rates, double *constan findRoot0(voi, states, rates, constants, computedConstants, algebraic); double leakage_current_g_L = 0.3; double membrane_E_R = 0.0; - double leakage_current_E_L = membrane_E_R-10.613; findRoot2(voi, states, rates, constants, computedConstants, algebraic); + findRoot3(voi, states, rates, constants, computedConstants, algebraic); double potassium_channel_g_K = 36.0; double potassium_channel_E_K = membrane_E_R+12.0; - findRoot11(voi, states, rates, constants, computedConstants, algebraic); findRoot12(voi, states, rates, constants, computedConstants, algebraic); findRoot13(voi, states, rates, constants, computedConstants, algebraic); - findRoot10(voi, states, rates, constants, computedConstants, algebraic); + findRoot14(voi, states, rates, constants, computedConstants, algebraic); + findRoot11(voi, states, rates, constants, computedConstants, algebraic); double sodium_channel_g_Na = 120.0; - double sodium_channel_E_Na = membrane_E_R-115.0; - findRoot7(voi, states, rates, constants, computedConstants, algebraic); findRoot8(voi, states, rates, constants, computedConstants, algebraic); findRoot9(voi, states, rates, constants, computedConstants, algebraic); + findRoot10(voi, states, rates, constants, computedConstants, algebraic); + double sodium_channel_m_gate_alpha_m = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + findRoot6(voi, states, rates, constants, computedConstants, algebraic); + findRoot7(voi, states, rates, constants, computedConstants, algebraic); findRoot4(voi, states, rates, constants, computedConstants, algebraic); findRoot5(voi, states, rates, constants, computedConstants, algebraic); - findRoot6(voi, states, rates, constants, computedConstants, algebraic); - findRoot3(voi, states, rates, constants, computedConstants, algebraic); findRoot1(voi, states, rates, constants, computedConstants, algebraic); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.py index 1e32024d0..75fa1f1f0 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.py @@ -10,7 +10,7 @@ STATE_COUNT = 4 CONSTANT_COUNT = 0 COMPUTED_CONSTANT_COUNT = 0 -ALGEBRAIC_COUNT = 10 +ALGEBRAIC_COUNT = 11 VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} @@ -32,7 +32,8 @@ {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, - {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, @@ -128,23 +129,21 @@ def objective_function_2(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[1] = u[0] + algebraic[4] = u[0] - leakage_current_g_L = 0.3 membrane_E_R = 0.0 - leakage_current_E_L = membrane_E_R-10.613 - f[0] = algebraic[1]-leakage_current_g_L*(states[0]-leakage_current_E_L)-0.0 + f[0] = algebraic[4]-(membrane_E_R-10.613)-0.0 def find_root_2(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[1] + u[0] = algebraic[4] u = nla_solve(objective_function_2, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[1] = u[0] + algebraic[4] = u[0] def objective_function_3(u, f, data): @@ -155,23 +154,21 @@ def objective_function_3(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[3] = u[0] + algebraic[1] = u[0] - sodium_channel_g_Na = 120.0 - membrane_E_R = 0.0 - sodium_channel_E_Na = membrane_E_R-115.0 + leakage_current_g_L = 0.3 - f[0] = algebraic[3]-sodium_channel_g_Na*pow(states[2], 3.0)*states[1]*(states[0]-sodium_channel_E_Na)-0.0 + f[0] = algebraic[1]-leakage_current_g_L*(states[0]-algebraic[4])-0.0 def find_root_3(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[3] + u[0] = algebraic[1] u = nla_solve(objective_function_3, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[3] = u[0] + algebraic[1] = u[0] def objective_function_4(u, f, data): @@ -182,19 +179,21 @@ def objective_function_4(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[4] = u[0] + algebraic[5] = u[0] + + membrane_E_R = 0.0 - f[0] = algebraic[4]-0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0)-0.0 + f[0] = algebraic[5]-(membrane_E_R-115.0)-0.0 def find_root_4(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[4] + u[0] = algebraic[5] u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[4] = u[0] + algebraic[5] = u[0] def objective_function_5(u, f, data): @@ -205,19 +204,21 @@ def objective_function_5(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[5] = u[0] + algebraic[3] = u[0] - f[0] = algebraic[5]-4.0*exp(states[0]/18.0)-0.0 + sodium_channel_g_Na = 120.0 + + f[0] = algebraic[3]-sodium_channel_g_Na*pow(states[2], 3.0)*states[1]*(states[0]-algebraic[5])-0.0 def find_root_5(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[5] + u[0] = algebraic[3] u = nla_solve(objective_function_5, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[5] = u[0] + algebraic[3] = u[0] def objective_function_6(u, f, data): @@ -228,19 +229,19 @@ def objective_function_6(u, f, data): computed_constants = data[4] algebraic = data[5] - rates[2] = u[0] + algebraic[7] = u[0] - f[0] = rates[2]-(algebraic[4]*(1.0-states[2])-algebraic[5]*states[2])-0.0 + f[0] = algebraic[7]-4.0*exp(states[0]/18.0)-0.0 def find_root_6(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = rates[2] + u[0] = algebraic[7] u = nla_solve(objective_function_6, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - rates[2] = u[0] + algebraic[7] = u[0] def objective_function_7(u, f, data): @@ -251,19 +252,19 @@ def objective_function_7(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[6] = u[0] + rates[2] = u[0] - f[0] = algebraic[6]-0.07*exp(states[0]/20.0)-0.0 + f[0] = rates[2]-(sodium_channel_m_gate_alpha_m*(1.0-states[2])-algebraic[7]*states[2])-0.0 def find_root_7(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[6] + u[0] = rates[2] u = nla_solve(objective_function_7, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[6] = u[0] + rates[2] = u[0] def objective_function_8(u, f, data): @@ -274,19 +275,19 @@ def objective_function_8(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[7] = u[0] + algebraic[8] = u[0] - f[0] = algebraic[7]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 + f[0] = algebraic[8]-0.07*exp(states[0]/20.0)-0.0 def find_root_8(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[7] + u[0] = algebraic[8] u = nla_solve(objective_function_8, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[7] = u[0] + algebraic[8] = u[0] def objective_function_9(u, f, data): @@ -297,19 +298,19 @@ def objective_function_9(u, f, data): computed_constants = data[4] algebraic = data[5] - rates[1] = u[0] + algebraic[9] = u[0] - f[0] = rates[1]-(algebraic[6]*(1.0-states[1])-algebraic[7]*states[1])-0.0 + f[0] = algebraic[9]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 def find_root_9(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = rates[1] + u[0] = algebraic[9] u = nla_solve(objective_function_9, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - rates[1] = u[0] + algebraic[9] = u[0] def objective_function_10(u, f, data): @@ -320,23 +321,19 @@ def objective_function_10(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[2] = u[0] - - potassium_channel_g_K = 36.0 - membrane_E_R = 0.0 - potassium_channel_E_K = membrane_E_R+12.0 + rates[1] = u[0] - f[0] = algebraic[2]-potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-potassium_channel_E_K)-0.0 + f[0] = rates[1]-(algebraic[8]*(1.0-states[1])-algebraic[9]*states[1])-0.0 def find_root_10(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[2] + u[0] = rates[1] u = nla_solve(objective_function_10, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[2] = u[0] + rates[1] = u[0] def objective_function_11(u, f, data): @@ -347,19 +344,23 @@ def objective_function_11(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[8] = u[0] + algebraic[2] = u[0] - f[0] = algebraic[8]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 + potassium_channel_g_K = 36.0 + membrane_E_R = 0.0 + potassium_channel_E_K = membrane_E_R+12.0 + + f[0] = algebraic[2]-potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-potassium_channel_E_K)-0.0 def find_root_11(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[8] + u[0] = algebraic[2] u = nla_solve(objective_function_11, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[8] = u[0] + algebraic[2] = u[0] def objective_function_12(u, f, data): @@ -370,19 +371,19 @@ def objective_function_12(u, f, data): computed_constants = data[4] algebraic = data[5] - algebraic[9] = u[0] + algebraic[10] = u[0] - f[0] = algebraic[9]-0.125*exp(states[0]/80.0)-0.0 + f[0] = algebraic[10]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 def find_root_12(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = algebraic[9] + u[0] = algebraic[10] u = nla_solve(objective_function_12, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) - algebraic[9] = u[0] + algebraic[10] = u[0] def objective_function_13(u, f, data): @@ -393,18 +394,41 @@ def objective_function_13(u, f, data): computed_constants = data[4] algebraic = data[5] - rates[3] = u[0] + algebraic[11] = u[0] - f[0] = rates[3]-(algebraic[8]*(1.0-states[3])-algebraic[9]*states[3])-0.0 + f[0] = algebraic[11]-0.125*exp(states[0]/80.0)-0.0 def find_root_13(voi, states, rates, constants, computed_constants, algebraic): u = [nan]*1 - u[0] = rates[3] + u[0] = algebraic[11] u = nla_solve(objective_function_13, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) + algebraic[11] = u[0] + + +def objective_function_14(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + + rates[3] = u[0] + + f[0] = rates[3]-(algebraic[10]*(1.0-states[3])-algebraic[11]*states[3])-0.0 + + +def find_root_14(voi, states, rates, constants, computed_constants, algebraic): + u = [nan]*1 + + u[0] = rates[3] + + u = nla_solve(objective_function_14, u, 1, [voi, states, rates, constants, computed_constants, algebraic]) + rates[3] = u[0] @@ -423,10 +447,11 @@ def initialise_variables(states, rates, constants, computed_constants, algebraic algebraic[3] = 0.0 algebraic[4] = 0.0 algebraic[5] = 0.0 - algebraic[6] = 0.0 algebraic[7] = 0.0 algebraic[8] = 0.0 algebraic[9] = 0.0 + algebraic[10] = 0.0 + algebraic[11] = 0.0 def compute_computed_constants(constants, computed_constants): @@ -438,23 +463,23 @@ def compute_rates(voi, states, rates, constants, computed_constants, algebraic): find_root_0(voi, states, rates, constants, computed_constants, algebraic) leakage_current_g_L = 0.3 membrane_E_R = 0.0 - leakage_current_E_L = membrane_E_R-10.613 find_root_2(voi, states, rates, constants, computed_constants, algebraic) + find_root_3(voi, states, rates, constants, computed_constants, algebraic) potassium_channel_g_K = 36.0 potassium_channel_E_K = membrane_E_R+12.0 - find_root_11(voi, states, rates, constants, computed_constants, algebraic) find_root_12(voi, states, rates, constants, computed_constants, algebraic) find_root_13(voi, states, rates, constants, computed_constants, algebraic) - find_root_10(voi, states, rates, constants, computed_constants, algebraic) + find_root_14(voi, states, rates, constants, computed_constants, algebraic) + find_root_11(voi, states, rates, constants, computed_constants, algebraic) sodium_channel_g_Na = 120.0 - sodium_channel_E_Na = membrane_E_R-115.0 - find_root_7(voi, states, rates, constants, computed_constants, algebraic) find_root_8(voi, states, rates, constants, computed_constants, algebraic) find_root_9(voi, states, rates, constants, computed_constants, algebraic) + find_root_10(voi, states, rates, constants, computed_constants, algebraic) + sodium_channel_m_gate_alpha_m = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + find_root_6(voi, states, rates, constants, computed_constants, algebraic) + find_root_7(voi, states, rates, constants, computed_constants, algebraic) find_root_4(voi, states, rates, constants, computed_constants, algebraic) find_root_5(voi, states, rates, constants, computed_constants, algebraic) - find_root_6(voi, states, rates, constants, computed_constants, algebraic) - find_root_3(voi, states, rates, constants, computed_constants, algebraic) find_root_1(voi, states, rates, constants, computed_constants, algebraic) @@ -463,21 +488,21 @@ def compute_variables(voi, states, rates, constants, computed_constants, algebra find_root_0(voi, states, rates, constants, computed_constants, algebraic) leakage_current_g_L = 0.3 membrane_E_R = 0.0 - leakage_current_E_L = membrane_E_R-10.613 find_root_2(voi, states, rates, constants, computed_constants, algebraic) + find_root_3(voi, states, rates, constants, computed_constants, algebraic) potassium_channel_g_K = 36.0 potassium_channel_E_K = membrane_E_R+12.0 - find_root_11(voi, states, rates, constants, computed_constants, algebraic) find_root_12(voi, states, rates, constants, computed_constants, algebraic) find_root_13(voi, states, rates, constants, computed_constants, algebraic) - find_root_10(voi, states, rates, constants, computed_constants, algebraic) + find_root_14(voi, states, rates, constants, computed_constants, algebraic) + find_root_11(voi, states, rates, constants, computed_constants, algebraic) sodium_channel_g_Na = 120.0 - sodium_channel_E_Na = membrane_E_R-115.0 - find_root_7(voi, states, rates, constants, computed_constants, algebraic) find_root_8(voi, states, rates, constants, computed_constants, algebraic) find_root_9(voi, states, rates, constants, computed_constants, algebraic) + find_root_10(voi, states, rates, constants, computed_constants, algebraic) + sodium_channel_m_gate_alpha_m = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + find_root_6(voi, states, rates, constants, computed_constants, algebraic) + find_root_7(voi, states, rates, constants, computed_constants, algebraic) find_root_4(voi, states, rates, constants, computed_constants, algebraic) find_root_5(voi, states, rates, constants, computed_constants, algebraic) - find_root_6(voi, states, rates, constants, computed_constants, algebraic) - find_root_3(voi, states, rates, constants, computed_constants, algebraic) find_root_1(voi, states, rates, constants, computed_constants, algebraic) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.with.externals.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.with.externals.c index 37fab4f5c..1d652ed39 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.with.externals.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.with.externals.c @@ -8,41 +8,45 @@ const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.2"; -const size_t STATE_COUNT = 3; -const size_t CONSTANT_COUNT = 0; -const size_t COMPUTED_CONSTANT_COUNT = 0; -const size_t ALGEBRAIC_COUNT = 8; -const size_t EXTERNAL_COUNT = 3; +const size_t STATE_COUNT = 4; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 11; +const size_t EXTERNAL_COUNT = 1; const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, {"h", "dimensionless", "sodium_channel_h_gate"}, {"m", "dimensionless", "sodium_channel_m_gate"}, {"n", "dimensionless", "potassium_channel_n_gate"} }; const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"} }; const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"E_K", "millivolt", "potassium_channel"} }; const VariableInfo ALGEBRAIC_INFO[] = { {"i_Stim", "microA_per_cm2", "membrane"}, {"i_L", "microA_per_cm2", "leakage_current"}, {"i_K", "microA_per_cm2", "potassium_channel"}, + {"E_L", "millivolt", "leakage_current"}, + {"E_Na", "millivolt", "sodium_channel"}, {"alpha_m", "per_millisecond", "sodium_channel_m_gate"}, {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, {"beta_n", "per_millisecond", "potassium_channel_n_gate"} }; const VariableInfo EXTERNAL_INFO[] = { - {"V", "millivolt", "membrane"}, - {"i_Na", "microA_per_cm2", "sodium_channel"}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate"} + {"i_Na", "microA_per_cm2", "sodium_channel"} }; double * createStatesArray() @@ -145,6 +149,33 @@ void findRoot0(double voi, double *states, double *rates, double *constants, dou algebraic[0] = u[0]; } +void objectiveFunction1(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + rates[0] = u[0]; + + f[0] = rates[0]-(-(-algebraic[0]+externals[0]+algebraic[2]+algebraic[1])/constants[0])-0.0; +} + +void findRoot1(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = rates[0]; + + nlaSolve(objectiveFunction1, u, 1, &rfi); + + rates[0] = u[0]; +} + void objectiveFunction2(double *u, double *f, void *data) { double voi = ((RootFindingInfo *) data)->voi; @@ -155,13 +186,11 @@ void objectiveFunction2(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[1] = u[0]; + algebraic[3] = u[0]; - double leakage_current_g_L = 0.3; double membrane_E_R = 0.0; - double leakage_current_E_L = membrane_E_R-10.613; - f[0] = algebraic[1]-leakage_current_g_L*(externals[0]-leakage_current_E_L)-0.0; + f[0] = algebraic[3]-(membrane_E_R-10.613)-0.0; } void findRoot2(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -169,14 +198,14 @@ void findRoot2(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[1]; + u[0] = algebraic[3]; nlaSolve(objectiveFunction2, u, 1, &rfi); - algebraic[1] = u[0]; + algebraic[3] = u[0]; } -void objectiveFunction4(double *u, double *f, void *data) +void objectiveFunction3(double *u, double *f, void *data) { double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; @@ -186,24 +215,26 @@ void objectiveFunction4(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[3] = u[0]; + algebraic[1] = u[0]; + + double leakage_current_g_L = 0.3; - f[0] = algebraic[3]-0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0)-0.0; + f[0] = algebraic[1]-leakage_current_g_L*(states[0]-algebraic[3])-0.0; } -void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +void findRoot3(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[3]; + u[0] = algebraic[1]; - nlaSolve(objectiveFunction4, u, 1, &rfi); + nlaSolve(objectiveFunction3, u, 1, &rfi); - algebraic[3] = u[0]; + algebraic[1] = u[0]; } -void objectiveFunction5(double *u, double *f, void *data) +void objectiveFunction4(double *u, double *f, void *data) { double voi = ((RootFindingInfo *) data)->voi; double *states = ((RootFindingInfo *) data)->states; @@ -215,17 +246,19 @@ void objectiveFunction5(double *u, double *f, void *data) algebraic[4] = u[0]; - f[0] = algebraic[4]-4.0*exp(externals[0]/18.0)-0.0; + double membrane_E_R = 0.0; + + f[0] = algebraic[4]-(membrane_E_R-115.0)-0.0; } -void findRoot5(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +void findRoot4(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; u[0] = algebraic[4]; - nlaSolve(objectiveFunction5, u, 1, &rfi); + nlaSolve(objectiveFunction4, u, 1, &rfi); algebraic[4] = u[0]; } @@ -240,9 +273,9 @@ void objectiveFunction6(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - rates[1] = u[0]; + algebraic[6] = u[0]; - f[0] = rates[1]-(algebraic[3]*(1.0-states[1])-algebraic[4]*states[1])-0.0; + f[0] = algebraic[6]-4.0*exp(states[0]/18.0)-0.0; } void findRoot6(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -250,11 +283,11 @@ void findRoot6(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = rates[1]; + u[0] = algebraic[6]; nlaSolve(objectiveFunction6, u, 1, &rfi); - rates[1] = u[0]; + algebraic[6] = u[0]; } void objectiveFunction7(double *u, double *f, void *data) @@ -267,9 +300,9 @@ void objectiveFunction7(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[5] = u[0]; + rates[2] = u[0]; - f[0] = algebraic[5]-0.07*exp(externals[0]/20.0)-0.0; + f[0] = rates[2]-(algebraic[5]*(1.0-states[2])-algebraic[6]*states[2])-0.0; } void findRoot7(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -277,11 +310,11 @@ void findRoot7(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[5]; + u[0] = rates[2]; nlaSolve(objectiveFunction7, u, 1, &rfi); - algebraic[5] = u[0]; + rates[2] = u[0]; } void objectiveFunction8(double *u, double *f, void *data) @@ -294,9 +327,9 @@ void objectiveFunction8(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[6] = u[0]; + algebraic[7] = u[0]; - f[0] = algebraic[6]-1.0/(exp((externals[0]+30.0)/10.0)+1.0)-0.0; + f[0] = algebraic[7]-0.07*exp(states[0]/20.0)-0.0; } void findRoot8(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -304,11 +337,11 @@ void findRoot8(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[6]; + u[0] = algebraic[7]; nlaSolve(objectiveFunction8, u, 1, &rfi); - algebraic[6] = u[0]; + algebraic[7] = u[0]; } void objectiveFunction9(double *u, double *f, void *data) @@ -321,9 +354,9 @@ void objectiveFunction9(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - rates[0] = u[0]; + algebraic[8] = u[0]; - f[0] = rates[0]-(algebraic[5]*(1.0-states[0])-algebraic[6]*states[0])-0.0; + f[0] = algebraic[8]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0; } void findRoot9(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -331,11 +364,11 @@ void findRoot9(double voi, double *states, double *rates, double *constants, dou RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = rates[0]; + u[0] = algebraic[8]; nlaSolve(objectiveFunction9, u, 1, &rfi); - rates[0] = u[0]; + algebraic[8] = u[0]; } void objectiveFunction10(double *u, double *f, void *data) @@ -348,23 +381,48 @@ void objectiveFunction10(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; + rates[1] = u[0]; + + f[0] = rates[1]-(algebraic[7]*(1.0-states[1])-algebraic[8]*states[1])-0.0; +} + +void findRoot10(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = rates[1]; + + nlaSolve(objectiveFunction10, u, 1, &rfi); + + rates[1] = u[0]; +} + +void objectiveFunction11(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + algebraic[2] = u[0]; double potassium_channel_g_K = 36.0; - double membrane_E_R = 0.0; - double potassium_channel_E_K = membrane_E_R+12.0; - f[0] = algebraic[2]-potassium_channel_g_K*pow(states[2], 4.0)*(externals[0]-potassium_channel_E_K)-0.0; + f[0] = algebraic[2]-potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computedConstants[0])-0.0; } -void findRoot10(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +void findRoot11(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) { RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; u[0] = algebraic[2]; - nlaSolve(objectiveFunction10, u, 1, &rfi); + nlaSolve(objectiveFunction11, u, 1, &rfi); algebraic[2] = u[0]; } @@ -379,9 +437,9 @@ void objectiveFunction12(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - algebraic[7] = u[0]; + algebraic[9] = u[0]; - f[0] = algebraic[7]-0.125*exp(externals[0]/80.0)-0.0; + f[0] = algebraic[9]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0; } void findRoot12(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -389,11 +447,11 @@ void findRoot12(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = algebraic[7]; + u[0] = algebraic[9]; nlaSolve(objectiveFunction12, u, 1, &rfi); - algebraic[7] = u[0]; + algebraic[9] = u[0]; } void objectiveFunction13(double *u, double *f, void *data) @@ -406,9 +464,9 @@ void objectiveFunction13(double *u, double *f, void *data) double *algebraic = ((RootFindingInfo *) data)->algebraic; double *externals = ((RootFindingInfo *) data)->externals; - rates[2] = u[0]; + algebraic[10] = u[0]; - f[0] = rates[2]-(externals[2]*(1.0-states[2])-algebraic[7]*states[2])-0.0; + f[0] = algebraic[10]-0.125*exp(states[0]/80.0)-0.0; } void findRoot13(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) @@ -416,60 +474,108 @@ void findRoot13(double voi, double *states, double *rates, double *constants, do RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; double u[1]; - u[0] = rates[2]; + u[0] = algebraic[10]; nlaSolve(objectiveFunction13, u, 1, &rfi); - rates[2] = u[0]; + algebraic[10] = u[0]; +} + +void objectiveFunction14(double *u, double *f, void *data) +{ + double voi = ((RootFindingInfo *) data)->voi; + double *states = ((RootFindingInfo *) data)->states; + double *rates = ((RootFindingInfo *) data)->rates; + double *constants = ((RootFindingInfo *) data)->constants; + double *computedConstants = ((RootFindingInfo *) data)->computedConstants; + double *algebraic = ((RootFindingInfo *) data)->algebraic; + double *externals = ((RootFindingInfo *) data)->externals; + + rates[3] = u[0]; + + f[0] = rates[3]-(algebraic[9]*(1.0-states[3])-algebraic[10]*states[3])-0.0; +} + +void findRoot14(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals) +{ + RootFindingInfo rfi = { voi, states, rates, constants, computedConstants, algebraic, externals }; + double u[1]; + + u[0] = rates[3]; + + nlaSolve(objectiveFunction14, u, 1, &rfi); + + rates[3] = u[0]; } void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - states[0] = 0.6; - states[1] = 0.05; - states[2] = 0.325; + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; rates[0] = 0.0; rates[1] = 0.0; rates[2] = 0.0; + rates[3] = 0.0; + constants[0] = 1.0; algebraic[0] = 0.0; algebraic[1] = 0.0; algebraic[2] = 0.0; algebraic[3] = 0.0; algebraic[4] = 0.0; - algebraic[5] = 0.0; algebraic[6] = 0.0; algebraic[7] = 0.0; + algebraic[8] = 0.0; + algebraic[9] = 0.0; + algebraic[10] = 0.0; } void computeComputedConstants(double *constants, double *computedConstants) { + double membrane_E_R = 0.0; + computedConstants[0] = membrane_E_R+12.0; } void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { + findRoot0(voi, states, rates, constants, computedConstants, algebraic, externals); + double leakage_current_g_L = 0.3; + double membrane_E_R = 0.0; + findRoot2(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot3(voi, states, rates, constants, computedConstants, algebraic, externals); + double potassium_channel_g_K = 36.0; + findRoot12(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot13(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot14(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot11(voi, states, rates, constants, computedConstants, algebraic, externals); + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); - findRoot4(voi, states, rates, constants, computedConstants, algebraic, externals); - findRoot5(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot1(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot6(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot7(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot8(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot9(voi, states, rates, constants, computedConstants, algebraic, externals); - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - findRoot12(voi, states, rates, constants, computedConstants, algebraic, externals); - findRoot13(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot10(voi, states, rates, constants, computedConstants, algebraic, externals); } void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - findRoot0(voi, states, rates, constants, computedConstants, algebraic, externals); double leakage_current_g_L = 0.3; + findRoot3(voi, states, rates, constants, computedConstants, algebraic, externals); + double potassium_channel_g_K = 36.0; + findRoot12(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot13(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot14(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot11(voi, states, rates, constants, computedConstants, algebraic, externals); + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + findRoot1(voi, states, rates, constants, computedConstants, algebraic, externals); double membrane_E_R = 0.0; - double leakage_current_E_L = membrane_E_R-10.613; - findRoot2(voi, states, rates, constants, computedConstants, algebraic, externals); - double potassium_channel_g_K = 36.0; - double potassium_channel_E_K = membrane_E_R+12.0; + findRoot4(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot6(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot7(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot8(voi, states, rates, constants, computedConstants, algebraic, externals); + findRoot9(voi, states, rates, constants, computedConstants, algebraic, externals); findRoot10(voi, states, rates, constants, computedConstants, algebraic, externals); - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.with.externals.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.with.externals.py index 5a140f97d..9e1d99ad0 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.with.externals.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.dae.wo.cc.untracked.variables.with.externals.py @@ -7,41 +7,45 @@ __version__ = "0.5.0" LIBCELLML_VERSION = "0.6.2" -STATE_COUNT = 3 -CONSTANT_COUNT = 0 -COMPUTED_CONSTANT_COUNT = 0 -ALGEBRAIC_COUNT = 8 -EXTERNAL_COUNT = 3 +STATE_COUNT = 4 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 11 +EXTERNAL_COUNT = 1 VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} ] CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"} ] COMPUTED_CONSTANT_INFO = [ + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} ] ALGEBRAIC_INFO = [ {"name": "i_Stim", "units": "microA_per_cm2", "component": "membrane"}, {"name": "i_L", "units": "microA_per_cm2", "component": "leakage_current"}, {"name": "i_K", "units": "microA_per_cm2", "component": "potassium_channel"}, + {"name": "E_L", "units": "millivolt", "component": "leakage_current"}, + {"name": "E_Na", "units": "millivolt", "component": "sodium_channel"}, {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} ] EXTERNAL_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane"}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"} ] @@ -104,6 +108,30 @@ def find_root_0(voi, states, rates, constants, computed_constants, algebraic, ex algebraic[0] = u[0] +def objective_function_1(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + rates[0] = u[0] + + f[0] = rates[0]-(-(-algebraic[0]+externals[0]+algebraic[2]+algebraic[1])/constants[0])-0.0 + + +def find_root_1(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = rates[0] + + u = nla_solve(objective_function_1, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + rates[0] = u[0] + + def objective_function_2(u, f, data): voi = data[0] states = data[1] @@ -113,26 +141,24 @@ def objective_function_2(u, f, data): algebraic = data[5] externals = data[6] - algebraic[1] = u[0] + algebraic[3] = u[0] - leakage_current_g_L = 0.3 membrane_E_R = 0.0 - leakage_current_E_L = membrane_E_R-10.613 - f[0] = algebraic[1]-leakage_current_g_L*(externals[0]-leakage_current_E_L)-0.0 + f[0] = algebraic[3]-(membrane_E_R-10.613)-0.0 def find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[1] + u[0] = algebraic[3] u = nla_solve(objective_function_2, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[1] = u[0] + algebraic[3] = u[0] -def objective_function_4(u, f, data): +def objective_function_3(u, f, data): voi = data[0] states = data[1] rates = data[2] @@ -141,22 +167,24 @@ def objective_function_4(u, f, data): algebraic = data[5] externals = data[6] - algebraic[3] = u[0] + algebraic[1] = u[0] - f[0] = algebraic[3]-0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0)-0.0 + leakage_current_g_L = 0.3 + f[0] = algebraic[1]-leakage_current_g_L*(states[0]-algebraic[3])-0.0 -def find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals): + +def find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[3] + u[0] = algebraic[1] - u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + u = nla_solve(objective_function_3, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[3] = u[0] + algebraic[1] = u[0] -def objective_function_5(u, f, data): +def objective_function_4(u, f, data): voi = data[0] states = data[1] rates = data[2] @@ -167,15 +195,17 @@ def objective_function_5(u, f, data): algebraic[4] = u[0] - f[0] = algebraic[4]-4.0*exp(externals[0]/18.0)-0.0 + membrane_E_R = 0.0 + + f[0] = algebraic[4]-(membrane_E_R-115.0)-0.0 -def find_root_5(voi, states, rates, constants, computed_constants, algebraic, externals): +def find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 u[0] = algebraic[4] - u = nla_solve(objective_function_5, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + u = nla_solve(objective_function_4, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) algebraic[4] = u[0] @@ -189,19 +219,19 @@ def objective_function_6(u, f, data): algebraic = data[5] externals = data[6] - rates[1] = u[0] + algebraic[6] = u[0] - f[0] = rates[1]-(algebraic[3]*(1.0-states[1])-algebraic[4]*states[1])-0.0 + f[0] = algebraic[6]-4.0*exp(states[0]/18.0)-0.0 def find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = rates[1] + u[0] = algebraic[6] u = nla_solve(objective_function_6, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - rates[1] = u[0] + algebraic[6] = u[0] def objective_function_7(u, f, data): @@ -213,19 +243,19 @@ def objective_function_7(u, f, data): algebraic = data[5] externals = data[6] - algebraic[5] = u[0] + rates[2] = u[0] - f[0] = algebraic[5]-0.07*exp(externals[0]/20.0)-0.0 + f[0] = rates[2]-(algebraic[5]*(1.0-states[2])-algebraic[6]*states[2])-0.0 def find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[5] + u[0] = rates[2] u = nla_solve(objective_function_7, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[5] = u[0] + rates[2] = u[0] def objective_function_8(u, f, data): @@ -237,19 +267,19 @@ def objective_function_8(u, f, data): algebraic = data[5] externals = data[6] - algebraic[6] = u[0] + algebraic[7] = u[0] - f[0] = algebraic[6]-1.0/(exp((externals[0]+30.0)/10.0)+1.0)-0.0 + f[0] = algebraic[7]-0.07*exp(states[0]/20.0)-0.0 def find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[6] + u[0] = algebraic[7] u = nla_solve(objective_function_8, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[6] = u[0] + algebraic[7] = u[0] def objective_function_9(u, f, data): @@ -261,19 +291,19 @@ def objective_function_9(u, f, data): algebraic = data[5] externals = data[6] - rates[0] = u[0] + algebraic[8] = u[0] - f[0] = rates[0]-(algebraic[5]*(1.0-states[0])-algebraic[6]*states[0])-0.0 + f[0] = algebraic[8]-1.0/(exp((states[0]+30.0)/10.0)+1.0)-0.0 def find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = rates[0] + u[0] = algebraic[8] u = nla_solve(objective_function_9, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - rates[0] = u[0] + algebraic[8] = u[0] def objective_function_10(u, f, data): @@ -285,21 +315,43 @@ def objective_function_10(u, f, data): algebraic = data[5] externals = data[6] + rates[1] = u[0] + + f[0] = rates[1]-(algebraic[7]*(1.0-states[1])-algebraic[8]*states[1])-0.0 + + +def find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = rates[1] + + u = nla_solve(objective_function_10, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + rates[1] = u[0] + + +def objective_function_11(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + algebraic[2] = u[0] potassium_channel_g_K = 36.0 - membrane_E_R = 0.0 - potassium_channel_E_K = membrane_E_R+12.0 - f[0] = algebraic[2]-potassium_channel_g_K*pow(states[2], 4.0)*(externals[0]-potassium_channel_E_K)-0.0 + f[0] = algebraic[2]-potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computed_constants[0])-0.0 -def find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals): +def find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 u[0] = algebraic[2] - u = nla_solve(objective_function_10, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + u = nla_solve(objective_function_11, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) algebraic[2] = u[0] @@ -313,19 +365,19 @@ def objective_function_12(u, f, data): algebraic = data[5] externals = data[6] - algebraic[7] = u[0] + algebraic[9] = u[0] - f[0] = algebraic[7]-0.125*exp(externals[0]/80.0)-0.0 + f[0] = algebraic[9]-0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0)-0.0 def find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = algebraic[7] + u[0] = algebraic[9] u = nla_solve(objective_function_12, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - algebraic[7] = u[0] + algebraic[9] = u[0] def objective_function_13(u, f, data): @@ -337,64 +389,108 @@ def objective_function_13(u, f, data): algebraic = data[5] externals = data[6] - rates[2] = u[0] + algebraic[10] = u[0] - f[0] = rates[2]-(externals[2]*(1.0-states[2])-algebraic[7]*states[2])-0.0 + f[0] = algebraic[10]-0.125*exp(states[0]/80.0)-0.0 def find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals): u = [nan]*1 - u[0] = rates[2] + u[0] = algebraic[10] u = nla_solve(objective_function_13, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) - rates[2] = u[0] + algebraic[10] = u[0] + + +def objective_function_14(u, f, data): + voi = data[0] + states = data[1] + rates = data[2] + constants = data[3] + computed_constants = data[4] + algebraic = data[5] + externals = data[6] + + rates[3] = u[0] + + f[0] = rates[3]-(algebraic[9]*(1.0-states[3])-algebraic[10]*states[3])-0.0 + + +def find_root_14(voi, states, rates, constants, computed_constants, algebraic, externals): + u = [nan]*1 + + u[0] = rates[3] + + u = nla_solve(objective_function_14, u, 1, [voi, states, rates, constants, computed_constants, algebraic, externals]) + + rates[3] = u[0] def initialise_variables(states, rates, constants, computed_constants, algebraic): - states[0] = 0.6 - states[1] = 0.05 - states[2] = 0.325 + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 rates[0] = 0.0 rates[1] = 0.0 rates[2] = 0.0 + rates[3] = 0.0 + constants[0] = 1.0 algebraic[0] = 0.0 algebraic[1] = 0.0 algebraic[2] = 0.0 algebraic[3] = 0.0 algebraic[4] = 0.0 - algebraic[5] = 0.0 algebraic[6] = 0.0 algebraic[7] = 0.0 + algebraic[8] = 0.0 + algebraic[9] = 0.0 + algebraic[10] = 0.0 def compute_computed_constants(constants, computed_constants): - pass + membrane_E_R = 0.0 + computed_constants[0] = membrane_E_R+12.0 def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals) + leakage_current_g_L = 0.3 + membrane_E_R = 0.0 + find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals) + potassium_channel_g_K = 36.0 + find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_14(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals) + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) - find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals) - find_root_5(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_1(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals) - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals) - find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals) def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): - find_root_0(voi, states, rates, constants, computed_constants, algebraic, externals) leakage_current_g_L = 0.3 + find_root_3(voi, states, rates, constants, computed_constants, algebraic, externals) + potassium_channel_g_K = 36.0 + find_root_12(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_13(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_14(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_11(voi, states, rates, constants, computed_constants, algebraic, externals) + algebraic[5] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + find_root_1(voi, states, rates, constants, computed_constants, algebraic, externals) membrane_E_R = 0.0 - leakage_current_E_L = membrane_E_R-10.613 - find_root_2(voi, states, rates, constants, computed_constants, algebraic, externals) - potassium_channel_g_K = 36.0 - potassium_channel_E_K = membrane_E_R+12.0 + find_root_4(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_6(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_7(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_8(voi, states, rates, constants, computed_constants, algebraic, externals) + find_root_9(voi, states, rates, constants, computed_constants, algebraic, externals) find_root_10(voi, states, rates, constants, computed_constants, algebraic, externals) - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.algebraic.variables.with.externals.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.algebraic.variables.with.externals.c index 15f0dc07e..f4e5bac15 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.algebraic.variables.with.externals.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.algebraic.variables.with.externals.c @@ -8,15 +8,16 @@ const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.2"; -const size_t STATE_COUNT = 3; +const size_t STATE_COUNT = 4; const size_t CONSTANT_COUNT = 5; const size_t COMPUTED_CONSTANT_COUNT = 3; -const size_t ALGEBRAIC_COUNT = 0; -const size_t EXTERNAL_COUNT = 3; +const size_t ALGEBRAIC_COUNT = 1; +const size_t EXTERNAL_COUNT = 1; const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, {"h", "dimensionless", "sodium_channel_h_gate"}, {"m", "dimensionless", "sodium_channel_m_gate"}, {"n", "dimensionless", "potassium_channel_n_gate"} @@ -37,12 +38,11 @@ const VariableInfo COMPUTED_CONSTANT_INFO[] = { }; const VariableInfo ALGEBRAIC_INFO[] = { + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"} }; const VariableInfo EXTERNAL_INFO[] = { - {"V", "millivolt", "membrane"}, - {"i_Na", "microA_per_cm2", "sodium_channel"}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate"} + {"i_Na", "microA_per_cm2", "sodium_channel"} }; double * createStatesArray() @@ -107,9 +107,10 @@ void deleteArray(double *array) void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - states[0] = 0.6; - states[1] = 0.05; - states[2] = 0.325; + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; constants[0] = 1.0; constants[1] = 0.0; constants[2] = 0.3; @@ -126,21 +127,24 @@ void computeComputedConstants(double *constants, double *computedConstants) void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { + double membrane_i_Stim = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; + double leakage_current_i_L = constants[2]*(states[0]-computedConstants[0]); + double potassium_channel_i_K = constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); - double sodium_channel_m_gate_alpha_m = 0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0); - double sodium_channel_m_gate_beta_m = 4.0*exp(externals[0]/18.0); - rates[1] = sodium_channel_m_gate_alpha_m*(1.0-states[1])-sodium_channel_m_gate_beta_m*states[1]; - double sodium_channel_h_gate_alpha_h = 0.07*exp(externals[0]/20.0); - double sodium_channel_h_gate_beta_h = 1.0/(exp((externals[0]+30.0)/10.0)+1.0); - rates[0] = sodium_channel_h_gate_alpha_h*(1.0-states[0])-sodium_channel_h_gate_beta_h*states[0]; - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - double potassium_channel_n_gate_beta_n = 0.125*exp(externals[0]/80.0); - rates[2] = externals[2]*(1.0-states[2])-potassium_channel_n_gate_beta_n*states[2]; + rates[0] = -(-membrane_i_Stim+externals[0]+potassium_channel_i_K+leakage_current_i_L)/constants[0]; + double sodium_channel_m_gate_beta_m = 4.0*exp(states[0]/18.0); + rates[2] = algebraic[3]*(1.0-states[2])-sodium_channel_m_gate_beta_m*states[2]; + double sodium_channel_h_gate_alpha_h = 0.07*exp(states[0]/20.0); + double sodium_channel_h_gate_beta_h = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + rates[1] = sodium_channel_h_gate_alpha_h*(1.0-states[1])-sodium_channel_h_gate_beta_h*states[1]; + double potassium_channel_n_gate_alpha_n = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + double potassium_channel_n_gate_beta_n = 0.125*exp(states[0]/80.0); + rates[3] = potassium_channel_n_gate_alpha_n*(1.0-states[3])-potassium_channel_n_gate_beta_n*states[3]; } void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.algebraic.variables.with.externals.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.algebraic.variables.with.externals.py index 3248cfa26..a3ced765d 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.algebraic.variables.with.externals.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.algebraic.variables.with.externals.py @@ -7,15 +7,16 @@ __version__ = "0.5.0" LIBCELLML_VERSION = "0.6.2" -STATE_COUNT = 3 +STATE_COUNT = 4 CONSTANT_COUNT = 5 COMPUTED_CONSTANT_COUNT = 3 -ALGEBRAIC_COUNT = 0 -EXTERNAL_COUNT = 3 +ALGEBRAIC_COUNT = 1 +EXTERNAL_COUNT = 1 VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} @@ -36,12 +37,11 @@ ] ALGEBRAIC_INFO = [ + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"} ] EXTERNAL_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane"}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"} ] @@ -78,9 +78,10 @@ def create_externals_array(): def initialise_variables(states, rates, constants, computed_constants, algebraic): - states[0] = 0.6 - states[1] = 0.05 - states[2] = 0.325 + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 constants[0] = 1.0 constants[1] = 0.0 constants[2] = 0.3 @@ -95,19 +96,22 @@ def compute_computed_constants(constants, computed_constants): def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + membrane_i_Stim = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 + leakage_current_i_L = constants[2]*(states[0]-computed_constants[0]) + potassium_channel_i_K = constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) - sodium_channel_m_gate_alpha_m = 0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0) - sodium_channel_m_gate_beta_m = 4.0*exp(externals[0]/18.0) - rates[1] = sodium_channel_m_gate_alpha_m*(1.0-states[1])-sodium_channel_m_gate_beta_m*states[1] - sodium_channel_h_gate_alpha_h = 0.07*exp(externals[0]/20.0) - sodium_channel_h_gate_beta_h = 1.0/(exp((externals[0]+30.0)/10.0)+1.0) - rates[0] = sodium_channel_h_gate_alpha_h*(1.0-states[0])-sodium_channel_h_gate_beta_h*states[0] - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - potassium_channel_n_gate_beta_n = 0.125*exp(externals[0]/80.0) - rates[2] = externals[2]*(1.0-states[2])-potassium_channel_n_gate_beta_n*states[2] + rates[0] = -(-membrane_i_Stim+externals[0]+potassium_channel_i_K+leakage_current_i_L)/constants[0] + sodium_channel_m_gate_beta_m = 4.0*exp(states[0]/18.0) + rates[2] = algebraic[3]*(1.0-states[2])-sodium_channel_m_gate_beta_m*states[2] + sodium_channel_h_gate_alpha_h = 0.07*exp(states[0]/20.0) + sodium_channel_h_gate_beta_h = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + rates[1] = sodium_channel_h_gate_alpha_h*(1.0-states[1])-sodium_channel_h_gate_beta_h*states[1] + potassium_channel_n_gate_alpha_n = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + potassium_channel_n_gate_beta_n = 0.125*exp(states[0]/80.0) + rates[3] = potassium_channel_n_gate_alpha_n*(1.0-states[3])-potassium_channel_n_gate_beta_n*states[3] def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.computed.constants.with.externals.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.computed.constants.with.externals.c index 0da4831e0..126baf57e 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.computed.constants.with.externals.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.computed.constants.with.externals.c @@ -8,15 +8,16 @@ const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.2"; -const size_t STATE_COUNT = 3; +const size_t STATE_COUNT = 4; const size_t CONSTANT_COUNT = 5; -const size_t COMPUTED_CONSTANT_COUNT = 0; -const size_t ALGEBRAIC_COUNT = 8; -const size_t EXTERNAL_COUNT = 3; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 9; +const size_t EXTERNAL_COUNT = 1; const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, {"h", "dimensionless", "sodium_channel_h_gate"}, {"m", "dimensionless", "sodium_channel_m_gate"}, {"n", "dimensionless", "potassium_channel_n_gate"} @@ -31,6 +32,7 @@ const VariableInfo CONSTANT_INFO[] = { }; const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"E_K", "millivolt", "potassium_channel"} }; const VariableInfo ALGEBRAIC_INFO[] = { @@ -41,13 +43,12 @@ const VariableInfo ALGEBRAIC_INFO[] = { {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, {"beta_n", "per_millisecond", "potassium_channel_n_gate"} }; const VariableInfo EXTERNAL_INFO[] = { - {"V", "millivolt", "membrane"}, - {"i_Na", "microA_per_cm2", "sodium_channel"}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate"} + {"i_Na", "microA_per_cm2", "sodium_channel"} }; double * createStatesArray() @@ -112,9 +113,10 @@ void deleteArray(double *array) void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - states[0] = 0.6; - states[1] = 0.05; - states[2] = 0.325; + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; constants[0] = 1.0; constants[1] = 0.0; constants[2] = 0.3; @@ -124,30 +126,38 @@ void initialiseVariables(double *states, double *rates, double *constants, doubl void computeComputedConstants(double *constants, double *computedConstants) { + computedConstants[2] = constants[1]+12.0; } void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { + algebraic[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; + double leakage_current_E_L = constants[1]-10.613; + algebraic[1] = constants[2]*(states[0]-leakage_current_E_L); + algebraic[2] = constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); - algebraic[3] = 0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0); - algebraic[4] = 4.0*exp(externals[0]/18.0); - rates[1] = algebraic[3]*(1.0-states[1])-algebraic[4]*states[1]; - algebraic[5] = 0.07*exp(externals[0]/20.0); - algebraic[6] = 1.0/(exp((externals[0]+30.0)/10.0)+1.0); - rates[0] = algebraic[5]*(1.0-states[0])-algebraic[6]*states[0]; - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - algebraic[7] = 0.125*exp(externals[0]/80.0); - rates[2] = externals[2]*(1.0-states[2])-algebraic[7]*states[2]; + rates[0] = -(-algebraic[0]+externals[0]+algebraic[2]+algebraic[1])/constants[0]; + algebraic[4] = 4.0*exp(states[0]/18.0); + rates[2] = algebraic[3]*(1.0-states[2])-algebraic[4]*states[2]; + algebraic[5] = 0.07*exp(states[0]/20.0); + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + rates[1] = algebraic[5]*(1.0-states[1])-algebraic[6]*states[1]; + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[8] = 0.125*exp(states[0]/80.0); + rates[3] = algebraic[7]*(1.0-states[3])-algebraic[8]*states[3]; } void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - algebraic[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; - externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); double leakage_current_E_L = constants[1]-10.613; - algebraic[1] = constants[2]*(externals[0]-leakage_current_E_L); - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); - double potassium_channel_E_K = constants[1]+12.0; - algebraic[2] = constants[4]*pow(states[2], 4.0)*(externals[0]-potassium_channel_E_K); + algebraic[1] = constants[2]*(states[0]-leakage_current_E_L); + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[4] = 4.0*exp(states[0]/18.0); + algebraic[5] = 0.07*exp(states[0]/20.0); + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + algebraic[2] = constants[4]*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[8] = 0.125*exp(states[0]/80.0); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.computed.constants.with.externals.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.computed.constants.with.externals.py index fa2ff1800..d98d9a538 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.computed.constants.with.externals.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.computed.constants.with.externals.py @@ -7,15 +7,16 @@ __version__ = "0.5.0" LIBCELLML_VERSION = "0.6.2" -STATE_COUNT = 3 +STATE_COUNT = 4 CONSTANT_COUNT = 5 -COMPUTED_CONSTANT_COUNT = 0 -ALGEBRAIC_COUNT = 8 -EXTERNAL_COUNT = 3 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 9 +EXTERNAL_COUNT = 1 VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} @@ -30,6 +31,7 @@ ] COMPUTED_CONSTANT_INFO = [ + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} ] ALGEBRAIC_INFO = [ @@ -40,13 +42,12 @@ {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} ] EXTERNAL_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane"}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"} ] @@ -83,9 +84,10 @@ def create_externals_array(): def initialise_variables(states, rates, constants, computed_constants, algebraic): - states[0] = 0.6 - states[1] = 0.05 - states[2] = 0.325 + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 constants[0] = 1.0 constants[1] = 0.0 constants[2] = 0.3 @@ -94,28 +96,35 @@ def initialise_variables(states, rates, constants, computed_constants, algebraic def compute_computed_constants(constants, computed_constants): - pass + computed_constants[2] = constants[1]+12.0 def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 + leakage_current_E_L = constants[1]-10.613 + algebraic[1] = constants[2]*(states[0]-leakage_current_E_L) + algebraic[2] = constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) - algebraic[3] = 0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0) - algebraic[4] = 4.0*exp(externals[0]/18.0) - rates[1] = algebraic[3]*(1.0-states[1])-algebraic[4]*states[1] - algebraic[5] = 0.07*exp(externals[0]/20.0) - algebraic[6] = 1.0/(exp((externals[0]+30.0)/10.0)+1.0) - rates[0] = algebraic[5]*(1.0-states[0])-algebraic[6]*states[0] - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - algebraic[7] = 0.125*exp(externals[0]/80.0) - rates[2] = externals[2]*(1.0-states[2])-algebraic[7]*states[2] + rates[0] = -(-algebraic[0]+externals[0]+algebraic[2]+algebraic[1])/constants[0] + algebraic[4] = 4.0*exp(states[0]/18.0) + rates[2] = algebraic[3]*(1.0-states[2])-algebraic[4]*states[2] + algebraic[5] = 0.07*exp(states[0]/20.0) + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + rates[1] = algebraic[5]*(1.0-states[1])-algebraic[6]*states[1] + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[8] = 0.125*exp(states[0]/80.0) + rates[3] = algebraic[7]*(1.0-states[3])-algebraic[8]*states[3] def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): - algebraic[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 - externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) leakage_current_E_L = constants[1]-10.613 - algebraic[1] = constants[2]*(externals[0]-leakage_current_E_L) - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) - potassium_channel_E_K = constants[1]+12.0 - algebraic[2] = constants[4]*pow(states[2], 4.0)*(externals[0]-potassium_channel_E_K) + algebraic[1] = constants[2]*(states[0]-leakage_current_E_L) + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[4] = 4.0*exp(states[0]/18.0) + algebraic[5] = 0.07*exp(states[0]/20.0) + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + algebraic[2] = constants[4]*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[8] = 0.125*exp(states[0]/80.0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.constants.with.externals.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.constants.with.externals.c index dad52f012..a0f399230 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.constants.with.externals.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.constants.with.externals.c @@ -8,21 +8,23 @@ const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.2"; -const size_t STATE_COUNT = 3; -const size_t CONSTANT_COUNT = 0; +const size_t STATE_COUNT = 4; +const size_t CONSTANT_COUNT = 1; const size_t COMPUTED_CONSTANT_COUNT = 3; -const size_t ALGEBRAIC_COUNT = 8; -const size_t EXTERNAL_COUNT = 3; +const size_t ALGEBRAIC_COUNT = 9; +const size_t EXTERNAL_COUNT = 1; const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, {"h", "dimensionless", "sodium_channel_h_gate"}, {"m", "dimensionless", "sodium_channel_m_gate"}, {"n", "dimensionless", "potassium_channel_n_gate"} }; const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"} }; const VariableInfo COMPUTED_CONSTANT_INFO[] = { @@ -39,13 +41,12 @@ const VariableInfo ALGEBRAIC_INFO[] = { {"beta_m", "per_millisecond", "sodium_channel_m_gate"}, {"alpha_h", "per_millisecond", "sodium_channel_h_gate"}, {"beta_h", "per_millisecond", "sodium_channel_h_gate"}, + {"alpha_n", "per_millisecond", "potassium_channel_n_gate"}, {"beta_n", "per_millisecond", "potassium_channel_n_gate"} }; const VariableInfo EXTERNAL_INFO[] = { - {"V", "millivolt", "membrane"}, - {"i_Na", "microA_per_cm2", "sodium_channel"}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate"} + {"i_Na", "microA_per_cm2", "sodium_channel"} }; double * createStatesArray() @@ -110,9 +111,11 @@ void deleteArray(double *array) void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - states[0] = 0.6; - states[1] = 0.05; - states[2] = 0.325; + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; + constants[0] = 1.0; } void computeComputedConstants(double *constants, double *computedConstants) @@ -125,26 +128,35 @@ void computeComputedConstants(double *constants, double *computedConstants) void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { + algebraic[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; + double leakage_current_g_L = 0.3; + algebraic[1] = leakage_current_g_L*(states[0]-computedConstants[0]); + double potassium_channel_g_K = 36.0; + algebraic[2] = potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); - algebraic[3] = 0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0); - algebraic[4] = 4.0*exp(externals[0]/18.0); - rates[1] = algebraic[3]*(1.0-states[1])-algebraic[4]*states[1]; - algebraic[5] = 0.07*exp(externals[0]/20.0); - algebraic[6] = 1.0/(exp((externals[0]+30.0)/10.0)+1.0); - rates[0] = algebraic[5]*(1.0-states[0])-algebraic[6]*states[0]; - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - algebraic[7] = 0.125*exp(externals[0]/80.0); - rates[2] = externals[2]*(1.0-states[2])-algebraic[7]*states[2]; + rates[0] = -(-algebraic[0]+externals[0]+algebraic[2]+algebraic[1])/constants[0]; + algebraic[4] = 4.0*exp(states[0]/18.0); + rates[2] = algebraic[3]*(1.0-states[2])-algebraic[4]*states[2]; + algebraic[5] = 0.07*exp(states[0]/20.0); + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + rates[1] = algebraic[5]*(1.0-states[1])-algebraic[6]*states[1]; + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[8] = 0.125*exp(states[0]/80.0); + rates[3] = algebraic[7]*(1.0-states[3])-algebraic[8]*states[3]; } void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { - algebraic[0] = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; - externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); double leakage_current_g_L = 0.3; - algebraic[1] = leakage_current_g_L*(externals[0]-computedConstants[0]); - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); + algebraic[1] = leakage_current_g_L*(states[0]-computedConstants[0]); + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); + externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); + algebraic[4] = 4.0*exp(states[0]/18.0); + algebraic[5] = 0.07*exp(states[0]/20.0); + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0); double potassium_channel_g_K = 36.0; - algebraic[2] = potassium_channel_g_K*pow(states[2], 4.0)*(externals[0]-computedConstants[2]); + algebraic[2] = potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + algebraic[8] = 0.125*exp(states[0]/80.0); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.constants.with.externals.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.constants.with.externals.py index 372dff1b2..d6d4668ae 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.constants.with.externals.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.constants.with.externals.py @@ -7,21 +7,23 @@ __version__ = "0.5.0" LIBCELLML_VERSION = "0.6.2" -STATE_COUNT = 3 -CONSTANT_COUNT = 0 +STATE_COUNT = 4 +CONSTANT_COUNT = 1 COMPUTED_CONSTANT_COUNT = 3 -ALGEBRAIC_COUNT = 8 -EXTERNAL_COUNT = 3 +ALGEBRAIC_COUNT = 9 +EXTERNAL_COUNT = 1 VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} ] CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"} ] COMPUTED_CONSTANT_INFO = [ @@ -38,13 +40,12 @@ {"name": "beta_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"}, {"name": "alpha_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, {"name": "beta_h", "units": "per_millisecond", "component": "sodium_channel_h_gate"}, + {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"}, {"name": "beta_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} ] EXTERNAL_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane"}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"} ] @@ -81,9 +82,11 @@ def create_externals_array(): def initialise_variables(states, rates, constants, computed_constants, algebraic): - states[0] = 0.6 - states[1] = 0.05 - states[2] = 0.325 + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 + constants[0] = 1.0 def compute_computed_constants(constants, computed_constants): @@ -94,24 +97,33 @@ def compute_computed_constants(constants, computed_constants): def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 + leakage_current_g_L = 0.3 + algebraic[1] = leakage_current_g_L*(states[0]-computed_constants[0]) + potassium_channel_g_K = 36.0 + algebraic[2] = potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) - algebraic[3] = 0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0) - algebraic[4] = 4.0*exp(externals[0]/18.0) - rates[1] = algebraic[3]*(1.0-states[1])-algebraic[4]*states[1] - algebraic[5] = 0.07*exp(externals[0]/20.0) - algebraic[6] = 1.0/(exp((externals[0]+30.0)/10.0)+1.0) - rates[0] = algebraic[5]*(1.0-states[0])-algebraic[6]*states[0] - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - algebraic[7] = 0.125*exp(externals[0]/80.0) - rates[2] = externals[2]*(1.0-states[2])-algebraic[7]*states[2] + rates[0] = -(-algebraic[0]+externals[0]+algebraic[2]+algebraic[1])/constants[0] + algebraic[4] = 4.0*exp(states[0]/18.0) + rates[2] = algebraic[3]*(1.0-states[2])-algebraic[4]*states[2] + algebraic[5] = 0.07*exp(states[0]/20.0) + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + rates[1] = algebraic[5]*(1.0-states[1])-algebraic[6]*states[1] + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[8] = 0.125*exp(states[0]/80.0) + rates[3] = algebraic[7]*(1.0-states[3])-algebraic[8]*states[3] def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): - algebraic[0] = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 - externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) leakage_current_g_L = 0.3 - algebraic[1] = leakage_current_g_L*(externals[0]-computed_constants[0]) - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1) + algebraic[1] = leakage_current_g_L*(states[0]-computed_constants[0]) + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) + externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) + algebraic[4] = 4.0*exp(states[0]/18.0) + algebraic[5] = 0.07*exp(states[0]/20.0) + algebraic[6] = 1.0/(exp((states[0]+30.0)/10.0)+1.0) potassium_channel_g_K = 36.0 - algebraic[2] = potassium_channel_g_K*pow(states[2], 4.0)*(externals[0]-computed_constants[2]) + algebraic[2] = potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[7] = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + algebraic[8] = 0.125*exp(states[0]/80.0) diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.variables.with.externals.c b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.variables.with.externals.c index d4e8b7d56..5eb5595c9 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.variables.with.externals.c +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.variables.with.externals.c @@ -8,33 +8,35 @@ const char VERSION[] = "0.6.0"; const char LIBCELLML_VERSION[] = "0.6.2"; -const size_t STATE_COUNT = 3; -const size_t CONSTANT_COUNT = 0; -const size_t COMPUTED_CONSTANT_COUNT = 0; -const size_t ALGEBRAIC_COUNT = 0; -const size_t EXTERNAL_COUNT = 3; +const size_t STATE_COUNT = 4; +const size_t CONSTANT_COUNT = 1; +const size_t COMPUTED_CONSTANT_COUNT = 1; +const size_t ALGEBRAIC_COUNT = 1; +const size_t EXTERNAL_COUNT = 1; const VariableInfo VOI_INFO = {"time", "millisecond", "environment"}; const VariableInfo STATE_INFO[] = { + {"V", "millivolt", "membrane"}, {"h", "dimensionless", "sodium_channel_h_gate"}, {"m", "dimensionless", "sodium_channel_m_gate"}, {"n", "dimensionless", "potassium_channel_n_gate"} }; const VariableInfo CONSTANT_INFO[] = { + {"Cm", "microF_per_cm2", "membrane"} }; const VariableInfo COMPUTED_CONSTANT_INFO[] = { + {"E_K", "millivolt", "potassium_channel"} }; const VariableInfo ALGEBRAIC_INFO[] = { + {"alpha_m", "per_millisecond", "sodium_channel_m_gate"} }; const VariableInfo EXTERNAL_INFO[] = { - {"V", "millivolt", "membrane"}, - {"i_Na", "microA_per_cm2", "sodium_channel"}, - {"alpha_n", "per_millisecond", "potassium_channel_n_gate"} + {"i_Na", "microA_per_cm2", "sodium_channel"} }; double * createStatesArray() @@ -99,32 +101,43 @@ void deleteArray(double *array) void initialiseVariables(double *states, double *rates, double *constants, double *computedConstants, double *algebraic) { - states[0] = 0.6; - states[1] = 0.05; - states[2] = 0.325; + states[0] = 0.0; + states[1] = 0.6; + states[2] = 0.05; + states[3] = 0.325; + constants[0] = 1.0; } void computeComputedConstants(double *constants, double *computedConstants) { + double membrane_E_R = 0.0; + computedConstants[2] = membrane_E_R+12.0; } void computeRates(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { + double membrane_i_Stim = ((voi >= 10.0) && (voi <= 10.5))?-20.0:0.0; + double leakage_current_g_L = 0.3; + double membrane_E_R = 0.0; + double leakage_current_E_L = membrane_E_R-10.613; + double leakage_current_i_L = leakage_current_g_L*(states[0]-leakage_current_E_L); + double potassium_channel_g_K = 36.0; + double potassium_channel_i_K = potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computedConstants[2]); + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); - double sodium_channel_m_gate_alpha_m = 0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0); - double sodium_channel_m_gate_beta_m = 4.0*exp(externals[0]/18.0); - rates[1] = sodium_channel_m_gate_alpha_m*(1.0-states[1])-sodium_channel_m_gate_beta_m*states[1]; - double sodium_channel_h_gate_alpha_h = 0.07*exp(externals[0]/20.0); - double sodium_channel_h_gate_beta_h = 1.0/(exp((externals[0]+30.0)/10.0)+1.0); - rates[0] = sodium_channel_h_gate_alpha_h*(1.0-states[0])-sodium_channel_h_gate_beta_h*states[0]; - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - double potassium_channel_n_gate_beta_n = 0.125*exp(externals[0]/80.0); - rates[2] = externals[2]*(1.0-states[2])-potassium_channel_n_gate_beta_n*states[2]; + rates[0] = -(-membrane_i_Stim+externals[0]+potassium_channel_i_K+leakage_current_i_L)/constants[0]; + double sodium_channel_m_gate_beta_m = 4.0*exp(states[0]/18.0); + rates[2] = algebraic[3]*(1.0-states[2])-sodium_channel_m_gate_beta_m*states[2]; + double sodium_channel_h_gate_alpha_h = 0.07*exp(states[0]/20.0); + double sodium_channel_h_gate_beta_h = 1.0/(exp((states[0]+30.0)/10.0)+1.0); + rates[1] = sodium_channel_h_gate_alpha_h*(1.0-states[1])-sodium_channel_h_gate_beta_h*states[1]; + double potassium_channel_n_gate_alpha_n = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0); + double potassium_channel_n_gate_beta_n = 0.125*exp(states[0]/80.0); + rates[3] = potassium_channel_n_gate_alpha_n*(1.0-states[3])-potassium_channel_n_gate_beta_n*states[3]; } void computeVariables(double voi, double *states, double *rates, double *constants, double *computedConstants, double *algebraic, double *externals, ExternalVariable externalVariable) { + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0); externals[0] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 0); - externals[2] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 2); - externals[1] = externalVariable(voi, states, rates, constants, computedConstants, algebraic, externals, 1); } diff --git a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.variables.with.externals.py b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.variables.with.externals.py index 273f0a46a..a8bc614fe 100644 --- a/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.variables.with.externals.py +++ b/tests/resources/generator/hodgkin_huxley_squid_axon_model_1952/model.untracked.variables.with.externals.py @@ -7,33 +7,35 @@ __version__ = "0.5.0" LIBCELLML_VERSION = "0.6.2" -STATE_COUNT = 3 -CONSTANT_COUNT = 0 -COMPUTED_CONSTANT_COUNT = 0 -ALGEBRAIC_COUNT = 0 -EXTERNAL_COUNT = 3 +STATE_COUNT = 4 +CONSTANT_COUNT = 1 +COMPUTED_CONSTANT_COUNT = 1 +ALGEBRAIC_COUNT = 1 +EXTERNAL_COUNT = 1 VOI_INFO = {"name": "time", "units": "millisecond", "component": "environment"} STATE_INFO = [ + {"name": "V", "units": "millivolt", "component": "membrane"}, {"name": "h", "units": "dimensionless", "component": "sodium_channel_h_gate"}, {"name": "m", "units": "dimensionless", "component": "sodium_channel_m_gate"}, {"name": "n", "units": "dimensionless", "component": "potassium_channel_n_gate"} ] CONSTANT_INFO = [ + {"name": "Cm", "units": "microF_per_cm2", "component": "membrane"} ] COMPUTED_CONSTANT_INFO = [ + {"name": "E_K", "units": "millivolt", "component": "potassium_channel"} ] ALGEBRAIC_INFO = [ + {"name": "alpha_m", "units": "per_millisecond", "component": "sodium_channel_m_gate"} ] EXTERNAL_INFO = [ - {"name": "V", "units": "millivolt", "component": "membrane"}, - {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"}, - {"name": "alpha_n", "units": "per_millisecond", "component": "potassium_channel_n_gate"} + {"name": "i_Na", "units": "microA_per_cm2", "component": "sodium_channel"} ] @@ -70,29 +72,39 @@ def create_externals_array(): def initialise_variables(states, rates, constants, computed_constants, algebraic): - states[0] = 0.6 - states[1] = 0.05 - states[2] = 0.325 + states[0] = 0.0 + states[1] = 0.6 + states[2] = 0.05 + states[3] = 0.325 + constants[0] = 1.0 def compute_computed_constants(constants, computed_constants): - pass + membrane_E_R = 0.0 + computed_constants[2] = membrane_E_R+12.0 def compute_rates(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + membrane_i_Stim = -20.0 if and_func(geq_func(voi, 10.0), leq_func(voi, 10.5)) else 0.0 + leakage_current_g_L = 0.3 + membrane_E_R = 0.0 + leakage_current_E_L = membrane_E_R-10.613 + leakage_current_i_L = leakage_current_g_L*(states[0]-leakage_current_E_L) + potassium_channel_g_K = 36.0 + potassium_channel_i_K = potassium_channel_g_K*pow(states[3], 4.0)*(states[0]-computed_constants[2]) + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) - sodium_channel_m_gate_alpha_m = 0.1*(externals[0]+25.0)/(exp((externals[0]+25.0)/10.0)-1.0) - sodium_channel_m_gate_beta_m = 4.0*exp(externals[0]/18.0) - rates[1] = sodium_channel_m_gate_alpha_m*(1.0-states[1])-sodium_channel_m_gate_beta_m*states[1] - sodium_channel_h_gate_alpha_h = 0.07*exp(externals[0]/20.0) - sodium_channel_h_gate_beta_h = 1.0/(exp((externals[0]+30.0)/10.0)+1.0) - rates[0] = sodium_channel_h_gate_alpha_h*(1.0-states[0])-sodium_channel_h_gate_beta_h*states[0] - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - potassium_channel_n_gate_beta_n = 0.125*exp(externals[0]/80.0) - rates[2] = externals[2]*(1.0-states[2])-potassium_channel_n_gate_beta_n*states[2] + rates[0] = -(-membrane_i_Stim+externals[0]+potassium_channel_i_K+leakage_current_i_L)/constants[0] + sodium_channel_m_gate_beta_m = 4.0*exp(states[0]/18.0) + rates[2] = algebraic[3]*(1.0-states[2])-sodium_channel_m_gate_beta_m*states[2] + sodium_channel_h_gate_alpha_h = 0.07*exp(states[0]/20.0) + sodium_channel_h_gate_beta_h = 1.0/(exp((states[0]+30.0)/10.0)+1.0) + rates[1] = sodium_channel_h_gate_alpha_h*(1.0-states[1])-sodium_channel_h_gate_beta_h*states[1] + potassium_channel_n_gate_alpha_n = 0.01*(states[0]+10.0)/(exp((states[0]+10.0)/10.0)-1.0) + potassium_channel_n_gate_beta_n = 0.125*exp(states[0]/80.0) + rates[3] = potassium_channel_n_gate_alpha_n*(1.0-states[3])-potassium_channel_n_gate_beta_n*states[3] def compute_variables(voi, states, rates, constants, computed_constants, algebraic, externals, external_variable): + algebraic[3] = 0.1*(states[0]+25.0)/(exp((states[0]+25.0)/10.0)-1.0) externals[0] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 0) - externals[2] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 2) - externals[1] = external_variable(voi, states, rates, constants, computed_constants, algebraic, externals, 1)