}
}
-void __ses_path_dr_forward(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, 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 = i; k <= j; k++) {
if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_NEG == p->id) {
- ses_ui_r(&p->dr, &p->jdr, v, jv, a, ja);
+ ses_ui_r(&p->dr, &p->jdr, SCF_EDA_V_Diode_ON, 0, 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);
+ scf_logw("c%ldp%ld, v: %lg, r: %lg, a: %lg, dr: %lg\n", p->cid, p->id, SCF_EDA_V_Diode_ON, p->r, a, p->dr);
p1 = c->pins[SCF_EDA_Diode_POS];
p1->a = a;
} else if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_B == p->id) {
- ses_ui_r(&p->dr, &p->jdr, v, jv, a, ja);
+ ses_ui_r(&p->dr, &p->jdr, SCF_EDA_V_NPN_OFF, 0, a, ja);
p->dr -= p->r;
p->jdr -= p->jr;
p1->ja = p1->hfe * ja;
p1->aconst = 1;
- scf_logw("c%ldp%ld, v: %lg, r: %lg, a: %lg, dr: %lg, n_diodes: %d, c%ldp%ld->a: %lg\n",
- p->cid, p->id, v, p->r, a, p->dr, n_diodes, p1->cid, p1->id, p1->a);
+ scf_logw("c%ldp%ld, v: %lg, r: %lg, a: %lg, dr: %lg, c%ldp%ld->a: %lg\n",
+ p->cid, p->id, SCF_EDA_V_NPN_OFF, p->r, a, p->dr, p1->cid, p1->id, p1->a);
p1 = c->pins[SCF_EDA_NPN_E];
p1->a = (1 + p1->hfe) * a;
}
}
-void __ses_path_dr_reverse(ScfEfunction* f, ses_path_t* path, int i, int j, int n_diodes, double a, double ja)
+void __ses_path_dr_reverse(ScfEfunction* f, ses_path_t* path, int i, int j, 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--) {
if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_NEG == p->id) {
- ses_ui_r(&p->dr, &p->jdr, v, jv, a, ja);
+ ses_ui_r(&p->dr, &p->jdr, SCF_EDA_V_Diode_ON, 0, 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);
+ scf_logw("c%ldp%ld, v: %lg, r: %lg, a: %lg, dr: %lg\n", p->cid, p->id, SCF_EDA_V_Diode_ON, p->r, a, p->dr);
p1 = c->pins[SCF_EDA_Diode_POS];
p1->a = a;
p1->ja = p1->hfe * ja;
p1->aconst = 1;
- ses_ui_r(&p->dr, &p->jdr, v, jv, a, ja);
+ ses_ui_r(&p->dr, &p->jdr, SCF_EDA_V_NPN_OFF, 0, 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);
+ scf_logw("c%ldp%ld, v: %lg, r: %lg, a: %lg, dr: %lg\n", p->cid, p->id, SCF_EDA_V_NPN_OFF, p->r, a, p->dr);
}
}
}
p1->v = el->v;
p1->jv = el->jv;
+ int i_diodes = 0;
+ int j_diodes = 0;
+ int i_NPNs = 0;
+ int j_NPNs = 0;
+
for (i = 0; i < path->pins->size; i++) {
pi = path->pins->data[i];
el = f->elines [pi->lid];
c = f->components[pi->cid];
-// if (!el->vconst)
-// break;
-
- pi->v = el->v;
- pi->jv = el->jv;
-
- if (SCF_EDA_Diode == c->type)
+ if (SCF_EDA_Diode == c->type) {
+ i_diodes++;
continue;
+ }
if (SCF_EDA_NPN != c->type)
break;
if (SCF_EDA_NPN_C == pi->id)
return 0;
+
+ i_NPNs++;
}
for (j = path->pins->size - 1; j >= i; j--) {
el = f->elines [pj->lid];
c = f->components[pj->cid];
-// if (!el->vconst)
-// break;
-
- pj->v = el->v;
- pj->jv = el->jv;
-
- if (SCF_EDA_Diode == c->type)
+ if (SCF_EDA_Diode == c->type) {
+ j_diodes++;
continue;
+ }
if (SCF_EDA_NPN != c->type)
break;
if (SCF_EDA_NPN_C == pj->id)
return 0;
+
+ j_NPNs++;
}
if (j <= i) {
return -1;
}
- int __ni = i / 2;
- int __nj = (path->pins->size - 1 - j) / 2;
- double __vi = p0->v - SCF_EDA_V_Diode_ON * __ni;
- double __vj = p1->v + SCF_EDA_V_Diode_ON * __nj;
+ i_diodes >>= 1;
+ j_diodes >>= 1;
- scf_logd("i: %d, j: %d, c%ldp%ld--c%ldp%ld, ni: %d, nj: %d, vi: %lg, vj: %lg\n",
- i, j, pi->cid, pi->id, pj->cid, pj->id, __ni, __nj, __vi, __vj);
+ i_NPNs >>= 1;
+ j_NPNs >>= 1;
+
+ double __vi = p0->v - SCF_EDA_V_Diode_ON * i_diodes - SCF_EDA_V_NPN_ON * i_NPNs;
+ double __vj = p1->v + SCF_EDA_V_Diode_ON * j_diodes + SCF_EDA_V_NPN_ON * j_NPNs;
+
+ scf_logd("i: %d, c%ldp%ld, __vi: %lg, i_diodes: %d, i_NPNs: %d\n", i, pi->cid, pi->id, __vi, i_diodes, i_NPNs);
+ scf_logd("j: %d, c%ldp%ld, __vj: %lg, j_diodes: %d, j_NPNs: %d\n", j, pj->cid, pj->id, __vj, j_diodes, j_NPNs);
pi->v = __vi;
pj->v = __vj;
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);
+ __ses_path_dr_forward(f, path, j, path->pins->size - 1, pj->a, pj->ja);
} else if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_B == pj->id) {
pj->a = a;
pj->ja = ja;
- scf_logd("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);
-
if (path->childs)
__ses_path_split_i(f, path, j, path->pins->size - 1, 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_dr_forward(f, path, j, path->pins->size - 1, path->n_diodes - pj->n_diodes + 1, pj->a, pj->ja);
+ __ses_path_dr_forward(f, path, j, path->pins->size - 1, pj->a, pj->ja);
}
if (i > 0)
if (path->childs)
__ses_path_split_i(f, path, 0, i, a, ja, &pi->a, &pi->ja);
- __ses_path_dr_reverse(f, path, 0, i, pi->n_diodes, pi->a, pi->ja);
+ __ses_path_dr_reverse(f, path, 0, i, 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);
p = c->pins[SCF_EDA_NPN_B];
- __ses_path_dr_reverse(f, path, 0, i, p->n_diodes, pi->a, pi->ja);
+ __ses_path_dr_reverse(f, path, 0, i, 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);