From 3afe5b861b89486cf3d8c90890b4332568c81919 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Wed, 25 Oct 2023 16:07:19 +0800 Subject: [PATCH] ses_step_va_diode.c --- scf_eda_pb.h | 6 +-- ses_step_va_diode.c | 94 +++++++++++++++++++-------------------------- 2 files changed, 43 insertions(+), 57 deletions(-) diff --git a/scf_eda_pb.h b/scf_eda_pb.h index 8406850..1579a45 100644 --- a/scf_eda_pb.h +++ b/scf_eda_pb.h @@ -29,11 +29,11 @@ enum { #define SCF_EDA_V_MIN -10000000.0 #define SCF_EDA_V_MAX 10000000.0 -#define SCF_EDA_V_Diode_ON 0.59 -#define SCF_EDA_V_Diode_OFF 0.58 +#define SCF_EDA_V_Diode_ON 0.58 +#define SCF_EDA_V_Diode_OFF 0.55 #define SCF_EDA_V_NPN_ON 0.70 -#define SCF_EDA_V_NPN_OFF 0.60 +#define SCF_EDA_V_NPN_OFF 0.61 enum { SCF_EDA_Battery_NEG, diff --git a/ses_step_va_diode.c b/ses_step_va_diode.c index 7b02a0d..6df9d0e 100644 --- a/ses_step_va_diode.c +++ b/ses_step_va_diode.c @@ -89,22 +89,14 @@ void __ses_path_split_i(ScfEfunction* f, ses_path_t* path, int i, int j, double } } -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++) { @@ -115,12 +107,12 @@ void __ses_path_dr_forward(ScfEfunction* f, ses_path_t* path, int i, int j, int 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; @@ -128,7 +120,7 @@ void __ses_path_dr_forward(ScfEfunction* f, ses_path_t* path, int i, int j, int } 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; @@ -138,8 +130,8 @@ void __ses_path_dr_forward(ScfEfunction* f, ses_path_t* path, int i, int j, int 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; @@ -152,22 +144,14 @@ void __ses_path_dr_forward(ScfEfunction* f, ses_path_t* path, int i, int j, int } } -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--) { @@ -178,12 +162,12 @@ void __ses_path_dr_reverse(ScfEfunction* f, ses_path_t* path, int i, int j, int 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; @@ -205,12 +189,12 @@ void __ses_path_dr_reverse(ScfEfunction* f, ses_path_t* path, int i, int j, int 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); } } } @@ -241,26 +225,29 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) 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--) { @@ -269,20 +256,18 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) 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) { @@ -290,13 +275,17 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) 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; @@ -347,7 +336,7 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) 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) { @@ -359,16 +348,13 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) 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) @@ -390,7 +376,7 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) 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); @@ -410,7 +396,7 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) 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); -- 2.25.1