From: yu.dongliang <18588496441@163.com> Date: Mon, 1 Apr 2024 13:57:35 +0000 (+0800) Subject: fix: add.pack error because of ses_step_va_bridge.c X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=cd7d122c1cc7929190130e7d2461e189f0ad48de;p=ses.git fix: add.pack error because of ses_step_va_bridge.c --- diff --git a/ses_core.h b/ses_core.h index 8dfeffc..f4ee4a2 100644 --- a/ses_core.h +++ b/ses_core.h @@ -64,12 +64,6 @@ struct ses_path_s double parent_r1; double parent_jr1; - double r0; - double jr0; - - double a0; - double ja0; - double r; double jr; @@ -79,6 +73,9 @@ struct ses_path_s double a; double ja; + double a0; + double ja0; + double da; double dja; @@ -127,9 +124,10 @@ 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); -void __ses_path_split_i(ScfEfunction* f, ses_path_t* path, int i, int j, double la, double jla, double* a, double* ja); -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_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); +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); diff --git a/ses_step_da.c b/ses_step_da.c index 790f06a..53d6bee 100644 --- a/ses_step_da.c +++ b/ses_step_da.c @@ -135,8 +135,6 @@ void __ses_npn_dr(ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe) 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; - - scf_loge("v: %lg, pb->dr: %lg\n", v, pb->dr); } int __ses_path_da(ScfEfunction* f, ses_path_t* path, int* changed, double da, double dja) diff --git a/ses_step_jr.c b/ses_step_jr.c index 6a7c497..4852397 100644 --- a/ses_step_jr.c +++ b/ses_step_jr.c @@ -287,7 +287,7 @@ int __ses_path_jr(ScfEfunction* f, ses_path_t* path) } } - scf_loge("path: %d, r: %lg, r0: %lg\n\n", path->index, path->r, path->r0); + scf_loge("path: %d, r: %lg\n\n", path->index, path->r); return 0; } diff --git a/ses_step_topo.c b/ses_step_topo.c index b13e7df..732b7d7 100644 --- a/ses_step_topo.c +++ b/ses_step_topo.c @@ -197,9 +197,11 @@ static int __topo_path_bridges(ScfEfunction* f, ses_path_t* path) int i; int j; - path->bridges = scf_vector_alloc(); - if (!path->bridges) - return -ENOMEM; + if (!path->bridges) { + path->bridges = scf_vector_alloc(); + if (!path->bridges) + return -ENOMEM; + } for (i = 0; i < path->childs->size - 1; ) { sp0 = path->childs->data[i]; @@ -486,6 +488,9 @@ static int __topo_path_diodes(ScfEfunction* f, ses_path_t* path) int i; int j; + scf_vector_clear(path->diodes, ( void (*)(void*) )free); + path->n_diodes = 0; + for (i = 0; i < path->pins->size; i++) { p = path->pins->data[i]; @@ -503,6 +508,7 @@ static int __topo_path_diodes(ScfEfunction* f, ses_path_t* path) if (SCF_EDA_Diode_NEG == p->id) { info->n_diodes++; + path->n_diodes++; if (__ses_branch_exist(path, i)) { j = i; @@ -524,6 +530,7 @@ static int __topo_path_diodes(ScfEfunction* f, ses_path_t* path) } info->n_NPNs++; + path->n_diodes++; continue; } else if (SCF_EDA_NPN_E == p->id) { @@ -617,11 +624,6 @@ static int _topo_layers(ScfEfunction* f, scf_vector_t* paths) Bp = B->pins[SCF_EDA_Battery_POS]; Bn = B->pins[SCF_EDA_Battery_NEG]; - for (i = 0; i < paths->size; i++) { - child = paths->data[i]; - child->index = i; - } - for (i = paths->size - 1; i >= 1; i--) { child = paths->data[i]; @@ -675,10 +677,6 @@ branch: int ret = _topo_path_bridges(f, child); if (ret < 0) return ret; - - ret = _topo_path_diodes(f, child); - if (ret < 0) - return ret; } return 0; @@ -715,6 +713,8 @@ static int _topo_diodes(ScfEfunction* f, ses_path_t* path) int i; + path->n_diodes = 0; + for (i = 0; i < path->pins->size; i++) { p = path->pins->data[i]; @@ -831,6 +831,12 @@ static int _topo_paths(ScfEfunction* f, ScfEline* el, scf_vector_t* paths) path = NULL; } + for (i = 0; i < paths->size; i++) { + path = paths->data[i]; + + path->index = i; + } + return 0; } @@ -884,8 +890,6 @@ static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ScfEcomponent* B; ScfEline* el; - size_t i; - _topo_clear(f); scf_vector_clear(ctx->paths, ( void (*)(void*) )ses_path_free); @@ -896,25 +900,38 @@ static int _topo_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* int ret = _topo_paths(f, el, ctx->paths); if (ret < 0) return ret; -#if 0 - ret = _topo_path_completes(f, ctx->paths); - if (ret < 0) - return ret; -#endif + + int size; + int i; + + do { + size = ctx->paths->size; + + for (i = 0; i < ctx->paths->size; i++) { + path = ctx->paths->data[i]; + + ret = _topo_diodes(f, path); + if (ret < 0) + return ret; + } + + ret = _topo_layers(f, ctx->paths); + if (ret < 0) + return ret; + + ret = _topo_path_completes(f, ctx->paths); + if (ret < 0) + return ret; + } while (size > ctx->paths->size); + for (i = 0; i < ctx->paths->size; i++) { path = ctx->paths->data[i]; - scf_vector_clear(path->diodes, ( void (*)(void*) )free); - - ret = _topo_diodes(f, path); + ret = _topo_path_diodes(f, path); if (ret < 0) return ret; } - ret = _topo_layers(f, ctx->paths); - if (ret < 0) - return ret; - _topo_print(ctx->paths); return 0; } diff --git a/ses_step_va.c b/ses_step_va.c index a2e963e..3f4b1de 100644 --- a/ses_step_va.c +++ b/ses_step_va.c @@ -1,7 +1,5 @@ #include"ses_core.h" -int _ses_path_cmp(const void* v0, const void* v1); - static int __ses_path_split_a(ScfEfunction* f, ses_path_t* path, int i, double* a, double *ja, int* changed) { ses_path_t* child; @@ -40,37 +38,40 @@ static int __ses_path_split_a(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; + double jr; - double _v = 0; - double _jv = 0; - double _a = 0; - double _ja = 0; + double v; + double jv; - __ses_path_pr(f, path, i, k, cp1, &_r, &_jr); + __ses_path_pr(f, path, i, k, cp1, &r, &jr); - ses_ir_u(&_v, &_jv, *a, *ja, _r, _jr); + ses_ir_u(&v, &jv, *a, *ja, r, jr); - scf_logw("child: %d, c%ldp%ld-c%ldp%ld (c%ldp%ld-c%ldp%ld), _v: %lg, a: %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, _v, *a, _r, p->pr, p->dr, p2->pr); + 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); - ses_ur_i(&_a, &_ja, _v, _jv, child->r, child->jr); + ses_ur_i(&child->a0, &child->ja0, v, jv, child->r, child->jr); - *a -= _a; - *ja -= _ja; + *a -= child->a0; + *ja -= child->ja0; el = f->elines[p2->lid]; - el->v = p->v - _v; - el->jv = p->jv - _jv; + el->v = p->v - v; + el->jv = p->jv - jv; - scf_loge("child: %d, c%ldp%ld, c%ldp%ld, p->v: %lg, el->v: %lg, _v: %lg\n", - child->index, p->cid, p->id, p2->cid, p2->id, p->v, el->v, _v); + if (child->n_diodes > 0) { + __ses_path_va_diode(f, child); + __ses_path_jr (f, child); + } int ret = __ses_path_va(f, child, changed); if (ret < 0) return ret; + 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); + n++; } @@ -138,7 +139,8 @@ int __ses_path_va(ScfEfunction* f, ses_path_t* path, int* changed) ses_ur_i(&path->a, &path->ja, v, jv, path->r, path->jr); - scf_loge("path: %d, v: %lg, r: %lg, a: %lg\n\n", path->index, v, path->r, path->a); + 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); double a = path->a; double ja = path->ja; @@ -153,10 +155,9 @@ int __ses_path_va(ScfEfunction* f, ses_path_t* path, int* changed) for (i = 0; i < path->pins->size; i++) { p = path->pins->data[i]; - if (!(i & 0x1) && path->childs) { - - __ses_path_split_v(f, path, i0, i, a, ja); + __ses_path_split_v(f, path, i0, i, a, ja); + if (!(i & 0x1) && path->childs) { int ret = __ses_path_split_a(f, path, i, &a, &ja, changed); if (ret < 0) return ret; @@ -166,8 +167,7 @@ int __ses_path_va(ScfEfunction* f, ses_path_t* path, int* changed) i0 = i; scf_logd("i: %d, p0: c%ldp%ld\n", i, p0->cid, p0->id); } - } else - __ses_path_split_v(f, path, i0, i, a, ja); + } el = f->elines[p->lid]; el->v = p->v; @@ -198,10 +198,8 @@ int __ses_path_va(ScfEfunction* f, ses_path_t* path, int* changed) cp1 = child->pins->data[child->pins->size - 1]; if (p->lid == cp1->lid) { - a += child->a; - ja += child->ja; - - scf_logd("path: %d, i: %d, c%ldp%ld, child->a: %lg + j%lg\n", child->index, i, cp1->cid, cp1->id, child->a, child->ja); + a += child->a0; + ja += child->ja0; } } } diff --git a/ses_step_va_bridge.c b/ses_step_va_bridge.c index cdee3a9..76d2fa1 100644 --- a/ses_step_va_bridge.c +++ b/ses_step_va_bridge.c @@ -51,11 +51,12 @@ int __ses_flow_a_pos(ScfEfunction* f, ses_flow_t* flow, double da_vip, double dj ses_ir_u(&v, &jv, da_vip, dja_vip, r, jr); } - if (p->v - v < Bp->lid) { + el = f->elines[p->lid]; + + if (p->lid != Bp->lid && p->v - v < Bp->lid) { p->v -= v; p->jv -= jv; - el = f->elines[p->lid]; el->v = p->v; el->jv = p->jv; } @@ -101,8 +102,6 @@ int __ses_flow_v_neg(ScfEfunction* f, ses_flow_t* flow, double dv_vip, double dj int i; int j; - ses_ur_i(&da, &dja, dv_vip, djv_vip, flow->neg_r, flow->neg_jr); - for (i = 0; i < flow->paths->size; i++) { path = flow->paths->data[i]; @@ -114,9 +113,14 @@ int __ses_flow_v_neg(ScfEfunction* f, ses_flow_t* flow, double dv_vip, double dj p = path->pins->data[j]; if (j0 < 0) { - if (!(j & 0x1) && p->lid == vip->lid) + if (!(j & 0x1) && p->lid == vip->lid) { j0 = j; - else + + ses_ur_i(&da, &dja, vip->v, vip->jv, flow->neg_r, flow->neg_jr); + + da -= p->a; + dja -= p->ja; + } else continue; } @@ -131,11 +135,12 @@ int __ses_flow_v_neg(ScfEfunction* f, ses_flow_t* flow, double dv_vip, double dj ses_ir_u(&v, &jv, da, dja, r, jr); } - if (p->v + v > Bn->lid) { + el = f->elines[p->lid]; + + if (p->lid != Bn->lid && p->v + v > Bn->lid) { p->v += v; p->jv += jv; - el = f->elines[p->lid]; el->v = p->v; el->jv = p->jv; } @@ -143,7 +148,7 @@ int __ses_flow_v_neg(ScfEfunction* f, ses_flow_t* flow, double dv_vip, double dj p->a += da; p->ja += dja; - scf_logw("c%ldp%ld->v: %lg, p->a: %lg, r: %lg, v: %lg, l%ld->v: %lg\n", p->cid, p->id, p->v, p->a, r, v, el->id, el->v); + 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); if (j & 0x1) { if (SCF_EDA_Diode == c->type) { @@ -154,6 +159,7 @@ 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) { @@ -238,6 +244,8 @@ static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* bridge, int* change double ja = 0; double Eta = 0.001; + int __changed = 0; + int k = 0; do { scf_logw("k: %d, ****************\n", k); @@ -250,12 +258,17 @@ static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* bridge, int* change p1->v = el->v; p1->jv = el->jv; - ret = __ses_path_va(f, bridge, changed); + 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; - __ses_path_jr(f, bridge); - da = bridge->a - a; dja = bridge->ja - ja; @@ -268,7 +281,7 @@ static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* bridge, int* change v = flow->vip->v; jv = flow->vip->jv; - ret = __ses_flow_a_pos(f, flow, Eta * da, Eta * dja, changed); + ret = __ses_flow_a_pos(f, flow, Eta * da, Eta * dja, &__changed); if (ret < 0) return ret; @@ -277,27 +290,27 @@ static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* bridge, int* change scf_logi("dv: %lg, v: %lg - %lg ----------------\n", dv, flow->vip->v, v); - ret = __ses_flow_v_neg(f, flow, dv, djv, changed); + ret = __ses_flow_v_neg(f, flow, dv, djv, &__changed); if (ret < 0) return ret; - __ses_path_jr(f, fpath); - ses_flow_jr(flow, f); - 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 (fabs(flow->vip->a - flow->vip_n->a - bridge->a) > 1e-4); + } while (0 == __changed && fabs(flow->vip->a - flow->vip_n->a - bridge->a) > 1e-4); v = p0->v - p1->v; jv = p0->jv - p1->jv; - scf_loge("bridge: %d, c%ldp%ld--c%ldp%ld, v: %lg, p0->v: %lg, p1->v: %lg, n_diodes: %d, p0->a: %lg, p1->a: %lg\n", - bridge->index, p0->cid, p0->id, p1->cid, p1->id, v, p0->v, p1->v, bridge->n_diodes, p0->a, p1->a); + 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", + 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; } @@ -316,13 +329,28 @@ static int ses_path_va_bridge(ScfEfunction* f, ses_path_t* path, int* changed, s return ret; if (path->bridges) { + scf_vector_t* vec = scf_vector_clone(path->childs); + if (!vec) + return -ENOMEM; + + ret = scf_vector_add(vec, path); + if (ret < 0) { + scf_vector_free(vec); + return ret; + } + for (j = 0; j < path->bridges->size; j++) { child = path->bridges->data[j]; - ret = ses_path_va_bridge(f, child, changed, paths); - if (ret < 0) + ret = ses_path_va_bridge(f, child, changed, vec); + if (ret < 0) { + scf_vector_free(vec); return ret; + } } + + scf_vector_free(vec); + vec = NULL; } return 0; diff --git a/ses_step_va_diode.c b/ses_step_va_diode.c index 47330d3..8ba13bd 100644 --- a/ses_step_va_diode.c +++ b/ses_step_va_diode.c @@ -1,7 +1,5 @@ #include"ses_core.h" -static 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) { ScfEcomponent* c; @@ -255,7 +253,7 @@ static void __ses_path_a_diode(ScfEfunction* f, ses_path_t* path, int k, double* 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); } -static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) +int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path) { ses_path_t* child; ses_info_t* info; diff --git a/ses_step_va_transistor.c b/ses_step_va_transistor.c index c68ee63..2cfaa7c 100644 --- a/ses_step_va_transistor.c +++ b/ses_step_va_transistor.c @@ -105,47 +105,6 @@ _changed: return 1; } -static int __ses_status_change(ScfEfunction* f, ScfEline* el) -{ - ScfEcomponent* c; - ScfEcomponent* B; - ScfEpin* Bp; - ScfEpin* Bn; - ScfEpin* p; - ScfEpin* pe; - - size_t j; - int changed = 0; - - B = f->components[0]; - Bp = B->pins[SCF_EDA_Battery_POS]; - Bn = B->pins[SCF_EDA_Battery_NEG]; - - for (j = 0; j + 1 < el->n_pins; j += 2) { - - c = f->components[el->pins[j]]; - p = c->pins [el->pins[j + 1]]; - - if (SCF_EDA_NPN == c->type) { - if (SCF_EDA_NPN_B == p->id) { - - pe = c->pins[SCF_EDA_NPN_E]; - changed += __ses_status_check(f, c, p, pe); - } - - } else if (SCF_EDA_Diode == c->type) { - - if (SCF_EDA_Diode_POS == p->id) { - - pe = c->pins[SCF_EDA_Diode_NEG]; - changed += __ses_status_check(f, c, p, pe); - } - } - } - - return changed; -} - static int __ses_path_va_transistor(ScfEfunction* f, ses_path_t* path) { ses_path_t* parent = path->parent; diff --git a/ses_steps.c b/ses_steps.c index 044cbc9..8521621 100644 --- a/ses_steps.c +++ b/ses_steps.c @@ -36,19 +36,16 @@ static ses_step_t* ses_steps_1[] = &ses_step_dc_diode, &ses_step_dc_transistor, -// &ses_step_simplify, &ses_step_topo, &ses_step_jr, &ses_step_va_diode, &ses_step_va_transistor, -#if 1 + &ses_step_jr, &ses_step_va, &ses_step_va_bridge, -// &ses_step_va_balance, -#endif }; static ses_step_t* ses_steps_2[] = @@ -144,7 +141,7 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count) return ret; int j; - for (j = 0; j < 3; j++) { + for (j = 0; j < 2; j++) { printf("\n\033[33m%s(), %d(), j: %d\033[0m\n", __func__, __LINE__, j); ret = __ses_steps_analyse(f, ns, i, ctx); @@ -156,7 +153,7 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count) break; if (ret < 0) - return ret; + break; } ret = __ses_steps_output(f, ns, i, ctx); diff --git a/ses_utils.c b/ses_utils.c index 6444795..23af6b6 100644 --- a/ses_utils.c +++ b/ses_utils.c @@ -44,10 +44,8 @@ int ses_paths_find_flow(ses_flow_t* flow, scf_vector_t* paths, ScfEpin* vip, ses if (vip ->lid == p->lid) { - if (j + 1 >= path->pins->size) { - scf_loge("ses_paths_find_flow error\n"); - return -1; - } + if (j + 1 >= path->pins->size) + break; flow->vip = p; flow->vip_n = path->pins->data[j + 1];; @@ -152,14 +150,13 @@ 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 == p0) { + 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; } - 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);