From aa75ea9814d9893fc02564dc25e5444ce5ea3439 Mon Sep 17 00:00:00 2001 From: rahulp13 Date: Mon, 13 Apr 2020 16:55:31 +0530 Subject: merged PR #131 --- src/ngspicetoModelica/NgspicetoModelica.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index a78bad1b..5dff56e0 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -365,9 +365,9 @@ class NgMoConverter: stat = stat + \ self.getUnitVal(words[i - 1]) + ',' + \ self.getUnitVal(words[i]) + ';' - stat = stat + ']);' + stat = stat[:-1] + ']);' modelicaCompInit.append(stat) - if typ[0] == words[3] and typ[0] != "dc": + if typ[0] == words[3] and typ[0] != "dc" and typ[0] != "ac": # It is DC constant but no dc keyword val_temp = typ[0].split('v') stat = self.mappingData["Sources"][sourceType]["dc"] + \ @@ -382,10 +382,17 @@ class NgMoConverter: '(V = ' + \ self.getUnitVal(words[4]) + ');' # check this modelicaCompInit.append(stat) + elif typ[0] == words[3] and typ[0] == "ac": + stat = self.mappingData["Sources"][sourceType][typ[0]] + \ + ' ' + \ + compName + \ + '(V = ' + \ + self.getUnitVal((words[4])) + ');' + modelicaCompInit.append(stat) elif sourceType == 'i': stat = self.mappingData["Sources"][sourceType]["dc"] + \ - ' ' + compName + '(I=' + self.getUnitVal(words[3]) + ');' + ' ' + compName + '(I=' + self.getUnitVal(words[4]) + ');' modelicaCompInit.append(stat) # Now empty the source list as it may be used by subcircuit -- cgit From 258fad3a4556915c9fba9981e52fd1289071f7f8 Mon Sep 17 00:00:00 2001 From: rahulp13 Date: Mon, 20 Apr 2020 11:45:43 +0530 Subject: resolves issue with netlist path --- src/ngspicetoModelica/ModelicaUI.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/ngspicetoModelica/ModelicaUI.py b/src/ngspicetoModelica/ModelicaUI.py index aa7cb330..f8889cce 100644 --- a/src/ngspicetoModelica/ModelicaUI.py +++ b/src/ngspicetoModelica/ModelicaUI.py @@ -1,4 +1,5 @@ import os +import traceback from PyQt4 import QtGui, QtCore from configuration.Appconfig import Appconfig from projManagement import Worker @@ -45,7 +46,7 @@ class OpenModelicaEditor(QtGui.QWidget): def browseFile(self): self.ngspiceNetlist = QtGui.QFileDialog.getOpenFileName( - self, 'Open Ngspice file', BROWSE_LOCATION) + self, 'Open Ngspice Netlist', BROWSE_LOCATION) self.FileEdit.setText(self.ngspiceNetlist) def callConverter(self): @@ -158,9 +159,11 @@ class OpenModelicaEditor(QtGui.QWidget): ) # Adding 'numNodesSub' by Fahim # Creating Final Output file - newfile = self.ngspiceNetlist.split('.') - newfilename = newfile[0] + fileDir = os.path.dirname(self.ngspiceNetlist) + newfile = os.path.basename(self.ngspiceNetlist) + newfilename = os.path.join(fileDir, newfile.split('.')[0]) outfile = newfilename + ".mo" + out = open(outfile, "w") out.writelines('model ' + os.path.basename(newfilename)) out.writelines('\n') @@ -207,24 +210,25 @@ class OpenModelicaEditor(QtGui.QWidget): self.msg = QtGui.QMessageBox() self.msg.setText( - "Ngspice netlist successfully converted to OpenModelica" + + "Ngspice netlist successfully converted to OpenModelica " + "netlist" ) self.obj_appconfig.print_info( - "Ngspice netlist successfully converted to OpenModelica" + + "Ngspice netlist successfully converted to OpenModelica " + "netlist" ) self.msg.exec_() - except Exception as e: + except BaseException as e: + traceback.print_exc() + print("================") self.msg = QtGui.QErrorMessage() self.msg.setModal(True) - self.msg.setWindowTitle("Ngspice to Modelica conversion error") + self.msg.setWindowTitle("Conversion Error") self.msg.showMessage( - 'Unable to convert NgSpice netlist to Modelica netlist.' + - 'Check the netlist :' + - str(e)) - self.msg.setWindowTitle("Ngspice to Modelica conversion error") + 'Unable to convert Ngspice netlist to Modelica netlist. ' + + 'Check the netlist : ' + repr(e) + ) def callOMEdit(self): -- cgit From 29074935e8ae45bd8008cbc477be1f71baf0b857 Mon Sep 17 00:00:00 2001 From: rahulp13 Date: Mon, 20 Apr 2020 11:47:10 +0530 Subject: update to Diode model, resolves issue with duplicate nodes --- src/ngspicetoModelica/NgspicetoModelica.py | 50 +++++++++++++----------------- 1 file changed, 21 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 5dff56e0..75bb8a52 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -406,18 +406,9 @@ class NgMoConverter: deviceName = eachline[0].lower() if deviceName == 'd': if len(words) > 3: - if 'n' in modelInfo[words[3]]: - n = float(modelInfo[words[3]]['n']) - else: - n = 1.0 - vt = str(float(0.025 * n)) - ''' - stat = self.mappingData["Devices"][deviceName]["import"]+\ - ' '+words[0] + '(Ids = ' + modelInfo[words[3]]['is']+\ - ', Vt = ' + vt + ', R = 1e12' +');' - ''' - start = self.mappingData["Devices"][deviceName]["import"] - stat = start + " " + words[0] + "(" + start = "\nparameter " + start += self.mappingData["Devices"][deviceName]["modelcard"] + stat = start + " card" + words[0] + "(" tempstatList = [] userDeviceParamList = [] refName = words[-1] @@ -432,17 +423,14 @@ class NgMoConverter: ) tempstatList.append( actualModelicaParam + - "=" + - self.getUnitVal( - modelInfo[refName][key]) + - " ") + " = " + + self.getUnitVal(modelInfo[refName][key]) + ) userDeviceParamList.append( str(actualModelicaParam)) except BaseException: pass - # Adding Vt and R - userDeviceParamList.append("Vt") - tempstatList.append("Vt=" + vt) + # Running loop over default parameter of OpenModelica for default in (self.mappingData ["Devices"] @@ -459,11 +447,14 @@ class NgMoConverter: [default] ) tempstatList.append( - default + "=" + - self.getUnitVal(defaultValue) + " ") - - stat += ",".join(str(item) for item in tempstatList) + ");" - + default + " = " + + self.getUnitVal(defaultValue)) + + stat += ", ".join(str(item) for item in tempstatList) + stat += ");" + "\n\n" + stat += self.mappingData["Devices"][deviceName]["import"] + stat += " " + words[0] + "(modelcarddiode=card" + words[0] + stat += ");" else: stat = (self.mappingData ["Devices"] @@ -942,8 +933,8 @@ class NgMoConverter: # Replace hyphen '-' from node for i in nodeTemp: + i = i.replace("-", "") if i not in node: - i = i.replace("-", "") node.append(i) for i in range(0, len(node), 1): @@ -976,10 +967,11 @@ class NgMoConverter: pinInit = pinInit + nodeDic[protectedNode[i]] pinInit = pinInit + ';' pinProtectedInit = pinProtectedInit + ';' - # print "Node---->",node - # print "nodeDic----->",nodeDic - # print "PinInit----->",pinInit - # print "pinProtectedinit--->",pinProtectedInit + # print ("Node---->",node) + # print ("nodeDic----->",nodeDic) + # print ("PinInit----->",pinInit) + # print ("pinProtectedinit--->",pinProtectedInit) + return node, nodeDic, pinInit, pinProtectedInit def connectInfo(self, compInfo, node, nodeDic, numNodesSub, subcktName): -- cgit From e8048c5bd325c4f05fa69ff6638259304905d74f Mon Sep 17 00:00:00 2001 From: rahulp13 Date: Mon, 20 Apr 2020 17:38:03 +0530 Subject: pycodestyle compliant - modelica --- src/ngspicetoModelica/ModelicaUI.py | 2 +- src/ngspicetoModelica/NgspicetoModelica.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ngspicetoModelica/ModelicaUI.py b/src/ngspicetoModelica/ModelicaUI.py index f8889cce..cd5cf03b 100644 --- a/src/ngspicetoModelica/ModelicaUI.py +++ b/src/ngspicetoModelica/ModelicaUI.py @@ -163,7 +163,7 @@ class OpenModelicaEditor(QtGui.QWidget): newfile = os.path.basename(self.ngspiceNetlist) newfilename = os.path.join(fileDir, newfile.split('.')[0]) outfile = newfilename + ".mo" - + out = open(outfile, "w") out.writelines('model ' + os.path.basename(newfilename)) out.writelines('\n') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 75bb8a52..83df42a4 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -407,7 +407,8 @@ class NgMoConverter: if deviceName == 'd': if len(words) > 3: start = "\nparameter " - start += self.mappingData["Devices"][deviceName]["modelcard"] + start += \ + self.mappingData["Devices"][deviceName]["modelcard"] stat = start + " card" + words[0] + "(" tempstatList = [] userDeviceParamList = [] -- cgit