Exemplo n.º 1
0
def pop(h, vars):
    h = pol(h)
    vars = list(vars)
    out = 0
    while vars:
        x = vars.pop(0)
        p = vars.pop(0)
        out += dop(x) * (-dop(p)(h)) + dop(p) * dop(x)(h)
    return out
Exemplo n.º 2
0
def pop(h,vars):
  h=pol(h)
  vars=list(vars)
  out=0
  while vars:
    x=vars.pop(0)
    p=vars.pop(0)
    out+=dop(x)*(-dop(p)(h))+dop(p)*dop(x)(h)
  return out
Exemplo n.º 3
0
def acosh(y):
  """Compute ArcCosh
    >>> from pol import *
    >>> x,y=mkpol('x,y')
    >>> acosh(cosh(1.4+x+y))
    1.4 + x + y
  """
  x0=pol(log(y+sqrt(y**2-1)))
  for i in range(y.order):
    x0=x0 + (y-cosh(x0))/sinh(x0)
  return x0
Exemplo n.º 4
0
def asinh(y):
  """Compute ArcSinh
    >>> from pol import *
    >>> x,y=mkpol('x,y')
    >>> asinh(sinh(.4+x+y))
    0.4 + x + y
  """
  x0=pol(log(y+sqrt(y**2+1)))
  for i in range(y.order):
    x0=x0 + (y-sinh(x0))/cosh(x0)
  return x0
Exemplo n.º 5
0
def acos(y):
  """Compute ArcCos
    >>> from pol import *
    >>> x,y=mkpol('x,y')
    >>> acos(cos(.4+x+y))
    0.4 + x + y
  """
  x0=pol(math.acos(y.zero()))
  for i in range(y.order):
    x0=x0 + -(y-cos(x0))/sin(x0)
  return x0
Exemplo n.º 6
0
def asin(y):
  """Compute ArcSin
    >>> from pol import *
    >>> x,y=mkpol('x,y')
    >>> asin(sin(.4+x+y))
    0.4 + x + y
  """
  x0=pol(math.asin(y.zero()))
  for i in range(y.order):
    x0=x0 + (y-sin(x0))/cos(x0)
  return x0
Exemplo n.º 7
0
 def _derpol(self,other):
   new=pol(order=min(self.order,other.order))
   new.vars=list(set(other.vars+self.vars))
   for i in self.coef:
     for j in other:
       c=self.coef[i]*other[j]
       expi=dict(zip(self.vars,i))
       expj=dict(zip(other.vars,j))
       newexp=tuple([-expi.get(k,0)+expj.get(k,0) for k in new.vars])
       for k in self.vars:
         c*=normder(expj.get(k,0), expi.get(k,0))
       new[newexp]=new.get(newexp,0.)+c
   return new.truncate().dropneg()
Exemplo n.º 8
0
 def _derpol(self, other):
     new = pol(order=min(self.order, other.order))
     new.vars = list(set(other.vars + self.vars))
     for i in self.coef:
         for j in other.coef:
             c = self.coef[i] * other.coef[j]
             expi = dict(zip(self.vars, i))
             expj = dict(zip(other.vars, j))
             newexp = tuple(
                 [-expi.get(k, 0) + expj.get(k, 0) for k in new.vars])
             for k in self.vars:
                 c *= normder(expj.get(k, 0), expi.get(k, 0))
             new.coef[newexp] = new.coef.get(newexp, 0.) + c
     return new.truncate().dropneg()
Exemplo n.º 9
0
def atan(y):
  """Compute ArcTan using Newton method
    x=f(y); y=g(x)
    x0=f(y0); x0=x0 +(y-g(x0))/g'(x)
    >>> from pol import *
    >>> p=pol('.4+x+y')
    >>> print tan(atan(p))
    0.4 + x + y
    >>> print atan(tan(p))
    0.4 + x + y
  """
  x0=pol(math.atan(y.zero()))
  for i in range(y.order):
    x0=x0 + (y-tan(x0))*cos(x0)**2
  return x0
Exemplo n.º 10
0
 def __init__(self,val=None,order=None,eps=1E-13,loc={},m='eval'):
   self.coef={}
   self.vars=[]
   self.order=1000
   self.eps=eps
   if val!=None:
     if isinstance(val,dop):
       self.coef.update(val.coef)
       self.vars=val.vars[:]
       self.order=val.order
       self.eps=val.eps
     elif isinstance(val,str):
       if m=='eval':
         c=compile(val,'eval','eval')
         l=dict( (i,dop(i,m='name')) for i in c.co_names)
         l.update(loc)
         dop.__init__(self,eval(c,{},l))
       elif m=='name':
         self.vars=[val]
         self.coef[(1,)]=pol(1.)
   if order is not None:
     self.order=order
Exemplo n.º 11
0
 def __init__(self, val=None, order=None, eps=1E-13, loc={}, m='eval'):
     self.coef = {}
     self.vars = []
     self.order = 1000
     self.eps = eps
     if val != None:
         if isinstance(val, dop):
             self.coef.update(val.coef)
             self.vars = val.vars[:]
             self.order = val.order
             self.eps = val.eps
         elif isinstance(val, str):
             if m == 'eval':
                 c = compile(val, 'eval', 'eval')
                 l = dict((i, dop(i, m='name')) for i in c.co_names)
                 l.update(loc)
                 dop.__init__(self, eval(c, {}, l))
             elif m == 'name':
                 self.vars = [val]
                 self.coef[(1, )] = pol(1.)
     if order is not None:
         self.order = order
Exemplo n.º 12
0
def main(args):
    """ parse command line arguments"""
    tstart = time.clock()
    if not args.log:
        logging.basicConfig(level=args.loglevel or logging.INFO)
    else:
        logging.basicConfig(filename='log', filemode='w', level=logging.DEBUG)
    logger = logging.getLogger(__name__)
    """ read plasma parameters """
    param = utils.read_param(args)
    """ iterate through wavenumber  """
    dk = (param['kend'][0] - param['kstart'][0]) / param['ksteps'][0]
    fzeta = np.empty(int(param['ksteps'][0]), dtype=complex)
    wave_k = np.empty(int(param['ksteps'][0]))
    zeta_guess = complex(param['omega_r'][0], param['omega_i'][0])

    # eigen value and polaization iEx/Ey*(omega_r/abs(omega_r))
    val = []
    pol = []

    for n in range(int(param['ksteps'][0])):
        logger.info('%d th iteration in %d ksteps \n', n, param['ksteps'][0])
        wave_k[n] = param['kstart'][0] + n * dk
        """ find dispersion relation root """
        data = (args, param, wave_k[n])
        try:
            # use parallel dsp if theta<0.1 degree
            if (abs(param['theta'][0]) < 1.):
                sol = root(disp.det_para,(zeta_guess.real,zeta_guess.imag), \
                    args=data,method='hybr',tol=param['sol_err'][0])
                fzeta[n] = complex(sol.x[0], sol.x[1])
            else:
                sol = root(disp.det,(zeta_guess.real,zeta_guess.imag), \
                    args=data,method='hybr',tol=param['sol_err'][0])
                fzeta[n] = complex(sol.x[0], sol.x[1])
            logger.info("solution: k*di=%1.2e , omega/Omega_ci=%1.2e+%1.2ei\n",
                        wave_k[n], fzeta[n].real, fzeta[n].imag)
            if (param['cal_pol'][0]):
                import pol as p
                val0, pol0 = p.pol(args, param, wave_k[n], fzeta[n])
                val.append(val0)
                pol.append(pol0)
            if (fzeta[n].imag < 0):
                param['exp'][0] = 0
        except ValueError:
            logger.info('ERROR in root finding: wave_k =%f', wave_k[n])
        """ extrapolate previous solutions for next guess """
        if (n > 3 and n < int(param['ksteps'][0]) - 1):
            zeta_guess = complex(interp(wave_k[n]+dk,wave_k[n-3:n],fzeta[n-3:n].real),\
           interp(wave_k[n]+dk,wave_k[n-3:n],fzeta[n-3:n].imag))
        else:
            zeta_guess = fzeta[n]
    """ save results to output file """
    param['wave_k'] = wave_k
    param['fzeta'] = fzeta
    if args.output:
        np.save(args.output + '.npy', param)
    else:
        np.save('output.npy', param)

    tend = time.clock()
    logger.info('\n Total time lapse: %1.2f\n', tend - tstart)
    return 0