cellml / libcellml

Repository for libCellML development.
https://libcellml.org
Apache License 2.0
16 stars 21 forks source link

Analyser: revise the way we interpret a CellML model #949

Open agarny opened 3 years ago

agarny commented 3 years ago

THINKING IN PROGRESS...


FOREACH component DO
    FOREACH equation DO
        COUNT number_of_variables IN equation

        IF number_of_variables EQUALS 0 THEN
            GENERATE ERROR MESSAGE
        ELSE IF number_of_variables EQUALS 1 THEN
            IF variable IS IN list_of_variables THEN
                SYSTEM IS OVERCONSTRAINED
            ELSE
                variable IS A CONSTANT

                ADD variable TO list_of_variables

                IF (equation IS OF FORM "x = ..." WITH RHS NOT INVOLVING x)
                    OR (equation IS OF FORM "... = x" WITH LHS NOT INVOLVING x) THEN
                    equation FOR x CAN BE SOLVED
                ELSE
                    equation FOR x CANNOT BE SOLVED DIRECTLY, BUT CAN BE SOLVED USING A SOLVER LIKE KINSOL
                    # resid = LHS-RHS
                    # IF variable HAS INITIAL VALUE THEN USE IT WITH KINSOL
                ENDIF
            ENDIF
        ELSE
            unknown_variables = []

            FOREACH variable IN equation DO
                IF variable IS NOT IN list_of_variables THEN
                    unknown_variables += variable
                ENDIF
            ENDFOREACH

            IF LEN(unknown_variables) EQUALS 1 THEN
                list_of_variables += unknown_variables[0]

                equation CAN BE SOLVED # TO BE FINISHED
            ELSE
                # n = LEN(unknown_variables)
                # Check (most likely outside this loop) other equations to see
                # whether we have n equations with n unknowns (kind of), e.g.
                #     x+y=3
                #     x*z = 5
                #     y+z = 7
            ENDIF

            # x + y = sin(z)
            # y = 3+5
            # z = 7
        ENDIF
    ENDFOREACH
ENDFOREACH



x: 3 y: 5 z: 7 x+y = z

residual = x+y-z


x = 3 y = 5 z: 7 x+y = z


x = 3 y: 5 z: 7 x+y = z

residual = x+y-z


x = 3 y: not intiialised z: not initialised x+y = z

underconstrained


The analyser should analyse the model without taking into account whether a variable has an initial value. The initial value of a variable should only be taken into account once we have analysed all the equations, in case having an initial value may give us a sensible system.