summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRahul P2020-04-20 18:02:00 +0530
committerGitHub2020-04-20 18:02:00 +0530
commitb8097333ca26b380180de0de18a987e0db292927 (patch)
tree4b406d498da23e00bb1d86c8e9b4ccfa4841419d /src
parent6a0ef73be748b4e885d4288dede37fc76ad95158 (diff)
parente8048c5bd325c4f05fa69ff6638259304905d74f (diff)
downloadeSim-b8097333ca26b380180de0de18a987e0db292927.tar.gz
eSim-b8097333ca26b380180de0de18a987e0db292927.tar.bz2
eSim-b8097333ca26b380180de0de18a987e0db292927.zip
Merge pull request #151 from rahulp13/master
Modelica : Diode model, resolves issues netlist path and duplicate nodes
Diffstat (limited to 'src')
-rw-r--r--src/ngspicetoModelica/ModelicaUI.py26
-rw-r--r--src/ngspicetoModelica/NgspicetoModelica.py64
2 files changed, 47 insertions, 43 deletions
diff --git a/src/ngspicetoModelica/ModelicaUI.py b/src/ngspicetoModelica/ModelicaUI.py
index aa7cb330..cd5cf03b 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):
diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py
index a78bad1b..83df42a4 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
@@ -399,18 +406,10 @@ 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]
@@ -425,17 +424,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"]
@@ -452,11 +448,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"]
@@ -935,8 +934,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):
@@ -969,10 +968,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):