diff options
author | fahim-oscad | 2016-04-25 15:44:05 +0530 |
---|---|---|
committer | fahim-oscad | 2016-04-25 15:44:05 +0530 |
commit | 99001f8ddcfa492c8068b864ec08fe2a85a88106 (patch) | |
tree | e4587978aa5dfee1f1f171a4d6ac0492cf81cea1 /src/ngspicetoModelica | |
parent | bbc4735bafa85adc9d838fc6b8d5a06de735a13f (diff) | |
download | eSim-99001f8ddcfa492c8068b864ec08fe2a85a88106.tar.gz eSim-99001f8ddcfa492c8068b864ec08fe2a85a88106.tar.bz2 eSim-99001f8ddcfa492c8068b864ec08fe2a85a88106.zip |
Modified code to include current source
Diffstat (limited to 'src/ngspicetoModelica')
-rw-r--r-- | src/ngspicetoModelica/Mapping.json | 18 | ||||
-rw-r--r-- | src/ngspicetoModelica/NgspicetoModelica.py | 69 |
2 files changed, 53 insertions, 34 deletions
diff --git a/src/ngspicetoModelica/Mapping.json b/src/ngspicetoModelica/Mapping.json index ce493eab..22a10f43 100644 --- a/src/ngspicetoModelica/Mapping.json +++ b/src/ngspicetoModelica/Mapping.json @@ -12,10 +12,17 @@ }, "Sources":{ - "pulse":"Analog.Sources.TrapezoidVoltage", - "sine":"Analog.Sources.SineVoltage", - "pwl" : "Analog.Sources.TableVoltage", - "dc" : "Analog.Sources.ConstantVoltage" + "v":{ + "pulse":"Analog.Sources.TrapezoidVoltage", + "sine":"Analog.Sources.SineVoltage", + "pwl" : "Analog.Sources.TableVoltage", + "dc" : "Analog.Sources.ConstantVoltage" + }, + + "i":{ + "dc":"Analog.Sources.ConstantCurrent" + } + }, "Devices":{ "d":{ @@ -153,7 +160,8 @@ "m":"e-3", "meg":"e6", "n":"e-9", - "f":"e-15" + "f":"e-15", + "ma":"e-3" } 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() |