From: yu.dongliang <18588496441@163.com> Date: Thu, 16 Nov 2023 04:27:47 +0000 (+0800) Subject: ses_step_va_bridge.c, ses_utils.c X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=853eaa197564d1ce27a992ef76e49ff69b944068;p=ses.git ses_step_va_bridge.c, ses_utils.c --- diff --git a/ses_step_va_bridge.c b/ses_step_va_bridge.c index 6173528..50f640d 100644 --- a/ses_step_va_bridge.c +++ b/ses_step_va_bridge.c @@ -1,5 +1,149 @@ #include"ses_core.h" +int __ses_flow_va_pos(ScfEfunction* f, ses_flow_t* flow, double a_bridge, double ja_bridge) +{ + if (!flow || !flow->paths || flow->paths->size <= 0 || !flow->vip) + return -EINVAL; + + ses_path_t* path = flow->paths->data[flow->paths->size - 1]; + ScfEpin* vip = flow->vip; + ScfEpin* p0; + ScfEpin* p; + + double tr = flow->pos_r; + double jtr = flow->pos_jr; + + int i; + int j; + + for (i = 0; i < flow->paths->size; i++) { + path = flow->paths->data[i]; + + double v; + double jv; + + double r; + double jr; + + int j0 = -1; + for (j = path->pins->size - 1; j >= 0; j--) { + p = path->pins->data[j]; + + if (j0 < 0) { + if ((j & 0x1) && p->lid == vip->lid) + j0 = j; + else + continue; + } + + __ses_path_pr(f, path, j, j0, NULL, &r, &jr); + + r = tr - r; + jr = jtr - jr; + + ses_ir_u(&v, &jv, a_bridge, ja_bridge, r, jr); + + p->v -= v; + p->jv -= jv; + + scf_logw("c%ldp%ld->v: %lg, r: %lg\n", p->cid, p->id, p->v, r); + break; + } + + assert(j0 >= 0); + + __ses_path_pr(f, path, j0, j, NULL, &r, &jr); + + tr -= r; + jtr -= jr; + + ses_ir_u(&v, &jv, a_bridge, ja_bridge, tr, jtr); + + vip = path->pins->data[0]; + vip->v -= v; + vip->jv -= jv; + + scf_logw("c%ldp%ld->v: %lg, r: %lg\n", vip->cid, vip->id, vip->v, tr); + } + + return 0; +} + +int __ses_flow_va_neg(ScfEfunction* f, ses_flow_t* flow, double a_bridge, double ja_bridge) +{ + if (!flow || !flow->paths || flow->paths->size <= 0 || !flow->vip) + return -EINVAL; + + ses_path_t* path = flow->paths->data[flow->paths->size - 1]; + ScfEpin* vip = flow->vip; + ScfEpin* p0; + ScfEpin* p; + + double tr = flow->neg_r; + double jtr = flow->neg_jr; + + int i; + int j; + + for (i = 0; i < flow->paths->size; i++) { + path = flow->paths->data[i]; + + double v; + double jv; + + double r; + double jr; + + int j0 = -1; + for (j = 0; j < path->pins->size; j++) { + p = path->pins->data[j]; + + if (j0 < 0) { + if (p->lid == vip->lid) + j0 = j; + else + continue; + } + + __ses_path_pr(f, path, j0, j, NULL, &r, &jr); + + r = tr - r; + jr = jtr - jr; + + if (p->sr != p->pr) + j0 = j; + + ses_ir_u(&v, &jv, a_bridge, ja_bridge, r, jr); + + p->v += v; + p->jv += jv; + + scf_loge("c%ldp%ld->v: %lg, r: %lg, %lg\n", p->cid, p->id, p->v, r, p->sr); + } + + assert(p0); + + vip = path->pins->data[j - 1]; + + if (j - 1 != j0) { + + __ses_path_sr(f, path, j0, j, NULL, &r, &jr); + + tr -= r; + jtr -= jr; + + ses_ir_u(&v, &jv, a_bridge, ja_bridge, tr, jtr); + + vip->v += v; + vip->jv += jv; + + scf_logw("c%ldp%ld->v: %lg + j%lg, r: %lg + j%lg\n", vip->cid, vip->id, vip->v, vip->jv, tr, jtr); + } + } + + return 0; +} + static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* bridge, int* changed, scf_vector_t* paths) { if (!bridge) @@ -69,6 +213,8 @@ static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* bridge, int* change double a = 0; double ja = 0; + double Eta = 0.001; + do { ret = __ses_path_va(f, bridge, changed); if (ret < 0) @@ -77,27 +223,21 @@ static int __ses_path_va_bridge(ScfEfunction* f, ses_path_t* bridge, int* change da = bridge->a - a; dja = bridge->ja - ja; - a += 0.001 * da; - ja += 0.001 * dja; - - fp0->a = flow->vip->a + a; - fp0->ja = flow->vip->ja + ja; - - double _v; - double _jv; - - double _a; - double _ja; + a += Eta * da; + ja += Eta * dja; - ses_ir_u(&_v, &_jv, fp0->a, fp0->ja, flow->pos_r, flow->pos_jr); + scf_loge("da: %lg, a: %lg\n", da, a); - flow->vip->v = fp0->v - _v; - flow->vip->jv = fp0->jv - _jv; + ret = __ses_flow_va_pos(f, flow, a, ja); + if (ret < 0) + return ret; + scf_logi("----------------\n\n"); - ses_ur_i(&_a, &_ja, flow->vip->v, flow->vip->jv, flow->neg_r, flow->neg_jr); + ret = __ses_flow_va_neg(f, flow, a, ja); + if (ret < 0) + return ret; + scf_logw("****************\n\n"); - scf_logw("da: %lg, a: %lg, fp0->a: %lg, _v: %lg, vip->v: %lg, _a: %lg\n", - da, a, fp0->a, _v, flow->vip->v, _a); } while (0); scf_logw("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", diff --git a/ses_utils.c b/ses_utils.c index d14f539..554aee4 100644 --- a/ses_utils.c +++ b/ses_utils.c @@ -68,132 +68,6 @@ int ses_paths_find_flow(ses_flow_t* flow, scf_vector_t* paths, ScfEpin* vip, ses return 0; } -void ses_flow_v_pos(ses_flow_t* flow, double a, double ja) -{ - if (!flow || !flow->paths || flow->paths->size <= 0 || !flow->vip) - return; - - ses_path_t* path = flow->paths->data[flow->paths->size - 1]; - ScfEpin* vip = flow->vip; - ScfEpin* p0; - ScfEpin* p; - - double tr = flow->pos_r; - double jtr = flow->pos_jr; - - int i; - int j; - - for (i = 0; i < flow->paths->size; i++) { - path = flow->paths->data[i]; - - double v; - double jv; - - p0 = NULL; - for (j = path->pins->size - 1; j >= 0; j--) { - p = path->pins->data[j]; - - if (!p0) { - if ((j & 0x1) && p->lid == vip->lid) - p0 = p; - else - continue; - } - - double r = tr - (p0->pr - p->pr); - double jr = jtr - (p0->jpr - p->jpr); - - ses_ir_u(&v, &jv, a, ja, r, jr); - - p->v -= v; - p->jv -= jv; - - scf_logw("c%ldp%ld->v: %lg + j%lg, r: %lg + j%lg\n", p->cid, p->id, p->v, p->jv, r, jr); - break; - } - - assert(p0); - - vip = path->pins->data[0]; - tr -= p0->pr; - jtr -= p0->jpr; - - ses_ir_u(&v, &jv, a, ja, tr, jtr); - - vip->v -= v; - vip->jv -= jv; - - scf_logw("c%ldp%ld->v: %lg + j%lg, r: %lg + j%lg\n", vip->cid, vip->id, vip->v, vip->jv, tr, jtr); - } -} - -void ses_flow_v_neg(ses_flow_t* flow, double a, double ja) -{ - if (!flow || !flow->paths || flow->paths->size <= 0 || !flow->vip) - return; - - ses_path_t* path = flow->paths->data[flow->paths->size - 1]; - ScfEpin* vip = flow->vip; - ScfEpin* p0; - ScfEpin* p; - - double tr = flow->neg_r; - double jtr = flow->neg_jr; - - int i; - int j; - - for (i = 0; i < flow->paths->size; i++) { - path = flow->paths->data[i]; - - double v; - double jv; - - p0 = NULL; - for (j = 0; j < path->pins->size; j++) { - p = path->pins->data[j]; - - if (!p0) { - if (p->lid == vip->lid) - p0 = p; - else - continue; - } - - double r = tr - (p->sr - p0->pr); - double jr = jtr - (p->jsr - p0->jpr); - - if (p->sr != p->pr) - p0 = p; - - ses_ir_u(&v, &jv, a, ja, r, jr); - - p->v += v; - p->jv += jv; - - scf_loge("c%ldp%ld->v: %lg + j%lg, r: %lg + j%lg, %lg\n", p->cid, p->id, p->v, p->jv, r, jr, p->sr); - } - - assert(p0); - - vip = path->pins->data[j - 1]; - - if (vip != p0) { - - tr -= vip->sr - p0->pr; - jtr -= vip->jsr - p0->jpr; - - ses_ir_u(&v, &jv, a, ja, tr, jtr); - - vip->v += v; - vip->jv += jv; - - scf_logw("c%ldp%ld->v: %lg + j%lg, r: %lg + j%lg\n", vip->cid, vip->id, vip->v, vip->jv, tr, jtr); - } - } -} - void ses_flow_jr(ses_flow_t* flow) { if (!flow)