def main(): parser = argparse.ArgumentParser() parser.add_argument('DSTDIR', default=tempfile.gettempdir(), nargs='?') args = parser.parse_args() print(args.DSTDIR) pillar = BFDTDobject() ## define geometry offset = array([1,2,3]) prism = SpecialTriangularPrism() prism.lower = offset+array([ 0,0,0 ]) prism.upper = offset+array([ 5,1,2 ]) prism.orientation = [2,0,1] prism.permittivity = pow(2.4,2) prism.conductivity = 0 prism.NvoxelsX = 30 prism.NvoxelsY = 30 prism.NvoxelsZ = 30 pillar.geometry_object_list.append(prism) # define excitation P_centre = prism.getGeoCentre() template_radius = prism.getInscribedSquarePlaneRadius(P_centre) print('template_radius = ',template_radius) #template_radius = 0.0307 #(A1_global,B1_global,C1_global,A2_global,B2_global,C2_global) = prism.getGlobalEnvelopPoints() envelop = prism.getGlobalEnvelopPoints() # define probes probe = bfdtd.Probe(position = P_centre) pillar.probe_list.append(probe) for i in envelop: print(i) probe = bfdtd.Probe(position = i) pillar.probe_list.append(probe) # excitations excitation, template = ExcitationWrapper(Ysym=False, centre=P_centre, size=template_radius, plane_direction='x', type='1D', excitation_direction=[0,0,1], frequency=123) pillar.appendExcitation(excitation) pillar.excitation_template_list.append(template) excitation, template = ExcitationWrapper(Ysym=False, centre=P_centre, size=template_radius, plane_direction='x', type='1D', excitation_direction=[0,1,0], frequency=123) pillar.appendExcitation(excitation) pillar.excitation_template_list.append(template) excitation, template = ExcitationWrapper(Ysym=False, centre=P_centre, size=template_radius, plane_direction='x', type='2D', excitation_direction=[0,0,1], frequency=123) pillar.appendExcitation(excitation) pillar.excitation_template_list.append(template) # write #DSTDIR = os.getenv('TESTDIR') BASENAME = 'prismtest' pillar.writeAll(os.path.join(args.DSTDIR, BASENAME), BASENAME)
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
def main(): parser = argparse.ArgumentParser() parser.add_argument('DSTDIR', default=tempfile.gettempdir(), nargs='?') args = parser.parse_args() print(args.DSTDIR) # DSTDIR + BASENAME BASENAME = 'planeWaveTest' if not os.path.isdir(args.DSTDIR): os.mkdir(args.DSTDIR) # define a wavelength for calculations Lambda = 0.1 # BFDTDobject sim = BFDTDobject() sim.boundaries.setBoundaryConditionsToPML() sim.box.upper = [2, 1, 1] # probes sim.appendProbe(bfdtd.Probe([0, 0.5, 0.5])) sim.appendProbe(bfdtd.Probe([0.25, 0.5, 0.5])) sim.appendProbe(bfdtd.Probe([0.5, 0.5, 0.5])) sim.appendProbe(bfdtd.Probe([0.75, 0.5, 0.5])) sim.appendProbe(bfdtd.Probe([1, 0.5, 0.5])) sim.appendProbe(bfdtd.Probe([1.25, 0.5, 0.5])) sim.appendProbe(bfdtd.Probe([1.5, 0.5, 0.5])) sim.appendProbe(bfdtd.Probe([1.75, 0.5, 0.5])) sim.appendProbe(bfdtd.Probe([2, 0.5, 0.5])) # excitation e = ExcitationWithUniformTemplate() e.plane_direction = [1, 0, 0] e.excitation_direction = ['Eyre', 'Hzre'] e.centre = sim.box.getCentro() e.setLambda(Lambda) sim.appendExcitation(e) # write sim.autoMeshGeometry(Lambda / 4.) sim.writeAll(os.path.join(args.DSTDIR, BASENAME)) sim.writeShellScript(os.path.join(args.DSTDIR, BASENAME + '.sh'), EXE='fdtd64_2003', WORKDIR='$JOBDIR', WALLTIME=12)
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('.')
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
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))
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')
def resonance_run(args): ''' Copy src to dst with added frequency snapshots from freqListFile ''' src = os.path.abspath(args.src).rstrip(os.sep) dst = os.path.abspath(args.dst).rstrip(os.sep) if os.path.isdir(src): print(src + ' is a directory') sim = bfdtd.readBristolFDTD(src + os.sep + os.path.basename(src) + '.in') if not args.fileBaseName: fileBaseName = os.path.basename(src) else: print(src + ' is not a directory') sim = bfdtd.readBristolFDTD(src) if not args.fileBaseName: fileBaseName = os.path.splitext(os.path.basename(src))[0] freqs = getFrequencies(args.freqListFile) print('---') print('Frequencies:') for f in freqs: print(f) print('---') # get src snapshot lists (all_time_snapshots, time_snapshots, epsilon_snapshots, mode_filtered_probes) = sim.getAllTimeSnapshots() fsnap_list = sim.getFrequencySnapshots() new_snapshot_list = [] if args.frequency_to_energy: for fsnap in fsnap_list: energy_snapshot = bfdtd.EnergySnapshot() energy_snapshot.setFromSnapshot(fsnap) energy_snapshot.setFrequencies(freqs) new_snapshot_list.append(energy_snapshot) if args.new_central: box = bfdtd.SnapshotBoxXYZ() exc = sim.getExcitations()[0] if args.intersection_at_P1: (P1, P2) = exc.getExtension() print('P1 = {}'.format(P1)) box.setIntersectionPoint(P1) else: box.setIntersectionPoint(exc.getCentro()) energy_snapshot = bfdtd.EnergySnapshot() energy_snapshot.setFrequencies(freqs) box.setBaseSnapshot(energy_snapshot) new_snapshot_list.append(box) print(new_snapshot_list) print(len(new_snapshot_list)) if args.clearAllSnapshots: sim.clearAllSnapshots() if args.clearEpsilonSnapshots: sim.clearEpsilonSnapshots() if args.clearFrequencySnapshots: sim.clearFrequencySnapshots() if args.clearModeFilteredProbes: sim.clearModeFilteredProbes() if args.clearTimeSnapshots: sim.clearTimeSnapshots() if args.clearProbes: sim.clearProbes() if args.clearGeometry: sim.clearGeometry() if args.iterations: sim.setIterations(args.iterations) sim.appendSnapshot(new_snapshot_list) exc = sim.getExcitations()[0] if args.source_frequency_range: exc.setFrequencyRange(*args.source_frequency_range) elif args.source_wavelength_range: exc.setWavelengthRange(*args.source_wavelength_range) elif args.source_frequency_range_from_DBR: wavelength, nLow, nHigh = args.source_frequency_range_from_DBR obj = geometries.DBR.DBR(wavelength, nLow, nHigh) fmin, fmax = obj.getFrequencyRange() exc.setFrequencyRange(fmin, fmax) elif args.source_frequency_range_max: lambda0 = args.source_frequency_range_max f0 = get_c0() / lambda0 delta_f = f0 / 4 fmin = f0 - delta_f / 2 fmax = f0 + delta_f / 2 exc.setFrequencyRange(fmin, fmax) print('FrequencyRange = {}'.format(exc.getFrequencyRange())) print('WavelengthRange = {}'.format(exc.getWavelengthRange())) print('exc.getPeriod() = {}'.format(exc.getPeriod())) print('exc.getTimeConstant() = {}'.format(exc.getTimeConstant())) print('exc.getPeriod()/exc.getTimeConstant() = {}'.format( exc.getPeriod() / exc.getTimeConstant())) exc.setStartTime(0) sim.printInfo() sim.setFileBaseName(fileBaseName) sim.setWallTime(args.walltime) sim.setAutosetNFrequencySnapshots(10) if args.run_source: sim.setSizeAndResolution([1, 1, 1], [32, 32, 32]) sim.getBoundaries().setBoundaryConditionsNormal() sim.clearAllSnapshots() sim.clearProbes() sim.clearGeometry() exc = sim.getExcitations()[0] exc.setLocation(sim.getCentro()) exc.setSize([0, 0, 0]) p = sim.appendProbe(bfdtd.Probe()) p.setStep(1) p.setLocation(exc.getLocation()) sim.setSimulationTime(sim.getExcitationEndTimeMax()) sim.writeTorqueJobDirectory(dst) #sim.writeAll(dst, fileBaseName) #sim.writeShellScript(os.path.join(dst, fileBaseName+'.sh')) print(sim.getSnapshots()) for s in sim.getSnapshots(): print(s.getName())
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
def main(): parser = argparse.ArgumentParser() parser.add_argument('DSTDIR', default=tempfile.gettempdir(), nargs='?') args = parser.parse_args() print(args.DSTDIR) if not os.path.isdir(args.DSTDIR): os.mkdir(args.DSTDIR) BASENAME = 'just_signal' sim = BFDTDobject() excitation_wavelength_mum = 0.910 sim.box.setLower([0, 0, 0]) sim.box.setUpper([ 10 * excitation_wavelength_mum, 10 * excitation_wavelength_mum, 10 * excitation_wavelength_mum ]) D_mum = 2 * excitation_wavelength_mum sim.flag.timeStep = 0.5 sim.flag.iterations = int( numpy.ceil(0.05 * D_mum / (get_c0() * sim.flag.timeStep * 1e-12))) sim.boundaries.setBoundaryConditionsXposToPML() sim.boundaries.setBoundaryConditionsYposToPML() sim.boundaries.setBoundaryConditionsZposToPML() sim.boundaries.setBoundaryConditionsXnegToPML() sim.boundaries.setBoundaryConditionsYnegToPML() sim.boundaries.setBoundaryConditionsZnegToPML() P_excitation = 0.5 * (sim.box.lower + sim.box.upper) delta = excitation_wavelength_mum propagation_direction = 'z' E1 = [1, 0, 0] freq_MHz = get_c0() / excitation_wavelength_mum excitation, template = ExcitationWrapper( Ysym=False, centre=P_excitation, size=delta, plane_direction=propagation_direction, type='1D', excitation_direction=E1, frequency=freq_MHz) excitation.time_constant = 10 * 4e-9 sim.excitation_list.append(excitation) probe = bfdtd.Probe( position=[P_excitation[0], P_excitation[1], P_excitation[2] + D_mum]) probe.name = 'resonance_probe' sim.probe_list.append(probe) probe = bfdtd.Probe(position=P_excitation) probe.name = 'onsignal_probe' sim.probe_list.append(probe) probe = bfdtd.Probe(position=[ P_excitation[0], P_excitation[1], P_excitation[2] + excitation_wavelength_mum / 4. ]) probe.name = 'resonance_probe' sim.probe_list.append(probe) #first = 1 #frequency_vector = [1] #F = sim.addFrequencySnapshot(1,P_excitation[0]); F.first = first; F.frequency_vector = frequency_vector #F = sim.addFrequencySnapshot(2,P_excitation[1]); F.first = first; F.frequency_vector = frequency_vector #F = sim.addFrequencySnapshot(3,P_excitation[2]); F.first = first; F.frequency_vector = frequency_vector #F = sim.addTimeSnapshot(1,P_excitation[0]); F.first = first #F = sim.addTimeSnapshot(2,P_excitation[0]); F.first = first #F = sim.addTimeSnapshot(3,P_excitation[0]); F.first = first # define mesh sim.autoMeshGeometry(meshing_factor=excitation_wavelength_mum / 4.) # write sim sim.writeAll(args.DSTDIR + os.sep + BASENAME, BASENAME) GEOshellscript(args.DSTDIR + os.sep + BASENAME + os.sep + BASENAME + '.sh', BASENAME, '$HOME/bin/fdtd', '$JOBDIR', WALLTIME=360) print('iterations = ', sim.flag.iterations) print('Ncells = ', sim.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)