def AddFrequencyFromInpFile(self): (files, selected_filter) = QtWidgets.QFileDialog.getOpenFileNames( parent=self, caption='Add frequencies from BFDTD input files', filter='BFDTD input files (*.in *.geo *.inp);; All Files(*)', directory=self.default_dir_InputDir) if files: self.default_dir_InputDir = files[0] obj = BFDTDobject() for i in files: obj.readBristolFDTD(i) excitation_freq_list = sorted(list(obj.getExcitationFrequencySet())) snap_freq_list = sorted(list(obj.getSnapshotFrequencySet())) print(excitation_freq_list) print(snap_freq_list) for f in excitation_freq_list: self.AddFrequency(f, get_c0() / f, 'from excitation') for f in snap_freq_list: self.AddFrequency(f, get_c0() / f, 'from frequency snapshot') return
def getFrequencyRange(self): t1 = self.wavelength / (4 * self.nLow) t2 = self.wavelength / (4 * self.nHigh) DBR_pair_thickness = t1 + t2 f0 = get_c0() / self.wavelength #f0 = ((self.nLow + self.nHigh)/(4*self.nLow*self.nHigh))*get_c0()/DBR_pair_thickness delta_f = (4 / numpy.pi) * numpy.arcsin( abs(self.nLow - self.nHigh) / (self.nLow + self.nHigh)) * f0 fmax = f0 + delta_f / 2 fmin = f0 - delta_f / 2 lambda_min = get_c0() / fmax lambda_max = get_c0() / fmin return (fmin, fmax)
def FreqTableChanged(self, row, column): print('Change at ({}, {})'.format(row, column)) if not self.ignoreChange: self.ignoreChange = True if column == 0: freq = float(self.tableWidget_Frequencies.item(row, 0).text()) wavelength = get_c0() / freq item = QTableWidgetItem() item.setData(Qt.DisplayRole, wavelength) self.tableWidget_Frequencies.setItem(row, 1, item) elif column == 1: wavelength = float( self.tableWidget_Frequencies.item(row, 1).text()) freq = get_c0() / wavelength item = QTableWidgetItem() item.setData(Qt.DisplayRole, freq) self.tableWidget_Frequencies.setItem(row, 0, item) self.ignoreChange = False
def AddFrequencyFromFrequencyList(self): (files, selected_filter) = QtWidgets.QFileDialog.getOpenFileNames( parent=self, caption='Add frequencies from frequency list files', filter= 'frequency list files (*.harminv.selection.txt);; text files (*.txt);; CSV files (*.csv);; All Files(*)', directory=self.default_dir_InputDir) if files: self.default_dir_InputDir = files[0] for i in files: freq_list = getFrequencies(i) for f in freq_list: self.AddFrequency(f, get_c0() / f, 'from ' + i) return
def process(maindir, destdir, overwrite, dry_run, disabled_epsilon=False, disabled_directions=[]): print('maindir = {}'.format(maindir)) print('destdir = {}'.format(destdir)) print('overwrite = {}'.format(overwrite)) print('dry_run = {}'.format(dry_run)) print('disabled_epsilon = {}'.format(disabled_epsilon)) print('disabled_directions = {}'.format(disabled_directions)) for direction in ['Ex', 'Ey', 'Ez']: if direction not in disabled_directions: # get the frequency list, to fail quickly in case of problems flist = os.path.join(maindir, direction, 'frequency-selection.txt') freq_MHz_list = getFrequencies(flist) # read in base file infile = os.path.join(maindir, direction, 'RCD111.in') sim = readBristolFDTD(infile, verbosity=0) sim.setFileBaseName('RCD111') # clean sim sim.clearProbes() sim.clearAllSnapshots() sim.clearFileList() # get excitation location excitation = sim.getExcitations()[0] excitation_location = excitation.getLocation() # get min/max param values dt = sim.getTimeStep() time_offset = max( excitation.getTimeOffset(), MIN_TIME_OFFSET_TIME_CONSTANT_RATIO * excitation.getTimeConstant()) starting_sample_min = int( ceil((time_offset + MIN_TIME_OFFSET_TIME_CONSTANT_RATIO * excitation.getTimeConstant()) / dt)) #print(dt) #print(starting_sample_min) Npoints_per_period_min = int( floor((1 / excitation.getFrequencyMax()) / dt)) #print(Npoints_per_period_min) repetition_min_1 = int( ceil((MIN_SAMPLINGTIME_MAXPERIOD_RATIO / excitation.getFrequencyMin()) / dt)) repetition_min_2 = int( ceil( (MIN_NFFT_POINTS_IN_EXCITATION_RANGE / (excitation.getFrequencyMax() - excitation.getFrequencyMin())) / dt)) #print(repetition_min_1) #print(repetition_min_2) first_min = starting_sample_min + max(repetition_min_1, repetition_min_2) #print(first_min) repetition = max([repetition_min_1, repetition_min_2] + REPETITION) starting_sample = max([starting_sample_min] + STARTING_SAMPLE) first = max([starting_sample + repetition] + FIRST) print('starting_sample = {}, first = {}, repetition = {}'.format( starting_sample, first, repetition)) #print('starting_sample = {}'.format(starting_sample)) #print('first = {}'.format(first)) #print('repetition = {}'.format(repetition)) # set up the volume box partial_box = SnapshotBoxVolume() # set up the XYZ box xyz_box = SnapshotBoxXYZ() xyz_box.setIntersectionPoint(excitation_location) # MV box size is chosen so that it will cover 1+2*47 = 95 mesh lines (we want Nsnaps<=99, but that includes 3 x/y/z snaps) xmesh = sim.getXmesh() (idx, val) = findNearestInSortedArray(xmesh, excitation_location[0], 0) MV_box_size = (xmesh[idx + 42] + xmesh[idx + 43]) / 2 - ( xmesh[idx - 42] + xmesh[idx - 43]) / 2 print('MV_box_size = {} = {}*sim.getSize()'.format( MV_box_size, MV_box_size / (sim.getSize()[0]))) # set up base frequency snapshot (we need two at the moment because one has full extension and the other one does not) fsnap_base_partial = FrequencySnapshot() fsnap_base_partial.setCentro(excitation_location) fsnap_base_partial.setSize([MV_box_size, MV_box_size, MV_box_size]) fsnap_base_partial.setPlaneOrientationX() fsnap_base_partial.setFullExtensionOn() fsnap_base_partial.setStartingSample(starting_sample) fsnap_base_partial.setFirst(first) fsnap_base_partial.setRepetition(repetition) fsnap_base_full = FrequencySnapshot() fsnap_base_full.setFromSnapshot(fsnap_base_partial) fsnap_base_full.setFullExtensionOn() #fsnap_base_full.setCentro(excitation_location) #fsnap_base_full.setSize(MV_box_size) #fsnap_base_full.setPlaneOrientationX() # custom snapshots fsnap_custom = FrequencySnapshot() fsnap_custom.setPlaneOrientationZ() fsnap_custom.setFullExtensionOn() fsnap_custom.setStartingSample(starting_sample) fsnap_custom.setFirst(first) fsnap_custom.setRepetition(repetition) f1 = copy.deepcopy(fsnap_custom) f1.setCentro([6.216506, 6.216506, 1.121651E+01]) f2 = copy.deepcopy(fsnap_custom) f2.setCentro([6.216506, 6.216506, 1.021651E+01]) f3 = copy.deepcopy(fsnap_custom) f3.setCentro([6.216506, 6.216506, 9.216510E+00]) f4 = copy.deepcopy(fsnap_custom) f4.setCentro([6.216506, 6.216506, 8.216510E+00]) f5 = copy.deepcopy(fsnap_custom) f5.setCentro([6.216506, 6.216506, 7.216510E+00]) # f6 = copy.deepcopy(fsnap_custom); f6.setCentro([6.216506,6.216506,6.216510E+00]) f7 = copy.deepcopy(fsnap_custom) f7.setCentro([6.216506, 6.216506, 5.216510E+00]) f8 = copy.deepcopy(fsnap_custom) f8.setCentro([6.216506, 6.216506, 4.216510E+00]) f9 = copy.deepcopy(fsnap_custom) f9.setCentro([6.216506, 6.216506, 3.216510E+00]) f10 = copy.deepcopy(fsnap_custom) f10.setCentro([6.216506, 6.216506, 2.216510E+00]) f11 = copy.deepcopy(fsnap_custom) f11.setCentro([6.216506, 6.216506, 1.216510E+00]) if direction == 'Ex': # create epsilon run outdir_epsilon = os.path.join(destdir, 'epsilon') print('outdir_epsilon = {}'.format(outdir_epsilon)) # set up base epsilon snapshots esnap_base_partial = EpsilonSnapshot() esnap_base_partial.setFromSnapshot(fsnap_base_partial) esnap_base_full = EpsilonSnapshot() esnap_base_full.setFromSnapshot(fsnap_base_full) #esnap_base_partial.setCentro(excitation_location) #esnap_base_partial.setSize(sim.getSize()/2) #esnap_base_partial.setPlaneOrientationY() ## set up base frequency snapshot #fsnap_base = FrequencySnapshot() #fsnap_base.setFromSnapshot(esnap_base) # attach base snapshots to boxes partial_box.setBaseSnapshot(esnap_base_partial) xyz_box.setBaseSnapshot(esnap_base_full) # add the snapshots sim.setSnapshots([partial_box, xyz_box]) # set up a short simulation sim.setIterations(1) sim.setWallTime(120) # write if not dry_run and not disabled_epsilon: sim.writeTorqueJobDirectory(outdir_epsilon, overwrite=overwrite) checkSnapshotNumber(os.path.join( outdir_epsilon, sim.getFileBaseName() + '.inp'), verbose=True) if direction not in disabled_directions: for freq_MHz in freq_MHz_list: print('freq_MHz = {}'.format(freq_MHz)) wavelength_mum = get_c0() / freq_MHz outdir_MV = os.path.join( destdir, direction, 'MV-freq-{:.0f}-MHz-lambda-{:.6f}-mum'.format( freq_MHz, wavelength_mum)) print('outdir_MV = {}'.format(outdir_MV)) # set snapshot frequency fsnap_base_partial.setFrequencies([freq_MHz]) fsnap_base_full.setFrequencies([freq_MHz]) fsnap_custom.setFrequencies([freq_MHz]) # attach base snapshots to boxes partial_box.setBaseSnapshot(fsnap_base_partial) xyz_box.setBaseSnapshot(fsnap_base_full) # add the snapshots sim.setSnapshots([ partial_box, xyz_box, f1, f2, f3, f4, f5, f7, f8, f9, f10, f11 ]) # set up a long simulation sim.setIterations(1e9) sim.setWallTime(360) # write if not dry_run: sim.writeTorqueJobDirectory(outdir_MV, overwrite=overwrite) checkSnapshotNumber(os.path.join( outdir_MV, sim.getFileBaseName() + '.inp'), verbose=True) return
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())
DSTDIR = '.' else: DSTDIR = tempfile.gettempdir() # various .geo parameters cubic_unit_cell_size = 1 # cubic unit cell size r_RCD = 0.1 # RCD cylinder radius n_RCD = 2 # RCD cylinder refractive index r_defect = 0.2 # defect radius n_defect = 3 # defect refractive index n_backfill = 1 # backfill index # various .inp parameters fmin_normalized = 0.514079 fmax_normalized = 0.55633 fmin = fmin_normalized * get_c0() / cubic_unit_cell_size fmax = fmax_normalized * get_c0() / cubic_unit_cell_size N_iterations = 5e6 walltime = 360 # X meshing parameters xmesh_Ncells_bottom = 1 xmesh_Ncells_RCD = 3 xmesh_Ncells_top = 1 # Y meshing parameters ymesh_Ncells_bottom = 1 ymesh_Ncells_RCD = 3 ymesh_Ncells_top = 1 # Z meshing parameters
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 __init__(self, name = None, current_source = None, P1 = None, P2 = None, E = None, H = None, Type = None, time_constant = None, amplitude = None, time_offset = None, frequency = None, param1 = None, param2 = None, template_filename = None, template_source_plane = None, template_target_plane = None, template_direction = None, template_rotation = None, layer = None, group = None): if name is None: name = 'excitation' if current_source is None: current_source = 7 if P1 is None: P1 = [0,0,0] if P2 is None: P2 = [0,0,0] if E is None: E = [1,0,0] if H is None: H = [0,0,0] if Type is None: Type = 10 if time_constant is None: time_constant = 4.000000E-09 #mus if amplitude is None: amplitude = 1.000000E+01 #V/mum??? if time_offset is None: time_offset = 2.700000E-08 #mus if frequency is None: frequency = get_c0() # in MHz, this corresponds to a wavelength of 1mum if param1 is None: param1 = 0 if param2 is None: param2 = 0 if template_source_plane is None: template_source_plane = 'x' if template_target_plane is None: template_target_plane = 'x' if template_direction is None: template_direction = 0 if template_rotation is None: template_rotation = 0 if layer is None: layer = 'excitation' if group is None: group = 'excitation' # read configuration options from a config file # if it does not exist, use defaults and create the config file config = configparser.ConfigParser({ 'SafetyChecks': 'True', 'AutoFix': 'True', }) configdir = os.path.join(utilities.getuserdir.getuserdir(), '.config', 'script_inception_public') os.makedirs(configdir, exist_ok=True) configfile_name = os.path.join(configdir, 'Excitation.ini') #print('configfile_name = ', configfile_name) configfiles_read = config.read(configfile_name) #print('configfiles_read = ', configfiles_read) self.SafetyChecks = config['DEFAULT'].getboolean('SafetyChecks') self.AutoFix = config['DEFAULT'].getboolean('AutoFix') if not configfiles_read: print('No config file found. Creating {}'.format(configfile_name)) with open(configfile_name, 'w') as configfile: config.write(configfile) self.name = name self.layer = layer self.group = group self.current_source = current_source self.P1 = P1 self.P2 = P2 self.E = E self.H = H self.Type = Type self.time_constant = time_constant self.amplitude = amplitude self.time_offset = time_offset self.frequency = frequency self.param1 = param1 self.param2 = param2 self.template_filename = template_filename self.template_source_plane = template_source_plane self.template_target_plane = template_target_plane self.template_direction = template_direction self.template_rotation = template_rotation self.meshing_parameters = MeshingParameters() self.fixLowerUpperAtWrite = True self.useForMeshing = True # set to False to disable use of this object during automeshing # .. todo:: deprecated, to be removed once a better safety/autofix system with adjustable reactions is put in place self.TimeOffsetSafetyBehaviour = 0
def write_entry(self, FILE=sys.stdout, AutoFix=True, SafetyChecks=True): ''' write entry into FILE .. todo:: reduce code duplication here .. todo:: Should fix+check functions be called from BFDTDobject? Or should fix+check args be passed to write_entry? or should object's AutoFix/SafetyChecks be modified from BFDTDobject? Every function should do one thing and do it well -> no fix+check in here Having fix+check in here reduces risk of accidental bad output writing -> fix+check should be in here Writing bad output should be made difficult, but not too difficult for testing purposes. ''' # autofix if AutoFix: self.fix() # safety checks if SafetyChecks: self.check() if self.current_source != 11: if self.fixLowerUpperAtWrite: self.P1, self.P2 = fixLowerUpper(self.P1, self.P2) FILE.write('EXCITATION **name={}\n'.format(self.getName())) FILE.write('{\n') FILE.write("{:d} ** CURRENT SOURCE\n".format(self.current_source)) FILE.write("{:E} **X1\n".format(self.P1[0])) FILE.write("{:E} **Y1\n".format(self.P1[1])) FILE.write("{:E} **Z1\n".format(self.P1[2])) FILE.write("{:E} **X2\n".format(self.P2[0])) FILE.write("{:E} **Y2\n".format(self.P2[1])) FILE.write("{:E} **Z2\n".format(self.P2[2])) FILE.write("{:d} **EX\n".format(self.E[0])) FILE.write("{:d} **EY\n".format(self.E[1])) FILE.write("{:d} **EZ\n".format(self.E[2])) FILE.write("{:d} **HX\n".format(self.H[0])) FILE.write("{:d} **HY\n".format(self.H[1])) FILE.write("{:d} **HZ\n".format(self.H[2])) FILE.write("{:d} **GAUSSIAN MODULATED SINUSOID\n".format(self.Type)) FILE.write("{:E} **TIME CONSTANT (mus if dimensions in mum)\n".format(self.getTimeConstant())) FILE.write("{:E} **AMPLITUDE\n".format(self.getAmplitude())) FILE.write("{:E} **TIME OFFSET (mus if dimensions in mum)\n".format(self.getTimeOffset())) FILE.write("{:E} **FREQUENCY (MHz if dimensions in mum) (c0/f = {:E})\n".format(self.getFrequency(), get_c0()/self.getFrequency())) FILE.write("{:E} **UNUSED PARAMETER\n".format(self.param1)) FILE.write("{:E} **UNUSED PARAMETER\n".format(self.param2)) if self.template_filename: # template specific # NOTE: Adding these template parameters seems to have no effect with current_source!=11, but it makes sense to not write them if no template_filename has been defined. FILE.write(addDoubleQuotesIfMissing(self.template_filename) + ' ** TEMPLATE FILENAME\n') FILE.write(addDoubleQuotesIfMissing(self.template_source_plane) + ' ** TEMPLATE SOURCE PLANE\n') FILE.write('}\n') FILE.write('\n') else: self.E = [1,1,1] self.H = [1,1,1] self.P1, self.P2 = fixLowerUpper(self.P1, self.P2) FILE.write('EXCITATION **name='+self.name+'\n') FILE.write('{\n') FILE.write("%d ** CURRENT SOURCE\n" % self.current_source) FILE.write("%E **X1\n" % self.P1[0]) FILE.write("%E **Y1\n" % self.P1[1]) FILE.write("%E **Z1\n" % self.P1[2]) FILE.write("%E **X2\n" % self.P2[0]) FILE.write("%E **Y2\n" % self.P2[1]) FILE.write("%E **Z2\n" % self.P2[2]) FILE.write("%d **EX\n" % self.E[0]) FILE.write("%d **EY\n" % self.E[1]) FILE.write("%d **EZ\n" % self.E[2]) FILE.write("%d **HX\n" % self.H[0]) FILE.write("%d **HY\n" % self.H[1]) FILE.write("%d **HZ\n" % self.H[2]) FILE.write("%d **GAUSSIAN MODULATED SINUSOID\n" % self.Type) FILE.write("%E **TIME CONSTANT\n" % self.time_constant) FILE.write("%E **AMPLITUDE\n" % self.amplitude) FILE.write("{:E} **TIME OFFSET\n".format(self.getTimeOffset())) FILE.write("%E **FREQUENCY (MHz if dimensions in mum) (c0/f = %E)\n" % (self.frequency, get_c0()/self.frequency)) FILE.write("%d **UNUSED PARAMETER\n" % self.param1) FILE.write("%d **UNUSED PARAMETER\n" % self.param2) if self.template_filename: # template specific FILE.write(addDoubleQuotesIfMissing(self.template_filename) + ' ** TEMPLATE FILENAME\n') FILE.write(addDoubleQuotesIfMissing(self.template_source_plane) + ' ** TEMPLATE SOURCE PLANE\n') FILE.write(addDoubleQuotesIfMissing(self.template_target_plane) + ' ** TEMPLATE TARGET PLANE\n') FILE.write("%d ** DIRECTION 0=-ve 1=+ve\n" % self.template_direction) FILE.write("%d ** ROTATE 0=no, 1=yes\n" % self.template_rotation) FILE.write('}\n') FILE.write('\n')
def getWavelength(self): return get_c0()/self.frequency
def getWavelengthMax(self): (fmin, fmax) = self.getFrequencyRange() return get_c0()/fmin
def setWavelengthRange(self, lambda_min, lambda_max): fmax = get_c0()/lambda_min fmin = get_c0()/lambda_max return self.setFrequencyRange(fmin, fmax)
def setWavelength(self, lambda_mum): self.frequency = get_c0()/lambda_mum