1
2 import types
3 import warnings
4
5 import empro
6 from empro import _deprecation
7 from empro.toolkit import long_path_util
8
9 if not hasattr(empro.internal,"analysis"):
10 empro.internal.analysis = types.ModuleType("empro.internal.analysis")
11
12 with warnings.catch_warnings():
13 warnings.simplefilter("ignore", DeprecationWarning)
14 if not hasattr(empro.internal, "sipi"):
15 _deprecation.module_set_deprecated_attr(
16 empro.internal,
17 "sipi",
18 empro.internal.analysis,
19 version=410,
20 message="Use empro.internal.analysis instead")
21
22 PIDC, PIAC, PASI, PPR, THERMAL, ELECTRO_THERMAL = 1,2,3,4,5,6
23 EMFU, EMUD, EMSM = 7,8,9
24 EMFUPE, EMUDPE = 10,11
25
26 FARZONE_ANGLE_INCREMENT = 5
27 from empro.toolkit import _printexception
28
29 _minimumPPRFrequency = 1e6
32 import gui
33 gui.initialize()
34
35 if not hasattr(empro.gui, "activeProjectView"):
36 import os
37 os.chdir(os.path.join(os.environ['EMPROHOME'], os.pardir, os.pardir))
38 try:
39 args = []
40 baseApp = empro.gui.BaseApp()
41 baseApp.init(args)
42 except:
43 pass
44
45 if not hasattr(empro.internal.analysis,"momentumDir"):
46 empro.internal.analysis.momentumDir = None
49
51 import os
52 import empro
53 import empro.toolkit.analysis
54 import json
55 import shutil
56
57
58
59
60
61
62
63
64 empro.toolkit.analysis.startEnvironment()
65 os.environ["EMPRO_CONE_DIMENSION"]="3"
66
67
68 wrkPath = kwargs.get("wrkDirPath", None)
69 if not wrkPath:
70 wrkPath = kwargs.get("path", "")
71 hpeesof_dir = kwargs.get("hpeesof_dir", "")
72 if hpeesof_dir:
73 empro.liboa.loadOALibraries(wrkPath, hpeesof_dir)
74 else:
75 empro.liboa.loadOALibraries(wrkPath)
76 libDefAttributes = empro.liboa.getAllLibDefAttributes()
77 for library, attributes in libDefAttributes.iteritems():
78 for key,value in attributes.iteritems():
79 if key=="addon_path":
80 import empro.toolkit.addon as addon
81 addon.loadAdditionalAddons(searchDirs=value, forceEnabled=True)
82
83
84 drfPath = kwargs.get("drfPath")
85 loadDisplayResourceFiles(wrkPath, drfPath)
86
87
88 setupFile = kwargs.get("libCellViewSetupFilePath", None)
89 oaDesignRefMap = None
90 if setupFile:
91
92
93
94
95 if not os.path.exists(setupFile):
96 from empro.gui import MessageBox
97 MessageBox.critical( "Load Design", "No such file: " + setupFile, 0, 0 )
98 return
99 repairInstructions = ""
100 repairDict = kwargs.get("repair_dict", None)
101 if repairDict:
102 repairInstructions = json.dumps(repairDict)
103 try:
104
105 oaDesignRefMap = empro.gui._readAndRepairOaDesignRefMapFromSetupFile(setupFile, repairInstructions)
106 except:
107 from empro.gui import MessageBox
108 import sys
109 msg = str(sys.exc_info()[1])
110 MessageBox.critical( "Load Design", "Error processing file {}:\n{} ".format(setupFile, msg), 0, 0 )
111 return
112
113 projectLocation = empro.libCellViewSetupFileProjectLocation(setupFile)
114 lib = projectLocation.lib
115 cell = projectLocation.cell
116 emview = projectLocation.view
117 else:
118 lib = kwargs.get("lib","")
119 cell = kwargs.get("cell","")
120 emview = kwargs.get("sipi_view","sipiSetup")
121 projectLocation = empro.libCellViewProjectLocation(lib, cell, emview)
122
123 if lib.startswith("/"):
124 lib = lib[1:]
125
126
127 empro.simulation.SimulatorSetup.addAvailablePresetsFromOa(lib)
128 empro.VendorPartsDbList.instance()._initUserVendorPartsDb(lib);
129
130
131 defaultSimDir = empro.simulation.directoryForSimulations(projectLocation, False)
132 legacySimDir = os.path.join("simulation", empro.internal.__fileSystemName(lib, True), empro.internal.__fileSystemName(cell, True), empro.internal.__fileSystemName(emview, True))
133 extraInputBaseDir = os.path.join(defaultSimDir, "extra")
134 defaultExtraInputDir = os.path.join(extraInputBaseDir, "0")
135 copyFromLegacyLocations = not os.path.exists(extraInputBaseDir)
136 kw_ltd_subst = kwargs.get("ltd_subst","")
137 if kw_ltd_subst:
138 if os.path.exists(kw_ltd_subst):
139 if not os.path.exists(defaultExtraInputDir): os.makedirs(defaultExtraInputDir)
140 shutil.copyfile(kw_ltd_subst, os.path.join(defaultExtraInputDir, "proj.ltd"))
141 elif os.path.exists(os.path.join(defaultExtraInputDir, "proj.ltd")):
142 os.remove(os.path.exists(os.path.join(defaultExtraInputDir, "proj.ltd")))
143 elif copyFromLegacyLocations:
144 if os.path.exists(os.path.join(defaultSimDir, "proj.ltd")):
145 if not os.path.exists(defaultExtraInputDir): os.makedirs(defaultExtraInputDir)
146 shutil.copyfile(os.path.join(defaultSimDir, "proj.ltd"), os.path.join(defaultExtraInputDir, "proj.ltd"))
147 elif os.path.exists(os.path.join(legacySimDir, "proj.ltd")):
148 if not os.path.exists(defaultExtraInputDir): os.makedirs(defaultExtraInputDir)
149 shutil.copyfile(os.path.join(legacySimDir, "proj.ltd"), os.path.join(defaultExtraInputDir, "proj.ltd"))
150 kw_libS3D = kwargs.get("libS3D","")
151 if kw_libS3D:
152 if os.path.exists(kw_libS3D):
153 if not os.path.exists(defaultExtraInputDir): os.makedirs(defaultExtraInputDir)
154 shutil.copyfile(kw_libS3D, os.path.join(defaultExtraInputDir, "proj_libS3D.xml"))
155 elif os.path.exists(os.path.join(defaultExtraInputDir, "proj_libS3D.xml")):
156 os.remove(os.path.exists(os.path.join(defaultExtraInputDir, "proj_libS3D.xml")))
157 elif copyFromLegacyLocations:
158 if os.path.exists(os.path.join(defaultSimDir, "proj_libS3D.xml")):
159 if not os.path.exists(defaultExtraInputDir): os.makedirs(defaultExtraInputDir)
160 shutil.copyfile(os.path.join(defaultSimDir, "proj_libS3D.xml"), os.path.join(defaultExtraInputDir, "proj_libS3D.xml"))
161 elif os.path.exists(os.path.join(legacySimDir, "proj_libS3D.xml")):
162 if not os.path.exists(defaultExtraInputDir): os.makedirs(defaultExtraInputDir)
163 shutil.copyfile(os.path.join(legacySimDir, "proj_libS3D.xml"), os.path.join(defaultExtraInputDir, "proj_libS3D.xml"))
164 var_dict = kwargs.get("var_dict")
165 if var_dict is not None:
166 if not os.path.exists(defaultExtraInputDir): os.makedirs(defaultExtraInputDir)
167 with open(os.path.join(defaultExtraInputDir, "varDict.json"), 'w') as outfile:
168 json.dump(var_dict, outfile)
169 expr_dict = kwargs.get("expr_dict")
170 if expr_dict is not None:
171 if not os.path.exists(defaultExtraInputDir): os.makedirs(defaultExtraInputDir)
172 with open(os.path.join(defaultExtraInputDir, "exprDict.json"), 'w') as outfile:
173 json.dump(expr_dict, outfile)
174
175
176
177
178 projectDirectory = projectLocation.directory()
179 sipiViewProjectFile = os.path.join(projectDirectory, "eesof_empro.xml")
180 if not os.path.exists(sipiViewProjectFile):
181 sipiViewProjectFile = os.path.join(projectDirectory, "Project.xml")
182 if os.path.exists(sipiViewProjectFile) and os.path.getsize(sipiViewProjectFile) > 50 :
183
184 empro.activeProject.loadActiveProjectFrom(lib, cell, emview)
185 else:
186
187 try:
188 with empro.activeProject as project:
189 sim = project.createSimulationData()
190 sim.engine="FemEngine"
191 project.location = projectLocation
192 if not oaDesignRefMap:
193 oaDesignRefMap = empro.geometry._readOaDesignRefMapFromViewSetup(lib, cell, emview)
194 for key, oaDesignRef in oaDesignRefMap.items():
195 layout = empro.geometry.OaLayout.readLayoutEx(oaDesignRef, key, extraInputBaseDir)
196 project.geometry().append(layout)
197 project.displayUnits.setPreference(layout.userUnits)
198 defaultName = { empro.analysis.Analysis.DCAnalysisType : "DC Analysis",
199 empro.analysis.Analysis.ACAnalysisType : "AC Analysis",
200 empro.analysis.Analysis.PPRAnalysisType : "PPR Analysis",
201 empro.analysis.Analysis.PASIAnalysisType : "PA-SI Analysis",
202 empro.analysis.Analysis.THAnalysisType : "Thermal Analysis",
203 empro.analysis.Analysis.ETHAnalysisType : "Electro-Thermal Analysis",}
204
205 analysisTypes = [empro.analysis.Analysis.DCAnalysisType, empro.analysis.Analysis.ACAnalysisType, empro.analysis.Analysis.PPRAnalysisType, empro.analysis.Analysis.PASIAnalysisType, empro.analysis.Analysis.THAnalysisType, empro.analysis.Analysis.ETHAnalysisType]
206
207 if "rfpro" in empro.core.ApplicationInfo.personality():
208 defaultName[empro.analysis.Analysis.EMFUAnalysisType] = "Full EM Analysis"
209 defaultName[empro.analysis.Analysis.EMUDAnalysisType] = "User Defined EM Analysis"
210 analysisTypes = []
211 analysisTypes.append(empro.analysis.Analysis.EMFUAnalysisType)
212 analysisTypes.append(empro.analysis.Analysis.EMUDAnalysisType)
213
214 if "pepro" in empro.core.ApplicationInfo.personality():
215 defaultName[empro.analysis.Analysis.EMFUPEAnalysisType] = "Parasitic Extraction-All Nets"
216 defaultName[empro.analysis.Analysis.EMUDPEAnalysisType] = "Parasitic Extraction-Selected Nets"
217 analysisTypes = []
218 analysisTypes.append(empro.analysis.Analysis.EMFUPEAnalysisType)
219 analysisTypes.append(empro.analysis.Analysis.EMUDPEAnalysisType)
220
221 for index, analysisType in enumerate(analysisTypes):
222 setup = empro.analysis.Analysis()
223 setup.analysisType = analysisType
224 setup.name = defaultName[analysisType]
225 empro.activeProject.analyses.append(setup)
226 project._clearUndoStack()
227 except:
228 from empro.gui import MessageBox
229 import sys
230 msg = str(sys.exc_info()[1])
231 MessageBox.critical( "Load Project", "The project has failed to load: " + msg, 0, 0 )
232
233 if hasattr(empro.gui, "activeProjectView"):
234
235 emview_utf8 = "Unknown"
236 try:
237 emview_utf8 = emview.decode(encoding='UTF-8', errors='strict')
238 except:
239 pass
240 title = cell + "[*] [" + lib + ":" + cell + ":" + emview_utf8 + "] " + getDisplayName()
241 _updateGui(title)
242
243
244 if hasattr(empro.gui, '_setADSCmptToVendorDBPythonCallback'):
245 try:
246 import empro.toolkit.analysis.schematic_generation as schematic_generation
247 empro.gui._setADSCmptToVendorDBPythonCallback(schematic_generation.addADSComponentInstancesToVendorDB)
248 except:
249 import sys
250 msg = str(sys.exc_info()[1])
251 print "Failed to set addADSComponentInstancesToVendorDBcallback function:\n", msg
252
253
254 if hasattr(empro, "addons"):
255
256 if hasattr(empro.addons, "LayersDisplay"):
257 try:
258 empro.addons.LayersDisplay.activateDockWidget()
259 except:
260 pass
261
262 if hasattr(empro.addons, "PDNTableView"):
263 try:
264 empro.addons.PDNTableView.activate()
265 except:
266 import sys
267 pass
268
269 if hasattr(empro.addons, "PDNOptimization_TableView"):
270 try:
271 empro.addons.PDNOptimization_TableView.activate()
272 except:
273 import sys
274 pass
275
276 if hasattr(empro.addons, "PDNOptimization_MultiModelTableView"):
277 try:
278 empro.addons.PDNOptimization_MultiModelTableView.activate()
279 except:
280 import sys
281 pass
282
284 if hasattr(empro.gui, "activeProjectView"):
285 pv = empro.gui.activeProjectView()
286 gv = pv.geometryView()
287
288 pv.windowTitle = title
289
290 gv.useCamera("top")
291 pv.showGeometryView()
292 gv.zoomGeometryViewToExtents()
293
317
327
334
351
368
377
393
407
424
426 intHash = _createPinHashNetType()
427 stringHash = {}
428 for (pinId,netTypeInt) in intHash.iteritems():
429 if netTypeInt == 1:
430 netTypeString = "sig"
431 elif netTypeInt == 2:
432 netTypeString = "pwr"
433 elif netTypeInt == 4:
434 netTypeString = "gnd"
435 else:
436 netTypeString = ""
437 stringHash[pinId] = netTypeString
438 return stringHash
439
448
451 if sipiData.analysisType in [EMFU, EMFUPE]:
452 usedNetNames = _allNetNames(sipiData)
453 else:
454 usedNetNames = [net.name for net in sipiData.getNetList()]
455 return usedNetNames
456
468
493
494
495 @_printexception
496 -def _pinsUsed(sipiData):
524
555
558 usedInstanceIds = set()
559 instanceIdMapping = _createInstanceHash()
560
561 thermalComponentGroupList = sipiData.getThermalComponentGroupList()
562 for group in thermalComponentGroupList:
563 for source in group:
564 usedInstanceIds.add(instanceIdMapping[source.instance().name])
565 for port in sipiData.getVrmList():
566 for pin in port.pins():
567 try:
568 usedInstanceIds.add(instanceIdMapping[pin.getInstanceName()])
569 except KeyError:
570 pass
571 for port in sipiData.getSinkList():
572 for pin in port.pins():
573 try:
574 usedInstanceIds.add(instanceIdMapping[pin.getInstanceName()])
575 except KeyError:
576 pass
577 for port in sipiData.getPortList():
578 for pin in port.pins():
579 try:
580 usedInstanceIds.add(instanceIdMapping[pin.getInstanceName()])
581 except KeyError:
582 pass
583 for componentGroup in sipiData.getComponentModelGroupList():
584 [usedInstanceIds.add(instanceIdMapping[componentInstance.name]) for componentInstance in componentGroup.instances()]
585 return usedInstanceIds
586
589 usedPins = _pinsUsed(sipiData)
590
591 pinHash = _createPinHash()
592 pinNetNames = _createPinHashNetName()
593
594 names = []
595 for pinName in usedPins:
596 hashOfPin = pinHash[pinName]
597 names.append( pinNetNames[hashOfPin] )
598 return set(names)
599
604
607 components = []
608 import os
609
610 for componentGroup in sipiData.getComponentModelGroupList():
611 updateableAfterSimulation = componentGroup.updateableAfterSimulation
612 for componentInstance in componentGroup.instances():
613 component = componentInstance.instance()
614
615 if len(component.pins())<=2:
616 pin1 = component.pins()[0]
617 pin2 = component.pins()[1]
618 pinName1 = component.name + "." + pin1.name
619 pinName2 = component.name + "." + pin2.name
620
621 circuitComponent = empro.components.CircuitComponent()
622 circuitComponent.name = component.name
623
624 if hasattr(circuitComponent, "calibration"):
625 circuitComponent.calibration = "NoCalibration"
626 if updateableAfterSimulation and sipiData.newSimulationData().componentsTreatedAsPorts and sipiData.analysisType != 4:
627 circuitComponent.port = True
628 circuitComponentDefinition = empro.components.Feed()
629 circuitComponentDefinition.name = circuitComponent.name
630 circuitComponentDefinition.impedance.resistance = componentInstance.referenceImpedanceFromPins()
631 circuitComponentDefinition.feedType = "Voltage"
632 circuitComponentDefinition.amplitudeMultiplier = 1
633 circuitComponent.definition = circuitComponentDefinition
634 else:
635 circuitComponent.port = False
636 if len(componentGroup.models()) == 0:
637 raise RuntimeError("No models are defined")
638 componentModel = componentGroup.models()[ componentGroup.defaultModelIndex ]
639 circuitComponentDefinition = componentModel.getPassiveLoad().clone()
640 circuitComponentDefinition.name = circuitComponent.name
641 circuitComponent.definition = circuitComponentDefinition
642
643 assert(len(component.pins())==2)
644 circuitComponent.tail = pin1.dotPosition
645 circuitComponent.head = pin2.dotPosition
646
647 minList = []
648 plusList = []
649 plusList.append( empro.components.MultiPinExtentPin(pinName1, pinLocations[pinHash[pinName1]]) )
650 minList.append( empro.components.MultiPinExtentPin(pinName2, pinLocations[pinHash[pinName2]]) )
651 circuitExtent = empro.components.MultiPinExtent(minList, plusList)
652 circuitComponent.extent = circuitExtent
653 circuitComponent.useExtent = True
654 components.append(circuitComponent)
655 else:
656 portMap = componentGroup.pinPortMap()
657 for portNr, minPlusPins in portMap.getPinNamesForPortNumbers(True):
658 circuitComponent = empro.components.CircuitComponent()
659 circuitComponent.name = _canonicalNameMultiPort(component.name, portNr)
660 if sipiData.newSimulationData().componentsTreatedAsPorts and sipiData.analysisType != 4:
661 circuitComponent.port = True
662 circuitComponentDefinition = empro.components.Feed()
663 circuitComponentDefinition.name = circuitComponent.name
664 circuitComponentDefinition.impedance.resistance = componentInstance.referenceImpedanceFromPins()
665 circuitComponentDefinition.feedType = "Voltage"
666 circuitComponentDefinition.amplitudeMultiplier = 1
667 circuitComponent.definition = circuitComponentDefinition
668 else:
669 if not componentGroup._requiresUpdateableAfterSimulation:
670 circuitComponent.port = False
671 if len(componentGroup.models()) == 0:
672 raise RuntimeError("No models are defined")
673 componentModel = componentGroup.models()[ componentGroup.defaultModelIndex ]
674 circuitComponentDefinition = componentModel.getPassiveLoad().clone()
675 circuitComponentDefinition.name = circuitComponent.name
676 circuitComponent.definition = circuitComponentDefinition
677 else:
678 raise RuntimeError("Embedded multiport circuit components not supported")
679
680 minList = []
681 plusList = []
682
683 for plusPinName in minPlusPins[0]:
684 pinName1 = component.name + "." + plusPinName
685 plusList.append( empro.components.MultiPinExtentPin(pinName1, pinLocations[pinHash[pinName1]]) )
686 for minusPinName in minPlusPins[1]:
687 if minusPinName == empro.geometry.OaLayout.getCoverPinName():
688 continue
689 pinName2 = component.name + "." + minusPinName
690 minList.append( empro.components.MultiPinExtentPin(pinName2, pinLocations[pinHash[pinName2]]) )
691
692 circuitExtent = empro.components.MultiPinExtent(minList, plusList) if len(minList)>0 else empro.components.MultiPinExtent(plusList)
693 circuitComponent.extent = circuitExtent
694 circuitComponent.useExtent = True
695
696 circuitComponent.tail = minList[0].position if len(minList) else plusList[0].position
697 circuitComponent.head = plusList[0].position
698
699 components.append(circuitComponent)
700 return components
701
704
705 import datetime
706 import os
707
708 vrmArePorts = True
709 if "SIPI_AC_VRMS_ARE_NOT_PORTS" in os.environ.keys():
710 vrmArePorts = False
711
712 pinHash = _createPinHash()
713 pinLocations = _createPinHashPositions()
714
715 lumped = 0
716 vrmList = sipiData.getVrmList()
717 sinkList = sipiData.getSinkList()
718 simPath = sipiData.simulationPath
719
720 components = []
721
722 def haveAtLeast(x, minimumValue):
723 if float(x)<minimumValue:
724 return minimumValue
725 return x
726
727 for vrm in vrmList:
728 port = vrm
729
730 circuitComponent = empro.components.CircuitComponent()
731 circuitComponent.name = vrm.name
732
733 circuitComponent._termType = empro.components._ettInput
734 if hasattr(circuitComponent, "calibration"):
735 circuitComponent.calibration = "NoCalibration"
736
737 if vrmArePorts:
738 circuitComponentDefinition = empro.components.Feed()
739 if sipiData.analysisType==4:
740 circuitComponentDefinition.impedance.resistance = haveAtLeast(vrm.resistance, 1e-6)
741 else:
742 circuitComponentDefinition.impedance.resistance = haveAtLeast(port.referenceImpedance,1e-6)
743 circuitComponentDefinition.feedType = "Voltage"
744 circuitComponentDefinition.amplitudeMultiplier = 1
745 circuitComponentDefinition.name = circuitComponent.name
746 circuitComponent.definition = circuitComponentDefinition
747 else:
748 circuitComponentDefinition = empro.components.PassiveLoad()
749 circuitComponentDefinition.name = circuitComponent.name
750 circuitComponentDefinition.impedance.resistance = haveAtLeast(vrm.resistance, 1e-6)
751 circuitComponentDefinition.impedance.inductance = vrm.inductance
752 circuitComponentDefinition.impedance.capacitance = 0.0
753 circuitComponent.definition = circuitComponentDefinition
754
755 plusPinNames = [x.name for x in port.plusPins()]
756 minusPinNames = [x.name for x in port.minusPins()]
757
758 minList = []
759 plusList = []
760 for pinName in plusPinNames:
761 plusList.append( empro.components.MultiPinExtentPin(pinName, pinLocations[pinHash[pinName]]) )
762 for pinName in minusPinNames:
763 minList.append( empro.components.MultiPinExtentPin(pinName, pinLocations[pinHash[pinName]]) )
764
765 circuitExtent = empro.components.MultiPinExtent(minList, plusList)
766 circuitComponent.extent = circuitExtent
767 circuitComponent.useExtent = True
768 circuitComponent.port = vrmArePorts
769 circuitComponent.tail = minList[0].position
770 circuitComponent.head = plusList[0].position
771 components.append(circuitComponent)
772
773 for sink in sinkList:
774 port = sink
775
776 circuitComponent = empro.components.CircuitComponent()
777
778 circuitComponent._termType = empro.components._ettOutput
779 if sink.pinCurrentModel=="EqualCurrent":
780 circuitComponent._pinModel = empro.components._EqualCurrent
781 circuitComponent.name = sink.name
782 if hasattr(circuitComponent, "calibration"):
783 circuitComponent.calibration = "NoCalibration"
784 circuitComponentDefinition = empro.components.Feed()
785 circuitComponentDefinition.name = circuitComponent.name
786 circuitComponentDefinition.feedType = "Current"
787 circuitComponentDefinition.amplitudeMultiplier = 1
788 if sipiData.analysisType == 4:
789 circuitComponentDefinition.impedance.resistance = haveAtLeast(sink.resistance, 1e-6)
790 else:
791 circuitComponentDefinition.impedance.resistance = haveAtLeast(port.referenceImpedance,1e-6)
792 circuitComponent.definition = circuitComponentDefinition
793
794 plusPinNames = [x.name for x in port.plusPins()]
795 minusPinNames = [x.name for x in port.minusPins()]
796
797 minList = []
798 plusList = []
799 for pinName in plusPinNames:
800 plusList.append( empro.components.MultiPinExtentPin(pinName, pinLocations[pinHash[pinName]]) )
801 for pinName in minusPinNames:
802 minList.append( empro.components.MultiPinExtentPin(pinName, pinLocations[pinHash[pinName]]) )
803
804 circuitExtent = empro.components.MultiPinExtent(minList, plusList)
805 circuitComponent.extent = circuitExtent
806 circuitComponent.useExtent = True
807 circuitComponent.port = True
808 circuitComponent.tail = minList[0].position
809 circuitComponent.head = plusList[0].position
810 components.append(circuitComponent)
811
812 components += _generateCircuitComponentsForComponentModels(sipiData, pinHash, pinLocations)
813
814 with empro.activeProject as project:
815 project.circuitComponents().clear()
816 project.circuitComponents().appendList(components)
817
821
822 import datetime
823 import os
824
825 pinHash = _createPinHash()
826 pinLocations = _createPinHashPositions()
827
828 simPath = sipiData.simulationPath
829
830 components = []
831
832 def haveAtLeast(x, minimumValue):
833 if float(x)<minimumValue:
834 return minimumValue
835 return x
836
837 ioPorts = sipiData.getPortList()
838 for port in ioPorts:
839 circuitComponent = empro.components.CircuitComponent()
840 circuitComponent.name = port.name
841 if hasattr(circuitComponent, "calibration"):
842 circuitComponent.calibration = "NoCalibration"
843 circuitComponentDefinition = empro.components.Feed()
844 circuitComponentDefinition.name = port.name
845 circuitComponentDefinition.feedType = "Current"
846 circuitComponentDefinition.amplitudeMultiplier = 1
847 circuitComponentDefinition.impedance.resistance = haveAtLeast(port.referenceImpedance, 1e-6)
848 circuitComponent.definition = circuitComponentDefinition
849 circuitComponent._termType = empro.components._ettInputOutput
850
851 plusPinNames = [x.name for x in port.plusPins()]
852 minusPinNames = [x.name for x in port.minusPins()]
853
854 minList = []
855 plusList = []
856 for pinName in plusPinNames:
857 plusList.append( empro.components.MultiPinExtentPin(pinName, pinLocations[pinHash[pinName]]) )
858 for pinName in minusPinNames:
859 minList.append( empro.components.MultiPinExtentPin(pinName, pinLocations[pinHash[pinName]]) )
860
861 circuitExtent = empro.components.MultiPinExtent(minList, plusList)
862 circuitComponent.extent = circuitExtent
863 circuitComponent.useExtent = True
864 circuitComponent.port = True
865 circuitComponent.tail = minList[0].position
866 circuitComponent.head = plusList[0].position
867 components.append(circuitComponent)
868
869 components += _generateCircuitComponentsForComponentModels(sipiData, pinHash, pinLocations)
870
871 with empro.activeProject as project:
872 project.circuitComponents().clear()
873 project.circuitComponents().appendList(components)
874
877
878 import datetime
879 import os
880
881 pinHash = _createPinHash()
882 pinLocations = _createPinHashPositions()
883
884 simPath = sipiData.simulationPath
885
886 components = []
887
888 def haveAtLeast(x, minimumValue):
889 if float(x)<minimumValue:
890 return minimumValue
891 return x
892
893 ioPorts = sipiData.getPortList()
894 for port in ioPorts:
895 circuitComponent = empro.components.CircuitComponent()
896 circuitComponent.name = port.name
897 if hasattr(circuitComponent, "calibration"):
898 circuitComponent.calibration = "NoCalibration"
899 circuitComponentDefinition = empro.components.Feed()
900 circuitComponentDefinition.name = port.name
901 circuitComponentDefinition.feedType = "Current"
902 circuitComponentDefinition.amplitudeMultiplier = 1
903 circuitComponentDefinition.impedance.resistance = haveAtLeast(port.referenceImpedance, 1e-6)
904 circuitComponent.definition = circuitComponentDefinition
905 circuitComponent._termType = empro.components._ettInputOutput
906
907 plusPinNames = [x.name for x in port.plusPins()]
908 minusPinNames = [x.name for x in port.minusPins()]
909
910 minList = []
911 plusList = []
912 for pinName in plusPinNames:
913 plusList.append( empro.components.MultiPinExtentPin(pinName, pinLocations[pinHash[pinName]]) )
914 for pinName in minusPinNames:
915 minList.append( empro.components.MultiPinExtentPin(pinName, pinLocations[pinHash[pinName]]) )
916
917 circuitExtent = empro.components.MultiPinExtent(minList, plusList) if len(minList)>0 else empro.components.MultiPinExtent(plusList)
918 circuitComponent.extent = circuitExtent
919 circuitComponent.useExtent = True
920 circuitComponent.port = True
921 circuitComponent.tail = minList[0].position if len(minList) else plusList[0].position
922 circuitComponent.head = plusList[0].position
923 components.append(circuitComponent)
924
925 components += _generateCircuitComponentsForComponentModels(sipiData, pinHash, pinLocations)
926
927 with empro.activeProject as project:
928 project.circuitComponents().clear()
929 project.circuitComponents().appendList(components)
930
934
935 components = []
936
937 pinHash = _createPinHash()
938 pinLocations = _createPinHashPositions()
939
940 def _haveAtLeastResistance(x, minimumValue):
941 d = float(x)
942 return str(d if d > minimumValue else minimumValue) + "ohm"
943
944
945 portsReduction = empro.analysis.TouchingPortsReduction(sipiData)
946 originalPortsReduction = portsReduction.originalPortsReduction
947 originalPortNames = portsReduction.originalPortNames
948 originalZRefs = portsReduction.originalZRefs
949 emModelReduction = portsReduction.emModelReduction
950
951 def _nextPortInfo():
952 result = None
953 reducedPortIdx = originalPortsReduction[_nextPortInfo.portIdx]
954 if _nextPortInfo.nextEmIdx < len(emModelReduction) and emModelReduction[_nextPortInfo.nextEmIdx] == reducedPortIdx:
955 result = (originalPortNames[_nextPortInfo.portIdx], originalZRefs[_nextPortInfo.portIdx])
956 _nextPortInfo.nextEmIdx = _nextPortInfo.nextEmIdx + 1
957 _nextPortInfo.portIdx = _nextPortInfo.portIdx + 1
958 return result
959
960 _nextPortInfo.portIdx = 0
961 _nextPortInfo.nextEmIdx = 0
962
963
964 for port in sipiData.getPortList():
965 nextPortInfo = _nextPortInfo();
966 if nextPortInfo:
967 circuitComponent = empro.components.CircuitComponent()
968 circuitComponent.name = port.name
969 if hasattr(circuitComponent, "calibration"):
970 circuitComponent.calibration = "NoCalibration"
971 circuitComponentDefinition = empro.components.Feed()
972 circuitComponentDefinition.name = port.name
973 circuitComponentDefinition.feedType = "Current"
974 circuitComponentDefinition.amplitudeMultiplier = 1
975 circuitComponentDefinition.impedance.resistance = _haveAtLeastResistance(port.referenceImpedance, 1e-6)
976 circuitComponent.definition = circuitComponentDefinition
977 circuitComponent._termType = empro.components._ettInputOutput
978 circuitComponent._portFeedType = port.feedType
979
980 plusPinNames = [x.name for x in port.plusPins()]
981 minusPinNames = [x.name for x in port.minusPins()]
982
983 minList = []
984 plusList = []
985 for pinName in plusPinNames:
986 plusList.append( empro.components.MultiPinExtentPin(pinName, pinLocations[pinHash[pinName]]) )
987 for pinName in minusPinNames:
988 minList.append( empro.components.MultiPinExtentPin(pinName, pinLocations[pinHash[pinName]]) )
989
990 circuitExtent = empro.components.MultiPinExtent(minList, plusList) if len(minList)>0 else empro.components.MultiPinExtent(plusList)
991 circuitComponent.extent = circuitExtent
992 circuitComponent.useExtent = True
993 circuitComponent.port = True
994 circuitComponent.tail = minList[0].position if len(minList) else plusList[0].position
995 circuitComponent.head = plusList[0].position
996 components.append(circuitComponent)
997
998 for componentGroup in sipiData.getComponentModelGroupList():
999 pinPortMap = componentGroup.pinPortMap()
1000 ignoreNonUsedPorts = True
1001 ports = pinPortMap.getPinNamesForPortNumbers(ignoreNonUsedPorts)
1002 for componentInstance in componentGroup.instances():
1003 component = componentInstance.instance()
1004 for (portNr, (plusPins, minusPins)) in ports:
1005 nextPortInfo = _nextPortInfo();
1006 if nextPortInfo:
1007 circuitComponent = empro.components.CircuitComponent()
1008 circuitComponent.name = _canonicalNameMultiPort(component.name, portNr)
1009 if sipiData.newSimulationData().componentsTreatedAsPorts:
1010 circuitComponent.port = True
1011 circuitComponentDefinition = empro.components.Feed()
1012 circuitComponentDefinition.name = circuitComponent.name
1013 circuitComponentDefinition.impedance.resistance = str(componentInstance.referenceImpedanceFromPins()) + "ohm"
1014 circuitComponentDefinition.feedType = "Voltage"
1015 circuitComponentDefinition.amplitudeMultiplier = 1
1016 circuitComponent.definition = circuitComponentDefinition
1017 circuitComponent._componentPort = True
1018 circuitComponent._deEmbeddingType = componentGroup.deEmbeddingType
1019 else:
1020 circuitComponent.port = False
1021 if len(componentGroup.models()) == 0:
1022 raise RuntimeError("No models are defined")
1023 componentModel = componentGroup.models()[ componentGroup.defaultModelIndex ]
1024 circuitComponentDefinition = componentModel.getPassiveLoad().clone()
1025 circuitComponentDefinition.name = circuitComponent.name
1026 circuitComponent.definition = circuitComponentDefinition
1027
1028 minList = []
1029 plusList = []
1030
1031 for plusPinName in plusPins:
1032 pinName1 = component.name + "." + plusPinName
1033 plusList.append( empro.components.MultiPinExtentPin(pinName1, pinLocations[pinHash[pinName1]]) )
1034 for minusPinName in minusPins:
1035 if minusPinName == empro.geometry.OaLayout.getCoverPinName():
1036 continue
1037 pinName2 = component.name + "." + minusPinName
1038 minList.append( empro.components.MultiPinExtentPin(pinName2, pinLocations[pinHash[pinName2]]) )
1039
1040 circuitExtent = empro.components.MultiPinExtent(minList, plusList) if len(minList)>0 else empro.components.MultiPinExtent(plusList)
1041 circuitComponent.extent = circuitExtent
1042 circuitComponent.useExtent = True
1043
1044 circuitComponent.tail = minList[0].position if len(minList) else plusList[0].position
1045 circuitComponent.head = plusList[0].position
1046
1047 components.append(circuitComponent)
1048
1049
1050 with empro.activeProject as project:
1051 project.circuitComponents().clear()
1052 project.circuitComponents().appendList(components)
1053
1109
1148
1151 import os
1152 import empro
1153
1154 empro.internal.analysis.sipiDataToUseForSimulation = sipiData
1155 pl = empro.activeProject.parameters()
1156 startFreq = pl.formula("minFreq")
1157 endFreq = pl.formula("maxFreq")
1158
1159
1160 sipiData._invokePublishRunBeforeSimulationCreation()
1161
1162 copySimulatorSetupData(sipiData)
1163
1164 simData = empro.activeProject.createSimulationData()
1165 sipiSimData = sipiData.newSimulationData()
1166
1167 simData.componentsTreatedAsPorts = True
1168
1169 bc = empro.activeProject.boundaryConditions()
1170 boundaryType = "Absorbing"
1171 xyBoundaryType = "Absorbing"
1172 bc.xLowerBoundaryType = xyBoundaryType
1173 bc.xUpperBoundaryType = xyBoundaryType
1174 bc.yLowerBoundaryType = xyBoundaryType
1175 bc.yUpperBoundaryType = xyBoundaryType
1176 bc.zLowerBoundaryType = boundaryType
1177 bc.zUpperBoundaryType = boundaryType
1178
1179
1180 simData.femFrequencyPlanList().clear()
1181 for fpi in range(len(sipiSimData.femFrequencyPlanList())):
1182 fp = sipiSimData.femFrequencyPlanList()[fpi]
1183 if not fp.enabled:
1184 continue
1185 if fp.type == "Automatic":
1186 realStartF, stopF = fp.startFrequency, fp.stopFrequency
1187 realStartF = max(realStartF, 20000.0)
1188 startF = max([realStartF, 2.0e6])
1189 highestRecommendedFreqAfs = sipiData._highestAdaptiveFrequencyForSI()
1190 highestRecommendedFreqAfs = int(highestRecommendedFreqAfs/1000.0)*1000.0
1191 newFrequencyPlans = []
1192 if startF<highestRecommendedFreqAfs:
1193
1194 newFp = empro.simulation.FrequencyPlan()
1195 newFp.type = "Adaptive"
1196 newFp.startFrequency = startF
1197 newFp.stopFrequency = min([highestRecommendedFreqAfs,stopF])
1198 newFp.numberOfFrequencyPoints = fp.numberOfFrequencyPoints
1199 newFp.samplePointsLimit = fp.samplePointsLimit
1200 newFp.enabled = fp.enabled
1201 newFrequencyPlans.append(newFp)
1202
1203 if stopF>highestRecommendedFreqAfs:
1204 electricalLength = (sipiData._largestNetLength()*2.0/3e8)*float(stopF)
1205
1206 newFp = empro.simulation.FrequencyPlan()
1207 newFp.type = "Linear"
1208 newFp.startFrequency = max([startF,highestRecommendedFreqAfs])
1209 newFp.stopFrequency = stopF
1210 newFp.numberOfFrequencyPoints = int(10.0*(electricalLength)*((stopF-highestRecommendedFreqAfs)/(1.0+stopF))+1)+1
1211 newFp.enabled = fp.enabled
1212 newFrequencyPlans.append(newFp)
1213
1214 if realStartF<startF:
1215 newFp = empro.simulation.FrequencyPlan()
1216 newFp.type = "Linear"
1217 newFp.startFrequency = realStartF
1218 newFp.stopFrequency = startF
1219 newFp.numberOfFrequencyPoints = 2
1220 newFp.enabled = fp.enabled
1221 newFrequencyPlans.append(newFp)
1222
1223 for fp in newFrequencyPlans:
1224 simData.femFrequencyPlanList().append(fp)
1225
1226 elif fp.type == "SMPS":
1227 newFrequencyPlans = _generateSMPSFreqPlan(fp)
1228 if not newFrequencyPlans:
1229 raise RuntimeError("SMPS frequency plan is invalid")
1230 for fp1 in newFrequencyPlans:
1231 simData.femFrequencyPlanList().append(fp1)
1232
1233 else:
1234 fp = fp.clone()
1235
1236 if fp.type=="Automatic":
1237 raise RuntimeError("Automatic Frequency plans are not supported")
1238 simData.femFrequencyPlanList().append(fp)
1239
1240 import empro.toolkit.analysis as sipi
1241 with empro.activeProject as project:
1242 project.farZoneSensors().clear()
1243 if sipiSimData.farFieldEnabled and simData.saveFieldsFor!="NoFrequencies":
1244 import math
1245 rad = math.pi / 180.0
1246 project.circuitComponentDefinitions().clear()
1247 farzoneSensor = empro.sensor.FarZoneSensor()
1248 farzoneSensor.angle1Start = 0.0
1249 farzoneSensor.angle1Increment = max(0.1, sipiSimData.farFieldAngularResolution * rad)
1250 farzoneSensor.angle1Stop = math.pi
1251 farzoneSensor.angle2Start = 0.0
1252 farzoneSensor.angle2Increment = max(0.1, sipiSimData.farFieldAngularResolution * rad)
1253 farzoneSensor.angle2Stop = math.pi * 2.0
1254 project.farZoneSensors().append(farzoneSensor)
1255
1256 sipi._generateCircuitComponentsForEMExtractionWithTouchingPortsReduction(sipiData)
1257
1258 existingPath = sipiData.simulationPath
1259 if existingPath and os.path.exists(existingPath):
1260 if waitForConfirmation:
1261 import empro.gui
1262 continueSimulating = empro.gui.MessageBox.question("Existing Results Found", "Previous simulation results exist and will be overwritten.\nWould you still like to continue?", 16384 + 65536, 16384) == 16384
1263 if not continueSimulating:
1264 return
1265
1266 import pyfemPlugin as pyfemPost
1267 pyfemPost.removeOptionManager(os.path.join(existingPath,"emds_dsn","design"))
1268 optionsXml = os.path.join(existingPath,"emds_dsn","design","options.xml")
1269 if os.path.exists(long_path_util.resolveLongPath(optionsXml)):
1270 os.remove(long_path_util.resolveLongPath(optionsXml))
1271
1272 _removeSimulationForSetup(sipiData)
1273 sim = empro.activeProject.createSimulationEx(True, False, existingPath)
1274 else:
1275 sim = empro.activeProject.createSimulationEx(True, False, "")
1276 sipiData.simulationPath = sim.simulationPath()
1277
1278
1279 sipiData._invokePublishRunAfterSimulationCreation(sim)
1280
1281
1282 if saveProject:
1283 empro.activeProject.saveActiveProject()
1284 elif hasattr(empro.gui, "activeProjectView"):
1285 empro.gui._projectUpdatedNoUndo()
1286
1287
1288 ctiDir = sipiData.simulationPath
1289 try:
1290 ctiDir = os.path.join(sipiData.simulationPath, "emds_dsn", "design")
1291 if not os.path.exists(ctiDir):
1292 os.makedirs(ctiDir)
1293 except EnvironmentError as error:
1294 ctiDirTmp = os.path.join(existingPath,"emds_dsn","design")
1295 if not os.path.exists(ctiDirTmp):
1296 ctiDir = sipiData.simulationPath
1297
1298 try:
1299 import os
1300 os.remove(os.path.join(sipiData.simulationPath,"emds_dsn","design",".next_solver_id"))
1301 except OSError:
1302 pass
1303
1304 sipiData._saveComponentHashes()
1305
1306
1307 portList = []
1308 index = 0
1309 circuitComponents = empro.activeProject.circuitComponents()
1310 for ci in range(len(circuitComponents)):
1311
1312 circComp = circuitComponents[ci]
1313 portList.append((circComp.name, circComp._termType, index))
1314 index = index+1
1315 with open(os.path.join(ctiDir, "ports.txt"), "w") as portsFile:
1316 for port in portList:
1317 portsFile.write("%s,%d,%d\n" % (port[0], port[1], port[2]))
1318
1319 if hasattr(empro.gui, "activeProjectView"):
1320 pv = empro.gui.activeProjectView()
1321 pv.showSimulationQueueView()
1322
1325 import os
1326 import empro
1327
1328 empro.internal.analysis.sipiDataToUseForSimulation = sipiData
1329 if hasattr(empro.gui, "activeProjectView"):
1330 pv = empro.gui.activeProjectView()
1331 pv.showSimulationQueueView()
1332
1333
1334 sipiData._invokePublishRunBeforeSimulationCreation()
1335
1336 copyCommonSimulationData(sipiData)
1337 simData = empro.activeProject.createSimulationData()
1338
1339 simData.engine = "VemEngine"
1340 existingPath = sipiData.simulationPath
1341
1342 import pyfemPlugin as pyfemPost
1343 pyfemPost.removeOptionManager(existingPath)
1344 optionsXml = os.path.join(existingPath,"options.xml")
1345 if os.path.exists(long_path_util.resolveLongPath(optionsXml)):
1346 os.remove(long_path_util.resolveLongPath(optionsXml))
1347 solverOptionsFile = os.path.join(existingPath,"design.opt")
1348 if os.path.exists(long_path_util.resolveLongPath(solverOptionsFile)):
1349 os.remove(long_path_util.resolveLongPath(solverOptionsFile))
1350
1351 if existingPath and os.path.exists(long_path_util.resolveLongPath(existingPath)):
1352 if waitForConfirmation:
1353 import empro.gui
1354 continueSimulating = empro.gui.MessageBox.question("Existing Results Found", "Previous simulation results exist and will be overwritten.\nWould you still like to continue?", 16384 + 65536, 16384) == 16384
1355 if not continueSimulating:
1356 return
1357
1358 _removeSimulationForSetup(sipiData)
1359 sim = empro.activeProject.createSimulationEx(False, False, existingPath)
1360 else:
1361 sim = empro.activeProject.createSimulationEx(False, False, "")
1362 sipiData.simulationPath = sim.simulationPath()
1363
1364
1365 sipiData._invokePublishRunAfterSimulationCreation(sim)
1366
1367
1368 if saveProject:
1369 empro.activeProject.saveActiveProject()
1370 elif hasattr(empro.gui, "activeProjectView"):
1371 empro.gui._projectUpdatedNoUndo()
1372
1373
1374 solverOptions = "\nOptFile 1.0"
1375 solverType = {"Auto":0, "Direct":1, "Iterative":2}.get(simData.vemMatrixSolver.solveMatrixType, 0)
1376 solverOptions += "\nElectric.solver: %d" % solverType
1377 solverOptions += "\nThermal.solver: %d" % solverType
1378 with open(long_path_util.resolveLongPath(os.path.join(sipiData.simulationPath,"design.opt")),"w") as optionsFile:
1379 optionsFile.write(solverOptions)
1380
1381
1382 import math
1383 resolution = float(simData.femMeshSettings.resolution)
1384 useResolution = simData.femMeshSettings.useResolution
1385 edgeMaxAngle = float(simData.femMeshSettings.arcResolution)*180.0/math.pi
1386 useTargetMesh = str(simData.femMeshSettings.useTargetMeshSize)
1387 targetMeshSize = float(simData.femMeshSettings.targetMeshSize)
1388 numberOfThreads = simData.resourceSettings.numberOfThreads
1389
1390 engine = "VemEngine"
1391 if sipiData.analysisType in [THERMAL, ELECTRO_THERMAL]:
1392 engine = "VemEngineThermal"
1393 if sipiData.analysisType in [ELECTRO_THERMAL]:
1394 engine = "VemEngineElectroThermal"
1395
1396 optionsText = r"""<!DOCTYPE OptionsFile>
1397 <OptionFile version="1" creator="sipro">
1398 <mesh>
1399 <option>
1400 <name>resolution</name>
1401 <initialValue>1e-6</initialValue>
1402 <value>%(resolution)15.15f</value>
1403 </option>
1404 <option>
1405 <name>useResolution</name>
1406 <initialValue>0</initialValue>
1407 <value>%(useResolution)d</value>
1408 </option>
1409 <option>
1410 <name>edgeMaxAngle</name>
1411 <initialValue>60</initialValue>
1412 <value>%(edgeMaxAngle)f</value>
1413 </option>
1414 <option>
1415 <name>useTargetMeshSize</name>
1416 <initialValue>False</initialValue>
1417 <value>%(useTargetMesh)s</value>
1418 </option>
1419 <option>
1420 <name>targetMeshSize</name>
1421 <initialValue>100 um</initialValue>
1422 <value>%(targetMeshSize)f</value>
1423 </option>
1424 </mesh>
1425 <general>
1426 <option>
1427 <name>engine</name>
1428 <initialValue>FemEngine</initialValue>
1429 <value>%(engine)s</value>
1430 </option>
1431 <option>
1432 <name>NB_THREADS</name>
1433 <initialValue>0</initialValue>
1434 <value>%(numberOfThreads)d</value>
1435 </option>
1436 </general>
1437 </OptionFile>""" % vars()
1438 with open(long_path_util.resolveLongPath(os.path.join(sipiData.simulationPath,"options.xml")),"w") as optionsFile:
1439 optionsFile.write(optionsText)
1440
1441 simLength = len(empro.activeProject.simulations())
1442 for simNr in range(simLength):
1443 simFromList = empro.activeProject.simulations()[simLength-simNr-1]
1444 if simFromList.simulationPath()==sim.simulationPath():
1445 simFromList.setQueued(True)
1446 break
1447 sipiData._saveComponentHashes()
1448
1451 import os
1452 import empro
1453
1454 empro.internal.analysis.sipiDataToUseForSimulation = sipiData
1455 pl = empro.activeProject.parameters()
1456 startFreq = pl.formula("minFreq")
1457 endFreq = pl.formula("maxFreq")
1458
1459 copyCommonSimulationData(sipiData)
1460
1461
1462 sipiData._invokePublishRunBeforeSimulationCreation()
1463
1464 simData = empro.activeProject.createSimulationData()
1465 sipiSimData = sipiData.newSimulationData()
1466
1467 simData.componentsTreatedAsPorts = True
1468
1469 bc = empro.activeProject.boundaryConditions()
1470 boundaryType = "Absorbing"
1471 xyBoundaryType = "Absorbing"
1472 bc.xLowerBoundaryType = xyBoundaryType
1473 bc.xUpperBoundaryType = xyBoundaryType
1474 bc.yLowerBoundaryType = xyBoundaryType
1475 bc.yUpperBoundaryType = xyBoundaryType
1476 bc.zLowerBoundaryType = boundaryType
1477 bc.zUpperBoundaryType = boundaryType
1478
1479
1480 simData.femFrequencyPlanList().clear()
1481 for fpi in range(len(sipiSimData.femFrequencyPlanList())):
1482 fp = sipiSimData.femFrequencyPlanList()[fpi]
1483 if not fp.enabled:
1484 continue
1485 if fp.type == "Automatic":
1486 realStartF, stopF = fp.startFrequency, fp.stopFrequency
1487 realStartF = max(realStartF, 20000.0)
1488 startF = max([realStartF, 2.0e6])
1489 highestRecommendedFreqAfs = sipiData._highestAdaptiveFrequencyForSI()
1490 highestRecommendedFreqAfs = int(highestRecommendedFreqAfs/1000.0)*1000.0
1491 newFrequencyPlans = []
1492 if startF<highestRecommendedFreqAfs:
1493
1494 newFp = empro.simulation.FrequencyPlan()
1495 newFp.type = "Adaptive"
1496 newFp.startFrequency = startF
1497 newFp.stopFrequency = min([highestRecommendedFreqAfs,stopF])
1498 newFp.numberOfFrequencyPoints = fp.numberOfFrequencyPoints
1499 newFp.samplePointsLimit = fp.samplePointsLimit
1500 newFp.enabled = fp.enabled
1501 newFrequencyPlans.append(newFp)
1502
1503 if stopF>highestRecommendedFreqAfs:
1504 electricalLength = (sipiData._largestNetLength()*2.0/3e8)*float(stopF)
1505
1506 newFp = empro.simulation.FrequencyPlan()
1507 newFp.type = "Linear"
1508 newFp.startFrequency = max([startF,highestRecommendedFreqAfs])
1509 newFp.stopFrequency = stopF
1510 newFp.numberOfFrequencyPoints = int(10.0*(electricalLength)*((stopF-highestRecommendedFreqAfs)/(1.0+stopF))+1)+1
1511 newFp.enabled = fp.enabled
1512 newFrequencyPlans.append(newFp)
1513
1514 if realStartF<startF:
1515 newFp = empro.simulation.FrequencyPlan()
1516 newFp.type = "Linear"
1517 newFp.startFrequency = realStartF
1518 newFp.stopFrequency = startF
1519 newFp.numberOfFrequencyPoints = 2
1520 newFp.enabled = fp.enabled
1521 newFrequencyPlans.append(newFp)
1522
1523 for fp in newFrequencyPlans:
1524 simData.femFrequencyPlanList().append(fp)
1525 else:
1526 fp = fp.clone()
1527
1528 if fp.type=="Automatic":
1529 raise RuntimeError("Automatic Frequency plans are not supported")
1530 simData.femFrequencyPlanList().append(fp)
1531
1532 import empro.toolkit.analysis as sipi
1533 with empro.activeProject as project:
1534 project.circuitComponentDefinitions().clear()
1535
1536 sipi._generateCircuitComponentsForPASI(sipiData)
1537
1538 existingPath = sipiData.simulationPath
1539 if existingPath and os.path.exists(existingPath):
1540 if waitForConfirmation:
1541 import empro.gui
1542 continueSimulating = empro.gui.MessageBox.question("Existing Results Found", "Previous simulation results exist and will be overwritten.\nWould you still like to continue?", 16384 + 65536, 16384) == 16384
1543 if not continueSimulating:
1544 return
1545
1546 _removeSimulationForSetup(sipiData)
1547 sim = empro.activeProject.createSimulationEx(True, False, existingPath)
1548 else:
1549 sim = empro.activeProject.createSimulationEx(True, False, "")
1550 sipiData.simulationPath = sim.simulationPath()
1551
1552 try:
1553 import os
1554 os.remove(os.path.join(existingPath,"emds_dsn","design",".next_solver_id"))
1555 except OSError:
1556 pass
1557
1558
1559 if saveProject:
1560 empro.activeProject.saveActiveProject()
1561 elif hasattr(empro.gui, "activeProjectView"):
1562 empro.gui._projectUpdatedNoUndo()
1563
1564
1565 ctiDir = sipiData.simulationPath
1566 try:
1567 ctiDir = os.path.join(sipiData.simulationPath, "emds_dsn", "design")
1568 if not os.path.exists(long_path_util.resolveLongPath(ctiDir)):
1569 os.makedirs(long_path_util.resolveLongPath(ctiDir))
1570 except EnvironmentError as error:
1571 ctiDirTmp = os.path.join(existingPath,"emds_dsn","design")
1572 if not os.path.exists(long_path_util.resolveLongPath(ctiDirTmp)):
1573 ctiDir = sipiData.simulationPath
1574
1575 sipiData._saveComponentHashes()
1576
1577
1578 with open(long_path_util.resolveLongPath(os.path.join(ctiDir, "ports.txt")), "w") as portsFile:
1579 portList = []
1580 index = 0
1581 circuitComponents = empro.activeProject.circuitComponents()
1582 for ci in range(len(circuitComponents)):
1583
1584 circComp = circuitComponents[ci]
1585 portList.append((circComp.name, circComp._termType, index))
1586 index = index+1
1587 for port in portList:
1588 portsFile.write("%s,%d,%d\n" % (port[0], port[1], port[2]))
1589
1590 ioPortList = sipiData.getPortList()
1591 _writePortPinInformation(ioPortList, ctiDir)
1592
1593
1594 sipiData._invokePublishRunAfterSimulationCreation(sim)
1595
1596 if hasattr(empro.gui, "activeProjectView"):
1597 pv = empro.gui.activeProjectView()
1598 pv.showSimulationQueueView()
1599
1626
1629 import os
1630 import empro
1631
1632 empro.internal.analysis.sipiDataToUseForSimulation = sipiData
1633 pl = empro.activeProject.parameters()
1634 startFreq = pl.formula("minFreq")
1635 endFreq = pl.formula("maxFreq")
1636
1637
1638 sipiData._invokePublishRunBeforeSimulationCreation()
1639
1640 copyCommonSimulationData(sipiData)
1641
1642 simData = empro.activeProject.createSimulationData()
1643 sipiSimData = sipiData.newSimulationData()
1644
1645 simData.componentsTreatedAsPorts = True
1646
1647 bc = empro.activeProject.boundaryConditions()
1648 boundaryType = "PMC"
1649 xyBoundaryType = "Absorbing"
1650 bc.xLowerBoundaryType = xyBoundaryType
1651 bc.xUpperBoundaryType = xyBoundaryType
1652 bc.yLowerBoundaryType = xyBoundaryType
1653 bc.yUpperBoundaryType = xyBoundaryType
1654 bc.zLowerBoundaryType = boundaryType
1655 bc.zUpperBoundaryType = boundaryType
1656
1657
1658 newSimData = empro.activeProject.createSimulationData()
1659
1660
1661 simData.femFrequencyPlanList().clear()
1662
1663 for fpi in range(len(sipiSimData.femFrequencyPlanList())):
1664 fp = sipiSimData.femFrequencyPlanList()[fpi]
1665 if not fp.enabled:
1666 continue
1667 if fp.type == "Automatic":
1668 startF, stopF = fp.startFrequency, fp.stopFrequency
1669 highestRecommendedFreqAfs = sipiData._highestAdaptiveFrequencyForAC()
1670 highestRecommendedFreqAfs = int(highestRecommendedFreqAfs/1000.0)*1000.0
1671 newFrequencyPlans = []
1672 if startF<highestRecommendedFreqAfs:
1673
1674 newFp = empro.simulation.FrequencyPlan()
1675 newFp.type = "Adaptive"
1676 newFp.startFrequency = startF
1677 newFp.stopFrequency = min([highestRecommendedFreqAfs,stopF])
1678 newFp.numberOfFrequencyPoints = fp.numberOfFrequencyPoints
1679 newFp.samplePointsLimit = fp.samplePointsLimit
1680 newFrequencyPlans.append(newFp)
1681
1682 newFp = empro.simulation.FrequencyPlan()
1683 newFp.type = "Logarithmic"
1684 newFp.startFrequency = startF
1685 newFp.stopFrequency = min([highestRecommendedFreqAfs,stopF])
1686 newFp.pointsPerDecade = 3
1687 newFrequencyPlans.append(newFp)
1688
1689 if stopF>highestRecommendedFreqAfs:
1690 electricalLength = (sipiData._largestNetLength()*2.0/3e8)*float(stopF)
1691 newFp = empro.simulation.FrequencyPlan()
1692 newFp.type = "Logarithmic"
1693 newFp.startFrequency = max([startF,highestRecommendedFreqAfs])
1694 newFp.stopFrequency = stopF
1695 newFp.pointsPerDecade = 5
1696 newFrequencyPlans.append(newFp)
1697
1698 for fp in newFrequencyPlans:
1699 simData.femFrequencyPlanList().append(fp)
1700 else:
1701 fp = fp.clone()
1702
1703 if fp.type=="Automatic":
1704 raise RuntimeError("Automatic Frequency plans are not supported")
1705 simData.femFrequencyPlanList().append(fp)
1706
1707 import empro.toolkit.analysis as sipi
1708 with empro.activeProject as project:
1709 project.circuitComponentDefinitions().clear()
1710 sipi._generateCircuitComponentsForAC(sipiData)
1711 existingPath = sipiData.simulationPath
1712 if existingPath and os.path.exists(existingPath):
1713 if waitForConfirmation:
1714 import empro.gui
1715 continueSimulating = empro.gui.MessageBox.question("Existing Results Found", "Previous simulation results exist and will be overwritten.\nWould you still like to continue?", 16384 + 65536, 16384) == 16384
1716 if not continueSimulating:
1717 return
1718
1719 import pyfemPlugin as pyfemPost
1720 pyfemPost.removeOptionManager(os.path.join(existingPath,"emds_dsn","design"))
1721 optionsXml = os.path.join(existingPath,"emds_dsn","design","options.xml")
1722 if os.path.exists(long_path_util.resolveLongPath(optionsXml)):
1723 os.remove(long_path_util.resolveLongPath(optionsXml))
1724
1725 _removeSimulationForSetup(sipiData)
1726 sim = empro.activeProject.createSimulationEx(True, False, existingPath)
1727 else:
1728 sim = empro.activeProject.createSimulationEx(True, False, "")
1729 sipiData.simulationPath = sim.simulationPath()
1730
1731 try:
1732 import os
1733 os.remove(long_path_util.resolveLongPath(os.path.join(existingPath,"emds_dsn","design",".next_solver_id")))
1734 except OSError:
1735 pass
1736
1737
1738 if saveProject:
1739 empro.activeProject.saveActiveProject()
1740 elif hasattr(empro.gui, "activeProjectView"):
1741 empro.gui._projectUpdatedNoUndo()
1742
1743
1744 sipiData._saveComponentHashes()
1745 writePortsFile(sipiData)
1746
1747
1748 sipiData._invokePublishRunAfterSimulationCreation(sim)
1749
1750
1751 if hasattr(empro.gui, "activeProjectView"):
1752 pv = empro.gui.activeProjectView()
1753 pv.showSimulationQueueView()
1754
1757 import empro
1758 import os
1759
1760
1761 ctiDir = sipiData.simulationPath
1762 try:
1763 ctiDir = os.path.join(sipiData.simulationPath, "emds_dsn", "design")
1764 if not os.path.exists(long_path_util.resolveLongPath(ctiDir)):
1765 os.makedirs(long_path_util.resolveLongPath(ctiDir))
1766 except EnvironmentError as error:
1767 existingPath = sipiData.simulationPath
1768 ctiDirTmp = os.path.join(existingPath,"emds_dsn","design")
1769 if not os.path.exists(ctiDirTmp):
1770 ctiDir = sipiData.simulationPath
1771
1772
1773 vrmNameToVrm = {}
1774 for vrm in sipiData.getVrmList():
1775 vrmNameToVrm[vrm.name] = vrm
1776
1777
1778 sinkNameToSink = {}
1779 for sink in sipiData.getSinkList():
1780 sinkNameToSink[sink.name] = sink
1781
1782
1783 cmptNameToImp = {}
1784 cmptNameToModelType = {}
1785 for componentModelGroup in sipiData.getComponentModelGroupList():
1786 selectedModel = componentModelGroup.models()[componentModelGroup.defaultModelIndex]
1787 impedanceSpec = selectedModel.getPassiveLoad().impedance
1788 modelType = selectedModel.modelType
1789 for componentInstance in componentModelGroup.instances():
1790 component = componentInstance.instance()
1791 if len(component.pins())<=2:
1792 cmptNameToImp[componentInstance.name] = impedanceSpec
1793 cmptNameToModelType[componentInstance.name] = modelType
1794 else:
1795 portMap = componentModelGroup.pinPortMap()
1796 for portNr, minPlusPins in portMap.getPinNamesForPortNumbers(True):
1797 cmptNameToImp[_canonicalNameMultiPort(componentInstance.name,portNr)] = impedanceSpec
1798 cmptNameToModelType[_canonicalNameMultiPort(componentInstance.name,portNr)] = modelType
1799
1800
1801
1802 portList = []
1803 index = 0
1804 circuitComponents = empro.activeProject.circuitComponents()
1805
1806 if sipiData.analysisType!=3:
1807
1808
1809 for ci in range(len(circuitComponents)):
1810
1811 circComp = circuitComponents[ci]
1812
1813 if circComp._termType == 0:
1814 vrm = vrmNameToVrm[circComp.name]
1815 portList.append((circComp.name, circComp._termType, index, float(vrm.resistance), float(vrm.inductance), 0, "Series"))
1816
1817 elif circComp._termType == 1:
1818 sink = sinkNameToSink[circComp.name]
1819 portList.append((circComp.name, circComp._termType, index, float(sink.resistance), 0, 0, "Series"))
1820
1821 elif circComp._termType == 5:
1822 cmptImpSpec = cmptNameToImp[circComp.name]
1823 modelType = cmptNameToModelType[circComp.name]
1824 if modelType==1:
1825
1826 resistance = float(cmptImpSpec.resistance)
1827 inductance = float(cmptImpSpec.inductance)
1828 capacitance = float(cmptImpSpec.capacitance)
1829 portList.append((circComp.name, circComp._termType, index, resistance, inductance, capacitance, cmptImpSpec.elementArrangement))
1830 index = index+1
1831
1832
1833 with open(long_path_util.resolveLongPath(os.path.join(ctiDir, "ports.txt")), "w") as portsFile:
1834 fieldHeaders = ["Name","Type","PortNbr","R","L","C","ElementArrangement"]
1835 portsFile.write("%s\n" % (','.join(str(fieldHeader) for fieldHeader in fieldHeaders)))
1836 for port in portList:
1837 line = ','.join(str(field) for field in port)
1838 portsFile.write("%s\n" % line)
1839
1841 import os
1842 import empro
1843
1844 empro.internal.analysis.sipiDataToUseForSimulation = sipiData
1845 existingPath = sipiData.simulationPath
1846 if existingPath and os.path.exists(existingPath):
1847 if waitForConfirmation:
1848 import empro.gui
1849 continueSimulating = empro.gui.MessageBox.question("Existing Results Found", "Previous simulation results exist and will be overwritten.\nWould you still like to continue?", 16384 + 65536, 16384) == 16384
1850 if not continueSimulating:
1851 return
1852
1853 pl = empro.activeProject.parameters()
1854 startFreq = pl.formula("minFreq")
1855 endFreq = pl.formula("maxFreq")
1856
1857
1858 sipiData._invokePublishRunBeforeSimulationCreation()
1859
1860 copyCommonSimulationData(sipiData)
1861
1862 sipiSimData = sipiData.newSimulationData()
1863 simData = empro.activeProject.createSimulationData()
1864
1865 simData.componentsTreatedAsPorts = False
1866
1867 bc = empro.activeProject.boundaryConditions()
1868 boundaryType = "Absorbing"
1869 xyBoundaryType = "Absorbing"
1870 bc.xLowerBoundaryType = xyBoundaryType
1871 bc.xUpperBoundaryType = xyBoundaryType
1872 bc.yLowerBoundaryType = xyBoundaryType
1873 bc.yUpperBoundaryType = xyBoundaryType
1874 bc.zLowerBoundaryType = boundaryType
1875 bc.zUpperBoundaryType = boundaryType
1876
1877
1878 simData.femFrequencyPlanList().clear()
1879 for fpi in range(len(sipiSimData.femFrequencyPlanList())):
1880 fp = sipiSimData.femFrequencyPlanList()[fpi]
1881 if not fp.enabled:
1882 continue
1883 fp = fp.clone()
1884 if float(fp.startFrequency)<_minimumPPRFrequency:
1885 fp.startFrequency = "%f" % _minimumPPRFrequency
1886 if fp.type=="Automatic":
1887 raise RuntimeError("Automatic Frequency plans are not supported")
1888 simData.femFrequencyPlanList().append(fp)
1889
1890 lowFreqLimit = sipiSimData.femEigenSolverSettings.lowFreqLimit
1891 simData.femEigenSolverSettings.lowFreqLimit = lowFreqLimit
1892 if lowFreqLimit<_minimumPPRFrequency:
1893 simData.femEigenSolverSettings.lowFreqLimit = _minimumPPRFrequency
1894 simData.femEigenSolverSettings.nbEigenFreq = sipiSimData.femEigenSolverSettings.nbEigenFreq
1895 simData.femEigenSolverSettings.highFreqLimit = sipiSimData.femEigenSolverSettings.highFreqLimit
1896 simData.femEigenSolverSettings.iterationTolerance = sipiSimData.femEigenSolverSettings.iterationTolerance
1897
1898 import empro.toolkit.analysis as sipi
1899 sipi._generateCircuitComponentsForAC(sipiData)
1900
1901 existingPath = sipiData.simulationPath
1902 if existingPath and os.path.exists(existingPath):
1903 import pyfemPlugin as pyfemPost
1904 pyfemPost.removeOptionManager(os.path.join(existingPath,"emds_dsn","design"))
1905 optionsXml = os.path.join(existingPath,"emds_dsn","design","options.xml")
1906 if os.path.exists(long_path_util.resolveLongPath(optionsXml)):
1907 os.remove(long_path_util.resolveLongPath(optionsXml))
1908 projectLog = os.path.join(existingPath,"project.log")
1909 if os.path.exists(long_path_util.resolveLongPath(projectLog)):
1910 os.remove(long_path_util.resolveLongPath(projectLog))
1911
1912 _removeSimulationForSetup(sipiData)
1913 sim = empro.activeProject.createSimulationEx(True, False, existingPath)
1914 else:
1915 sim = empro.activeProject.createSimulationEx(True, False, "")
1916 sipiData.simulationPath = sim.simulationPath()
1917
1918 try:
1919 import os
1920 os.remove(os.path.join(existingPath,"emds_dsn","design",".next_solver_id"))
1921 except OSError:
1922 pass
1923
1924
1925 sipiData._invokePublishRunAfterSimulationCreation(sim)
1926
1927
1928 if saveProject:
1929 empro.activeProject.saveActiveProject()
1930 elif hasattr(empro.gui, "activeProjectView"):
1931 empro.gui._projectUpdatedNoUndo()
1932
1933 sipiData._saveComponentHashes()
1934
1935 if hasattr(empro.gui, "activeProjectView"):
1936 pv = empro.gui.activeProjectView()
1937 pv.showSimulationQueueView()
1938
1939 import xml.sax
1940 -class NameIdContentHandler(xml.sax.ContentHandler):
1941 - def __init__(self):
1942 xml.sax.ContentHandler.__init__(self)
1943 self.lastName = None
1944 self.lastId = None
1945 self.mapping = {}
1946
1947 - def endElement(self, name):
1948 if name == "OALayoutOverview":
1949 return False
1950 if name == "id":
1951 self.lastId = int(self.content)
1952 if name == "name":
1953 self.lastName = self.content
1954 if self.lastId!=None:
1955 self.mapping[self.lastId]=self.lastName
1956 self.lastId = None
1957
1958 - def characters(self, content):
1959 self.content = content
1960
1964
1965 @_printexception
1966 -def _filterData(sipiData,pathSuffix=""):
1988
1989
1990 @_printexception
1991 -def generateTestBench(sipiData, overwrite=0, noErrorMessageBox=False):
2007
2008 @_printexception
2009 -def generateSubCircuit(sipiData, overwrite=0, noErrorMessageBox=False, whereToSave=1):
2010 try:
2011 import empro.toolkit.analysis.schematic_generation as schematic_generation
2012 import os
2013 workingDirectory = os.getcwd()
2014 oaLayout = empro.activeProject.geometry()[0]
2015 libName = oaLayout._designRef.lib
2016 cellName = oaLayout._designRef.cell
2017 lcvName = schematic_generation.generateSchematic(workingDirectory, sipiData, libName, cellName, schematicType=2, overwrite=overwrite, noErrorMessageBox=noErrorMessageBox, whereToSave=whereToSave)
2018 return lcvName
2019 except:
2020 if noErrorMessageBox:
2021 raise
2022 import sys
2023 msg = str(sys.exc_info()[1])
2024 empro.gui.MessageBox.critical("Failed to generate sub circuit", "Failed to generate sub circuit.\nReason:\n" + msg,0,0)
2025
2026 @_printexception
2027 -def simulateTestBench(lcvName, overwrite=0, closeDesign = 0, noErrorMessageBox=False):
2038
2041 import empro.toolkit.analysis.schematic_generation as schematic_generation
2042
2043 AnalysisName = sipiData.name
2044 AnalysisName = schematic_generation._fixSetupName(AnalysisName)
2045 oaLayout = empro.activeProject.geometry()[0]
2046 libName = oaLayout._designRef.lib
2047 cellName = oaLayout._designRef.cell
2048 lcvName = None
2049
2050
2051
2052 try:
2053 lcvName = generateSubCircuit(sipiData, 1, noErrorMessageBox, 2)
2054 except:
2055 return
2056 finally:
2057
2058
2059 empro.toolkit.rpc.callAEL('deempe_close_subcircuit_if_opened', [AnalysisName, libName, cellName])
2060
2061
2062
2063 if lcvName is None:
2064 return
2065
2066 try:
2067 lcvName = schematic_generation.generateVoltageSpikesTestbench(sipiData, libName, cellName, overwrite, noErrorMessageBox)
2068 return lcvName
2069 except:
2070 if noErrorMessageBox:
2071 raise
2072 import sys
2073 msg = str(sys.exc_info()[1])
2074 empro.gui.MessageBox.critical("Failed to generate testbench for voltage spikes", "Failed to generate testbench for voltage spikes.\nReason: " + msg,0,0)
2075
2076 @_printexception
2077 -def generateConductedEmiTB(sipiData, overwrite=0, noErrorMessageBox=False, whereToSave=1):
2078 import empro.toolkit.analysis.schematic_generation as schematic_generation
2079
2080 AnalysisName = sipiData.name
2081 AnalysisName = schematic_generation._fixSetupName(AnalysisName)
2082 oaLayout = empro.activeProject.geometry()[0]
2083 libName = oaLayout._designRef.lib
2084 cellName = oaLayout._designRef.cell
2085 lcvName = None
2086
2087
2088
2089 try:
2090 lcvName = generateSubCircuit(sipiData, 1, noErrorMessageBox, 2)
2091 except:
2092 return
2093 finally:
2094
2095
2096 empro.toolkit.rpc.callAEL('deempe_close_subcircuit_if_opened', [AnalysisName, libName, cellName])
2097
2098
2099
2100 if lcvName is None:
2101 return
2102
2103 try:
2104 lcvName = schematic_generation.generateConductedEmiTestbench(sipiData, libName, cellName, overwrite, noErrorMessageBox)
2105 return lcvName
2106 except:
2107 if noErrorMessageBox:
2108 raise
2109 import sys
2110 msg = str(sys.exc_info()[1])
2111 empro.gui.MessageBox.critical("Failed to generate testbench for Conducted EMI", "Failed to generate testbench for Conducted EMI.\nReason: " + msg,0,0)
2112
2128
2147
2150 resultFilter = []
2151 filterData = _filterData(sipiData)
2152 filterData[-1] = "Not Set"
2153 resultFilter.append((("Layer","LayerId"),filterData))
2154 resultFilter.append((("Net Type","NetId"), {4:"Signal", 1:"Power", 2:"Ground"}))
2155 return resultFilter
2156
2160 resultFilter = []
2161 filterData = _filterData(sipiData)
2162 filterData[-1] = "Not Set"
2163 resultFilter.append((("Layer","LayerIdExt"),filterData))
2164 resultFilter.append((("Net Type","NetId"), {-1: "Not Available", 0 : "Not Set", 4:"Signal", 1:"Power", 2:"Ground"}))
2165 return resultFilter
2166
2170 try:
2171 sipiData = result.getData()
2172 import os
2173 if sipiData.simulationPath=="" or not os.path.exists(sipiData.simulationPath):
2174 raise NoSimulationAvailable(sipiData.name)
2175 import empro
2176 gv = empro.gui.activeProjectView()
2177 gv.showGeometryView()
2178 gv = gv.geometryView()
2179 gv.displayResult(result, "[" + sipiData.name + "]: Voltage", getDCResultFilter(sipiData))
2180 except NoSimulationAvailable:
2181 import empro
2182 empro.gui.MessageBox.warning("Failed to Display Fields", "No simulation available for <%s>" %sipiData.name,0,0)
2183 except:
2184 import sys
2185 import traceback
2186 msg = str(sys.exc_info()[1])
2187 empro.gui.MessageBox.critical("Failed to Display Voltage", "Failed to Display Voltage.\nReason:\n" + msg,0,0)
2188
2192 try:
2193 sipiData = result.getData()
2194 import os
2195 if sipiData.simulationPath=="" or not os.path.exists(sipiData.simulationPath):
2196 raise NoSimulationAvailable(sipiData.name)
2197 import empro
2198 gv = empro.gui.activeProjectView()
2199 gv.showGeometryView()
2200 gv = gv.geometryView()
2201 resultFilter = getTemperatureResultFilter(sipiData)
2202 gv.displayResult(result, "[" + sipiData.name + "]: Temperature", resultFilter)
2203 except NoSimulationAvailable:
2204 import empro
2205 empro.gui.MessageBox.warning("Failed to Display Fields", "No simulation available for <%s>" %sipiData.name,0,0)
2206 except:
2207 import sys
2208 import traceback
2209 msg = str(sys.exc_info()[1])
2210 empro.gui.MessageBox.critical("Failed to Display Temperature", "Failed to Display Temperature.\nReason:\n" + msg,0,0)
2211
2215 try:
2216 sipiData = result.getData()
2217 import os
2218 if sipiData.simulationPath=="" or not os.path.exists(sipiData.simulationPath):
2219 raise NoSimulationAvailable(sipiData.name)
2220 import empro
2221 gv = empro.gui.activeProjectView()
2222 gv.showGeometryView()
2223 gv = gv.geometryView()
2224 gv.displayResult(result, "[" + sipiData.name + "]: Power Loss Density", getDCResultFilter(sipiData))
2225 except NoSimulationAvailable:
2226 import empro
2227 empro.gui.MessageBox.warning("Failed to Display Fields", "No simulation available for <%s>" %sipiData.name,0,0)
2228 except:
2229 import sys
2230 import traceback
2231 msg = str(sys.exc_info()[1])
2232 empro.gui.MessageBox.critical("Failed to Display Power Density", "Failed to Display Power Density.\nReason:\n" + msg,0,0)
2233
2237 try:
2238 sipiData = result.getData()
2239 import os
2240 if sipiData.simulationPath=="" or not os.path.exists(sipiData.simulationPath):
2241 raise NoSimulationAvailable(sipiData.name)
2242 import empro
2243 gv = empro.gui.activeProjectView()
2244 gv.showGeometryView()
2245 gv = gv.geometryView()
2246 gv.displayResult(result, "[" + sipiData.name + "]: Current Density", getDCResultFilter(sipiData))
2247 except NoSimulationAvailable:
2248 import empro
2249 empro.gui.MessageBox.warning("Failed to Display Current", "No simulation available for <%s>" %sipiData.name,0,0)
2250 except:
2251 import sys
2252 import traceback
2253 msg = str(sys.exc_info()[1])
2254 empro.gui.MessageBox.critical("Failed to Display Current", "Failed to Display Current.\nReason:\n" + msg,0,0)
2255
2259 vendorPartsDb = empro.VendorPartsDb.instance()
2260 import sqlite3
2261 db = sqlite3.connect(vendorPartsDb.pathToDb)
2262 sqlresult = db.execute( sqlstatement )
2263 fields = [x[0] for x in sqlresult.description]
2264 rows = sqlresult.fetchall()
2265 row = rows[0]
2266 data = dict(zip(fields,row))
2267 db.close()
2268 return data
2269
2274
2283
2292
2301
2339
2341 index = 0
2342 vrmNameToIndex = []
2343 sinkNameToIndex = []
2344 ioPortNameToIndex = []
2345 cmptNameToIndex = []
2346 impedanceSpecsGenerators = []
2347
2348 pinHash = _createPinHash()
2349 pinNetNames = _createPinHashNetName()
2350 def getNetNamesOfComponent(port, pinHash, pinNetNames):
2351 if pinType == "plus":
2352 return list(set([ pinNetNames[ pinHash[x.name] ] for x in port.plusPins()]))
2353 else:
2354 return list(set([ pinNetNames[ pinHash[x.name] ] for x in port.minusPins()]))
2355
2356 def getPinNamesOfComponent(port):
2357 plusPinNames = []
2358 for x in port.plusPins():
2359 plusPinNames.append(x.name)
2360 minusPinNames = []
2361 for x in port.minusPins():
2362 minusPinNames.append(x.name)
2363 return [plusPinNames, minusPinNames]
2364
2365
2366 analysisType = int(sipiSetupData.analysisType)
2367 if analysisType in [sipiSetupData.ACAnalysisType, sipiSetupData.PPRAnalysisType]:
2368 loadVRMs = True
2369 loadSinks = True
2370 loadIoPorts = False
2371 loadComponents = True
2372 elif analysisType == sipiSetupData.PASIAnalysisType:
2373 loadVRMs = False
2374 loadSinks = False
2375 loadIoPorts = True
2376 loadComponents = True
2377 else:
2378 raise RuntimeError("Impedance/Sparameter plots not supported for analysis type %d" % analysisType)
2379
2380
2381 import os
2382 if hasattr(sipiSetupData, "simulationPath"):
2383 pathToSimulate = sipiSetupData.simulationPath
2384 else:
2385 lastSimulation = empro.activeProject.simulations()[-1]
2386 pathToSimulate = lastSimulation.simulationPath()
2387 ctiDir = os.path.join(pathToSimulate, "emds_dsn", "design")
2388 ctiFileLocation = os.path.join(ctiDir, "design_ffs.cti")
2389 if not os.path.exists(ctiFileLocation):
2390 ctiFileLocation = os.path.join(ctiDir, "design.cti")
2391 if not os.path.exists(ctiFileLocation):
2392 ctiFileLocation = os.path.join(ctiDir, "design_dfs.cti")
2393 if not os.path.exists(ctiFileLocation):
2394 msg = "Failed to find results."
2395 empro.gui.MessageBox.critical("Failed to Show Impedance", "Failed to Generate Impedance.\nReason:\n" + msg,0,0)
2396 return
2397
2398
2399 if loadVRMs:
2400 for vrm in sipiSetupData.getVrmList():
2401 netNames = getNetNamesOfComponent(vrm, pinHash, pinNetNames)
2402 vrmNameToIndex.append((vrm.name, (index, netNames) ))
2403 impedanceSpecsGenerators.append( (vrm, _vrmToImpedance) )
2404 index += 1
2405
2406
2407 if loadSinks:
2408 for sink in sipiSetupData.getSinkList():
2409 netNames = getNetNamesOfComponent(sink, pinHash, pinNetNames)
2410 sinkNameToIndex.append((sink.name, (index, netNames) ))
2411 impedanceSpecsGenerators.append( (sink, _sinkToImpedance) )
2412 index += 1
2413
2414
2415 if loadIoPorts:
2416 for ioPort in sipiSetupData.getPortList():
2417 netNames = getNetNamesOfComponent(ioPort, pinHash, pinNetNames)
2418 ioPortNameToIndex.append((ioPort.name, (index, netNames) ))
2419 impedanceSpecsGenerators.append( (ioPort, _ioToImpedance) )
2420 index += 1
2421
2422
2423 if loadComponents:
2424 for componentModelGroup in sipiSetupData.getComponentModelGroupList():
2425 for componentInstance in componentModelGroup.instances():
2426 cmptNameToIndex.append((componentInstance.name, index))
2427 impedanceSpecsGenerators.append( (componentModelGroup, _modelToImpedance) )
2428 index += 1
2429
2430 return impedanceSpecsGenerators, ctiFileLocation, vrmNameToIndex, sinkNameToIndex, ioPortNameToIndex, cmptNameToIndex
2431
2433 diffPairList = []
2434 for diffPair in portList.differentialPairs():
2435 P0 = diffPair[0]
2436 P1 = diffPair[1]
2437 C = "Common(%s,%s)"%(P0,P1)
2438 D = "Diff(%s,%s)"%(P0,P1)
2439 diffPairList.append(((P0,P1),(D,C)))
2440 return diffPairList
2441
2443 dpg = []
2444 dpg.append( (sipiSetupData.getPortList(), _ioPortListToDifferentialPairs) )
2445 return dpg
2446
2449 import empro
2450 for sipiData in sipiDatas:
2451 empro.gui.showImpedanceDialog(sipiData)
2452
2455 import empro
2456 for sipiData in sipiDatas:
2457 empro.gui.showSParameterDialog(sipiData)
2458
2461 import empro, os
2462
2463 def fieldDataAvailable(simDir):
2464 import fnmatch
2465 for root, dirs, files in os.walk(simDir):
2466 for file in fnmatch.filter(files, "*.ffp"):
2467 return True
2468 return False
2469
2470 gv = empro.gui.activeProjectView()
2471 gv.showGeometryView()
2472 gv = gv.geometryView()
2473 if sipiData.newSimulationData().engine=="MomEngine":
2474 if sipiData.newSimulationData().momPhysModel.solveModelType=="RF":
2475 empro.gui.MessageBox.warning("Failed to Display Far Field", "Far Field is not available for Momentum RF",0,0)
2476 return
2477 momDir = os.path.join(sipiData.simulationPath, "work")
2478 if not os.path.exists(momDir):
2479 empro.gui.MessageBox.warning("Failed to Display Far Field", "Simulation results directory does not exist",0,0)
2480 return
2481 msfFile = os.path.join(momDir,"proj.msf")
2482 if not os.path.exists(long_path_util.resolveLongPath(msfFile)):
2483 empro.gui.MessageBox.warning("Failed to Display Far Field", "No Far Field data available",0,0)
2484 return
2485 gv.displayMomFarfield(sipiData.simulationPath, sipiData.newSimulationData().farFieldAngularResolution)
2486 else:
2487
2488 femDir = os.path.join(sipiData.simulationPath, "emds_dsn", "design")
2489 optionsXml = os.path.join(femDir,"options.xml")
2490 if not fieldDataAvailable(femDir) or not os.path.exists(long_path_util.resolveLongPath(optionsXml)) :
2491 empro.gui.MessageBox.warning("Failed to Display Far Field", "No Far Field data available",0,0)
2492 return
2493 gv.displayFarfield(sipiData.simulationPath)
2494
2498 resultFilter = []
2499 fullFilterMap = _filterData(sipiData,"emds_dsn/design")
2500 reducedFilterMap = {}
2501 for k,v in fullFilterMap.iteritems():
2502 if "Dielectric Layer" in v: continue
2503 reducedFilterMap[k] = v
2504 resultFilter.append((("Layer","LayerId"),reducedFilterMap))
2505
2506 return resultFilter
2507
2510 sipiData = result.getData()
2511 import empro, os
2512
2513 def fieldDataAvailable(simDir):
2514 import fnmatch
2515 for root, dirs, files in os.walk(simDir):
2516 for file in fnmatch.filter(files, "*.blg"):
2517 return True
2518 for file in fnmatch.filter(files, "*.blp"):
2519 return True
2520 for file in fnmatch.filter(files, "*solution.bin"):
2521 return True
2522 return False
2523
2524 if empro.activeProject._hasEncryptedData():
2525 empro.gui.MessageBox.warning("Failed to Display Fields", "Field Visualization is not available for encrypted substrates,...",0,0)
2526 return
2527
2528 resultType = result.getType()
2529
2530 gv = empro.gui.activeProjectView()
2531 gv.showGeometryView()
2532 gv = gv.geometryView()
2533 if sipiData.analysisType in [EMFU, EMUD, EMSM, EMFUPE, EMUDPE]:
2534 if resultType == 10:
2535
2536
2537 if sipiData.newSimulationData().engine=="MomEngine":
2538 empro.gui.MessageBox.warning("Failed to Display Fields", "Electric Field is not available for Momentum",0,0)
2539 return
2540 elif sipiData.newSimulationData().saveFieldsFor == "NoFrequencies":
2541 empro.gui.MessageBox.warning("Failed to Display Fields", "Electric Fields were not stored for any frequency",0,0)
2542 return
2543 fieldName = "E"
2544 resultName = "Electric Fields"
2545 elif resultType == 11:
2546 if sipiData.newSimulationData().engine=="MomEngine":
2547 empro.gui.MessageBox.warning("Failed to Display Fields", "Magnetic Field is not available for Momentum",0,0)
2548 return
2549 elif sipiData.newSimulationData().saveFieldsFor == "NoFrequencies":
2550 empro.gui.MessageBox.warning("Failed to Display Fields", "Magnetic Fields were not stored for any frequency",0,0)
2551 return
2552 fieldName = "H"
2553 resultName = "Magnetic Fields"
2554 elif resultType == 12:
2555 if sipiData.newSimulationData().saveFieldsFor == "NoFrequencies":
2556 empro.gui.MessageBox.warning("Failed to Display Current Density", "Current Density was not stored for any frequency",0,0)
2557 return
2558 fieldName = "Jc"
2559 resultName = "Current Density"
2560 else:
2561 raise RuntimeError("unknown field type")
2562 try:
2563 if sipiData.newSimulationData().engine=="MomEngine":
2564 momDir = os.path.join(sipiData.simulationPath, "work")
2565 gv.displayMomField(momDir)
2566 else:
2567 femDir = os.path.join(sipiData.simulationPath, "emds_dsn", "design")
2568 optionsXml = os.path.join(femDir,"options.xml")
2569 if not fieldDataAvailable(femDir) or not os.path.exists(long_path_util.resolveLongPath(optionsXml)) :
2570 empro.gui.MessageBox.warning("Failed to Display " + resultName, "No " + resultName + " data available",0,0)
2571 return
2572 topologyFilter = empro.output.MultiPlaneFilter("multi plane filter")
2573 gv.displayMultiField(femDir, fieldName, topologyFilter)
2574 except:
2575 import traceback
2576 traceback.print_exc()
2577 empro.gui.MessageBox.warning("Failed to Display %s" % fieldName, "Result is not available.\nRun the analysis with field storage enabled to display %s results." % fieldName,0,0)
2578 else:
2579 try:
2580 if resultType == 10: fieldName = "Electric Field"
2581 elif resultType == 11: fieldName = "Magnetic Field"
2582 elif resultType == 12: fieldName = "Current Density"
2583 elif resultType == 18: fieldName = "Nearfield"
2584 else: fieldName = "unknown field type"
2585 acFilter = _getACResultFilter(sipiData)
2586 gv.displayResult(result, "[" + sipiData.name + "]: " + fieldName, acFilter)
2587 except NoSimulationAvailable:
2588 empro.gui.MessageBox.warning("Failed to Display Fields", "No simulation available for <%s>"%sipiData.name,0,0)
2589 except:
2590 import traceback
2591 traceback.print_exc()
2592 empro.gui.MessageBox.warning("Failed to Display Fields", "Fields are not available.\nRun the analysis with field storage enabled to display field results.",0,0)
2593
2594
2595
2596 -def createVrmFromInstance(instanceName, preferredPowerNetNames=None, preferredGroundNetNames=None):
2613
2629
2633
2642
2649
2656
2663
2668
2673
2679
2681 import empro.toolkit.analysis
2682 analysisType = setup.analysisType
2683 if analysisType in [PIDC, THERMAL, ELECTRO_THERMAL]:
2684 empro.toolkit.analysis.runDCSimulationFlow(setup, waitForConfirmation)
2685 elif analysisType==PIAC:
2686 empro.toolkit.analysis.runACSimulationFlow(setup, waitForConfirmation)
2687 elif analysisType==PASI:
2688 empro.toolkit.analysis.runPASISimulationFlow(setup, waitForConfirmation)
2689 elif analysisType==PPR:
2690 empro.toolkit.analysis.runPPRSimulationFlow(setup, waitForConfirmation)
2691 elif analysisType in [EMFU, EMUD, EMFUPE, EMUDPE]:
2692 empro.toolkit.analysis.runEMExtractionSimulationFlow(setup, waitForConfirmation)
2693 else:
2694 raise RuntimeError("Unknown Analysis Type")
2695
2705
2711
2714
2715 - def __init__(self, sipiSetupData, verbose=False):
2716
2717
2718 self.data = sipiSetupData
2719 temp = _getImpedanceSpecGenerators(sipiSetupData)
2720 self.impSpecGenerators = temp[0]
2721 self.ctiFileLocation = temp[1]
2722
2723
2724 import empro.enparams as enparams
2725 self.evaluator = enparams.CitiEvaluator(self.ctiFileLocation, False)
2726 self.Sstored = enparams.VectorOfScatteringMatrices(self.evaluator.nbPorts(),self.evaluator.nbStoredFrequencies())
2727 self.evaluator.loadSampledSparameters(self.Sstored)
2728
2729
2730 self.names = {}
2731 self.activeComponents = []
2732 for name, id in temp[2]:
2733 self.names[id[0]] = name
2734 self.activeComponents.append(id[0])
2735 for name, id in temp[3]:
2736 self.names[id[0]] = name
2737 self.activeComponents.append(id[0])
2738 for name, id in temp[4]:
2739 self.names[id[0]] = name
2740 self.activeComponents.append(id[0])
2741 for name, id in temp[5]:
2742 self.names[id] = name
2743 self.name2id = {}
2744 for k,v in self.names.iteritems():
2745 self.name2id[v] = k
2746
2747 self.Sloaded = None
2748
2749 if verbose:
2750 print "RAW PORTS:"
2751 keys = sorted(self.names.keys())
2752 for key in keys:
2753 print "%3d : %s" % (key, self.names[key])
2754
2756 return self.evaluator.nbPorts()
2757
2759 return len(self.activeComponents)
2760
2762 impSpecs = []
2763 for comp, fun in self.impSpecGenerators:
2764 impSpecs.append(fun(comp))
2765 for i in range(len(impSpecs)):
2766 impSpecs[i].name = self.names[i]
2767 if verbose:
2768 print "IMPEDANCE SPECIFICATIONS:"
2769 cnt = 0
2770 for impSpec in impSpecs:
2771 print "%3d: %s" % (cnt, impSpec.str())
2772 cnt += 1
2773 return impSpecs
2774
2776 result = ""
2777 result += "Result Evaluator for <%s>" % self.data.name
2778 result += "\n\tsimulation directory: %s" % self.data.simulationPath
2779 impSpecs = self.getImpedanceSpecifications()
2780 cnt = 0
2781 for impSpec in impSpecs:
2782 cnt += 1
2783 result += "\n\tcomponent %3d: %s" % (cnt, impSpec.str())
2784 return result
2785
2791
2797
2800 import os
2801 import empro.core
2802
2803 toolDisplayDrf = os.path.join(workingDirectory or os.getcwd(), "_" + empro.core.ApplicationInfo.personality() + "Display.drf")
2804 if os.path.exists(toolDisplayDrf):
2805 empro.liboa.loadDisplayResourceFile(toolDisplayDrf)
2806
2807 if drfPath:
2808 empro.liboa.loadDisplayResourceFile(drfPath)
2809 else:
2810 cdsInstDir = os.getenv("CDS_INST_DIR")
2811 if cdsInstDir:
2812 empro.liboa.loadDisplayResourceFile(os.path.join(cdsInstDir, "share/cdssetup/dfII/default.drf"))
2813 if drfPath:
2814 empro.liboa.loadDisplayResourceFile(drfPath)
2815 cdsSite = os.getenv("CDS_SITE")
2816 if cdsSite:
2817 empro.liboa.loadDisplayResourceFile(os.path.join(cdsSite, "display.drf"))
2818 cdsProject = os.getenv("CDS_PROJECT")
2819 if cdsProject:
2820 empro.liboa.loadDisplayResourceFile(os.path.join(cdsProject, "display.drf"))
2821 empro.liboa.loadDisplayResourceFile(os.path.expanduser("~/display.drf"))
2822 empro.liboa.loadDisplayResourceFile(os.path.join(workingDirectory or os.getcwd(), "display.drf"))
2823
2836
2914
2919