示例#1
0
    def test_math(self):
        from libcellml import Component

        # appendMath(const std::string &math)
        x = Component()
        x.appendMath('More maths')
        x.appendMath(' please!')

        # std::string getMath()
        self.assertEqual(x.getMath(), 'More maths please!')
        x = Component()
        self.assertEqual(x.getMath(), '')

        # void setMath(const std::string &math)
        x.setMath('bonjour')
        self.assertEqual(x.getMath(), 'bonjour')
        x.setMath('hola')
        self.assertEqual(x.getMath(), 'hola')
        '  <apply><eq/>\n'\
        '    <ci>i_K</ci>\n'\
        '    <apply><times/>\n'\
        '       <apply><power/>\n'\
        '           <ci>n</ci>\n'\
        '           <cn cellml:units="dimensionless">4</cn>\n'\
        '       </apply>\n'\
        '       <ci>g_K</ci>\n'\
        '       <apply><minus/>\n'\
        '           <ci>V</ci>\n'\
        '           <ci>E_K</ci>\n'\
        '       </apply>\n'\
        '    </apply>\n'\
        '  </apply>\n'

    k_channel_equations.setMath(math_header)
    k_channel_equations.appendMath(equation_iK)
    k_channel_equations.appendMath(math_footer)
     
    #  2.c 
    #      Once the mathematics has been added to the component, and the component to the 
    #      model, we can make use of the diagnostic messages within the Validator class
    #      to tell us what else needs to be done.  
    #      Create a Validator instance, and pass it your model for processing using the 
    #      validateModel function.  
    validator = Validator()
    validator.validateModel(model)

    #  end 2.c

    #      Calling the validator does not return anything: we have to go looking for issues 
示例#3
0
        equation3 = \
            '<apply>\
                <eq/>\
                <ci>i_Na</ci>\
                <apply>\
                    <times/>\
                    <ci>Na_conductance</ci>\
                    <apply>\
                        <minus/>\
                        <ci>V</ci>\
                        <ci>E_Na</ci>\
                    </apply>\
                </apply>\
            </apply>'

        sodium_channel.setMath(math_header)
        sodium_channel.appendMath(equation1)
        sodium_channel.appendMath(equation2)
        sodium_channel.appendMath(equation3)
        sodium_channel.appendMath(math_footer)

    #  1.c Add the variables
    if True:
        V = Variable()
        V.setName("V")
        V.setUnits("mV")
        sodium_channel.addVariable(V)

        t = Variable()
        t.setName("t")
        t.setUnits("ms")
                        <bvar>\
                            <ci>t</ci>\
                        </bvar>\
                        <ci>x</ci>\
                    </apply>\
                    <apply><plus/>\
                        <apply><times/>\
                            <ci>a</ci>\
                            <ci>x</ci>\
                        </apply>\
                        <ci>b</ci>\
                    </apply>\
                </apply>"

    #   1.e   Include the MathML strings in the component
    component.setMath(math_header)
    component.appendMath(equation)
    component.appendMath(math_footer)

    #  1.f   Create a validator and use it to check the model so far
    validator = Validator()
    validator.validateModel(model)
    print_errors_to_terminal(validator)

    #  1.g   Create some variables and add them to the component
    time = Variable()
    time.setName("t")
    component.addVariable(time)

    distance = Variable()
    distance.setName("x")
        '    <apply><minus/>\n'\
        '      <apply><times/>\n'\
        '        <ci>alpha_X</ci>\n'\
        '        <apply><minus/>\n'\
        '          <cn cellml:units="dimensionless">1</cn>\n'\
        '          <ci>X</ci>\n'\
        '        </apply>\n'\
        '      </apply>\n'\
        '      <apply><times/>\n'\
        '        <ci>beta_X</ci>\n'\
        '        <ci>X</ci>\n'\
        '      </apply>\n'\
        '    </apply>\n'\
        '  </apply>\n'

    gateEquations.setMath(math_header)
    gateEquations.appendMath(equation)
    gateEquations.appendMath(math_footer)

    #  2.d
    #      Print the model to the terminal using the print_model helper function and
    #      check it is what you'd expect.  Include the second argument as True so that
    #      the maths is included.
    print_model(model, True)

    # end 2

    print('----------------------------------------------------------')
    print('   STEP 3: Validate the model                            ')
    print('----------------------------------------------------------')