def test5(destdir): sim = BFDTDobject() S = sim.appendSnapshot(TimeSnapshot()) for plane in ['x', 'y', 'z']: for E in itertools.product(range(2), repeat=3): for H in itertools.product(range(2), repeat=3): for J in itertools.product(range(2), repeat=3): for power in [0, 1]: for eps in [0, 1]: print(plane, E, H, J, power, eps) S.setPlaneLetter(plane) S.setEfield(E) S.setHfield(H) S.setJfield(J) S.setPower(power) S.setEpsilon(eps) sim.runSimulation(destdir) #print(S) #print(S.getTypeBasedOnAttributes()) if S.getTypeBasedOnAttributes( ) == ModeFilteredProbe: outfile = 'i1_id_00.prn' else: outfile = plane + '1_id_01.prn' #print('outfile =', outfile) with open(os.path.join(destdir, outfile)) as f: print(f.readline()) #sim.writeTorqueJobDirectory(destdir) #sim.runSimulation(destdir) return
def test(): sim = BFDTDobject() sim.setSizeAndResolution([1, 1, 1], [200, 200, 200]) MV = sim.appendSnapshot(ModeVolumeBox()) #MV.setExtension(*sim.getExtension()) MV.setExtension([0.12, 0.45, 0.78], [0.88, 0.66, 0.99]) MV.setFrequencies([1]) MV.setPlaneOrientationX() generateInpAndPrnFiles('/tmp/MV_validation/', sim, example_function_1, example_function_2, example_function_3)
def loadInputFiles(self): self.BFDTD_object = BFDTDobject() for row in range(self.listWidget_InputFiles.count()): input_file = self.listWidget_InputFiles.item(row).text() self.BFDTD_object.readBristolFDTD(input_file) self.lineEdit_Ncells.setText('{}'.format( self.BFDTD_object.getNcells())) # populate the object list self.object_list = self.BFDTD_object.getObjects() self.comboBox_ObjectLocation.clear() self.comboBox_ObjectLocation.addItems( [i.getName() for i in self.object_list]) return
def test4(destdir): sim = BFDTDobject() S = sim.appendSnapshot(TimeSnapshot()) S.setEfield([0, 0, 0]) S.setHfield([0, 0, 0]) S.setJfield([0, 0, 0]) S.setPower(0) S.setEpsilon(0) print('=====') #print(S) subdir = '{}{}{}-{}{}{}-{}{}{}-{}-{}'.format(S.E[0], S.E[1], S.E[2], S.H[0], S.H[1], S.H[2], S.J[0], S.J[1], S.J[2], S.power, S.eps) print(subdir, S.getTypeBasedOnAttributes()) sim.runSimulation(os.path.join(destdir, subdir)) for i in range(11): (S.E[0], S.E[1], S.E[2], S.H[0], S.H[1], S.H[2], S.J[0], S.J[1], S.J[2], S.power, S.eps) = i * [0] + [1] + (10 - i) * [0] print('=====') subdir = '{}{}{}-{}{}{}-{}{}{}-{}-{}'.format(S.E[0], S.E[1], S.E[2], S.H[0], S.H[1], S.H[2], S.J[0], S.J[1], S.J[2], S.power, S.eps) print(subdir, S.getTypeBasedOnAttributes()) sim.runSimulation(os.path.join(destdir, subdir)) return
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 main(): ### basic setup of the simulation sim = BFDTDobject() sim.setExecutable('fdtd64_2014') sim.setIterations(1) S = [1, 2, 3] N = 3 * array([10, 20, 30]) sim.setSizeAndResolution(S, N) xblock = Block() xblock.setName('xblock') location = [0.750, 1.000, 1.500] dimensions = [0.500, 0.200, 0.200] xblock.setLocation(location) xblock.setSize(dimensions) xblock.setRelativePermittivity(2) yblock = Block() yblock.setName('yblock') location = [0.500, 1.500, 1.500] dimensions = [0.200, 1.000, 0.200] yblock.setLocation(location) yblock.setSize(dimensions) yblock.setRelativePermittivity(3) zblock = Block() zblock.setName('zblock') location = [0.500, 1.000, 2.250] dimensions = [0.200, 0.200, 1.500] zblock.setLocation(location) zblock.setSize(dimensions) zblock.setRelativePermittivity(4) sim.appendGeometryObject([xblock, yblock, zblock]) c = sim.getCentro() e = sim.appendExcitation(Excitation()) e.setExtension(c, c) e.setEx() ### various snapshot tests # A pythonic way to switch between just outputting the files and running them. #myfunc = sim.runSimulation myfunc = sim.writeAll # full MV box MV = ModeVolumeBoxFull() sim.setSnapshots([MV]) MV.setPlaneOrientationX() sim.setFileBaseName('MV-full-X') myfunc(sim.getFileBaseName()) MV.setPlaneOrientationY() sim.setFileBaseName('MV-full-Y') myfunc(sim.getFileBaseName()) MV.setPlaneOrientationZ() sim.setFileBaseName('MV-full-Z') myfunc(sim.getFileBaseName()) # MV box from lower to centre MV = ModeVolumeBox() MV.setExtension(sim.getLower(), sim.getCentro()) sim.setSnapshots([MV]) MV.setPlaneOrientationX() sim.setFileBaseName('MV-lower-to-centre-X') myfunc(sim.getFileBaseName()) MV.setPlaneOrientationY() sim.setFileBaseName('MV-lower-to-centre-Y') myfunc(sim.getFileBaseName()) MV.setPlaneOrientationZ() sim.setFileBaseName('MV-lower-to-centre-Z') myfunc(sim.getFileBaseName()) # MV box from centre to upper MV = ModeVolumeBox() MV.setExtension(sim.getCentro(), sim.getUpper()) sim.setSnapshots([MV]) MV.setPlaneOrientationX() sim.setFileBaseName('MV-centre-to-upper-X') myfunc(sim.getFileBaseName()) MV.setPlaneOrientationY() sim.setFileBaseName('MV-centre-to-upper-Y') myfunc(sim.getFileBaseName()) MV.setPlaneOrientationZ() sim.setFileBaseName('MV-centre-to-upper-Z') myfunc(sim.getFileBaseName()) # other sim.clearAllSnapshots() eps = sim.addEpsilonBox() eps.setPlaneOrientationX() sim.setFileBaseName('slice_x') #sim.writeAll(sim.getFileBaseName()) myfunc(sim.getFileBaseName()) eps.setPlaneOrientationY() sim.setFileBaseName('slice_y') myfunc(sim.getFileBaseName()) #sim.writeAll(sim.getFileBaseName()) #myfunc('.') eps.setPlaneOrientationZ() sim.setFileBaseName('slice_z') myfunc(sim.getFileBaseName()) #sim.writeAll(sim.getFileBaseName()) #myfunc('.') # smaller MV box: epsbox = EpsilonBox() epsbox.setPlaneOrientationY() epsbox.setCentro(c) epsbox.setSize(0.5 * sim.getSize()) sim.setSnapshots([epsbox]) epsbox.setPlaneOrientationX() sim.setFileBaseName('mini-box-centered-X') myfunc(sim.getFileBaseName()) epsbox.setPlaneOrientationY() sim.setFileBaseName('mini-box-centered-Y') myfunc(sim.getFileBaseName()) epsbox.setPlaneOrientationZ() sim.setFileBaseName('mini-box-centered-Z') myfunc(sim.getFileBaseName()) epsbox.setCentro(epsbox.getCentro() + array([1 / 4, 0, 0])) epsbox.setPlaneOrientationX() sim.setFileBaseName('mini-box-offset-X') #sim.writeAll(sim.getFileBaseName()) myfunc(sim.getFileBaseName()) epsbox.setPlaneOrientationY() sim.setFileBaseName('mini-box-offset-Y') #sim.writeAll(sim.getFileBaseName()) myfunc(sim.getFileBaseName()) epsbox.setPlaneOrientationZ() sim.setFileBaseName('mini-box-offset-Z') #sim.writeAll(sim.getFileBaseName()) myfunc(sim.getFileBaseName()) epsbox.setPlaneOrientationX() epsbox.setExtension(sim.getCentro(), sim.getExtension()[1]) sim.setFileBaseName('mini-box-centre-to-upper-X') myfunc(sim.getFileBaseName()) epsbox.setExtension(sim.getExtension()[0], sim.getCentro()) sim.setFileBaseName('mini-box-lower-to-centre-X') myfunc(sim.getFileBaseName()) epsbox.setPlaneOrientationY() epsbox.setExtension(sim.getCentro(), sim.getExtension()[1]) sim.setFileBaseName('mini-box-centre-to-upper-Y') myfunc(sim.getFileBaseName()) epsbox.setExtension(sim.getExtension()[0], sim.getCentro()) sim.setFileBaseName('mini-box-lower-to-centre-Y') myfunc(sim.getFileBaseName()) epsbox.setPlaneOrientationZ() epsbox.setExtension(sim.getCentro(), sim.getExtension()[1]) sim.setFileBaseName('mini-box-centre-to-upper-Z') myfunc(sim.getFileBaseName()) epsbox.setExtension(sim.getExtension()[0], sim.getCentro()) sim.setFileBaseName('mini-box-lower-to-centre-Z') myfunc(sim.getFileBaseName()) #myfunc('.') #sim.clearAllSnapshots() #eps_full = sim.appendSnapshot(EpsilonSnapshot()) #eps_partial = sim.appendSnapshot(EpsilonSnapshot()) #sim.setFileBaseName('full_vs_partial') #myfunc(sim.getFileBaseName()) return 0
def __init__(self): super(BFDTDtoolMainWindow, self).__init__() # Set up the user interface from Designer. self.setupUi(self) # Connect up the buttons. self.pushButton_addInputFiles.clicked.connect(self.addInputFiles) self.pushButton_removeInputFiles.clicked.connect(self.removeInputFiles) self.pushButton_moveInputFileUp.clicked.connect(self.moveInputFileUp) self.pushButton_moveInputFileDown.clicked.connect( self.moveInputFileDown) self.pushButton_loadInputFiles.clicked.connect(self.loadInputFiles) self.actionSaveConfig.triggered.connect(self.SaveConfig) self.actionSaveConfigAs.triggered.connect(self.SaveConfigAs) self.actionLoadConfig.triggered.connect(self.LoadConfig) self.pushButton_AddFrequency.clicked.connect( self.AddFrequencyButtonClicked) self.pushButton_AddFrequencyFromFrequencyList.clicked.connect( self.AddFrequencyFromFrequencyList) self.pushButton_AddFrequencyFromInpFile.clicked.connect( self.AddFrequencyFromInpFile) self.pushButton_RemoveFrequency.clicked.connect(self.RemoveFrequency) self.pushButton_moveFrequencyUp.clicked.connect(self.moveFrequencyUp) self.pushButton_moveFrequencyDown.clicked.connect( self.moveFrequencyDown) self.pushButton_clearFrequencyList.clicked.connect( self.clearFrequencyList) self.pushButton_SelectOutputDirectory.clicked.connect( self.SelectOutputDirectory) self.comboBox_ObjectLocation.currentIndexChanged.connect( self.updateLocation) self.pushButton_Run.clicked.connect(self.Run) self.radioButton_ObjectLocation.toggled.connect( self.radioButton_ObjectLocation_toggled) self.ignoreChange = False self.tableWidget_Frequencies.cellChanged.connect(self.FreqTableChanged) self.tableWidget_Frequencies.verticalHeader().setSectionsMovable(True) #self.model_InputFiles = FileListModel(self) self.BFDTD_object = BFDTDobject() self.object_list = [] self.ConfigFileName = None # default directories for the various filedialogs self.default_dir_InputDir = os.path.expanduser("~") self.default_dir_Config = os.path.expanduser("~") self.default_dir_OutputDir = os.path.expanduser("~") #self.model_InputFiles = QStringListModel(self) #self.listView_InputFiles.setModel(self.model_InputFiles) #item = QtWidgets.QListWidgetItem() #self.listWidget_InputFiles.addItem(item) #item = QtWidgets.QListWidgetItem() #self.listWidget_InputFiles.addItem(item) #item = QtWidgets.QListWidgetItem() #item.setText('ROFFLLOLLOOL') #self.listWidget_InputFiles.addItem(item) #self.listWidget_InputFiles.addItems(['jijuijij', '454654', 'jijfsdfsdij']) #__sortingEnabled = self.listWidget_InputFiles.isSortingEnabled() #self.listWidget_InputFiles.setSortingEnabled(False) #item = self.listWidget_InputFiles.item(0) #item.setText(_translate("MainWindow", "New Item")) #item = self.listWidget_InputFiles.item(1) #item.setText(_translate("MainWindow", "gdf")) #item = self.listWidget_InputFiles.item(2) #item.setText(_translate("MainWindow", "New gdfg")) #self.listWidget_InputFiles.setSortingEnabled(__sortingEnabled) #lol = QListWidgetItem("Sycamore", self.listView_InputFiles); #QListWidgetItem("Chestnut"), listWidget); #QListWidgetItem("Mahogany"), listWidget); #QListWidgetItem *newItem = new QListWidgetItem; #newItem->setText(itemText); #listWidget->insertItem(row, newItem); self.readSettings()
class BFDTDtoolMainWindow(QMainWindow, Ui_MainWindow): def __init__(self): super(BFDTDtoolMainWindow, self).__init__() # Set up the user interface from Designer. self.setupUi(self) # Connect up the buttons. self.pushButton_addInputFiles.clicked.connect(self.addInputFiles) self.pushButton_removeInputFiles.clicked.connect(self.removeInputFiles) self.pushButton_moveInputFileUp.clicked.connect(self.moveInputFileUp) self.pushButton_moveInputFileDown.clicked.connect( self.moveInputFileDown) self.pushButton_loadInputFiles.clicked.connect(self.loadInputFiles) self.actionSaveConfig.triggered.connect(self.SaveConfig) self.actionSaveConfigAs.triggered.connect(self.SaveConfigAs) self.actionLoadConfig.triggered.connect(self.LoadConfig) self.pushButton_AddFrequency.clicked.connect( self.AddFrequencyButtonClicked) self.pushButton_AddFrequencyFromFrequencyList.clicked.connect( self.AddFrequencyFromFrequencyList) self.pushButton_AddFrequencyFromInpFile.clicked.connect( self.AddFrequencyFromInpFile) self.pushButton_RemoveFrequency.clicked.connect(self.RemoveFrequency) self.pushButton_moveFrequencyUp.clicked.connect(self.moveFrequencyUp) self.pushButton_moveFrequencyDown.clicked.connect( self.moveFrequencyDown) self.pushButton_clearFrequencyList.clicked.connect( self.clearFrequencyList) self.pushButton_SelectOutputDirectory.clicked.connect( self.SelectOutputDirectory) self.comboBox_ObjectLocation.currentIndexChanged.connect( self.updateLocation) self.pushButton_Run.clicked.connect(self.Run) self.radioButton_ObjectLocation.toggled.connect( self.radioButton_ObjectLocation_toggled) self.ignoreChange = False self.tableWidget_Frequencies.cellChanged.connect(self.FreqTableChanged) self.tableWidget_Frequencies.verticalHeader().setSectionsMovable(True) #self.model_InputFiles = FileListModel(self) self.BFDTD_object = BFDTDobject() self.object_list = [] self.ConfigFileName = None # default directories for the various filedialogs self.default_dir_InputDir = os.path.expanduser("~") self.default_dir_Config = os.path.expanduser("~") self.default_dir_OutputDir = os.path.expanduser("~") #self.model_InputFiles = QStringListModel(self) #self.listView_InputFiles.setModel(self.model_InputFiles) #item = QtWidgets.QListWidgetItem() #self.listWidget_InputFiles.addItem(item) #item = QtWidgets.QListWidgetItem() #self.listWidget_InputFiles.addItem(item) #item = QtWidgets.QListWidgetItem() #item.setText('ROFFLLOLLOOL') #self.listWidget_InputFiles.addItem(item) #self.listWidget_InputFiles.addItems(['jijuijij', '454654', 'jijfsdfsdij']) #__sortingEnabled = self.listWidget_InputFiles.isSortingEnabled() #self.listWidget_InputFiles.setSortingEnabled(False) #item = self.listWidget_InputFiles.item(0) #item.setText(_translate("MainWindow", "New Item")) #item = self.listWidget_InputFiles.item(1) #item.setText(_translate("MainWindow", "gdf")) #item = self.listWidget_InputFiles.item(2) #item.setText(_translate("MainWindow", "New gdfg")) #self.listWidget_InputFiles.setSortingEnabled(__sortingEnabled) #lol = QListWidgetItem("Sycamore", self.listView_InputFiles); #QListWidgetItem("Chestnut"), listWidget); #QListWidgetItem("Mahogany"), listWidget); #QListWidgetItem *newItem = new QListWidgetItem; #newItem->setText(itemText); #listWidget->insertItem(row, newItem); self.readSettings() def radioButton_ObjectLocation_toggled(self, checked): if checked: self.lineEdit_X.setReadOnly(True) self.lineEdit_Y.setReadOnly(True) self.lineEdit_Z.setReadOnly(True) self.updateLocation() else: self.lineEdit_X.setReadOnly(False) self.lineEdit_Y.setReadOnly(False) self.lineEdit_Z.setReadOnly(False) return 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 addInputFiles(self): print('self.default_dir_InputDir = {}'.format( self.default_dir_InputDir)) (files_to_add, selected_filter) = QtWidgets.QFileDialog.getOpenFileNames( parent=self, caption='Add BFDTD input files', filter='BFDTD input files (*.in *.geo *.inp);; All Files(*)', directory=self.default_dir_InputDir) if files_to_add: print('Setting self.default_dir_InputDir to {}'.format( files_to_add[0])) self.default_dir_InputDir = files_to_add[0] print('self.default_dir_InputDir = {}'.format( self.default_dir_InputDir)) if not self.checkBox_DirectLoad.isChecked(): self.listWidget_InputFiles.addItems(files_to_add) else: self.listWidget_InputFiles.clear() self.listWidget_InputFiles.addItems(files_to_add) self.loadInputFiles() #for i in files_to_add: #item = QtWidgets.QListWidgetItem() #item.setText(i) #self.listWidget_InputFiles.addItem(item) #print((files_to_add, dirname)) #self.model_InputFiles.setStringList(files_to_add) #self.model_InputFiles.addInputFiles(files_to_add) def removeInputFiles(self): #print('A') #self.listWidget_InputFiles.selectedItems() #print('B') for i in self.listWidget_InputFiles.selectedItems(): self.listWidget_InputFiles.takeItem( self.listWidget_InputFiles.row(i)) #self.listWidget_InputFiles.removeItemWidget(self.listWidget_InputFiles.currentItem()) #index = self.listView_InputFiles.selectionModel().currentIndex() #model = self.listView_InputFiles.model() #print(index) #print(index.row()) #if (model.removeRow(index.row(), index.parent())): #print('YIPPIKAYAY!!!') ##self.updateActions() def moveInputFileUp(self): current_selection = self.listWidget_InputFiles.selectedItems() selected_rows = [] for item in current_selection: selected_rows.append(self.listWidget_InputFiles.row(item)) selected_rows.sort(reverse=False) for row in selected_rows: item = self.listWidget_InputFiles.takeItem(row) self.listWidget_InputFiles.insertItem(row - 1, item) self.listWidget_InputFiles.setCurrentItem( item, QItemSelectionModel.SelectCurrent) #current_selection = self.listWidget_InputFiles.selectedItems() #for i in current_selection: #current_row = self.listWidget_InputFiles.row(i) #item = self.listWidget_InputFiles.takeItem(current_row) #self.listWidget_InputFiles.insertItem(current_row-1, item) #self.listWidget_InputFiles.setCurrentItem(item, QItemSelectionModel.SelectCurrent) return def moveInputFileDown(self): current_selection = self.listWidget_InputFiles.selectedItems() selected_rows = [] for item in current_selection: selected_rows.append(self.listWidget_InputFiles.row(item)) selected_rows.sort(reverse=True) for row in selected_rows: item = self.listWidget_InputFiles.takeItem(row) self.listWidget_InputFiles.insertItem(row + 1, item) self.listWidget_InputFiles.setCurrentItem( item, QItemSelectionModel.SelectCurrent) #current_row = self.listWidget_InputFiles.row(i) #print((current_row, i.text())) #item = self.listWidget_InputFiles.takeItem(current_row) #self.listWidget_InputFiles.insertItem(current_row+1, item) #self.listWidget_InputFiles.setCurrentItem(item, QItemSelectionModel.SelectCurrent) return def loadInputFiles(self): self.BFDTD_object = BFDTDobject() for row in range(self.listWidget_InputFiles.count()): input_file = self.listWidget_InputFiles.item(row).text() self.BFDTD_object.readBristolFDTD(input_file) self.lineEdit_Ncells.setText('{}'.format( self.BFDTD_object.getNcells())) # populate the object list self.object_list = self.BFDTD_object.getObjects() self.comboBox_ObjectLocation.clear() self.comboBox_ObjectLocation.addItems( [i.getName() for i in self.object_list]) return def updateLocation(self, index=None): if index is None: index = self.comboBox_ObjectLocation.currentIndex() if self.radioButton_ObjectLocation.isChecked(): if 0 <= index and index < len(self.object_list): print((index, len(self.object_list))) obj = self.object_list[index] loc = obj.getLocation() print(loc) self.lineEdit_X.setText(str(loc[0])) self.lineEdit_Y.setText(str(loc[1])) self.lineEdit_Z.setText(str(loc[2])) return def writeSettings(self, filename=None): if filename is None: settings = QSettings() else: settings = QSettings(filename, QSettings.IniFormat) settings.setValue("Niterations", self.spinBox_Niterations.value()) settings.setValue("Walltime", self.spinBox_Walltime.value()) Executable_List = [ self.comboBox_Executable.itemText(i) for i in range(self.comboBox_Executable.count()) ] settings.setValue("Executable_List", Executable_List) settings.setValue("Executable_Index", self.comboBox_Executable.currentIndex()) settings.setValue("BaseName", self.lineEdit_BaseName.text()) settings.setValue("OutputDirectory", self.lineEdit_OutputDirectory.text()) settings.setValue("lineEdit_X", self.lineEdit_X.text()) settings.setValue("lineEdit_Y", self.lineEdit_Y.text()) settings.setValue("lineEdit_Z", self.lineEdit_Z.text()) settings.setValue("DirectLoad", self.checkBox_DirectLoad.isChecked()) settings.setValue("Verbosity", self.spinBox_Verbosity.value()) settings.setValue("StartingSample", self.spinBox_StartingSample.value()) settings.setValue("First", self.spinBox_First.value()) settings.setValue("Repetition", self.spinBox_Repetition.value()) settings.setValue("Operation", self.comboBox_Operation.currentIndex()) settings.setValue("ObjectLocation", self.comboBox_ObjectLocation.currentIndex()) settings.setValue("ArbitraryLocation", self.radioButton_ArbitraryLocation.isChecked()) settings.setValue("default_dir_Config", self.default_dir_Config) settings.setValue("default_dir_InputDir", self.default_dir_InputDir) settings.setValue("default_dir_OutputDir", self.default_dir_OutputDir) #self.radioButton_ObjectLocation.isChecked() def readSettings(self, filename=None): if filename is None: settings = QSettings() else: settings = QSettings(filename, QSettings.IniFormat) self.spinBox_Niterations.setValue(int(settings.value("Niterations", 1))) self.spinBox_Walltime.setValue(int(settings.value("Walltime", 1))) Executable_List = settings.value("Executable_List", [ 'fdtd64_2003', 'fdtd64_2008', 'fdtd64_2013', 'fdtd64_2013_dispersive', 'fdtd64_withRotation' ]) self.comboBox_Executable.clear() self.comboBox_Executable.addItems(Executable_List) self.comboBox_Executable.setCurrentIndex( int(settings.value("Executable_Index", 2))) self.lineEdit_BaseName.setText(settings.value("BaseName", 'sim')) self.lineEdit_OutputDirectory.setText( settings.value("OutputDirectory", tempfile.gettempdir())) self.lineEdit_X.setText(settings.value("lineEdit_X", '0')) self.lineEdit_Y.setText(settings.value("lineEdit_Y", '0')) self.lineEdit_Z.setText(settings.value("lineEdit_Z", '0')) self.checkBox_DirectLoad.setChecked( settings.value("DirectLoad", False, type=bool)) self.spinBox_Verbosity.setValue( settings.value("Verbosity", 0, type=int)) self.spinBox_StartingSample.setValue( settings.value("StartingSample", 1, type=int)) self.spinBox_First.setValue(settings.value("First", 1, type=int)) self.spinBox_Repetition.setValue( settings.value("Repetition", 1, type=int)) self.comboBox_Operation.setCurrentIndex( settings.value("Operation", 0, type=int)) self.comboBox_ObjectLocation.setCurrentIndex( settings.value("ObjectLocation", 0, type=int)) self.radioButton_ArbitraryLocation.setChecked( settings.value("ArbitraryLocation", False, type=bool)) self.radioButton_ObjectLocation.setChecked(not ( settings.value("ArbitraryLocation", False, type=bool))) self.default_dir_Config = settings.value("default_dir_Config", os.path.expanduser("~")) self.default_dir_InputDir = settings.value("default_dir_InputDir", os.path.expanduser("~")) self.default_dir_OutputDir = settings.value("default_dir_OutputDir", os.path.expanduser("~")) def closeEvent(self, event): print('Exiting 1') self.writeSettings() print('Exiting 2') event.accept() return def SaveConfig(self): """ what to do when the save button is clicked """ if not self.ConfigFileName: self.SaveConfigAs() else: try: self.writeSettings(self.ConfigFileName) except: QtGui.QMessageBox.critical( self, "Critical", "Couldn't write to file {0}".format( os.path.abspath(self.ConfigFileName))) def SaveConfigAs(self): """ what to do when the save as button is clicked """ # TODO: Use custom dialog with default suffix (use setDefaultSuffix()) (filename, directory) = QFileDialog.getSaveFileName( caption='Save configuration', directory=self.default_dir_Config) if filename: self.default_dir_Config = filename self.ConfigFileName = filename self.SaveConfig() def LoadConfig(self): """ handle load button pressed """ (filename, directory) = QFileDialog.getOpenFileName( caption='Load configuration', directory=self.default_dir_Config) if filename: self.default_dir_Config = filename self.ConfigFileName = filename self.readSettings(self.ConfigFileName) def SelectOutputDirectory(self): options = QFileDialog.ShowDirsOnly directory = QFileDialog.getExistingDirectory( self, "Select output directory", options=options, directory=self.default_dir_OutputDir) if directory: self.default_dir_OutputDir = directory self.lineEdit_OutputDirectory.setText(directory) return # TODO: Get sorting by numbers (not string) to work. # TODO: Get validators to work. # TODO: Get drag and drop of rows to work # TODO: spreadsheet/.csv import/export/drag-drop # TODO: Fix incorrect exiting. Sometimes the process just stays active after closing the window, sometimes, there is this error: # *** glibc detected *** python3: malloc(): memory corruption: 0x00000000023d3cb0 *** def AddFrequencyButtonClicked(self): self.AddFrequency() def AddFrequency(self, freq=None, wavelength=None, comment=''): self.tableWidget_Frequencies.setSortingEnabled(False) self.tableWidget_Frequencies.insertRow( self.tableWidget_Frequencies.rowCount()) if freq is None: freq = self.tableWidget_Frequencies.rowCount() if wavelength is None: wavelength = self.tableWidget_Frequencies.rowCount() row_contents = [float(freq), float(wavelength), str(comment)] setRow(self.tableWidget_Frequencies, self.tableWidget_Frequencies.rowCount() - 1, row_contents) #self.tableWidget_Frequencies. #self.tableWidget_Frequencies.setRowCount(self.tableWidget_Frequencies.rowCount()+1) #self.tableWidget_Frequencies.setItem(self.tableWidget_Frequencies.rowCount()-1, 0, QTableWidgetItem(str(self.tableWidget_Frequencies.rowCount()-1), type=float) ) #self.tableWidget_Frequencies.setItem(self.tableWidget_Frequencies.rowCount()-1, 1, QTableWidgetItem(str(self.tableWidget_Frequencies.rowCount()-1), type=float) ) #self.tableWidget_Frequencies.setItem(self.tableWidget_Frequencies.rowCount()-1, 0, QTableWidgetItem(QVariant.Double) ) #self.tableWidget_Frequencies.setItem(self.tableWidget_Frequencies.rowCount()-1, 1, QTableWidgetItem(QVariant.Double) ) #freq_item = QTableWidgetItem() #wavelength_item = QTableWidgetItem() #freq_item.setData(Qt.DisplayRole, freq) #wavelength_item.setData(Qt.DisplayRole, wavelength) #self.tableWidget_Frequencies.setItem(self.tableWidget_Frequencies.rowCount()-1, 0, freq_item ) #self.tableWidget_Frequencies.setItem(self.tableWidget_Frequencies.rowCount()-1, 1, wavelength_item ) self.tableWidget_Frequencies.setSortingEnabled(True) return 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 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 RemoveFrequency(self): current_selection = self.tableWidget_Frequencies.selectedItems() selected_rows = set() for item in current_selection: selected_rows.add(self.tableWidget_Frequencies.row(item)) selected_rows = list(selected_rows) selected_rows.sort(reverse=True) print(selected_rows) for row in selected_rows: self.tableWidget_Frequencies.removeRow(row) return def moveFrequencyUp(self): current_selection = self.tableWidget_Frequencies.selectedItems() selected_rows = set() for item in current_selection: selected_rows.add(self.tableWidget_Frequencies.row(item)) selected_rows = list(selected_rows) selected_rows.sort(reverse=False) print(selected_rows) for row in selected_rows: if row > 0: row_contents = getRow(self.tableWidget_Frequencies, row) self.tableWidget_Frequencies.removeRow(row) self.tableWidget_Frequencies.insertRow(row - 1) setRow(self.tableWidget_Frequencies, row - 1, row_contents) selectRow(self.tableWidget_Frequencies, row - 1) return #item = self.tableWidget_Frequencies.item(row-1, 0) #self.tableWidget_Frequencies.setCurrentItem(item, QItemSelectionModel.SelectCurrent) #myrange = QTableWidgetSelectionRange(row-1, 0, row-1, self.tableWidget_Frequencies.columnCount()) #self.tableWidget_Frequencies.setRangeSelected(myrange, True) #myrange = QTableWidgetSelectionRange(0, 0, self.tableWidget_Frequencies.rowCount(), self.tableWidget_Frequencies.columnCount()) #self.tableWidget_Frequencies.setRangeSelected(myrange, True) #return #row_contents = getRow(table_widget, row) #item(row,0) #insertRow(row-1) #removeRow(row) #return #self.tableWidget_Frequencies.rowMoved(0, 0, 1) #return #current_selection = self.tableWidget_Frequencies.selectedItems() #selected_rows = set() #for item in current_selection: #selected_rows.add(self.tableWidget_Frequencies.row(item)) #selected_rows = list(selected_rows) #print(selected_rows) #selected_rows.sort(reverse=False) #for row in selected_rows: #item = self.tableWidget_Frequencies.takeItem(row, 0) #self.tableWidget_Frequencies.insertRow(row-1) #self.tableWidget_Frequencies.insertItem(row-1, item) #self.tableWidget_Frequencies.setCurrentItem(item, QItemSelectionModel.SelectCurrent) #return def moveFrequencyDown(self): current_selection = self.tableWidget_Frequencies.selectedItems() selected_rows = set() for item in current_selection: selected_rows.add(self.tableWidget_Frequencies.row(item)) selected_rows = list(selected_rows) selected_rows.sort(reverse=True) print(selected_rows) for row in selected_rows: if row < self.tableWidget_Frequencies.rowCount() - 1: row_contents = getRow(self.tableWidget_Frequencies, row) self.tableWidget_Frequencies.removeRow(row) self.tableWidget_Frequencies.insertRow(row + 1) setRow(self.tableWidget_Frequencies, row + 1, row_contents) selectRow(self.tableWidget_Frequencies, row + 1) return def clearFrequencyList(self): self.tableWidget_Frequencies.setRowCount(0) #self.tableWidget_Frequencies.clearContents() #self.tableWidget_Frequencies.clearContents() return def Run(self): # general settings self.BFDTD_object.setWallTime(self.spinBox_Walltime.value()) self.BFDTD_object.setIterations(self.spinBox_Niterations.value()) self.BFDTD_object.setExecutable(self.comboBox_Executable.currentText()) self.BFDTD_object.setFileBaseName(self.lineEdit_BaseName.text()) # checkbox operations if self.checkBox_removeProbes.isChecked(): self.BFDTD_object.clearProbes() if self.checkBox_removeTimeAndEpsilonSnapshots.isChecked(): self.BFDTD_object.clearTimeSnapshots() self.BFDTD_object.clearEpsilonSnapshots() if self.checkBox_removeFrequencySnapshots.isChecked(): self.BFDTD_object.clearFrequencySnapshots() if self.checkBox_removeGeometryObjects.isChecked(): self.BFDTD_object.clearGeometry() if self.checkBox_clearFileList.isChecked(): self.BFDTD_object.clearFileList() #clearGeometry() #clearProbes() #clearFileList() #clearTimeSnapshots() #clearFrequencySnapshots() #clearEpsilonSnapshots() #clearModeFilteredProbes() #clearAllSnapshots() # operation specific handling if self.comboBox_Operation.currentIndex() == 0: print('Adding central snapshots') # get location location = [ float(self.lineEdit_X.text()), float(self.lineEdit_Y.text()), float(self.lineEdit_Z.text()) ] # get frequency list freqlist = [ float(self.tableWidget_Frequencies.item(i, 0).text()) for i in range(self.tableWidget_Frequencies.rowCount()) ] print(location) print(freqlist) self.BFDTD_object.addCentralXYZSnapshots(location, freqlist, withEpsilon=True) # write files try: self.BFDTD_object.writeTorqueJobDirectory( self.lineEdit_OutputDirectory.text(), overwrite=False) except UserWarning as err: reply = QMessageBox.question( self, "WARNING", err.args[0] + '\n\nOne or more of the files to be written already exists in the specified destination directory.\nDo you want to proceed anyway, overwriting them?', QMessageBox.Yes | QMessageBox.No) if reply == QMessageBox.Yes: self.BFDTD_object.writeTorqueJobDirectory( self.lineEdit_OutputDirectory.text(), overwrite=True) except: QMessageBox.critical( self, 'Unexpected error', '{}: {}\n\nTraceback:\n{}'.format(sys.exc_info()[0].__name__, sys.exc_info()[1], sys.exc_info()[2])) return
Ny = int((dim_y / norm(v) + 1) / 2) Nz = int((dim_z / norm(w) + 1) / 2) # if you want a specific number of unit-cells #Nx = 2 #Ny = 2 #Nz = 2 # print out number of periods print('Nx={} Ny={} Nz={}'.format(Nx, Ny, Nz)) # create the desired array RCD.createRectangularArraySymmetrical(Nx, Ny, Nz) # create a BFDTDobject sim = BFDTDobject() sim.setDefaultRefractiveIndex(n_backfill) sim.setSizeAndResolution( [dim_x + 2 * buffer_x, dim_y + 2 * buffer_y, dim_z + 2 * buffer_z], [1, 1, 1]) sim.appendGeometryObject(RCD) # centre the RCD object in the simulation box RCD.setLocation(sim.box.getCentro()) # get and remove the defect idx_defect = RCD.getIndexOf(0, 0, 0, 'G2', 0) geo_list = RCD.getGeoList() defect = geo_list.pop(idx_defect) # modify the defect
def generate_MV_refs_LowIndexCavity(destdir): sim = BFDTDobject() sim.disableSafetyChecks() #sim.setSizeAndResolution([1,1,1], [100, 90, 80]) sim.setSizeAndResolution([10, 10, 10], [100, 100, 100], False) Niterations = sim.setIterations( 1, AfterSources=True ) # adds default excitation + appropriate sim time + 1 iteration print('Niterations = {}'.format(Niterations)) MV = sim.appendSnapshot(ModeVolumeBoxFull()) MV.setPlaneOrientationZ() # current default in calcMV script... myfunc_low = lambda x, y, z, t: gaussian3D(x, y, z, t, centro=sim.getCentro(), epsilon_outside=10, epsilon_inside=1) myfunc_equal = lambda x, y, z, t: gaussian3D(x, y, z, t, centro=sim.getCentro(), epsilon_outside=1, epsilon_inside=1) myfunc_high = lambda x, y, z, t: gaussian3D(x, y, z, t, centro=sim.getCentro(), epsilon_outside=1, epsilon_inside=10) subdir = os.path.join(destdir, 'low_index') sim.writeTorqueJobDirectory(subdir) sim.sampleFunction(myfunc_low, subdir) subdir = os.path.join(destdir, 'equal_index') sim.writeTorqueJobDirectory(subdir) sim.sampleFunction(myfunc_equal, subdir) subdir = os.path.join(destdir, 'high_index') sim.writeTorqueJobDirectory(subdir) sim.sampleFunction(myfunc_high, subdir) return
def generate_MV_refs(destdir): ''' .. todo:: Warn if using to many snapshots to avoid BFDTD output mess. ''' sim = BFDTDobject() sim.disableSafetyChecks() #sim.setSizeAndResolution([1,1,1], [100, 90, 80]) sim.setSizeAndResolution([10, 5, 4], [5, 5, 5], True) Niterations = sim.setIterations( 1, AfterSources=True ) # adds default excitation + appropriate sim time + 1 iteration print('Niterations = {}'.format(Niterations)) #sim.setSizeAndResolution([10, 4, 4], [5,5,5], True) #mesh = sim.getMesh() #mesh.setXmesh(linspaces([0, 0.2, 0.5, 0.7, 1], [20, 30, 40, 50])) #mesh.setYmesh(linspaces([0, 0.25, 0.52, 0.67, 1], [60, 31, 42, 51])) #mesh.setZmesh(linspaces([0, 0.23, 0.6, 0.75, 1], [22, 33, 44, 55])) #mesh.setXmesh(linspaces([0, 0.2, 0.5, 0.7, 1], [21, 22, 23, 24])) #mesh.setYmesh(linspaces([0, 0.25, 0.52, 0.67, 1], [25, 26, 27, 28])) #mesh.setZmesh(linspaces([0, 0.23, 0.6, 0.75, 1], [29, 30, 31, 42])) #sim.setSizeAndResolution([1,1,1], [5,5,5]) #sim.setSizeAndResolution([1,1,1], [53,5,5]) #sim.setSizeAndResolution([1,1,1], [438,1,1]) #sim.setSizeAndResolution([1,1,1], [40, 50, 60]) #sim.setSizeAndResolution([2,3,1], [100, 100, 100]) #sim.setSizeAndResolution([1,1,1], [20, 30, 40]) MV = sim.appendSnapshot(ModeVolumeBoxFull()) #MV.setWavelengths(0.637) MV.setWavelengths(0.250) test_function_list = [ #('example_function_0', example_function_0), #('example_function_1', example_function_1), #('example_function_2', example_function_2), #('example_function_3', example_function_3), #('example_function_4', example_function_4), #('example_function_5', example_function_5), #('example_function_6', example_function_6), #('example_function_7', example_function_7), ('UniverseIsFullOfBalls', UniverseIsFullOfBalls), ] for test_function_name, test_function in test_function_list: print('===>', test_function_name, test_function) MV.setPlaneOrientationX() subdir = os.path.join(destdir, test_function_name, 'X') sim.writeTorqueJobDirectory(subdir) sim.sampleFunction(test_function, subdir) MV.setPlaneOrientationY() subdir = os.path.join(destdir, test_function_name, 'Y') sim.writeTorqueJobDirectory(subdir) sim.sampleFunction(test_function, subdir) MV.setPlaneOrientationZ() subdir = os.path.join(destdir, test_function_name, 'Z') sim.writeTorqueJobDirectory(subdir) sim.sampleFunction(test_function, subdir) return
def generate_MV_refs_partial(destdir): sim = BFDTDobject() sim.setSizeAndResolution([1, 1, 1], [4, 4, 4]) MV = sim.appendSnapshot(ModeVolumeBox()) mx = sim.getXmesh() my = sim.getYmesh() mz = sim.getZmesh() #test_function_name = 'example_function_0' #test_function = example_function_0 MV.setPlaneOrientationZ() #subdir = os.path.join(destdir, test_function_name, 'Z') MV.setExtension([mx[1], my[1], mz[0]], [mx[-2], my[-2], mz[-1]]) subdir = os.path.join(destdir, 'partial-centro', 'Z') sim.runSimulation(subdir) MV.setExtension([mx[0], my[0], mz[0]], [mx[-2], my[-2], mz[-1]]) subdir = os.path.join(destdir, 'partial-bottom-left', 'Z') sim.runSimulation(subdir) MV.setExtension([mx[1], my[0], mz[0]], [mx[-1], my[-2], mz[-1]]) subdir = os.path.join(destdir, 'partial-bottom-right', 'Z') sim.runSimulation(subdir) MV.setExtension([mx[0], my[1], mz[0]], [mx[-2], my[-1], mz[-1]]) subdir = os.path.join(destdir, 'partial-top-left', 'Z') sim.runSimulation(subdir) MV.setExtension([mx[1], my[1], mz[0]], [mx[-1], my[-1], mz[-1]]) subdir = os.path.join(destdir, 'partial-top-right', 'Z') sim.runSimulation(subdir) MV.setExtension([mx[0], my[0], mz[0]], [mx[-1], my[-1], mz[-1]]) subdir = os.path.join(destdir, 'full', 'Z') sim.runSimulation(subdir) #sim.writeTorqueJobDirectory(subdir) #sim.sampleFunction(test_function, subdir) return
def test3(destdir): # generate all possible time snapshot columns sim = BFDTDobject() sim.appendProbe(2 * [Probe()]) sim.appendSnapshot(3 * [FrequencySnapshot()]) sim.appendSnapshot(4 * [TimeSnapshot()]) sim.appendSnapshot(5 * [EpsilonSnapshot()]) sim.appendSnapshot(6 * [ModeFilteredProbe()]) sim.checkSimulation() code.interact(local=locals()) return
def test2(destdir): sim = BFDTDobject() #sim.setSizeAndResolution([1,1,1], [5,5,5]) #sim.setSizeAndResolution([1,1,1], [53,5,5]) #sim.setSizeAndResolution([1,1,1], [438,1,1]) #sim.setSizeAndResolution([1,1,1], [40, 50, 60]) #sim.setSizeAndResolution([2,3,4], [100, 100, 100]) sim.setSizeAndResolution([2, 3, 4], [20, 30, 40]) MV = sim.appendSnapshot(ModeVolumeBoxFull()) MV.setPlaneOrientationX() #TODO: MV.setLambda test_function = example_function_3 MV.setPlaneOrientationX() subdir = os.path.join(destdir, 'X') sim.writeTorqueJobDirectory(subdir) sim.sampleFunction(test_function, subdir) MV.setPlaneOrientationY() subdir = os.path.join(destdir, 'Y') sim.writeTorqueJobDirectory(subdir) sim.sampleFunction(test_function, subdir) MV.setPlaneOrientationZ() subdir = os.path.join(destdir, 'Z') sim.writeTorqueJobDirectory(subdir) sim.sampleFunction(test_function, subdir)