Ejemplo n.º 1
0
    def VisitEqnSet(self, eqnset, modfilecontents,  build_parameters, **kwargs):
        self.assigment_statements = {}
        ASTActionerDefaultIgnoreMissing.VisitEqnSet(self,eqnset,modfilecontents=modfilecontents, build_parameters=build_parameters, **kwargs)


        # The order of writing out assignments is important. There are 3 phases,
        # 1. Initialisation
        # 2. Pre-State Solving
        # 3. Post-State Solving

        # At this stage, we assume that there are no assignments dependant on states depending on
        # further assignments. This can be resolved, but I have not done so here....


        # 1. Initialisation:
        # We perform all assignments in order:
        assignments_ordered = VisitorFindDirectSymbolDependance.get_assignment_dependancy_ordering( eqnset)
        for ass in assignments_ordered:
            modfilecontents.section_INITIAL.append( self.assigment_statements[ass] )

        # 2. Find which assignments are used by the states:

        required_assignments = []
        dependancies = VisitorFindDirectSymbolDependance()
        dependancies.VisitEqnSet(eqnset)

        for s in eqnset.timederivatives:
            ass_deps = [d for d in dependancies.dependancies[s] if not isinstance(d, StateVariable) ]
            required_assignments.extend( ass_deps)


        all_deps = []
        for i in required_assignments:
            a = VisitorFindDirectSymbolDependance().get_assignment_dependancy_ordering_recursive(eqnset=eqnset, ass=i)
            all_deps.extend(a)
            all_deps.append(i)

        for ass in unique(all_deps):
            unexpected_deps = [d for d in dependancies.dependancies[ass] if not isinstance(d, (AssignedVariable, SymbolicConstant, SuppliedValue, Parameter)) ]
            print unexpected_deps
            print 'Unexpected:', [s.symbol for s in unexpected_deps]

            assert not unexpected_deps, "Resolution of dependances in Neurounits can't support assignments need by timeerivatives which are dependanct on state variables (%s)"%(unexpected_deps)
            modfilecontents.section_BREAKPOINT_pre_solve.append( self.assigment_statements[ass] )



        # 3. Find the dependancies of the current variables:
        all_deps = []
        for c in build_parameters.currents:
            a = VisitorFindDirectSymbolDependance().get_assignment_dependancy_ordering_recursive(eqnset=eqnset, ass=c)
            all_deps.extend(a)
            all_deps.append(c)

        for ass in unique(all_deps):
            modfilecontents.section_BREAKPOINT_post_solve.append(self.assigment_statements[ass])
Ejemplo n.º 2
0
 def __init__(self, ):
     ASTActionerDefaultIgnoreMissing.__init__(self,action_predicates=[ SingleVisitPredicate() ])
Ejemplo n.º 3
0
 def __init__(self, ):
     ASTActionerDefaultIgnoreMissing.__init__(
         self, action_predicates=[SingleVisitPredicate()])