p->jdr -= jr;
}
-void __ses_path_dr2(ScfEfunction* f, ses_path_t* path, int i, int j, int n_diodes, double a, double ja)
+void __ses_path_dr_forward(ScfEfunction* f, ses_path_t* path, int i, int j, int n_diodes, double a, double ja)
{
assert(n_diodes > 0);
scf_logw("c%ldp%ld, v: %lg, r: %lg, a: %lg, dr: %lg, n_diodes: %d\n", p->cid, p->id, v, p->r, a, p->dr, n_diodes);
+ p1 = c->pins[SCF_EDA_Diode_POS];
+ p1->a = a;
+ p1->ja = ja;
+
} else if (SCF_EDA_Transistor == c->type && SCF_EDA_Transistor_B == p->id) {
- p1 = c->pins[SCF_EDA_Transistor_C];
+ ses_ui_r(&p->dr, &p->jdr, v, jv, a, ja);
+
+ p->dr -= p->r;
+ p->jdr -= p->jr;
+
+ scf_logw("c%ldp%ld, v: %lg, r: %lg, a: %lg, dr: %lg, n_diodes: %d\n", p->cid, p->id, v, p->r, a, p->dr, n_diodes);
+
+ p1 = c->pins[SCF_EDA_Transistor_C];
+ p1->a = p1->hfe * a;
+ p1->ja = p1->hfe * ja;
+ p1->aconst = 1;
+
+ p1 = c->pins[SCF_EDA_Transistor_E];
+ p1->a = (1 + p1->hfe) * a;
+ p1->ja = (1 + p1->hfe) * ja;
+ p1->aconst = 1;
+
+ a = p1->a;
+ ja = p1->ja;
+ }
+ }
+}
+
+void __ses_path_dr_reverse(ScfEfunction* f, ses_path_t* path, int i, int j, int n_diodes, double a, double ja)
+{
+ assert(n_diodes > 0);
+
+ ScfEpin* p = path->pins->data[i];
+ ScfEpin* p1 = path->pins->data[j];
+
+ double v = p->v - p1->v;
+ double jv = p->jv - p1->jv;
+
+ double r;
+ double jr;
+
+ v /= n_diodes;
+ jv /= n_diodes;
+
+ int k;
+ for (k = j; k >= i; k--) {
+
+ ScfEcomponent* c;
+
+ p = path->pins->data[k];
+ c = f->components[p->cid];
+
+ if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_NEG == p->id) {
ses_ui_r(&p->dr, &p->jdr, v, jv, a, ja);
scf_logw("c%ldp%ld, v: %lg, r: %lg, a: %lg, dr: %lg, n_diodes: %d\n", p->cid, p->id, v, p->r, a, p->dr, n_diodes);
- a *= (1 + p1->hfe);
- ja *= (1 + p1->hfe);
+ p1 = c->pins[SCF_EDA_Diode_POS];
+ p1->a = a;
+ p1->ja = ja;
+
+ } else if (SCF_EDA_Transistor == c->type && SCF_EDA_Transistor_B == p->id) {
+
+ p1 = c->pins[SCF_EDA_Transistor_E];
+ p1->a = a;
+ p1->ja = ja;
+ p1->aconst = 1;
+
+ p1 = c->pins[SCF_EDA_Transistor_C];
+
+ a /= (1 + p1->hfe);
+ ja /= (1 + p1->hfe);
+
+ p1->a = p1->hfe * a;
+ p1->ja = p1->hfe * ja;
+ p1->aconst = 1;
+
+ ses_ui_r(&p->dr, &p->jdr, v, jv, a, ja);
+
+ p->dr -= p->r;
+ p->jdr -= p->jr;
+
+ scf_logw("c%ldp%ld, v: %lg, r: %lg, a: %lg, dr: %lg, n_diodes: %d\n", p->cid, p->id, v, p->r, a, p->dr, n_diodes);
}
}
}
pi->v = el->v;
pi->jv = el->jv;
- if (SCF_EDA_Diode != c->type)
+ if (SCF_EDA_Diode == c->type)
+ continue;
+
+ if (SCF_EDA_Transistor != c->type)
break;
- }
- if (SCF_EDA_Transistor == c->type)
- return 0;
+ if (SCF_EDA_Transistor_C == p->id)
+ return 0;
+ }
for (j = path->pins->size - 1; j >= i; j--) {
pj = path->pins->data[j];
pj->v = el->v;
pj->jv = el->jv;
- if (SCF_EDA_Diode != c->type)
+ if (SCF_EDA_Diode == c->type)
+ continue;
+
+ if (SCF_EDA_Transistor != c->type)
break;
- }
- if (SCF_EDA_Transistor == c->type)
- return 0;
+ if (SCF_EDA_Transistor_C == p->id)
+ return 0;
+ }
if (j <= i) {
scf_loge("all components are Diode\n");
double v = pi->v - pj->v;
double jv = pi->jv - pj->jv;
- double pr = pj->pr - pi->pr;
- double jpr = pj->jpr - pi->jpr;
+ double pr = pj->pr - pj->r - pi->pr;
+ double jpr = pj->jpr - pj->jr - pi->jpr;
- double sr = pj->sr - pi->sr;
- double jsr = pj->jsr - pi->jsr;
+ double sr = pj->sr - pj->r - pi->sr;
+ double jsr = pj->jsr - pj->jr - pi->jsr;
double a;
double ja;
if (path->childs)
__ses_path_split_i(path, pj, p1, a, ja, &pj->a, &pj->ja);
- p = c->pins[SCF_EDA_Diode_NEG];
- p->a = pj->a;
- p->ja = pj->ja;
+ scf_loge("j: %d, c%ldp%ld--c%ldp%ld, v: %lg, pj->v: %lg, pj->a: %lg, pr: %lg, sr: %lg\n\n",
+ j, pj->cid, pj->id, p1->cid, p1->id, v, pj->v, pj->a, pr, sr);
+
+ __ses_path_dr_forward(f, path, j, path->pins->size - 1, path->n_diodes - pj->n_diodes, pj->a, pj->ja);
+
+ } else if (SCF_EDA_Transistor == c->type && SCF_EDA_Transistor_B == pj->id) {
+
+ el = f->elines[pj->lid];
+ el->a = a;
+ el->ja = ja;
+ el->aconst = 1;
+
+ pj->a = a;
+ pj->ja = ja;
+
+ if (path->childs)
+ __ses_path_split_i(path, pj, p1, a, ja, &pj->a, &pj->ja);
scf_loge("j: %d, c%ldp%ld--c%ldp%ld, v: %lg, pj->v: %lg, pj->a: %lg, pr: %lg, sr: %lg\n\n",
j, pj->cid, pj->id, p1->cid, p1->id, v, pj->v, pj->a, pr, sr);
- __ses_path_dr2(f, path, j, path->pins->size - 1, path->n_diodes - pj->n_diodes, pj->a, pj->ja);
+ __ses_path_dr_forward(f, path, j, path->pins->size - 1, path->n_diodes - pj->n_diodes + 1, pj->a, pj->ja);
}
if (i > 0)
if (path->childs)
__ses_path_split_i(path, p0, pi, a, ja, &pi->a, &pi->ja);
- __ses_path_dr2(f, path, 0, i, pi->n_diodes, pi->a, pi->ja);
+ __ses_path_dr_reverse(f, path, 0, i, pi->n_diodes, pi->a, pi->ja);
+
+ scf_loge("i: %d, c%ldp%ld--c%ldp%ld, v: %lg, pi->v: %lg, pi->a: %lg, pr: %lg, sr: %lg\n\n",
+ i, p0->cid, p0->id, pi->cid, pi->id, v, pi->v, pi->a, pr, sr);
+
+ } else if (SCF_EDA_Transistor == c->type && SCF_EDA_Transistor_E == pj->id) {
+
+ el = f->elines[pi->lid];
+ el->a = a;
+ el->ja = ja;
+ el->aconst = 1;
+
+ pi->a = a;
+ pi->ja = ja;
+
+ if (path->childs)
+ __ses_path_split_i(path, p0, pi, a, ja, &pi->a, &pi->ja);
+
+ p = c->pins[SCF_EDA_Transistor_B];
- p0->a = pi->a;
- p0->ja = pi->ja;
+ __ses_path_dr_reverse(f, path, 0, i, p->n_diodes, pi->a, pi->ja);
scf_loge("i: %d, c%ldp%ld--c%ldp%ld, v: %lg, pi->v: %lg, pi->a: %lg, pr: %lg, sr: %lg\n\n",
i, p0->cid, p0->id, pi->cid, pi->id, v, pi->v, pi->a, pr, sr);