From 1e548a07da04646202ee20673e6a4470ee063708 Mon Sep 17 00:00:00 2001 From: fahimkhan Date: Wed, 9 Mar 2016 15:21:48 +0530 Subject: Remove lower case function as it is not required --- src/ngspicetoModelica/NgspicetoModelica.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 95f991bd..95a93b36 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -40,9 +40,13 @@ class NgMoConverter: if eachline[0]=='*': continue elif eachline[0]=='.': - optionInfo.append(eachline.lower()) + optionInfo.append(eachline) + ##No need of making it lower case as netlist is already converted to ngspice + #optionInfo.append(eachline.lower()) else: - schematicInfo.append(eachline.lower()) + schematicInfo.append(eachline) + ##No need of making it lower case as netlist is already converted to ngspice + #schematicInfo.append(eachline.lower()) return optionInfo,schematicInfo def addModel(self,optionInfo): @@ -104,7 +108,7 @@ class NgMoConverter: for eachitem in info: modelInfo[eachmodel][info[0]] = info[1] #dic within a dic #modelInfo[eachmodel] = modelInfo[eachmodel].split() - # modelInfo[eachmodel] = modelInfo[eachmodel].lower() + #modelInfo[eachmodel] = modelInfo[eachmodel].lower() f.close() @@ -168,7 +172,6 @@ class NgMoConverter: """ print "Val------------->",val for i in range(0,len(val),1): - print "Val[i]----------------->",val[i] if val[i] in ['k','u','p','t','g','m','n','f']: newval = val.split(val[i]) print "new Value------------>",newval @@ -672,22 +675,22 @@ def main(args): #Getting all the require information lines = obj_NgMoConverter.readNetlist(filename) #print "Complete Lines of Ngspice netlist :lines ---------------->",lines - optionInfo, schematicInfo=obj_NgMoConverter.separateNetlistInfo(lines) + optionInfo, schematicInfo = obj_NgMoConverter.separateNetlistInfo(lines) #print "All option details like analysis,subckt,.ic,.model : OptionInfo------------------->",optionInfo #print "Schematic connection info :schematicInfo",schematicInfo modelName, modelInfo, subcktName, paramInfo, inbuiltmodelName, inbuiltmodelInfo = obj_NgMoConverter.addModel(optionInfo) print "Name of Model : modelName-------------------->",modelName print "Model Information :modelInfo--------------------->",modelInfo - print "Subcircuit Name :subcktName------------------------>",subcktName - print "Parameter Information :paramInfo---------------------->",paramInfo - print "Ngspice inbuiltmodelName :inbuiltmodelName---------------------->",inbuiltmodelName - print "Ngspice inbuiltmodelInfo :inbuiltmodelInfo----------------------->",inbuiltmodelInfo + #print "Subcircuit Name :subcktName------------------------>",subcktName + #print "Parameter Information :paramInfo---------------------->",paramInfo + #print "Ngspice inbuiltmodelName :inbuiltmodelName---------------------->",inbuiltmodelName + #print "Ngspice inbuiltmodelInfo :inbuiltmodelInfo----------------------->",inbuiltmodelInfo modelicaParamInit = obj_NgMoConverter.processParam(paramInfo) #print "Make modelicaParamInit from paramInfo :processParamInit------------->",modelicaParamInit compInfo, plotInfo = obj_NgMoConverter.separatePlot(schematicInfo) - #print "Info like run etc : CompInfo----------------->",compInfo + print "Info like run etc : CompInfo----------------->",compInfo #print "Plot info like plot,print etc :plotInfo",plotInfo IfMOS = '0' -- cgit From 91f2816832a8f708db659ae856a5b2c97744c0cc Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Mon, 14 Mar 2016 15:09:54 +0530 Subject: Make it work for External Model Library --- src/ngspicetoModelica/NgspicetoModelica.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 95a93b36..74401c9b 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -84,6 +84,7 @@ class NgMoConverter: #Adding details of model(external) and subckt into modelInfo and subcktInfo + print "Model Name ------------ >",modelName for eachmodel in modelName: filename = eachmodel + '.lib' if os.path.exists(filename): @@ -96,19 +97,19 @@ class NgMoConverter: print filename + " does not exist" sys.exit() data = f.read() - data = data.lower() + #data = data.lower() #No need to make it lower case newdata = data.split('(') - newdata = newdata[1].split() - modelInfo[eachmodel] = {} + refModelName = newdata[0].split()[1] + modelParameter = newdata[1].split() + + modelInfo[refModelName] = {} - for eachline in newdata: + for eachline in modelParameter: if len(eachline) > 1: info = eachline.split('=') # modelInfo[eachmodel][info[0]] = {} for eachitem in info: - modelInfo[eachmodel][info[0]] = info[1] #dic within a dic - #modelInfo[eachmodel] = modelInfo[eachmodel].split() - #modelInfo[eachmodel] = modelInfo[eachmodel].lower() + modelInfo[refModelName][info[0]] = info[1] #dic within a dic f.close() @@ -202,7 +203,7 @@ class NgMoConverter: def compInit(self,compInfo, node, modelInfo, subcktName): """ - For each component in the netlist initialise it acc to Modelica format + For each component in the netlist initialize it according to Modelica format """ print "CompInfo inside compInit function : compInit",compInfo #### initial processing to check if MOs is present. If so, library to be used is BondLib @@ -253,6 +254,8 @@ class NgMoConverter: modelicaCompInit.append(stat) elif eachline[0] == 'd': if len(words) > 3: + print words[3] + print "ModelInfo",modelInfo n = float(modelInfo[words[3]]['n']) vt_temp = 0.025*n vt = str(vt_temp) @@ -413,8 +416,7 @@ class NgMoConverter: for i in range(0,len(compInfo),1): compInfo[i] = compInfo[i].replace("[","").replace("]","") - - + for eachline in compInfo: words = eachline.split() if eachline[0] in ['m', 'e', 'g', 't']: @@ -719,8 +721,8 @@ def main(args): node, nodeDic, pinInit, pinProtectedInit = obj_NgMoConverter.nodeSeparate(compInfo, '0', [], subcktName,[]) print "All nodes in the netlist :node---------------->",node print "NodeDic which will be used for modelica : nodeDic------------->",nodeDic - print "PinInit-------------->",pinInit - print "pinProtectedInit----------->",pinProtectedInit + #print "PinInit-------------->",pinInit + #print "pinProtectedInit----------->",pinProtectedInit modelicaCompInit, numNodesSub = obj_NgMoConverter.compInit(compInfo,node, modelInfo, subcktName) print "ModelicaComponents : modelicaCompInit----------->",modelicaCompInit @@ -728,7 +730,7 @@ def main(args): connInfo = obj_NgMoConverter.connectInfo(compInfo, node, nodeDic, numNodesSub,subcktName) - print "ConnInfo------------------>",connInfo + #print "ConnInfo------------------>",connInfo ###After Sub Ckt Func -- cgit From 697ff38a5712f97a4ca5b81731d4bd3bf0bc69f6 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Mon, 21 Mar 2016 14:12:08 +0530 Subject: Removing Lower case functionality for Reference Model Name --- src/ngspicetoModelica/NgspicetoModelica.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 74401c9b..582e8796 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -97,9 +97,11 @@ class NgMoConverter: print filename + " does not exist" sys.exit() data = f.read() - #data = data.lower() #No need to make it lower case - newdata = data.split('(') + #data = data.lower() #Won't work if Reference model name is Upper Case + newdata = data.split('(') + #First fetch the refModelName and then lower case its parameter refModelName = newdata[0].split()[1] + newdata[1] = newdata[1].lower() modelParameter = newdata[1].split() modelInfo[refModelName] = {} @@ -255,7 +257,7 @@ class NgMoConverter: elif eachline[0] == 'd': if len(words) > 3: print words[3] - print "ModelInfo",modelInfo + print "ModelInfo----------->",modelInfo n = float(modelInfo[words[3]]['n']) vt_temp = 0.025*n vt = str(vt_temp) -- cgit From 09306d977713deba69879a3f35a025c018b74876 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Tue, 22 Mar 2016 17:17:53 +0530 Subject: write getUnitVal function to fetch the proper unit value for modelica --- src/ngspicetoModelica/NgspicetoModelica.py | 31 +++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 582e8796..61843c25 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -1,11 +1,17 @@ import sys import os import re +import json from string import maketrans class NgMoConverter: + ifMOS = False + def __init__(self): - pass + #Loading JSON file which hold the mapping information between ngspice and Modelica. + with open('Mapping.json') as mappingFile: + self.mappingData = json.load(mappingFile) + def readNetlist(self,filename): """ @@ -43,6 +49,10 @@ class NgMoConverter: optionInfo.append(eachline) ##No need of making it lower case as netlist is already converted to ngspice #optionInfo.append(eachline.lower()) + elif eachline[0]=='m': + ifMOS = True + print "Mos is present ",ifMOS + schematicInfo.append(eachline) else: schematicInfo.append(eachline) ##No need of making it lower case as netlist is already converted to ngspice @@ -203,6 +213,24 @@ class NgMoConverter: value = val return value + def getUnitVal(self,compValue): + print "Received compValue--------> ",compValue + regExp = re.compile("([0-9]+)([a-zA-Z]+)") + matchString = regExp.match(str(compValue)) #separating number and string + try: + numValue = matchString.group(1) + unitValue = matchString.group(2) + #print "Num Value---------->",numValue + #print "Unit Value------->",unitValue + #print "Converted Unit ------->",self.mappingData["Units"][unitValue] + modifiedcompValue = numValue+self.mappingData["Units"][unitValue] + return modifiedcompValue + except: + return compValue + + def getModelicaComponent(self): + print "Get Modelica Component" + def compInit(self,compInfo, node, modelInfo, subcktName): """ For each component in the netlist initialize it according to Modelica format @@ -233,6 +261,7 @@ class NgMoConverter: words = eachline.split() val = words[3] value = self.splitIntoVal(val) + _value = self.getUnitVal(words[-1]) if eachline[0] == 'r': stat = 'Analog.Basic.Resistor ' + words[0] + '(R = ' + value + ');' modelicaCompInit.append(stat) -- cgit From 5f405de9cf3f3e968f7a45f48710ae99a2372941 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Wed, 23 Mar 2016 11:12:39 +0530 Subject: Remove number dependency of node --- src/ngspicetoModelica/NgspicetoModelica.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 61843c25..df7113ac 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -259,9 +259,9 @@ class NgMoConverter: break for eachline in compInfo: words = eachline.split() - val = words[3] - value = self.splitIntoVal(val) - _value = self.getUnitVal(words[-1]) + #val = words[3] + #value = self.splitIntoVal(val) + value = self.getUnitVal(words[-1]) if eachline[0] == 'r': stat = 'Analog.Basic.Resistor ' + words[0] + '(R = ' + value + ');' modelicaCompInit.append(stat) @@ -384,7 +384,7 @@ class NgMoConverter: else: continue - if '0' in node: + if '0' or 'gnd' in node: modelicaCompInit.append('Analog.Basic.Ground g;') return modelicaCompInit, numNodesSub -- cgit From 35e169f59e7d7ba8da89c944f205f9c092b21960 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Wed, 23 Mar 2016 16:56:18 +0530 Subject: Completed code for mapping of Source And started Mapping code for device --- src/ngspicetoModelica/NgspicetoModelica.py | 139 +++++++++++++++-------------- 1 file changed, 70 insertions(+), 69 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index df7113ac..09096795 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -5,13 +5,18 @@ import json from string import maketrans class NgMoConverter: - ifMOS = False + def __init__(self): #Loading JSON file which hold the mapping information between ngspice and Modelica. with open('Mapping.json') as mappingFile: self.mappingData = json.load(mappingFile) + self.ifMOS = False + self.sourceDetail = [] + self.deviceDetail = [] + self.deviceList = ['d','D','j','J','q','Q'] #MOSFET is excluded as it has special case + def readNetlist(self,filename): """ @@ -39,6 +44,7 @@ class NgMoConverter: """ optionInfo = [] schematicInfo = [] + for eachline in data: if len(eachline) > 1: #if eachline[0] == '+': @@ -49,10 +55,14 @@ class NgMoConverter: optionInfo.append(eachline) ##No need of making it lower case as netlist is already converted to ngspice #optionInfo.append(eachline.lower()) - elif eachline[0]=='m': - ifMOS = True - print "Mos is present ",ifMOS - schematicInfo.append(eachline) + elif eachline[0] in self.deviceList: + if eachline[0]=='m' or eachline[0]=='M': + self.ifMOS = True + schematicInfo.append(eachline) + self.deviceDetail.append(eachline) + elif eachline[0]=='v' or eachline[0]=='V': + #schematicInfo.append(eachline) + self.sourceDetail.append(eachline) else: schematicInfo.append(eachline) ##No need of making it lower case as netlist is already converted to ngspice @@ -220,22 +230,17 @@ class NgMoConverter: try: numValue = matchString.group(1) unitValue = matchString.group(2) - #print "Num Value---------->",numValue - #print "Unit Value------->",unitValue - #print "Converted Unit ------->",self.mappingData["Units"][unitValue] modifiedcompValue = numValue+self.mappingData["Units"][unitValue] return modifiedcompValue except: return compValue - def getModelicaComponent(self): - print "Get Modelica Component" - + 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 = {} @@ -257,6 +262,57 @@ class NgMoConverter: if eachline[0] == 'm': IfMOS = '1' break + + #Lets Start with Source details + for eachline in self.sourceDetail: + eachline = eachline.lower() + words = eachline.split() + typ = words[3].split('(') + if typ[0] == "pulse": + per = words[9].split(')') + stat = self.mappingData["Sources"][typ[0]]+' '+words[0]+'(rising = '+words[6]+', V = '+words[4]\ + +', width = '+words[8]+', period = '+per[0]+', offset = '+typ[1]+', startTime = '+words[5]+', falling = '+words[7]+');' + modelicaCompInit.append(stat) + if typ[0] == "sine": + theta = words[7].split(')') + stat = self.mappingData["Sources"][typ[0]]+' '+words[0]+'(offset = '+typ[1]+', V = '+words[4]+', freqHz = '+words[5]+', startTime = '+words[6]+', phase = '+theta[0]+');' + modelicaCompInit.append(stat) + if typ[0] == "pwl": + keyw = self.mappingData["Sources"][typ[0]]+' ' + stat = keyw + words[0] + '(table = [' + typ[1] + ',' + words[4] + ';' + length = len(words); + for i in range(6,length,2): + if i == length-2: + w = words[i].split(')') + stat = stat + words[i-1] + ',' + w[0] + else: + stat = stat + words[i-1] + ',' + words[i] + ';' + stat = stat + ']);' + modelicaCompInit.append(stat) + if typ[0] == words[3] and typ[0] != "dc": + #It is DC constant but no dc keyword + val_temp = typ[0].split('v') + stat = self.mappingData["Sources"]["dc"]+' ' + words[0] + '(V = ' + val_temp[0] + ');' + modelicaCompInit.append(stat) + elif typ[0] == words[3] and typ[0] == "dc": + stat = self.mappingData["Sources"][typ[0]]+' ' + words[0] + '(V = ' + words[4] + ');' ### check this + modelicaCompInit.append(stat) + + #Lets start for device + for eachline in self.deviceDetail: + words=eachline.split() + if eachline[0]=='d' or eachline[0]=='D': + if len(words)>3: + if modelInfo[words[3]].has_key('n'): + n = float(modelInfo[words[3]]['n']) + else: + n = 1.0 + vt = str(float(0.025*n)) + stat = self.mappingData["Devices"][eachline[0]]+' '+ words[0] + '(Ids = ' + modelInfo[words[3]]['is'] + ', Vt = ' + vt + ', R = 1e12' +');' + else: + stat = self.mappingData["Devices"][eachline[0]]+' '+ words[0] +';' + modelicaCompInit.append(stat) + for eachline in compInfo: words = eachline.split() #val = words[3] @@ -283,17 +339,7 @@ class NgMoConverter: elif eachline[0] == 'h': stat = 'Analog.Basic.CCV ' + words[0] + '(transResistance = ' + self.splitIntoVal(words[4]) + ');' modelicaCompInit.append(stat) - elif eachline[0] == 'd': - if len(words) > 3: - print words[3] - print "ModelInfo----------->",modelInfo - n = float(modelInfo[words[3]]['n']) - vt_temp = 0.025*n - vt = str(vt_temp) - stat = 'Analog.Semiconductors.Diode ' + words[0] + '(Ids = ' + modelInfo[words[3]]['is'] + ', Vt = ' + vt + ', R = 1e12' +');' - else: - stat = 'Analog.Semiconductors.Diode ' + words[0] +';' - modelicaCompInit.append(stat) + elif eachline[0] == 'm': line_l = words[7].split('=') line_w = words[8].split('=') @@ -319,52 +365,7 @@ class NgMoConverter: + line_pd[1] + ', PS = ' + line_pd[1] + ');' stat = stat.translate(maketrans('{}', ' ')) modelicaCompInit.append(stat) - elif eachline[0] == 'v': - typ = words[3].split('(') - if typ[0] == "pulse": - per = words[9].split(')') - #if IfMOS == '0': - #stat = 'Spice3.Sources.V_pulse '+words[0]+'(TR = '+words[6]+', V2 = '+words[4]+', PW = '+words[8]+', PER = '+per[0]+', V1 = '+typ[1]+', TD = '+words[5]+', TF = '+words[7]+');' - #elif IfMOS == '1': - stat = 'Analog.Sources.TrapezoidVoltage '+words[0]+'(rising = '+words[6]+', V = '+words[4]\ - +', width = '+words[8]+', period = '+per[0]+', offset = '+typ[1]+', startTime = '+words[5]+', falling = '+words[7]+');' - modelicaCompInit.append(stat) - if typ[0] == "sine": - theta = words[7].split(')') - #if IfMOS == '0': - #stat = 'Spice3.Sources.V_sin '+words[0]+'(VO = '+typ[1]+', VA = '+words[4]+', FREQ = '+words[5]+', TD = '+words[6]+', THETA = '+theta[0]+');' - #elif IfMOS == '1': - stat = 'Analog.Sources.SineVoltage '+words[0]+'(offset = '+typ[1]+', V = '+words[4]+', freqHz = '+words[5]+', startTime = '+words[6]+', phase = '+theta[0]+');' - modelicaCompInit.append(stat) - if typ[0] == "pwl": - #if IfMOS == '0': - #keyw = 'Spice3.Sources.V_pwl ' - #elif IfMOS == '1': - keyw = 'Analog.Sources.TableVoltage ' - stat = keyw + words[0] + '(table = [' + typ[1] + ',' + words[4] + ';' - length = len(words); - for i in range(6,length,2): - if i == length-2: - w = words[i].split(')') - stat = stat + words[i-1] + ',' + w[0] - else: - stat = stat + words[i-1] + ',' + words[i] + ';' - stat = stat + ']);' - modelicaCompInit.append(stat) - if typ[0] == words[3] and typ[0] != "dc": - val_temp = typ[0].split('v') - #if IfMOS == '0': - stat = 'Analog.Sources.ConstantVoltage ' + words[0] + '(V = ' + val_temp[0] + ');' - #elif IfMOS == '1': - #stat = 'Analog.Sources.ConstantVoltage ' + words[0] + '(V = ' + val_temp[0] + ');' - modelicaCompInit.append(stat) - elif typ[0] == words[3] and typ[0] == "dc": - #if IfMOS == '0': - #stat = 'Spice3.Sources.V_constant ' + words[0] + '(V = ' + words[4] + ');' ### check this - #elif IfMOS == '1': - stat = 'Analog.Sources.ConstantVoltage ' + words[0] + '(V = ' + words[4] + ');' ### check this - modelicaCompInit.append(stat) - + elif eachline[0] == 'x': temp_line = eachline.split() temp = temp_line[0].split('x') -- cgit From 8084cd3300be5d7237039b61b840e8c6195f000e Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Mon, 28 Mar 2016 17:25:17 +0530 Subject: Modified code for Transistor --- src/ngspicetoModelica/NgspicetoModelica.py | 140 +++++++++++++++++++++++------ 1 file changed, 112 insertions(+), 28 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 09096795..f4402b80 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -3,6 +3,7 @@ import os import re import json from string import maketrans +from lepl.matchers.derived import Star class NgMoConverter: @@ -22,6 +23,7 @@ class NgMoConverter: """ Read Ngspice Netlist """ + netlist = [] if os.path.exists(filename): try: f = open(filename) @@ -34,26 +36,30 @@ class NgMoConverter: sys.exit() data = f.read() - #data = data.translate(maketrans('\n+', ' ')) + data = data.splitlines() f.close() - return data.splitlines() + for eachline in data: + eachline=eachline.strip() + if len(eachline)>1: + if eachline[0]=='+': + netlist.append(netlist.pop()+eachline.replace('+',' ',1)) + else: + netlist.append(eachline) + return netlist - def separateNetlistInfo(self,data): + def separateNetlistInfo(self,netlist): """ Separate schematic data and option data """ optionInfo = [] schematicInfo = [] - for eachline in data: + for eachline in netlist: if len(eachline) > 1: - #if eachline[0] == '+': - # eachline=eachline.translate(maketrans('\n+',' ')) if eachline[0]=='*': continue elif eachline[0]=='.': optionInfo.append(eachline) - ##No need of making it lower case as netlist is already converted to ngspice #optionInfo.append(eachline.lower()) elif eachline[0] in self.deviceList: if eachline[0]=='m' or eachline[0]=='M': @@ -78,9 +84,8 @@ class NgMoConverter: modelInfo = {} subcktName = [] paramInfo = [] - inbuiltmodelName = [] - inbuiltmodelInfo = {} - #modelInfo['paramInfo'] = {} + transInfo = {} + for eachline in optionInfo: words = eachline.split() if words[0] == '.include': @@ -92,16 +97,36 @@ class NgMoConverter: elif words[0] == '.param': paramInfo.append(eachline) elif words[0] == '.model': + model = words[1] + modelInfo[model] = {} + eachline = eachline.replace(' = ','=').replace('= ','=').replace(' =','=') + eachline = eachline.split('(') + templine = eachline[0].split() + trans = templine[1] + transInfo[trans] = [] + if templine[2] in ['npn', 'pnp', 'pmos', 'nmos']: + transInfo[trans] = templine[2] + eachline[1] = eachline[1].lower() + eachline = eachline[1].split() + + for eachitem in eachline: + if len(eachitem) > 1: + eachitem = eachitem.replace(')','') + iteminfo = eachitem.split('=') + for each in iteminfo: + modelInfo[model][iteminfo[0]] = iteminfo[1] + + """ name = words[1]+':'+words[2].split('(')[0] #model_ref_name:actual_model_name - inbuiltmodelName.append(name) - inbuiltmodelInfo[name] = {} + modelName.append(name) + modelInfo[name] = {} #Get all the data with () of .model line paramData = re.compile("\((.*)\)" ).search(eachline).group(1) info = paramData.split() for eachitem in info: eachitem = eachitem.split('=') - inbuiltmodelInfo[name][eachitem[0]] = eachitem[1] - + modelInfo[name][eachitem[0]] = eachitem[1] + """ #Adding details of model(external) and subckt into modelInfo and subcktInfo print "Model Name ------------ >",modelName @@ -117,8 +142,29 @@ class NgMoConverter: print filename + " does not exist" sys.exit() data = f.read() + data = data.replace('+', '').replace('\n','').replace(' = ','=').replace('= ','=').replace(' =','=') #data = data.lower() #Won't work if Reference model name is Upper Case - newdata = data.split('(') + newdata = data.split('(') + templine_f = newdata[0].split() + trans_f = templine_f[1] + transInfo[trans_f] = [] + if templine_f[2] in ['npn', 'pnp', 'pmos', 'nmos']: + transInfo[trans_f] = templine_f[2] + + refModelName = trans_f + newdata[1] = newdata[1].lower() + modelParameter = newdata[1].split() + + modelInfo[refModelName] = {} + + for eachline in modelParameter: + if len(eachline) > 1: + eachline = eachline.replace(')','') + info = eachline.split('=') + for eachitem in info: + modelInfo[refModelName][info[0]] = info[1] + f.close() + ''' #First fetch the refModelName and then lower case its parameter refModelName = newdata[0].split()[1] newdata[1] = newdata[1].lower() @@ -133,9 +179,9 @@ class NgMoConverter: for eachitem in info: modelInfo[refModelName][info[0]] = info[1] #dic within a dic f.close() - + ''' - return modelName, modelInfo, subcktName, paramInfo,inbuiltmodelName,inbuiltmodelInfo + return modelName, modelInfo, subcktName, paramInfo ,transInfo def processParam(self,paramInfo): """ @@ -152,7 +198,6 @@ class NgMoConverter: stat = 'parameter Real ' + final_line + ';' stat = stat.translate(maketrans('{}', ' ')) modelicaParam.append(stat) - print "Modelica Parameter----------->",modelicaParam return modelicaParam @@ -193,11 +238,9 @@ class NgMoConverter: """ Split the number k,u,p,t,g etc into powers e3,e-6 etc """ - print "Val------------->",val for i in range(0,len(val),1): if val[i] in ['k','u','p','t','g','m','n','f']: newval = val.split(val[i]) - print "new Value------------>",newval if val[i] == 'k': value = newval[0] + 'e3' if val[i] == 'u': @@ -234,9 +277,21 @@ class NgMoConverter: return modifiedcompValue except: return compValue + + def tryExists(self,modelInfo,words,wordNo, key,default): + """ + checks if entry for key exists in dictionary, else returns default + """ + try: + keyval = modelInfo[words[wordNo]][key] + keyval = self.getUnitVal(keyval) + print "Key------->",modelInfo + except KeyError: + keyval = str(default) + return keyval - def compInit(self,compInfo, node, modelInfo, subcktName): + def compInit(self,compInfo, node, modelInfo, subcktName,dir_name): """ For each component in the netlist initialize it according to Modelica format """ @@ -255,8 +310,10 @@ class NgMoConverter: 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': @@ -312,6 +369,32 @@ class NgMoConverter: else: stat = self.mappingData["Devices"][eachline[0]]+' '+ words[0] +';' modelicaCompInit.append(stat) + + elif eachline[0]=='q' or eachline[0]=='Q': + print "Starting Transistor" + if words[4]=='npn': + start = 'Analog.Semiconductors.NPN ' + elif words[4]=='pnp': + start = 'Analog.Semiconductors.PNP ' + + inv_vak = float(self.tryExists(modelInfo,words,4, 'vaf', 50)) + vak_temp = 1/inv_vak + vak = str(vak_temp) + bf = self.tryExists(modelInfo,words,4, 'bf', 50) + br = self.tryExists(modelInfo,words,4, 'br', 0.1) + Is = self.tryExists(modelInfo,words,4, 'is', 1e-16) + tf = self.tryExists(modelInfo,words,4, 'tf', 1.2e-10) + tr = self.tryExists(modelInfo,words,4, 'tr', 5e-9) + cjs = self.tryExists(modelInfo,words,4, 'cjs', 1e-12) + cje = self.tryExists(modelInfo,words,4, 'cje', 4e-13) + cjc = self.tryExists(modelInfo,words,4, 'cjc', 5e-13) + vje = self.tryExists(modelInfo,words,4, 'vje', 0.8) + mje = self.tryExists(modelInfo,words,4, 'mje', 0.4) + vjc = self.tryExists(modelInfo,words,4, 'vjc', 0.8) + mjc = self.tryExists(modelInfo,words,4, 'mjc', 0.333) + stat = start + words[0] +'(Bf = ' + bf + ', Br = ' + br + ', Is = ' +Is+ ', Vak = ' + vak + ', Tauf = ' +tf+ ', Taur = ' +tr+ ', Ccs = ' +cjs+ ', Cje = ' +cje+ ', Cjc = ' +cjc+ ', Phie = ' + vje + ', Me = ' + mje + ', Phic = ' + vjc + ', Mc = ' + mjc + ');' + modelicaCompInit.append(stat) + for eachline in compInfo: words = eachline.split() @@ -552,7 +635,6 @@ class NgMoConverter: temp = templine[0].split('x') index = temp[1] for i in range(0,len(templine),1): - print "Test------------------>" if templine[i] in subcktName: #Ask Manas Added subcktName in function Call subname = templine[i] nodeNumInfo = self.getSubInterface(subname, numNodesSub) @@ -604,11 +686,12 @@ class NgMoConverter: for i in range(0,len(intLine),1): nodeSubInterface.append(intLine[i]) - subModel, subModelInfo, subsubName, subParamInfo,subinbuiltmodelName, subinbuiltmodelInfo = self.addModel(subOptionInfo) + subModel, subModelInfo, subsubName, subParamInfo,transInfo = self.addModel(subOptionInfo) print "Sub Model------------------------------------>",subModel print "SubModelInfo---------------------------------->",subModelInfo print "subsubName------------------------------------->",subsubName print "subParamInfo----------------------------------->",subParamInfo + print "transInfo----------------------------------->",transInfo IfMOSsub = '0' for eachline in subSchemInfo: #words = eachline.split() @@ -703,6 +786,9 @@ def main(args): print "USAGE:" print "python NgspicetoModelica.py " sys.exit() + + dir_name = os.path.dirname(os.path.realpath(filename)) + file_basename = os.path.basename(filename) obj_NgMoConverter = NgMoConverter() @@ -712,14 +798,12 @@ def main(args): optionInfo, schematicInfo = obj_NgMoConverter.separateNetlistInfo(lines) #print "All option details like analysis,subckt,.ic,.model : OptionInfo------------------->",optionInfo #print "Schematic connection info :schematicInfo",schematicInfo - modelName, modelInfo, subcktName, paramInfo, inbuiltmodelName, inbuiltmodelInfo = obj_NgMoConverter.addModel(optionInfo) + modelName, modelInfo, subcktName, paramInfo,transInfo = obj_NgMoConverter.addModel(optionInfo) print "Name of Model : modelName-------------------->",modelName print "Model Information :modelInfo--------------------->",modelInfo #print "Subcircuit Name :subcktName------------------------>",subcktName #print "Parameter Information :paramInfo---------------------->",paramInfo - #print "Ngspice inbuiltmodelName :inbuiltmodelName---------------------->",inbuiltmodelName - #print "Ngspice inbuiltmodelInfo :inbuiltmodelInfo----------------------->",inbuiltmodelInfo - + modelicaParamInit = obj_NgMoConverter.processParam(paramInfo) #print "Make modelicaParamInit from paramInfo :processParamInit------------->",modelicaParamInit @@ -756,7 +840,7 @@ def main(args): #print "PinInit-------------->",pinInit #print "pinProtectedInit----------->",pinProtectedInit - modelicaCompInit, numNodesSub = obj_NgMoConverter.compInit(compInfo,node, modelInfo, subcktName) + modelicaCompInit, numNodesSub = obj_NgMoConverter.compInit(compInfo,node, modelInfo, subcktName,dir_name) print "ModelicaComponents : modelicaCompInit----------->",modelicaCompInit print "SubcktNumNodes : numNodesSub---------------->",numNodesSub -- cgit From dc5ea0f98eeb95f9cfd3d8110eb0ae987c77da89 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Tue, 29 Mar 2016 11:51:32 +0530 Subject: Modified MOSFET functionality according to new code --- src/ngspicetoModelica/NgspicetoModelica.py | 93 ++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 31 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index f4402b80..86c96bc1 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -64,7 +64,7 @@ class NgMoConverter: elif eachline[0] in self.deviceList: if eachline[0]=='m' or eachline[0]=='M': self.ifMOS = True - schematicInfo.append(eachline) + #schematicInfo.append(eachline) self.deviceDetail.append(eachline) elif eachline[0]=='v' or eachline[0]=='V': #schematicInfo.append(eachline) @@ -291,7 +291,7 @@ class NgMoConverter: return keyval - def compInit(self,compInfo, node, modelInfo, subcktName,dir_name): + def compInit(self,compInfo, node, modelInfo, subcktName,dir_name,transInfo): """ For each component in the netlist initialize it according to Modelica format """ @@ -299,6 +299,7 @@ class NgMoConverter: #### 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() @@ -371,7 +372,6 @@ class NgMoConverter: modelicaCompInit.append(stat) elif eachline[0]=='q' or eachline[0]=='Q': - print "Starting Transistor" if words[4]=='npn': start = 'Analog.Semiconductors.NPN ' elif words[4]=='pnp': @@ -394,6 +394,63 @@ class NgMoConverter: mjc = self.tryExists(modelInfo,words,4, 'mjc', 0.333) stat = start + words[0] +'(Bf = ' + bf + ', Br = ' + br + ', Is = ' +Is+ ', Vak = ' + vak + ', Tauf = ' +tf+ ', Taur = ' +tr+ ', Ccs = ' +cjs+ ', Cje = ' +cje+ ', Cjc = ' +cjc+ ', Phie = ' + vje + ', Me = ' + mje + ', Phic = ' + vjc + ', Mc = ' + mjc + ');' modelicaCompInit.append(stat) + + elif eachline[0]=='m' or eachline[0]=="M": + print "Starting Mosfet" + eachline = eachline.split(words[5]) + eachline = eachline[1] + eachline = eachline.strip() + eachline = eachline.replace(' = ', '=').replace('= ','=').replace(' =','=').replace(' * ', '*').replace(' + ', '+').replace(' { ', '').replace(' } ', '') + eachline = eachline.split() + mosInfo[words[0]] = {} + for each in eachline: + if len(each) > 1: + each = each.split('=') + mosInfo[words[0]][each[0]] = each[1] + trans = transInfo[words[5]] + if trans == 'nmos': + start = 'BondLib.Electrical.Analog.Spice.Mn ' + else: + start = 'BondLib.Electrical.Analog.Spice.Mp ' + vto = self.tryExists(modelInfo,words,5,'vto',0) + gam = self.tryExists(modelInfo,words,5,'gamma',0) + phi = self.tryExists(modelInfo,words,5, 'phi', 0) + ld = self.tryExists(modelInfo,words,5,'ld',0) + uo = self.tryExists(modelInfo,words,5,'uo',0) + lam = self.tryExists(modelInfo,words,5,'lambda',0) + tox = self.tryExists(modelInfo,words,5,'tox',3e-9) + pb = self.tryExists(modelInfo,words,5, 'pb',0.8) + cj = self.tryExists(modelInfo,words,5, 'cj',0) + cjsw = self.tryExists(modelInfo,words,5, 'cjsw',1e-9) + mj = self.tryExists(modelInfo,words,5, 'mj',0.33) + mjsw = self.tryExists(modelInfo,words,5, 'mjsw',0.33) + cgdo = self.tryExists(modelInfo,words,5, 'cgdo',0) + js = self.tryExists(modelInfo,words,5, 'js',0) + cgbo = self.tryExists(modelInfo,words,5, 'cgbo',0) + cgso = self.tryExists(modelInfo,words,5,'cgso',0) + try: + l = mosInfo[words[0]]['l'] + except KeyError: + l = '1e-6' + try: + w = mosInfo[words[0]]['w'] + except KeyError: + w = '100e-6' + try: + As = mosInfo[words[0]]['as'] + ad = mosInfo[words[0]]['ad'] + except KeyError: + As = '0' + ad = '0' + try: + ps = mosInfo[words[0]]['ps'] + pd = mosInfo[words[0]]['pd'] + except KeyError: + ps = '0' + pd = '0' + stat = start + words[0] + '(Tnom = 300, VT0 = ' + vto + ', GAMMA = ' + gam + ', PHI = ' + phi + ', LD = ' +ld+ ', U0 = ' + str(float(uo)*0.0001) + ', LAMBDA = ' + lam + ', TOX = ' +tox+ ', PB = ' + pb + ', CJ = ' +cj+ ', CJSW = ' +cjsw+ ', MJ = ' + mj + ', MJSW = ' + mjsw + ', CGD0 = ' +cgdo+ ', JS = ' +js+ ', CGB0 = ' +cgbo+ ', CGS0 = ' +cgso+ ', L = ' +l+ ', W = ' + w + ', Level = 1' + ', AD = ' + ad + ', AS = ' + As + ', PD = ' + pd + ', PS = ' + ps + ');' + stat = stat.translate(maketrans('{}', ' ')) + modelicaCompInit.append(stat) for eachline in compInfo: @@ -422,33 +479,7 @@ class NgMoConverter: elif eachline[0] == 'h': stat = 'Analog.Basic.CCV ' + words[0] + '(transResistance = ' + self.splitIntoVal(words[4]) + ');' modelicaCompInit.append(stat) - - elif eachline[0] == 'm': - line_l = words[7].split('=') - line_w = words[8].split('=') - line_pd = words[9].split('=') - line_ps = words[10].split('=') - line_ad = words[11].split('=') - line_as = words[12].split('=') - if words[5] == "mos_n" or words[5] == "mosfet_n": - start = 'BondLib.Electrical.Analog.Spice.Mn ' - if words[5] == "mos_p" or words[5] == "mosfet_p": - start = 'BondLib.Electrical.Analog.Spice.Mp ' - stat = start + words[0] + '(Tnom = 300, VT0 = ' + modelInfo[\ - words[5]]['vto'] + ', GAMMA = ' + modelInfo[words[5]]['gamma'] +\ - ', PHI = ' + modelInfo[words[5]]['phi'] + ', LD = ' + self.splitIntoVal(modelInfo[words[5]]['ld'])\ - + ', U0 = ' + str(float(self.splitIntoVal(modelInfo[words[5]]['uo']))*0.0001) + ', LAMBDA = ' \ - + modelInfo[words[5]]['lambda'] + ', TOX = ' + self.splitIntoVal(modelInfo[words[5]]['tox']) \ - + ', PB = ' + modelInfo[words[5]]['pb'] + ', CJ = ' + self.splitIntoVal(modelInfo[words[5]]['cj']) \ - + ', CJSW = ' + self.splitIntoVal(modelInfo[words[5]]['cjsw']) + ', MJ = ' + modelInfo[words[5]]['mj'] \ - + ', MJSW = ' + modelInfo[words[5]]['mjsw'] + ', CGD0 = ' + self.splitIntoVal(modelInfo[words[5]]['cgdo']) \ - + ', JS = ' + self.splitIntoVal(modelInfo[words[5]]['js']) + ', CGB0 = ' + self.splitIntoVal(modelInfo[words[5]]['cgbo']) \ - + ', CGS0 = ' + self.splitIntoVal(modelInfo[words[5]]['cgso']) + ', L = ' + self.splitIntoVal(line_l[1]) + ', W = ' \ - + line_w[1] + ', Level = 1' + ', AD = ' + line_ad[1] + ', AS = ' + line_as[1] + ', PD = ' \ - + line_pd[1] + ', PS = ' + line_pd[1] + ');' - stat = stat.translate(maketrans('{}', ' ')) - modelicaCompInit.append(stat) - + elif eachline[0] == 'x': temp_line = eachline.split() temp = temp_line[0].split('x') @@ -840,7 +871,7 @@ def main(args): #print "PinInit-------------->",pinInit #print "pinProtectedInit----------->",pinProtectedInit - modelicaCompInit, numNodesSub = obj_NgMoConverter.compInit(compInfo,node, modelInfo, subcktName,dir_name) + modelicaCompInit, numNodesSub = obj_NgMoConverter.compInit(compInfo,node, modelInfo, subcktName,dir_name,transInfo) print "ModelicaComponents : modelicaCompInit----------->",modelicaCompInit print "SubcktNumNodes : numNodesSub---------------->",numNodesSub -- cgit From 3e77eeefe130134733eeef04512da0546c4beb63 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Tue, 29 Mar 2016 12:09:05 +0530 Subject: Modifeid code for sub circuit --- src/ngspicetoModelica/NgspicetoModelica.py | 38 +++++++++++++++++------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 86c96bc1..bda2e14e 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -16,6 +16,7 @@ class NgMoConverter: self.ifMOS = False self.sourceDetail = [] self.deviceDetail = [] + self.subCktDetail = [] self.deviceList = ['d','D','j','J','q','Q'] #MOSFET is excluded as it has special case @@ -66,6 +67,8 @@ class NgMoConverter: self.ifMOS = True #schematicInfo.append(eachline) self.deviceDetail.append(eachline) + elif eachline[0]=='x' or eachline[0]=='X': + self.subCktDetail.append(eachline) elif eachline[0]=='v' or eachline[0]=='V': #schematicInfo.append(eachline) self.sourceDetail.append(eachline) @@ -451,6 +454,25 @@ class NgMoConverter: stat = start + words[0] + '(Tnom = 300, VT0 = ' + vto + ', GAMMA = ' + gam + ', PHI = ' + phi + ', LD = ' +ld+ ', U0 = ' + str(float(uo)*0.0001) + ', LAMBDA = ' + lam + ', TOX = ' +tox+ ', PB = ' + pb + ', CJ = ' +cj+ ', CJSW = ' +cjsw+ ', MJ = ' + mj + ', MJSW = ' + mjsw + ', CGD0 = ' +cgdo+ ', JS = ' +js+ ', CGB0 = ' +cgbo+ ', CGS0 = ' +cgso+ ', L = ' +l+ ', W = ' + w + ', Level = 1' + ', AD = ' + ad + ', AS = ' + As + ', PD = ' + pd + ', PS = ' + ps + ');' stat = stat.translate(maketrans('{}', ' ')) modelicaCompInit.append(stat) + + #Lets start for Subcircuit + for eachline in self.subCktDetail: + temp_line = eachline.split() + temp = temp_line[0].split('x') + index = temp[1] + for i in range(0,len(temp_line),1): + if temp_line[i] in subcktName: + subname = temp_line[i] + numNodesSub[subname] = i - 1 + point = i + if len(temp_line) > point + 1: + rem = temp_line[point+1:len(temp_line)] + rem_new = ','.join(rem) + stat = subname + ' ' + subname +'_instance' + index + '(' + rem_new + ');' + else: + stat = subname + ' ' + subname +'_instance' + index + ';' + modelicaCompInit.append(stat) + for eachline in compInfo: @@ -480,22 +502,6 @@ class NgMoConverter: stat = 'Analog.Basic.CCV ' + words[0] + '(transResistance = ' + self.splitIntoVal(words[4]) + ');' modelicaCompInit.append(stat) - elif eachline[0] == 'x': - temp_line = eachline.split() - temp = temp_line[0].split('x') - index = temp[1] - for i in range(0,len(temp_line),1): - if temp_line[i] in subcktName: - subname = temp_line[i] - numNodesSub[subname] = i - 1 - point = i - if len(temp_line) > point + 1: - rem = temp_line[point+1:len(temp_line)] - rem_new = ','.join(rem) - stat = subname + ' ' + subname +'_instance' + index + '(' + rem_new + ');' - else: - stat = subname + ' ' + subname +'_instance' + index + ';' - modelicaCompInit.append(stat) else: continue -- cgit From b1b818837136a647084b3133fa913622894e490f Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Tue, 29 Mar 2016 14:47:16 +0530 Subject: Remove zero voltage source from netlist --- src/ngspicetoModelica/NgspicetoModelica.py | 50 +++++++++++++++++++----------- 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index bda2e14e..eb5842d2 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -71,7 +71,11 @@ class NgMoConverter: self.subCktDetail.append(eachline) elif eachline[0]=='v' or eachline[0]=='V': #schematicInfo.append(eachline) - self.sourceDetail.append(eachline) + #Removing zero voltage source as it is not require in Modelica + if eachline.split()[-1]=='0': + continue + else: + self.sourceDetail.append(eachline) else: schematicInfo.append(eachline) ##No need of making it lower case as netlist is already converted to ngspice @@ -526,7 +530,7 @@ class NgMoConverter: nodesInfoLine = intLine[0:newindex] return nodesInfoLine - def getSubParamLine(self,subname, numNodesSub, subParamInfo): + def getSubParamLine(self,subname, numNodesSub, subParamInfo,dir_name): """ Take subcircuit name and give the info related to parameters in the first line and initislise it in """ @@ -534,10 +538,10 @@ class NgMoConverter: subOptionInfo_p = [] subSchemInfo_p = [] filename_t = subname + '.sub' + filename_t = os.path.join(dir_name, filename_t) data_p = self.readNetlist(filename_t) subOptionInfo_p, subSchemInfo_p = self.separateNetlistInfo(data_p) - print "subOptionInfo_p------------------------->",subOptionInfo_p - print "subSchemInfo_p----------------------------->",subSchemInfo_p + if len(subOptionInfo_p) > 0: newline = subOptionInfo_p[0] newline = newline.split('.subckt '+ subname) @@ -571,16 +575,16 @@ class NgMoConverter: for eachline in compInfo: words = eachline.split() - if eachline[0] in ['m', 'e', 'g', 't']: + if eachline[0] in ['m', 'e', 'g', 't','M','E','G','T']: nodeTemp.append(words[1]) nodeTemp.append(words[2]) nodeTemp.append(words[3]) nodeTemp.append(words[4]) - elif eachline[0] in ['q', 'j']: + elif eachline[0] in ['q', 'j','J','Q']: nodeTemp.append(words[1]) nodeTemp.append(words[2]) nodeTemp.append(words[3]) - elif eachline[0] == 'x': + elif eachline[0]=='x' or eachline[0]=='X': templine = eachline.split() for i in range(0,len(templine),1): if templine[i] in subcktName: @@ -632,12 +636,13 @@ class NgMoConverter: sourcesInfo = self.separateSource(compInfo) for eachline in compInfo: words = eachline.split() - if eachline[0] == 'r' or eachline[0] == 'c' or eachline[0] == 'd' or eachline[0] == 'l' or eachline[0] == 'v': + if eachline[0]=='r' or eachline[0]=='R' or eachline[0]=='c' or eachline[0]=='C' or eachline[0]=='d' or eachline[0]=='D' \ + or eachline[0]=='l' or eachline[0]=='L' or eachline[0]=='v' or eachline[0]=='V': conn = 'connect(' + words[0] + '.p,' + nodeDic[words[1]] + ');' connInfo.append(conn) conn = 'connect(' + words[0] + '.n,' + nodeDic[words[2]] + ');' connInfo.append(conn) - elif eachline[0] == 'm': + elif eachline[0]=='m' or eachline[0]=='M': conn = 'connect(' + words[0] + '.D,' + nodeDic[words[1]] + ');' connInfo.append(conn) conn = 'connect(' + words[0] + '.G,' + nodeDic[words[2]] + ');' @@ -646,7 +651,7 @@ class NgMoConverter: connInfo.append(conn) conn = 'connect(' + words[0] + '.B,' + nodeDic[words[4]] + ');' connInfo.append(conn) - elif eachline[0] in ['f','h']: + elif eachline[0] in ['f','h','F','H']: vsource = words[3] sourceNodes = sourcesInfo[vsource] sourceNodes = sourceNodes.split() @@ -658,7 +663,16 @@ class NgMoConverter: connInfo.append(conn) conn = 'connect(' + words[0] + '.n2,'+ nodeDic[words[2]] + ');' connInfo.append(conn) - elif eachline[0] in ['g','e']: + elif eachline[0] in ['g','e','G','E']: + conn = 'connect(' + words[0] + '.p1,'+ nodeDic[words[3]] + ');' + connInfo.append(conn) + conn = 'connect(' + words[0] + '.n1,'+ nodeDic[words[4]] + ');' + connInfo.append(conn) + conn = 'connect(' + words[0] + '.p2,'+ nodeDic[words[1]] + ');' + connInfo.append(conn) + conn = 'connect(' + words[0] + '.n2,'+ nodeDic[words[2]] + ');' + connInfo.append(conn) + elif eachline[0] in ['g','e','G','E']: conn = 'connect(' + words[0] + '.p1,'+ nodeDic[words[3]] + ');' connInfo.append(conn) conn = 'connect(' + words[0] + '.n1,'+ nodeDic[words[4]] + ');' @@ -667,7 +681,7 @@ class NgMoConverter: connInfo.append(conn) conn = 'connect(' + words[0] + '.n2,'+ nodeDic[words[2]] + ');' connInfo.append(conn) - elif eachline[0] == 'x': + elif eachline[0]=='x' or eachline[0]=='X': templine = eachline.split() temp = templine[0].split('x') index = temp[1] @@ -681,14 +695,14 @@ class NgMoConverter: connInfo.append(conn) else: continue - if '0' in node: + if '0' or 'gnd' in node: conn = 'connect(g.p,n0);' connInfo.append(conn) return connInfo - def procesSubckt(self,subcktName,numNodesSub): + def procesSubckt(self,subcktName,numNodesSub,dir_name): #Process the subcircuit file .sub in the project folder @@ -699,8 +713,8 @@ class NgMoConverter: subModelInfo = {} subsubName = [] subParamInfo = [] - subinbuiltmodelName = [] - subinbuiltmodelInfo = {} + #subinbuiltmodelName = [] + #subinbuiltmodelInfo = {} nodeSubInterface = [] nodeSub = [] nodeDicSub = {} @@ -762,7 +776,7 @@ class NgMoConverter: modelicaSubCompInit, numNodesSubsub = self.compInit(subSchemInfo, nodeSub, subModelInfo, subsubName) print "modelicaSubCompInit--------------------->",modelicaSubCompInit print "numNodesSubsub-------------------------->",numNodesSubsub - modelicaSubParamNew = self.getSubParamLine(eachsub, numNodesSub, modelicaSubParam) ###Ask Manas + modelicaSubParamNew = self.getSubParamLine(eachsub, numNodesSub, modelicaSubParam,dir_name) ###Ask Manas print "modelicaSubParamNew----------------->",modelicaSubParamNew connSubInfo = self.connectInfo(subSchemInfo, nodeSub, nodeDicSub, numNodesSubsub,subcktName) newname = filename.split('.') @@ -889,7 +903,7 @@ def main(args): ###After Sub Ckt Func if len(subcktName) > 0: data, subOptionInfo, subSchemInfo, subModel, subModelInfo, subsubName,subParamInfo, modelicaSubCompInit, modelicaSubParam,\ - nodeSubInterface,nodeSub, nodeDicSub, pinInitSub, connSubInfo = obj_NgMoConverter.procesSubckt(subcktName,numNodesSub) #Adding 'numNodesSub' by Fahim + nodeSubInterface,nodeSub, nodeDicSub, pinInitSub, connSubInfo = obj_NgMoConverter.procesSubckt(subcktName,numNodesSub,dir_name) #Adding 'numNodesSub' by Fahim #Creating Final Output file newfile = filename.split('.') -- cgit From 4569b2cb1ca37e6e291640d269521897760541c0 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Tue, 29 Mar 2016 17:54:10 +0530 Subject: Remove the unwanted import statement --- src/ngspicetoModelica/NgspicetoModelica.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index eb5842d2..d2d36c8c 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -3,7 +3,6 @@ import os import re import json from string import maketrans -from lepl.matchers.derived import Star class NgMoConverter: @@ -955,4 +954,4 @@ def main(args): # Call main function if __name__ == '__main__': - main(sys.argv) \ No newline at end of file + main(sys.argv) -- cgit From 8ac1b2874949f65dda3d940de77cc315a3babd69 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Wed, 30 Mar 2016 14:16:34 +0530 Subject: Remove splitval function completly --- src/ngspicetoModelica/NgspicetoModelica.py | 68 ++---------------------------- 1 file changed, 4 insertions(+), 64 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index d2d36c8c..c89c742b 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -121,18 +121,6 @@ class NgMoConverter: iteminfo = eachitem.split('=') for each in iteminfo: modelInfo[model][iteminfo[0]] = iteminfo[1] - - """ - name = words[1]+':'+words[2].split('(')[0] #model_ref_name:actual_model_name - modelName.append(name) - modelInfo[name] = {} - #Get all the data with () of .model line - paramData = re.compile("\((.*)\)" ).search(eachline).group(1) - info = paramData.split() - for eachitem in info: - eachitem = eachitem.split('=') - modelInfo[name][eachitem[0]] = eachitem[1] - """ #Adding details of model(external) and subckt into modelInfo and subcktInfo print "Model Name ------------ >",modelName @@ -170,22 +158,6 @@ class NgMoConverter: for eachitem in info: modelInfo[refModelName][info[0]] = info[1] f.close() - ''' - #First fetch the refModelName and then lower case its parameter - refModelName = newdata[0].split()[1] - newdata[1] = newdata[1].lower() - modelParameter = newdata[1].split() - - modelInfo[refModelName] = {} - - for eachline in modelParameter: - if len(eachline) > 1: - info = eachline.split('=') - # modelInfo[eachmodel][info[0]] = {} - for eachitem in info: - modelInfo[refModelName][info[0]] = info[1] #dic within a dic - f.close() - ''' return modelName, modelInfo, subcktName, paramInfo ,transInfo @@ -240,38 +212,6 @@ class NgMoConverter: sourceInfo[words_s[0]] = words_s[1:3] return sourceInfo - def splitIntoVal(self,val): - """ - Split the number k,u,p,t,g etc into powers e3,e-6 etc - """ - for i in range(0,len(val),1): - if val[i] in ['k','u','p','t','g','m','n','f']: - newval = val.split(val[i]) - if val[i] == 'k': - value = newval[0] + 'e3' - if val[i] == 'u': - value = newval[0] + 'e-6' - if val[i] == 'p': - value = newval[0] + 'e-12' - if val[i] == 't': - value = newval[0] + 'e12' - if val[i] == 'g': - value = newval[0] + 'e9' - if val[i] == 'm': - if i != len(val)-1: - if val[i+1] == 'e': - value = newval[0] + 'e6' - else: - value = newval[0] +'e-3' - if val[i] == 'n': - value = newval[0] + 'e-9' - if val[i] == 'f': - value = newval[0] +'e-15' - - else: - value = val - return value - def getUnitVal(self,compValue): print "Received compValue--------> ",compValue regExp = re.compile("([0-9]+)([a-zA-Z]+)") @@ -493,16 +433,16 @@ class NgMoConverter: stat = 'Analog.Basic.Inductor ' + words[0] + '(L = ' + value + ');' modelicaCompInit.append(stat) elif eachline[0] == 'e': - stat = 'Analog.Basic.VCV ' + words[0] + '(gain = ' + self.splitIntoVal(words[5]) + ');' + stat = 'Analog.Basic.VCV ' + words[0] + '(gain = ' + self.getUnitVal(words[5]) + ');' modelicaCompInit.append(stat) elif eachline[0] == 'g': - stat = 'Analog.Basic.VCC ' + words[0] + '(transConductance = ' + self.splitIntoVal(words[5]) + ');' + stat = 'Analog.Basic.VCC ' + words[0] + '(transConductance = ' + self.getUnitVal(words[5]) + ');' modelicaCompInit.append(stat) elif eachline[0] == 'f': - stat = 'Analog.Basic.CCC ' + words[0] + '(gain = ' + self.splitIntoVal(words[4]) + ');' + stat = 'Analog.Basic.CCC ' + words[0] + '(gain = ' + self.getUnitVal(words[4]) + ');' modelicaCompInit.append(stat) elif eachline[0] == 'h': - stat = 'Analog.Basic.CCV ' + words[0] + '(transResistance = ' + self.splitIntoVal(words[4]) + ');' + stat = 'Analog.Basic.CCV ' + words[0] + '(transResistance = ' + self.getUnitVal(words[4]) + ');' modelicaCompInit.append(stat) else: -- cgit From 9ff48b10ff4c184aa605003df48ccf463ccecf2b Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Thu, 31 Mar 2016 14:00:58 +0530 Subject: Modified getUnitVal function to accomodate decimal values --- src/ngspicetoModelica/NgspicetoModelica.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index c89c742b..6fe75516 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -214,12 +214,17 @@ class NgMoConverter: def getUnitVal(self,compValue): print "Received compValue--------> ",compValue - regExp = re.compile("([0-9]+)([a-zA-Z]+)") + #regExp = re.compile("([0-9]+)([a-zA-Z]+)") + regExp = re.compile("([0-9]+)\.?([0-9]+)?([a-zA-Z])?") matchString = regExp.match(str(compValue)) #separating number and string try: - numValue = matchString.group(1) - unitValue = matchString.group(2) - modifiedcompValue = numValue+self.mappingData["Units"][unitValue] + valBeforeDecimal = matchString.group(1) + valAfterDecimal = matchString.group(2) + unitValue = matchString.group(3) + if str(valAfterDecimal)=='None': + modifiedcompValue = valBeforeDecimal+self.mappingData["Units"][unitValue] + else: + modifiedcompValue = valBeforeDecimal+'.'+valAfterDecimal+self.mappingData["Units"][unitValue] return modifiedcompValue except: return compValue -- cgit From fefb08b28917b55a545815b517c19736934fe3e4 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Tue, 5 Apr 2016 16:17:06 +0530 Subject: Modified subcircuit functionality in Openmodelica --- src/ngspicetoModelica/NgspicetoModelica.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 6fe75516..fa915c41 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -405,6 +405,9 @@ class NgMoConverter: #Lets start for Subcircuit for eachline in self.subCktDetail: + print "each Line-------->",eachline + global point + global subname temp_line = eachline.split() temp = temp_line[0].split('x') index = temp[1] @@ -717,7 +720,7 @@ class NgMoConverter: print "NodeDicSub-------------------------->",nodeDicSub print "PinInitSub-------------------------->",pinInitSub print "PinProtectedInitSub------------------->",pinProtectedInitSub - modelicaSubCompInit, numNodesSubsub = self.compInit(subSchemInfo, nodeSub, subModelInfo, subsubName) + modelicaSubCompInit, numNodesSubsub = self.compInit(subSchemInfo, nodeSub, subModelInfo, subsubName,dir_name,transInfo) print "modelicaSubCompInit--------------------->",modelicaSubCompInit print "numNodesSubsub-------------------------->",numNodesSubsub modelicaSubParamNew = self.getSubParamLine(eachsub, numNodesSub, modelicaSubParam,dir_name) ###Ask Manas -- cgit From 68ab58bafcb572f3d75a06e85c62aede7eadbff9 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Wed, 13 Apr 2016 14:09:57 +0530 Subject: Subject:Modified to append the voltage,device and subcircuit detail into schematicInfo Description:Modified to append the voltage,device and subcircuit detail into schematicInfo --- src/ngspicetoModelica/NgspicetoModelica.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index fa915c41..0ebf8436 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -64,12 +64,12 @@ class NgMoConverter: elif eachline[0] in self.deviceList: if eachline[0]=='m' or eachline[0]=='M': self.ifMOS = True - #schematicInfo.append(eachline) + schematicInfo.append(eachline) self.deviceDetail.append(eachline) elif eachline[0]=='x' or eachline[0]=='X': self.subCktDetail.append(eachline) elif eachline[0]=='v' or eachline[0]=='V': - #schematicInfo.append(eachline) + schematicInfo.append(eachline) #Removing zero voltage source as it is not require in Modelica if eachline.split()[-1]=='0': continue @@ -236,7 +236,6 @@ class NgMoConverter: try: keyval = modelInfo[words[wordNo]][key] keyval = self.getUnitVal(keyval) - print "Key------->",modelInfo except KeyError: keyval = str(default) return keyval @@ -423,8 +422,7 @@ class NgMoConverter: else: stat = subname + ' ' + subname +'_instance' + index + ';' modelicaCompInit.append(stat) - - + for eachline in compInfo: words = eachline.split() @@ -572,6 +570,10 @@ class NgMoConverter: pinInit = pinInit + nodeDic[protectedNode[i]] pinInit = pinInit + ';' pinProtectedInit = pinProtectedInit + ';' + print "Node---->",node + print "nodeDic----->",nodeDic + print "PinInit----->",pinInit + print "pinProtectedinit--->",pinProtectedInit return node, nodeDic, pinInit, pinProtectedInit @@ -580,15 +582,27 @@ class NgMoConverter: Make node connections in the modelica netlist """ connInfo = [] + print "compinfo-------->",compInfo sourcesInfo = self.separateSource(compInfo) for eachline in compInfo: words = eachline.split() + print "eachline----->",eachline + print "eachline[0]------->",eachline[0] if eachline[0]=='r' or eachline[0]=='R' or eachline[0]=='c' or eachline[0]=='C' or eachline[0]=='d' or eachline[0]=='D' \ or eachline[0]=='l' or eachline[0]=='L' or eachline[0]=='v' or eachline[0]=='V': conn = 'connect(' + words[0] + '.p,' + nodeDic[words[1]] + ');' connInfo.append(conn) conn = 'connect(' + words[0] + '.n,' + nodeDic[words[2]] + ');' connInfo.append(conn) + elif eachline[0]=='q' or eachline[0]=='Q': + print "Inside Transistor--->" + print "Node Dict------>",nodeDic + conn = 'connect(' + words[0] + '.C,' + nodeDic[words[1]] + ');' + connInfo.append(conn) + conn = 'connect(' + words[0] + '.B,' + nodeDic[words[2]] + ');' + connInfo.append(conn) + conn = 'connect(' + words[0] + '.E,' + nodeDic[words[3]] + ');' + connInfo.append(conn) elif eachline[0]=='m' or eachline[0]=='M': conn = 'connect(' + words[0] + '.D,' + nodeDic[words[1]] + ');' connInfo.append(conn) -- cgit From 6cb70b28dd399fb2bc460b7412fddbfd59c8244d Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Fri, 15 Apr 2016 12:03:12 +0530 Subject: Remove Extra condition --- src/ngspicetoModelica/NgspicetoModelica.py | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 0ebf8436..8509a883 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -633,15 +633,6 @@ class NgMoConverter: connInfo.append(conn) conn = 'connect(' + words[0] + '.n2,'+ nodeDic[words[2]] + ');' connInfo.append(conn) - elif eachline[0] in ['g','e','G','E']: - conn = 'connect(' + words[0] + '.p1,'+ nodeDic[words[3]] + ');' - connInfo.append(conn) - conn = 'connect(' + words[0] + '.n1,'+ nodeDic[words[4]] + ');' - connInfo.append(conn) - conn = 'connect(' + words[0] + '.p2,'+ nodeDic[words[1]] + ');' - connInfo.append(conn) - conn = 'connect(' + words[0] + '.n2,'+ nodeDic[words[2]] + ');' - connInfo.append(conn) elif eachline[0]=='x' or eachline[0]=='X': templine = eachline.split() temp = templine[0].split('x') -- cgit From a17747edc9d3829603358b8de48e7b2ce1ba5e09 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Mon, 18 Apr 2016 11:56:26 +0530 Subject: Gnd issue solved --- src/ngspicetoModelica/NgspicetoModelica.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 8509a883..813f1a5e 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -454,7 +454,7 @@ class NgMoConverter: else: continue - if '0' or 'gnd' in node: + if '0' in node: modelicaCompInit.append('Analog.Basic.Ground g;') return modelicaCompInit, numNodesSub @@ -647,7 +647,7 @@ class NgMoConverter: connInfo.append(conn) else: continue - if '0' or 'gnd' in node: + if '0' in node: conn = 'connect(g.p,n0);' connInfo.append(conn) -- cgit From f9f323cb8f895dd7e1378b8c97ced398ad472b4a Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Mon, 18 Apr 2016 12:23:59 +0530 Subject: Utilised Get UnitFunction for Source value as well --- src/ngspicetoModelica/NgspicetoModelica.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 813f1a5e..0aaf7936 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -278,16 +278,16 @@ class NgMoConverter: typ = words[3].split('(') if typ[0] == "pulse": per = words[9].split(')') - stat = self.mappingData["Sources"][typ[0]]+' '+words[0]+'(rising = '+words[6]+', V = '+words[4]\ - +', width = '+words[8]+', period = '+per[0]+', offset = '+typ[1]+', startTime = '+words[5]+', falling = '+words[7]+');' + stat = self.mappingData["Sources"][typ[0]]+' '+words[0]+'(rising = '+self.getUnitVal(words[6])+', V = '+self.getUnitVal(words[4])\ + +', width = '+self.getUnitVal(words[8])+', period = '+self.getUnitVal(per[0])+', offset = '+self.getUnitVal(typ[1])+', startTime = '+self.getUnitVal(words[5])+', falling = '+self.getUnitVal(words[7])+');' modelicaCompInit.append(stat) if typ[0] == "sine": theta = words[7].split(')') - stat = self.mappingData["Sources"][typ[0]]+' '+words[0]+'(offset = '+typ[1]+', V = '+words[4]+', freqHz = '+words[5]+', startTime = '+words[6]+', phase = '+theta[0]+');' + stat = self.mappingData["Sources"][typ[0]]+' '+words[0]+'(offset = '+self.getUnitVal(typ[1])+', V = '+self.getUnitVal(words[4])+', freqHz = '+self.getUnitVal(words[5])+', startTime = '+self.getUnitVal(words[6])+', phase = '+self.getUnitVal(theta[0])+');' modelicaCompInit.append(stat) if typ[0] == "pwl": keyw = self.mappingData["Sources"][typ[0]]+' ' - stat = keyw + words[0] + '(table = [' + typ[1] + ',' + words[4] + ';' + stat = keyw + words[0] + '(table = [' + self.getUnitVal(typ[1]) + ',' + self.getUnitVal(words[4]) + ';' length = len(words); for i in range(6,length,2): if i == length-2: @@ -300,10 +300,10 @@ class NgMoConverter: if typ[0] == words[3] and typ[0] != "dc": #It is DC constant but no dc keyword val_temp = typ[0].split('v') - stat = self.mappingData["Sources"]["dc"]+' ' + words[0] + '(V = ' + val_temp[0] + ');' + stat = self.mappingData["Sources"]["dc"]+' ' + words[0] + '(V = ' + self.getUnitVal(val_temp[0]) + ');' modelicaCompInit.append(stat) elif typ[0] == words[3] and typ[0] == "dc": - stat = self.mappingData["Sources"][typ[0]]+' ' + words[0] + '(V = ' + words[4] + ');' ### check this + stat = self.mappingData["Sources"][typ[0]]+' ' + words[0] + '(V = ' + self.getUnitVal(words[4]) + ');' ### check this modelicaCompInit.append(stat) #Lets start for device -- cgit From c7283f5300b5c8704c8a7866bd9b4b2bb8ce169b Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Mon, 18 Apr 2016 12:41:02 +0530 Subject: Remove Zero Voltage condition as It is now working in OpenModelica OMEdit --- src/ngspicetoModelica/NgspicetoModelica.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 0aaf7936..169c382a 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -70,11 +70,7 @@ class NgMoConverter: self.subCktDetail.append(eachline) elif eachline[0]=='v' or eachline[0]=='V': schematicInfo.append(eachline) - #Removing zero voltage source as it is not require in Modelica - if eachline.split()[-1]=='0': - continue - else: - self.sourceDetail.append(eachline) + self.sourceDetail.append(eachline) else: schematicInfo.append(eachline) ##No need of making it lower case as netlist is already converted to ngspice -- cgit From 93dec048fc303048c8391b71f93add6b6d294b23 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Mon, 18 Apr 2016 13:43:13 +0530 Subject: Remove Unwanted lower function --- src/ngspicetoModelica/NgspicetoModelica.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 169c382a..0ea21b8d 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -269,7 +269,7 @@ class NgMoConverter: #Lets Start with Source details for eachline in self.sourceDetail: - eachline = eachline.lower() + #eachline = eachline.lower() words = eachline.split() typ = words[3].split('(') if typ[0] == "pulse": -- cgit From 55cfe66779913747c29f8c4fbc7e1a8e02c04f3c Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Mon, 18 Apr 2016 13:56:03 +0530 Subject: Modeified Lower case of Voltage Issue --- src/ngspicetoModelica/NgspicetoModelica.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 0ea21b8d..b6ea5835 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -269,8 +269,12 @@ class NgMoConverter: #Lets Start with Source details for eachline in self.sourceDetail: - #eachline = eachline.lower() words = eachline.split() + #Preserve component name from lower case function + compName = words[0] + #Now Lower case all other + words = eachline.lower().split() + words[0] = compName typ = words[3].split('(') if typ[0] == "pulse": per = words[9].split(')') -- cgit From b693280f4bcb6f662c3679145162e4d69dddf839 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Mon, 18 Apr 2016 15:49:44 +0530 Subject: Final gnd and zero issue resolved --- src/ngspicetoModelica/NgspicetoModelica.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index b6ea5835..d00e29dc 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -454,7 +454,7 @@ class NgMoConverter: else: continue - if '0' in node: + if '0' or 'gnd' in node: modelicaCompInit.append('Analog.Basic.Ground g;') return modelicaCompInit, numNodesSub @@ -650,6 +650,9 @@ class NgMoConverter: if '0' in node: conn = 'connect(g.p,n0);' connInfo.append(conn) + elif 'gnd' in node: + conn = 'connect(g.p,ngnd);' + connInfo.append(conn) return connInfo -- cgit From b5ae41e385deab139479d3992d99edcaf895fc2f Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Thu, 21 Apr 2016 11:35:51 +0530 Subject: started working for inbuit ngspice model --- src/ngspicetoModelica/NgspicetoModelica.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index d00e29dc..56225b30 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -16,7 +16,9 @@ class NgMoConverter: self.sourceDetail = [] self.deviceDetail = [] self.subCktDetail = [] + self.inbuiltModelDetail = [] self.deviceList = ['d','D','j','J','q','Q'] #MOSFET is excluded as it has special case + self.inbuiltModelList = {} def readNetlist(self,filename): @@ -70,7 +72,10 @@ class NgMoConverter: self.subCktDetail.append(eachline) elif eachline[0]=='v' or eachline[0]=='V': schematicInfo.append(eachline) - self.sourceDetail.append(eachline) + self.sourceDetail.append(eachline) + elif eachline[0]=='a' or eachline[0]=='A': + schematicInfo.append(eachline) + self.inbuiltModelDetail.append(eachline) else: schematicInfo.append(eachline) ##No need of making it lower case as netlist is already converted to ngspice @@ -119,7 +124,6 @@ class NgMoConverter: modelInfo[model][iteminfo[0]] = iteminfo[1] #Adding details of model(external) and subckt into modelInfo and subcktInfo - print "Model Name ------------ >",modelName for eachmodel in modelName: filename = eachmodel + '.lib' if os.path.exists(filename): @@ -209,7 +213,6 @@ class NgMoConverter: return sourceInfo def getUnitVal(self,compValue): - print "Received compValue--------> ",compValue #regExp = re.compile("([0-9]+)([a-zA-Z]+)") regExp = re.compile("([0-9]+)\.?([0-9]+)?([a-zA-Z])?") matchString = regExp.match(str(compValue)) #separating number and string @@ -247,6 +250,7 @@ class NgMoConverter: numNodesSub = {} mosInfo = {} IfMOS = '0' + for eachline in compInfo: #words = eachline.split() if eachline[0] == 'm': @@ -324,7 +328,7 @@ class NgMoConverter: elif eachline[0]=='q' or eachline[0]=='Q': if words[4]=='npn': start = 'Analog.Semiconductors.NPN ' - elif words[4]=='pnp': + else: start = 'Analog.Semiconductors.PNP ' inv_vak = float(self.tryExists(modelInfo,words,4, 'vaf', 50)) @@ -346,7 +350,6 @@ class NgMoConverter: modelicaCompInit.append(stat) elif eachline[0]=='m' or eachline[0]=="M": - print "Starting Mosfet" eachline = eachline.split(words[5]) eachline = eachline[1] eachline = eachline.strip() @@ -401,10 +404,14 @@ class NgMoConverter: stat = start + words[0] + '(Tnom = 300, VT0 = ' + vto + ', GAMMA = ' + gam + ', PHI = ' + phi + ', LD = ' +ld+ ', U0 = ' + str(float(uo)*0.0001) + ', LAMBDA = ' + lam + ', TOX = ' +tox+ ', PB = ' + pb + ', CJ = ' +cj+ ', CJSW = ' +cjsw+ ', MJ = ' + mj + ', MJSW = ' + mjsw + ', CGD0 = ' +cgdo+ ', JS = ' +js+ ', CGB0 = ' +cgbo+ ', CGS0 = ' +cgso+ ', L = ' +l+ ', W = ' + w + ', Level = 1' + ', AD = ' + ad + ', AS = ' + As + ', PD = ' + pd + ', PS = ' + ps + ');' stat = stat.translate(maketrans('{}', ' ')) modelicaCompInit.append(stat) + + #Lets start for inbuilt model of ngspice + for eachline in self.inbuiltModelDetail: + print "each line of inbuilt Model------->",eachline + print "Model Info--------->",modelInfo #Lets start for Subcircuit for eachline in self.subCktDetail: - print "each Line-------->",eachline global point global subname temp_line = eachline.split() @@ -491,7 +498,6 @@ class NgMoConverter: newline = subOptionInfo_p[0] newline = newline.split('.subckt '+ subname) intLine = newline[1].split() - print "numNodesSub Index---------->",numNodesSub newindex = numNodesSub[subname] appen_line = intLine[newindex:len(intLine)] appen_param = ','.join(appen_line) @@ -511,7 +517,7 @@ class NgMoConverter: 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): @@ -586,8 +592,8 @@ class NgMoConverter: sourcesInfo = self.separateSource(compInfo) for eachline in compInfo: words = eachline.split() - print "eachline----->",eachline - print "eachline[0]------->",eachline[0] + #print "eachline----->",eachline + #print "eachline[0]------->",eachline[0] if eachline[0]=='r' or eachline[0]=='R' or eachline[0]=='c' or eachline[0]=='C' or eachline[0]=='d' or eachline[0]=='D' \ or eachline[0]=='l' or eachline[0]=='L' or eachline[0]=='v' or eachline[0]=='V': conn = 'connect(' + words[0] + '.p,' + nodeDic[words[1]] + ');' -- cgit From 955682e89b02d66b1985687cd1d2466f6c06320e Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Thu, 21 Apr 2016 14:46:23 +0530 Subject: Inbuilt model of Ngspice is mapped(Only Zener is mapped for time being) --- src/ngspicetoModelica/NgspicetoModelica.py | 44 ++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 56225b30..72e2c6eb 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -18,7 +18,7 @@ class NgMoConverter: self.subCktDetail = [] self.inbuiltModelDetail = [] self.deviceList = ['d','D','j','J','q','Q'] #MOSFET is excluded as it has special case - self.inbuiltModelList = {} + self.inbuiltModelDict = {} def readNetlist(self,filename): @@ -113,6 +113,8 @@ class NgMoConverter: transInfo[trans] = [] if templine[2] in ['npn', 'pnp', 'pmos', 'nmos']: transInfo[trans] = templine[2] + else: + self.inbuiltModelDict[model]=templine[2] eachline[1] = eachline[1].lower() eachline = eachline[1].split() @@ -407,9 +409,45 @@ class NgMoConverter: #Lets start for inbuilt model of ngspice for eachline in self.inbuiltModelDetail: - print "each line of inbuilt Model------->",eachline - print "Model Info--------->",modelInfo + words=eachline.split() + userModelParamList = [] + #print "Model Info--------->",modelInfo + #print "Inbuilt Model Mapped to ref---------->",self.inbuiltModelDict + refName = words[-1] + print "Reference Model Name------->",refName + actualModelName = self.inbuiltModelDict[refName] + print "Actual Model Name------->",actualModelName + start = self.mappingData["Models"][actualModelName]["import"] + print "Import Statement-------->",start + stat = start +" "+ words[0]+"(" + tempstatList=[] + print "Start Stat-------->",stat + for key in modelInfo[refName]: + #If parameter is not mapped then it will just pass + try: + actualModelicaParam = self.mappingData["Models"][actualModelName]["mapping"][key] + tempstatList.append(actualModelicaParam+"="+modelInfo[refName][actualModelicaParam]+" ") + userModelParamList.append(str(actualModelicaParam)) + except: + pass + print "User Model list---->",userModelParamList + + #Running loop over default parameter of OpenModelica + for default in self.mappingData["Models"][actualModelName]["default"]: + if default in userModelParamList: + continue + else: + defaultValue = self.mappingData["Models"][actualModelName]["default"][default] + tempstatList.append(default+"="+defaultValue+" ") + + #print "My Stat------------>",stat + #print "Temp Stat List--------->",tempstatList + stat += ",".join(str(item) for item in tempstatList)+");" + print "End Stat---------->",stat + modelicaCompInit.append(stat) + + #Lets start for Subcircuit for eachline in self.subCktDetail: global point -- cgit From c86b02741c88f220219410508d388bbc56fa766f Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Thu, 21 Apr 2016 15:56:56 +0530 Subject: Modified inbuilt ngspice model code for getUnitVal function --- src/ngspicetoModelica/NgspicetoModelica.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 72e2c6eb..cdb41299 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -411,8 +411,6 @@ class NgMoConverter: for eachline in self.inbuiltModelDetail: words=eachline.split() userModelParamList = [] - #print "Model Info--------->",modelInfo - #print "Inbuilt Model Mapped to ref---------->",self.inbuiltModelDict refName = words[-1] print "Reference Model Name------->",refName actualModelName = self.inbuiltModelDict[refName] @@ -421,17 +419,17 @@ class NgMoConverter: print "Import Statement-------->",start stat = start +" "+ words[0]+"(" tempstatList=[] - print "Start Stat-------->",stat + print "Start of Stat-------->",stat for key in modelInfo[refName]: #If parameter is not mapped then it will just pass try: actualModelicaParam = self.mappingData["Models"][actualModelName]["mapping"][key] - tempstatList.append(actualModelicaParam+"="+modelInfo[refName][actualModelicaParam]+" ") + tempstatList.append(actualModelicaParam+"="+self.getUnitVal(modelInfo[refName][key])+" ") userModelParamList.append(str(actualModelicaParam)) except: pass - print "User Model list---->",userModelParamList + print "User Model Parameter list---->",userModelParamList #Running loop over default parameter of OpenModelica for default in self.mappingData["Models"][actualModelName]["default"]: @@ -439,7 +437,7 @@ class NgMoConverter: continue else: defaultValue = self.mappingData["Models"][actualModelName]["default"][default] - tempstatList.append(default+"="+defaultValue+" ") + tempstatList.append(default+"="+self.getUnitVal(defaultValue)+" ") #print "My Stat------------>",stat #print "Temp Stat List--------->",tempstatList -- cgit From a89ff374e616efcc48945d8644f6d329f18a05bb Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Thu, 21 Apr 2016 16:35:23 +0530 Subject: Remove hyphen from ngspice node --- src/ngspicetoModelica/NgspicetoModelica.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index cdb41299..5467b98b 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -558,6 +558,8 @@ class NgMoConverter: #Removing '[' and ']' from compInfo for Digital node for i in range(0,len(compInfo),1): compInfo[i] = compInfo[i].replace("[","").replace("]","") + #Remove "-" from node as it does not work in modelica + compInfo[i] = compInfo[i].replace("-","") for eachline in compInfo: @@ -583,7 +585,8 @@ class NgMoConverter: for i in nodeTemp: if i not in node: node.append(i) - + + for i in range(0, len(node),1): nodeDic[node[i]] = 'n' + node[i] if ifSub == '0': -- cgit From 6147bc36dd3ab957b8700e7af26f5c2e2c43cfcc Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Thu, 21 Apr 2016 20:21:19 +0530 Subject: Modified code for mosfet--- Need to design again --- src/ngspicetoModelica/NgspicetoModelica.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 5467b98b..fbf7103e 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -17,7 +17,7 @@ class NgMoConverter: self.deviceDetail = [] self.subCktDetail = [] self.inbuiltModelDetail = [] - self.deviceList = ['d','D','j','J','q','Q'] #MOSFET is excluded as it has special case + self.deviceList = ['d','D','j','J','q','Q','m','M'] self.inbuiltModelDict = {} @@ -363,6 +363,7 @@ class NgMoConverter: each = each.split('=') mosInfo[words[0]][each[0]] = each[1] trans = transInfo[words[5]] + print "trans------------>",trans if trans == 'nmos': start = 'BondLib.Electrical.Analog.Spice.Mn ' else: @@ -404,7 +405,7 @@ class NgMoConverter: ps = '0' pd = '0' stat = start + words[0] + '(Tnom = 300, VT0 = ' + vto + ', GAMMA = ' + gam + ', PHI = ' + phi + ', LD = ' +ld+ ', U0 = ' + str(float(uo)*0.0001) + ', LAMBDA = ' + lam + ', TOX = ' +tox+ ', PB = ' + pb + ', CJ = ' +cj+ ', CJSW = ' +cjsw+ ', MJ = ' + mj + ', MJSW = ' + mjsw + ', CGD0 = ' +cgdo+ ', JS = ' +js+ ', CGB0 = ' +cgbo+ ', CGS0 = ' +cgso+ ', L = ' +l+ ', W = ' + w + ', Level = 1' + ', AD = ' + ad + ', AS = ' + As + ', PD = ' + pd + ', PS = ' + ps + ');' - stat = stat.translate(maketrans('{}', ' ')) + #stat = stat.translate(maketrans('{}', ' ')) #Not required modelicaCompInit.append(stat) #Lets start for inbuilt model of ngspice -- cgit From 5f6efbb2f906457d0982188068e3359f723988d0 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Fri, 22 Apr 2016 12:02:47 +0530 Subject: Modified Transistor import section code to include proper name from dictionary --- src/ngspicetoModelica/NgspicetoModelica.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index fbf7103e..2d608402 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -328,7 +328,8 @@ class NgMoConverter: modelicaCompInit.append(stat) elif eachline[0]=='q' or eachline[0]=='Q': - if words[4]=='npn': + trans = transInfo[words[4]] + if trans == 'npn': start = 'Analog.Semiconductors.NPN ' else: start = 'Analog.Semiconductors.PNP ' -- cgit From e70346be5682964b5e24463267609b0f32decd19 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Fri, 22 Apr 2016 12:33:43 +0530 Subject: Modified again for transistor --- src/ngspicetoModelica/NgspicetoModelica.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 2d608402..00a33604 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -111,6 +111,7 @@ class NgMoConverter: templine = eachline[0].split() trans = templine[1] transInfo[trans] = [] + templine[2] = templine[2].lower() if templine[2] in ['npn', 'pnp', 'pmos', 'nmos']: transInfo[trans] = templine[2] else: @@ -143,7 +144,8 @@ class NgMoConverter: newdata = data.split('(') templine_f = newdata[0].split() trans_f = templine_f[1] - transInfo[trans_f] = [] + transInfo[trans_f] = [] + templine_f[2] = templine_f[2].lower() if templine_f[2] in ['npn', 'pnp', 'pmos', 'nmos']: transInfo[trans_f] = templine_f[2] @@ -329,6 +331,8 @@ class NgMoConverter: elif eachline[0]=='q' or eachline[0]=='Q': trans = transInfo[words[4]] + print "Trans---------->",trans + print "TransInfo---------->",transInfo if trans == 'npn': start = 'Analog.Semiconductors.NPN ' else: -- cgit From a815ce722770e1e8271f5a5987b3d1ad88ff61e0 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Fri, 22 Apr 2016 19:33:33 +0530 Subject: Started new Mapping for Diode and Transistor --- src/ngspicetoModelica/NgspicetoModelica.py | 104 ++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 32 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 00a33604..9985b8f0 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -19,6 +19,7 @@ class NgMoConverter: self.inbuiltModelDetail = [] self.deviceList = ['d','D','j','J','q','Q','m','M'] self.inbuiltModelDict = {} + def readNetlist(self,filename): @@ -148,7 +149,7 @@ class NgMoConverter: templine_f[2] = templine_f[2].lower() if templine_f[2] in ['npn', 'pnp', 'pmos', 'nmos']: transInfo[trans_f] = templine_f[2] - + refModelName = trans_f newdata[1] = newdata[1].lower() modelParameter = newdata[1].split() @@ -317,46 +318,86 @@ class NgMoConverter: #Lets start for device for eachline in self.deviceDetail: words=eachline.split() - if eachline[0]=='d' or eachline[0]=='D': + deviceName = eachline[0].lower() + if deviceName=='d': if len(words)>3: if modelInfo[words[3]].has_key('n'): n = float(modelInfo[words[3]]['n']) else: n = 1.0 vt = str(float(0.025*n)) - stat = self.mappingData["Devices"][eachline[0]]+' '+ words[0] + '(Ids = ' + modelInfo[words[3]]['is'] + ', Vt = ' + vt + ', R = 1e12' +');' + #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]+"(" + tempstatList=[] + userDeviceParamList=[] + refName = words[-1] + for key in modelInfo[refName]: + #If parameter is not mapped then it will just pass + try: + actualModelicaParam = self.mappingData["Devices"][deviceName]["mapping"][key] + tempstatList.append(actualModelicaParam+"="+self.getUnitVal(modelInfo[refName][key])+" ") + userDeviceParamList.append(str(actualModelicaParam)) + except: + 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"][deviceName]["default"]: + if default in userDeviceParamList: + continue + else: + defaultValue = self.mappingData["Devices"][deviceName]["default"][default] + tempstatList.append(default+"="+self.getUnitVal(defaultValue)+" ") + + stat += ",".join(str(item) for item in tempstatList)+");" + else: - stat = self.mappingData["Devices"][eachline[0]]+' '+ words[0] +';' + stat = self.mappingData["Devices"][deviceName]["import"]+" "+ words[0] +";" modelicaCompInit.append(stat) - elif eachline[0]=='q' or eachline[0]=='Q': + elif deviceName=='q': trans = transInfo[words[4]] - print "Trans---------->",trans - print "TransInfo---------->",transInfo if trans == 'npn': - start = 'Analog.Semiconductors.NPN ' + start = self.mappingData["Devices"][deviceName]["import"]+".NPN" + elif trans == 'pnp': + start = self.mappingData["Devices"][deviceName]["import"]+".PNP" else: - start = 'Analog.Semiconductors.PNP ' - - inv_vak = float(self.tryExists(modelInfo,words,4, 'vaf', 50)) - vak_temp = 1/inv_vak - vak = str(vak_temp) - bf = self.tryExists(modelInfo,words,4, 'bf', 50) - br = self.tryExists(modelInfo,words,4, 'br', 0.1) - Is = self.tryExists(modelInfo,words,4, 'is', 1e-16) - tf = self.tryExists(modelInfo,words,4, 'tf', 1.2e-10) - tr = self.tryExists(modelInfo,words,4, 'tr', 5e-9) - cjs = self.tryExists(modelInfo,words,4, 'cjs', 1e-12) - cje = self.tryExists(modelInfo,words,4, 'cje', 4e-13) - cjc = self.tryExists(modelInfo,words,4, 'cjc', 5e-13) - vje = self.tryExists(modelInfo,words,4, 'vje', 0.8) - mje = self.tryExists(modelInfo,words,4, 'mje', 0.4) - vjc = self.tryExists(modelInfo,words,4, 'vjc', 0.8) - mjc = self.tryExists(modelInfo,words,4, 'mjc', 0.333) - stat = start + words[0] +'(Bf = ' + bf + ', Br = ' + br + ', Is = ' +Is+ ', Vak = ' + vak + ', Tauf = ' +tf+ ', Taur = ' +tr+ ', Ccs = ' +cjs+ ', Cje = ' +cje+ ', Cjc = ' +cjc+ ', Phie = ' + vje + ', Me = ' + mje + ', Phic = ' + vjc + ', Mc = ' + mjc + ');' + print "Transistor "+trans+" does not support" + sys.exit(1) + + stat = start+" "+words[0]+"(" + tempstatList=[] + userDeviceParamList=[] + refName = words[-1] + for key in modelInfo[refName]: + #If parameter is not mapped then it will just pass + try: + if key=="vaf": + inv_vak = float(self.getUnitVal(modelInfo[refName][key])) + vak_temp = 1/inv_vak + vak = str(vak_temp) + tempstatList.append("Vak="+vak+" ") + userDeviceParamList.append(str("Vak")) + else: + actualModelicaParam = self.mappingData["Devices"][deviceName]["mapping"][key] + tempstatList.append(actualModelicaParam+"="+self.getUnitVal(modelInfo[refName][key])+" ") + userDeviceParamList.append(str(actualModelicaParam)) + except: + pass + #Running loop over default parameter of OpenModelica + for default in self.mappingData["Devices"][deviceName]["default"]: + if default in userDeviceParamList: + continue + else: + defaultValue = self.mappingData["Devices"][deviceName]["default"][default] + tempstatList.append(default+"="+self.getUnitVal(defaultValue)+" ") + + stat += ",".join(str(item) for item in tempstatList)+");" modelicaCompInit.append(stat) - elif eachline[0]=='m' or eachline[0]=="M": + elif deviceName=='m': eachline = eachline.split(words[5]) eachline = eachline[1] eachline = eachline.strip() @@ -621,10 +662,10 @@ 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 @@ -646,7 +687,6 @@ class NgMoConverter: conn = 'connect(' + words[0] + '.n,' + nodeDic[words[2]] + ');' connInfo.append(conn) elif eachline[0]=='q' or eachline[0]=='Q': - print "Inside Transistor--->" print "Node Dict------>",nodeDic conn = 'connect(' + words[0] + '.C,' + nodeDic[words[1]] + ');' connInfo.append(conn) -- cgit From bbc4735bafa85adc9d838fc6b8d5a06de735a13f Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Mon, 25 Apr 2016 14:18:48 +0530 Subject: Subject: Major changes for mapping the parameters of Devices Description: Now the parameters are written in Mapping.json and any new parameter and device can be eaily added and removed. --- src/ngspicetoModelica/NgspicetoModelica.py | 95 ++++++++++++++++++------------ 1 file changed, 57 insertions(+), 38 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 9985b8f0..93eac1f5 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -364,13 +364,13 @@ class NgMoConverter: elif trans == 'pnp': start = self.mappingData["Devices"][deviceName]["import"]+".PNP" else: - print "Transistor "+trans+" does not support" + print "Transistor "+trans+" Not found" sys.exit(1) stat = start+" "+words[0]+"(" tempstatList=[] userDeviceParamList=[] - refName = words[-1] + refName = words[4] for key in modelInfo[refName]: #If parameter is not mapped then it will just pass try: @@ -409,49 +409,75 @@ class NgMoConverter: each = each.split('=') mosInfo[words[0]][each[0]] = each[1] trans = transInfo[words[5]] - print "trans------------>",trans + if trans == 'nmos': - start = 'BondLib.Electrical.Analog.Spice.Mn ' + start = self.mappingData["Devices"][deviceName]["import"]+".Mn" + elif trans=='pmos' : + start = self.mappingData["Devices"][deviceName]["import"]+".Mp" else: - start = 'BondLib.Electrical.Analog.Spice.Mp ' - vto = self.tryExists(modelInfo,words,5,'vto',0) - gam = self.tryExists(modelInfo,words,5,'gamma',0) - phi = self.tryExists(modelInfo,words,5, 'phi', 0) - ld = self.tryExists(modelInfo,words,5,'ld',0) - uo = self.tryExists(modelInfo,words,5,'uo',0) - lam = self.tryExists(modelInfo,words,5,'lambda',0) - tox = self.tryExists(modelInfo,words,5,'tox',3e-9) - pb = self.tryExists(modelInfo,words,5, 'pb',0.8) - cj = self.tryExists(modelInfo,words,5, 'cj',0) - cjsw = self.tryExists(modelInfo,words,5, 'cjsw',1e-9) - mj = self.tryExists(modelInfo,words,5, 'mj',0.33) - mjsw = self.tryExists(modelInfo,words,5, 'mjsw',0.33) - cgdo = self.tryExists(modelInfo,words,5, 'cgdo',0) - js = self.tryExists(modelInfo,words,5, 'js',0) - cgbo = self.tryExists(modelInfo,words,5, 'cgbo',0) - cgso = self.tryExists(modelInfo,words,5,'cgso',0) + print "MOSFET "+trans+" not found" + sys.exit(1) + + + stat = start+" "+words[0]+"(" + tempstatList=[] + userDeviceParamList=[] + refName = words[5] + + for key in modelInfo[refName]: + #If parameter is not mapped then it will just pass + try: + if key=="uo": + U0 = str(float(self.getUnitVal(modelInfo[refName][key]))*0.0001) + tempstatList.append("U0="+U0+" ") + userDeviceParamList.append(str("U0")) + else: + actualModelicaParam = self.mappingData["Devices"][deviceName]["mapping"][key] + tempstatList.append(actualModelicaParam+"="+self.getUnitVal(modelInfo[refName][key])+" ") + userDeviceParamList.append(str(actualModelicaParam)) + except Exception as err: + print str(err) + + #Running loop over default parameter of OpenModelica + for default in self.mappingData["Devices"][deviceName]["default"]: + if default in userDeviceParamList: + continue + else: + defaultValue = self.mappingData["Devices"][deviceName]["default"][default] + tempstatList.append(default+"="+self.getUnitVal(defaultValue)+" ") + + + #Adding LEVEL(This is constant not the device levele) + tempstatList.append("LEVEL=1"+" ") + try: l = mosInfo[words[0]]['l'] + tempstatList.append("L="+self.getUnitVal(l)+" ") except KeyError: - l = '1e-6' + tempstatList.append("L=1e-6"+" ") try: w = mosInfo[words[0]]['w'] + tempstatList.append("W="+self.getUnitVal(w)+" ") except KeyError: - w = '100e-6' + tempstatList.append("W=100e-6"+" ") try: As = mosInfo[words[0]]['as'] ad = mosInfo[words[0]]['ad'] + tempstatList.append("AS="+self.getUnitVal(As)+" ") + tempstatList.append("AD="+self.getUnitVal(ad)+" ") except KeyError: - As = '0' - ad = '0' + tempstatList.append("AS=0"+" ") + tempstatList.append("AD=0"+" ") try: ps = mosInfo[words[0]]['ps'] pd = mosInfo[words[0]]['pd'] + tempstatList.append("PS="+self.getUnitVal(ps)+" ") + tempstatList.append("PD="+self.getUnitVal(pd)+" ") except KeyError: - ps = '0' - pd = '0' - stat = start + words[0] + '(Tnom = 300, VT0 = ' + vto + ', GAMMA = ' + gam + ', PHI = ' + phi + ', LD = ' +ld+ ', U0 = ' + str(float(uo)*0.0001) + ', LAMBDA = ' + lam + ', TOX = ' +tox+ ', PB = ' + pb + ', CJ = ' +cj+ ', CJSW = ' +cjsw+ ', MJ = ' + mj + ', MJSW = ' + mjsw + ', CGD0 = ' +cgdo+ ', JS = ' +js+ ', CGB0 = ' +cgbo+ ', CGS0 = ' +cgso+ ', L = ' +l+ ', W = ' + w + ', Level = 1' + ', AD = ' + ad + ', AS = ' + As + ', PD = ' + pd + ', PS = ' + ps + ');' - #stat = stat.translate(maketrans('{}', ' ')) #Not required + tempstatList.append("PS=0"+" ") + tempstatList.append("PD=0"+" ") + + stat += ",".join(str(item) for item in tempstatList)+");" modelicaCompInit.append(stat) #Lets start for inbuilt model of ngspice @@ -459,14 +485,12 @@ class NgMoConverter: words=eachline.split() userModelParamList = [] refName = words[-1] - print "Reference Model Name------->",refName actualModelName = self.inbuiltModelDict[refName] - print "Actual Model Name------->",actualModelName + start = self.mappingData["Models"][actualModelName]["import"] - print "Import Statement-------->",start stat = start +" "+ words[0]+"(" tempstatList=[] - print "Start of Stat-------->",stat + for key in modelInfo[refName]: #If parameter is not mapped then it will just pass try: @@ -476,8 +500,6 @@ class NgMoConverter: except: pass - print "User Model Parameter list---->",userModelParamList - #Running loop over default parameter of OpenModelica for default in self.mappingData["Models"][actualModelName]["default"]: if default in userModelParamList: @@ -486,10 +508,7 @@ class NgMoConverter: defaultValue = self.mappingData["Models"][actualModelName]["default"][default] tempstatList.append(default+"="+self.getUnitVal(defaultValue)+" ") - #print "My Stat------------>",stat - #print "Temp Stat List--------->",tempstatList stat += ",".join(str(item) for item in tempstatList)+");" - print "End Stat---------->",stat modelicaCompInit.append(stat) -- cgit From 99001f8ddcfa492c8068b864ec08fe2a85a88106 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Mon, 25 Apr 2016 15:44:05 +0530 Subject: Modified code to include current source --- src/ngspicetoModelica/NgspicetoModelica.py | 69 +++++++++++++++++------------- 1 file changed, 40 insertions(+), 29 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 93eac1f5..90c288a6 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -18,6 +18,7 @@ class NgMoConverter: self.subCktDetail = [] self.inbuiltModelDetail = [] self.deviceList = ['d','D','j','J','q','Q','m','M'] + self.sourceList = ['v','V','i','I'] self.inbuiltModelDict = {} @@ -71,7 +72,7 @@ class NgMoConverter: self.deviceDetail.append(eachline) elif eachline[0]=='x' or eachline[0]=='X': self.subCktDetail.append(eachline) - elif eachline[0]=='v' or eachline[0]=='V': + elif eachline[0] in self.sourceList: schematicInfo.append(eachline) self.sourceDetail.append(eachline) elif eachline[0]=='a' or eachline[0]=='A': @@ -285,36 +286,46 @@ class NgMoConverter: words = eachline.lower().split() words[0] = compName typ = words[3].split('(') - if typ[0] == "pulse": - per = words[9].split(')') - stat = self.mappingData["Sources"][typ[0]]+' '+words[0]+'(rising = '+self.getUnitVal(words[6])+', V = '+self.getUnitVal(words[4])\ - +', width = '+self.getUnitVal(words[8])+', period = '+self.getUnitVal(per[0])+', offset = '+self.getUnitVal(typ[1])+', startTime = '+self.getUnitVal(words[5])+', falling = '+self.getUnitVal(words[7])+');' - modelicaCompInit.append(stat) - if typ[0] == "sine": - theta = words[7].split(')') - stat = self.mappingData["Sources"][typ[0]]+' '+words[0]+'(offset = '+self.getUnitVal(typ[1])+', V = '+self.getUnitVal(words[4])+', freqHz = '+self.getUnitVal(words[5])+', startTime = '+self.getUnitVal(words[6])+', phase = '+self.getUnitVal(theta[0])+');' - modelicaCompInit.append(stat) - if typ[0] == "pwl": - keyw = self.mappingData["Sources"][typ[0]]+' ' - stat = keyw + words[0] + '(table = [' + self.getUnitVal(typ[1]) + ',' + self.getUnitVal(words[4]) + ';' - length = len(words); - for i in range(6,length,2): - if i == length-2: - w = words[i].split(')') - stat = stat + words[i-1] + ',' + w[0] - else: - stat = stat + words[i-1] + ',' + words[i] + ';' - stat = stat + ']);' - modelicaCompInit.append(stat) - if typ[0] == words[3] and typ[0] != "dc": - #It is DC constant but no dc keyword - val_temp = typ[0].split('v') - stat = self.mappingData["Sources"]["dc"]+' ' + words[0] + '(V = ' + self.getUnitVal(val_temp[0]) + ');' - modelicaCompInit.append(stat) - elif typ[0] == words[3] and typ[0] == "dc": - stat = self.mappingData["Sources"][typ[0]]+' ' + words[0] + '(V = ' + self.getUnitVal(words[4]) + ');' ### check this + + sourceType = compName[0].lower() + + if sourceType == 'v': + if typ[0] == "pulse": + per = words[9].split(')') + stat = self.mappingData["Sources"][sourceType][typ[0]]+' '+compName+'(rising = '+self.getUnitVal(words[6])+', V = '+self.getUnitVal(words[4])\ + +', width = '+self.getUnitVal(words[8])+', period = '+self.getUnitVal(per[0])+', offset = '+self.getUnitVal(typ[1])+', startTime = '+self.getUnitVal(words[5])+', falling = '+self.getUnitVal(words[7])+');' + modelicaCompInit.append(stat) + if typ[0] == "sine": + theta = words[7].split(')') + stat = self.mappingData["Sources"][sourceType][typ[0]]+' '+compName+'(offset = '+self.getUnitVal(typ[1])+', V = '+self.getUnitVal(words[4])+', freqHz = '+self.getUnitVal(words[5])+', startTime = '+self.getUnitVal(words[6])+', phase = '+self.getUnitVal(theta[0])+');' + modelicaCompInit.append(stat) + if typ[0] == "pwl": + keyw = self.mappingData["Sources"][sourceType][typ[0]]+' ' + stat = keyw + compName + '(table = [' + self.getUnitVal(typ[1]) + ',' + self.getUnitVal(words[4]) + ';' + length = len(words); + for i in range(6,length,2): + if i == length-2: + w = words[i].split(')') + stat = stat + words[i-1] + ',' + w[0] + else: + stat = stat + words[i-1] + ',' + words[i] + ';' + stat = stat + ']);' + modelicaCompInit.append(stat) + if typ[0] == words[3] and typ[0] != "dc": + #It is DC constant but no dc keyword + val_temp = typ[0].split('v') + stat = self.mappingData["Sources"][sourceType]["dc"]+' ' + compName + '(V = ' + self.getUnitVal(val_temp[0]) + ');' + modelicaCompInit.append(stat) + elif typ[0] == words[3] and typ[0] == "dc": + stat = self.mappingData["Sources"][sourceType][typ[0]]+' ' + compName + '(V = ' + self.getUnitVal(words[4]) + ');' ### check this + modelicaCompInit.append(stat) + + elif sourceType=='i': + print "Word---------------->",words[3] + stat = self.mappingData["Sources"][sourceType]["dc"]+' '+compName+'(I='+self.getUnitVal(words[3])+');' modelicaCompInit.append(stat) + #Lets start for device for eachline in self.deviceDetail: words=eachline.split() -- cgit From 7981bce4c6391e585d07011c0a3b122c847ab32a Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Mon, 25 Apr 2016 19:30:59 +0530 Subject: Added node details for Constant Current Source --- src/ngspicetoModelica/NgspicetoModelica.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 90c288a6..ad60a46a 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -708,10 +708,9 @@ class NgMoConverter: sourcesInfo = self.separateSource(compInfo) for eachline in compInfo: words = eachline.split() - #print "eachline----->",eachline - #print "eachline[0]------->",eachline[0] + if eachline[0]=='r' or eachline[0]=='R' or eachline[0]=='c' or eachline[0]=='C' or eachline[0]=='d' or eachline[0]=='D' \ - or eachline[0]=='l' or eachline[0]=='L' or eachline[0]=='v' or eachline[0]=='V': + or eachline[0]=='l' or eachline[0]=='L' or eachline[0]=='v' or eachline[0]=='V' or eachline[0]=='i' or eachline[0]=='I': conn = 'connect(' + words[0] + '.p,' + nodeDic[words[1]] + ');' connInfo.append(conn) conn = 'connect(' + words[0] + '.n,' + nodeDic[words[2]] + ');' -- cgit From 7439467316fad7746d6ecc8335f7c294a254f869 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Tue, 26 Apr 2016 11:45:03 +0530 Subject: Table voltage unit (PWL) resolved --- src/ngspicetoModelica/NgspicetoModelica.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index ad60a46a..5735db4b 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -306,9 +306,9 @@ class NgMoConverter: for i in range(6,length,2): if i == length-2: w = words[i].split(')') - stat = stat + words[i-1] + ',' + w[0] + stat = stat + self.getUnitVal(words[i-1]) + ',' + self.getUnitVal(w[0]) else: - stat = stat + words[i-1] + ',' + words[i] + ';' + stat = stat + self.getUnitVal(words[i-1]) + ',' + self.getUnitVal(words[i]) + ';' stat = stat + ']);' modelicaCompInit.append(stat) if typ[0] == words[3] and typ[0] != "dc": @@ -321,7 +321,6 @@ class NgMoConverter: modelicaCompInit.append(stat) elif sourceType=='i': - print "Word---------------->",words[3] stat = self.mappingData["Sources"][sourceType]["dc"]+' '+compName+'(I='+self.getUnitVal(words[3])+');' modelicaCompInit.append(stat) -- cgit From 5022a36736ffff855f7dada14b5b98988179ecbe Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Tue, 26 Apr 2016 14:01:51 +0530 Subject: Modified getUnitVal function --- src/ngspicetoModelica/NgspicetoModelica.py | 57 ++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 15 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 5735db4b..6483bd13 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -220,20 +220,38 @@ class NgMoConverter: def getUnitVal(self,compValue): #regExp = re.compile("([0-9]+)([a-zA-Z]+)") - regExp = re.compile("([0-9]+)\.?([0-9]+)?([a-zA-Z])?") + #Remove '(' and ')' if any + compValue = compValue.replace('(','').replace(')','') + regExp = re.compile("([-])?([0-9]+)\.?([0-9]+)?([a-zA-Z])?") matchString = regExp.match(str(compValue)) #separating number and string try: - valBeforeDecimal = matchString.group(1) - valAfterDecimal = matchString.group(2) - unitValue = matchString.group(3) + signVal = matchString.group(1) + valBeforeDecimal = matchString.group(2) + valAfterDecimal = matchString.group(3) + unitValue = matchString.group(4) + modifiedcompValue = "" + + if str(signVal)=='None': + pass + else: + modifiedcompValue += signVal + + modifiedcompValue += valBeforeDecimal + if str(valAfterDecimal)=='None': - modifiedcompValue = valBeforeDecimal+self.mappingData["Units"][unitValue] + pass else: - modifiedcompValue = valBeforeDecimal+'.'+valAfterDecimal+self.mappingData["Units"][unitValue] + modifiedcompValue += valAfterDecimal + + if str(unitValue)=='None': + pass + else: + modifiedcompValue += self.mappingData["Units"][unitValue] + return modifiedcompValue except: return compValue - + def tryExists(self,modelInfo,words,wordNo, key,default): """ checks if entry for key exists in dictionary, else returns default @@ -634,12 +652,11 @@ class NgMoConverter: #Removing '[' and ']' from compInfo for Digital node for i in range(0,len(compInfo),1): compInfo[i] = compInfo[i].replace("[","").replace("]","") - #Remove "-" from node as it does not work in modelica - compInfo[i] = compInfo[i].replace("-","") - + for eachline in compInfo: words = eachline.split() + if eachline[0] in ['m', 'e', 'g', 't','M','E','G','T']: nodeTemp.append(words[1]) nodeTemp.append(words[2]) @@ -658,8 +675,11 @@ class NgMoConverter: else: nodeTemp.append(words[1]) nodeTemp.append(words[2]) + + #Replace hyphen '-' from node for i in nodeTemp: if i not in node: + i = i.replace("-","") node.append(i) @@ -703,11 +723,14 @@ class NgMoConverter: Make node connections in the modelica netlist """ connInfo = [] - print "compinfo-------->",compInfo sourcesInfo = self.separateSource(compInfo) for eachline in compInfo: words = eachline.split() + #Remove '-' from compInfo + for i in range(0,len(words),1): + words[i] = words[i].replace("-","") + if eachline[0]=='r' or eachline[0]=='R' or eachline[0]=='c' or eachline[0]=='C' or eachline[0]=='d' or eachline[0]=='D' \ or eachline[0]=='l' or eachline[0]=='L' or eachline[0]=='v' or eachline[0]=='V' or eachline[0]=='i' or eachline[0]=='I': conn = 'connect(' + words[0] + '.p,' + nodeDic[words[1]] + ');' @@ -715,7 +738,6 @@ class NgMoConverter: conn = 'connect(' + words[0] + '.n,' + nodeDic[words[2]] + ');' connInfo.append(conn) elif eachline[0]=='q' or eachline[0]=='Q': - print "Node Dict------>",nodeDic conn = 'connect(' + words[0] + '.C,' + nodeDic[words[1]] + ');' connInfo.append(conn) conn = 'connect(' + words[0] + '.B,' + nodeDic[words[2]] + ');' @@ -757,11 +779,10 @@ class NgMoConverter: temp = templine[0].split('x') index = temp[1] for i in range(0,len(templine),1): - if templine[i] in subcktName: #Ask Manas Added subcktName in function Call + if templine[i] in subcktName: subname = templine[i] nodeNumInfo = self.getSubInterface(subname, numNodesSub) for i in range(0, numNodesSub[subname], 1): - #conn = 'connect(' + subname + '_instance' + index + '.' + nodeDic[nodeNumInfo[i]] + ',' + nodeDic[words[i+1]] + ');' conn = 'connect(' + subname + '_instance' + index + '.' + 'n'+ nodeNumInfo[i] + ',' + nodeDic[words[i+1]] + ');' connInfo.append(conn) else: @@ -772,6 +793,13 @@ class NgMoConverter: elif 'gnd' in node: conn = 'connect(g.p,ngnd);' connInfo.append(conn) + + print "Connection Information--------->",connInfo + + + # Removing hypen from netlist as it is not supported in modelica + #for i in range(0,len(connInfo),1): + # connInfo[i] = connInfo[i].replace("-","") return connInfo @@ -933,7 +961,6 @@ def main(args): modelicaParamInit = obj_NgMoConverter.processParam(paramInfo) #print "Make modelicaParamInit from paramInfo :processParamInit------------->",modelicaParamInit compInfo, plotInfo = obj_NgMoConverter.separatePlot(schematicInfo) - print "Info like run etc : CompInfo----------------->",compInfo #print "Plot info like plot,print etc :plotInfo",plotInfo IfMOS = '0' -- cgit From 9eb2372278e7823e0df3ccb94306ce7f62e3f97b Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Wed, 27 Apr 2016 11:31:51 +0530 Subject: Modified Code for dependant source --- src/ngspicetoModelica/NgspicetoModelica.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 6483bd13..af926cdb 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -756,7 +756,9 @@ class NgMoConverter: elif eachline[0] in ['f','h','F','H']: vsource = words[3] sourceNodes = sourcesInfo[vsource] - sourceNodes = sourceNodes.split() + #print "Source Nodes------>",sourceNodes + #print "Source Info------->",sourcesInfo + #sourceNodes = sourceNodes.split() #No need to split as it is in the form of list conn = 'connect(' + words[0] + '.p1,'+ nodeDic[sourceNodes[0]] + ');' connInfo.append(conn) conn = 'connect(' + words[0] + '.n1,'+ nodeDic[sourceNodes[1]] + ');' -- cgit From d72f0914f3b7944fb97e3d242e3757b1d6388de0 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Wed, 27 Apr 2016 14:53:43 +0530 Subject: Modified code to exclude voltage source of main circuit into subcircuit netlist --- src/ngspicetoModelica/NgspicetoModelica.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index af926cdb..b512cfef 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -241,7 +241,7 @@ class NgMoConverter: if str(valAfterDecimal)=='None': pass else: - modifiedcompValue += valAfterDecimal + modifiedcompValue += '.'+valAfterDecimal if str(unitValue)=='None': pass @@ -342,6 +342,10 @@ class NgMoConverter: stat = self.mappingData["Sources"][sourceType]["dc"]+' '+compName+'(I='+self.getUnitVal(words[3])+');' modelicaCompInit.append(stat) + #Now empty the source list as it may be used by subcircuit + self.sourceDetail[:] = [] + + print "Source Detail after processing-------->",self.sourceDetail #Lets start for device for eachline in self.deviceDetail: @@ -508,6 +512,9 @@ class NgMoConverter: stat += ",".join(str(item) for item in tempstatList)+");" modelicaCompInit.append(stat) + #Empty device details as well + self.deviceDetail[:]=[] + #Lets start for inbuilt model of ngspice for eachline in self.inbuiltModelDetail: words=eachline.split() @@ -539,6 +546,8 @@ class NgMoConverter: stat += ",".join(str(item) for item in tempstatList)+");" modelicaCompInit.append(stat) + #Empty inbuilt Model + self.inbuiltModelDetail[:] = [] #Lets start for Subcircuit for eachline in self.subCktDetail: -- cgit From 9ceb75c40199d846c4075d05efca41925a56db78 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Wed, 27 Apr 2016 16:30:38 +0530 Subject: Resolve Mega Units --- src/ngspicetoModelica/NgspicetoModelica.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index b512cfef..6689d0c6 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -48,7 +48,9 @@ class NgMoConverter: if eachline[0]=='+': netlist.append(netlist.pop()+eachline.replace('+',' ',1)) else: + print "EachLine------------>",eachline netlist.append(eachline) + print "Netlist.............>",netlist return netlist def separateNetlistInfo(self,netlist): @@ -58,7 +60,10 @@ class NgMoConverter: optionInfo = [] schematicInfo = [] + + for eachline in netlist: + if len(eachline) > 1: if eachline[0]=='*': continue @@ -71,6 +76,7 @@ class NgMoConverter: schematicInfo.append(eachline) self.deviceDetail.append(eachline) elif eachline[0]=='x' or eachline[0]=='X': + schematicInfo.append(eachline) self.subCktDetail.append(eachline) elif eachline[0] in self.sourceList: schematicInfo.append(eachline) @@ -82,6 +88,8 @@ class NgMoConverter: schematicInfo.append(eachline) ##No need of making it lower case as netlist is already converted to ngspice #schematicInfo.append(eachline.lower()) + + print "Subcircuit------->",self.subCktDetail return optionInfo,schematicInfo def addModel(self,optionInfo): @@ -222,7 +230,8 @@ class NgMoConverter: #regExp = re.compile("([0-9]+)([a-zA-Z]+)") #Remove '(' and ')' if any compValue = compValue.replace('(','').replace(')','') - regExp = re.compile("([-])?([0-9]+)\.?([0-9]+)?([a-zA-Z])?") + #regExp = re.compile("([-])?([0-9]+)\.?([0-9]+)?([a-zA-Z])?") + regExp = re.compile("([-])?([0-9]+)\.?([0-9]+)?(\w+)?") matchString = regExp.match(str(compValue)) #separating number and string try: signVal = matchString.group(1) @@ -230,7 +239,6 @@ class NgMoConverter: valAfterDecimal = matchString.group(3) unitValue = matchString.group(4) modifiedcompValue = "" - if str(signVal)=='None': pass else: @@ -568,7 +576,9 @@ class NgMoConverter: else: stat = subname + ' ' + subname +'_instance' + index + ';' modelicaCompInit.append(stat) - + + #Empty Sub Circuit Detail + self.subCktDetail[:] = [] for eachline in compInfo: words = eachline.split() @@ -677,13 +687,18 @@ class NgMoConverter: nodeTemp.append(words[3]) elif eachline[0]=='x' or eachline[0]=='X': templine = eachline.split() + print "TempLine------------>",templine + print "Subckt Name---------->",subcktName for i in range(0,len(templine),1): if templine[i] in subcktName: point = i + print "Added in node----->",words[1:point] nodeTemp.extend(words[1:point]) else: nodeTemp.append(words[1]) nodeTemp.append(words[2]) + + #Replace hyphen '-' from node for i in nodeTemp: @@ -994,12 +1009,12 @@ def main(args): if eachline[0] == 'm': IfMOS = '1' break - #print "Subcircuit OptionInfo : subOptionInfo------------------->",subOptionInfo - #print "Subcircuit Schematic Info :subSchemInfo-------------------->",subSchemInfo + print "Subcircuit OptionInfo : subOptionInfo------------------->",subOptionInfo + print "Subcircuit Schematic Info :subSchemInfo-------------------->",subSchemInfo node, nodeDic, pinInit, pinProtectedInit = obj_NgMoConverter.nodeSeparate(compInfo, '0', [], subcktName,[]) - print "All nodes in the netlist :node---------------->",node - print "NodeDic which will be used for modelica : nodeDic------------->",nodeDic + #print "All nodes in the netlist :node---------------->",node + #print "NodeDic which will be used for modelica : nodeDic------------->",nodeDic #print "PinInit-------------->",pinInit #print "pinProtectedInit----------->",pinProtectedInit -- cgit From 11ac9b3874e4e84576c3b735c8ecbfd6583648bc Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Thu, 28 Apr 2016 12:14:32 +0530 Subject: Modified Code for Sub Circuit --- src/ngspicetoModelica/NgspicetoModelica.py | 69 ++++++++++++++++-------------- 1 file changed, 36 insertions(+), 33 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 6689d0c6..ad5f703a 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -48,9 +48,8 @@ class NgMoConverter: if eachline[0]=='+': netlist.append(netlist.pop()+eachline.replace('+',' ',1)) else: - print "EachLine------------>",eachline netlist.append(eachline) - print "Netlist.............>",netlist + #print "Netlist.............>",netlist return netlist def separateNetlistInfo(self,netlist): @@ -89,7 +88,7 @@ class NgMoConverter: ##No need of making it lower case as netlist is already converted to ngspice #schematicInfo.append(eachline.lower()) - print "Subcircuit------->",self.subCktDetail + #print "Subcircuit------->",self.subCktDetail return optionInfo,schematicInfo def addModel(self,optionInfo): @@ -276,7 +275,7 @@ class NgMoConverter: """ 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 = {} @@ -353,7 +352,7 @@ class NgMoConverter: #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: @@ -692,7 +691,7 @@ class NgMoConverter: 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]) @@ -820,7 +819,7 @@ class NgMoConverter: conn = 'connect(g.p,ngnd);' connInfo.append(conn) - print "Connection Information--------->",connInfo + #print "Connection Information--------->",connInfo # Removing hypen from netlist as it is not supported in modelica @@ -852,11 +851,13 @@ class NgMoConverter: if len(subcktName) > 0: for eachsub in subcktName: filename = eachsub + '.sub' + basename = filename + filename = os.path.join(dir_name, filename) data = self.readNetlist(filename) 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 @@ -865,12 +866,12 @@ class NgMoConverter: for i in range(0,len(intLine),1): nodeSubInterface.append(intLine[i]) - subModel, subModelInfo, subsubName, subParamInfo,transInfo = self.addModel(subOptionInfo) - print "Sub Model------------------------------------>",subModel - print "SubModelInfo---------------------------------->",subModelInfo - print "subsubName------------------------------------->",subsubName - print "subParamInfo----------------------------------->",subParamInfo - print "transInfo----------------------------------->",transInfo + subModel, subModelInfo, subsubName, subParamInfo,subtransInfo = self.addModel(subOptionInfo) + #print "Sub Model------------------------------------>",subModel + #print "SubModelInfo---------------------------------->",subModelInfo + #print "subsubName------------------------------------->",subsubName + #print "subParamInfo----------------------------------->",subParamInfo + #print "subtransInfo----------------------------------->",subtransInfo IfMOSsub = '0' for eachline in subSchemInfo: #words = eachline.split() @@ -883,7 +884,8 @@ class NgMoConverter: #subsubOptionInfo = [] #subsubSchemInfo = [] for eachsub in subsubName: - filename_stemp = eachsub + '.sub' + filename_st = eachsub + '.sub' + filename_stemp = os.path.join(dir_name, filename_st) data = self.readNetlist(filename_stemp) subsubOptionInfo, subsubSchemInfo = self.separateNetlistInfo(data) for eachline in subsubSchemInfo: @@ -891,22 +893,23 @@ class NgMoConverter: 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 - modelicaSubCompInit, numNodesSubsub = self.compInit(subSchemInfo, nodeSub, subModelInfo, subsubName,dir_name,transInfo) - print "modelicaSubCompInit--------------------->",modelicaSubCompInit - print "numNodesSubsub-------------------------->",numNodesSubsub + #print "NodeSub------------------------->",nodeSub + #print "NodeDicSub-------------------------->",nodeDicSub + #print "PinInitSub-------------------------->",pinInitSub + #print "PinProtectedInitSub------------------->",pinProtectedInitSub + modelicaSubCompInit, numNodesSubsub = self.compInit(subSchemInfo, nodeSub, subModelInfo, subsubName,dir_name,subtransInfo) + #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 newname = filename.split('.') newfilename = newname[0] outfilename = newfilename+ ".mo" @@ -978,8 +981,8 @@ def main(args): #print "All option details like analysis,subckt,.ic,.model : OptionInfo------------------->",optionInfo #print "Schematic connection info :schematicInfo",schematicInfo modelName, modelInfo, subcktName, paramInfo,transInfo = obj_NgMoConverter.addModel(optionInfo) - print "Name of Model : modelName-------------------->",modelName - print "Model Information :modelInfo--------------------->",modelInfo + #print "Name of Model : modelName-------------------->",modelName + #print "Model Information :modelInfo--------------------->",modelInfo #print "Subcircuit Name :subcktName------------------------>",subcktName #print "Parameter Information :paramInfo---------------------->",paramInfo @@ -1009,8 +1012,8 @@ def main(args): if eachline[0] == 'm': IfMOS = '1' break - print "Subcircuit OptionInfo : subOptionInfo------------------->",subOptionInfo - print "Subcircuit Schematic Info :subSchemInfo-------------------->",subSchemInfo + #print "Subcircuit OptionInfo : subOptionInfo------------------->",subOptionInfo + #print "Subcircuit Schematic Info :subSchemInfo-------------------->",subSchemInfo node, nodeDic, pinInit, pinProtectedInit = obj_NgMoConverter.nodeSeparate(compInfo, '0', [], subcktName,[]) #print "All nodes in the netlist :node---------------->",node @@ -1019,8 +1022,8 @@ def main(args): #print "pinProtectedInit----------->",pinProtectedInit modelicaCompInit, numNodesSub = obj_NgMoConverter.compInit(compInfo,node, modelInfo, subcktName,dir_name,transInfo) - print "ModelicaComponents : modelicaCompInit----------->",modelicaCompInit - print "SubcktNumNodes : numNodesSub---------------->",numNodesSub + #print "ModelicaComponents : modelicaCompInit----------->",modelicaCompInit + #print "SubcktNumNodes : numNodesSub---------------->",numNodesSub connInfo = obj_NgMoConverter.connectInfo(compInfo, node, nodeDic, numNodesSub,subcktName) -- cgit From 458d27e3fa3f8864eb2b47e2b39ca74a6f5e035f Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Thu, 28 Apr 2016 15:08:08 +0530 Subject: Generated Subcircuit .mo file properly when the folder contains '.' in path --- src/ngspicetoModelica/NgspicetoModelica.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index ad5f703a..058a2442 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -910,11 +910,12 @@ class NgMoConverter: #print "modelicaSubParamNew----------------->",modelicaSubParamNew connSubInfo = self.connectInfo(subSchemInfo, nodeSub, nodeDicSub, numNodesSubsub,subcktName) #print "connSubInfo----------------->",connSubInfo - newname = filename.split('.') + newname = basename.split('.') newfilename = newname[0] outfilename = newfilename+ ".mo" + outfilename = os.path.join(dir_name, outfilename) out = open(outfilename,"w") - out.writelines('model ' + os.path.basename(newfilename)) + out.writelines('model ' + newfilename) out.writelines('\n') if IfMOSsub == '0': out.writelines('import Modelica.Electrical.*;') @@ -949,7 +950,7 @@ class NgMoConverter: else: out.writelines(eachline) out.writelines('\n') - out.writelines('end '+ os.path.basename(newfilename) + ';') + out.writelines('end '+ newfilename + ';') out.writelines('\n') out.close() -- cgit From 2debdb42d3acc1e6beacbba0809905f38ee06fcc Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Thu, 28 Apr 2016 16:46:32 +0530 Subject: Modified getunit function : Now it lower the case before taking value from Mapping.json --- src/ngspicetoModelica/NgspicetoModelica.py | 1 + 1 file changed, 1 insertion(+) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 058a2442..a8ef6048 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -229,6 +229,7 @@ class NgMoConverter: #regExp = re.compile("([0-9]+)([a-zA-Z]+)") #Remove '(' and ')' if any compValue = compValue.replace('(','').replace(')','') + compValue = compValue.lower() #regExp = re.compile("([-])?([0-9]+)\.?([0-9]+)?([a-zA-Z])?") regExp = re.compile("([-])?([0-9]+)\.?([0-9]+)?(\w+)?") matchString = regExp.match(str(compValue)) #separating number and string -- cgit From c753fd25e8a6492c359acd0d518fdc7f6528e64b Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Mon, 2 May 2016 15:04:22 +0530 Subject: Modified few parameters name of MOSFET- O to 0 --- src/ngspicetoModelica/NgspicetoModelica.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index a8ef6048..fd2d4d7c 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -488,7 +488,7 @@ class NgMoConverter: #Adding LEVEL(This is constant not the device levele) - tempstatList.append("LEVEL=1"+" ") + tempstatList.append("level=1"+" ") try: l = mosInfo[words[0]]['l'] -- cgit From 27a8bfb7902a0ce85e1ce02b11d6b172f5ee21fb Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Tue, 3 May 2016 14:28:29 +0530 Subject: Change parameter level with Level --- src/ngspicetoModelica/NgspicetoModelica.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index fd2d4d7c..35ab5ec2 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -487,8 +487,8 @@ class NgMoConverter: tempstatList.append(default+"="+self.getUnitVal(defaultValue)+" ") - #Adding LEVEL(This is constant not the device levele) - tempstatList.append("level=1"+" ") + #Adding LEVEL(This is constant not the device level) + tempstatList.append("Level=1"+" ") try: l = mosInfo[words[0]]['l'] -- cgit From e53b087fbe87c1857b3b04b0dbd4030e774f404d Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Wed, 4 May 2016 14:30:19 +0530 Subject: Added functionality for inbuilt ngspice model inside SubCircuit --- src/ngspicetoModelica/NgspicetoModelica.py | 146 +++++++++++++---------------- 1 file changed, 63 insertions(+), 83 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 35ab5ec2..3aabc72d 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -16,10 +16,10 @@ class NgMoConverter: self.sourceDetail = [] self.deviceDetail = [] self.subCktDetail = [] - self.inbuiltModelDetail = [] self.deviceList = ['d','D','j','J','q','Q','m','M'] self.sourceList = ['v','V','i','I'] - self.inbuiltModelDict = {} + + @@ -49,7 +49,7 @@ class NgMoConverter: netlist.append(netlist.pop()+eachline.replace('+',' ',1)) else: netlist.append(eachline) - #print "Netlist.............>",netlist + return netlist def separateNetlistInfo(self,netlist): @@ -81,14 +81,13 @@ class NgMoConverter: schematicInfo.append(eachline) self.sourceDetail.append(eachline) elif eachline[0]=='a' or eachline[0]=='A': - schematicInfo.append(eachline) - self.inbuiltModelDetail.append(eachline) + schematicInfo.append(eachline) else: schematicInfo.append(eachline) ##No need of making it lower case as netlist is already converted to ngspice #schematicInfo.append(eachline.lower()) - #print "Subcircuit------->",self.subCktDetail + return optionInfo,schematicInfo def addModel(self,optionInfo): @@ -101,6 +100,7 @@ class NgMoConverter: subcktName = [] paramInfo = [] transInfo = {} + inbuiltModelDict = {} for eachline in optionInfo: words = eachline.split() @@ -124,10 +124,9 @@ class NgMoConverter: if templine[2] in ['npn', 'pnp', 'pmos', 'nmos']: transInfo[trans] = templine[2] else: - self.inbuiltModelDict[model]=templine[2] + inbuiltModelDict[model]=templine[2] eachline[1] = eachline[1].lower() eachline = eachline[1].split() - for eachitem in eachline: if len(eachitem) > 1: eachitem = eachitem.replace(')','') @@ -171,8 +170,9 @@ class NgMoConverter: for eachitem in info: modelInfo[refModelName][info[0]] = info[1] f.close() - - return modelName, modelInfo, subcktName, paramInfo ,transInfo + + + return modelName, modelInfo, subcktName, paramInfo ,transInfo,inbuiltModelDict def processParam(self,paramInfo): """ @@ -259,20 +259,9 @@ class NgMoConverter: return modifiedcompValue except: return compValue + - def tryExists(self,modelInfo,words,wordNo, key,default): - """ - checks if entry for key exists in dictionary, else returns default - """ - try: - keyval = modelInfo[words[wordNo]][key] - keyval = self.getUnitVal(keyval) - except KeyError: - keyval = str(default) - return keyval - - - def compInit(self,compInfo, node, modelInfo, subcktName,dir_name,transInfo): + def compInit(self,compInfo, node, modelInfo, subcktName,dir_name,transInfo,inbuiltModelDict): """ For each component in the netlist initialize it according to Modelica format """ @@ -522,41 +511,7 @@ class NgMoConverter: #Empty device details as well self.deviceDetail[:]=[] - - #Lets start for inbuilt model of ngspice - for eachline in self.inbuiltModelDetail: - words=eachline.split() - userModelParamList = [] - refName = words[-1] - actualModelName = self.inbuiltModelDict[refName] - - start = self.mappingData["Models"][actualModelName]["import"] - stat = start +" "+ words[0]+"(" - tempstatList=[] - - for key in modelInfo[refName]: - #If parameter is not mapped then it will just pass - try: - actualModelicaParam = self.mappingData["Models"][actualModelName]["mapping"][key] - tempstatList.append(actualModelicaParam+"="+self.getUnitVal(modelInfo[refName][key])+" ") - userModelParamList.append(str(actualModelicaParam)) - except: - pass - - #Running loop over default parameter of OpenModelica - for default in self.mappingData["Models"][actualModelName]["default"]: - if default in userModelParamList: - continue - else: - defaultValue = self.mappingData["Models"][actualModelName]["default"][default] - tempstatList.append(default+"="+self.getUnitVal(defaultValue)+" ") - - stat += ",".join(str(item) for item in tempstatList)+");" - modelicaCompInit.append(stat) - - #Empty inbuilt Model - self.inbuiltModelDetail[:] = [] - + #Lets start for Subcircuit for eachline in self.subCktDetail: global point @@ -580,12 +535,40 @@ class NgMoConverter: #Empty Sub Circuit Detail self.subCktDetail[:] = [] + #Lets start for inbuilt model of ngspice for eachline in compInfo: - words = eachline.split() - #val = words[3] - #value = self.splitIntoVal(val) + words=eachline.split() value = self.getUnitVal(words[-1]) - if eachline[0] == 'r': + if eachline[0] == 'a' or eachline[0] == 'A': + userModelParamList = [] + refName = words[-1] + actualModelName = inbuiltModelDict[refName] + + start = self.mappingData["Models"][actualModelName]["import"] + stat = start +" "+ words[0]+"(" + tempstatList=[] + + for key in modelInfo[refName]: + #If parameter is not mapped then it will just pass + try: + actualModelicaParam = self.mappingData["Models"][actualModelName]["mapping"][key] + tempstatList.append(actualModelicaParam+"="+self.getUnitVal(modelInfo[refName][key])+" ") + userModelParamList.append(str(actualModelicaParam)) + except: + pass + + #Running loop over default parameter of OpenModelica + for default in self.mappingData["Models"][actualModelName]["default"]: + if default in userModelParamList: + continue + else: + defaultValue = self.mappingData["Models"][actualModelName]["default"][default] + tempstatList.append(default+"="+self.getUnitVal(defaultValue)+" ") + + stat += ",".join(str(item) for item in tempstatList)+");" + modelicaCompInit.append(stat) + + elif eachline[0] == 'r': stat = 'Analog.Basic.Resistor ' + words[0] + '(R = ' + value + ');' modelicaCompInit.append(stat) elif eachline[0] == 'c': @@ -606,10 +589,10 @@ class NgMoConverter: elif eachline[0] == 'h': stat = 'Analog.Basic.CCV ' + words[0] + '(transResistance = ' + self.getUnitVal(words[4]) + ');' modelicaCompInit.append(stat) - else: continue - + + if '0' or 'gnd' in node: modelicaCompInit.append('Analog.Basic.Ground g;') return modelicaCompInit, numNodesSub @@ -633,7 +616,7 @@ class NgMoConverter: def getSubParamLine(self,subname, numNodesSub, subParamInfo,dir_name): """ - Take subcircuit name and give the info related to parameters in the first line and initislise it in + Take subcircuit name and give the info related to parameters in the first line and initialize it in """ #nodeSubInterface = [] subOptionInfo_p = [] @@ -687,8 +670,6 @@ class NgMoConverter: nodeTemp.append(words[3]) elif eachline[0]=='x' or eachline[0]=='X': templine = eachline.split() - print "TempLine------------>",templine - print "Subckt Name---------->",subcktName for i in range(0,len(templine),1): if templine[i] in subcktName: point = i @@ -820,13 +801,9 @@ class NgMoConverter: conn = 'connect(g.p,ngnd);' connInfo.append(conn) - #print "Connection Information--------->",connInfo - + - # Removing hypen from netlist as it is not supported in modelica - #for i in range(0,len(connInfo),1): - # connInfo[i] = connInfo[i].replace("-","") - + return connInfo @@ -841,21 +818,18 @@ class NgMoConverter: subModelInfo = {} subsubName = [] subParamInfo = [] - #subinbuiltmodelName = [] - #subinbuiltmodelInfo = {} nodeSubInterface = [] nodeSub = [] nodeDicSub = {} pinInitsub = [] connSubInfo = [] - print "subcktName------------------>",subcktName if len(subcktName) > 0: for eachsub in subcktName: filename = eachsub + '.sub' 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 @@ -867,12 +841,14 @@ class NgMoConverter: for i in range(0,len(intLine),1): nodeSubInterface.append(intLine[i]) - subModel, subModelInfo, subsubName, subParamInfo,subtransInfo = self.addModel(subOptionInfo) + subModel, subModelInfo, subsubName, subParamInfo,subtransInfo,subInbuiltModelDict = self.addModel(subOptionInfo) #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: #words = eachline.split() @@ -904,7 +880,7 @@ class NgMoConverter: #print "NodeDicSub-------------------------->",nodeDicSub #print "PinInitSub-------------------------->",pinInitSub #print "PinProtectedInitSub------------------->",pinProtectedInitSub - modelicaSubCompInit, numNodesSubsub = self.compInit(subSchemInfo, nodeSub, subModelInfo, subsubName,dir_name,subtransInfo) + modelicaSubCompInit, numNodesSubsub = self.compInit(subSchemInfo, nodeSub, subModelInfo, subsubName,dir_name,subtransInfo,subInbuiltModelDict) #print "modelicaSubCompInit--------------------->",modelicaSubCompInit #print "numNodesSubsub-------------------------->",numNodesSubsub modelicaSubParamNew = self.getSubParamLine(eachsub, numNodesSub, modelicaSubParam,dir_name) ###Ask Manas @@ -982,15 +958,17 @@ def main(args): optionInfo, schematicInfo = obj_NgMoConverter.separateNetlistInfo(lines) #print "All option details like analysis,subckt,.ic,.model : OptionInfo------------------->",optionInfo #print "Schematic connection info :schematicInfo",schematicInfo - modelName, modelInfo, subcktName, paramInfo,transInfo = obj_NgMoConverter.addModel(optionInfo) + modelName, modelInfo, subcktName, paramInfo,transInfo,inbuiltModelDict = obj_NgMoConverter.addModel(optionInfo) #print "Name of Model : modelName-------------------->",modelName #print "Model Information :modelInfo--------------------->",modelInfo #print "Subcircuit Name :subcktName------------------------>",subcktName #print "Parameter Information :paramInfo---------------------->",paramInfo + #print "InBuilt Model ---------------------->",inbuiltModelDict + modelicaParamInit = obj_NgMoConverter.processParam(paramInfo) - #print "Make modelicaParamInit from paramInfo :processParamInit------------->",modelicaParamInit + #print "Make modelicaParamInit from paramInfo : processParamInit------------->",modelicaParamInit compInfo, plotInfo = obj_NgMoConverter.separatePlot(schematicInfo) #print "Plot info like plot,print etc :plotInfo",plotInfo IfMOS = '0' @@ -1000,6 +978,7 @@ def main(args): if eachline[0] == 'm': IfMOS = '1' break + subOptionInfo = [] subSchemInfo = [] if len(subcktName) > 0: @@ -1008,6 +987,7 @@ def main(args): 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() @@ -1016,14 +996,14 @@ def main(args): break #print "Subcircuit OptionInfo : subOptionInfo------------------->",subOptionInfo #print "Subcircuit Schematic Info :subSchemInfo-------------------->",subSchemInfo - + node, nodeDic, pinInit, pinProtectedInit = obj_NgMoConverter.nodeSeparate(compInfo, '0', [], subcktName,[]) #print "All nodes in the netlist :node---------------->",node #print "NodeDic which will be used for modelica : nodeDic------------->",nodeDic #print "PinInit-------------->",pinInit #print "pinProtectedInit----------->",pinProtectedInit - modelicaCompInit, numNodesSub = obj_NgMoConverter.compInit(compInfo,node, modelInfo, subcktName,dir_name,transInfo) + modelicaCompInit, numNodesSub = obj_NgMoConverter.compInit(compInfo,node, modelInfo, subcktName,dir_name,transInfo,inbuiltModelDict) #print "ModelicaComponents : modelicaCompInit----------->",modelicaCompInit #print "SubcktNumNodes : numNodesSub---------------->",numNodesSub -- cgit From c5a108d361ea264cbe33b8486e8ad0b6b32d252b Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Fri, 6 May 2016 12:53:50 +0530 Subject: Added JFET model --- src/ngspicetoModelica/NgspicetoModelica.py | 49 +++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 3aabc72d..1e67c07b 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -74,6 +74,7 @@ class NgMoConverter: self.ifMOS = True schematicInfo.append(eachline) self.deviceDetail.append(eachline) + print "Device Detail--------->",self.deviceDetail elif eachline[0]=='x' or eachline[0]=='X': schematicInfo.append(eachline) self.subCktDetail.append(eachline) @@ -121,7 +122,7 @@ class NgMoConverter: trans = templine[1] transInfo[trans] = [] templine[2] = templine[2].lower() - if templine[2] in ['npn', 'pnp', 'pmos', 'nmos']: + if templine[2] in ['npn', 'pnp', 'pmos', 'nmos','njf','pjf']: transInfo[trans] = templine[2] else: inbuiltModelDict[model]=templine[2] @@ -154,7 +155,7 @@ class NgMoConverter: trans_f = templine_f[1] transInfo[trans_f] = [] templine_f[2] = templine_f[2].lower() - if templine_f[2] in ['npn', 'pnp', 'pmos', 'nmos']: + if templine_f[2] in ['npn', 'pnp', 'pmos', 'nmos','njf','pjf']: transInfo[trans_f] = templine_f[2] refModelName = trans_f @@ -171,6 +172,8 @@ class NgMoConverter: modelInfo[refModelName][info[0]] = info[1] f.close() + print "Model Info----->",modelInfo + return modelName, modelInfo, subcktName, paramInfo ,transInfo,inbuiltModelDict @@ -393,7 +396,7 @@ class NgMoConverter: elif trans == 'pnp': start = self.mappingData["Devices"][deviceName]["import"]+".PNP" else: - print "Transistor "+trans+" Not found" + print "Transistor "+str(trans)+" Not found" sys.exit(1) stat = start+" "+words[0]+"(" @@ -444,7 +447,7 @@ class NgMoConverter: elif trans=='pmos' : start = self.mappingData["Devices"][deviceName]["import"]+".Mp" else: - print "MOSFET "+trans+" not found" + print "MOSFET "+str(trans)+" not found" sys.exit(1) @@ -508,7 +511,43 @@ class NgMoConverter: stat += ",".join(str(item) for item in tempstatList)+");" modelicaCompInit.append(stat) - + + elif deviceName=='j': + print "TransInfo---->",transInfo + trans = transInfo[words[4]] + if trans == 'njf': + start = self.mappingData["Devices"][deviceName]["import"]+".NJF" + elif trans == 'pjf': + start = self.mappingData["Devices"][deviceName]["import"]+".PJF" + else: + print "JFET "+str(trans)+" Not found" + sys.exit(1) + + stat = start+" "+words[0]+"(" + tempstatList=[] + userDeviceParamList=[] + refName = words[4] + for key in modelInfo[refName]: + #If parameter is not mapped then it will just pass + try: + actualModelicaParam = self.mappingData["Devices"][deviceName]["mapping"][key] + tempstatList.append(actualModelicaParam+"="+self.getUnitVal(modelInfo[refName][key])+" ") + userDeviceParamList.append(str(actualModelicaParam)) + except: + pass + #Running loop over default parameter of OpenModelica + for default in self.mappingData["Devices"][deviceName]["default"]: + if default in userDeviceParamList: + continue + else: + defaultValue = self.mappingData["Devices"][deviceName]["default"][default] + tempstatList.append(default+"="+self.getUnitVal(defaultValue)+" ") + + stat += ",".join(str(item) for item in tempstatList)+");" + modelicaCompInit.append(stat) + + + #Empty device details as well self.deviceDetail[:]=[] -- cgit From 6c73f608fd6b4b3fec92cdc6c4842a5afc0a9d6f Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Fri, 6 May 2016 14:26:14 +0530 Subject: Mapping for JFET is done --- src/ngspicetoModelica/NgspicetoModelica.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index 1e67c07b..df165fa0 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -74,7 +74,6 @@ class NgMoConverter: self.ifMOS = True schematicInfo.append(eachline) self.deviceDetail.append(eachline) - print "Device Detail--------->",self.deviceDetail elif eachline[0]=='x' or eachline[0]=='X': schematicInfo.append(eachline) self.subCktDetail.append(eachline) @@ -172,7 +171,7 @@ class NgMoConverter: modelInfo[refModelName][info[0]] = info[1] f.close() - print "Model Info----->",modelInfo + return modelName, modelInfo, subcktName, paramInfo ,transInfo,inbuiltModelDict @@ -513,12 +512,11 @@ class NgMoConverter: modelicaCompInit.append(stat) elif deviceName=='j': - print "TransInfo---->",transInfo trans = transInfo[words[4]] if trans == 'njf': - start = self.mappingData["Devices"][deviceName]["import"]+".NJF" + start = self.mappingData["Devices"][deviceName]["import"]+".J_NJFJFET" elif trans == 'pjf': - start = self.mappingData["Devices"][deviceName]["import"]+".PJF" + start = self.mappingData["Devices"][deviceName]["import"]+".J_PJFJFET" else: print "JFET "+str(trans)+" Not found" sys.exit(1) -- cgit From 703b45855189130cb65f8fabf9d2fe5a54910e16 Mon Sep 17 00:00:00 2001 From: fahim-oscad Date: Tue, 10 May 2016 10:45:31 +0530 Subject: Modifed JFET modelica model --- src/ngspicetoModelica/NgspicetoModelica.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index df165fa0..e9855e03 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -513,6 +513,7 @@ class NgMoConverter: elif deviceName=='j': trans = transInfo[words[4]] + """ if trans == 'njf': start = self.mappingData["Devices"][deviceName]["import"]+".J_NJFJFET" elif trans == 'pjf': @@ -520,8 +521,10 @@ class NgMoConverter: else: print "JFET "+str(trans)+" Not found" sys.exit(1) + """ + start = self.mappingData["Devices"][deviceName]["import"] - stat = start+" "+words[0]+"(" + stat = start+" "+words[0]+"(modelcard(" tempstatList=[] userDeviceParamList=[] refName = words[4] @@ -541,7 +544,7 @@ class NgMoConverter: defaultValue = self.mappingData["Devices"][deviceName]["default"][default] tempstatList.append(default+"="+self.getUnitVal(defaultValue)+" ") - stat += ",".join(str(item) for item in tempstatList)+");" + stat += ",".join(str(item) for item in tempstatList)+"));" modelicaCompInit.append(stat) @@ -786,6 +789,13 @@ class NgMoConverter: connInfo.append(conn) conn = 'connect(' + words[0] + '.E,' + nodeDic[words[3]] + ');' connInfo.append(conn) + elif eachline[0]=='j' or eachline[0]=='J': + conn = 'connect('+words[0]+'.D,' + nodeDic[words[1]]+');' + connInfo.append(conn) + conn = 'connect('+words[0]+'.G,' + nodeDic[words[2]]+');' + connInfo.append(conn) + conn = 'connect('+words[0]+'.S,' + nodeDic[words[3]]+');' + connInfo.append(conn) elif eachline[0]=='m' or eachline[0]=='M': conn = 'connect(' + words[0] + '.D,' + nodeDic[words[1]] + ');' connInfo.append(conn) -- cgit From bb8a6a6974d2f425d51df1a3042706011ff351ad Mon Sep 17 00:00:00 2001 From: athulappadan Date: Wed, 25 May 2016 14:17:33 +0530 Subject: DockWidget added in UI for ngspice to modelica conversion --- src/ngspicetoModelica/NgspicetoModelica.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/ngspicetoModelica/NgspicetoModelica.py') diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py index e9855e03..7b7e4527 100644 --- a/src/ngspicetoModelica/NgspicetoModelica.py +++ b/src/ngspicetoModelica/NgspicetoModelica.py @@ -7,9 +7,9 @@ from string import maketrans class NgMoConverter: - def __init__(self): + def __init__(self, map_json): #Loading JSON file which hold the mapping information between ngspice and Modelica. - with open('Mapping.json') as mappingFile: + with open(map_json) as mappingFile: self.mappingData = json.load(mappingFile) self.ifMOS = False @@ -987,8 +987,9 @@ def main(args): """ It is main function of module Ngspice to Modelica converter """ - if len(sys.argv) == 2: + if len(sys.argv) == 3: filename = sys.argv[1] + map_json = sys.argv[2] else: print "USAGE:" print "python NgspicetoModelica.py " @@ -996,8 +997,11 @@ def main(args): dir_name = os.path.dirname(os.path.realpath(filename)) file_basename = os.path.basename(filename) + + cwd = os.getcwd() + os.chdir(dir_name) - obj_NgMoConverter = NgMoConverter() + obj_NgMoConverter = NgMoConverter(map_json) #Getting all the require information lines = obj_NgMoConverter.readNetlist(filename) @@ -1110,6 +1114,8 @@ def main(args): out.close() + + os.chdir(cwd) # Call main function -- cgit