3 self._weighting = weighting
4
5 - def weight(self, excitation, frequency):
7
10
12 assert(self._weighting==other._weighting or self._weighting.keys()==other._weighting.keys())
13 for name, value in self._weighting.iteritems():
14 self._weighting[name] = value + other._weighting[name]
15 return self
16
18 assert(self._weighting==other._weighting or self._weighting.keys()==other._weighting.keys())
19 for name, value in self._weighting.iteritems():
20 self._weighting[name] = value - other._weighting[name]
21 return self
22
24 for name, value in self._weighting.iteritems():
25 self._weighting[name] = scalar * other._weighting[name]
26 return self
27
30 self._weighting = weighting
31 self._results = results
32 import empro, empro.enparams
33 import os
34 import math, cmath
35
36 baseDir = os.path.split(empro.activeProject.simulations()[-1].simulationPath())[0]
37 cbInput = os.path.join(baseDir,"%06d" % int(self._results._sim),"Run0001", "project.input")
38 if not os.path.exists(cbInput):
39 raise RuntimeError("Need %(cbInput)s to extract as-simulated ports" % vars())
40 assert(os.path.exists(cbInput))
41 import empro._calcbridge as calcbridge
42 cb = calcbridge.v6ProjectFile()
43 cb.load(cbInput)
44
45 sioFile = os.path.join(baseDir,"%06d" % int(self._results._sim), "data.000.sio")
46 ctiFile = os.path.join(baseDir,"%06d" % int(self._results._sim), "data.000.cti")
47 sioFile2 = os.path.join(baseDir,"%06d" % int(self._results._sim), "emds_dsn","design","design.sio")
48 ctiFile2 = os.path.join(baseDir,"%06d" % int(self._results._sim), "emds_dsn","design","design.cti")
49
50 simExcitations = empro.enparams.MultiComponentEvaluator()
51 for i in range(cb.numberOfComponents()):
52
53 cc = cb.getComponent(i)
54 a,p = cc.getAmplitude(), cc.getPhase()
55 portName = cc.name()
56 simExcitations.add(portName, complex(a*math.cos(p),a*math.sin(p)), "Voltage", cc.getResistance(),cc.getInductance(),cc.getCapacitance(),"Series")
57
58 if os.path.exists(sioFile):
59
60 self._trafo = empro.enparams.SimulatedCircuitTransformer(sioFile,simExcitations)
61 elif os.path.exists(sioFile2):
62 self._trafo = empro.enparams.SimulatedCircuitTransformer(sioFile2,simExcitations)
63 elif os.path.exists(ctiFile):
64 self._trafo = empro.enparams.SimulatedCircuitTransformer(ctiFile,simExcitations)
65 elif os.path.exists(ctiFile2):
66 self._trafo = empro.enparams.SimulatedCircuitTransformer(ctiFile2,simExcitations)
67 else:
68 raise RuntimeError("Need sio or cti file to compute weights based on port excitations")
69
70
71 self._requestedTransform = empro.enparams.MultiComponentEvaluator()
72 for portName, spec in sorted(self._weighting.iteritems()):
73 self._requestedTransform.add(portName, spec.source, spec.feedType, spec.R, spec.L, spec.C, spec.arrangement)
74
75 - def weight(self, excitation, frequency):
78
82
83
85 - def __init__(self, results, excitation, frequencies=None, coherent=True):
86 self._excitation = excitation
87 self._frequencies = frequencies
88 self._coherent = coherent
89 self._results = results
90 self._availableExcitationsToRun = None
91 self._excitationWeights = self._transformExcitation(self._excitation)
92
114
116 assert(type(other) == type(self))
117 assert(self._frequencies==other._frequencies)
118 assert(self._coherent==other._coherent)
119 self._excitationWeights += other._excitationWeights
120 return self
121
123 if other is 0:
124 return self
125 return other.__add__(self)
126
128 assert(type(other) == type(self))
129 assert(self._frequencies==other._frequencies)
130 assert(self._excitationWeights==other._excitationWeights or self._excitationWeights.keys()==other._excitationWeights.keys())
131 self._excitationWeights -= other._excitationWeights
132 return self
133
135 self._excitationWeights *= scalar
136 return self
137
139 self._excitationWeights *= scalar
140 return self
141
144