Example #1
0
def start(dt=dt):
    analitic = Analitic(r=1,
                        v=-gamma_div_2m,
                        r_function=r_analitic_function,
                        v_function=v_analitic_function,
                        a_function=a_function)
    verlet = Verlet(r=1, v=-gamma_div_2m, a_function=a_function, dt=dt)
    beeman = Beeman(r=1, v=-gamma_div_2m, a_function=a_function, dt=dt)
    gear = Gear5(r=1, v=-gamma_div_2m, a_function=a_function, dt=dt, k=k, m=m)
    strr = ""
    for index in xrange(1, int(tf / dt) + 1):
        t = index * dt
        #import ipdb; ipdb.set_trace()
        analitic.loop(t)
        verlet.loop()
        beeman.loop()
        gear.loop()
        #strr+= (str(verlet[R])) + '\t' + str(analitic[R]) + '\t' + (str(verlet[V])) + '\t' + str(analitic[V]) + '\t' + (str(verlet[A])) + '\t' + str(analitic[A]) + '\n'

    plot(analitic.r_history, verlet.r_history, beeman.r_history,
         gear.r_history)

    with open('output_particle/data.txt', 'w') as outfile:
        methods = [verlet, beeman, gear]
        outfile.write(
            reduce(
                lambda accum, elem: accum + str(elem.__class__) + str(
                    elem.get_error(analitic.r_history)) + " ,", methods, ""))
Example #2
0
 def __init__(self,
              dim=3,
              n_a=3,
              st=0.01,
              sts=100,
              algorithm='LeapFrog',
              force_fields=['SoftWall', 'MinBarrierMin'],
              parameters=[[1, 10], [5, 10, 3, 0.02]]):
     self.n_atoms = int(n_a)
     self.atoms = [Atom(dim, st) for i in range(self.n_atoms)]
     self.time_step = float(st)
     self.steps = int(sts)
     if algorithm == 'Verlet':
         self.algorithm = Verlet()
     elif algorithm == 'VelocityVerlet':
         self.algorithm = VelocityVerlet()
     elif algorithm == 'LeapFrog':
         self.algorithm = LeapFrog()
     else:
         sys.exit('Wrong algorithm name')
     self.force_fields = []
     for f in range(len(force_fields)):
         if force_fields[f] == 'SoftWall':
             self.force_fields.append(SoftWall(parameters[f]))
             for a in self.atoms:
                 a.Recalculate(st, True)
         elif force_fields[f] == 'MinBarrierMin':
             self.force_fields.append(MinBarrierMin(parameters[f]))
             for a in self.atoms:
                 a.Recalculate(st, True)
         elif force_fields[f] == 'LenardJones':
             self.force_fields.append(LenardJones(parameters[f]))
             for a in self.atoms:
                 for i in range(a.coords_t.dim):
                     if a.coords_t[i] >= 0:
                         a.coords_t[i] += a.number
                     else:
                         a.coords_t[i] -= a.number
         else:
             sys.exit('Wrong potential name')
Example #3
0
 def set_positions(self):
     model = LennartJonesModel('H',1,2)
     algo = Verlet(model, self)
     v = algo.run(10)
     for atom in self:
         atom.pos =  atom.pos + v