From 4964329b190d3f78b803b37141c774ad473ee3d8 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Sat, 29 Jul 2023 23:33:14 +0800 Subject: [PATCH] ses_step_va.c --- ses_core.h | 6 +++++ ses_step_va.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 78 insertions(+), 3 deletions(-) diff --git a/ses_core.h b/ses_core.h index dba8c55..62c16d1 100644 --- a/ses_core.h +++ b/ses_core.h @@ -30,6 +30,12 @@ struct ses_path_s scf_vector_t* childs; ses_path_t* parent; + double r0; + double jr0; + + double r; + double jr; + int type; int index; }; diff --git a/ses_step_va.c b/ses_step_va.c index c5df06d..64f21fe 100644 --- a/ses_step_va.c +++ b/ses_step_va.c @@ -1,13 +1,70 @@ #include"ses_core.h" +int __ses_path_jr(ses_path_t* path) +{ + if (!path) + return -EINVAL; + + ses_path_t* child; + ScfEpin* p; + + int i; + + path->r0 = 0; + path->jr0 = 0; + + for (i = 0; i < path->pins->size; i++) { + p = path->pins->data[i]; + + path->r0 += p->r; + path->jr0 += p->jr; + } + + double R = path->r0 * path->r0 + path->jr0 * path->jr0; + double r = path->r0 / R; + double jr = -path->jr0 / R; + + scf_loge("path: %d, r0: %lg, jr0: %lg, r: %lg, jr: %lg\n", path->index, path->r0, path->jr0, r, jr); + + if (path->childs) { + for (i = 0; i < path->childs->size; i++) { + child = path->childs->data[i]; + + int ret = __ses_path_jr(child); + if (ret < 0) + return ret; + + R = child->r * child->r + child->jr * child->jr; + + double _r = child->r / R; + double _jr = -child->jr / R; + + r += _r; + jr += _jr; + + scf_loge("child: %d, r: %lg, jr: %lg, r0: %lg, jr0: %lg, _r: %lg, _jr: %lg\n\n", + child->index, child->r, child->jr, child->r0, child->jr0, _r, _jr); + } + } + + R = r * r + jr * jr; + r = r / R; + jr = -jr / R; + + path->r = r; + path->jr = jr; + + 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; - ScfEline* el2; - ScfEline* elp; - ScfEline* eln; ScfEpin* p; size_t i; @@ -16,6 +73,18 @@ static int _va_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ct B = f->components[0]; + for (i = 0; i < ctx->paths->size; i++) { + path = ctx->paths->data[i]; + + scf_logi("i: %ld, path->type: %d\n", i, path->type); + + int ret = __ses_path_jr(path); + if (ret < 0) + return ret; + + printf("\n"); + } + return 0; } -- 2.25.1