58 #define USE_GROUNDS 1 // use extra grounds ?
59 #define USE_CROSSES 1 // use additional cross connectors ?
60 #define SORTED_LIST 1 // use sorted node list?
62 #define TINYS (NR_TINY * 1.235) // 'tiny' value for singularities
73 tees = crosses = opens = grounds = 0;
127 nr_double_t tiny1 = (d == 0) ? 1.0 -
TINYS : 1.0;
128 nr_double_t tiny2 = tiny1 * tiny1;
129 nr_double_t tiny3 = tiny1 * tiny2;
130 d = (1.0 - s->
getS (k,
l) * tiny1) * (1.0 - s->
getS (
l, k) * tiny1) -
140 for (j1 = 0; j1 < s->
getSize (); j1++) {
143 if (j1 == k || j1 ==
l)
continue;
149 for (i1 = 0; i1 < s->
getSize (); i1++) {
152 if (i1 == k || i1 ==
l)
continue;
155 p = s->
getS (i1, j1);
157 (s->
getS (k, j1) * s->
getS (i1,
l) * (1.0 - s->
getS (
l, k)) * tiny3 +
158 s->
getS (
l, j1) * s->
getS (i1, k) * (1.0 - s->
getS (k,
l)) * tiny3 +
161 result->
setS (i2++, j2, p);
189 nr_double_t tiny1 = (d == 0) ? 1.0 -
TINYS : 1.0;
190 nr_double_t tiny2 = tiny1 * tiny1;
191 nr_double_t tiny3 = tiny1 * tiny2;
192 d = 1.0 - s->
getS (k, k) * t->
getS (
l,
l) * tiny2;
201 for (j1 = 0; j1 < s->
getSize (); j1++) {
204 if (j1 == k)
continue;
210 for (i1 = 0; i1 < s->
getSize (); i1++) {
213 if (i1 == k)
continue;
216 p = s->
getS (i1, j1);
218 result->
setS (i2++, j2, p);
222 for (i1 = 0; i1 < t->
getSize (); i1++) {
225 if (i1 ==
l)
continue;
228 p = s->
getS (k, j1) * t->
getS (i1,
l) * tiny2 /
d;
229 result->
setS (i2++, j2, p);
236 for (j1 = 0; j1 < t->
getSize (); j1++) {
239 if (j1 ==
l)
continue;
245 for (i1 = 0; i1 < s->
getSize (); i1++) {
248 if (i1 == k)
continue;
251 p = t->
getS (
l, j1) * s->
getS (i1, k) * tiny2 /
d;
252 result->
setS (i2++, j2, p);
256 for (i1 = 0; i1 < t->
getSize (); i1++) {
259 if (i1 ==
l)
continue;
262 p = t->
getS (i1, j1);
264 result->
setS (i2++, j2, p);
290 nr_double_t tiny1 = (t == 0) ? 1.0 -
TINYS : 1.0;
291 nr_double_t tiny2 = tiny1 * tiny1;
292 t = (1.0 - c->
getS (k,
l) * tiny1) * (1.0 - c->
getS (
l, k) * tiny1) -
302 for (j1 = 0; j1 < c->
getSize (); j1++) {
305 if (j1 == k || j1 ==
l)
continue;
308 for (i1 = 0; i1 < c->
getSize (); i1++) {
311 if (i1 == k || i1 ==
l)
continue;
313 k1 = (c->
getS (i1,
l) * (1.0 - c->
getS (
l, k)) +
314 c->
getS (
l,
l) * c->
getS (i1, k)) * tiny2 / t;
315 k2 = (c->
getS (i1, k) * (1.0 - c->
getS (k,
l)) +
316 c->
getS (k, k) * c->
getS (i1,
l)) * tiny2 / t;
317 k3 = (c->
getS (j1,
l) * (1.0 - c->
getS (
l, k)) +
318 c->
getS (
l,
l) * c->
getS (j1, k)) * tiny2 / t;
319 k4 = (c->
getS (j1, k) * (1.0 - c->
getS (k,
l)) +
320 c->
getS (k, k) * c->
getS (j1,
l)) * tiny2 / t;
323 c->
getN (i1, j1) + c->
getN (k, j1) * k1 + c->
getN (
l, j1) * k2 +
325 c->
getN (
l, k) * k2) +
328 result->
setN (i2, j2, p);
356 nr_double_t tiny1 = (t == 0) ? 1.0 -
TINYS : 1.0;
357 nr_double_t tiny2 = tiny1 * tiny1;
358 nr_double_t tiny3 = tiny1 * tiny2;
359 nr_double_t tiny4 = tiny1 * tiny3;
360 t = 1.0 - c->
getS (k, k) * d->
getS (
l,
l) * tiny2;
369 for (j1 = 0; j1 < c->
getSize (); j1++) {
372 if (j1 == k)
continue;
375 for (i1 = 0; i1 < c->
getSize (); i1++) {
378 if (i1 == k)
continue;
381 p = c->
getN (i1, j1) +
387 result->
setN (i2, j2, p);
402 for (j1 = 0; j1 < d->
getSize (); j1++) {
405 if (j1 ==
l)
continue;
408 for (i1 = 0; i1 < c->
getSize (); i1++) {
411 if (i1 == k)
continue;
417 d->
getN (
l, j1) * c->
getS (i1, k) * tiny1 / t +
419 result->
setN (i2, j2, p);
425 for (i1 = 0; i1 < d->
getSize (); i1++) {
428 if (i1 ==
l)
continue;
431 p = d->
getN (i1, j1) +
436 result->
setN (i2, j2, p);
453 if (
noise)
c->calcNoiseSP (freq);
476 result = c1 = c2 = cand1 = cand2 = NULL;
477 n1 = n2 = cand = NULL;
484 if (
c->getPort ())
continue;
487 for (
int i = 0;
i <
c->getSize ();
i++) {
490 if ((cand =
subnet->findConnectedCircuitNode (
c->getNode (
i))) != NULL) {
498 cand1 =
c1; cand2 =
c2; n1 = c1->
getNode (
i); n2 = cand;
503 if (c1->
getSize () - 2 < ports) {
505 cand1 =
c1; cand2 =
c2; n1 = c1->
getNode (
i); n2 = cand;
514 if (cand1 != NULL && cand2 != NULL) {
516 if (cand1 != cand2) {
523 subnet->reducedCircuit (result);
529 subnet->removeCircuit (cand1);
530 subnet->removeCircuit (cand2);
531 subnet->insertCircuit (result);
532 result->setOriginal (0);
542 subnet->reducedCircuit (result);
547 subnet->removeCircuit (cand1);
548 subnet->insertCircuit (result);
549 result->setOriginal (0);
559 if (
c->isNonLinear ())
c->calcOperatingPoints ();
561 if (
noise)
c->initNoiseSP ();
605 ports =
subnet->countNodes ();
614 while (ports >
subnet->getPorts ()) {
643 if (!strcmp (_name,
"gnd"))
return;
651 for (
int i = 0;
i <
c->getSize ();
i++) {
652 _node =
c->getNode (
i);
653 if (!strcmp (_node->
getName (), _name)) {
657 nodes[++count] = _node;
690 subnet->insertedCircuit (result);
703 subnet->insertCircuit (result);
706 nodes[1] = result->
getNode (0);
716 result =
new cross ();
717 subnet->insertedCircuit (result);
734 subnet->insertCircuit (result);
737 nodes[1] = result->
getNode (0);
750 subnet->removeCircuit (c);
764 subnet->removeCircuit (c);
771 if (strcmp (n->
getName (),
"gnd") &&
772 subnet->findConnectedNode (n) == NULL) {
774 subnet->insertedCircuit (result);
776 subnet->insertCircuit (result);
786 subnet->removeCircuit (c);
796 subnet->insertedCircuit (result);
801 subnet->insertCircuit (result);
813 subnet->removeCircuit (c);
830 root =
subnet->getRoot ();
834 subnet->removeCircuit (c, 0);
842 root =
subnet->getRoot ();
855 root =
subnet->getRoot ();
884 if (
c->getInserted () > inserted) {
885 inserted =
c->getInserted ();
909 }
while (cand != NULL);
926 subnet->insertedCircuit (result);
928 result->
setNode (1,
c->getNode(0)->getName ());
929 result->
setNode (2,
c->getNode(1)->getName ());
933 c->getNode(1)->setName (
"PacGround");
943 subnet->insertCircuit (result);
964 subnet->removeCircuit (c);
973 node * sig_i, * sig_j;
983 if ((f =
data->findDependency (
"frequency")) == NULL) {
984 f =
new vector (
"frequency");
985 data->addDependency (f);
992 if (!
c->getPort ()) {
994 for (
int i = 0;
i <
c->getSize ();
i++) {
995 for (
int j = 0; j <
c->getSize (); j++) {
998 sig_i =
subnet->findConnectedNode (
c->getNode (
i));
999 sig_j =
subnet->findConnectedNode (
c->getNode (j));
1012 if ((res_i == ni || res_i == no) && (res_j == ni || res_j == no)) {
1017 ro = (res_i == ni) ? 0 : 1;
1018 co = (res_j == ni) ? 0 : 1;
1020 noise_c[co + ro * 2] =
c->getN (
i, j);
1021 noise_s[co + ro * 2] =
c->getS (
i, j);
1039 nr_double_t z0,
vector * f) {
1047 c11 *
norm (s21) - 2.0 *
real (c12 * s21 *
conj (s11)) +
1049 n2 = 2.0 * (c22 * s11 - c12 * s21) / (c22 + n1);
1052 Sopt = 1.0 -
norm (n2);
1053 if (
real (Sopt) < 0.0)
1054 Sopt = (1.0 +
sqrt (Sopt)) / n2;
1056 Sopt = (1.0 -
sqrt (Sopt)) / n2;
1059 Fmin =
real (1.0 + (c22 - n1 * norm (Sopt)) /
1060 norm (s21) / (1.0 + norm (Sopt)));
1063 Rn =
real ((c11 - 2.0 *
real (c12 *
conj ((1.0 + s11) / s21)) +
1064 c22 * norm ((1.0 + s11) / s21)) / 4.0);
1082 char * text = (
char *) malloc (strlen (c) + strlen (n) + 2);
1083 sprintf (text,
"%s.%s", c, n);
1093 vector * f =
data->findDependency (
"frequency");
1095 c->saveCharacteristics (freq);
1097 c->calcCharacteristics (freq);
void dropConnections(void)
std::complex< nr_double_t > nr_complex_t
matrix real(matrix a)
Real part matrix.
void saveResults(nr_double_t)
void saveVariable(const char *, nr_complex_t, qucs::vector *)
Save variable into analysis dataset.
void insertConnectors(node *)
circuit * getCircuit(void)
void sortedNodes(node **, node **)
nr_double_t getPropertyDouble(const char *)
void insertGround(node *)
void dropCross(circuit *)
void insertCross(node **, char *)
void noiseInterconnect(circuit *, node *, node *)
void logprogressclear(int points)
Global physical constants header file.
int getPropertyInteger(const char *)
static const nr_double_t z0
nr_complex_t getN(int, int)
int getSize(void)
Get the number of ports the circuit element has.
void insertDifferentialPorts(void)
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
void saveCharacteristics(nr_double_t)
void setName(const char *)
base class for qucs circuit elements.
void noiseConnect(circuit *, node *, node *)
void addProperty(property *)
virtual void initSP(void)
placehoder for S-Parameter initialisation function
void insertConnections(void)
The analysis class header file.
int solve(void)
placehoder for solution function
char * createSP(int, int)
The circuit class header file.
void dropDifferentialPort(circuit *)
circuit * connectedJoin(node *, node *)
void insertTee(node **, char *)
void logprogressbar(nr_double_t current, nr_double_t final, int points)
nr_double_t norm(const nr_complex_t z)
Compute euclidian norm of complex number.
virtual void initNoiseSP(void)
void setCircuit(circuit *)
void setNode(int, const char *, int intern=0)
nr_double_t getValue(void)
sweep * createSweep(const char *)
create a named sweep object
char * createCV(char *, char *)
void setS(int, int, nr_complex_t)
void setN(int, int, nr_complex_t)
matrix conj(matrix a)
Conjugate complex matrix.
void saveNoiseResults(nr_complex_t[4], nr_complex_t[4], nr_double_t, vector *)
circuit * interconnectJoin(node *, node *)
void dropGround(circuit *)
char * getPropertyString(const char *)
void insert(struct nodelist_t *)
void logprint(int level, const char *format,...)
nr_complex_t getS(int, int)
#define PROP_NO_SUBSTRATE
static char * createMatrixString(const char *, int, int)