From: yu.dongliang <18588496441@163.com> Date: Thu, 28 Sep 2023 08:10:39 +0000 (+0800) Subject: __ses_path_va_diode() X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=0d8c3d31a9eb01fb488248a16db9fc2fc11e4066;p=ses.git __ses_path_va_diode() --- diff --git a/ses_step_va_diode.c b/ses_step_va_diode.c index 1ce0aa2..53976d2 100644 --- a/ses_step_va_diode.c +++ b/ses_step_va_diode.c @@ -72,6 +72,47 @@ void __ses_path_dr(ScfEpin* p0, ScfEpin* p1, ScfEpin* p) p->jdr -= jr; } +void __ses_path_dr2(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 = p1->sr - p->sr; + double jr = p1->jsr - p->jsr; + + double dr; + double jdr; + + ses_ui_r(&dr, &jdr, v, jv, a, ja); + + dr -= r; + jdr -= jr; + + dr /= n_diodes; + jdr /= n_diodes; + + int k; + for (k = i; k <= j; 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) { + p->dr = dr; + p->jdr = jdr; + + scf_logw("c%ldp%ld, v: %lg, r: %lg, a: %lg, dr: %lg, n_diodes: %d\n", p->cid, p->id, v, r, a, dr, n_diodes); + } + } +} + static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) { ses_path_t* child; @@ -142,7 +183,7 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) } if (j < path->pins->size - 1) - pj = path->pins->data[j + 1]; + pj = path->pins->data[++j]; double v = pi->v - pj->v; double jv = pi->jv - pj->jv; @@ -163,7 +204,9 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) else ses_ur_i(&a, &ja, v, jv, sr, jsr); - if (SCF_EDA_Diode_POS == pj->id) { + c = f->components[pj->cid]; + + if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_POS == pj->id) { el = f->elines[pj->lid]; el->a = a; @@ -176,21 +219,22 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) if (path->childs) __ses_path_split_i(path, pj, p1, a, ja, &pj->a, &pj->ja); - c = f->components[pj->cid]; p = c->pins[SCF_EDA_Diode_NEG]; p->a = pj->a; p->ja = pj->ja; - __ses_path_dr(pj, p1, p); + 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); - scf_loge("j: %d, c%ldp%ld--c%ldp%ld, v: %lg, pj->v: %lg, pj->a: %lg, pr: %lg, sr: %lg, p->dr: %lg\n\n", - j, pj->cid, pj->id, p1->cid, p1->id, v, pj->v, pj->a, pr, sr, p->dr); + __ses_path_dr2(f, path, j, path->pins->size - 1, path->n_diodes - pj->n_diodes, pj->a, pj->ja); } if (i > 0) - pi = path->pins->data[i - 1]; + pi = path->pins->data[--i]; + + c = f->components[pi->cid]; - if (SCF_EDA_Diode_NEG == pi->id) { + if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_NEG == pi->id) { el = f->elines[pi->lid]; el->a = a; @@ -203,13 +247,13 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) if (path->childs) __ses_path_split_i(path, p0, pi, a, ja, &pi->a, &pi->ja); - __ses_path_dr(p0, pi, pi); + __ses_path_dr2(f, path, 0, i, pi->n_diodes, pi->a, pi->ja); p0->a = pi->a; p0->ja = pi->ja; - scf_loge("i: %d, c%ldp%ld--c%ldp%ld, v: %lg, pi->v: %lg, pi->a: %lg, pr: %lg, sr: %lg, p->dr: %lg\n\n", - i, p0->cid, p0->id, pi->cid, pi->id, v, pi->v, pi->a, pr, sr, pi->dr); + 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); } return 0; diff --git a/test/main.c b/test/main.c index 96f2672..a624c11 100644 --- a/test/main.c +++ b/test/main.c @@ -24,12 +24,18 @@ int main(int argc, char* argv[]) EDA_INST_ADD_COMPONENT(f, D0, SCF_EDA_Diode); EDA_INST_ADD_COMPONENT(f, D1, SCF_EDA_Diode); + EDA_INST_ADD_COMPONENT(f, D2, SCF_EDA_Diode); EDA_INST_ADD_COMPONENT(f, R0, SCF_EDA_Resistor); + EDA_INST_ADD_COMPONENT(f, R1, SCF_EDA_Resistor); EDA_PIN_ADD_PIN(D0, SCF_EDA_Diode_POS, B, SCF_EDA_Battery_POS); - EDA_PIN_ADD_PIN(D0, SCF_EDA_Diode_NEG, R0, 1); - EDA_PIN_ADD_PIN(R0, 0, D1, SCF_EDA_Diode_POS); - EDA_PIN_ADD_PIN(D1, SCF_EDA_Diode_NEG, B, SCF_EDA_Battery_NEG); + EDA_PIN_ADD_PIN(D0, SCF_EDA_Diode_NEG, D1, SCF_EDA_Diode_POS); + EDA_PIN_ADD_PIN(D1, SCF_EDA_Diode_NEG, R0, 1); + EDA_PIN_ADD_PIN(R0, 0, B, SCF_EDA_Battery_NEG); + + EDA_PIN_ADD_PIN(D2, SCF_EDA_Diode_POS, B, SCF_EDA_Battery_POS); + EDA_PIN_ADD_PIN(D2, SCF_EDA_Diode_NEG, R1, 1); + EDA_PIN_ADD_PIN(R1, 0, D1, SCF_EDA_Battery_NEG); scf_eboard__add_function(b, f);