Пример #1
0
    def test_encapsulation(self):
        from libcellml import Issue, Model

        e = Issue()
        self.assertIsNone(e.model())
        name = 'moodle'
        m = Model()
        m.setName(name)
        e.setEncapsulation(m)
        self.assertIsInstance(e.encapsulation(), Model)
        self.assertEqual(e.encapsulation().name(), name)
Пример #2
0
    def test_model(self):
        from libcellml import ImportSource, Model

        model = Model()
        model.setName('bert')
        x = ImportSource()
        self.assertIsNone(x.model())
        x.setModel(model)
        self.assertEqual(x.model().name(), model.name())
        x.setModel(None)
        self.assertIsNone(x.model())
Пример #3
0
    def test_get_model(self):
        from libcellml import ImportSource, Model

        # libcellml::ModelPtr getModel() const;
        model = Model()
        model.setName('bert')
        x = ImportSource()
        self.assertIsNone(x.getModel())
        x.setModel(model)
        self.assertEqual(x.getModel().getName(), model.getName())
        x.setModel(None)
        self.assertIsNone(x.getModel())
Пример #4
0
    def test_model(self):
        from libcellml import Issue, Model

        # ModelPtr model()
        e = Issue()
        self.assertIsNone(e.model())
        name = 'moodle'
        m = Model()
        m.setName(name)
        e.setModel(m)
        self.assertIsInstance(e.model(), Model)
        self.assertEqual(e.model().name(), name)
Пример #5
0
    def test_get_model(self):
        from libcellml import Error, Model

        # ModelPtr getModel()
        e = Error()
        self.assertIsNone(e.getModel())
        name = 'moodle'
        m = Model()
        m.setName(name)
        e.setModel(m)
        self.assertIsInstance(e.getModel(), Model)
        self.assertEqual(e.getModel().getName(), name)
Пример #6
0
        - the concept of component hierarchy and encapsulation (Tutorial 5)
        - the use of the API to create all of the entities in a model (Tutorial 3)
        - the content MathML2 markup for mathematical equations (Tutorial 4)
        - serialisation and printing of a model to a CellML file (Tutorial 1)

"""

from libcellml import Component, Model, Printer, Units, Validator, Variable

from utilities.tutorial_utilities import print_errors_to_terminal

if __name__ == "__main__":
    #  0 Setup stuff that is used throughout
    validator = Validator()
    model = Model()
    model.setName("Tutorial7_SodiumChannelModel")

    math_header = '<math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:cellml="http://www.cellml.org/cellml/2.0#">'
    math_footer = '</math>'

    print("-----------------------------------------------")
    print("  STEP 1: Creating the sodium channel")
    print("-----------------------------------------------")

    #  1.a Create the component instance, name it, and add to the model
    sodium_channel = Component()
    sodium_channel.setName("sodiumChannel")
    model.addComponent(sodium_channel)

    #  1.b Add the MathML representing the governing equations
    if True:
from libcellml import Component, Generator, GeneratorProfile, Model, Units, Validator, Variable

from utilities.tutorial_utilities import print_errors_to_terminal, print_model_to_terminal

if __name__ == "__main__":
    print("-----------------------------------------------------")
    print("     TUTORIAL 3: CREATE A MODEL USING THE API        ")
    print("-----------------------------------------------------")

    # ---------------------------------------------------------------------------
    #   STEP 1: Create the model instance
    #
    #   1.a   Allocate the ModelPtr
    model = Model()
    model.setName("Tutorial3_model")

    #   1.b   Create a component to use as an integrator, set its attributes and
    #        add it to the model
    component = Component()
    component.setName("component")
    model.addComponent(component)

    #   Checking that it worked
    print_model_to_terminal(model)

    #   1.c,d Create the MathML2 string representing the governing equation.  The
    #        header and footer are below already.
    math_header = '<math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:cellml="http://www.cellml.org/cellml/2.0#">'
    math_footer = '</math>'
    #  Setup useful things.
    math_header = '<math xmlns="http://www.w3.org/1998/Math/MathML" xmlns:cellml="http://www.cellml.org/cellml/2.0#">\n'
    math_footer = '</math>'

    print('----------------------------------------------------------')
    print('   STEP 1: Setup the model                                ')
    print('----------------------------------------------------------')

    #  1.a
    #      The first step is to create a Model item which will later contain the component and
    #      the units it needs.
    model = Model()

    #  1.b
    #      Each CellML element must have a name, which is set using the setName() function.
    model.setName('GateModel')

    #  1.c
    #      We'll create a wrapper component whose only job is to encapsulate the other components.
    #      This makes is a lot easier for this model to be reused, as the connections between
    #      components internal to this one won't need to be re-established.
    #      Note that the constructor for all named CellML entities is overloaded, so
    #      you can pass it the name string at the time of creation.
    #      Create a component named 'gate'.
    gate = Component('gate')

    #  1.d Finally we need to add the component to the model.  This sets it at the top-level of
    #      the components' encapsulation hierarchy.  All other components need to be added
    #      to this component, rather than the model.
    #      Add the component to the model using the Model::addComponent() function.
    model.addComponent(gate)
Пример #9
0
    This tutorial explores the ability of libCellML to generate files representing 
    the model which can be solved in Python or C.  By the time you have worked 
    through Tutorial 6 you will be able to:
        - use the Generator functionality to create models in Python or C format
        - use the simple solver provided to run the created models.
    
    Tutorial 6 assumes that you are already comfortable with:
        - file manipulation and summarising using the utility functions
      
"""
from libcellml import Model, Parser, Validator

if __name__ == "__main__":
    #  0    Create a new model instance representing the combined model and name it.
    model = Model()
    model.setName("Tutorial8_HHModel")
    validator = Validator()
    parser = Parser()

    print("-----------------------------------------------")
    print("    STEP 1: Read the membrane component")
    print("-----------------------------------------------")

    #  1.a  Read the model provided for you in the "Tutorial8_MembraneModel.cellml"
    #       file in the resources folder.

    #  1.b  Create a temporary model for the membrane

    #  1.b  Extract the membrane component from the parsed model and add it
    #       to the combined model.  Note that the membrane component's parent
    #       must be cleared before adding it to the model.