Exemple #1
0
    def test_EpsilonBox(self):
        with tempfile.TemporaryDirectory(
                prefix='testSnapshotBoxVolume-') as outdir:

            #outdir = '/tmp/testSnapshotBoxVolume'

            sim = bfdtd.BFDTDobject()
            sim.setSizeAndResolution([10, 11, 12], [41, 42, 43])

            b = bfdtd.Block()
            b.setSize([1, 2, 3])
            b.setLocation([4, 5, 6])
            sim.appendGeometryObject(b)

            mybox = bfdtd.EpsilonBox()
            mybox.setPlaneOrientationY()
            mybox.setExtension(*b.getExtension())
            mybox.setFullExtensionOff()

            sim.appendSnapshot(mybox)

            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_epsbox.inp'))

        return
Exemple #2
0
    def test_ModeVolumeBox(self):
        with tempfile.TemporaryDirectory(
                prefix='testSnapshotBoxVolume-') as outdir:
            #outdir = '/tmp/testSnapshotBoxVolume'

            sim = bfdtd.BFDTDobject()
            sim.setSizeAndResolution([10, 11, 12], [41, 42, 43])

            b = bfdtd.Block()
            b.setSize([1, 2, 3])
            b.setLocation([4, 5, 6])
            sim.appendGeometryObject(b)

            MV = bfdtd.ModeVolumeBox()

            MV.setFullExtensionOff()

            MV.setPlaneOrientationZ()
            MV.setExtension(*b.getExtension())

            MV.epsilon_repetition = 456

            MV.name = 'myname'
            MV.layer = 'mylayer'
            MV.group = 'mygroup'

            MV.first = 11
            MV.repetition = 1337
            MV.starting_sample = 789

            MV.frequency_vector = [22, 33]

            MV.interpolate = 45
            MV.mod_only = 46
            MV.mod_all = 47
            MV.real_dft = 123

            MV.useForMeshing = False

            MV.E = [1, 2, 3]
            MV.H = [4, 5, 6]
            MV.J = [7, 8, 9]

            sim.appendSnapshot(MV)

            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_MV.inp'))

        return
Exemple #3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('DSTDIR', default=tempfile.gettempdir(), nargs='?')
    args = parser.parse_args()
    print(args.DSTDIR)

    pillar = BFDTDobject()

    # define box
    pillar.box.lower = [0, 0, 0]
    pillar.box.upper = [1, 1, 1]

    # define geometry
    #prism = Block()
    #prism.lower = [ 1.1,1.2,1.3 ]
    #prism.upper = [ 2.4,2.5,2.6 ]
    #prism.permittivity = 24
    #pillar.geometry_object_list.append(prism)

    #prism = Block()
    #prism.lower = [ 1.5,1.5,1.5 ]
    #prism.upper = [ 2.5,2.5,2.5 ]
    #prism.permittivity = 10
    #pillar.geometry_object_list.append(prism)

    #prism = Block()
    #prism.lower = [ 3.7,3.8,3.9 ]
    #prism.upper = [ 4.10,4.11,4.12 ]
    #prism.permittivity = 42
    #pillar.geometry_object_list.append(prism)

    meshing_parameters = MeshingParameters()
    #meshing_parameters.

    prism = bfdtd.Block()
    prism.lower = pillar.box.lower
    prism.upper = pillar.box.upper
    prism.permittivity = 1
    pillar.geometry_object_list.append(prism)

    # define mesh
    pillar.autoMeshGeometry(0.637 / 16.)

    # write
    #DSTDIR = os.getenv('TESTDIR')
    BASENAME = 'meshing_test'
    pillar.writeAll(args.DSTDIR + os.sep + BASENAME, BASENAME)
    print(pillar.getNcells())
Exemple #4
0
    def test_SnapshotBoxXYZ(self):
        with tempfile.TemporaryDirectory(
                prefix='testSnapshotBoxVolume-') as outdir:
            #outdir = '/tmp/testSnapshotBoxVolume'

            sim = bfdtd.BFDTDobject()
            sim.setSizeAndResolution([10, 11, 12], [41, 42, 43])

            b = bfdtd.Block()
            b.setSize([1, 2, 3])
            b.setLocation([4, 5, 6])
            sim.appendGeometryObject(b)

            tsnap = bfdtd.TimeSnapshot()
            tsnap.setExtension(*b.getExtension())
            esnap = bfdtd.EpsilonSnapshot()
            esnap.setExtension(*b.getExtension())
            mfp = bfdtd.ModeFilteredProbe()
            mfp.setExtension(*b.getExtension())
            fsnap = bfdtd.FrequencySnapshot()
            fsnap.setExtension(*b.getExtension())

            MV = bfdtd.SnapshotBoxXYZ()
            MV.setIntersectionPoint([3.75, 5.5, 7])

            sim.appendSnapshot(MV)

            sim.writeGeoFile(os.path.join(outdir, 'testSnapshotBoxVolume.geo'))

            MV.setBaseSnapshot(tsnap)
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_tsnap_xyz.inp'))

            MV.setBaseSnapshot(esnap)
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_esnap_xyz.inp'))

            MV.setBaseSnapshot(mfp)
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_mfp_xyz.inp'))

            MV.setBaseSnapshot(fsnap)
            fsnap.setFullExtensionOff()
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_fsnap_xyz.inp'))

        return
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('ctlfile', default='test.geo.ctl', nargs='?')
    parser.add_argument('geofile', default='test.geo', nargs='?')
    parser.add_argument('-v',
                        '--verbose',
                        action="count",
                        dest="verbosity",
                        default=0,
                        help='verbosity level')
    args = parser.parse_args()

    if args.verbosity > 0:
        print(args)

    sim = bfdtd.BFDTDobject()
    sim.setSizeAndResolution([1, 2, 4], [10, 10, 10], True)

    c = sim.appendGeometryObject(bfdtd.Cylinder())
    c.setLocation([1 / 2, 2 / 2, 1])
    c.setOuterRadius(0.25)
    c.setAxis([1, 1, 1])
    c.setHeight(1)
    c.setRelativePermittivity(2)

    s = sim.appendGeometryObject(bfdtd.Sphere())
    s.setLocation([1 / 2, 2 / 2, 2])
    s.setOuterRadius(0.25)
    s.setRelativePermittivity(3)

    b = sim.appendGeometryObject(bfdtd.Block())
    b.setLocation([1 / 2, 2 / 2, 3])
    b.setSize([1 / 8, 1 / 4, 1 / 2])
    b.setRelativePermittivity(4)

    sim.writeCtlFile(args.ctlfile)
    sim.writeGeoFile(args.geofile)

    return 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))
Exemple #7
0
    def getGWLandBFDTDobjects(self):
        GWL_obj = GWLobject()
        BFDTD_obj = BFDTDobject()

        layer_type_X = self.shiftInitialLayerType_X
        layer_type_Y = self.shiftInitialLayerType_Y

        if self.BottomToTop:
            layer_idx_list = range(self.Nlayers_Z)
        else:
            layer_idx_list = range(self.Nlayers_Z - 1, -1, -1)

        for layer_idx in layer_idx_list:
            direction = layer_idx % 2 + self.bottomLayerYPeriodic % 2

            # TODO: reduce code duplication here between lines in X and lines in Y direction.
            if direction % 2 == 0:  # lines in the Y direction

                if self.isSymmetrical:
                    N = self.NRodsPerLayer_X + (layer_type_X + 1) % 2
                else:
                    N = self.NRodsPerLayer_X

                # NOTE: some leftover from fitting the nanoscribe-style woodpile? Add option for it...? :/
                #for rod_idx in range(N-1,-1,-1):
                for rod_idx in range(N):
                    X = self.Xmin + self.Xoffset + layer_type_X * 0.5 * self.interRodDistance + rod_idx * self.interRodDistance
                    P1 = self.offset + numpy.array(
                        [X, self.Ymax, layer_idx * self.interLayerDistance])
                    P2 = self.offset + numpy.array(
                        [X, self.Ymin, layer_idx * self.interLayerDistance])
                    if self.rod_type == 'line':
                        GWL_obj.addLine(P1, P2)
                    elif self.rod_type == 'blockContinuous':
                        obj = GWL.tilted_grating.Parallelepiped()
                        obj.e1_vec3 = [0, 1, 0]
                        obj.e2_vec3 = [1, 0, 0]
                        if self.BottomToTop:
                            obj.e3_vec3 = [0, 0, 1]
                        else:
                            obj.e3_vec3 = [0, 0, -1]
                        width = self.LineNumber_X * self.LineDistance_X
                        height = self.LineNumber_Z * self.LineDistance_Z
                        obj.voxelsize_vec3 = numpy.array([
                            self.LineDistance_X, self.LineDistance_Y,
                            self.LineDistance_Z
                        ])
                        obj.size_vec3 = [
                            abs(P2[1] - P1[1]) + obj.voxelsize_vec3[0], width,
                            height
                        ]
                        obj.overlap_vec3 = numpy.array([0, 0, 0])
                        obj.center_vec3 = 0.5 * (P1 + P2)
                        obj.computePoints()
                        GWL_obj.addGWLobject(obj)
                    else:
                        GWL_obj.addYblock(P1, P2, self.LineNumber_X,
                                          self.LineDistance_X,
                                          self.LineNumber_Z,
                                          self.LineDistance_Z,
                                          self.BottomToTop)
                    block = bfdtd.Block()
                    block.setLowerAbsolute(
                        P1 - 0.5 * self.rod_width * numpy.array([1, 0, 0]) -
                        0.5 * self.rod_height * numpy.array([0, 0, 1]))
                    block.setUpperAbsolute(
                        P2 + 0.5 * self.rod_width * numpy.array([1, 0, 0]) +
                        0.5 * self.rod_height * numpy.array([0, 0, 1]))
                    block.setName("woodpile")
                    BFDTD_obj.geometry_object_list.append(block)
                layer_type_X = (layer_type_X + 1) % 2

            else:  # lines in the X direction

                if self.isSymmetrical:
                    N = self.NRodsPerLayer_Y + (layer_type_Y + 1) % 2
                else:
                    N = self.NRodsPerLayer_Y

                for rod_idx in range(N):
                    Y = self.Ymin + self.Yoffset + layer_type_Y * 0.5 * self.interRodDistance + rod_idx * self.interRodDistance
                    P1 = self.offset + numpy.array(
                        [self.Xmin, Y, layer_idx * self.interLayerDistance])
                    P2 = self.offset + numpy.array(
                        [self.Xmax, Y, layer_idx * self.interLayerDistance])
                    if self.rod_type == 'line':
                        GWL_obj.addLine(P1, P2)
                    # TODO: This is a quick hack at the moment. A lot of stuff needs to be rewritten to make things nicer.
                    elif self.rod_type == 'blockContinuous':
                        obj = GWL.tilted_grating.Parallelepiped()
                        obj.e1_vec3 = [1, 0, 0]
                        obj.e2_vec3 = [0, 1, 0]
                        if self.BottomToTop:
                            obj.e3_vec3 = [0, 0, 1]
                        else:
                            obj.e3_vec3 = [0, 0, -1]
                        width = self.LineNumber_Y * self.LineDistance_Y
                        height = self.LineNumber_Z * self.LineDistance_Z
                        obj.voxelsize_vec3 = numpy.array([
                            self.LineDistance_X, self.LineDistance_Y,
                            self.LineDistance_Z
                        ])
                        obj.size_vec3 = [
                            abs(P2[0] - P1[0]) + obj.voxelsize_vec3[0], width,
                            height
                        ]
                        obj.overlap_vec3 = numpy.array([0, 0, 0])
                        obj.center_vec3 = 0.5 * (P1 + P2)
                        obj.computePoints()
                        GWL_obj.addGWLobject(obj)
                    else:
                        GWL_obj.addXblock(P1, P2, self.LineNumber_Y,
                                          self.LineDistance_Y,
                                          self.LineNumber_Z,
                                          self.LineDistance_Z,
                                          self.BottomToTop)
                    block = bfdtd.Block()
                    block.setLowerAbsolute(
                        P1 - 0.5 * self.rod_width * numpy.array([0, 1, 0]) -
                        0.5 * self.rod_height * numpy.array([0, 0, 1]))
                    block.setUpperAbsolute(
                        P2 + 0.5 * self.rod_width * numpy.array([0, 1, 0]) +
                        0.5 * self.rod_height * numpy.array([0, 0, 1]))
                    block.setName("woodpile")
                    BFDTD_obj.geometry_object_list.append(block)
                layer_type_Y = (layer_type_Y + 1) % 2

            # optional: just add another write to easily distinguish layers inside file
            # TODO: Replace with comment. Requires addition of some addComment() command.
            GWL_obj.startNewVoxelSequence()
        return (GWL_obj, BFDTD_obj)
Exemple #8
0
def prismPillar(DSTDIR, BASENAME, pos, exc):
    sim = 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 = 4
    radius = k * Lambda_mum / (4 * n_diamond)
    Nbottom = 3
    Ntop = 3
    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)
    print('height = ', height)
    buffer = 0.05
    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
    sim.flag.iterations = 100000
    #sim.flag.iterations = 1

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

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

    #P_centre = sim.box.getCenter()

    ## define geometry

    #prism = TriangularPrism()
    prism = SpecialTriangularPrism()
    prism.lower = [0, 0, 0]
    prism.upper = [
        height, 2 * 3. / 2. * radius * 1.0 / numpy.sqrt(3), 3. / 2. * radius
    ]
    #prism.lower = [1,1,1]
    #prism.upper = [1,10,1]
    #prism.lower = [1,2,3]
    #prism.upper = [3,7,13]
    prism.orientation = [2, 0, 1]
    #prism.orientation = [2,1,0]
    prism.permittivity = pow(n_diamond, 2)
    prism.conductivity = 0
    prism.NvoxelsX = 30
    prism.NvoxelsY = 30
    prism.NvoxelsZ = 30

    prismPos = numpy.copy(sim.box.getCentro())
    if sim.boundaries.Ypos_bc == 1:
        prismPos[1] = sim.box.upper[1]
    prism.setGeoCentre(prismPos)
    #sim.probe_list.append(Probe(position = prism.getGeoCentre()))
    #prism.setGeoCentre([0,0,0])
    #sim.probe_list.append(Probe(position = prism.getGeoCentre()))

    sim.geometry_object_list.append(prism)

    buffersize = 10 * delta
    n_meshblock = 2.4

    # X buffers
    block = bfdtd.Block()
    block.setRefractiveIndex(n_meshblock)
    block.setLowerAbsolute(
        [prism.lower[0] - buffersize, prism.lower[1], prism.lower[2]])
    block.setUpperAbsolute([prism.lower[0], prism.upper[1], prism.upper[2]])
    sim.mesh_object_list.append(block)

    block = bfdtd.Block()
    block.setRefractiveIndex(n_meshblock)
    block.setLowerAbsolute([prism.upper[0], prism.lower[1], prism.lower[2]])
    block.setUpperAbsolute(
        [prism.upper[0] + buffersize, prism.upper[1], prism.upper[2]])
    sim.mesh_object_list.append(block)

    # Y buffers
    block = bfdtd.Block()
    block.setRefractiveIndex(n_meshblock)
    block.setLowerAbsolute(
        [prism.lower[0], prism.lower[1] - buffersize, prism.lower[2]])
    block.setUpperAbsolute([prism.upper[0], prism.lower[1], prism.upper[2]])
    sim.mesh_object_list.append(block)

    block = bfdtd.Block()
    block.setRefractiveIndex(n_meshblock)
    block.setLowerAbsolute([prism.lower[0], prism.upper[1], prism.lower[2]])
    block.setUpperAbsolute(
        [prism.upper[0], prism.upper[1] + buffersize, prism.upper[2]])
    sim.mesh_object_list.append(block)

    # Z buffers
    block = bfdtd.Block()
    block.setRefractiveIndex(n_meshblock)
    block.setLowerAbsolute(
        [prism.lower[0], prism.lower[1], prism.lower[2] - buffersize])
    block.setUpperAbsolute([prism.upper[0], prism.upper[1], prism.lower[2]])
    sim.mesh_object_list.append(block)

    block = bfdtd.Block()
    block.setRefractiveIndex(n_meshblock)
    block.setLowerAbsolute([prism.lower[0], prism.lower[1], prism.upper[2]])
    block.setUpperAbsolute(
        [prism.upper[0], prism.upper[1], prism.upper[2] + buffersize])
    sim.mesh_object_list.append(block)

    #sim.autoMeshGeometry(0.637/10)
    #print sim.getNcells()

    ##################################
    # prepare some points

    (A1_global, B1_global, C1_global, A2_global, B2_global,
     C2_global) = prism.getGlobalEnvelopPoints()
    #sim.probe_list.append(Probe(position = A1_global))
    #sim.probe_list.append(Probe(position = B1_global))
    #sim.probe_list.append(Probe(position = C1_global))
    #sim.probe_list.append(Probe(position = A2_global))
    #sim.probe_list.append(Probe(position = B2_global))
    #sim.probe_list.append(Probe(position = C2_global))

    bottom_centre = (A1_global + B1_global + C1_global) / 3.0
    print('bottom_centre = ', bottom_centre)
    top_centre = (A2_global + B2_global + C2_global) / 3.0

    P_centre = prism.getGeoCentre()

    template_radius = prism.getInscribedSquarePlaneRadius(P_centre)
    print('template_radius = ', template_radius)

    P3 = numpy.array(P_centre)

    prism_height = prism.upper[0] - prism.lower[0]
    prism_bottom = prism.lower[1]

    P1 = numpy.copy(bottom_centre)
    P1[0] = A1_global[0] - delta
    P2 = numpy.copy(bottom_centre)
    P2[2] = A1_global[2] - delta

    P4 = numpy.copy(top_centre)
    P4[2] = A2_global[2] - delta
    P5 = numpy.copy(top_centre)
    P5[0] = A2_global[0] + delta

    sim.autoMeshGeometry(0.637 / 10)
    # define excitation
    ################
    if sim.boundaries.Ypos_bc == 2:
        Ysym = False
    else:
        Ysym = True

    if pos == 0:
        QuadrupleExcitation(Ysym, sim, P1, 'x', delta, template_radius, freq,
                            exc)
    elif pos == 1:
        QuadrupleExcitation(Ysym, sim, P2 + 2 * delta * numpy.array([0, 0, 1]),
                            'z', delta, template_radius, freq, exc)
    elif pos == 2:
        QuadrupleExcitation(Ysym, sim, P3, 'x', delta, template_radius, freq,
                            exc)
    elif pos == 3:
        QuadrupleExcitation(Ysym, sim, P4, 'z', delta, template_radius, freq,
                            exc)
    elif pos == 4:
        QuadrupleExcitation(Ysym, sim, P5, 'x', delta, template_radius, freq,
                            exc)
    else:
        raise Exception('Invalid value for pos.')
    ################

    # create template
    #x_min = 0.0
    #x_max = 4.00
    #y_min = 0.0
    #y_max = 4.00
    #step_x = 2.00e-2
    #step_y = 2.00e-1
    #x_list = arange(x_min,x_max,step_x)
    #y_list = arange(y_min,y_max,step_y)

    #probe_X = [ P_centre[0]-(0.5*height+delta), P_centre[0], P_centre[0]+(0.5*height+delta) ]

    #if sim.boundaries.Ypos_bc == 2:
    #probe_Y = [ P_centre[1] ]
    #else:
    #probe_Y = [ P_centre[1]-delta ]

    #probe_Z = [ P_centre[2]-radius-delta, P_centre[2] ]

    #for x in probe_X:
    #for y in probe_Y:
    #for z in probe_Z:
    #probe = Probe(position = [ x,y,z ])
    #sim.probe_list.append(probe)

    # define frequency snapshots and probes
    first = min(65400, sim.flag.iterations)
    frequency_vector = [freq]

    P1_m = numpy.copy(P1)
    P2_m = numpy.copy(P2)
    P3_m = numpy.copy(P3)
    P4_m = numpy.copy(P4)
    P5_m = numpy.copy(P5)
    if sim.boundaries.Ypos_bc == 1:
        voxeldim_global = prism.getVoxelDimensions()
        P1_m[1] = P1_m[1] - voxeldim_global[1]
        P2_m[1] = P2_m[1] - voxeldim_global[1]
        P3_m[1] = P3_m[1] - voxeldim_global[1]
        P4_m[1] = P4_m[1] - voxeldim_global[1]
        P5_m[1] = P5_m[1] - voxeldim_global[1]

    Plist = [P1_m, P2_m, P3_m, P4_m, P5_m]
    for idx in range(len(Plist)):
        P = Plist[idx]
        F = sim.addFrequencySnapshot('x', P[0])
        F.first = first
        F.frequency_vector = frequency_vector
        F.name = 'x_' + str(idx)
        F = sim.addFrequencySnapshot('y', P[1])
        F.first = first
        F.frequency_vector = frequency_vector
        F.name = 'y_' + str(idx)
        F = sim.addFrequencySnapshot('z', P[2])
        F.first = first
        F.frequency_vector = frequency_vector
        F.name = 'z_' + str(idx)
        probe = bfdtd.Probe(position=P)
        probe.name = 'p_' + str(idx)
        sim.probe_list.append(probe)

    #F = sim.addFrequencySnapshot(1,P_centre[0]); F.first = first; F.frequency_vector = frequency_vector
    #if sim.boundaries.Ypos_bc == 2:
    #F = sim.addFrequencySnapshot(2,P_centre[1]); F.first = first; F.frequency_vector = frequency_vector
    #else:
    #F = sim.addFrequencySnapshot(2,P_centre[1]-delta); F.first = first; F.frequency_vector = frequency_vector
    #F = sim.addFrequencySnapshot(3,P_centre[2]); F.first = first; F.frequency_vector = frequency_vector

    F = sim.addBoxFrequencySnapshots()
    F.first = first
    F.frequency_vector = frequency_vector

    L = [prism.lower[0], prism.lower[1], prism.lower[2]
         ] - delta * numpy.array([1, 1, 1])
    U = [prism.upper[0], prism.upper[1], prism.upper[2]
         ] + delta * numpy.array([1, 1, 1])
    F = bfdtd.FrequencySnapshot()
    F.setName('Efficiency box frequency snapshot')
    F.setExtension(L, U)
    F.setFirst(first)
    F.setFrequencies(frequency_vector)
    sim.appendSnapshot(F)

    print('==========================================')
    L = P2 - template_radius * numpy.array([1, 1, 0])
    U = P2 + template_radius * numpy.array([1, 1, 0])
    print(('L=', L))
    print(('U=', U))
    F = bfdtd.FrequencySnapshot()
    F.setName('Efficiency input frequency snapshot')
    F.setExtension(L, U)
    F.setPlaneOrientationZ()
    F.setFirst(first)
    F.setFrequencies(frequency_vector)
    sim.appendSnapshot(F)
    print('==========================================')

    print('==========================================')
    L = P4 - template_radius * numpy.array([1, 1, 0])
    U = P4 + template_radius * numpy.array([1, 1, 0])
    print(('L=', L))
    print(('U=', U))
    F = bfdtd.FrequencySnapshot()
    F.setName('Efficiency output frequency snapshot')
    F.setExtension(L, U)
    F.setPlaneOrientationZ()
    F.setFirst(first)
    F.setFrequencies(frequency_vector)
    sim.appendSnapshot(F)
    print('==========================================')

    F = sim.addTimeSnapshot('z', P1[2])
    F.first = first

    ## define mesh
    #sim.addMeshingBox(lower,upper,)
    #sim.autoMeshGeometry(0.637/10)

    # write
    #DSTDIR = os.getenv('DATADIR')
    #DSTDIR = os.getenv('TESTDIR')
    #DSTDIR = os.getenv('TESTDIR')+os.sep+'triangle_pillar'
    #DSTDIR = os.getenv('DATADIR')+os.sep+'triangle_pillar'
    dest = DSTDIR + os.sep + BASENAME
    sim.writeAll(dest, BASENAME)
    GEOshellscript(dest + os.sep + BASENAME + '.sh',
                   BASENAME,
                   '$HOME/bin/fdtd',
                   '$JOBDIR',
                   WALLTIME=360)
    newdest = dest + os.sep + 'nogeometry'
    efficiency_run(dest, newdest)
    GEOshellscript(newdest + os.sep + BASENAME + '.sh',
                   BASENAME,
                   '$HOME/bin/fdtd',
                   '$JOBDIR',
                   WALLTIME=360)

    template = dest + os.sep + 'template.dat'
    try:
        shutil.copyfile(template, newdest + os.sep + 'template.dat')
    except IOError as e:
        print('File not found : ' + template)

    #GEOshellscript_advanced(DSTDIR+os.sep+BASENAME+os.sep+BASENAME+'.sh', BASENAME, getProbeColumnFromExcitation(excitation.E),'$HOME/bin/fdtd', '$JOBDIR', WALLTIME = 360)
    print(sim.getNcells())
def createSim(DSTDIR, geom):
    Lambda = 0.637

    sim = BFDTDobject()
    sim.boundaries.setBoundaryConditionsToPML()

    sim.flag.iterations = 65400
    #sim.flag.iterations = 30000
    #sim.flag.iterations = 1000
    #sim.flag.iterations = 10

    n = 2.4
    #height = 5*Lambda/n
    #radius = 0.5*Lambda/n
    height = 1
    radius = 10

    sim.box.lower = [0, 0, 0]
    sim.box.upper = [
        height + 4 * Lambda, 2 * radius + 1 * Lambda, 2 * radius + 1 * Lambda
    ]
    P_centre = sim.box.getCentro()

    ######################################
    # GEOMETRY
    bulk_block = bfdtd.Block()
    bulk_block.lower = sim.box.lower
    bulk_block.upper = sim.box.upper
    bulk_block.setRefractiveIndex(2.4)

    block = bfdtd.Block()
    block.lower = [
        P_centre[0] - 0.5 * height, P_centre[1] - radius, P_centre[2] - radius
    ]
    block.upper = [
        P_centre[0] + 0.5 * height, P_centre[1] + radius, P_centre[2] + radius
    ]
    block.setRefractiveIndex(2.4)

    prism = SpecialTriangularPrism()
    prism.lower = [0, 0, 0]
    prism.upper = [
        height, 2 * 3. / 2. * radius * 1.0 / numpy.sqrt(3), 3. / 2. * radius
    ]
    prism.orientation = [2, 0, 1]
    prism.setRefractiveIndex(2.4)
    prism.NvoxelsX = 30
    prism.NvoxelsY = 30
    prism.NvoxelsZ = 30
    prism.setGeoCentre(sim.box.getCentro())

    prism_block = bfdtd.Block()
    #prism_block.lower = [ P_centre[0]-0.5*height, P_centre[1]-0.5*radius, P_centre[2]-numpy.sqrt(3.0)/2.0*radius ]
    #prism_block.upper = [ P_centre[0]+0.5*height, P_centre[1]+radius, P_centre[2]+numpy.sqrt(3.0)/2.0*radius ]
    prism_block.lower = prism.lower
    prism_block.upper = prism.upper
    prism_block.setRefractiveIndex(2.4)

    vertices = numpy.zeros([8, 3])

    distorted_0 = bfdtd.Distorted()
    vertices[0] = P_centre + numpy.array(
        [-0.5 * height, -numpy.sqrt(3) / 2. * radius, radius])
    vertices[1] = P_centre + numpy.array(
        [0.5 * height, -numpy.sqrt(3) / 2. * radius, radius])
    vertices[2] = P_centre + numpy.array(
        [0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[3] = P_centre + numpy.array(
        [-0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[4] = P_centre + numpy.array(
        [-0.5 * height,
         numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[5] = P_centre + numpy.array([
        0.5 * height, numpy.sqrt(3) / 2. * radius, -0.5 * radius
    ])
    vertices[6] = P_centre + numpy.array(
        [0.5 * height, numpy.sqrt(3) / 2. * radius, radius])
    vertices[7] = P_centre + numpy.array(
        [-0.5 * height, numpy.sqrt(3) / 2. * radius, radius])
    distorted_0.setVerticesAbsolute(vertices)
    distorted_0.setRefractiveIndex(2.4)

    distorted_1 = bfdtd.Distorted()
    vertices[0] = P_centre + numpy.array(
        [-0.5 * height, -numpy.sqrt(3) / 2. * radius, radius])
    vertices[1] = P_centre + numpy.array([
        0.5 * height - 3. / 2. * radius, -numpy.sqrt(3) / 2. * radius, radius
    ])
    vertices[2] = P_centre + numpy.array(
        [0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[3] = P_centre + numpy.array(
        [-0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[4] = P_centre + numpy.array(
        [-0.5 * height,
         numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[5] = P_centre + numpy.array([
        0.5 * height, numpy.sqrt(3) / 2. * radius, -0.5 * radius
    ])
    vertices[6] = P_centre + numpy.array(
        [0.5 * height - 3. / 2. * radius,
         numpy.sqrt(3) / 2. * radius, radius])
    vertices[7] = P_centre + numpy.array(
        [-0.5 * height, numpy.sqrt(3) / 2. * radius, radius])
    distorted_1.setVerticesAbsolute(vertices)
    distorted_1.setRefractiveIndex(2.4)

    distorted_2 = bfdtd.Distorted()
    vertices[0] = P_centre + numpy.array([
        -0.5 * height + 3. / 2. * radius, -numpy.sqrt(3) / 2. * radius, radius
    ])
    vertices[1] = P_centre + numpy.array(
        [0.5 * height, -numpy.sqrt(3) / 2. * radius, radius])
    vertices[2] = P_centre + numpy.array(
        [0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[3] = P_centre + numpy.array(
        [-0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[4] = P_centre + numpy.array(
        [-0.5 * height,
         numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[5] = P_centre + numpy.array([
        0.5 * height, numpy.sqrt(3) / 2. * radius, -0.5 * radius
    ])
    vertices[6] = P_centre + numpy.array(
        [0.5 * height, numpy.sqrt(3) / 2. * radius, radius])
    vertices[7] = P_centre + numpy.array([
        -0.5 * height + 3. / 2. * radius,
        numpy.sqrt(3) / 2. * radius, radius
    ])
    distorted_2.setVerticesAbsolute(vertices)
    distorted_2.setRefractiveIndex(2.4)

    distorted_3 = bfdtd.Distorted()
    vertices[0] = P_centre + numpy.array([
        -0.5 * height + 3. / 2. * radius, -numpy.sqrt(3) / 2. * radius, radius
    ])
    vertices[1] = P_centre + numpy.array([
        0.5 * height - 3. / 2. * radius, -numpy.sqrt(3) / 2. * radius, radius
    ])
    vertices[2] = P_centre + numpy.array(
        [0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[3] = P_centre + numpy.array(
        [-0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[4] = P_centre + numpy.array(
        [-0.5 * height,
         numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[5] = P_centre + numpy.array([
        0.5 * height, numpy.sqrt(3) / 2. * radius, -0.5 * radius
    ])
    vertices[6] = P_centre + numpy.array(
        [0.5 * height - 3. / 2. * radius,
         numpy.sqrt(3) / 2. * radius, radius])
    vertices[7] = P_centre + numpy.array([
        -0.5 * height + 3. / 2. * radius,
        numpy.sqrt(3) / 2. * radius, radius
    ])
    distorted_3.setVerticesAbsolute(vertices)
    distorted_3.setRefractiveIndex(2.4)

    distorted_4 = bfdtd.Distorted()
    vertices[0] = P_centre + numpy.array([-0.5 * height, 0, radius])
    vertices[1] = P_centre + numpy.array([0.5 * height, 0, radius])
    vertices[2] = P_centre + numpy.array(
        [0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[3] = P_centre + numpy.array(
        [-0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[4] = P_centre + numpy.array(
        [-0.5 * height,
         numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[5] = P_centre + numpy.array([
        0.5 * height, numpy.sqrt(3) / 2. * radius, -0.5 * radius
    ])
    vertices[6] = P_centre + numpy.array([0.5 * height, 0, radius])
    vertices[7] = P_centre + numpy.array([-0.5 * height, 0, radius])
    distorted_4.setVerticesAbsolute(vertices)
    distorted_4.setRefractiveIndex(2.4)

    distorted_5 = bfdtd.Distorted()
    vertices[0] = P_centre + numpy.array([-0.5 * height, 0, radius])
    vertices[1] = P_centre + numpy.array(
        [0.5 * height - 3. / 2. * radius, 0, radius])
    vertices[2] = P_centre + numpy.array(
        [0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[3] = P_centre + numpy.array(
        [-0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[4] = P_centre + numpy.array(
        [-0.5 * height,
         numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[5] = P_centre + numpy.array([
        0.5 * height, numpy.sqrt(3) / 2. * radius, -0.5 * radius
    ])
    vertices[6] = P_centre + numpy.array(
        [0.5 * height - 3. / 2. * radius, 0, radius])
    vertices[7] = P_centre + numpy.array([-0.5 * height, 0, radius])
    distorted_5.setVerticesAbsolute(vertices)
    distorted_5.setRefractiveIndex(2.4)

    distorted_6 = bfdtd.Distorted()
    vertices[0] = P_centre + numpy.array(
        [-0.5 * height + 3. / 2. * radius, 0, radius])
    vertices[1] = P_centre + numpy.array([0.5 * height, 0, radius])
    vertices[2] = P_centre + numpy.array(
        [0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[3] = P_centre + numpy.array(
        [-0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[4] = P_centre + numpy.array(
        [-0.5 * height,
         numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[5] = P_centre + numpy.array([
        0.5 * height, numpy.sqrt(3) / 2. * radius, -0.5 * radius
    ])
    vertices[6] = P_centre + numpy.array([0.5 * height, 0, radius])
    vertices[7] = P_centre + numpy.array(
        [-0.5 * height + 3. / 2. * radius, 0, radius])
    distorted_6.setVerticesAbsolute(vertices)
    distorted_6.setRefractiveIndex(2.4)

    distorted_7 = bfdtd.Distorted()
    vertices[0] = P_centre + numpy.array(
        [-0.5 * height + 3. / 2. * radius, 0, radius])
    vertices[1] = P_centre + numpy.array(
        [0.5 * height - 3. / 2. * radius, 0, radius])
    vertices[2] = P_centre + numpy.array(
        [0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[3] = P_centre + numpy.array(
        [-0.5 * height, -numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[4] = P_centre + numpy.array(
        [-0.5 * height,
         numpy.sqrt(3) / 2. * radius, -0.5 * radius])
    vertices[5] = P_centre + numpy.array([
        0.5 * height, numpy.sqrt(3) / 2. * radius, -0.5 * radius
    ])
    vertices[6] = P_centre + numpy.array(
        [0.5 * height - 3. / 2. * radius, 0, radius])
    vertices[7] = P_centre + numpy.array(
        [-0.5 * height + 3. / 2. * radius, 0, radius])
    distorted_7.setVerticesAbsolute(vertices)
    distorted_7.setRefractiveIndex(2.4)

    cylinder_base = bfdtd.Cylinder()
    cylinder_base.setRefractiveIndex(1)
    rcyl = 0.5 * Lambda / (4. * 1.)
    intercyl = 0.5 * radius
    cylinder_base.outer_radius = rcyl
    cylinder_base.height = 2 * radius
    cylinder_list = []
    for i in range(6):
        cylinder_list.append(copy.deepcopy(cylinder_base))
        cylinder_list[i].centre = P_centre + numpy.array([
            Lambda, 0, 0
        ]) - numpy.array([radius + rcyl + i * (intercyl + 2 * rcyl), 0, 0])

    #sim.geometry_object_list.extend([bulk_block, block, prism, prism_block, distorted_0, distorted_1, distorted_2, distorted_3, distorted_4, distorted_5, distorted_6, distorted_7])
    #sim.geometry_object_list.extend([bulk_block, block, prism, prism_block])
    sim.geometry_object_list.extend([bulk_block, block])
    #sim.geometry_object_list.extend([block])
    #sim.geometry_object_list.extend(cylinder_list)
    ######################################

    P_input = P_centre - numpy.array([0.5 * height + 0.5 * Lambda, 0, 0])
    P_input_excitation = P_input - numpy.array([0.5 * Lambda, 0, 0])
    P_output = P_centre + numpy.array([0.5 * height + 0.5 * Lambda, 0, 0])

    (A1_global, B1_global, C1_global, A2_global, B2_global,
     C2_global) = prism.getGlobalEnvelopPoints()
    triangle_input = (A1_global + B1_global + C1_global) / 3.0
    triangle_output = (A2_global + B2_global + C2_global) / 3.0

    P_input_top = numpy.array(
        [triangle_input[0], triangle_input[1], prism.upper[2] - 0.1 * Lambda])
    P_output_top = numpy.array([
        triangle_output[0], triangle_output[1], prism.upper[2] - 0.1 * Lambda
    ])

    P_input_bottom = numpy.array(
        [triangle_input[0], triangle_input[1], prism.lower[2] + 0.1 * Lambda])
    P_output_bottom = numpy.array([
        triangle_output[0], triangle_output[1], prism.lower[2] + 0.1 * Lambda
    ])

    e_input = ExcitationWithGaussianTemplate()
    e_input.name = 'input'
    e_input.centre = P_input_excitation
    e_input.sigma_x = 0.1 * radius
    e_input.sigma_y = 0.1 * radius
    e_input.amplitude = 1
    e_input.plane_direction = 'x'
    e_input.excitation_direction = ['Eyre']
    e_input.frequency = get_c0() / Lambda
    e_input.template_filename = 'input.dat'
    e_input.setExtension(P_input_excitation - numpy.array([0, radius, radius]),
                         P_input_excitation + numpy.array([0, radius, radius]))
    sim.excitation_list.append(e_input)

    # measurement objects
    probe_input = bfdtd.Probe(position=P_input)
    probe_input.name = 'probe_input'
    sim.probe_list.append(probe_input)
    sim.addModeFilteredProbe('x', P_input[0])

    probe_output = bfdtd.Probe(position=P_output)
    probe_output.name = 'probe_output'
    sim.probe_list.append(probe_output)
    sim.addModeFilteredProbe('x', P_output[0])

    F = sim.addFrequencySnapshot('x', P_input[0])
    F.first = 10
    F.frequency_vector = [get_c0() / Lambda]
    F = sim.addFrequencySnapshot('y', P_input[1])
    F.first = 10
    F.frequency_vector = [get_c0() / Lambda]
    F = sim.addFrequencySnapshot('z', P_input[2])
    F.first = 10
    F.frequency_vector = [get_c0() / Lambda]

    T = sim.addTimeSnapshot('x', P_input[0])
    T.first = 10
    T.repetition = 10
    T = sim.addTimeSnapshot('y', P_input[1])
    T.first = 10
    T.repetition = 10
    T = sim.addTimeSnapshot('z', P_input[2])
    T.first = 10
    T.repetition = 10

    #probe_output = Probe(position = P_output); probe_output.name = 'probe_output'
    #sim.probe_list.append(probe_output)
    #sim.addModeFilteredProbe('x',P_output[0])

    #probe_input_top = Probe(position = P_input_top); probe_input_top.name = 'probe_input_top'
    #sim.probe_list.append(probe_input_top)
    #sim.addModeFilteredProbe('z',P_input_top[2])

    #probe_output_top = Probe(position = P_output_top); probe_output_top.name = 'probe_output_top'
    #sim.probe_list.append(probe_output_top)
    #sim.addModeFilteredProbe('z',P_output_top[2])

    #probe_input_bottom = Probe(position = P_input_bottom); probe_input_bottom.name = 'probe_input_bottom'
    #sim.probe_list.append(probe_input_bottom)
    #sim.addModeFilteredProbe('z',P_input_bottom[2])

    #probe_output_bottom = Probe(position = P_output_bottom); probe_output_bottom.name = 'probe_output_bottom'
    #sim.probe_list.append(probe_output_bottom)
    #sim.addModeFilteredProbe('z',P_output_bottom[2])

    # define mesh
    a = 10
    sim.autoMeshGeometry(Lambda / a)
    #MAXCELLS=8000000;
    MAXCELLS = 1000000
    while (sim.getNcells() > MAXCELLS and a > 1):
        a = a - 1
        sim.autoMeshGeometry(Lambda / a)

    print('sim.getNcells() = ' + str(sim.getNcells()))
    if sim.getNcells() > MAXCELLS:
        sys.exit(-1)

    if geom == 'empty':
        print(geom)
        sim.geometry_object_list = []
    elif geom == 'bulk':
        print(geom)
        sim.geometry_object_list = [bulk_block]
    elif geom == 'block':
        print(geom)
        sim.geometry_object_list = [block]
    elif geom == 'prism':
        print(geom)
        sim.geometry_object_list = [prism]
    elif geom == 'prism_block':
        print(geom)
        sim.geometry_object_list = [prism_block]
    elif geom == 'distorted_0':
        print(geom)
        sim.geometry_object_list = [distorted_0]
    elif geom == 'distorted_1':
        print(geom)
        sim.geometry_object_list = [distorted_1]
    elif geom == 'distorted_2':
        print(geom)
        sim.geometry_object_list = [distorted_2]
    elif geom == 'distorted_3':
        print(geom)
        sim.geometry_object_list = [distorted_3]
    elif geom == 'distorted_4':
        print(geom)
        sim.geometry_object_list = [distorted_4]
    elif geom == 'distorted_5':
        print(geom)
        sim.geometry_object_list = [distorted_5]
    elif geom == 'distorted_6':
        print(geom)
        sim.geometry_object_list = [distorted_6]
    elif geom == 'distorted_7':
        print(geom)
        sim.geometry_object_list = [distorted_7]
    elif geom == 'cylinder':
        print(geom)
        sim.geometry_object_list = [block]
        sim.geometry_object_list.extend(cylinder_list)
    else:
        print('unknown geom: ' + geom)
        sys.exit(-1)

    BASENAME = 'transmission'
    sim.writeAll(DSTDIR + os.path.sep + geom, BASENAME)
    sim.writeShellScript(DSTDIR + os.path.sep + geom + os.path.sep + BASENAME +
                         '.sh',
                         EXE='/space/ANONYMIZED/home_rama/bin/fdtd64_2008',
                         WORKDIR='$JOBDIR',
                         WALLTIME=12)
def createSim(DSTDIR):
    Lambda = 0.637

    sim = BFDTDobject()

    sim.flag.iterations = 65400

    sim.box.lower = [0, 0, 0]
    sim.box.upper = [12 * Lambda, 3 * Lambda, 3 * Lambda]
    P_centre = sim.box.getCentro()

    height = 10 * Lambda
    radius = 0.5 * Lambda

    block = bfdtd.Block()
    block.lower = [
        P_centre[0] - 0.5 * height, P_centre[1] - radius, P_centre[2] - radius
    ]
    block.upper = [
        P_centre[0] + 0.5 * height, P_centre[1] + radius, P_centre[2] + radius
    ]
    block.setRefractiveIndex(2.4)
    sim.geometry_object_list.append(block)

    P_input = P_centre - numpy.array([4 * Lambda, 0, 0])
    P_input_excitation = P_input - numpy.array([0.1 * Lambda, 0, 0])
    P_output = P_centre + numpy.array([4 * Lambda, 0, 0])

    e_input = ExcitationWithGaussianTemplate()
    e_input.name = 'input'
    e_input.centre = P_input_excitation
    e_input.sigma_x = radius
    e_input.sigma_y = radius
    e_input.amplitude = 1
    e_input.plane_direction = 'x'
    e_input.excitation_direction = ['Eyre']
    e_input.frequency = get_c0() / Lambda
    e_input.template_filename = 'input.dat'
    e_input.setExtension(P_input_excitation - numpy.array([0, radius, radius]),
                         P_input_excitation + numpy.array([0, radius, radius]))
    sim.excitation_list.append(e_input)

    # measurement objects
    probe_input = bfdtd.Probe(position=P_input)
    probe_input.name = 'probe_input'
    sim.probe_list.append(probe_input)

    probe_output = bfdtd.Probe(position=P_output)
    probe_output.name = 'probe_output'
    sim.probe_list.append(probe_output)

    sim.addModeFilteredProbe('x', P_input[0])

    sim.addModeFilteredProbe('x', P_output[0])

    # define mesh
    a = 5
    sim.autoMeshGeometry(Lambda / a)
    while (sim.getNcells() > 8000000 and a > 1):
        a = a - 1
        sim.autoMeshGeometry(Lambda / a)

    print('sim.getNcells() = ' + str(sim.getNcells()))
    if sim.getNcells() > 8000000:
        sys.exit(-1)

    sim.writeAll(DSTDIR, 'transmission')
import random
import tempfile

from utilities.brisFDTD_ID_info import FREQUENCYSNAPSHOT_MAX, TIMESNAPSHOT_MAX, MODEFILTEREDPROBE_MAX

import bfdtd

#tmp = tempfile.mkdtemp()
tmp = '/tmp/test/'
print('simdir = {}'.format(tmp))

sim = bfdtd.BFDTDobject()

sim.setSizeAndResolution([3,3,3], [30,40,50])

b = bfdtd.Block()
b.setSize([1,1,1])
b.setLocation(sim.getCentro())
b.setRelativePermittivity(2)
sim.appendGeometryObject(b)

#t = sim.appendSnapshot(TimeSnapshot())
#t.setEpsilon(True)

#sim.appendSnapshot(TimeSnapshot())

for s in [bfdtd.EpsilonSnapshot, bfdtd.FrequencySnapshot]:
  ex = sim.appendSnapshot(s())
  ey = sim.appendSnapshot(s())
  ez = sim.appendSnapshot(s())
def semi_loncar(DSTDIR, BASENAME, pos, exc):
    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
    cylinder_radius = 0.300
    pillar_radius = 0.500
    inter_centre_distance = 1.111
    h_air = Lambda_mum / (4 * n_air)
    h_diamond = Lambda_mum / (4 * n_diamond)
    h_cavity = Lambda_mum / (n_diamond)
    pillar_height = 7 + 3 * inter_centre_distance
    print('pillar_height = {}'.format(pillar_height))
    buffer = 0.05
    FullBox_upper = [
        pillar_height + 2 * buffer, 2 * (pillar_radius + buffer),
        2 * (pillar_radius + buffer)
    ]

    P_centre = [
        buffer + 0.5 * pillar_height, 0.5 * FullBox_upper[1],
        0.5 * FullBox_upper[2]
    ]
    pillar_bottom_centre = P_centre - array([0.5 * pillar_height, 0, 0])

    # define flag
    pillar.flag.iterations = 100000
    #pillar.flag.iterations = 1

    # define boundary conditions
    pillar.boundaries.Xpos_bc = 2
    pillar.boundaries.Ypos_bc = 2  #1
    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]
        ]

    #P_centre = pillar.box.getCenter()

    ## define geometry

    block = bfdtd.Block()
    block.lower = [
        P_centre[0] - 0.5 * pillar_height, P_centre[1] - pillar_radius,
        P_centre[2] - pillar_radius
    ]
    block.upper = [
        P_centre[0] + 0.5 * pillar_height, P_centre[1] + pillar_radius,
        P_centre[2] + pillar_radius
    ]
    block.setRefractiveIndex(n_diamond)
    block.conductivity = 0
    pillar.setGeometryObjects([block])

    cylinder = bfdtd.Cylinder()
    cylinder.centre = pillar_bottom_centre + array(
        [inter_centre_distance - cylinder_radius, 0, 0])
    cylinder.outer_radius = 0.5 * cylinder_radius
    cylinder.height = 2 * pillar_radius
    cylinder.setRefractiveIndex(n_air)
    cylinder.conductivity = 0

    cylinder1 = copy.deepcopy(cylinder)
    cylinder1.centre = cylinder.centre + array(
        [0 * inter_centre_distance, 0, 0])
    cylinder2 = copy.deepcopy(cylinder)
    cylinder2.centre = cylinder.centre + array(
        [1 * inter_centre_distance, 0, 0])
    cylinder3 = copy.deepcopy(cylinder)
    cylinder3.centre = cylinder.centre + array(
        [2 * inter_centre_distance, 0, 0])

    pillar.appendGeometryObject(block)
    pillar.appendGeometryObject(cylinder1)
    pillar.appendGeometryObject(cylinder2)
    pillar.appendGeometryObject(cylinder3)

    buffersize = 10 * delta
    n_meshblock = 2.4

    # X buffers
    block = bfdtd.Block()
    block.setRefractiveIndex(n_meshblock)
    block.setRelativeConductivity(0)
    block.lower = [
        block.getLowerAbsolute()[0] - buffersize,
        block.getLowerAbsolute()[1],
        block.getLowerAbsolute()[2]
    ]
    block.upper = [
        block.getLowerAbsolute()[0],
        block.getUpperAbsolute()[1],
        block.getUpperAbsolute()[2]
    ]
    pillar.mesh_object_list.append(block)

    block = bfdtd.Block()
    block.setRefractiveIndex(n_meshblock)
    block.setRelativeConductivity(0)
    block.lower = [
        block.getUpperAbsolute()[0],
        block.getLowerAbsolute()[1],
        block.getLowerAbsolute()[2]
    ]
    block.upper = [
        block.getUpperAbsolute()[0] + buffersize,
        block.getUpperAbsolute()[1],
        block.getUpperAbsolute()[2]
    ]
    pillar.mesh_object_list.append(block)

    # Y buffers
    block = bfdtd.Block()
    block.setRefractiveIndex(n_meshblock)
    block.setRelativeConductivity(0)
    block.lower = [
        block.getLowerAbsolute()[0],
        block.getLowerAbsolute()[1] - buffersize,
        block.getLowerAbsolute()[2]
    ]
    block.upper = [
        block.getUpperAbsolute()[0],
        block.getLowerAbsolute()[1],
        block.getUpperAbsolute()[2]
    ]
    pillar.mesh_object_list.append(block)

    block = bfdtd.Block()
    block.setRefractiveIndex(n_meshblock)
    block.setRelativeConductivity(0)
    block.lower = [
        block.getLowerAbsolute()[0],
        block.getUpperAbsolute()[1],
        block.getLowerAbsolute()[2]
    ]
    block.upper = [
        block.getUpperAbsolute()[0],
        block.getUpperAbsolute()[1] + buffersize,
        block.getUpperAbsolute()[2]
    ]
    pillar.mesh_object_list.append(block)

    # Z buffers
    block = bfdtd.Block()
    block.setRefractiveIndex(n_meshblock)
    block.setRelativeConductivity(0)
    block.lower = [
        block.getLowerAbsolute()[0],
        block.getLowerAbsolute()[1],
        block.getLowerAbsolute()[2] - buffersize
    ]
    block.upper = [
        block.getUpperAbsolute()[0],
        block.getUpperAbsolute()[1],
        block.getLowerAbsolute()[2]
    ]
    pillar.mesh_object_list.append(block)

    block = bfdtd.Block()
    block.setRefractiveIndex(n_meshblock)
    block.setRelativeConductivity(0)
    block.lower = [
        block.getLowerAbsolute()[0],
        block.getLowerAbsolute()[1],
        block.getUpperAbsolute()[2]
    ]
    block.upper = [
        block.getUpperAbsolute()[0],
        block.getUpperAbsolute()[1],
        block.getUpperAbsolute()[2] + buffersize
    ]
    pillar.mesh_object_list.append(block)

    #pillar.autoMeshGeometry(0.637/10)
    #print pillar.getNcells()

    ##################################
    # prepare some points

    #(A1_global,B1_global,C1_global,A2_global,B2_global,C2_global) = block.getGlobalEnvelopPoints()
    #pillar.probe_list.append(Probe(position = A1_global))
    #pillar.probe_list.append(Probe(position = B1_global))
    #pillar.probe_list.append(Probe(position = C1_global))
    #pillar.probe_list.append(Probe(position = A2_global))
    #pillar.probe_list.append(Probe(position = B2_global))
    #pillar.probe_list.append(Probe(position = C2_global))

    #bottom_centre = (A1_global+B1_global+C1_global)/3.0
    #print('bottom_centre = ',bottom_centre)
    #top_centre = (A2_global+B2_global+C2_global)/3.0

    P_centre = block.getCentro()

    #template_radius = block.getInscribedSquarePlaneRadius(P_centre)
    #print('template_radius = ',template_radius)

    #P3 = array(P_centre)

    #prism_height = block.getUpperAbsolute()[0] - block.getLowerAbsolute()[0]
    #prism_bottom = block.getLowerAbsolute()[1]

    #P1 = copy(bottom_centre)
    #P1[0] = A1_global[0] - delta
    #P2 = copy(bottom_centre)
    #P2[2] = A1_global[2] - delta

    #P4 = copy(top_centre)
    #P4[2] = A2_global[2] - delta
    #P5 = copy(top_centre)
    #P5[0] = A2_global[0] + delta

    #pillar.autoMeshGeometry(0.637/10)
    # define excitation
    ################
    if pillar.boundaries.Ypos_bc == 2:
        Ysym = False
    else:
        Ysym = True

    #if pos == 0:
    #QuadrupleExcitation(Ysym,pillar,P1,'x',delta,template_radius,freq,exc)
    #elif pos == 1:
    #QuadrupleExcitation(Ysym,pillar,P2,'z',delta,template_radius,freq,exc)
    #elif pos == 2:
    #QuadrupleExcitation(Ysym,pillar,P3,'x',delta,template_radius,freq,exc)
    #elif pos == 3:
    #QuadrupleExcitation(Ysym,pillar,P4,'z',delta,template_radius,freq,exc)
    #elif pos == 4:
    #QuadrupleExcitation(Ysym,pillar,P5,'x',delta,template_radius,freq,exc)
    #else:
    #sys.exit(-1)
    ################

    # create template
    #x_min = 0.0
    #x_max = 4.00
    #y_min = 0.0
    #y_max = 4.00
    #step_x = 2.00e-2
    #step_y = 2.00e-1
    #x_list = arange(x_min,x_max,step_x)
    #y_list = arange(y_min,y_max,step_y)

    #probe_X = [ P_centre[0]-(0.5*height+delta), P_centre[0], P_centre[0]+(0.5*height+delta) ]

    #if pillar.boundaries.Ypos_bc == 2:
    #probe_Y = [ P_centre[1] ]
    #else:
    #probe_Y = [ P_centre[1]-delta ]

    #probe_Z = [ P_centre[2]-radius-delta, P_centre[2] ]

    #for x in probe_X:
    #for y in probe_Y:
    #for z in probe_Z:
    #probe = Probe(position = [ x,y,z ])
    #pillar.probe_list.append(probe)

    # define frequency snapshots and probes
    first = min(65400, pillar.flag.iterations)
    frequency_vector = [freq]

    #P1_m = copy(P1)
    #P2_m = copy(P2)
    #P3_m = copy(P3)
    #P4_m = copy(P4)
    #P5_m = copy(P5)
    #if pillar.boundaries.Ypos_bc == 1:
    #voxeldim_global = block.getVoxelDimensions()
    #P1_m[1] = P1_m[1] - voxeldim_global[1]
    #P2_m[1] = P2_m[1] - voxeldim_global[1]
    #P3_m[1] = P3_m[1] - voxeldim_global[1]
    #P4_m[1] = P4_m[1] - voxeldim_global[1]
    #P5_m[1] = P5_m[1] - voxeldim_global[1]

    #Plist = [P1_m,P2_m,P3_m,P4_m,P5_m]
    #for idx in range(len(Plist)):
    #P = Plist[idx]
    #F = pillar.addFrequencySnapshot(1,P[0]); F.first = first; F.frequency_vector = frequency_vector; F.name='x_'+str(idx)
    #F = pillar.addFrequencySnapshot(2,P[1]); F.first = first; F.frequency_vector = frequency_vector; F.name='y_'+str(idx)
    #F = pillar.addFrequencySnapshot(3,P[2]); F.first = first; F.frequency_vector = frequency_vector; F.name='z_'+str(idx)
    #probe = Probe(position = P); probe.name = 'p_'+str(idx)
    #pillar.probe_list.append(probe)

    #F = pillar.addFrequencySnapshot(1,P_centre[0]); F.first = first; F.frequency_vector = frequency_vector
    #if pillar.boundaries.Ypos_bc == 2:
    #F = pillar.addFrequencySnapshot(2,P_centre[1]); F.first = first; F.frequency_vector = frequency_vector
    #else:
    #F = pillar.addFrequencySnapshot(2,P_centre[1]-delta); F.first = first; F.frequency_vector = frequency_vector
    #F = pillar.addFrequencySnapshot(3,P_centre[2]); F.first = first; F.frequency_vector = frequency_vector

    F = pillar.addBoxFrequencySnapshots()
    F.first = first
    F.frequency_vector = frequency_vector

    ## define mesh
    #pillar.addMeshingBox(lower,upper,)
    #pillar.autoMeshGeometry(0.637/10)

    # write
    #DSTDIR = os.getenv('DATADIR')
    #DSTDIR = os.getenv('TESTDIR')
    #DSTDIR = os.path.join(os.getenv('TESTDIR'), 'triangle_pillar')
    #DSTDIR = os.path.join(os.getenv('DATADIR'), 'triangle_pillar')
    pillar.writeAll(os.path.join(DSTDIR, BASENAME), BASENAME)
    GEOshellscript(os.path.join(DSTDIR, BASENAME, BASENAME + '.sh'),
                   BASENAME,
                   '$HOME/bin/fdtd',
                   '$JOBDIR',
                   WALLTIME=360)
    #GEOshellscript_advanced(os.path.join(DSTDIR, BASENAME, BASENAME+'.sh'), BASENAME, getProbeColumnFromExcitation(excitation.E),'$HOME/bin/fdtd', '$JOBDIR', WALLTIME = 360)
    print(pillar.getNcells())
Exemple #13
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
Exemple #14
0
    def test_SnapshotBoxVolume(self):
        with tempfile.TemporaryDirectory(
                prefix='testSnapshotBoxVolume-') as outdir:

            #outdir = '/tmp/testSnapshotBoxVolume'

            sim = bfdtd.BFDTDobject()
            sim.setSizeAndResolution([10, 11, 12], [41, 42, 43])

            b = bfdtd.Block()
            b.setSize([1, 2, 3])
            b.setLocation([4, 5, 6])
            sim.appendGeometryObject(b)

            tsnap = bfdtd.TimeSnapshot()
            tsnap.setExtension(*b.getExtension())
            esnap = bfdtd.EpsilonSnapshot()
            esnap.setExtension(*b.getExtension())
            mfp = bfdtd.ModeFilteredProbe()
            mfp.setExtension(*b.getExtension())
            fsnap = bfdtd.FrequencySnapshot()
            fsnap.setExtension(*b.getExtension())

            MV = bfdtd.SnapshotBoxVolume()
            sim.appendSnapshot(MV)

            #code.interact(local=locals())

            sim.writeGeoFile(os.path.join(outdir, 'testSnapshotBoxVolume.geo'))

            tsnap.setPlaneLetter('x')
            MV.setBaseSnapshot(tsnap)
            sim.setFileBaseName('tsnap_x')
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_tsnap_x.inp'))

            tsnap.setPlaneLetter('y')
            MV.setBaseSnapshot(tsnap)
            sim.setFileBaseName('tsnap_y')
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_tsnap_y.inp'))

            tsnap.setPlaneLetter('z')
            MV.setBaseSnapshot(tsnap)
            sim.setFileBaseName('tsnap_z')
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_tsnap_z.inp'))

            esnap.setPlaneLetter('x')
            MV.setBaseSnapshot(esnap)
            sim.setFileBaseName('esnap_x')
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_esnap_x.inp'))

            esnap.setPlaneLetter('y')
            MV.setBaseSnapshot(esnap)
            sim.setFileBaseName('esnap_y')
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_esnap_y.inp'))

            esnap.setPlaneLetter('z')
            MV.setBaseSnapshot(esnap)
            sim.setFileBaseName('esnap_z')
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_esnap_z.inp'))

            mfp.setPlaneLetter('x')
            MV.setBaseSnapshot(mfp)
            sim.setFileBaseName('mfp_x')
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_mfp_x.inp'))

            mfp.setPlaneLetter('y')
            MV.setBaseSnapshot(mfp)
            sim.setFileBaseName('mfp_y')
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_mfp_y.inp'))

            mfp.setPlaneLetter('z')
            MV.setBaseSnapshot(mfp)
            sim.setFileBaseName('mfp_z')
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_mfp_z.inp'))

            fsnap.setPlaneLetter('x')
            MV.setBaseSnapshot(fsnap)
            sim.setFileBaseName('fsnap_x')
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_fsnap_x.inp'))

            fsnap.setPlaneLetter('y')
            MV.setBaseSnapshot(fsnap)
            sim.setFileBaseName('fsnap_y')
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_fsnap_y.inp'))

            fsnap.setPlaneLetter('z')
            MV.setBaseSnapshot(fsnap)
            sim.setFileBaseName('fsnap_z')
            sim.writeInpFile(
                os.path.join(outdir, 'testSnapshotBoxVolume_fsnap_z.inp'))

        return
Exemple #15
0
def chalco(DSTDIR, BASENAME):

    n_chalcogenide = 2.4
    n_air = 1.0
    n_Au = 1.0
    n_glass = 1.5

    nHigh = n_chalcogenide
    nLow = n_air

    Lambda_mum = 0.637

    #######################
    # layer specifications
    #######################
    layer_size_DBR_left = np.array(
        30 * [Lambda_mum / (4 * n_chalcogenide), Lambda_mum / (4 * n_air)])
    excitation_DBR_left = np.array(30 * [0, 0])

    denominator_factor = np.array([4.04, 4.04, 4.28, 4.28, 4.56, 4.56])
    n = 3 * [nHigh, nLow]
    layer_size_taper_left = Lambda_mum / (denominator_factor * n)
    excitation_taper_left = np.array(3 * [0, 0])

    layer_size_cavity = np.array([Lambda_mum / (4.71 * n_chalcogenide)])
    excitation_cavity = np.array([1])

    denominator_factor = np.array([4.56, 4.56, 4.28, 4.28, 4.04, 4.04])
    n = 3 * [nLow, nHigh]
    layer_size_taper_right = Lambda_mum / (denominator_factor * n)
    excitation_taper_right = np.array(3 * [0, 0])

    layer_size_DBR_right = np.array(
        15 * [Lambda_mum / (4 * n_air), Lambda_mum / (4 * n_chalcogenide)])
    excitation_DBR_right = np.array(15 * [0, 0])

    layer_size_total_cavity = np.concatenate(
        (layer_size_taper_left, layer_size_cavity, layer_size_taper_right))
    print('cavity layers = ' + str(layer_size_total_cavity))
    print('cavity size = ' + str(sum(layer_size_total_cavity)))

    layer_size_total_cavity = (
        (2 * Lambda_mum / n_chalcogenide) /
        sum(layer_size_total_cavity)) * layer_size_total_cavity

    excitation_all = np.concatenate(
        (excitation_DBR_left, excitation_taper_left, excitation_cavity,
         excitation_taper_right, excitation_DBR_right))
    #layer_size_all = np.concatenate( (layer_size_DBR_left, layer_size_taper_left, layer_size_cavity, layer_size_taper_right, layer_size_DBR_right) )
    layer_size_all = np.concatenate(
        (layer_size_DBR_left, layer_size_total_cavity, layer_size_DBR_right))
    print(layer_size_all)
    ######################

    pillar = BFDTDobject()

    # pillar parameters
    Au_thickness = 0.200
    chalcogenide_thickness = 0.300
    glass_thickness = 1.0

    width_chalcogenide = 0.300
    width_substrate = 1.0
    pillar_height = sum(layer_size_all)
    print('pillar_height = ' + str(pillar_height))
    buffer = 1  #0.300
    FullBox_upper = [
        pillar_height + 2 * buffer, width_substrate + 2 * buffer,
        glass_thickness + Au_thickness + chalcogenide_thickness + 2 * buffer
    ]

    freq = get_c0() / Lambda_mum
    delta = Lambda_mum / (10 * nHigh)

    # define flag
    pillar.flag.iterations = 100000
    #pillar.flag.iterations = 10

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

    PML = False
    if PML:
        # PML
        pillar.boundaries.Xpos_bc = 10
        pillar.boundaries.Ypos_bc = 1
        pillar.boundaries.Zpos_bc = 10
        pillar.boundaries.Xneg_bc = 10
        pillar.boundaries.Yneg_bc = 10
        pillar.boundaries.Zneg_bc = 10

        pillar.boundaries.Xpos_param = [8, 2, 1e-3]
        pillar.boundaries.Ypos_param = [1, 1, 0]
        pillar.boundaries.Zpos_param = [8, 2, 1e-3]
        pillar.boundaries.Xneg_param = [8, 2, 1e-3]
        pillar.boundaries.Yneg_param = [8, 2, 1e-3]
        pillar.boundaries.Zneg_param = [8, 2, 1e-3]
    else:
        # no PML
        pillar.boundaries.Xpos_bc = 2
        pillar.boundaries.Ypos_bc = 1
        pillar.boundaries.Zpos_bc = 2
        pillar.boundaries.Xneg_bc = 2
        pillar.boundaries.Yneg_bc = 2
        pillar.boundaries.Zneg_bc = 2

        pillar.boundaries.Xpos_param = [1, 1, 0]
        pillar.boundaries.Ypos_param = [1, 1, 0]
        pillar.boundaries.Zpos_param = [1, 1, 0]
        pillar.boundaries.Xneg_param = [1, 1, 0]
        pillar.boundaries.Yneg_param = [1, 1, 0]
        pillar.boundaries.Zneg_param = [1, 1, 0]

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

    glass_centre = [P_centre[0], P_centre[1], buffer + 0.5 * glass_thickness]
    Au_centre = [
        P_centre[0], P_centre[1], buffer + glass_thickness + 0.5 * Au_thickness
    ]
    chalcogenide_centre = [
        P_centre[0], P_centre[1],
        buffer + glass_thickness + Au_thickness + 0.5 * chalcogenide_thickness
    ]

    # define glass pillar
    glass_pillar = bfdtd.Block()
    glass_pillar.lower = [
        glass_centre[0] - 0.5 * pillar_height,
        glass_centre[1] - 0.5 * width_substrate,
        glass_centre[2] - 0.5 * glass_thickness
    ]
    glass_pillar.upper = [
        glass_centre[0] + 0.5 * pillar_height,
        glass_centre[1] + 0.5 * width_substrate,
        glass_centre[2] + 0.5 * glass_thickness
    ]
    glass_pillar.permittivity = pow(n_glass, 2)
    glass_pillar.conductivity = 0
    pillar.geometry_object_list.append(glass_pillar)

    # define Au pillar
    Au_pillar = bfdtd.Block()
    Au_pillar.lower = [
        Au_centre[0] - 0.5 * pillar_height,
        Au_centre[1] - 0.5 * width_substrate, Au_centre[2] - 0.5 * Au_thickness
    ]
    Au_pillar.upper = [
        Au_centre[0] + 0.5 * pillar_height,
        Au_centre[1] + 0.5 * width_substrate, Au_centre[2] + 0.5 * Au_thickness
    ]
    Au_pillar.permittivity = pow(n_Au, 2)
    Au_pillar.conductivity = 0
    pillar.geometry_object_list.append(Au_pillar)

    # define chalcogenide pillar
    N = len(layer_size_all)
    print('N = ' + str(N))
    lower_x = glass_pillar.lower[0]
    for idx in range(N):
        if idx % 2 == 0:
            #print layer_size[idx]
            grating = bfdtd.Block()
            grating.lower = [
                lower_x, chalcogenide_centre[1] - 0.5 * width_chalcogenide,
                chalcogenide_centre[2] - 0.5 * chalcogenide_thickness
            ]
            grating.upper = [
                lower_x + layer_size_all[idx],
                chalcogenide_centre[1] + 0.5 * width_chalcogenide,
                chalcogenide_centre[2] + 0.5 * chalcogenide_thickness
            ]
            grating.permittivity = pow(n_chalcogenide, 2)
            grating.conductivity = 0
            pillar.geometry_object_list.append(grating)
        if excitation_all[idx] == 1:
            L = np.array([
                lower_x, chalcogenide_centre[1] - 0.5 * width_chalcogenide,
                chalcogenide_centre[2] - 0.5 * chalcogenide_thickness
            ])
            U = np.array([
                lower_x + layer_size_all[idx],
                chalcogenide_centre[1] + 0.5 * width_chalcogenide,
                chalcogenide_centre[2] + 0.5 * chalcogenide_thickness
            ])
            P_excitation = 0.5 * (L + U)
        lower_x = lower_x + layer_size_all[idx]

    #################
    ## define excitation
    #################
    if pillar.boundaries.Ypos_bc == 2:
        Ysym = False
    else:
        Ysym = True

    template_radius = 0
    QuadrupleExcitation(Ysym, pillar, P_excitation, 'x', delta,
                        template_radius, freq, 0)
    #################

    #################
    ## define frequency snapshots and probes
    #################
    #first = min(65400,pillar.flag.iterations)
    #frequency_vector = [freq]

    ## define probe
    #P = [ main_pillar.upper[0] + delta, P_centre[1], P_centre[2] ]
    #if Ysym:
    #P[1] = P[1]-delta

    #probe = Probe(position = P); probe.name = 'resonance_probe'
    #pillar.probe_list.append(probe)

    ## define snapshots around probe
    #F = pillar.addFrequencySnapshot(1,P[0]); F.first = first; F.frequency_vector = frequency_vector; F.name='x_'+str(0)
    #F = pillar.addFrequencySnapshot(2,P[1]); F.first = first; F.frequency_vector = frequency_vector; F.name='y_'+str(0)
    #F = pillar.addFrequencySnapshot(3,P[2]); F.first = first; F.frequency_vector = frequency_vector; F.name='z_'+str(0)

    ## define central snapshots
    #F = pillar.addFrequencySnapshot(1,P_excitation[0]); F.first = first; F.frequency_vector = frequency_vector
    #if pillar.boundaries.Ypos_bc == 2:
    #F = pillar.addFrequencySnapshot(2,P_excitation[1]); F.first = first; F.frequency_vector = frequency_vector
    #else:
    #F = pillar.addFrequencySnapshot(2,P_excitation[1]-delta); F.first = first; F.frequency_vector = frequency_vector
    #F = pillar.addFrequencySnapshot(3,P_excitation[2]); F.first = first; F.frequency_vector = frequency_vector

    ## box frequency snapshots
    #F = pillar.addBoxFrequencySnapshots(); F.first = first; F.frequency_vector = frequency_vector

    ## efficiency snapshots around structure
    ## TODO: write function to do this
    #L = [ main_pillar.lower[0], main_pillar.lower[1]-grating_depth, main_pillar.lower[2]-grating_depth ] - delta*np.array([1,1,1])
    #U = [ main_pillar.upper[0], main_pillar.upper[1]+grating_depth, main_pillar.upper[2]+grating_depth ] + delta*np.array([1,1,1])
    #if pillar.boundaries.Ypos_bc == 1:
    #U[1] = min(U[1],pillar.box.upper[1])
    #F = Frequency_snapshot(name='Efficiency box frequency snapshot', P1=L, P2=U); F.first = first; F.frequency_vector = frequency_vector;
    #pillar.snapshot_list.append(F)

    # define mesh
    pillar.autoMeshGeometry(Lambda_mum / 20.0)

    # write pillar
    pillar.writeAll(DSTDIR + os.sep + BASENAME, BASENAME)
    GEOshellscript(DSTDIR + os.sep + BASENAME + os.sep + BASENAME + '.sh',
                   BASENAME,
                   '$HOME/bin/fdtd',
                   '$JOBDIR',
                   WALLTIME=360)
    #GEOshellscript_advanced(DSTDIR+os.sep+BASENAME+os.sep+BASENAME+'.sh', BASENAME, getProbeColumnFromExcitation(pillar.excitation_list[0].E),'$HOME/bin/fdtd', '$JOBDIR', WALLTIME = 360)
    print(pillar.getNcells())
def rectangularYagiWithTaper(DSTDIR, BASENAME, nHigh, nLow, Lambda_mum,
                             layer_size, excitation_array, PML,
                             pillar_diametro, defect_type):
    '''
  layer_size : list of layer sizes, including the cavity
  excitation_array : list of zeros and ones, the same length as layer_size. A source will be placed into the layer with the corresponding index if excitation_array[idx]==1
  PML : true/false, use Perfect Matching Layers or not?
  '''
    #denominator_factor = numpy.array(denominator_factor)
    #n = numpy.array(n)

    hole_length = 2 * pillar_diametro

    pillar = bfdtd.BFDTDobject()

    # calculate layer height
    #layer_size = Lambda_mum/(denominator_factor*n)
    #print(layer_size)

    # pillar parameters
    pillar_height = sum(layer_size)
    #print('pillar_height = '+str(pillar_height))
    #pillar_radius = 0.5*0.340
    pillar_radius = 0.5 * pillar_diametro
    bufferSpace = 1
    FullBox_upper = [
        pillar_height + 2 * bufferSpace, 2 * (pillar_radius + bufferSpace),
        2 * (pillar_radius + bufferSpace)
    ]
    #FullBox_upper = [ 10, 10, 4 ]
    #grating_depth = 3*0.100
    grating_depth = 0.100
    freq = constants.get_c0() / Lambda_mum
    delta = Lambda_mum / (10 * nHigh)

    # define flag
    pillar.flag.iterations = 1048000
    #pillar.flag.iterations = 100000
    #pillar.flag.iterations = 10

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

    # default excitation location
    P_excitation = pillar.getCentro()

    if PML:
        # PML
        pillar.boundaries.Xpos_bc = 10
        pillar.boundaries.Ypos_bc = 1
        pillar.boundaries.Zpos_bc = 10
        pillar.boundaries.Xneg_bc = 10
        pillar.boundaries.Yneg_bc = 10
        pillar.boundaries.Zneg_bc = 10

        pillar.boundaries.Xpos_param = [8, 2, 1e-3]
        pillar.boundaries.Ypos_param = [1, 1, 0]
        pillar.boundaries.Zpos_param = [8, 2, 1e-3]
        pillar.boundaries.Xneg_param = [8, 2, 1e-3]
        pillar.boundaries.Yneg_param = [8, 2, 1e-3]
        pillar.boundaries.Zneg_param = [8, 2, 1e-3]
    else:
        # no PML
        pillar.boundaries.Xpos_bc = 2
        pillar.boundaries.Ypos_bc = 2
        pillar.boundaries.Zpos_bc = 2
        pillar.boundaries.Xneg_bc = 2
        pillar.boundaries.Yneg_bc = 2
        pillar.boundaries.Zneg_bc = 2

        pillar.boundaries.Xpos_param = [1, 1, 0]
        pillar.boundaries.Ypos_param = [1, 1, 0]
        pillar.boundaries.Zpos_param = [1, 1, 0]
        pillar.boundaries.Xneg_param = [1, 1, 0]
        pillar.boundaries.Yneg_param = [1, 1, 0]
        pillar.boundaries.Zneg_param = [1, 1, 0]

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

    # define main pillar
    main_pillar = bfdtd.Block()
    main_pillar.setLowerAbsolute([
        P_centre[0] - 0.5 * pillar_height, P_centre[1] - pillar_radius,
        P_centre[2] - pillar_radius
    ])
    main_pillar.setUpperAbsolute([
        P_centre[0] + 0.5 * pillar_height, P_centre[1] + pillar_radius,
        P_centre[2] + pillar_radius
    ])
    #main_pillar.setLowerAbsolute([  0, P_centre[1]-pillar_radius, P_centre[2]-pillar_radius ])
    #main_pillar.setUpperAbsolute([ 10, P_centre[1]+pillar_radius, P_centre[2]+pillar_radius ])
    main_pillar.setRefractiveIndex(nHigh)
    main_pillar.setName('main_pillar')
    if defect_type != 'cylinder_layers':
        pillar.setGeometryObjects([main_pillar])

    # define defects
    N = len(layer_size)
    #print('N = '+str(N))
    lower_x = main_pillar.getLowerAbsolute()[0]

    if defect_type == 'cylinder_holes':
        # .. todo:: fix mesh (i.e. replace MeshBox with latest meshing system...)
        #mesh_box = bfdtd.MeshBox()
        #mesh_box.lower = [ pillar.box.lower[0], P_centre[1]-pillar_radius, P_centre[2]-0.5*max(layer_size) ]
        #mesh_box.upper = [ pillar.box.upper[0], P_centre[1]+pillar_radius, P_centre[2]+0.5*max(layer_size) ]
        #mesh_box.permittivity3D = [1e-3, 1e-3, pow(2*nHigh,2)]
        #pillar.mesh_object_list.append(mesh_box)
        pass

    for idx in range(N):
        if defect_type == 'cylinder_holes':
            if idx % 2 == 1:
                #print layer_size[idx]
                defect = bfdtd.Cylinder()
                defect.setName('Cylinder_{}'.format(idx))
                defect.setDiametre(layer_size[idx])
                defect.setLocation([
                    lower_x + 0.5 * layer_size[idx], P_centre[1], P_centre[2]
                ])
                defect.setHeight(hole_length)
                defect.setRefractiveIndex(nLow)
                pillar.appendGeometryObject(defect)
            #print 'idx = ',idx, 'excitation_array = ', excitation_array
            if excitation_array[idx] == 1:
                L = numpy.array([
                    lower_x, P_centre[1] - pillar_radius - grating_depth,
                    P_centre[2] - pillar_radius - grating_depth
                ])
                U = numpy.array([
                    lower_x + layer_size[idx],
                    P_centre[1] + pillar_radius + grating_depth,
                    P_centre[2] + pillar_radius + grating_depth
                ])
                P_excitation = 0.5 * (L + U)
            lower_x = lower_x + layer_size[idx]
        elif defect_type == 'block_holes':
            if idx % 2 == 1:
                #print layer_size[idx]
                defect = bfdtd.Block()
                defect.setName('Block_{}'.format(idx))
                defect.setLowerAbsolute([
                    lower_x, P_centre[1] - 0.5 * hole_length,
                    P_centre[2] - pillar_radius + grating_depth
                ])
                defect.setUpperAbsolute([
                    lower_x + layer_size[idx], P_centre[1] + 0.5 * hole_length,
                    P_centre[2] + pillar_radius - grating_depth
                ])
                defect.setRefractiveIndex(nLow)
                pillar.geometry_object_list.append(defect)
            #print 'idx = ',idx, 'excitation_array = ', excitation_array
            if excitation_array[idx] == 1:
                L = numpy.array([
                    lower_x, P_centre[1] - pillar_radius - grating_depth,
                    P_centre[2] - pillar_radius - grating_depth
                ])
                U = numpy.array([
                    lower_x + layer_size[idx],
                    P_centre[1] + pillar_radius + grating_depth,
                    P_centre[2] + pillar_radius + grating_depth
                ])
                P_excitation = 0.5 * (L + U)
            lower_x = lower_x + layer_size[idx]
        elif defect_type == 'cylinder_layers':
            # TODO: finish implementing this. Also see pillar_1D.py and similar scripts to reduce code duplication.
            defect = bfdtd.Cylinder()
            defect.setName('Cylinder_{}'.format(idx))
            lower = numpy.array([
                lower_x, P_centre[1] - pillar_radius,
                P_centre[2] - pillar_radius + grating_depth
            ])
            upper = numpy.array([
                lower_x + layer_size[idx], P_centre[1] + pillar_radius,
                P_centre[2] + pillar_radius - grating_depth
            ])
            defect.setLocation(0.5 * (lower + upper))
            defect.setOuterRadius(pillar_radius)
            if idx % 2 == 0:
                defect.setRefractiveIndex(nHigh)
            else:
                defect.setRefractiveIndex(nLow)
            defect.setHeight(layer_size[idx])
            defect.setAxis([1, 0, 0])
            pillar.geometry_object_list.append(defect)
            #print 'idx = ',idx, 'excitation_array = ', excitation_array
            if excitation_array[idx] == 1:
                L = numpy.array([
                    lower_x, P_centre[1] - pillar_radius - grating_depth,
                    P_centre[2] - pillar_radius - grating_depth
                ])
                U = numpy.array([
                    lower_x + layer_size[idx],
                    P_centre[1] + pillar_radius + grating_depth,
                    P_centre[2] + pillar_radius + grating_depth
                ])
                P_excitation = 0.5 * (L + U)
            lower_x = lower_x + layer_size[idx]
        elif defect_type == 'grating':
            if idx % 2 == 0:
                #print layer_size[idx]
                defect = bfdtd.Block()
                defect.setName('Block_{}'.format(idx))
                defect.setLowerAbsolute([
                    lower_x, P_centre[1] - pillar_radius - grating_depth,
                    P_centre[2] - pillar_radius - grating_depth
                ])
                defect.setUpperAbsolute([
                    lower_x + layer_size[idx],
                    P_centre[1] + pillar_radius + grating_depth,
                    P_centre[2] + pillar_radius + grating_depth
                ])
                defect.setRefractiveIndex(nHigh)
                pillar.geometry_object_list.append(defect)
            #print 'idx = ',idx, 'excitation_array = ', excitation_array
            if excitation_array[idx] == 1:
                L = numpy.array([
                    lower_x, P_centre[1] - pillar_radius - grating_depth,
                    P_centre[2] - pillar_radius - grating_depth
                ])
                U = numpy.array([
                    lower_x + layer_size[idx],
                    P_centre[1] + pillar_radius + grating_depth,
                    P_centre[2] + pillar_radius + grating_depth
                ])
                P_excitation = 0.5 * (L + U)
            lower_x = lower_x + layer_size[idx]
            #if lower_x > 10:
            #break
        else:
            print('unknown defect type: ' + defect_type)
            sys.exit(1)

    #print(pillar.getGeometryObjects())

    ################
    # define excitation
    ################
    if pillar.boundaries.Ypos_bc == 2:
        Ysym = False
    else:
        Ysym = True

    template_radius = 0
    QuadrupleExcitation(Ysym, pillar, P_excitation, 'x', delta,
                        template_radius, freq, 0)
    ################

    ################
    # define frequency snapshots and probes
    ################
    first = min(65400, pillar.flag.iterations)
    frequency_vector = [freq]

    # define probe
    P = [main_pillar.getUpperAbsolute()[0] + delta, P_centre[1], P_centre[2]]
    if Ysym:
        P[1] = P[1] - delta
    probe = bfdtd.Probe(position=P)
    probe.name = 'resonance_probe'
    pillar.appendProbe(probe)

    P = [P_excitation[0] + delta, P_centre[1], P_centre[2]]
    if Ysym:
        P[1] = P[1] - delta
    probe = bfdtd.Probe(position=P)
    probe.name = 'resonance_probe'
    pillar.appendProbe(probe)

    # define snapshots around probe
    #F = pillar.addFrequencySnapshot(1,P[0]); F.first = first; F.frequency_vector = frequency_vector; F.name='x_'+str(0)
    #F = pillar.addFrequencySnapshot(2,P[1]); F.first = first; F.frequency_vector = frequency_vector; F.name='y_'+str(0)
    #F = pillar.addFrequencySnapshot(3,P[2]); F.first = first; F.frequency_vector = frequency_vector; F.name='z_'+str(0)

    # define central snapshots
    F = pillar.addFrequencySnapshot('x', P_excitation[0])
    F.first = first
    F.frequency_vector = frequency_vector
    if pillar.boundaries.Ypos_bc == 2:
        F = pillar.addFrequencySnapshot('y', P_excitation[1])
        F.first = first
        F.frequency_vector = frequency_vector
    else:
        F = pillar.addFrequencySnapshot('y', P_excitation[1] - delta)
        F.first = first
        F.frequency_vector = frequency_vector
    F = pillar.addFrequencySnapshot('z', P_excitation[2])
    F.first = first
    F.frequency_vector = frequency_vector

    F = pillar.addTimeSnapshot('x', P_excitation[0])
    F.first = first
    if pillar.boundaries.Ypos_bc == 2:
        F = pillar.addTimeSnapshot('y', P_excitation[1])
        F.first = first
    else:
        F = pillar.addTimeSnapshot('y', P_excitation[1] - delta)
        F.first = first
    F = pillar.addTimeSnapshot('z', P_excitation[2])
    F.first = first

    # box frequency snapshots
    #F = pillar.addBoxFrequencySnapshots(); F.first = first; F.frequency_vector = frequency_vector

    # efficiency snapshots around structure
    ## TODO: write function to do this
    #L = [ main_pillar.lower[0], main_pillar.lower[1]-grating_depth, main_pillar.lower[2]-grating_depth ] - delta*numpy.array([1,1,1])
    #U = [ main_pillar.upper[0], main_pillar.upper[1]+grating_depth, main_pillar.upper[2]+grating_depth ] + delta*numpy.array([1,1,1])
    #if pillar.boundaries.Ypos_bc == 1:
    #U[1] = min(U[1],pillar.box.upper[1])
    #F = Frequency_snapshot(name='Efficiency box frequency snapshot', P1=L, P2=U); F.first = first; F.frequency_vector = frequency_vector;
    #pillar.snapshot_list.append(F)

    lower_wall = bfdtd.Block()
    lower_wall.setName('lower_wall')
    lower_wall.setLowerAbsolute([0, 0, 0])
    lower_wall.setUpperAbsolute(
        [0.5, pillar.box.upper[1], pillar.box.upper[2]])
    lower_wall.setRefractiveIndex(nHigh)
    lower_wall.setRelativeConductivity(0)
    #pillar.appendGeometryObject(lower_wall)

    upper_wall = bfdtd.Block()
    upper_wall.setName('upper_wall')
    upper_wall.setLowerAbsolute([pillar.box.upper[0] - 0.5, 0, 0])
    upper_wall.setUpperAbsolute(
        [pillar.box.upper[0], pillar.box.upper[1], pillar.box.upper[2]])
    upper_wall.setRefractiveIndex(nHigh)
    upper_wall.setRelativeConductivity(0)
    #pillar.appendGeometryObject(upper_wall)

    # define mesh
    a = 20
    pillar.autoMeshGeometry(0.637 / a)
    while (pillar.getNcells() > 8000000 and a > 1):
        a = a - 1
        pillar.autoMeshGeometry(0.637 / a)

    #pillar.autoMeshGeometry(1000)

    # write pillar
    #pillar.writeAll(DSTDIR+os.sep+BASENAME, BASENAME)
    ##GEOshellscript(DSTDIR+os.sep+BASENAME+os.sep+BASENAME+'.sh', BASENAME,'$HOME/bin/fdtd', '$JOBDIR', WALLTIME = 360)
    #GEOshellscript_advanced(DSTDIR+os.sep+BASENAME+os.sep+BASENAME+'.sh', BASENAME, getProbeColumnFromExcitation(pillar.excitation_list[0].E),'$HOME/bin/fdtd', '$JOBDIR', WALLTIME = 360)

    pillar.writeAll(DSTDIR, BASENAME)
    GEOshellscript(DSTDIR + os.sep + BASENAME + '.sh',
                   BASENAME,
                   '$HOME/bin/fdtd',
                   '$JOBDIR',
                   WALLTIME=360)
    #GEOshellscript_advanced(DSTDIR+os.sep+BASENAME+os.sep+BASENAME+'.sh', BASENAME, getProbeColumnFromExcitation(pillar.excitation_list[0].E),'$HOME/bin/fdtd', '$JOBDIR', WALLTIME = 360)

    print('pillar.getNcells() = ' + str(pillar.getNcells()))
    if pillar.getNcells() > 8000000:
        sys.exit(-1)