36 using namespace qucs::eqn;
39 eqndefined::eqndefined () : circuit () {
41 setVariableSized (
true);
54 if (veqn)
free (veqn);
55 if (ieqn)
free (ieqn);
56 if (geqn)
free (geqn);
57 if (qeqn)
free (qeqn);
58 if (ceqn)
free (ceqn);
59 if (_jstat)
free (_jstat);
60 if (_jdyna)
free (_jdyna);
61 if (_charges)
free (_charges);
67 if (ieqn == NULL) initModel ();
72 #define A(a) ((assignment *) (a))
73 #define C(c) ((constant *) (c))
74 #define BP(n) real (getV (n * 2 + 0) - getV (n * 2 + 1))
78 char * str =
strchr (getName (),
'.');
83 char * txt = (
char *) malloc (strlen (str) + strlen (base) + 3);
85 sprintf (txt,
"%s.%s%d", str, base, n);
87 sprintf (txt,
"%s%d", base, n);
93 char * str =
strchr (getName (),
'.');
98 char * txt = (
char *) malloc (strlen (str) + strlen (base) + 4);
100 sprintf (txt,
"%s.%s%d%d", str, base, r, c);
102 sprintf (txt,
"%s%d%d", base, r, c);
116 return A(eqn)->getResultDouble ();
121 int i, j, k, branches = getSize () / 2;
122 char * in, * qn, * vn, * gn, * cn, * vnold, * inold;
126 veqn = (
void **) malloc (
sizeof (
assignment *) * branches);
127 ieqn = (
void **) malloc (
sizeof (
assignment *) * branches);
128 geqn = (
void **) malloc (
sizeof (
assignment *) * branches * branches);
129 qeqn = (
void **) malloc (
sizeof (
assignment *) * branches);
130 ceqn = (
void **) malloc (
sizeof (
assignment *) * branches * branches);
133 _jstat = (nr_double_t *) malloc (
sizeof (nr_double_t) * branches * branches);
134 _jdyna = (nr_double_t *) malloc (
sizeof (nr_double_t) * branches * branches);
135 _charges = (nr_double_t *) malloc (
sizeof (nr_double_t) * branches);
138 for (i = 0; i < branches; i++) {
139 vn = createVariable (
"V", i + 1);
140 if ((veqn[i] = getEnv()->getChecker()->findEquation (vn)) == NULL) {
141 veqn[
i] = getEnv()->getChecker()->addDouble (
"#voltage", vn, 0);
142 A(veqn[i])->evalType ();
143 A(veqn[i])->skip = 1;
149 for (i = 0; i < branches; i++) {
152 in = createVariable (
"I", i + 1);
153 ivalue = getEnv()->getChecker()->findEquation (in);
156 "EDD `%s'\n", in, getName ());
158 qn = createVariable (
"Q", i + 1);
159 qvalue = getEnv()->getChecker()->findEquation (qn);
162 "EDD `%s'\n", qn, getName ());
168 for (j = 0; j < branches; j++) {
169 in = createVariable (
"I", j + 1);
170 inold = createVariable (
"I", j + 1,
false);
171 vn = createVariable (
"V", j + 1);
172 vnold = createVariable (
"V", j + 1,
false);
174 ivalue->replace (vnold, vn);
175 ivalue->replace (inold, in);
178 qvalue->replace (vnold, vn);
179 qvalue->replace (inold, in);
191 for (i = 0; i < branches; i++) {
192 if (ieqn[i]) {
A(ieqn[i])->evalType ();
A(ieqn[i])->skip = 1; }
193 if (qeqn[i]) {
A(qeqn[i])->evalType ();
A(qeqn[i])->skip = 1; }
197 for (k = 0, i = 0; i < branches; i++) {
201 for (j = 0; j < branches; j++, k++) {
202 vn = createVariable (
"V", j + 1);
206 gn = createVariable (
"G", i + 1, j + 1);
207 if ((geqn[k] = getEnv()->getChecker()->findEquation (gn)) == NULL) {
208 diff = ivalue->differentiate (vn);
209 getEnv()->getChecker()->addEquation (diff);
213 A(diff)->rename (gn);
227 for (k = 0, i = 0; i < branches; i++) {
231 for (j = 0; j < branches; j++, k++) {
232 vn = createVariable (
"V", j + 1);
236 cn = createVariable (
"C", i + 1, j + 1);
237 if ((ceqn[k] = getEnv()->getChecker()->findEquation (cn)) == NULL) {
238 diff = qvalue->differentiate (vn);
239 getEnv()->getChecker()->addEquation (diff);
242 A(diff)->rename (cn);
245 for (
int l = 0;
l < branches;
l++) {
246 in = createVariable (
"I",
l + 1);
247 diff = qvalue->differentiate (in);
248 A(diff)->mul (
A(geqn[
l * branches + j]));
249 A(ceqn[k])->add (
A(diff));
253 A(ceqn[k])->evalType ();
254 A(ceqn[k])->skip = 1;
270 int i, branches = getSize () / 2;
273 for (i = 0; i < branches; i++) {
274 setResult (veqn[i],
BP (i));
277 getEnv()->passConstants ();
278 getEnv()->equationSolver ();
283 int i, j, k, branches = getSize () / 2;
289 for (i = 0; i < branches; i++) {
290 nr_double_t
c = getResult (ieqn[i]);
291 setI (i * 2 + 0, -c);
292 setI (i * 2 + 1, +c);
296 for (k = 0, i = 0; i < branches; i++) {
299 for (j = 0; j < branches; j++, k++) {
300 nr_double_t g = getResult (geqn[k]);
301 setY (i * 2 + 0, j * 2 + 0, +g);
302 setY (i * 2 + 1, j * 2 + 1, +g);
303 setY (i * 2 + 0, j * 2 + 1, -g);
304 setY (i * 2 + 1, j * 2 + 0, -g);
309 setGV (i * 2 + 0, +gv);
310 setGV (i * 2 + 1, -gv);
314 addI (i * 2 + 0, +gv);
315 addI (i * 2 + 1, -gv);
322 int i, j, k, branches = getSize () / 2;
325 for (k = 0, i = 0; i < branches; i++) {
326 nr_double_t q = getResult (qeqn[i]);
328 for (j = 0; j < branches; j++, k++) {
329 nr_double_t g = getResult (geqn[k]);
331 nr_double_t
c = getResult (ceqn[k]);
344 evalOperatingPoints ();
355 setMatrixY (calcMatrixY (frequency));
360 int i, j, k, branches = getSize () / 2;
361 matrix
y (2 * branches);
362 nr_double_t o = 2 *
M_PI * frequency;
365 for (k = 0, i = 0; i < branches; i++) {
366 for (j = 0; j < branches; j++, k++) {
370 y (r + 0, c + 0) = +val;
371 y (r + 1, c + 1) = +val;
372 y (r + 0, c + 1) = -val;
373 y (r + 1, c + 0) = -val;
382 int branches = getSize () / 2;
383 setStates (2 * branches);
389 int state,
i, j, k, branches = getSize () / 2;
395 evalOperatingPoints ();
398 for (i = 0; i < branches; i++) {
401 transientCapacitanceQ (state, r + 0, r + 1, _charges[i]);
405 for (k = 0, i = 0; i < branches; i++) {
406 for (j = 0; j < branches; j++, k++) {
409 nr_double_t
v =
BP (j);
410 transientCapacitanceC (r + 0, r + 1, c + 0, c + 1, _jdyna[k], v);
423 setMatrixS (
ytos (calcMatrixY (frequency)));
429 if (ieqn == NULL) initModel ();
435 int i, j, k, branches = getSize () / 2;
441 evalOperatingPoints ();
444 for (i = 0; i < branches; i++) {
445 setQ (i * 2 + 0, -_charges[i]);
446 setQ (i * 2 + 1, +_charges[i]);
450 for (k = 0, i = 0; i < branches; i++) {
452 for (j = 0; j < branches; j++, k++) {
455 nr_double_t val = _jdyna[k];
456 setQV (r + 0, c + 0, +val);
457 setQV (r + 1, c + 1, +val);
458 setQV (r + 0, c + 1, -val);
459 setQV (r + 1, c + 0, -val);
462 setCV (i * 2 + 0, +cv);
463 setCV (i * 2 + 1, -cv);
std::complex< nr_double_t > nr_complex_t
matrix ytos(matrix y, qucs::vector z0)
Admittance matrix to scattering parameters.
qucs::matrix calcMatrixY(nr_double_t)
void setResult(void *, nr_double_t)
nr_double_t getResult(void *)
#define M_PI
Archimedes' constant ( )
void evalOperatingPoints(void)
vector diff(vector, vector, int n=1)
void initSP(void)
placehoder for S-Parameter initialisation function
void saveOperatingPoints(void)
virtual void initHB(void)
The environment class definition.
void logprint(int level, const char *format,...)
char * createVariable(const char *, int, int, bool prefix=true)
#define PROP_NO_SUBSTRATE