From 8a003286b5440346b83b51b21f548f6a7e18a000 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Tue, 5 Sep 2023 15:41:32 +0800 Subject: [PATCH] ses_step_va.c --- ses_step_va.c | 112 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 68 insertions(+), 44 deletions(-) diff --git a/ses_step_va.c b/ses_step_va.c index 3d9860e..52a8535 100644 --- a/ses_step_va.c +++ b/ses_step_va.c @@ -56,11 +56,6 @@ static int __ses_path_jr(ScfEfunction* f, ses_path_t* path) for (i = path->childs->size - 1; i >= 0; i--) { child = path->childs->data[i]; - if (child->pins->size < 2) { - scf_loge("\n"); - return -EINVAL; - } - int ret = __ses_path_jr(f, child); if (ret < 0) return ret; @@ -152,63 +147,103 @@ static int __ses_path_va(ScfEfunction* f, ses_path_t* path) ses_path_t* child; ScfEcomponent* c; + ScfEline* el; ScfEpin* p; ScfEpin* p0; ScfEpin* p1; ScfEpin* cp0; ScfEpin* cp1; - double R; - double r; - double jr; + int i; + int j; - int i; - int j; + p0 = path->pins->data[0]; + p1 = path->pins->data[path->pins->size - 1]; - r = 0; - jr = 0; + 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 R = path->r * path->r + path->jr * path->jr; + + double v = p0->v - p1->v; + double jv = p0->jv - p1->jv; + + double a = ( v * path->r + jv * path->jr) / R; + double ja = (jv * path->r - v * path->jr) / R; + + scf_loge("path: %d, v: %lg + j%lg, r: %lg + j%lg, a: %lg + j%lg\n", path->index, v, jv, path->r, path->jr, a, ja); + + double r = 0; + double jr = 0; + double dv = 0; + double jdv = 0; for (i = 0; i < path->pins->size; i++) { p = path->pins->data[i]; - scf_loge("i: %d, c%ldp%ld, p->tr: %lg, p->jtr: %lg\n", i, p->cid, p->id, p->tr, p->jtr); + + v = a * p->tr - ja * p->jtr; + jv = ja * p->tr + a * p->jtr; + + p->v = p0->v - v; + p->jv = p0->jv - jv; + + el = f->elines[p->lid]; + el->v = p->v; + el->jv = p->jv; + + r += p->r; + jr += p->jr; + + if (i & 0x1) { + c = f->components[p->cid]; + r += c->r; + jr += c->jr; + + dv -= p->v; + jdv -= p->jv; + + R = r * r + jr * jr; + p->a = ( dv * r + jdv * jr) / R; + p->ja = (jdv * r - dv * jr) / R; + + scf_loge("i: %d, c%ldp%ld, v: %lg + j%lg, p->v: %lg + j%lg, dv: %lg + j%lg, r: %lg + j%lg, a: %lg + j%lg\n\n", i, p->cid, p->id, + v, jv, p->v, p->jv, dv, jdv, r, jr, p->a, p->ja); + + r = 0; + jr = 0; + } else { + dv = p->v; + jdv = p->jv; + + scf_loge("i: %d, c%ldp%ld, v: %lg + j%lg, p->v: %lg + j%lg\n", i, p->cid, p->id, v, jv, p->v, p->jv); + } } printf("\n"); if (path->childs) { - scf_vector_qsort(path->childs, _ses_path_cmp); - for (i = path->childs->size - 1; i >= 0; i--) { child = path->childs->data[i]; - if (child->pins->size < 2) { - scf_loge("\n"); - return -EINVAL; - } - - int ret = __ses_path_jr(f, child); + int ret = __ses_path_va(f, child); if (ret < 0) return ret; } } - p = path->pins->data[path->pins->size - 1]; - - path->r = p->tr; - path->jr = p->jtr; - - scf_loge("path: %d, r: %lg, jr: %lg, r0: %lg, jr0: %lg\n", - path->index, path->r, path->jr, path->r0, path->jr0); return 0; } static int _va_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) { ses_path_t* path; - ScfEcomponent* c; ScfEcomponent* B; - ScfEline* el; ScfEpin* p0; ScfEpin* p1; ScfEpin* Bp; @@ -233,7 +268,9 @@ static int _va_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ct B = f->components[0]; Bp = B->pins[SCF_EDA_Battery_POS]; Bn = B->pins[SCF_EDA_Battery_NEG]; -#if 0 +#if 1 + printf("\n*******************\n"); + for (i = 0; i < ctx->paths->size; i++) { path = ctx->paths->data[i]; @@ -250,19 +287,6 @@ 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; - double v = Bp->v - Bn->v; - - double R = path->r * path->r + path->jr * path->jr; - - double a = v * path->r / R; - double ja = -v * path->jr / R; - - for (i = 0; i < path->pins->size; i++) { -// p = path->pins->data[i]; -// scf_loge("i: %d, c%ldp%ld, p->tr: %lg, p->jtr: %lg\n", i, p->cid, p->id, p->tr, p->jtr); - } - - int ret = __ses_path_va(f, path); if (ret < 0) return ret; -- 2.25.1