def test_initial_value(self): from libcellml import Variable # std::string initialValue() value = '5 + x' v = Variable() self.assertEqual(v.initialValue(), '') v.setInitialValue(value) self.assertEqual(v.initialValue(), value)
def test_set_initial_value(self): from libcellml import Variable # void setInitialValue(const std::string &initialValue) v = Variable() v.setInitialValue('test') del (v) # void setInitialValue(double initialValue) v = Variable() v.setInitialValue('test') del (v) # void setInitialValue(const VariablePtr &variable) v1 = Variable() v2 = Variable() v1.setInitialValue(v2) del (v1, v2)
def test_set_initial_value(self): from libcellml import Variable # void setInitialValue(const std::string &initialValue) v = Variable() v.setInitialValue('test1') self.assertEqual("test1", v.initialValue()) # void setInitialValue(double initialValue) v = Variable() v.setInitialValue(3.0) self.assertEqual("3", v.initialValue()) v.removeInitialValue() self.assertEqual("", v.initialValue()) # void setInitialValue(const VariablePtr &variable) v1 = Variable() v2 = Variable() v1.setInitialValue(v2) self.assertEqual("", v1.initialValue())
sodium_channel.addVariable(t) h = Variable() h.setName("h") h.setUnits("dimensionless") sodium_channel.addVariable(h) m = Variable() m.setName("m") m.setUnits("dimensionless") sodium_channel.addVariable(m) g_Na = Variable() g_Na.setName("g_Na") g_Na.setUnits("mS_per_cm2") g_Na.setInitialValue(120) sodium_channel.addVariable(g_Na) E_Na = Variable() E_Na.setName("E_Na") E_Na.setUnits("mV") sodium_channel.addVariable(E_Na) i_Na = Variable() i_Na.setName("i_Na") i_Na.setUnits("microA_per_cm2") sodium_channel.addVariable(i_Na) Nao = Variable() Nao.setName("Nao") Nao.setUnits("mM")
<ci>x</ci>\ </apply>\ <cn cellml:units="league">2.0</cn>\ </apply>\ </apply>' component.setMath(math_header) component.appendMath(equation2) component.appendMath(math_footer) # 2.e Create and define the constant "a" to have a value of -1. Check that there # are no more validation errors. a = Variable() a.setName("a") a.setUnits("dimensionless") a.setInitialValue(-1.0) component.addVariable(a) print("-----------------------------------------------------") print(" Printing the validation errors after Step 2 ") print("-----------------------------------------------------") validator.validateModel(model) print_errors_to_terminal(validator) # --------------------------------------------------------------------------- # STEP 3: Output the model for solving # # 3.a Create a Generator instance and use it to process the model. Output # any errors to the terminal using the utility function printErrorsToTerminal # called with your generator as argument.
# - we need to specify the connections between variables and # - we need to permit external connections on the variables. # 6.c # Create a component which will store the hard-coded values for initialisation. # Name it 'gateParameters', and add it to the top-level gate component as a sibling # of the gateEquations component. gateParameters = Component('gateParameters') gate.addComponent(gateParameters) # 6.d # Create appropriate variables in this component, and set their units. # Use the setInitialValue function to initialise them. X = Variable('X') X.setUnits('dimensionless') X.setInitialValue(0) gateParameters.addVariable(X) alpha = Variable('alpha') alpha.setUnits(per_ms) alpha.setInitialValue(0.1) gateParameters.addVariable(alpha) beta = Variable('beta') beta.setUnits(per_ms) beta.setInitialValue(0.5) gateParameters.addVariable(beta) # 6.e # Specify a variable equivalence between the gateEquations variables and the parameter variables. # Validate the model again, expecting errors related to the variable interface types.
print("\n-----------------------------------------------") print(" STEP 5: Create the environment component") print("-----------------------------------------------") print_encapsulation_structure_to_terminal(model) # 5.a Creating the environment component and adding it to the model environment = Component() environment.setName("environment") model.addComponent(environment) # 5.b Add variables to the environment component. if True: V = Variable() V.setName("V") V.setInitialValue(-85) V.setUnits("mV") environment.addVariable(V) t = Variable() t.setName("t") t.setUnits("ms") environment.addVariable(t) # 5.c Add the new component to the model and validate validator.validateModel(model) print_errors_to_terminal(validator) print("\n-----------------------------------------------") print(" STEP 6: Connect the equivalent variables") print("-----------------------------------------------")
# 4.a # Create an Analyser instance and pass it the model using the # analyseModel function. analyser = Analyser() analyser.analyseModel(model) # 4.b # Check for errors found in the analyser. You should expect 6 errors, # related to variables whose values are not computed or initialised. print_issues(analyser) # 4.c # Add initial conditions to all variables except the base variable, time # and the constant c which will be computed. Reprocess the model. a.setInitialValue(-0.8) b.setInitialValue(0.3) d.setInitialValue(-0.6) sharks.setInitialValue(1.0) fish.setInitialValue(2.0) # 4.d # Reprocess the model and check that the analyser is now free of errors. analyser.analyseModel(model) print_issues(analyser) # end 4 print("-------------------------------------------------------------") print(" Step 5: Generate code and output ") print("-------------------------------------------------------------")
print("-----------------------------------------------") print(" STEP 3: Define the variables and their units ") print("-----------------------------------------------") # 3.a,b Declaring the variables, their names, units, and initial conditions # Note that the names given to variables must be the same as that used # within the <ci> blocks in the MathML string we created in step 2.a. t = Variable() t.setName("t") t.setUnits("millisecond") V = Variable() V.setName("V") V.setUnits("millivolt") V.setInitialValue(0.0) alpha_n = Variable() alpha_n.setName("alpha_n") alpha_n.setUnits("per_millisecond") alpha_n.setInitialValue(1.0) beta_n = Variable() beta_n.setName("beta_n") beta_n.setUnits("per_millisecond") beta_n.setInitialValue(2.0) n = Variable() n.setName("n") n.setUnits("dimensionless") n.setInitialValue(1.0)