Exemple #1
0
def main():
    """ This is the main function of the code it is the starting point of
    a simulation. """

    # Load input parameters from the input file and add the, in allcaps
    # to the global namespace.
    global EXTERNAL_FIELD_VECTOR, ELECTRODE
    parameters = load_input(sys.argv[1], param_descriptors)
    globals().update(dict((key.upper(), item)
                          for key, item in parameters.iteritems()))
    if RANDOM_SEED >= 0:
        seed(RANDOM_SEED)
    
    EXTERNAL_FIELD_VECTOR = array([0.0, 0.0, EXTERNAL_FIELD])
    ELECTRODE = init_electrode()
    
    # init a tree from scratch
    tr, r0, q0 = init_from_scratch(INITIAL_NODES)
    
    dt = TIME_STEP
    t = r_[0:END_TIME:dt]
    
    r, q = r0, q0

    dfile = DataFile(OUT_FILE, parameters=parameters)
    branched = False
    
    for i, it in enumerate(t):
        # with ContextTimer("plotting"):
        #     plot_projections(r, q)
        #     pylab.savefig('tree_%.3d.png' % i)
        # print 't = %g\ttree_%.3d.png' % (it, i)
        print "%d/%d  t = %g" % (i, len(t), it)
        branch_prob = BRANCHING_PROBABILITY

        if SINGLE_BRANCHING_TIME > 0:
            if it > SINGLE_BRANCHING_TIME:
                if not branched:
                    branch_prob = inf
                    branched = True

        if SINGLE_BRANCHING_Z != 0 and not branched:
            zterm = r[tr.terminals()[0], Z]
            if zterm < SINGLE_BRANCHING_Z:
                if not branched:
                    branch_prob = inf
                    branched = True

        r, q = adapt_step(tr, r, q, dt, p=branch_prob)

        with ContextTimer("saving %d" % i):
            phi = solve_phi(r, q)
            dfile.add_step(it, tr, r, q, phi,
                           error=error, error_dq=error_dq)
            
        if END_WITH_RECONNECTION and tr.reconnects(r):
            print "Finishing due to a reconnection."
            break
Exemple #2
0
def main():
    """ This is the main function of the code it is the starting point of
    a simulation. """

    # Load input parameters from the input file and add the, in allcaps
    # to the global namespace.
    global EXTERNAL_FIELD_VECTOR, ELECTRODE
    parameters = load_input(sys.argv[1], param_descriptors)
    globals().update(
        dict((key.upper(), item) for key, item in parameters.iteritems()))
    if RANDOM_SEED >= 0:
        seed(RANDOM_SEED)

    EXTERNAL_FIELD_VECTOR = array([0.0, 0.0, EXTERNAL_FIELD])
    ELECTRODE = init_electrode()

    # init a tree from scratch
    tr, r0, q0 = init_from_scratch(INITIAL_NODES)

    dt = TIME_STEP
    t = r_[0:END_TIME:dt]

    r, q = r0, q0

    dfile = DataFile(OUT_FILE, parameters=parameters)
    branched = False

    for i, it in enumerate(t):
        # with ContextTimer("plotting"):
        #     plot_projections(r, q)
        #     pylab.savefig('tree_%.3d.png' % i)
        # print 't = %g\ttree_%.3d.png' % (it, i)
        print "%d/%d  t = %g" % (i, len(t), it)
        branch_prob = BRANCHING_PROBABILITY

        if SINGLE_BRANCHING_TIME > 0:
            if it > SINGLE_BRANCHING_TIME:
                if not branched:
                    branch_prob = inf
                    branched = True

        if SINGLE_BRANCHING_Z != 0 and not branched:
            zterm = r[tr.terminals()[0], Z]
            if zterm < SINGLE_BRANCHING_Z:
                if not branched:
                    branch_prob = inf
                    branched = True

        r, q = adapt_step(tr, r, q, dt, p=branch_prob)

        with ContextTimer("saving %d" % i):
            phi = solve_phi(r, q)
            dfile.add_step(it, tr, r, q, phi, error=error, error_dq=error_dq)

        if END_WITH_RECONNECTION and tr.reconnects(r):
            print "Finishing due to a reconnection."
            break