From 16b76756bd6ee71447b32bc1346bc90127d3139b Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Wed, 17 Apr 2024 16:47:52 +0800 Subject: [PATCH] change resistance value from complex to real number, fix some issues --- Makefile | 2 +- scf_eda_pack.c | 24 ++-- scf_eda_pack.h | 29 +---- ses_core.h | 65 +++++------ ses_step_da.c | 90 +++++--------- ses_step_dc_transistor.c | 4 +- ses_step_jr.c | 245 ++++++++++----------------------------- ses_step_output.c | 2 + ses_step_va.c | 116 +++++++++--------- ses_step_va_balance.c | 245 --------------------------------------- ses_step_va_bridge.c | 238 ++++++++++++++++++++----------------- ses_step_va_diode.c | 187 ++++++++++++------------------ ses_step_va_line.c | 30 +++++ ses_step_va_transistor.c | 108 ++++++----------- ses_steps.c | 7 +- ses_utils.c | 33 ++---- 16 files changed, 484 insertions(+), 941 deletions(-) delete mode 100644 ses_step_va_balance.c create mode 100644 ses_step_va_line.c diff --git a/Makefile b/Makefile index 68e2d7f..79d6c18 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ CFILES += ses_step_va_diode.c CFILES += ses_step_va_transistor.c CFILES += ses_step_va.c CFILES += ses_step_va_bridge.c -CFILES += ses_step_va_balance.c +CFILES += ses_step_va_line.c CFILES += ses_step_da.c CFILES += ses_step_output.c diff --git a/scf_eda_pack.c b/scf_eda_pack.c index 12c1e89..6eec934 100644 --- a/scf_eda_pack.c +++ b/scf_eda_pack.c @@ -17,25 +17,25 @@ static int component_pins[SCF_EDA_Components_NB] = static scf_edata_t component_datas[] = { - {SCF_EDA_None, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {SCF_EDA_Battery, 0, SCF_EDA_Battery_POS, 0, 0, 0, 0, 0, 0, 0}, + {SCF_EDA_None, 0, 0, 0, 0, 0, 0, 0, 0}, + {SCF_EDA_Battery, 0, SCF_EDA_Battery_POS, 0, 0, 0, 0, 0, 0}, - {SCF_EDA_Resistor, 0, 0, 0, 0, 10 * 1000, 0, 0, 0, 0}, - {SCF_EDA_Capacitor, 0, 0, 0, 0, 1e12, 0, 0.1, 0, 0}, - {SCF_EDA_Inductor, 0, 0, 0, 0, 0, 0, 0, 1000, 0}, + {SCF_EDA_Resistor, 0, 0, 0, 0, 10 * 1000, 0, 0, 0}, + {SCF_EDA_Capacitor, 0, 0, 0, 0, 1e12, 0.1, 0, 0}, + {SCF_EDA_Inductor, 0, 0, 0, 0, 0, 0, 1000, 0}, }; static scf_edata_t pin_datas[] = { - {SCF_EDA_None, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + {SCF_EDA_None, 0, 0, 0, 0, 0, 0, 0, 0}, - {SCF_EDA_Diode, 0, SCF_EDA_Diode_NEG, 0, 0, 750, 0, 0, 0, 0}, + {SCF_EDA_Diode, 0, SCF_EDA_Diode_NEG, 0, 0, 750, 0, 0, 0}, - {SCF_EDA_NPN, 0, SCF_EDA_NPN_B, 0, 0, 750, 0, 0, 0, 0}, - {SCF_EDA_NPN, 0, SCF_EDA_NPN_C, 0, 0, 10, 0, 0, 0, 150}, + {SCF_EDA_NPN, 0, SCF_EDA_NPN_B, 0, 0, 750, 0, 0, 0}, + {SCF_EDA_NPN, 0, SCF_EDA_NPN_C, 0, 0, 10, 0, 0, 150}, - {SCF_EDA_PNP, 0, SCF_EDA_PNP_B, 0, 0, 750, 0, 0, 0, 0}, - {SCF_EDA_PNP, 0, SCF_EDA_PNP_C, 0, 0, 10, 0, 0, 0, 150}, + {SCF_EDA_PNP, 0, SCF_EDA_PNP_B, 0, 0, 750, 0, 0, 0}, + {SCF_EDA_PNP, 0, SCF_EDA_PNP_C, 0, 0, 10, 0, 0, 150}, }; static scf_edata_t* _pin_find_data(const uint64_t type, const uint64_t model, const uint64_t pid) @@ -359,7 +359,6 @@ ScfEcomponent* scf_ecomponent__alloc(uint64_t type) c->v = ed->v; c->a = ed->a; c->r = ed->r; - c->jr = ed->jr; c->uf = ed->uf; c->uh = ed->uh; } @@ -386,7 +385,6 @@ ScfEcomponent* scf_ecomponent__alloc(uint64_t type) pin->v = ed->v; pin->a = ed->a; pin->r = ed->r; - pin->jr = ed->jr; pin->uf = ed->uf; pin->uh = ed->uh; pin->hfe = ed->hfe; diff --git a/scf_eda_pack.h b/scf_eda_pack.h index 8b3dbd3..e5e6d3b 100644 --- a/scf_eda_pack.h +++ b/scf_eda_pack.h @@ -77,7 +77,6 @@ typedef struct { double v; double a; double r; - double jr; double uf; double uh; double hfe; @@ -112,24 +111,16 @@ struct scf_epin_s SCF_PACK_DEF_VAR(uint64_t, c_lid); SCF_PACK_DEF_VAR(double, v); - SCF_PACK_DEF_VAR(double, jv); SCF_PACK_DEF_VAR(double, a); - SCF_PACK_DEF_VAR(double, ja); SCF_PACK_DEF_VAR(double, r); - SCF_PACK_DEF_VAR(double, jr); SCF_PACK_DEF_VAR(double, uf); SCF_PACK_DEF_VAR(double, uh); SCF_PACK_DEF_VAR(double, hfe); SCF_PACK_DEF_VAR(double, dr); - SCF_PACK_DEF_VAR(double, jdr); - SCF_PACK_DEF_VAR(double, sr); - SCF_PACK_DEF_VAR(double, jsr); - SCF_PACK_DEF_VAR(double, pr); - SCF_PACK_DEF_VAR(double, jpr); SCF_PACK_DEF_VAR(uint64_t, path); @@ -154,24 +145,15 @@ SCF_PACK_INFO_VARS(ScfEpin, tos, uint64_t), SCF_PACK_INFO_VAR(ScfEpin, c_lid), SCF_PACK_INFO_VAR(ScfEpin, v), -SCF_PACK_INFO_VAR(ScfEpin, jv), SCF_PACK_INFO_VAR(ScfEpin, a), -SCF_PACK_INFO_VAR(ScfEpin, ja), SCF_PACK_INFO_VAR(ScfEpin, r), -SCF_PACK_INFO_VAR(ScfEpin, jr), SCF_PACK_INFO_VAR(ScfEpin, uf), SCF_PACK_INFO_VAR(ScfEpin, uh), SCF_PACK_INFO_VAR(ScfEpin, hfe), SCF_PACK_INFO_VAR(ScfEpin, dr), -SCF_PACK_INFO_VAR(ScfEpin, jdr), - SCF_PACK_INFO_VAR(ScfEpin, sr), -SCF_PACK_INFO_VAR(ScfEpin, jsr), - -SCF_PACK_INFO_VAR(ScfEpin, pr), -SCF_PACK_INFO_VAR(ScfEpin, jpr), SCF_PACK_INFO_VAR(ScfEpin, path), SCF_PACK_INFO_VAR(ScfEpin, x), @@ -206,12 +188,11 @@ typedef struct { SCF_PACK_DEF_OBJS(ScfLine, lines); SCF_PACK_DEF_VAR(double, v); - SCF_PACK_DEF_VAR(double, jv); SCF_PACK_DEF_VAR(double, a); - SCF_PACK_DEF_VAR(double, ja); SCF_PACK_DEF_VAR(uint8_t, vconst); SCF_PACK_DEF_VAR(uint8_t, aconst); SCF_PACK_DEF_VAR(uint8_t, vflag); + SCF_PACK_DEF_VAR(uint8_t, vinit); } ScfEline; SCF_PACK_TYPE(ScfEline) @@ -225,9 +206,7 @@ SCF_PACK_INFO_OBJS(ScfEline, conns, ScfEconn), SCF_PACK_INFO_OBJS(ScfEline, lines, ScfLine), SCF_PACK_INFO_VAR(ScfEline, v), -SCF_PACK_INFO_VAR(ScfEline, jv), SCF_PACK_INFO_VAR(ScfEline, a), -SCF_PACK_INFO_VAR(ScfEline, ja), SCF_PACK_INFO_VAR(ScfEline, vconst), SCF_PACK_INFO_VAR(ScfEline, aconst), SCF_PACK_INFO_VAR(ScfEline, vflag), @@ -241,12 +220,9 @@ struct scf_ecomponent_s SCF_PACK_DEF_OBJS(ScfEpin, pins); SCF_PACK_DEF_VAR(double, v); - SCF_PACK_DEF_VAR(double, jv); SCF_PACK_DEF_VAR(double, a); - SCF_PACK_DEF_VAR(double, ja); SCF_PACK_DEF_VAR(double, r); - SCF_PACK_DEF_VAR(double, jr); SCF_PACK_DEF_VAR(double, uf); SCF_PACK_DEF_VAR(double, uh); @@ -267,12 +243,9 @@ SCF_PACK_INFO_VAR(ScfEcomponent, model), SCF_PACK_INFO_OBJS(ScfEcomponent, pins, ScfEpin), SCF_PACK_INFO_VAR(ScfEcomponent, v), -SCF_PACK_INFO_VAR(ScfEcomponent, jv), SCF_PACK_INFO_VAR(ScfEcomponent, a), -SCF_PACK_INFO_VAR(ScfEcomponent, ja), SCF_PACK_INFO_VAR(ScfEcomponent, r), -SCF_PACK_INFO_VAR(ScfEcomponent, jr), SCF_PACK_INFO_VAR(ScfEcomponent, uf), SCF_PACK_INFO_VAR(ScfEcomponent, uh), diff --git a/ses_core.h b/ses_core.h index f4ee4a2..d7c0f4b 100644 --- a/ses_core.h +++ b/ses_core.h @@ -21,16 +21,10 @@ struct ses_flow_s int neg_pins; double pos_r; - double pos_jr; - double neg_r; - double neg_jr; double v; - double jv; - double a; - double ja; }; #define SES_PATH_MAIN 0 @@ -59,25 +53,18 @@ struct ses_path_s int parent_p1; double parent_r0; - double parent_jr0; - double parent_r1; - double parent_jr1; - double r; - double jr; + double parent_pr; - double v; - double jv; + double sr; + double pr; + double v; double a; - double ja; double a0; - double ja0; - double da; - double dja; int type; int index; @@ -125,18 +112,18 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count); int ses_paths_find_flow(ses_flow_t* flow, scf_vector_t* paths, ScfEpin* vip, ses_path_t* bridge); int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path); -void __ses_path_split_i (ScfEfunction* f, ses_path_t* path, int i, int j, double la, double jla, double* a, double* ja); +void __ses_path_split_i (ScfEfunction* f, ses_path_t* path, int i, int j, double la, double* a); int __ses_status_check (ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe); int __ses_topo_paths (ScfEfunction* f, scf_vector_t* paths); int __ses_path_jr (ScfEfunction* f, ses_path_t* path); -void __ses_path_pr (ScfEfunction* f, ses_path_t* path, int i, int j, ScfEpin* cp1, double* r, double* jr); -void __ses_path_sr (ScfEfunction* f, ses_path_t* path, int i, int j, ScfEpin* cp1, double* r, double* jr); +void __ses_path_pr (ScfEfunction* f, ses_path_t* path, int i, int j, ses_path_t* child, double* r); +void __ses_path_sr (ScfEfunction* f, ses_path_t* path, int i, int j, double* r); int __ses_path_va (ScfEfunction* f, ses_path_t* path, int *changed); int __ses_path_da (ScfEfunction* f, ses_path_t* path, int *changed, double da, double dja); int __ses_path_pos(ScfEfunction* f, ScfEline* el); int __ses_path_neg(ScfEfunction* f, ScfEline* el); -void __ses_npn_epr (ScfEfunction* f, ScfEpin* pe, double* r, double* jr); +void __ses_npn_epr (ScfEfunction* f, ScfEpin* pe, double* r); void __ses_npn_dr (ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe); void __ses_pn_dr (ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe); @@ -164,24 +151,30 @@ static inline void forward(int* px, int* py, int dx, int dy, int d) static inline void ses_ur_i(double* a, double* ja, double v, double jv, double r, double jr) { - double R = r * r + jr * jr; + double R = r * r + jr * jr; - *a = ( v * r + jv * jr) / R; - *ja = (jv * r - v * jr) / R; + *a = (v * r + jv * jr) / R; + + if (ja) + *ja = (jv * r - v * jr) / R; } static inline void ses_ui_r(double* r, double* jr, double v, double jv, double a, double ja) { - double R = a * a + ja * ja; + double R = a * a + ja * ja; + + *r = (v * a + jv * ja) / R; - *r = ( v * a + jv * ja) / R; - *jr = (jv * a - v * ja) / R; + if (jr) + *jr = (jv * a - v * ja) / R; } static inline void ses_ir_u(double* v, double* jv, double a, double ja, double r, double jr) { - *v = a * r - ja * jr; - *jv = ja * r + a * jr; + *v = a * r - ja * jr; + + if (jv) + *jv = ja * r + a * jr; } static inline void ses_split_i(double* a, double* ja, double ta, double jta, double r, double jr, double pr, double jpr) @@ -191,8 +184,10 @@ static inline void ses_split_i(double* a, double* ja, double ta, double jta, dou double t = ta * pr - jta * jpr; double jt = jta * pr + ta * jpr; - *a = ( t * r + jt * jr) / R; - *ja = (jt * r - t * jr) / R; + *a = (t * r + jt * jr) / R; + + if (ja) + *ja = (jt * r - t * jr) / R; } static inline void ses_split_r(double* r1, double* jr1, double tr, double jtr, double r0, double jr0) @@ -212,7 +207,9 @@ static inline void ses_split_r(double* r1, double* jr1, double tr, double jtr, d R = tr * tr + jtr * jtr; *r1 = tr / R; - *jr1 = jtr / -R; + + if (jr1) + *jr1 = jtr / -R; } static inline void ses_merge_r(double* tr, double* jtr, double r0, double jr0, double r1, double jr1) @@ -232,7 +229,9 @@ static inline void ses_merge_r(double* tr, double* jtr, double r0, double jr0, d R = r0* r0 + jr0 * jr0; *tr = r0 / R; - *jtr = jr0 / -R; + + if (jtr) + *jtr = jr0 / -R; } #endif diff --git a/ses_step_da.c b/ses_step_da.c index 53d6bee..07bebf1 100644 --- a/ses_step_da.c +++ b/ses_step_da.c @@ -38,34 +38,28 @@ static int __ses_path_split_da(ScfEfunction* f, ses_path_t* path, int i, double* return -EINVAL; } - double _r = p2->pr - p->pr; - double _jr = p2->jpr - p->jpr; + double _r = p2->pr - p->pr; + double _dv = 0; + double _da = 0; - double _dv = 0; - double _djv = 0; - double _da = 0; - double _dja = 0; + __ses_path_pr(f, path, i, k, child, &_r); - __ses_path_pr(f, path, i, k, cp1, &_r, &_jr); - - ses_ir_u(&_dv, &_djv, *da, *dja, _r, _jr); + ses_ir_u(&_dv, NULL, *da, 0, _r, 0); scf_logw("child: %d, c%ldp%ld-c%ldp%ld (c%ldp%ld-c%ldp%ld), _dv: %lg, da: %lg, _r: %lg, p->pr: %lg, p->dr: %lg, p2->pr: %lg\n", child->index, p->cid, p->id, p2->cid, p2->id, cp0->cid, cp0->id, cp1->cid, cp1->id, _dv, *da, _r, p->pr, p->dr, p2->pr); - ses_ur_i(&_da, &_dja, _dv, _djv, child->r, child->jr); + ses_ur_i(&_da, NULL, _dv, 0, child->pr, 0); - *da -= _da; - *dja -= _dja; + *da -= _da; - el = f->elines[p2->lid]; - el->v -= _dv; - el->jv -= _djv; + el = f->elines[p2->lid]; + el->v -= _dv; scf_loge("child: %d, c%ldp%ld, c%ldp%ld, p->v: %lg, el->v: %lg, _dv: %lg\n", child->index, p->cid, p->id, p2->cid, p2->id, p->v, el->v, _dv); - int ret = __ses_path_da(f, child, changed, _da, _dja); + int ret = __ses_path_da(f, child, changed, _da, 0); if (ret < 0) return ret; @@ -85,56 +79,44 @@ static void __ses_path_split_dv(ScfEfunction* f, ses_path_t* path, int i0, int i ScfEpin* p = path->pins->data[i]; double dv; - double djv; double r; - double jr; - __ses_path_sr(f, path, i0, i, NULL, &r, &jr); + __ses_path_sr(f, path, i0, i, &r); - ses_ir_u(&dv, &djv, da, dja, r, jr); + ses_ir_u(&dv, NULL, da, 0, r, 0); - if (p->lid != Bp->lid && p->lid != Bn->lid) { + if (p->lid != Bp->lid && p->lid != Bn->lid) p->v -= dv; - p->jv -= djv; - } scf_logd("c%ldp%ld, c%ldp%ld, da: %lg, r: %lg, dv: %lg\n", p0->cid, p0->id, p->cid, p->id, da, r, dv); } void __ses_pn_dr(ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe) { - double v = pb->v - pe->v; - double jv = pb->jv - pe->jv; + double v = pb->v - pe->v; double r; - double jr; if (v >= SCF_EDA_V_Diode_ON) { - ses_ui_r(&r, &jr, v, jv, pb->a, pb->ja); + ses_ui_r(&r, NULL, v, 0, pb->a, 0); pe->dr = r - pe->r; } else if (v > SCF_EDA_V_Diode_OFF) pe->dr = pb->r * (SCF_EDA_V_Diode_ON - SCF_EDA_V_Diode_OFF) / (v - SCF_EDA_V_Diode_OFF + 0.001); - else - pe->dr = 1e12; } void __ses_npn_dr(ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe) { - double v = pb->v - pe->v; - double jv = pb->jv - pe->jv; + double v = pb->v - pe->v; double r; - double jr; if (v >= SCF_EDA_V_NPN_ON) { - ses_ui_r(&r, &jr, v, jv, pb->a, pb->ja); + ses_ui_r(&r, NULL, v, 0, pb->a, 0); pb->dr = r - pb->r; } else if (v > SCF_EDA_V_NPN_OFF) pb->dr = pb->r * (SCF_EDA_V_NPN_ON - SCF_EDA_V_NPN_OFF) / (v - SCF_EDA_V_NPN_OFF + 0.001); - else - pb->dr = 1e12; } int __ses_path_da(ScfEfunction* f, ses_path_t* path, int* changed, double da, double dja) @@ -160,13 +142,10 @@ int __ses_path_da(ScfEfunction* f, ses_path_t* path, int* changed, double da, do int i; int j; - double r = 0; - double jr = 0; - double dv = 0; - double jdv = 0; + double r = 0; + double dv = 0; - path->da = da; - path->dja = dja; + path->da = da; int i0 = 0; @@ -175,9 +154,9 @@ int __ses_path_da(ScfEfunction* f, ses_path_t* path, int* changed, double da, do if (!(i & 0x1) && path->childs) { - __ses_path_split_dv(f, path, i0, i, da, dja); + __ses_path_split_dv(f, path, i0, i, da, 0); - int ret = __ses_path_split_da(f, path, i, &da, &dja, changed); + int ret = __ses_path_split_da(f, path, i, &da, NULL, changed); if (ret < 0) return ret; @@ -187,29 +166,21 @@ int __ses_path_da(ScfEfunction* f, ses_path_t* path, int* changed, double da, do scf_logd("i: %d, p0: c%ldp%ld\n", i, p0->cid, p0->id); } } else - __ses_path_split_dv(f, path, i0, i, da, dja); + __ses_path_split_dv(f, path, i0, i, da, 0); el = f->elines[p->lid]; el->v = p->v; - el->jv = p->jv; - - r += p->r + p->dr; - jr += p->jr + p->jdr; + r += p->r + p->dr; if (i & 0x1) { c = f->components[p->cid]; r += c->r; - jr += c->jr; - dv -= p->v; - jdv -= p->jv; - p->a += da; - p->ja += dja; + p->a += da; - p2 = path->pins->data[i - 1]; - p2->a += da; - p2->ja += dja; + p2 = path->pins->data[i - 1]; + p2->a += da; if (path->childs) { for (j = 0; j < path->childs->size; j++) { @@ -220,7 +191,6 @@ int __ses_path_da(ScfEfunction* f, ses_path_t* path, int* changed, double da, do if (p->lid == cp1->lid) { da += child->da; - dja += child->dja; scf_logd("path: %d, i: %d, c%ldp%ld, child->da: %lg\n", child->index, i, cp1->cid, cp1->id, child->da); } @@ -253,11 +223,9 @@ int __ses_path_da(ScfEfunction* f, ses_path_t* path, int* changed, double da, do } } - r = 0; - jr = 0; + r = 0; } else { - dv = p->v; - jdv = p->jv; + dv = p->v; scf_loge("path: %d, i: %d, c%ldp%ld, p->v: %lg, dv: %lg, p->a: %lg, da: %lg, p->pr: %lg\n", path->index, i, p->cid, p->id, p->v, dv, p->a, da, p->pr); } diff --git a/ses_step_dc_transistor.c b/ses_step_dc_transistor.c index 031382e..ee01625 100644 --- a/ses_step_dc_transistor.c +++ b/ses_step_dc_transistor.c @@ -102,8 +102,8 @@ static int _dc_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, se c->status = SCF_EDA_Status_OFF; } - scf_loge("\033[34mc%ld, status: %d, pb->v: %lg, pe->v: %lg, diff: %lg, off: %lg\033[0m\n", - c->id, c->status, pb->v, pe->v, pb->v - pe->v, SCF_EDA_V_NPN_OFF); + scf_loge("\033[34mc%ld, status: %d, lock: %d, pb->v: %lg, pe->v: %lg, diff: %lg, off: %lg\033[0m\n", + c->id, c->status, c->lock, pb->v, pe->v, pb->v - pe->v, SCF_EDA_V_NPN_OFF); } return 0; diff --git a/ses_step_jr.c b/ses_step_jr.c index 4852397..4bf0c13 100644 --- a/ses_step_jr.c +++ b/ses_step_jr.c @@ -1,135 +1,41 @@ #include"ses_core.h" -void __ses_npn_epr(ScfEfunction* f, ScfEpin* pe, double* r, double* jr) +void __ses_npn_epr(ScfEfunction* f, ScfEpin* pe, double* r) { ScfEcomponent* c = f->components[pe->cid]; ScfEpin* pb = c->pins[SCF_EDA_NPN_B]; ScfEpin* pc = c->pins[SCF_EDA_NPN_C]; - ses_merge_r(r, jr, pb->pr, pb->jpr, pc->pr, pc->jpr); + ses_merge_r(r, NULL, pb->pr, 0, pc->pr, 0); } -void __ses_path_sr(ScfEfunction* f, ses_path_t* path, int i, int j, ScfEpin* cp1, double* r, double* jr) +void __ses_path_sr(ScfEfunction* f, ses_path_t* path, int i, int j, double* r) { - ScfEpin* p0 = path->pins->data[i]; - ScfEpin* p1 = path->pins->data[j]; + ScfEpin* p0 = path->pins->data[i]; + ScfEpin* p1 = path->pins->data[j]; - ScfEcomponent* c0 = f->components[p0->cid]; - ScfEcomponent* c1 = f->components[p1->cid]; + *r = p1->sr - p0->pr; - double r1 = 0; - double jr1 = 0; - - scf_logd("c%ldp%ld-c%ldp%ld, p0->sr: %lg, p0->pr: %lg, p1->sr: %lg, p1->pr: %lg\n", - p0->cid, p0->id, p1->cid, p1->id, p0->sr, p0->pr, p1->sr, p1->pr); - - if (SCF_EDA_NPN == c1->type) { - - if (SCF_EDA_NPN_E == p1->id) { - if (cp1 != p1) - p1 = path->pins->data[j - 1]; - - } else if (j > 0) { - r1 = p1->r + p1->dr; - jr1 = p1->jr + p1->jdr; - } else { - *r = 0; - *jr = 0; - return; - } - } - - if (SCF_EDA_NPN == c0->type) { - if (i > 0) { - p0 = path->pins->data[i - 1]; - c0 = f->components[p0->cid]; - - double pr0 = p0->pr; - double jpr0 = p0->jpr; - - if (SCF_EDA_NPN == c0->type && SCF_EDA_NPN_E == p0->id) - __ses_npn_epr(f, p0, &pr0, &jpr0); - - *r = p1->sr - r1 - pr0; - *jr = p1->jsr - jr1 - jpr0; - } else { - *r = p1->sr; - *jr = p1->jsr; - } - } else { - *r = p1->sr - r1 - p0->sr; - *jr = p1->jsr - jr1 - p0->jsr; - } - - scf_logd("c%ldp%ld-c%ldp%ld, r: %lg, p0->sr: %lg, p0->pr: %lg, p1->sr: %lg, p1->pr: %lg\n", + scf_logi("c%ldp%ld-c%ldp%ld, r: %lg, p0->sr: %lg, p0->pr: %lg, p1->sr: %lg, p1->pr: %lg\n", p0->cid, p0->id, p1->cid, p1->id, *r, p0->sr, p0->pr, p1->sr, p1->pr); } -void __ses_path_pr(ScfEfunction* f, ses_path_t* path, int i, int j, ScfEpin* cp1, double* r, double* jr) +void __ses_path_pr(ScfEfunction* f, ses_path_t* path, int i, int j, ses_path_t* child, double* r) { - ScfEpin* p0 = path->pins->data[i]; - ScfEpin* p1 = path->pins->data[j]; - - ScfEcomponent* c0 = f->components[p0->cid]; - ScfEcomponent* c1 = f->components[p1->cid]; - - scf_logd("c%ldp%ld-c%ldp%ld, p0->pr: %lg, p1->pr: %lg\n", p0->cid, p0->id, p1->cid, p1->id, p0->pr, p1->pr); + ScfEpin* p0 = path->pins->data[i]; + ScfEpin* p1 = path->pins->data[j]; - double pr1 = p1->pr; - double jpr1 = p1->jpr; + if (!child) { + *r = p1->pr - p0->pr; - if (SCF_EDA_NPN == c1->type) { - - if (SCF_EDA_NPN_E == p1->id) { - if (cp1 != p1) - p1 = path->pins->data[j - 1]; - - pr1 = p1->pr; - jpr1 = p1->jpr; - - } else if (j > 0) { - p1 = path->pins->data[j - 1]; - c1 = f->components[p1->cid]; - - pr1 = p1->pr; - jpr1 = p1->jpr; - - if (SCF_EDA_NPN == c1->type && SCF_EDA_NPN_E == p1->id) - __ses_npn_epr(f, p1, &pr1, &jpr1); - } else { - *r = 0; - *jr = 0; - return; - } - } - - if (SCF_EDA_NPN == c0->type) { - - if (SCF_EDA_NPN_E == p0->id) { - *r = pr1 - p0->pr; - *jr = jpr1 - p0->jpr; - - } else if (i > 0) { - p0 = path->pins->data[i - 1]; - c0 = f->components[p0->cid]; - - double pr0 = p0->pr; - double jpr0 = p0->jpr; - - if (SCF_EDA_NPN == c0->type && SCF_EDA_NPN_E == p0->id) - __ses_npn_epr(f, p0, &pr0, &jpr0); - - *r = pr1 - pr0; - *jr = jpr1 - jpr0; - } else { - *r = pr1; - *jr = jpr1; - } + scf_logd("c%ldp%ld-c%ldp%ld, r: %lg, p0->pr: %lg, p1->pr: %lg\n", + p0->cid, p0->id, p1->cid, p1->id, *r, p0->pr, p1->pr); } else { - *r = pr1 - p0->pr; - *jr = jpr1 - p0->jpr; + *r = child->parent_pr - p0->pr; + + scf_logd("c%ldp%ld-c%ldp%ld, r: %lg, p0->pr: %lg, p1->pr: %lg, child->parent_pr: %lg\n", + p0->cid, p0->id, p1->cid, p1->id, *r, p0->pr, p1->pr, child->parent_pr); } - scf_logd("c%ldp%ld-c%ldp%ld, r: %lg, p0->pr: %lg, p1->pr: %lg\n", p0->cid, p0->id, p1->cid, p1->id, *r, p0->pr, p1->pr); } int __ses_path_jr(ScfEfunction* f, ses_path_t* path) @@ -150,47 +56,52 @@ int __ses_path_jr(ScfEfunction* f, ses_path_t* path) ScfEpin* cp0; ScfEpin* cp1; - double R; double r; - double jr; + double r2; int i; int j; - r = 0; - jr = 0; + if (path->childs) { + for (i = 0; i < path->childs->size; i++) { + child = path->childs->data[i]; + + int ret = __ses_path_jr(f, child); + if (ret < 0) + return ret; + } + } + + r = 0; for (i = 0; i < path->pins->size; i++) { p = path->pins->data[i]; - r += p->r + p->dr; - jr += p->jr + p->jdr; - - if (i & 0x1) { - c = f->components[p->cid]; - r += c->r; - jr += c->jr; - } + c = f->components[p->cid]; + r2 = r; + r += p->r + p->dr; - p->sr = r; - p->jsr = jr; + if (i & 0x1) + r += c->r; - p->pr = r; - p->jpr = jr; + if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_E != p->id) { + p->sr = r2; + p->pr = r2; + } else { + p->sr = r; + p->pr = r; + } scf_loge("path: %d, i: %d, c%ldp%ld, p->sr: %lg\n", path->index, i, p->cid, p->id, p->sr); } - printf("\n"); if (path->childs) { + printf("\033[32mchilds:\033[0m\n"); + for (i = path->childs->size - 1; i >= 0; i--) { child = path->childs->data[i]; - int ret = __ses_path_jr(f, child); - if (ret < 0) - return ret; - cp0 = child->pins->data[0]; cp1 = child->pins->data[child->pins->size - 1]; p0 = NULL; @@ -224,70 +135,36 @@ int __ses_path_jr(ScfEfunction* f, ses_path_t* path) return -EINVAL; double pr; - double jpr; - - __ses_path_pr(f, path, k, j, NULL, &pr, &jpr); - ses_merge_r(&r, &jr, pr, jpr, child->r, child->jr); + __ses_path_pr(f, path, k, j, NULL, &pr); - double dr = pr - r; - double jdr = jpr - jr; + ses_merge_r(&r, NULL, pr, 0, child->pr, 0); - p1->pr -= dr; - p1->jpr -= jdr; + double dr = pr - r; - c = f->components[p1->cid]; - - if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == p1->id) { - - p = path->pins->data[j - 1]; - - if (cp1 != p1) { - p->pr -= dr; - p->jpr -= jdr; - } else { - p1->pr = p->pr - dr; - p1->jpr = p->jpr - jdr; - } - } + p1->pr -= dr; + child->parent_pr = p1->pr; scf_logi("j: %d, c%ldp%ld, p->pr: %lg, p->sr: %lg, pr: %lg, dr: %lg\n", j, p1->cid, p1->id, p1->pr, p1->sr, pr, dr); for (++j; j < path->pins->size; j++) { - p = path->pins->data[j]; - - p->pr -= dr; - p->jpr -= jdr; + p = path->pins->data[j]; - p->sr -= dr; - p->jsr -= jdr; + p->pr -= dr; + p->sr -= dr; scf_logd("j: %d, c%ldp%ld, p->pr: %lg, p->sr: %lg\n", j, p->cid, p->id, p->pr, p->sr); } - scf_logw("child: %d, r: %lg, dr: %lg\n", child->index, child->r, dr); + scf_logw("child: %d, pr: %lg, dr: %lg\n", child->index, child->pr, dr); } } - p = path->pins->data[path->pins->size - 1]; - - path->r = p->pr; - path->jr = p->jpr; - - if (path->bridges) { - - printf("\033[33mbridges:\033[0m\n"); - - for (i = path->bridges->size - 1; i >= 0; i--) { - child = path->bridges->data[i]; - - int ret = __ses_path_jr(f, child); - if (ret < 0) - return ret; - } - } + p = path->pins->data[path->pins->size - 1]; + path->pr = p->pr; + path->sr = p->sr; - scf_loge("path: %d, r: %lg\n\n", path->index, path->r); + scf_loge("path: %d, pr: %lg, sr: %lg\n\n", path->index, path->pr, path->sr); return 0; } @@ -302,8 +179,8 @@ static void __ses_path_parent_jr(ScfEfunction* f, ses_path_t* path) for (i = 0; i < path->childs->size; i++) { sp = path->childs->data[i]; - __ses_path_pr(f, path, 0, sp->parent_p0, NULL, &sp->parent_r0, &sp->parent_jr0); - __ses_path_pr(f, path, sp->parent_p1, path->pins->size - 1, NULL, &sp->parent_r1, &sp->parent_jr1); + __ses_path_pr(f, path, 0, sp->parent_p0, NULL, &sp->parent_r0); + __ses_path_pr(f, path, sp->parent_p1, path->pins->size - 1, NULL, &sp->parent_r1); scf_logw("child: %d, parent_p0: %d, parent_p1: %d, r0: %lg, r1: %lg\n", sp->index, sp->parent_p0, sp->parent_p1, sp->parent_r0, sp->parent_r1); @@ -317,8 +194,8 @@ static void __ses_path_parent_jr(ScfEfunction* f, ses_path_t* path) for (i = 0; i < path->bridges->size; i++) { sp = path->bridges->data[i]; - __ses_path_pr(f, path, 0, sp->parent_p0, NULL, &sp->parent_r0, &sp->parent_jr0); - __ses_path_pr(f, path, sp->parent_p1, path->pins->size - 1, NULL, &sp->parent_r1, &sp->parent_jr1); + __ses_path_pr(f, path, 0, sp->parent_p0, NULL, &sp->parent_r0); + __ses_path_pr(f, path, sp->parent_p1, path->pins->size - 1, NULL, &sp->parent_r1); scf_loge("bridges: %d, parent_p0: %d, parent_p1: %d, r0: %lg, r1: %lg\n", sp->index, sp->parent_p0, sp->parent_p1, sp->parent_r0, sp->parent_r1); diff --git a/ses_step_output.c b/ses_step_output.c index 5bd543d..7b24d91 100644 --- a/ses_step_output.c +++ b/ses_step_output.c @@ -161,6 +161,8 @@ static int _output_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t size_t i; + printf("\n"); + for (i = 0; i < f->n_elines; i++) { el = f->elines[i]; diff --git a/ses_step_va.c b/ses_step_va.c index 3f4b1de..08a9ea2 100644 --- a/ses_step_va.c +++ b/ses_step_va.c @@ -6,8 +6,8 @@ static int __ses_path_split_a(ScfEfunction* f, ses_path_t* path, int i, double* ScfEcomponent* c; ScfEline* el; - ScfEpin* p; - ScfEpin* p2; + ScfEpin* p0; + ScfEpin* p1; ScfEpin* cp0; ScfEpin* cp1; @@ -15,7 +15,7 @@ static int __ses_path_split_a(ScfEfunction* f, ses_path_t* path, int i, double* int k; int n = 0; - p = path->pins->data[i]; + p0 = path->pins->data[i]; for (j = 0; j < path->childs->size; j++) { child = path->childs->data[j]; @@ -23,13 +23,13 @@ static int __ses_path_split_a(ScfEfunction* f, ses_path_t* path, int i, double* cp0 = child->pins->data[0]; cp1 = child->pins->data[child->pins->size - 1]; - if (p->lid != cp0->lid) + if (p0->lid != cp0->lid) continue; for (k = i + 1; k < path->pins->size; k++) { - p2 = path->pins->data[k]; + p1 = path->pins->data[k]; - if (p2->lid == cp1->lid) + if (p1->lid == cp1->lid) break; } @@ -39,26 +39,29 @@ static int __ses_path_split_a(ScfEfunction* f, ses_path_t* path, int i, double* } double r; - double jr; - double v; - double jv; - __ses_path_pr(f, path, i, k, cp1, &r, &jr); + __ses_path_pr(f, path, i, k, child, &r); - ses_ir_u(&v, &jv, *a, *ja, r, jr); + ses_ir_u(&v, NULL, *a, 0, r, 0); scf_logw("child: %d, c%ldp%ld-c%ldp%ld (c%ldp%ld-c%ldp%ld, n_diodes: %d), v: %lg, a: %lg, r: %lg\n", - child->index, p->cid, p->id, p2->cid, p2->id, cp0->cid, cp0->id, cp1->cid, cp1->id, child->n_diodes, v, *a, r); + child->index, p0->cid, p0->id, p1->cid, p1->id, cp0->cid, cp0->id, cp1->cid, cp1->id, child->n_diodes, v, *a, r); - ses_ur_i(&child->a0, &child->ja0, v, jv, child->r, child->jr); + ses_ur_i(&child->a0, NULL, v, 0, child->pr, 0); *a -= child->a0; - *ja -= child->ja0; - el = f->elines[p2->lid]; - el->v = p->v - v; - el->jv = p->jv - jv; + el = f->elines[p1->lid]; + el->v = p0->v - v; + + double _pr = p1->pr; + double _sr = p1->sr; + double _cpr = cp1->pr; + double _csr = cp1->sr; + + cp1->pr = child->pr; + cp1->sr = child->sr; if (child->n_diodes > 0) { __ses_path_va_diode(f, child); @@ -69,8 +72,13 @@ static int __ses_path_split_a(ScfEfunction* f, ses_path_t* path, int i, double* if (ret < 0) return ret; + cp1->pr = _cpr; + cp1->sr = _csr; + p1->pr = _pr; + p1->sr = _sr; + scf_loge("child: %d, c%ldp%ld-c%ldp%ld (c%ldp%ld-c%ldp%ld, n_diodes: %d), p->v: %lg, v: %lg, child->a0: %lg, child->a: %lg\n\n", - child->index, p->cid, p->id, p2->cid, p2->id, cp0->cid, cp0->id, cp1->cid, cp1->id, child->n_diodes, p->v, v, child->a0, child->a); + child->index, p0->cid, p0->id, p1->cid, p1->id, cp0->cid, cp0->id, cp1->cid, cp1->id, child->n_diodes, p0->v, v, child->a0, child->a); n++; } @@ -86,18 +94,15 @@ static void __ses_path_split_v(ScfEfunction* f, ses_path_t* path, int i0, int i, ScfEpin* p = path->pins->data[i]; double v; - double jv; double r; - double jr; - __ses_path_sr(f, path, i0, i, NULL, &r, &jr); + __ses_path_sr(f, path, i0, i, &r); - ses_ir_u(&v, &jv, a, ja, r, jr); + ses_ir_u(&v, NULL, a, 0, r, 0); - p->v = p0->v - v; - p->jv = p0->jv - jv; + p->v = p0->v - v; - scf_logd("c%ldp%ld, c%ldp%ld, a: %lg, r: %lg, v: %lg\n", p0->cid, p0->id, p->cid, p->id, a, r, v); + scf_logd("c%ldp%ld, c%ldp%ld, a: %lg, r: %lg, v: %lg, p0->v: %lg, p->v: %lg\n", p0->cid, p0->id, p->cid, p->id, a, r, v, p0->v, p->v); } int __ses_path_va(ScfEfunction* f, ses_path_t* path, int* changed) @@ -128,37 +133,32 @@ int __ses_path_va(ScfEfunction* f, ses_path_t* path, int* changed) el = f->elines[p0->lid]; p0->v = el->v; - p0->jv = el->jv; el = f->elines[p1->lid]; p1->v = el->v; - p1->jv = el->jv; - - double v = p0->v - p1->v; - double jv = p0->jv - p1->jv; - ses_ur_i(&path->a, &path->ja, v, jv, path->r, path->jr); + double v = p0->v - p1->v; - scf_loge("path: %d, c%ldp%ld-c%ldp%ld, v: %lg, r: %lg, a: %lg\n\n", - path->index, p0->cid, p0->id, p1->cid, p1->id, v, path->r, path->a); + ses_ur_i(&path->a, NULL, v, 0, path->pr, 0); - double a = path->a; - double ja = path->ja; + scf_logw("path: %d, c%ldp%ld-c%ldp%ld, p0->v: %lg, p1->v: %lg, v: %lg, r: %lg, a: %lg\n\n", + path->index, p0->cid, p0->id, p1->cid, p1->id, p0->v, p1->v, v, path->pr, path->a); - double r = 0; - double jr = 0; - double dv = 0; - double jdv = 0; + double a = path->a; + double r = 0; + double dv = 0; int i0 = 0; for (i = 0; i < path->pins->size; i++) { p = path->pins->data[i]; - __ses_path_split_v(f, path, i0, i, a, ja); + scf_logw("c%ldp%ld, p->r: %lg, dr: %lg, sr: %lg, pr: %lg\n", p->cid, p->id, p->r, p->dr, p->sr, p->pr); + + __ses_path_split_v(f, path, i0, i, a, 0); if (!(i & 0x1) && path->childs) { - int ret = __ses_path_split_a(f, path, i, &a, &ja, changed); + int ret = __ses_path_split_a(f, path, i, &a, NULL, changed); if (ret < 0) return ret; @@ -171,24 +171,17 @@ int __ses_path_va(ScfEfunction* f, ses_path_t* path, int* changed) el = f->elines[p->lid]; el->v = p->v; - el->jv = p->jv; - - r += p->r + p->dr; - jr += p->jr + p->jdr; + r += p->r + p->dr; if (i & 0x1) { c = f->components[p->cid]; r += c->r; - jr += c->jr; - dv -= p->v; - jdv -= p->jv; - ses_ur_i(&p->a, &p->ja, dv, jdv, r, jr); + ses_ur_i(&p->a, NULL, dv, 0, r, 0); p2 = path->pins->data[i - 1]; p2->a = p->a; - p2->ja = p->ja; if (path->childs) { for (j = 0; j < path->childs->size; j++) { @@ -197,10 +190,8 @@ int __ses_path_va(ScfEfunction* f, ses_path_t* path, int* changed) cp0 = child->pins->data[0]; cp1 = child->pins->data[child->pins->size - 1]; - if (p->lid == cp1->lid) { - a += child->a0; - ja += child->ja0; - } + if (p->lid == cp1->lid) + a += child->a0; } } @@ -226,16 +217,15 @@ int __ses_path_va(ScfEfunction* f, ses_path_t* path, int* changed) *changed += __ses_status_check(f, c, p2, p); __ses_npn_dr(c, p2, p); + + c->pins[SCF_EDA_NPN_C]->aconst = 1; } } } - r = 0; - jr = 0; + r = 0; } else { - dv = p->v; - jdv = p->jv; - + dv = p->v; scf_loge("path: %d, i: %d, c%ldp%ld, p->v: %lg, dv: %lg, a: %lg, p->pr: %lg\n", path->index, i, p->cid, p->id, p->v, dv, a, p->pr); } } @@ -265,8 +255,6 @@ static int _va_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ct for (i = 0; i < ctx->paths->size; i++) { path = ctx->paths->data[i]; - scf_logi("i: %d, path->index: %d\n", i, path->index); - if (path->pins->size < 2) { scf_loge("\n"); return -EINVAL; @@ -278,11 +266,13 @@ static int _va_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ct if (p0->lid != Bp->lid || p1->lid != Bn->lid) continue; + scf_logi("i: %d, path->index: %d\n", i, path->index); + + __ses_path_jr(f, path); + int ret = __ses_path_va(f, path, &changed); if (ret < 0) return ret; - - printf("\n"); } ctx->changed += changed; diff --git a/ses_step_va_balance.c b/ses_step_va_balance.c deleted file mode 100644 index 16fc24c..0000000 --- a/ses_step_va_balance.c +++ /dev/null @@ -1,245 +0,0 @@ -#include"ses_core.h" - -static void inline __ses_bridge_i(double* i0, double* i1, double* i2, double* i3, double* i4, - double* v0, double* v1, double* v4, double V, - double R0, double R1, double R2, double R3, double R4, - double vd0, double vd1, double vd2, double vd3, double vd4) -{ - double N0 = R3 * (R0 + R1) + R4 * (R1 + R3); - double N2 = (R1 + R3) * (R2 + R4) + R3 * (R1 - R2); - double RV02 = R1 * (vd2 + vd4 - vd3) + R3 * (vd1 + vd4 - vd0); -/* - N0 i0 - N2 i2 = RV02 - R0 i0 + R2 i2 = V - vd0 - vd1 - */ - *i2 = (N0 * (V - vd0 - vd1) - R0 * RV02) / (N0 * R2 + R0 * N2); - *i0 = (N2 * *i2 + RV02) / N0; - *i4 = *i2 - *i0; - - *i1 = (*i0 * R0 + vd0 - *i4 * R4 - vd4 - vd1) / R1; - *i3 = *i1 - *i4; - - *v0 = *i2 * R2 + vd2; - *v1 = *i3 * R3 + vd3; - *v4 = *i4 * R4 + vd4; -} - -static size_t __ses_line_update(ScfEfunction* f, ScfEline* el) -{ - ScfEcomponent* c; - ScfEpin* p; - ScfEpin* p2; - - size_t n = 0; - size_t i; - - for (i = 0; i + 1 < el->n_pins; i += 2) { - - c = f->components[el->pins[i]]; - p = c->pins [el->pins[i + 1]]; - p->v = el->v; - - if (SCF_EDA_Diode == c->type) { - - if (SCF_EDA_Diode_POS == p->id) { - - p2 = c->pins[SCF_EDA_Diode_NEG]; - n += __ses_status_check(f, c, p, p2); - - } else { - p2 = c->pins[SCF_EDA_Diode_POS]; - n += __ses_status_check(f, c, p2, p); - } - - } else if (SCF_EDA_NPN == c->type) { - - if (SCF_EDA_NPN_B == p->id) { - - p2 = c->pins[SCF_EDA_NPN_E]; - n += __ses_status_check(f, c, p, p2); - - } else if (SCF_EDA_NPN_E == p->id) { - - p2 = c->pins[SCF_EDA_NPN_B]; - n += __ses_status_check(f, c, p2, p); - } - } - } - - return n; -} - -static int __ses_path_va_balance(ScfEfunction* f, ses_path_t* bridge, ses_flow_t* flow0, ses_flow_t* flow1) -{ - if (!bridge || !flow0 || !flow1) - return -EINVAL; - - if (bridge->pins->size < 2) { - scf_loge("\n"); - return -EINVAL; - } - - ScfEcomponent* c; - ScfEline* el; - ScfEpin* p; - ScfEpin* p0 = bridge->pins->data[0]; - ScfEpin* p1 = bridge->pins->data[bridge->pins->size - 1]; - - ses_path_t* path0 = flow0->paths->data[flow0->paths->size - 1]; - ses_path_t* path1 = flow1->paths->data[flow1->paths->size - 1]; - - ScfEpin* p0p0 = path0->pins->data[0]; - ScfEpin* p0p1 = path0->pins->data[path0->pins->size - 1]; - - ScfEpin* p1p0 = path1->pins->data[0]; - ScfEpin* p1p1 = path1->pins->data[path1->pins->size - 1]; - - int i; - int j; - int k; - - el = f->elines[p0->lid]; - p0->v = el->v; - p0->jv = el->jv; - - el = f->elines[p1->lid]; - p1->v = el->v; - p1->jv = el->jv; - - scf_loge("p0: %lg, p1: %lg, diff: %lg, bridge->r: %lg\n", p0->v, p1->v, p0->v - p1->v, bridge->r); - - if (p0->v > p1->v) { - - double v = p0p0->v - p1p1->v; - - double a0; - double a1; - double a2; - double a3; - double a4; - double v0; - double v1; - double v4; - - __ses_bridge_i(&a0, &a1, &a2, &a3, &a4, &v0, &v1, &v4, v, - flow1->pos_r, flow0->pos_r, flow1->neg_r, flow0->neg_r, 0, - 0, 0, 0, 0, - bridge->n_diodes * SCF_EDA_V_Diode_ON); - - scf_loge("v: %lg, a0: %lg, a1: %lg, a2: %lg, a3: %lg, a4: %lg\n", v, a0, a1, a2, a3, a4); - scf_loge("v0: %lg, v1: %lg, v4: %lg, v1 - v0: %lg\n", v0, v1, v4, v1 - v0); - - el = f->elines[p0->lid]; - el->v = v1; - - el = f->elines[p1->lid]; - el->v = v0; - - size_t n0 = __ses_line_update(f, f->elines[p0->lid]); - size_t n1 = __ses_line_update(f, f->elines[p1->lid]); - - return n0 + n1 > 0; - - } else { - - } - - return 0; -} - -static int _va_balance_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) -{ - ses_flow_t* flow0; - ses_flow_t* flow1; - ses_path_t* bridge; - - ScfEcomponent* B; - ScfEpin* p0; - ScfEpin* p1; - ScfEpin* Bp; - ScfEpin* Bn; - - B = f->components[0]; - Bp = B->pins[SCF_EDA_Battery_POS]; - Bn = B->pins[SCF_EDA_Battery_NEG]; - - printf("\n*******************\n"); - - flow0 = ses_flow_alloc(); - if (!flow0) - return -ENOMEM; - - flow1 = ses_flow_alloc(); - if (!flow1) { - ses_flow_free(flow0); - return -ENOMEM; - } - - int n = 0; - int i; - - for (i = 0; i < ctx->paths->size; i++) { - bridge = ctx->paths->data[i]; - - if (bridge->pins->size < 2) { - scf_loge("\n"); - return -EINVAL; - } - - p0 = bridge->pins->data[0]; - p1 = bridge->pins->data[bridge->pins->size - 1]; - - if (p0->lid == Bp->lid || p1->lid == Bn->lid) - continue; - - scf_logi("i: %d, bridge->type: %d\n", i, bridge->type); - - ses_path_print(bridge); - - flow0->paths->size = 0; - flow1->paths->size = 0; - - int ret = ses_paths_find_flow(flow0, ctx->paths, p0, bridge); - if (ret < 0) - return ret; - - ret = ses_paths_find_flow(flow1, ctx->paths, p1, bridge); - if (ret < 0) - return ret; - - ses_flow_print(flow0); - printf("\n"); - - ses_flow_jr(flow0, f); - - printf("-------------\n"); - - ses_flow_print(flow1); - printf("\n"); - - ses_flow_jr(flow1, f); - printf("-------------\n"); - - ret = __ses_path_va_balance(f, bridge, flow0, flow1); - if (ret < 0) - return ret; - - n += ret; - - printf("\n"); - } - - ses_flow_free(flow0); - ses_flow_free(flow1); - - if (n > 0) - return -EAGAIN; - return 0; -} - -ses_step_t ses_step_va_balance = -{ - .name = "va_balance", - - .handler = _va_balance_handler, -}; diff --git a/ses_step_va_bridge.c b/ses_step_va_bridge.c index 76d2fa1..d2bc45d 100644 --- a/ses_step_va_bridge.c +++ b/ses_step_va_bridge.c @@ -1,6 +1,6 @@ #include"ses_core.h" -int __ses_flow_a_pos(ScfEfunction* f, ses_flow_t* flow, double da_vip, double dja_vip, int* changed) +int __ses_flow_a_pos(ScfEfunction* f, ses_flow_t* flow, double da_vip, int* changed) { if (!flow || !flow->paths || flow->paths->size <= 0 || !flow->vip) return -EINVAL; @@ -16,9 +16,8 @@ int __ses_flow_a_pos(ScfEfunction* f, ses_flow_t* flow, double da_vip, double dj ScfEline* el; double v; - double jv; - ses_ir_u(&v, &jv, da_vip, dja_vip, flow->pos_r, flow->pos_jr); + ses_ir_u(&v, NULL, da_vip, 0, flow->pos_r, 0); int i; int j; @@ -26,8 +25,7 @@ int __ses_flow_a_pos(ScfEfunction* f, ses_flow_t* flow, double da_vip, double dj for (i = 0; i < flow->paths->size; i++) { path = flow->paths->data[i]; - double r = 0; - double jr = 0; + double r = 0; int j0 = -1; for (j = path->pins->size - 1; j >= 0; j--) { @@ -40,34 +38,27 @@ int __ses_flow_a_pos(ScfEfunction* f, ses_flow_t* flow, double da_vip, double dj continue; } - r += p->r + p->dr; - jr += p->jr + p->jdr; + r += p->r + p->dr; if (!(j & 0x1)) { - c = f->components[p->cid]; - r += c->r; - jr += c->jr; + c = f->components[p->cid]; + r += c->r; - ses_ir_u(&v, &jv, da_vip, dja_vip, r, jr); + ses_ir_u(&v, NULL, da_vip, 0, r, 0); } el = f->elines[p->lid]; if (p->lid != Bp->lid && p->v - v < Bp->lid) { p->v -= v; - p->jv -= jv; - el->v = p->v; - el->jv = p->jv; } - p->a += da_vip; - p->ja += dja_vip; + p->a += da_vip; scf_logw("c%ldp%ld->v: %lg, p->a: %lg, r: %lg, l%ld->v: %lg\n", p->cid, p->id, p->v, p->a, r, el->id, el->v); if (!(j & 0x1)) { r = 0; - jr = 0; } } @@ -77,7 +68,7 @@ int __ses_flow_a_pos(ScfEfunction* f, ses_flow_t* flow, double da_vip, double dj return 0; } -int __ses_flow_v_neg(ScfEfunction* f, ses_flow_t* flow, double dv_vip, double djv_vip, int* changed) +int __ses_flow_v_neg(ScfEfunction* f, ses_flow_t* flow, double dv_vip, int* changed) { if (!flow || !flow->paths || flow->paths->size <= 0 || !flow->vip) return -EINVAL; @@ -93,11 +84,8 @@ int __ses_flow_v_neg(ScfEfunction* f, ses_flow_t* flow, double dv_vip, double dj ScfEpin* p2; ScfEline* el; - double v = dv_vip; - double jv = djv_vip; - + double v = dv_vip; double da; - double dja; int i; int j; @@ -105,8 +93,7 @@ int __ses_flow_v_neg(ScfEfunction* f, ses_flow_t* flow, double dv_vip, double dj for (i = 0; i < flow->paths->size; i++) { path = flow->paths->data[i]; - double r = 0; - double jr = 0; + double r = 0; int j0 = -1; for (j = 0; j < path->pins->size; j++) { @@ -116,37 +103,30 @@ int __ses_flow_v_neg(ScfEfunction* f, ses_flow_t* flow, double dv_vip, double dj if (!(j & 0x1) && p->lid == vip->lid) { j0 = j; - ses_ur_i(&da, &dja, vip->v, vip->jv, flow->neg_r, flow->neg_jr); + ses_ur_i(&da, NULL, vip->v, 0, flow->neg_r, 0); - da -= p->a; - dja -= p->ja; + da -= p->a; } else continue; } - r += p->r + p->dr; - jr += p->jr + p->jdr; + r += p->r + p->dr; if (j & 0x1) { - c = f->components[p->cid]; - r += c->r; - jr += c->jr; + c = f->components[p->cid]; + r += c->r; - ses_ir_u(&v, &jv, da, dja, r, jr); + ses_ir_u(&v, NULL, da, 0, r, 0); } el = f->elines[p->lid]; if (p->lid != Bn->lid && p->v + v > Bn->lid) { p->v += v; - p->jv += jv; - el->v = p->v; - el->jv = p->jv; } - p->a += da; - p->ja += dja; + p->a += da; scf_logw("c%ldp%ld->v: %lg, p->a: %lg, r: %lg, v: %lg, da: %lg\n", p->cid, p->id, p->v, p->a, r, v, da); @@ -159,7 +139,6 @@ int __ses_flow_v_neg(ScfEfunction* f, ses_flow_t* flow, double dv_vip, double dj *changed += __ses_status_check(f, c, p2, p); __ses_pn_dr(c, p2, p); - } } else if (SCF_EDA_NPN == c->type) { @@ -175,8 +154,7 @@ int __ses_flow_v_neg(ScfEfunction* f, ses_flow_t* flow, double dv_vip, double dj } } - r = 0; - jr = 0; + r = 0; } } @@ -186,6 +164,86 @@ int __ses_flow_v_neg(ScfEfunction* f, ses_flow_t* flow, double dv_vip, double dj return 0; } +static int __ses_bridge_v(ScfEfunction* f, ses_path_t* bridge, double vmin, ses_flow_t* flow) +{ + ScfEline* el; + ScfEpin* p0 = bridge->pins->data[0]; + ScfEpin* p1 = bridge->pins->data[bridge->pins->size - 1]; + + double da; + double v; + double dv; + + double a = 0; + double Eta = 0.001; + + int __changed = 0; + int k = 0; + + while (p0->v - p1->v > vmin) { + + scf_logw("k: %d, ****************\n", k); + + el = f->elines[p0->lid]; + p0->v = el->v; + + el = f->elines[p1->lid]; + p1->v = el->v; + + if (bridge->n_diodes > 0) { + __ses_path_va_diode(f, bridge); + __ses_path_jr (f, bridge); + } + + __changed = 0; + + int ret = __ses_path_va(f, bridge, &__changed); + if (ret < 0) + return ret; + + da = bridge->a - a; + a += Eta * da; + + scf_loge("da: %lg, a: %lg, bridge->a: %lg, bridge->pr: %lg, p0->v: %lg, p1->v: %lg, diff: %lg, vmin: %lg\n", + da, a, bridge->a, bridge->pr, p0->v, p1->v, p0->v - p1->v, vmin); + + v = flow->vip->v; + + ret = __ses_flow_a_pos(f, flow, Eta * da, &__changed); + if (ret < 0) + return ret; + + dv = flow->vip->v - v; + + scf_logi("dv: %lg, v: %lg - %lg ----------------\n", dv, flow->vip->v, v); + + ret = __ses_flow_v_neg(f, flow, dv, &__changed); + if (ret < 0) + return ret; + + scf_logw("flow vip: c%ldp%ld->a: %lg, vip_n: c%ldp%ld->a: %lg, bridge->a: %lg, diff: %lg\n\n", + flow->vip->cid, flow->vip->id, flow->vip->a, + flow->vip_n->cid, flow->vip_n->id, flow->vip_n->a, + bridge->a, + flow->vip->a - flow->vip_n->a - bridge->a); + + ses_flow_jr(flow, f); + + if (__changed > 0 + || fabs(dv) < 0.001 + || fabs(flow->vip->a - flow->vip_n->a - bridge->a) < 1e-4) + break; + k++; + } + + return __changed; +} + +static int __ses_bridge_r(ScfEfunction* f, ses_path_t* bridge, int vmin, ses_flow_t* flow) +{ + return 0; +} + static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* bridge, int* changed, scf_vector_t* paths) { if (!bridge) @@ -198,6 +256,7 @@ static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* bridge, int* change ses_flow_t* flow; ses_path_t* fpath; + ses_info_t* info; ScfEcomponent* B; ScfEline* el; @@ -216,6 +275,8 @@ static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* bridge, int* change if (p0->lid == Bp->lid && p1->lid == Bn->lid) return 0; + __ses_path_jr(f, bridge); + flow = ses_flow_alloc(); if (!flow) return -ENOMEM; @@ -231,85 +292,56 @@ static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* bridge, int* change fpath = flow->paths->data[flow->paths->size - 1]; - scf_logw("flow vip: c%ldp%ld->a: %lg, vip_n: c%ldp%ld->a: %lg\n\n", - flow->vip->cid, flow->vip->id, flow->vip->a, flow->vip_n->cid, flow->vip_n->id, flow->vip_n->a); - - double da; - double dja; + scf_logw("flow vip: c%ldp%ld->a: %lg, v:%lg, vip_n: c%ldp%ld->a: %lg, v: %lg\n\n", + flow->vip->cid, flow->vip->id, flow->vip->a, flow->vip->v, flow->vip_n->cid, flow->vip_n->id, flow->vip_n->a, flow->vip_n->v); double v; double jv; + double vmin = 0; + int i; - double a = 0; - double ja = 0; - double Eta = 0.001; + for (i = 0; i < bridge->diodes->size; i++) { + info = bridge->diodes->data[i]; - int __changed = 0; - - int k = 0; - do { - scf_logw("k: %d, ****************\n", k); - - el = f->elines[p0->lid]; - p0->v = el->v; - p0->jv = el->jv; - - el = f->elines[p1->lid]; - p1->v = el->v; - p1->jv = el->jv; - - if (bridge->n_diodes > 0) { - __ses_path_va_diode(f, bridge); - __ses_path_jr (f, bridge); - } - - __changed = 0; - - ret = __ses_path_va(f, bridge, &__changed); - if (ret < 0) - return ret; - - da = bridge->a - a; - dja = bridge->ja - ja; - - a += Eta * da; - ja += Eta * dja; + vmin += info->n_diodes * SCF_EDA_V_Diode_ON + info->n_NPNs * SCF_EDA_V_NPN_ON; + } - scf_loge("da: %lg, a: %lg, bridge->a: %lg, bridge->r: %lg, p0->v: %lg, p1->v: %lg\n", - da, a, bridge->a, bridge->r, p0->v, p1->v); + el = f->elines[p0->lid]; + p0->v = el->v; - v = flow->vip->v; - jv = flow->vip->jv; + el = f->elines[p1->lid]; + p1->v = el->v; - ret = __ses_flow_a_pos(f, flow, Eta * da, Eta * dja, &__changed); - if (ret < 0) - return ret; + if (bridge->n_diodes > 0) { + __ses_path_va_diode(f, bridge); + __ses_path_jr (f, bridge); + } - double dv = flow->vip->v - v; - double djv = flow->vip->jv - jv; + int __changed = 0; - scf_logi("dv: %lg, v: %lg - %lg ----------------\n", dv, flow->vip->v, v); + ret = __ses_path_va(f, bridge, &__changed); + if (ret < 0) + return ret; +#if 0 + if (0 == __changed) { - ret = __ses_flow_v_neg(f, flow, dv, djv, &__changed); + ret = __ses_bridge_v(f, bridge, vmin, flow); if (ret < 0) return ret; - scf_logw("flow vip: c%ldp%ld->a: %lg, vip_n: c%ldp%ld->a: %lg, bridge->a: %lg, diff: %lg\n\n", - flow->vip->cid, flow->vip->id, flow->vip->a, - flow->vip_n->cid, flow->vip_n->id, flow->vip_n->a, - bridge->a, - flow->vip->a - flow->vip_n->a - bridge->a); - - ses_flow_jr(flow, f); - k++; - } while (0 == __changed && fabs(flow->vip->a - flow->vip_n->a - bridge->a) > 1e-4); - + if (0 == ret) { + ret = __ses_bridge_r(f, bridge, vmin, flow); + if (ret < 0) + return ret; + } else + __changed = ret; + } +#endif v = p0->v - p1->v; - jv = p0->jv - p1->jv; changed += __changed; - scf_loge("bridge: %d, c%ldp%ld--c%ldp%ld, __changed: %d, v: %lg, p0->v: %lg, p1->v: %lg, n_diodes: %d, p0->a: %lg, p1->a: %lg\n", + scf_loge("bridge: %d, c%ldp%ld--c%ldp%ld, __changed: %d, v: %lg, p0->v: %lg, p1->v: %lg, n_diodes: %d, p0->a: %lg, p1->a: %lg\n\n", bridge->index, p0->cid, p0->id, p1->cid, p1->id, __changed, v, p0->v, p1->v, bridge->n_diodes, p0->a, p1->a); return 0; @@ -369,8 +401,6 @@ static int _va_bridge_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ct int ret = ses_path_va_bridge(f, path, &changed, ctx->paths); if (ret < 0) return ret; - - printf("\n"); } ctx->changed += changed; diff --git a/ses_step_va_diode.c b/ses_step_va_diode.c index 8ba13bd..0c1d4b6 100644 --- a/ses_step_va_diode.c +++ b/ses_step_va_diode.c @@ -1,6 +1,6 @@ #include"ses_core.h" -void __ses_path_split_i(ScfEfunction* f, ses_path_t* path, int i, int j, double la, double jla, double* a, double* ja) +void __ses_path_split_i(ScfEfunction* f, ses_path_t* path, int i, int j, double la, double* a) { ScfEcomponent* c; ses_path_t* child; @@ -10,13 +10,10 @@ void __ses_path_split_i(ScfEfunction* f, ses_path_t* path, int i, int j, double ScfEpin* p0 = path->pins->data[i]; ScfEpin* p1 = path->pins->data[j]; - double v = p0->v - p1->v; - double jv = p0->jv - p1->jv; - + double v = p0->v - p1->v; double r; - double jr; - __ses_path_pr(f, path, i, j, NULL, &r, &jr); + __ses_path_pr(f, path, i, j, NULL, &r); scf_loge("c%ldp%ld--c%ldp%ld, r: %lg\n", p0->cid, p0->id, p1->cid, p1->id, r); @@ -30,42 +27,38 @@ void __ses_path_split_i(ScfEfunction* f, ses_path_t* path, int i, int j, double if (cp0->lid != p0->lid || cp1->lid != p1->lid) continue; - if (0 == child->n_diodes) { + ses_ur_i(&child->a, NULL, v, 0, child->pr, 0); + + if (child->a >= la) + ses_split_i(&child->a, NULL, la, 0, child->pr, 0, r, 0); - ses_ur_i(&child->a, &child->ja, v, jv, child->r, child->jr); + *a -= child->a; - if (child->a >= la) - ses_split_i(&child->a, &child->ja, la, jla, child->r, child->jr, r, jr); + double _sr = cp1->sr; + double _pr = cp1->pr; - scf_logw("j: %d, c%ldp%ld--c%ldp%ld, v: %lg, child->r: %lg, r: %lg, child->a: %lg, el->a: %lg\n", - j, cp0->cid, cp0->id, cp1->cid, cp1->id, v, child->r, r, child->a, la); + cp1->sr = child->sr; + cp1->pr = child->pr; + + if (child->n_diodes > 0) { - } else { int ret = __ses_path_va_diode(f, child); if (ret < 0) - ses_split_i(&child->a, &child->ja, la, jla, child->r, child->jr, r, jr); - - scf_loge("j: %d, c%ldp%ld--c%ldp%ld, v: %lg, child->r: %lg, r: %lg, child->a: %lg, el->a: %lg\n", - j, cp0->cid, cp0->id, cp1->cid, cp1->id, v, child->r, r, child->a, la); + ses_split_i(&child->a, NULL, la, 0, child->pr, 0, r, 0); } - *a -= child->a; - *ja -= child->ja; + scf_logi("j: %d, c%ldp%ld--c%ldp%ld, v: %lg, child->pr: %lg, r: %lg, child->a: %lg, el->a: %lg\n", + j, cp0->cid, cp0->id, cp1->cid, cp1->id, v, child->pr, r, child->a, la); - cp1->v = p1->v; - cp1->jv = p1->jv; + cp1->v = p1->v; + cp0->v = p0->v; - cp0->v = p0->v; - cp0->jv = p0->jv; - - double ca = child->a; - double cja = child->ja; + double ca = child->a; if (child->childs) - __ses_path_split_i(f, child, 0, child->pins->size - 1, child->a, child->ja, &ca, &cja); + __ses_path_split_i(f, child, 0, child->pins->size - 1, child->a, &ca); - cp0->a = ca; - cp0->ja = cja; + cp0->a = ca; c = f->components[cp1->cid]; @@ -74,16 +67,16 @@ void __ses_path_split_i(ScfEfunction* f, ses_path_t* path, int i, int j, double else p = cp1; - ses_ui_r(&p->dr, &p->jdr, v, jv, ca, cja); + ses_ui_r(&p->dr, NULL, v, 0, ca, 0); - p->dr -= p->sr; - p->jdr -= p->jsr; + p->dr -= cp1->sr; + p->a = ca; - p->a = ca; - p->ja = cja; + cp1->sr = _sr; + cp1->pr = _pr; - scf_loge("j: %d, c%ldp%ld--c%ldp%ld, v: %lg, child->r: %lg, r: %lg, cp1->a: %lg, el->a: %lg, c%ldp%ld->dr: %lg\n", - j, cp0->cid, cp0->id, cp1->cid, cp1->id, v, child->r, r, p->a, la, p->cid, p->id, p->dr); + scf_logi("j: %d, c%ldp%ld--c%ldp%ld, v: %lg, child->pr: %lg, r: %lg, cp1->a: %lg, el->a: %lg, c%ldp%ld->dr: %lg\n\n", + j, cp0->cid, cp0->id, cp1->cid, cp1->id, v, child->pr, r, p->a, la, p->cid, p->id, p->dr); } } @@ -105,39 +98,33 @@ void __ses_path_dr_forward(ScfEfunction* f, ses_path_t* path, int i, int j, doub if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_NEG == p->id) { - ses_ui_r(&p->dr, &p->jdr, SCF_EDA_V_Diode_ON, 0, a, ja); + ses_ui_r(&p->dr, NULL, SCF_EDA_V_Diode_ON, 0, a, 0); - p->dr -= p->r; - p->jdr -= p->jr; + p->dr -= p->r; 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 = ja; + 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, SCF_EDA_V_NPN_ON, 0, a, ja); + ses_ui_r(&p->dr, NULL, SCF_EDA_V_NPN_ON, 0, a, 0); - p->dr -= p->r; - p->jdr -= p->jr; + p->dr -= p->r; - p1 = c->pins[SCF_EDA_NPN_C]; - p1->a = p1->hfe * a; - p1->ja = p1->hfe * ja; + p1 = c->pins[SCF_EDA_NPN_C]; + p1->a = p1->hfe * a; p1->aconst = 1; 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_ON, p->r, a, p->dr, p1->cid, p1->id, p1->a); - p1 = c->pins[SCF_EDA_NPN_E]; - p1->a = (1 + p1->hfe) * a; - p1->ja = (1 + p1->hfe) * ja; + p1 = c->pins[SCF_EDA_NPN_E]; + p1->a = (1 + p1->hfe) * a; p1->aconst = 1; - a = p1->a; - ja = p1->ja; + a = p1->a; } } } @@ -148,7 +135,6 @@ void __ses_path_dr_reverse(ScfEfunction* f, ses_path_t* path, int i, int j, doub ScfEpin* p1 = path->pins->data[j]; double r; - double jr; int k; for (k = j; k >= i; k--) { @@ -160,44 +146,38 @@ void __ses_path_dr_reverse(ScfEfunction* f, ses_path_t* path, int i, int j, doub if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_NEG == p->id) { - ses_ui_r(&p->dr, &p->jdr, SCF_EDA_V_Diode_ON, 0, a, ja); + ses_ui_r(&p->dr, NULL, SCF_EDA_V_Diode_ON, 0, a, 0); - p->dr -= p->r; - p->jdr -= p->jr; + p->dr -= p->r; 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 = ja; + p1 = c->pins[SCF_EDA_Diode_POS]; + p1->a = a; } else if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_B == p->id) { - p1 = c->pins[SCF_EDA_NPN_E]; - p1->a = a; - p1->ja = ja; + p1 = c->pins[SCF_EDA_NPN_E]; + p1->a = a; p1->aconst = 1; p1 = c->pins[SCF_EDA_NPN_C]; a /= (1 + p1->hfe); - ja /= (1 + p1->hfe); - p1->a = p1->hfe * a; - p1->ja = p1->hfe * ja; + p1->a = p1->hfe * a; p1->aconst = 1; - ses_ui_r(&p->dr, &p->jdr, SCF_EDA_V_NPN_ON, 0, a, ja); + ses_ui_r(&p->dr, NULL, SCF_EDA_V_NPN_ON, 0, a, 0); - p->dr -= p->r; - p->jdr -= p->jr; + p->dr -= p->r; scf_logw("c%ldp%ld, v: %lg, r: %lg, a: %lg, dr: %lg\n", p->cid, p->id, SCF_EDA_V_NPN_ON, p->r, a, p->dr); } } } -static void __ses_path_a_diode(ScfEfunction* f, ses_path_t* path, int k, double* a, double* ja) +static void __ses_path_a_diode(ScfEfunction* f, ses_path_t* path, int k, double* a) { ses_info_t* info; @@ -206,11 +186,10 @@ static void __ses_path_a_diode(ScfEfunction* f, ses_path_t* path, int k, double* ScfEpin* pi; ScfEpin* pj; - double v = p0->v - p1->v; - double jv = p0->jv - p1->jv; + double v = p0->v - p1->v; + double r = 0; - double r = 0; - double jr = 0; + double _r; int i = 0; int j; @@ -220,16 +199,12 @@ static void __ses_path_a_diode(ScfEfunction* f, ses_path_t* path, int k, double* pi = path->pins->data[i]; pj = path->pins->data[info->i]; - v -= info->n_diodes * SCF_EDA_V_Diode_ON; - v -= info->n_NPNs * SCF_EDA_V_NPN_ON; - - double _r; - double _jr; + v -= info->n_diodes * SCF_EDA_V_Diode_ON; + v -= info->n_NPNs * SCF_EDA_V_NPN_ON; - __ses_path_pr(f, path, i, info->i, NULL, &_r, &_jr); + __ses_path_pr(f, path, i, info->i, NULL, &_r); - r += _r; - jr += _jr; + r += _r; scf_logd("c%ldp%ld--c%ldp%ld, r: %lg, v: %lg, _r: %lg\n", pi->cid, pi->id, pj->cid, pj->id, r, v, _r); @@ -241,14 +216,12 @@ static void __ses_path_a_diode(ScfEfunction* f, ses_path_t* path, int k, double* if (i < path->pins->size - 1) { pi = path->pins->data[i]; - r += p1->sr - p1->r - pi->pr; - jr += p1->jsr - p1->jr - pi->jpr; + __ses_path_pr(f, path, i, path->pins->size - 1, NULL, &_r); - scf_logd("c%ldp%ld--c%ldp%ld, r: %lg, v: %lg, pi->pr: %lg, p1->sr: %lg, p1->r: %lg\n", - pi->cid, pi->id, p1->cid, p1->id, r, v, pi->pr, p1->sr, p1->r); + r += _r; } - ses_ur_i(a, ja, v, jv, r, jr); + ses_ur_i(a, NULL, v, 0, r, 0); scf_loge("c%ldp%ld--c%ldp%ld, r: %lg, v: %lg, a: %lg\n\n", p0->cid, p0->id, p1->cid, p1->id, r, v, *a); } @@ -280,20 +253,13 @@ int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) el = f->elines[p0->lid]; p0->v = el->v; - p0->jv = el->jv; el = f->elines[p1->lid]; p1->v = el->v; - p1->jv = el->jv; double v; - double jv; - double r; - double jr; - double a; - double ja; for (j = 0; j < path->diodes->size; j++) { info = path->diodes->data[j]; @@ -305,50 +271,43 @@ int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) assert((SCF_EDA_Diode == c->type && SCF_EDA_Diode_POS == pi->id) || (SCF_EDA_NPN == c->type && SCF_EDA_NPN_B == pi->id)); - __ses_path_a_diode(f, path, j, &a, &ja); + __ses_path_a_diode(f, path, j, &a); - if (0 == j) { - path->a = a; - path->ja = ja; - } + if (a < 0) + break; - pi->a = a; - pi->ja = ja; + if (0 == j) + path->a = a; - __ses_path_pr(f, path, 0, info->i, NULL, &r, &jr); + pi->a = a; - ses_ir_u(&v, &jv, a, ja, r, jr); + __ses_path_pr(f, path, 0, info->i, NULL, &r); - pi->v = p0->v - v; - pi->jv = p0->jv - jv; + ses_ir_u(&v, NULL, a, 0, r, 0); - pj->v = pi->v - info->n_diodes * SCF_EDA_V_Diode_ON - info->n_NPNs * SCF_EDA_V_NPN_ON; - pj->jv = pi->jv; + pi->v = p0->v - v; + pj->v = pi->v - info->n_diodes * SCF_EDA_V_Diode_ON - info->n_NPNs * SCF_EDA_V_NPN_ON; scf_logi("c%ldp%ld->v: %lg, c%ldp%ld->v: %lg, c%ldp%ld->v: %lg, r: %lg, v: %lg, a: %lg\n", p0->cid, p0->id, p0->v, pi->cid, pi->id, pi->v, pj->cid, pj->id, pj->v, r, v, a); el = f->elines[pi->lid]; el->a = a; - el->ja = ja; el->v = pi->v; - el->jv = pi->jv; el->aconst = 1; el = f->elines[pj->lid]; el->a = a; - el->ja = ja; el->v = pj->v; - el->jv = pj->jv; el->aconst = 1; if (path->childs) - __ses_path_split_i(f, path, info->i, info->j, a, ja, &pi->a, &pi->ja); + __ses_path_split_i(f, path, info->i, info->j, a, &pi->a); scf_loge("info->i: %d, info->j: %d, c%ldp%ld--c%ldp%ld, pi->v: %lg, pj->v: %lg, pi->a: %lg\n\n", info->i, info->j, pi->cid, pi->id, pj->cid, pj->id, pi->v, pj->v, pi->a); - __ses_path_dr_forward(f, path, info->i, info->j, pi->a, pi->ja); + __ses_path_dr_forward(f, path, info->i, info->j, pi->a, 0); } return 0; @@ -384,6 +343,8 @@ static int ses_path_va_diode(ScfEfunction* f, ses_path_t* path) if (p0->lid != Bp->lid || p1->lid != Bn->lid) return 0; + __ses_path_jr(f, path); + int ret = __ses_path_va_diode(f, path); if (ret < 0) return ret; diff --git a/ses_step_va_line.c b/ses_step_va_line.c new file mode 100644 index 0000000..823193f --- /dev/null +++ b/ses_step_va_line.c @@ -0,0 +1,30 @@ +#include"ses_core.h" + +static int _va_line_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) +{ + ScfEcomponent* B = f->components[0]; + ScfEpin* Bp = B->pins[SCF_EDA_Battery_POS]; + ScfEpin* Bn = B->pins[SCF_EDA_Battery_NEG]; + ScfEline* el; + + int i; + for (i = 0; i < f->n_elines; i++) { + el = f->elines[i]; + + if (el->vinit) { + scf_logw("el%ld->v: %lg\n", el->id, el->v); + + el->v = SCF_EDA_V_INIT; + el->vinit = 0; + } + } + + return 0; +} + +ses_step_t ses_step_va_line = +{ + .name = "va_line", + + .handler = _va_line_handler, +}; diff --git a/ses_step_va_transistor.c b/ses_step_va_transistor.c index 2cfaa7c..eb33d4c 100644 --- a/ses_step_va_transistor.c +++ b/ses_step_va_transistor.c @@ -5,21 +5,18 @@ void __ses_path_dr_transistor(ScfEfunction* f, ses_path_t* path, int i, int j) 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 v = p->v - p1->v; double r; - double jr; + double dr; - __ses_path_sr(f, path, i, j, NULL, &r, &jr); + __ses_path_sr(f, path, i, j, &r); - ses_ui_r(&p->dr, &p->jdr, v, jv, p->a, p->ja); + ses_ui_r(&dr, NULL, v, 0, p->a, 0); - p->dr -= r; - p->jdr -= jr; + p->dr = dr - r; - scf_logi("c%ldp%ld--c%ldp%ld, v: %lg, r: %lg, p->sr: %lg, p->a: %lg, p->dr: %lg\n", - p->cid, p->id, p1->cid, p1->id, v, r, p->sr, p->a, p->dr); + scf_logi("c%ldp%ld--c%ldp%ld, v: %lg, r: %lg, dr: %lg, p->sr: %lg, p->a: %lg, p->dr: %lg\n", + p->cid, p->id, p1->cid, p1->id, v, r, dr, p->sr, p->a, p->dr); } int __ses_status_check(ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe) @@ -82,9 +79,9 @@ int __ses_status_check(ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* _changed: if (SCF_EDA_NPN == c->type) { - p2 = c->pins [SCF_EDA_NPN_C]; - el = f->elines[p2->lid]; - el->v = SCF_EDA_V_INIT; + p2 = c->pins [SCF_EDA_NPN_C]; + el = f->elines[p2->lid]; + el->vinit = 1; for (i = 0; i + 1 < el->n_pins; i += 2) { @@ -111,25 +108,13 @@ static int __ses_path_va_transistor(ScfEfunction* f, ses_path_t* path) ses_path_t* child; ScfEcomponent* c; - ScfEcomponent* B; ScfEline* el; ScfEpin* p0; ScfEpin* pj; - ScfEpin* Bp; - ScfEpin* Bn; ScfEpin* p; ScfEpin* pc; - B = f->components[0]; - Bp = B->pins[SCF_EDA_Battery_POS]; - Bn = B->pins[SCF_EDA_Battery_NEG]; - - if (path->parent) { - Bp = parent->pins->data[0]; - Bn = parent->pins->data[parent->pins->size - 1]; - } - int i; int j = path->pins->size - 1; @@ -138,24 +123,18 @@ static int __ses_path_va_transistor(ScfEfunction* f, ses_path_t* path) el = f->elines[p0->lid]; p0->v = el->v; - p0->jv = el->jv; el = f->elines[pj->lid]; pj->v = el->v; - pj->jv = el->jv; for (i = path->pins->size - 1; i >= 0; i--) { pc = path->pins->data[i]; pj = path->pins->data[j]; double v; - double jv; - + double a; double pr; - double jpr; - double _pr; - double _jpr; c = f->components[pc->cid]; @@ -164,26 +143,20 @@ static int __ses_path_va_transistor(ScfEfunction* f, ses_path_t* path) if (SCF_EDA_NPN != c->type || SCF_EDA_NPN_C != pc->id) { if (j < path->pins->size - 1) { - - pc->a = pj->a; - pc->ja = pj->ja; + pc->a = pj->a; if (pc->lid != pj->lid) { + __ses_path_pr(f, path, i, j, NULL, &pr); - __ses_path_pr(f, path, i, j, NULL, &pr, &jpr); + ses_ir_u(&v, NULL, pj->a, 0, pr, 0); - ses_ir_u(&v, &jv, pj->a, pj->ja, pr, jpr); - - pc->v = p0->v - v; - pc->jv = p0->jv - jv; + pc->v = p0->v - v; if (path->childs) - __ses_path_split_i(f, path, i, j, pj->a, pj->ja, &pc->a, &pc->ja); + __ses_path_split_i(f, path, i, j, pj->a, &pc->a); - } else { + } else pc->v = pj->v; - pc->jv = pj->jv; - } j = i; } @@ -191,31 +164,30 @@ static int __ses_path_va_transistor(ScfEfunction* f, ses_path_t* path) } if (!pc->aconst) - continue; + break; - __ses_path_pr(f, path, 0, i, NULL, &pr, &jpr); + pc->a = pc->hfe * c->pins[SCF_EDA_NPN_B]->a; - ses_ir_u(&v, &jv, pc->a, pc->ja, pr, jpr); + __ses_path_pr(f, path, 0, i, NULL, &pr); - pc->v = p0->v - v; - pc->jv = p0->jv - jv; + ses_ir_u(&v, NULL, pc->a, 0, pr, 0); + + pc->v = p0->v - v; if (pc->v < pj->v) { - pr += path->parent_r0; - jpr += path->parent_jr0; + v = p0->v - pj->v; - v = Bp->v - pj->v; - jv = Bp->jv - pj->jv; + __ses_path_pr(f, path, 0, j, NULL, &_pr); - _pr = pc->pr + path->parent_r0 + path->parent_r1; - _jpr = pc->jpr + path->parent_jr0 + path->parent_jr1; + ses_ur_i(&a, NULL, v, 0, _pr, 0); - ses_ur_i(&pc->a, &pc->ja, v, jv, _pr, _jpr); + if (path->childs) + __ses_path_split_i(f, path, 0, j, a, &a); - ses_ir_u(&v, &jv, pc->a, pc->ja, pr, jpr); + ses_ir_u(&v, NULL, a, 0, pr, 0); - pc->v = Bp->v - v; - pc->jv = Bp->jv - jv; + pc->v = p0->v - v; + pc->a = a; scf_logi("i: %d, c%ldp%ld--c%ldp%ld, v: %lg, pc->v: %lg, pc->a: %lg, pr: %lg, _pr: %lg pc->pr: %lg\n", i, p0->cid, p0->id, pc->cid, pc->id, v, pc->v, pc->a, pr, _pr, pc->pr); @@ -223,30 +195,24 @@ static int __ses_path_va_transistor(ScfEfunction* f, ses_path_t* path) el = f->elines[pc->lid]; el->v = pc->v; - el->jv = pc->jv; el->a = pc->a; - el->ja = pc->ja; el->vconst = 1; - scf_logd("i: %d, c%ldp%ld--c%ldp%ld, v: %lg, pc->v: %lg, pc->a: %lg, pr: %lg, pc->dr: %lg\n", + scf_logw("i: %d, c%ldp%ld--c%ldp%ld, v: %lg, pc->v: %lg, pc->a: %lg, pr: %lg, pc->dr: %lg\n", i, p0->cid, p0->id, pc->cid, pc->id, v, pc->v, pc->a, pr, pc->dr); if (path->childs) { - __ses_path_split_i(f, path, i, j, el->a, el->ja, &pc->a, &pc->ja); + __ses_path_split_i(f, path, i, j, el->a, &pc->a); if (i > 0) { p = path->pins->data[i - 1]; p->a = el->a; - p->ja = el->ja; p->v = el->v; - p->jv = el->jv; - __ses_path_split_i(f, path, 0, i - 1, el->a, el->ja, &p->a, &p->ja); + __ses_path_split_i(f, path, 0, i - 1, el->a, &p->a); } - } else { - p0->a = el->a; - p0->ja = el->ja; - } + } else + p0->a = el->a; __ses_path_dr_transistor(f, path, i, j); @@ -287,6 +253,8 @@ static int ses_path_va_transistor(ScfEfunction* f, ses_path_t* path) p0 = path->pins->data[0]; p1 = path->pins->data[path->pins->size - 1]; + __ses_path_jr(f, path); + int ret = __ses_path_va_transistor(f, path); if (ret < 0) return ret; diff --git a/ses_steps.c b/ses_steps.c index 8521621..5f36ea2 100644 --- a/ses_steps.c +++ b/ses_steps.c @@ -19,7 +19,7 @@ extern ses_step_t ses_step_va_diode; extern ses_step_t ses_step_va_transistor; extern ses_step_t ses_step_va; extern ses_step_t ses_step_va_bridge; -extern ses_step_t ses_step_va_balance; +extern ses_step_t ses_step_va_line; extern ses_step_t ses_step_output; @@ -38,14 +38,15 @@ static ses_step_t* ses_steps_1[] = &ses_step_topo, - &ses_step_jr, +// &ses_step_jr, &ses_step_va_diode, &ses_step_va_transistor, - &ses_step_jr, +// &ses_step_jr, &ses_step_va, &ses_step_va_bridge, + &ses_step_va_line, }; static ses_step_t* ses_steps_2[] = diff --git a/ses_utils.c b/ses_utils.c index 23af6b6..3208b35 100644 --- a/ses_utils.c +++ b/ses_utils.c @@ -81,11 +81,8 @@ void ses_flow_jr(ses_flow_t* flow, ScfEfunction* f) flow->pos_pins = 0; flow->neg_pins = 0; - flow->pos_r = 0; - flow->pos_jr = 0; - - flow->neg_r = 0; - flow->neg_jr = 0; + flow->pos_r = 0; + flow->neg_r = 0; if (!flow->paths || !flow->vip) return; @@ -112,14 +109,12 @@ void ses_flow_jr(ses_flow_t* flow, ScfEfunction* f) vip = path->pins->data[0]; c = f->components[p->cid]; - double pr = p->pr; - double jpr = p->jpr; + double pr = p->pr; if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == p->id) - __ses_npn_epr(f, p, &pr, &jpr); + __ses_npn_epr(f, p, &pr); - flow->pos_r += pr; - flow->pos_jr += jpr; + flow->pos_r += pr; scf_logd("flow->pos_r: %lg, c%ldp%ld->pr: %lg, pr: %lg, vip c%ldp%ld->pr: %lg\n", flow->pos_r, p->cid, p->id, p->pr, pr, vip->cid, vip->id, vip->pr); @@ -150,13 +145,11 @@ void ses_flow_jr(ses_flow_t* flow, ScfEfunction* f) if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == p->id) { p = path->pins->data[j - 1]; - if (p->lid == p0->lid) { - flow->neg_r += p->r + p->dr; - flow->neg_jr += p->jr + p->jdr; - } else { - flow->neg_r += p->pr - p0->pr; - flow->neg_jr += p->jpr - p0->jpr; - } + if (p->lid == p0->lid) + flow->neg_r += p->r + p->dr; + else + flow->neg_r += p->pr - p0->pr; + scf_loge("flow->neg_r: %lg, c%ldp%ld->sr: %lg, p0 c%ldp%ld->pr: %lg\n", flow->neg_r, p->cid, p->id, p->sr, p0->cid, p0->id, p0->pr); @@ -167,8 +160,7 @@ void ses_flow_jr(ses_flow_t* flow, ScfEfunction* f) } else if (p->sr != p->pr) { - flow->neg_r += p->sr - p0->pr; - flow->neg_jr += p->jsr - p0->jpr; + flow->neg_r += p->sr - p0->pr; scf_logw("flow->neg_r: %lg, c%ldp%ld->sr: %lg, p0 c%ldp%ld->pr: %lg\n", flow->neg_r, p->cid, p->id, p->sr, p0->cid, p0->id, p0->pr); @@ -181,8 +173,7 @@ void ses_flow_jr(ses_flow_t* flow, ScfEfunction* f) vip = path->pins->data[j - 1]; if (vip != p0) { - flow->neg_r += vip->sr - p0->pr; - flow->neg_jr += vip->jsr - p0->jpr; + flow->neg_r += vip->sr - p0->pr; scf_loge("flow->neg_r: %lg, vip c%ldp%ld->sr: %lg, p0 c%ldp%ld->pr: %lg\n", flow->neg_r, vip->cid, vip->id, vip->sr, p0->cid, p0->id, p0->pr); } -- 2.25.1