Skip to content

Commit

Permalink
Merge pull request #153 from rahulp13/master
Browse files Browse the repository at this point in the history
updates related to OM converter
  • Loading branch information
rahulp13 authored Apr 29, 2020
2 parents a35d497 + b0c203a commit 175208c
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Examples/7805VoltageRegulator/D.lib
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.model 1n4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04)
.model 1N4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04)

2 changes: 1 addition & 1 deletion Examples/7812VoltageRegulator/D.lib
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.model 1n4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04)
.model 1N4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04)

30 changes: 5 additions & 25 deletions src/ngspicetoModelica/ModelicaUI.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import glob
import traceback
from PyQt4 import QtGui, QtCore
from configuration.Appconfig import Appconfig
Expand All @@ -19,8 +20,7 @@ def __init__(self, dir=None):
self.projName = os.path.basename(self.projDir)
self.ngspiceNetlist = os.path.join(
self.projDir, self.projName + ".cir.out")
self.modelicaNetlist = os.path.join(
self.projDir, self.projName + ".mo")
self.modelicaNetlist = os.path.join(self.projDir, "*.mo")
self.map_json = Appconfig.modelica_map_json

self.grid = QtGui.QGridLayout()
Expand Down Expand Up @@ -96,28 +96,6 @@ def callConverter(self):
IfMOS = '1'
break

subOptionInfo = []
subSchemInfo = []
if len(subcktName) > 0:
# subOptionInfo = []
# subSchemInfo = []
for eachsub in subcktName:
filename_temp = eachsub + '.sub'
data = obj_NgMoConverter.readNetlist(filename_temp)
# print "Data---------->",data
subOptionInfo, subSchemInfo = (
obj_NgMoConverter.separateNetlistInfo(data)
)
for eachline in subSchemInfo:
# words = eachline.split()
if eachline[0] == 'm':
IfMOS = '1'
break
# print("Subcircuit OptionInfo :" +
# "subOptionInfo------------------->", subOptionInfo)
# print("Subcircuit Schematic Info :" +
# "subSchemInfo-------------------->", subSchemInfo)

node, nodeDic, pinInit, pinProtectedInit = \
obj_NgMoConverter.nodeSeparate(
compInfo, '0', [], subcktName, []
Expand Down Expand Up @@ -233,7 +211,9 @@ def callConverter(self):
def callOMEdit(self):

if self.obj_validation.validateTool("OMEdit"):
self.cmd2 = "OMEdit " + self.modelicaNetlist
modelFiles = glob.glob(self.modelicaNetlist)
modelFiles = ' '.join(file for file in modelFiles)
self.cmd2 = "OMEdit " + modelFiles
self.obj_workThread2 = Worker.WorkerThread(self.cmd2)
self.obj_workThread2.start()
print("OMEdit called")
Expand Down
118 changes: 72 additions & 46 deletions src/ngspicetoModelica/NgspicetoModelica.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def separateNetlistInfo(self, netlist):
"""
optionInfo = []
schematicInfo = []
self.deviceDetail = []

for eachline in netlist:

Expand Down Expand Up @@ -284,33 +285,33 @@ def compInit(self, compInfo, node, modelInfo, subcktName,
For each component in the netlist initialize it
according to Modelica format
"""
# print "CompInfo inside compInit function : compInit------->",compInfo
# print ("CompInfo inside compInit function : compInit----->",compInfo)
# initial processing to check if MOs is present. If so, library to be
# used is BondLib
modelicaCompInit = []
numNodesSub = {}
mosInfo = {}
# IfMOS = '0'

for eachline in compInfo:
# words = eachline.split()
if eachline[0] == 'm':
# IfMOS = '1'
break
if len(subcktName) > 0:
subOptionInfo = []
subSchemInfo = []
for eachsub in subcktName:
filename_tem = eachsub + '.sub'
filename_tem = os.path.join(dir_name, filename_tem)
data = self.readNetlist(filename_tem)
subOptionInfo, subSchemInfo = self.separateNetlistInfo(data)

for eachline in subSchemInfo:
# words = eachline.split()
if eachline[0] == 'm':
# IfMOS = '1'
break
# for eachline in compInfo:
# # words = eachline.split()
# if eachline[0] == 'm':
# # IfMOS = '1'
# break
# if len(subcktName) > 0:
# subOptionInfo = []
# subSchemInfo = []
# for eachsub in subcktName:
# filename_tem = eachsub + '.sub'
# filename_tem = os.path.join(dir_name, filename_tem)
# data = self.readNetlist(filename_tem)
# subOptionInfo, subSchemInfo = self.separateNetlistInfo(data)

# for eachline in subSchemInfo:
# # words = eachline.split()
# if eachline[0] == 'm':
# # IfMOS = '1'
# break

# Lets Start with Source details
for eachline in self.sourceDetail:
Expand Down Expand Up @@ -398,7 +399,7 @@ def compInit(self, compInfo, node, modelInfo, subcktName,
# Now empty the source list as it may be used by subcircuit
self.sourceDetail[:] = []

# print "Source Detail after processing-------->",self.sourceDetail
# print ("Source Detail after processing-------->",self.sourceDetail)

# Lets start for device
for eachline in self.deviceDetail:
Expand Down Expand Up @@ -471,7 +472,8 @@ def compInit(self, compInfo, node, modelInfo, subcktName,
self.mappingData["Devices"][deviceName]["import"]
) + ".NPN"
elif trans == 'pnp':
start = self.mappingData(
start = (
self.mappingData
["Devices"]
[deviceName]
["import"]
Expand Down Expand Up @@ -863,7 +865,15 @@ def getSubInterface(self, subname, numNodesSub):
newline = newline.split('.subckt ' + subname)
intLine = newline[1].split()
newindex = numNodesSub[subname]
nodesInfoLine = intLine[0:newindex]
nodeTemp = intLine[0:newindex]

nodesInfoLine = []
# Replace hyphen '-' from node
for i in nodeTemp:
i = i.replace("-", "")
if i not in nodesInfoLine:
nodesInfoLine.append(i)

return nodesInfoLine

def getSubParamLine(self, subname, numNodesSub, subParamInfo, dir_name):
Expand Down Expand Up @@ -903,7 +913,7 @@ def nodeSeparate(self, compInfo, ifSub, subname, subcktName, numNodesSub):
pinInit = 'Modelica.Electrical.Analog.Interfaces.Pin '
pinProtectedInit = 'Modelica.Electrical.Analog.Interfaces.Pin '
protectedNode = []
# print "CompInfo coming to nodeSeparate function: compInfo",compInfo
# print ("CompInfo coming to nodeSeparate function: compInfo",compInfo)

# Removing '[' and ']' from compInfo for Digital node
for i in range(0, len(compInfo), 1):
Expand All @@ -926,7 +936,7 @@ def nodeSeparate(self, compInfo, ifSub, subname, subcktName, numNodesSub):
for i in range(0, len(templine), 1):
if templine[i] in subcktName:
point = i
# print "Added in node----->",words[1:point]
# print ("Added in node----->",words[1:point])
nodeTemp.extend(words[1:point])
else:
nodeTemp.append(words[1])
Expand All @@ -951,6 +961,7 @@ def nodeSeparate(self, compInfo, ifSub, subname, subcktName, numNodesSub):
continue
else:
protectedNode.append(node[i])

if ifSub == '1':
if len(nonprotectedNode) > 0:
for i in range(0, len(nonprotectedNode), 1):
Expand Down Expand Up @@ -1000,7 +1011,9 @@ def connectInfo(self, compInfo, node, nodeDic, numNodesSub, subcktName):
eachline[0] == 'v' or
eachline[0] == 'V' or
eachline[0] == 'i' or
eachline[0] == 'I'
eachline[0] == 'I' or
eachline[0] == 'a' or
eachline[0] == 'A'
):
conn = 'connect(' + words[0] + '.p,' + nodeDic[words[1]] + ');'
connInfo.append(conn)
Expand Down Expand Up @@ -1107,10 +1120,10 @@ def procesSubckt(self, subcktName, numNodesSub, dir_name):
basename = filename
filename = os.path.join(dir_name, filename)
data = self.readNetlist(filename)
# print "Data-------------------->",data
# print ("Data-------------------->",data)
subOptionInfo, subSchemInfo = self.separateNetlistInfo(data)
# print "SubOptionInfo------------------->",subOptionInfo
# print "SubSchemInfo-------------------->",subSchemInfo
# print ("SubOptionInfo------------------->",subOptionInfo)
# print ("SubSchemInfo-------------------->",subSchemInfo)
if len(subOptionInfo) > 0:
newline = subOptionInfo[0]
# subInitLine = newline
Expand All @@ -1124,12 +1137,12 @@ def procesSubckt(self, subcktName, numNodesSub, dir_name):
subtransInfo, subInbuiltModelDict = (
self.addModel(subOptionInfo)
)
# print "Sub Model------------------------------->",subModel
# print "SubModelInfo------------------------>",subModelInfo
# print "subsubName---------------------------->",subsubName
# print "subParamInfo------------------------>",subParamInfo
# print "subtransInfo------------------------>",subtransInfo
# print "subInbuiltModel-------------->",subInbuiltModelDict
# print ("Sub Model------------------------------->",subModel)
# print ("SubModelInfo------------------------>",subModelInfo)
# print ("subsubName---------------------------->",subsubName)
# print ("subParamInfo------------------------>",subParamInfo)
# print ("subtransInfo------------------------>",subtransInfo)
# print ("subInbuiltModel-------------->",subInbuiltModelDict)

IfMOSsub = '0'
for eachline in subSchemInfo:
Expand All @@ -1154,18 +1167,18 @@ def procesSubckt(self, subcktName, numNodesSub, dir_name):
if eachline[0] == 'm':
IfMOSsub = '1'
break
# print "subsubOptionInfo------------------>",subsubOptionInfo
# print "subsubSchemInfo-------------------->",subsubSchemInfo
# print ("subsubOptionInfo----------------->",subsubOptionInfo)
# print ("subsubSchemInfo------------------->",subsubSchemInfo)

modelicaSubParam = self.processParam(subParamInfo)
# print "modelicaSubParam------------------>",modelicaSubParam
# print ("modelicaSubParam----------------->",modelicaSubParam)
nodeSub, nodeDicSub, pinInitSub,\
pinProtectedInitSub = self.nodeSeparate(
subSchemInfo, '1', eachsub, subsubName, numNodesSub)
# print "NodeSub------------------------->",nodeSub
# print "NodeDicSub-------------------------->",nodeDicSub
# print "PinInitSub-------------------------->",pinInitSub
# print "PinProtectedInitSub----------->",pinProtectedInitSub
# print ("NodeSub------------------------->",nodeSub)
# print ("NodeDicSub-------------------------->",nodeDicSub)
# print ("PinInitSub-------------------------->",pinInitSub)
# print ("PinProtectedInitSub----------->",pinProtectedInitSub)
modelicaSubCompInit, numNodesSubsub = self.compInit(
subSchemInfo,
nodeSub,
Expand All @@ -1175,22 +1188,35 @@ def procesSubckt(self, subcktName, numNodesSub, dir_name):
subtransInfo,
subInbuiltModelDict
)
# print "modelicaSubCompInit------------>",modelicaSubCompInit
# print "numNodesSubsub---------------------->",numNodesSubsub
# print ("modelicaSubCompInit---------->",modelicaSubCompInit)
# print ("numNodesSubsub-------------------->",numNodesSubsub)
modelicaSubParamNew = self.getSubParamLine(
eachsub,
numNodesSub,
modelicaSubParam,
dir_name) # Ask Manas
# print "modelicaSubParamNew------------>",modelicaSubParamNew
# print ("modelicaSubParamNew---------->",modelicaSubParamNew)
connSubInfo = self.connectInfo(
subSchemInfo,
nodeSub,
nodeDicSub,
numNodesSubsub,
subcktName
)
# print "connSubInfo----------------->",connSubInfo
# print ("connSubInfo----------------->",connSubInfo)

# Recursively process Subcircuit
if len(subsubName) > 0:
data, subOptionInfo, subSchemInfo, subModel, subModelInfo,\
subsubName, subParamInfo, modelicaSubCompInit,\
modelicaSubParam, nodeSubInterface, nodeSub,\
nodeDicSub, pinInitSub, connSubInfo = (
self.procesSubckt(
subsubName, numNodesSubsub, dir_name
)
)

# After Sub Ckt Func
newname = basename.split('.')
newfilename = newname[0]
outfilename = newfilename + ".mo"
Expand Down
2 changes: 1 addition & 1 deletion src/projManagement/Worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def call_system(self, command):
@params
:command => (self.args) takes space separated string of\
comamnds to be executed in different child processes
(see subproces.Popen())
(see subprocess.Popen())
"""

procThread = Appconfig()
Expand Down

0 comments on commit 175208c

Please sign in to comment.