Esempio n. 1
0
def set_initial(settings, initial_array):
    import expresso.pycas as pc
    from ..coordinate_ndarray import CoordinateNDArray

    if isinstance(initial_array, CoordinateNDArray):
        initial = pc.array("initial", initial_array.data)
    else:
        initial = pc.array("initial", initial_array)

    sb = settings.simulation_box

    if tuple(initial_array.axis) == (sb.x, ):
        settings.partial_differential_equation.u0 = initial(sb.xi)
    elif tuple(initial_array.axis) == (sb.x, sb.y):
        settings.partial_differential_equation.u0 = initial(sb.yi, sb.xi)
        sb.Ny = initial_array.shape[1]
        if isinstance(initial_array, CoordinateNDArray):
            sb.unlock('ymin')
            sb.unlock('ymax')
            sb.unlock('sy')
            sb.ymin = initial_array.bounds[1][0]
            sb.ymax = initial_array.bounds[1][1]
            sb.sy = sb.ymax - sb.ymin
            sb.lock('ymin', 'defined by initial array')
            sb.lock('ymax', 'defined by initial array')
            sb.lock('sy', 'defined by ymin and ymax')

    else:
        raise ValueError('initial array axis must be (x,) or (x,y)')

    sb.Nx = initial_array.shape[0]

    if isinstance(initial_array, CoordinateNDArray):
        sb.unlock('xmin')
        sb.unlock('xmax')
        sb.unlock('sx')
        sb.xmin = initial_array.bounds[0][0]
        sb.xmax = initial_array.bounds[0][1]
        sb.sx = sb.xmax - sb.xmin
        sb.lock('xmin', 'defined by initial array')
        sb.lock('xmax', 'defined by initial array')
        sb.lock('sx', 'defined by xmin and xmax')
Esempio n. 2
0
def set_initial(settings,initial_array):
    import expresso.pycas as pc
    from coordinate_ndarray import CoordinateNDArray

    if isinstance(initial_array,CoordinateNDArray):
        initial = pc.array("initial",initial_array.data)
    else:
        initial = pc.array("initial",initial_array)

    sb = settings.simulation_box

    if tuple(initial_array.axis) == (sb.x,):
        settings.partial_differential_equation.u0 = initial(sb.xi)
    elif tuple(initial_array.axis) == (sb.x,sb.y):
        settings.partial_differential_equation.u0 = initial(sb.yi,sb.xi)
        sb.Ny = initial_array.shape[1]
        if isinstance(initial_array,CoordinateNDArray):
            sb.unlock('ymin')
            sb.unlock('ymax')
            sb.unlock('sy')
            sb.ymin = initial_array.bounds[1][0]
            sb.ymax = initial_array.bounds[1][1]
            sb.sy = sb.ymax - sb.ymin
            sb.lock('ymin','defined by initial array')
            sb.lock('ymax','defined by initial array')
            sb.lock('sy','defined by ymin and ymax')

    else:
        raise ValueError('initial array axis must be (x,) or (x,y)')

    sb.Nx = initial_array.shape[0]

    if isinstance(initial_array,CoordinateNDArray):
        sb.unlock('xmin')
        sb.unlock('xmax')
        sb.unlock('sx')
        sb.xmin = initial_array.bounds[0][0]
        sb.xmax = initial_array.bounds[0][1]
        sb.sx = sb.xmax - sb.xmin
        sb.lock('xmin','defined by initial array')
        sb.lock('xmax','defined by initial array')
        sb.lock('sx','defined by xmin and xmax')
Esempio n. 3
0
    def init_material(settings):
        import units
        import numpy as np

        sb = settings.simulation_box
        r = settings.refractive_indices
        omega = settings.wave_equation.omega

        try:
            N = settings.get_as(sb.Nomega,int)
            omegamin,omegamax = (sb.omegamin,sb.omegamax)

            EminExpr = omegamin * units.hbar / units.eV
            EmaxExpr = omegamax * units.hbar / units.eV

            omega_dependent = True
        except:
            N = 3
            E = units.hbar * omega / units.eV
            EmaxExpr = E + 1
            EminExpr = E - 1
            omega_i = 1
            omega_dependent = False
        try:
            Emin = settings.get_as(EminExpr,float)
            Emax = settings.get_as(EmaxExpr,float)
        except:
            setattr(r,nname,None)
            return

        key = (N,Emin,Emax)
        if not hasattr(r,'_cache'):
            r.add_attribute('_cache', {})
        else:
            if nname in r._cache and r._cache[nname] == key:
                return
        if omega_dependent:
            narr = pc.array(nname,np.array(get_refraction_indices(name,Emin,Emax,N)))
            setattr(r,nname,narr(sb.omegai))
        else:
            setattr(r,nname,get_refraction_indices(name,Emax,Emin,3)[1])

        r._cache[nname] = key