Exemplo n.º 1
0
def test5():
    sim = bfdtd.BFDTDobject()
    RCD = bfdtd.RCD.RCD_HexagonalLattice()
    RCD.setUnitCellType(2)
    sim.appendGeometryObject(RCD)

    RCD.setOuterRadius(0.1)
    RCD.setRefractiveIndex(2)
    RCD.createRectangularArraySymmetrical(1, 1, 1)
    sim.writeGeoFile(tempfile.gettempdir() + os.sep + 'RCD111_1x1x1.geo')

    RCD.clearGeoList()
    RCD.setOuterRadius(0.05)
    RCD.setRefractiveIndex(3)
    RCD.createRectangularArraySymmetrical(3, 3, 3)

    sim.writeGeoFile(tempfile.gettempdir() + os.sep + 'RCD111_3x3x3.geo')

    (u, v, w) = RCD.getLatticeVectors()
    U = bfdtd.Excitation()
    U.setExtension([0, 0, 0], u)
    V = bfdtd.Excitation()
    V.setExtension([0, 0, 0], v)
    W = bfdtd.Excitation()
    W.setExtension([0, 0, 0], w)

    sim.appendExcitation(U)
    sim.appendExcitation(V)
    sim.appendExcitation(W)

    sim.writeInpFile(tempfile.gettempdir() + os.sep + 'RCD111_E.inp')
    return
Exemplo n.º 2
0
def test1():
    # effect of dipole length
    sim = bfdtd.BFDTDobject()

    S = 3
    N = 30
    sim.setSizeAndResolution([S, S, S], [N, N, N])
    c = sim.getCentro()

    E = sim.appendExcitation(bfdtd.Excitation())
    E.setEx()
    E.setLocation(c)

    dt = sim.getTimeStep()
    T = 10 * dt
    f0 = 1 / T
    Q = 100
    df = f0 / Q

    #E.setTimeOffset(100*T)
    #E.setFrequency(10/T)
    #E.setTimeConstant(20*T)
    #E.setFrequency(10/E.getTimeConstant())
    #E.setFrequency(f0)
    #E.setFrequencyRange(f0-df, f0+df)
    print(E.setFrequencyRange(5e8, 5.5e8))

    E.setTimeOffset(20 * E.getTimeConstant())
    E.setAmplitude(1)

    p = sim.appendProbe(bfdtd.Probe())
    p.setLocation(c)
    p.setStep(1)

    print(T)
    print(1 / T)
    print(100 * T)
    sim.setTimeStep((1 / E.getFrequency()) / 100)
    #sim.setSimulationTime(1e-7)
    sim.setSimulationTime(E.getTimeOffset() + 20 * E.getTimeConstant())
    #sim.setIterations(1)

    for L in linspace(0, 1, 10):
        outdir = 'LX_{:.3f}'.format(L)
        print('outdir =', outdir)
        E.setSize([L, 0, 0])
        sim.runSimulation(outdir)

        outdir = 'LY_{:.3f}'.format(L)
        print('outdir =', outdir)
        E.setSize([0, L, 0])
        sim.runSimulation(outdir)

        outdir = 'LZ_{:.3f}'.format(L)
        print('outdir =', outdir)
        E.setSize([0, 0, L])
        sim.runSimulation(outdir)

    return
Exemplo n.º 3
0
def test0():
    # create files
    sim = bfdtd.BFDTDobject()
    S = 3
    N = 30
    sim.setSizeAndResolution([S, S, S], [N, N, N])
    c = sim.getCentro()

    #sim.setBoundaryConditionsToPML()

    E = sim.appendExcitation(bfdtd.Excitation())
    #E.setExtension(c-array([0.25,0,0]),c+array([0.25,0,0]))
    E.setExtension(c, c)
    E.setEx()

    dt = sim.getTimeStep()
    T = 10 * dt

    #E.setTimeOffset(100*T)
    #E.setFrequency(10/T)
    #E.setTimeConstant(20*T)
    #E.setFrequency(10/E.getTimeConstant())
    f0 = 1 / T
    Q = 100
    df = f0 / Q
    #E.setFrequency(f0)
    #E.setFrequencyRange(f0-df, f0+df)
    print(E.setFrequencyRange(5e8, 5.5e8))

    E.setTimeOffset(20 * E.getTimeConstant())
    E.setAmplitude(1)

    p = sim.appendProbe(bfdtd.Probe())
    p.setPosition(c)
    p.setStep(1)

    print(T)
    print(1 / T)
    print(100 * T)
    sim.setTimeStep((1 / E.getFrequency()) / 100)
    #sim.setSimulationTime(1e-7)
    sim.setSimulationTime(E.getTimeOffset() + 20 * E.getTimeConstant())

    print(sim.getIterations())
    print(E.getFrequencyRange())
    print('A={}; tau={}; w={}; f={}; fmin={}; fmax={};'.format(
        E.getAmplitude(), E.getTimeOffset(), E.getTimeConstant(),
        E.getFrequency(), *E.getFrequencyRange()))

    # run simulation
    sim.setExecutable('fdtd64_2013')
    sim.runSimulation('.')
Exemplo n.º 4
0
def test_checkPeriodvsTimeConstant():
    print('=== test_checkPeriodvsTimeConstant ===')
    E = bfdtd.Excitation()
    E.setTimeConstant(1 - 1e-9)
    E.setPeriod(1)
    E.checkPeriodvsTimeConstant(raise_exception=True)
    E.setTimeConstant(1)
    E.setPeriod(1)
    E.checkPeriodvsTimeConstant(raise_exception=True)
    E.setTimeConstant(1 + 1e-9)
    E.setPeriod(1)
    E.checkPeriodvsTimeConstant(raise_exception=True)
    E.setTimeConstant(1 - 2e-9)
    E.setPeriod(1)
    E.checkPeriodvsTimeConstant(raise_exception=True)
    return
Exemplo n.º 5
0
def test2():
    sim = bfdtd.BFDTDobject()
    S = 1
    N = 30
    sim.setSizeAndResolution([S, S, S], [N, N, N])

    c = sim.getCentro()

    E = sim.appendExcitation(bfdtd.Excitation())
    E.setEx()
    E.setLocation(c)
    E.setSize([0, 0, 0])

    dt_max = sim.getTimeStepMax()
    T_max = 10 * dt_max
    f_min = 1 / T_max
    Q = 100
    #df = f0_min/Q
    f_max = ((Q + 1 / 2) / (Q - 1 / 2)) * f_min

    print(E.setFrequencyRange(f_min, f_max))

    E.setTimeOffset(1 * E.getTimeConstant())
    E.setAmplitude(1)

    p = sim.appendProbe(bfdtd.Probe())
    p.setLocation(c)
    p.setStep(1)

    sim.setTimeStep((1 / E.getFrequency()) / 100)
    #sim.setSimulationTime(E.getTimeOffset()+10*E.getTimeConstant())

    sim.setIterations(ceil(E.getTimeOffset() / sim.getTimeStep()) + 99)

    Tbox = sim.appendSnapshot(bfdtd.TimeSnapshotBoxFull())
    Tbox.setFirst(sim.getIterations() - 99)
    Tbox.setRepetition(1)

    print(E.getTimeOffset() / sim.getTimeStep())
    print(sim.getIterations())

    sim.runSimulation('/tmp/dipole-test2', verbosity=2)
    return
Exemplo n.º 6
0
def test_setFrequencyRange():
    E = bfdtd.Excitation()
    fmin = 157414649.10606748
    fmax = 202390263.1363725
    E.setFrequencyRange(fmin, fmax)
    fmin = 157414649
    fmax = 202390263.1363725
    E.setFrequencyRange(fmin, fmax, autofix=True)
    fmin = 157414649.10606748
    fmax = 202390263.2
    E.setFrequencyRange(fmin, fmax, autofix=True)
    for i in range(-9, 10):
        f0 = 1.23456789 * (10**i)
        print('{:.3e}'.format(f0))
        E.setFrequencyRange(7 / 8 * f0, 9 / 8 * f0)
    for i in range(-9, 10):
        f0 = 1.23456789 * (10**i)
        print('{:.3e}'.format(f0))
        E.setFrequencyRange(7 / 8 * f0, 9.1 / 8 * f0, autofix=True)
    for i in range(-9, 10):
        f0 = 1.23456789 * (10**i)
        print('{:.3e}'.format(f0))
        E.setFrequencyRange(6.9 / 8 * f0, 9 / 8 * f0, autofix=True)
    return
Exemplo n.º 7
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('DSTDIR', default=tempfile.gettempdir(), nargs='?')
    args = parser.parse_args()
    print(args.DSTDIR)

    pillar = bfdtd.BFDTDobject()

    # constants
    n_air = 1
    n_diamond = 2.4
    Lambda_mum = 0.637
    delta = Lambda_mum / (10 * n_diamond)
    freq = constants.get_c0() / Lambda_mum
    k = 1
    radius = k * Lambda_mum / (4 * n_diamond)
    Nbottom = 30
    Ntop = 30
    h_air = Lambda_mum / (4 * n_air)
    h_diamond = Lambda_mum / (4 * n_diamond)
    h_cavity = Lambda_mum / (n_diamond)
    height = Nbottom * (h_air + h_diamond) + h_cavity + Ntop * (h_air +
                                                                h_diamond)
    buffer = 0.25
    FullBox_upper = [
        height + 2 * buffer, 2 * (radius + buffer), 2 * (radius + buffer)
    ]
    P_centre = [
        buffer + Nbottom * (h_air + h_diamond) + 0.5 * h_cavity,
        0.5 * FullBox_upper[1], 0.5 * FullBox_upper[2]
    ]

    # define flag
    pillar.flag.iterations = 100000

    # define boundary conditions
    pillar.boundaries.Xpos_bc = 2
    pillar.boundaries.Ypos_bc = 1  #2
    pillar.boundaries.Zpos_bc = 2

    # define box
    pillar.box.lower = [0, 0, 0]
    if pillar.boundaries.Ypos_bc == 2:
        pillar.box.upper = FullBox_upper
    else:
        pillar.box.upper = [
            FullBox_upper[0], 0.5 * FullBox_upper[1], FullBox_upper[2]
        ]

    # define geometry
    block = bfdtd.Block()
    block.setLowerAbsolute([
        P_centre[0] - 0.5 * height, P_centre[1] - radius, P_centre[2] - radius
    ])
    block.setUpperAbsolute([
        P_centre[0] + 0.5 * height, P_centre[1] + radius, P_centre[2] + radius
    ])
    block.setRefractiveIndex(n_diamond)
    pillar.setGeometryObjects([block])

    # define excitation
    excitation = bfdtd.Excitation()
    P1 = [P_centre[0], P_centre[1] - 1 * delta, P_centre[2]]
    P2 = P_centre
    excitation.setExtension(P1, P2)
    excitation.setFrequency(freq)
    excitation.setEy()
    pillar.appendExcitation(excitation)

    # define probe
    if pillar.boundaries.Ypos_bc == 2:
        probe = bfdtd.Probe(
            position=[buffer + height + delta, P_centre[1], P_centre[2]])
    else:
        probe = bfdtd.Probe(position=[
            buffer + height + delta, P_centre[1] - delta, P_centre[2]
        ])
    pillar.probe_list = [probe]

    # define frequency snapshots
    first = min(65400, pillar.flag.iterations)
    frequency_vector = [freq]
    F = pillar.addFrequencySnapshot('x', P_centre[0])
    F.first = first
    F.frequency_vector = frequency_vector
    if pillar.boundaries.Ypos_bc == 2:
        F = pillar.addFrequencySnapshot('y', P_centre[1])
        F.first = first
        F.frequency_vector = frequency_vector
    else:
        F = pillar.addFrequencySnapshot('y', P_centre[1] - delta)
        F.first = first
        F.frequency_vector = frequency_vector
    F = pillar.addFrequencySnapshot('z', P_centre[2])
    F.first = first
    F.frequency_vector = frequency_vector
    F = pillar.addBoxFrequencySnapshots()
    F.first = first
    F.frequency_vector = frequency_vector

    # define mesh
    thicknessVector_X = [
        block.getLowerAbsolute()[0] - pillar.box.lower[0],
        P_centre[0] - block.getLowerAbsolute()[0],
        block.getUpperAbsolute()[0] - P_centre[0], delta,
        pillar.box.upper[0] - (block.getUpperAbsolute()[0] + delta)
    ]
    if pillar.boundaries.Ypos_bc == 2:
        thicknessVector_Y = [
            block.getLowerAbsolute()[1] - pillar.box.lower[1],
            (P_centre[1] - delta) - block.getLowerAbsolute()[1], delta, delta,
            block.getUpperAbsolute()[1] - (P_centre[1] + delta),
            pillar.box.upper[1] - block.getUpperAbsolute()[1]
        ]
    else:
        thicknessVector_Y = [
            block.getLowerAbsolute()[1] - pillar.box.lower[1],
            (P_centre[1] - delta) - block.getLowerAbsolute()[1], delta
        ]
    thicknessVector_Z = LimitsToThickness([
        pillar.box.lower[2],
        block.getLowerAbsolute()[2], P_centre[2],
        block.getUpperAbsolute()[2], pillar.box.upper[2]
    ])
    max_delta_Vector_X = [delta] * len(thicknessVector_X)
    max_delta_Vector_Y = [delta] * len(thicknessVector_Y)
    max_delta_Vector_Z = [delta] * len(thicknessVector_Z)
    delta_X_vector, local_delta_X_vector = subGridMultiLayer(
        max_delta_Vector_X, thicknessVector_X)
    delta_Y_vector, local_delta_Y_vector = subGridMultiLayer(
        max_delta_Vector_Y, thicknessVector_Y)
    delta_Z_vector, local_delta_Z_vector = subGridMultiLayer(
        max_delta_Vector_Z, thicknessVector_Z)
    pillar.getMesh().setXmeshDelta(delta_X_vector)
    pillar.getMesh().setYmeshDelta(delta_Y_vector)
    pillar.getMesh().setZmeshDelta(delta_Z_vector)

    # write
    #DSTDIR = os.getenv('DATADIR')
    #DSTDIR = os.getenv('TESTDIR')
    #DSTDIR = os.getenv('DATADIR')+os.sep+'run_20110602'
    #DSTDIR = tempfile.mkdtemp()
    BASENAME = 'simple_pillar'
    pillar.writeAll(args.DSTDIR + os.sep + BASENAME, BASENAME)
    GEOshellscript_advanced(args.DSTDIR + os.sep + BASENAME + os.sep +
                            BASENAME + '.sh',
                            BASENAME,
                            getProbeColumnFromExcitation(excitation.E),
                            '$HOME/bin/fdtd',
                            '$JOBDIR',
                            WALLTIME=360)
    print(pillar.getNcells())
    print('DSTDIR = {}'.format(args.DSTDIR))
Exemplo n.º 8
0
def test0():
    parser = argparse.ArgumentParser()
    parser.add_argument('DSTDIR', default=tempfile.gettempdir(), nargs='?')
    parser.add_argument('-v',
                        '--verbose',
                        action="count",
                        dest="verbosity",
                        default=0,
                        help='verbosity level')
    parser.add_argument('-r', '--run', action="store_true")
    args = parser.parse_args()
    print(args)

    sim = bfdtd.BFDTDobject()
    sim.setVerbosity(args.verbosity)
    sim.setSizeAndResolution([1, 2, 3], [32, 32, 32], True)

    E = bfdtd.Excitation()
    E.setTimeConstant(1e-8)
    E.setPeriod(E.getTimeConstant() / 10)
    E.setStartTime(0)
    E.setLocation(sim.getCentro())
    E.setEx()
    #E.setSize([2*1/32,0,0])
    sim.appendExcitation(E)

    print(E)

    p = bfdtd.Probe()
    p.setStep(1)
    p.setLocation(E.getLocation())
    sim.appendProbe(p)

    n = 5
    bsize = [0.5, 2 * 0.5, 3 * 0.5]  # E.getLambda()/(2*n)

    b = bfdtd.Block()
    b.setLocation(sim.getCentro())
    b.setRefractiveIndex(n)
    b.setSize(bsize)
    sim.appendGeometryObject(b)

    energy_snapshot = bfdtd.EnergySnapshot()
    energy_snapshot.setFrequencies(E.getFrequency())

    f = bfdtd.SnapshotBoxXYZ()
    f.setBaseSnapshot(energy_snapshot)
    f.setIntersectionPoint(sim.getCentro())
    sim.appendSnapshot(f)

    #sim.appendSnapshot(bfdtd.EpsilonSnapshot())

    sim.setSimulationTime(2 * E.getEndTime())
    sim.setAutosetNFrequencySnapshots(10)

    if args.run:
        sim.runSimulation(args.DSTDIR)

    print('------------')
    E.printInfo()
    print('------------')
    sim.printInfo()
    print('------------')

    # default
    #------------
    #self.getStartTime() = 0.0
    #self.getPeakTime() = 2e-08
    #self.getEndTime() = 4e-08
    #self.getPeriod() = 3.3356409519815204e-09
    #------------
    #self.getNcells() = 32768
    #self.getIterations() = 739
    #self.getSimulationTime() = 4.002723944839243e-08
    #self.getTimeStep() = 5.416405879349449e-11 -> mus
    #------------

    return 0