-
Notifications
You must be signed in to change notification settings - Fork 0
/
sycira.mac
295 lines (268 loc) · 9.07 KB
/
sycira.mac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
ckt:["Title",
[[V0,"V",[1,0],[],[],ue,[]],
[Ri,"R",[1,2],[],[],Ri,[]],
[L1,"L",[2,0],[],[],L1,[]],
[L2,"L",[3,0],[],[],L2,[]],
[Rl,"R",[3,0],[],[],Rl,[]]],
[[K1,"K",[],[],[L1,L2],1,[]]],
[]
];
circuit:
1 title
2 list of element-lists
3 list of coupling elements
4 list of nodes (empty at init)
5 list of values (numeric) not used yet
element:
1 name
2 type
3 nodeslist
4 name of controlling element
5 name of coupled inductors
6 value
7 initial value
*/
sycira(ckt):=block([Eqsi,k,j,eqs,var,v,s,t,inode, a],
/* generate list of nodes */
ckt:gennodelist(ckt),
/* coupling of inductors */
ckt:couple(ckt),
/*initialize Variables*/
s:'s,
t:'t,
v[0]:0,
for k:1 thru length(ckt[4]) do
inode[ckt[4][k]]:0,
Eqsi["aux_vars"]:set(),
Eqsi["state_vars"]:set(),
Eqsi["aux_curr_eqs"]:set(),
Eqsi["volt_eqs"]:set(),
Eqsi["init_eqs"]:set(),
Eqsi["curr_eqs"]:set(),
/*Eqsi["node_currs"]:set(),*/
/* generate set of equations */
for k:1 thru length(ckt[2]) do
(
if ( intersect(set(ckt[2][k][2]), set("R","L","C","V","I","E","F","G","H")) = set(ckt[2][k][2])) then
(
SyciraGeneq(ckt[2][k][2],ckt[2][k],"ac")
)
),
eqs:Eqsi["volt_eqs"],
for k:1 thru length(ckt[4]) do
eqs:union(set(inode[ckt[4][k]]=0),eqs),
for k:1 thru length(Eqs["curr_eqs"]) do
eqs:subst(rhs(Eqs["curr_eqs"][k]),lhs(Eqs["curr_eqs"][k]),eqs),
/*subst(x,y,z) x for y in z ,maple subs(a=b,c) b for a in c;*/
var:Eqsi["aux_vars"],
for k:1 thru length(ckt[4]) do
var:union(var,set(v[ckt[4][k]])),
var:setdifference(var,set(v[0])),
return([listify(eqs),listify(var)])
);
/*
implemented:
V Voltage Source
I CurrentSource
R Resistor
L Inductance
C Capacitance
E VCVS Voltage controlled voltage Source
F CCCS Current controlled current source
G VCCS Voltage controlled current source
H CCVS Current controlled voltage source
K coupling between inductors
not yet implemented:
coupling between capacitors
conductances
not implemented:
has to be realised with subcircuits flattened by netlist preprocessor
D
J
M
Q
X
T transmission line (loss less)
Units are also handled in external C routine:
t/T Tera 10^12
g/G Giga 10^9
MEG Mega 10^6 ;special case
k/K Kilo 10^3
m/M milli 10^(-3)
u/U micro 10^(-6)
n/N nano 10^(-9)
p/P pico 10^(-12)
f/F femto 10^(-15)
mil 254^(-4) ; special case millivol != <> mV
R posnode negnode val <TC=alpha<,beta>> ; T[T]=R[0](1+alpha*delta[T]+beta*(delta[T])^2
; [alpha]=1/K, [beta]=1/(K^2)
C posnode negnode val <IC=u(t=0)> ;
C posnode negnode POLY C[0] <C[1] <C[2] <... C[n]>>> <IC=u(t=0)> ; nonlinear capacitor
; [C[n]]=1/(V^n) voltage dependant capacitor
L posnode negnode val <IC=i(t=0)> ;
L posnode negnode POLY L[0] <L[1] <L[2] <... L[n]>>> <IC=u(t=0)> ; nonlinear inductor
; [L[n]]=1/(A^n) current dependant inductor
K L1 L2 val
G posnode negnode posrefnode negrefnode val ; [val] = Siemens
E posnode negnode posrefnode negrefnode val ; [val] = 1
F posnode negnode senselementname val ; [val] = 1
H posnode negnode senselementname val ; [val] = Ohm
*/
gennodelist(ckt):=block([k, nodes],
nodes:set(0),
/* check that 0 node exists */
for k:1 thru length(ckt[2]) do
(
nodes:union(nodes, setify(ckt[2][k][3]))
),
ckt[4]:listify(nodes),
return(ckt)
);
couple(ckt):=block([k,j,elem1,elem2,val],
for k:1 thru length(ckt[3]) do /* für jede kopplung k*/
(
for j:1 thru length(ckt[2]) do /* kontrolle jedes Elements */
(
if ckt[3][k][5][1]=ckt[2][j][1] then
(
elem1:j
),
if ckt[3][k][5][2]=ckt[2][j][1] then
(
elem2:j
)
),
val:ckt[3][k][6]*sqrt(ckt[2][elem1][6]*ckt[2][elem2][6]),
ckt[2][elem1][5]:append(ckt[2][elem1][5],[[ckt[2][elem2][1],val]]),
ckt[2][elem2][5]:append(ckt[2][elem2][5],[[ckt[2][elem1][1],val]])
),
ckt[3]:[],
return(ckt)
);
SyciraGeneqV(element):=block([],
Eqsi["aux_vars"]:union(Eqsi["aux_vars"],set(i[element[1]])),
Eqsi["aux_curr_eqs"]:union(Eqsi["aux_curr_eqs"], set(i[element[1]]=i[element[1]])),
Eqsi["volt_eqs"]:union(Eqsi["volt_eqs"], set(v[element[3][1]]-v[element[3][2]]=element[6])),
inode[element[3][1]]:inode[element[3][1]]+i[element[1]],
inode[element[3][2]]:inode[element[3][2]]-i[element[1]]
);
SyciraGeneqR(element):=block([i,r],
r:element[6],
if r = 0 then
SyciraGeneqV(element)
else
(
element[6]:(v[element[3][1]]-v[element[3][2]])/r,
SyciraGeneqI(element)
)
);
SyciraGeneqI(element):=block([],
Eqsi["aux_curr_eqs"]:union(Eqsi["aux_curr_eqs"],set(i[element[1]]=element[6])),
Eqsi["curr_eqs"]:union(Eqsi["curr_eqs"],set(i[element[1]]=element[6])),
inode[element[3][1]]:inode[element[3][1]]+element[6],
inode[element[3][2]]:inode[element[3][2]]-element[6]
);
SyciraGeneqE(element):=block([],
element[6]:element[6]*(v[element[3][3]]-v[element[3][4]]),
SyciraGeneqV(element)
);
SyciraGeneqF(element):=block([],
element[6]:element[6]*i[element[4]],
SyciraGeneqI(element)
);
SyciraGeneqG(element):=block([],
element[6]:element[6]*(v[element[3][3]]-v[element[3][4]]),
SyciraGeneqI(element)
);
SyciraGeneqH(element):=block([],
element[6]:element[6]*i[element[4]],
SyciraGeneqV(element)
);
SyciraGeneqC(element,analysis):=block([],
if analysis = "dc" then
(
element[6]:0,
SyciraGeneqI(element)
)
else
(
if analysis="ac" then
(
/*u:v[element[1]],Q:element[6]*v,i:s*Q*/
Eqsi["aux_vars"]:union(Eqsi["aux_vars"],set(v[element[1]])),
Eqsi["aux_curr_eqs"]:union(Eqsi["aux_curr_eqs"],set(i[element[1]]=s*element[6]*v[element[1]])),
Eqsi["volt_eqs"]:union(Eqsi["volt_eqs"],set(v[element[3][1]]-v[element[3][2]]=v[element[1]])),
inode[element[3][1]]:inode[element[3][1]]+s*element[6]*v[element[1]],
inode[element[3][2]]:inode[element[3][2]]-s*element[6]*v[element[1]]
)
else /*tran*/
(
Eqsi["aux_curr_eqs"]:union(Eqsi["aux_curr_eqs"],set(i[element[1]]=diff(element[6]*v[element[1]](t),t))),
Eqsi["volt_eqs"]:union(Eqsi["volt_eqs"],set(v[element[3][1]]-v[element[3][2]]=v[element[1]](t) )),
inode[element[3][1]]:inode[element[3][1]]+diff(element[6]*v[element[1]](t),t),
inode[element[3][2]]:inode[element[3][2]]-diff(element[6]*v[element[1]](t),t),
Eqsi["aux_vars"]:union(Eqsi["aux_vars"], set(diff(v[element[1]](t),t))),
Eqsi["state_vars"]:union(Eqsi["state_vars"],set(v[element[1]](t))),
Eqsi["init_eqs"]:union(Eqsi["init_eqs"],set(ev(v[element[1]](t)=element[7],t=0)))
)
)
);
SyciraGeneqL(element,analysis):=block([phi,k],
if analysis = "dc" then
(
element[6]:0,
SyciraGeneqV(element)
)
else
(
if analysis = "ac" then
(
phi:i[element[1]]*element[6],
for k:1 thru length(element[5]) do
(
phi:phi+i[element[5][k][1]]*element[5][k][2]
),
Eqsi["aux_curr_eqs"]:union(Eqsi["aux_curr_eqs"], set(i[element[1]]=i[element[1]])),
Eqsi["volt_eqs"]:union(Eqsi["volt_eqs"],set(v[element[3][1]]-v[element[3][2]]=s*phi)),
inode[element[3][1]]:inode[element[3][1]]+i[element[1]],
inode[element[3][2]]:inode[element[3][2]]-i[element[1]],
Eqsi["aux_vars"]:union(Eqsi["aux_vars"], set(i[element[1]]))
)
else
(
phi:i[element[1]](t)*element[6],
for k:1 thru length(element[5]) do
(
phi:phi+i[element[5][k][1]](t)*element[5][k][2]
),
Eqsi["aux_curr_eqs"]:union(Eqsi["aux_curr_eqs"],set(i[element[1]](t)=i[element[1]](t) )),
Eqsi["volt_eqs"]:union(Eqsi["volt_eqs"],set(v[element[3][1]]-v[element[3][2]]=diff(phi,t))),
inode[element[3][1]]:inode[element[3][1]]+i[element[1]](t),
inode[element[3][2]]:inode[element[3][2]]-i[element[1]](t),
Eqsi["state_vars"]:union(Eqsi["state_vars"],set(i[element[1]](t) )),
Eqsi["aux_vars"]:union(Eqsi["aux_vars"],set(diff(i[element[1]](t),t))),
Eqsi["init_eqs"]:union(Eqsi["init_eqs"], set(ev(i[element[1]](t)=element[7], t=0)))
)
)
);
SyciraGeneq(elemtype, element, ana):=block([],
if elemtype = "R" then
return( SyciraGeneqR(element)),
if elemtype = "L" then
return( SyciraGeneqL(element,ana)),
if elemtype = "C" then
return( SyciraGeneqC(element,ana)),
if elemtype = "E" then
return( SyciraGeneqE(element)),
if elemtype = "F" then
return( SyciraGeneqF(element)),
if elemtype = "G" then
return( SyciraGeneqG(element)),
if elemtype = "H" then
return( SyciraGeneqH(element)),
if elemtype = "I" then
return( SyciraGeneqI(element)),
if elemtype = "V" then
return( SyciraGeneqV(element))
);