From: yu.dongliang <18588496441@163.com> Date: Wed, 6 Sep 2023 02:45:50 +0000 (+0800) Subject: ses_step_jr.c X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=1b0533e1f1e9418911e9502c1bc55efa49ad4081;p=ses.git ses_step_jr.c --- diff --git a/Makefile b/Makefile index 5b3ab32..32bd7d7 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ CFILES += ses_step_dc_transistor.c CFILES += ses_step_simplify.c CFILES += ses_step_topo.c +CFILES += ses_step_jr.c CFILES += ses_step_va.c CFILES += ses_step_va_balance.c CFILES += ses_step_output.c diff --git a/ses_core.h b/ses_core.h index 5e1d709..92eebf9 100644 --- a/ses_core.h +++ b/ses_core.h @@ -73,7 +73,7 @@ int ses_loop_function(ScfEfunction* f, scf_vector_t* loops); int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count); -static void vertical(int* px, int* py, int dx, int dy, int d) +static inline void vertical(int* px, int* py, int dx, int dy, int d) { /* [cos90, -sin90] [0 -1] x @@ -86,7 +86,7 @@ static void vertical(int* px, int* py, int dx, int dy, int d) *py = dx * d / R; } -static void forward(int* px, int* py, int dx, int dy, int d) +static inline void forward(int* px, int* py, int dx, int dy, int d) { double R = sqrt(dx * dx + dy * dy); @@ -94,4 +94,26 @@ static void forward(int* px, int* py, int dx, int dy, int d) *py = dy * d / R; } +static inline void ses_ur_i(double* a, double* ja, double v, double jv, double r, double jr) +{ + double R = r * r + jr * jr; + + *a = ( v * r + jv * jr) / R; + *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; + + *r = ( v * a + jv * ja) / R; + *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; +} + #endif diff --git a/ses_step_jr.c b/ses_step_jr.c new file mode 100644 index 0000000..80c7b64 --- /dev/null +++ b/ses_step_jr.c @@ -0,0 +1,174 @@ +#include"ses_core.h" + +int _ses_path_cmp(const void* v0, const void* v1); + +static int __ses_path_jr(ScfEfunction* f, ses_path_t* path) +{ + if (!path) + return -EINVAL; + + if (path->pins->size < 2) { + scf_loge("\n"); + return -EINVAL; + } + + ses_path_t* child; + ScfEcomponent* c; + ScfEpin* p; + ScfEpin* p0; + ScfEpin* p1; + ScfEpin* cp0; + ScfEpin* cp1; + + double R; + double r; + double jr; + + int i; + int j; + + r = 0; + jr = 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; + } + + p->sr = r; + p->jsr = jr; + + p->pr = r; + p->jpr = jr; + + scf_loge("i: %d, c%ldp%ld, p->tr: %lg, p->jtr: %lg\n", i, p->cid, p->id, p->sr, p->jsr); + } + 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]; + + 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; + p1 = NULL; + + for (j = 0; j < path->pins->size; j++) { + p = path->pins->data[j]; + + if (p->lid == cp0->lid) { + p0 = p; + break; + } + } + + if (!p0) + return -EINVAL; + + for ( ; j < path->pins->size; j++) { + p = path->pins->data[j]; + + if (p->lid == cp1->lid) { + p1 = p; + break; + } + } + + if (!p1) + return -EINVAL; + + R = child->r * child->r + child->jr * child->jr; + + double _r = child->r / R; + double _jr = -child->jr / R; + + r = p1->pr - p0->pr; + jr = p1->jpr - p0->jpr; + + R = r * r + jr * jr; + r = r / R; + jr = -jr / R; + + r += _r; + jr += _jr; + + R = r * r + jr * jr; + r = r / R; + jr = -jr / R; + + double dr = p1->pr - (p0->pr + r); + double jdr = p1->jpr - (p0->jpr + jr); + + for ( ; j < path->pins->size; j++) { + p = path->pins->data[j]; + + p->pr -= dr; + p->jpr -= jdr; + + scf_logw("j: %d, c%ldp%ld, p->pr: %lg + j%lg\n", j, p->cid, p->id, p->pr, p->jpr); + } + + scf_loge("child: %d, r: %lg, jr: %lg, r0: %lg, jr0: %lg, _r: %lg, _jr: %lg, dr: %lg, jdr: %lg\n\n", + child->index, child->r, child->jr, child->r0, child->jr0, _r, _jr, dr, jdr); + } + } + + p = path->pins->data[path->pins->size - 1]; + + path->r = p->pr; + path->jr = p->jpr; + + 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 _jr_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx) +{ + ses_path_t* path; + ScfEcomponent* B; + ScfEpin* p0; + ScfEpin* p1; + ScfEpin* Bp; + ScfEpin* Bn; + + size_t i; + size_t j; + size_t k; + + 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(f, path); + if (ret < 0) + return ret; + + printf("\n"); + } + + return 0; +} + +ses_step_t ses_step_jr = +{ + .name = "jr", + + .handler = _jr_handler, +}; diff --git a/ses_step_va.c b/ses_step_va.c index 29b95d5..4a2a2ef 100644 --- a/ses_step_va.c +++ b/ses_step_va.c @@ -2,164 +2,6 @@ int _ses_path_cmp(const void* v0, const void* v1); -static inline void __ses_ur_i(double* a, double* ja, double v, double jv, double r, double jr) -{ - double R = r * r + jr * jr; - - *a = ( v * r + jv * jr) / R; - *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; - - *r = ( v * a + jv * ja) / R; - *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; -} - -static int __ses_path_jr(ScfEfunction* f, ses_path_t* path) -{ - if (!path) - return -EINVAL; - - if (path->pins->size < 2) { - scf_loge("\n"); - return -EINVAL; - } - - ses_path_t* child; - ScfEcomponent* c; - ScfEpin* p; - ScfEpin* p0; - ScfEpin* p1; - ScfEpin* cp0; - ScfEpin* cp1; - - double R; - double r; - double jr; - - int i; - int j; - - r = 0; - jr = 0; - - for (i = 0; i < path->pins->size; i++) { - p = path->pins->data[i]; - - r += p->r; - jr += p->jr; - - if (i & 0x1) { - c = f->components[p->cid]; - r += c->r; - jr += c->jr; - } - - p->sr = r; - p->jsr = jr; - - p->pr = r; - p->jpr = jr; - - scf_loge("i: %d, c%ldp%ld, p->tr: %lg, p->jtr: %lg\n", i, p->cid, p->id, p->sr, p->jsr); - } - 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]; - - 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; - p1 = NULL; - - for (j = 0; j < path->pins->size; j++) { - p = path->pins->data[j]; - - if (p->lid == cp0->lid) { - p0 = p; - break; - } - } - - if (!p0) - return -EINVAL; - - for ( ; j < path->pins->size; j++) { - p = path->pins->data[j]; - - if (p->lid == cp1->lid) { - p1 = p; - break; - } - } - - if (!p1) - return -EINVAL; - - R = child->r * child->r + child->jr * child->jr; - - double _r = child->r / R; - double _jr = -child->jr / R; - - r = p1->pr - p0->pr; - jr = p1->jpr - p0->jpr; - - R = r * r + jr * jr; - r = r / R; - jr = -jr / R; - - r += _r; - jr += _jr; - - R = r * r + jr * jr; - r = r / R; - jr = -jr / R; - - double dr = p1->pr - (p0->pr + r); - double jdr = p1->jpr - (p0->jpr + jr); - - for ( ; j < path->pins->size; j++) { - p = path->pins->data[j]; - - p->pr -= dr; - p->jpr -= jdr; - - scf_logw("j: %d, c%ldp%ld, p->pr: %lg + j%lg\n", j, p->cid, p->id, p->pr, p->jpr); - } - - scf_loge("child: %d, r: %lg, jr: %lg, r0: %lg, jr0: %lg, _r: %lg, _jr: %lg, dr: %lg, jdr: %lg\n\n", - child->index, child->r, child->jr, child->r0, child->jr0, _r, _jr, dr, jdr); - } - } - - p = path->pins->data[path->pins->size - 1]; - - path->r = p->pr; - path->jr = p->jpr; - - 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 __ses_path_va(ScfEfunction* f, ses_path_t* path) { if (!path) @@ -200,7 +42,7 @@ static int __ses_path_va(ScfEfunction* f, ses_path_t* path) double a = 0; double ja = 0; - __ses_ur_i(&a, &ja, v, jv, path->r, path->jr); + ses_ur_i(&a, &ja, v, jv, path->r, path->jr); 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); @@ -240,8 +82,8 @@ static int __ses_path_va(ScfEfunction* f, ses_path_t* path) double _a = 0; double _ja = 0; - __ses_ir_u(&_v, &_jv, a, ja, _r, _jr); - __ses_ur_i(&_a, &_ja, _v, _jv, child->r, child->jr); + ses_ir_u(&_v, &_jv, a, ja, _r, _jr); + ses_ur_i(&_a, &_ja, _v, _jv, child->r, child->jr); a -= _a; ja -= _ja; @@ -256,7 +98,7 @@ static int __ses_path_va(ScfEfunction* f, ses_path_t* path) } } - __ses_ir_u(&v, &jv, a, ja, p->sr, p->jsr); + ses_ir_u(&v, &jv, a, ja, p->sr, p->jsr); p->v = p0->v - v; p->jv = p0->jv - jv; @@ -276,7 +118,7 @@ static int __ses_path_va(ScfEfunction* f, ses_path_t* path) dv -= p->v; jdv -= p->jv; - __ses_ur_i(&p->a, &p->ja, dv, jdv, r, jr); + ses_ur_i(&p->a, &p->ja, dv, jdv, r, jr); 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); @@ -309,22 +151,10 @@ static int _va_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ct size_t j; size_t k; - 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(f, path); - if (ret < 0) - return ret; - - printf("\n"); - } - B = f->components[0]; Bp = B->pins[SCF_EDA_Battery_POS]; Bn = B->pins[SCF_EDA_Battery_NEG]; -#if 1 + printf("\n*******************\n"); for (i = 0; i < ctx->paths->size; i++) { @@ -349,7 +179,7 @@ static int _va_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ct printf("\n"); } -#endif + return 0; } @@ -358,5 +188,4 @@ ses_step_t ses_step_va = .name = "va", .handler = _va_handler, - }; diff --git a/ses_steps.c b/ses_steps.c index 4f2903f..c16d71b 100644 --- a/ses_steps.c +++ b/ses_steps.c @@ -13,6 +13,7 @@ extern ses_step_t ses_step_dc_transistor; extern ses_step_t ses_step_simplify; extern ses_step_t ses_step_topo; +extern ses_step_t ses_step_jr; extern ses_step_t ses_step_va; extern ses_step_t ses_step_va_balance; @@ -29,6 +30,8 @@ static ses_step_t* ses_steps[] = &ses_step_simplify, &ses_step_topo, + + &ses_step_jr, &ses_step_va, &ses_step_va_balance,