tmp
authoryu.dongliang <18588496441@163.com>
Fri, 27 Oct 2023 14:05:36 +0000 (22:05 +0800)
committeryu.dongliang <18588496441@163.com>
Fri, 27 Oct 2023 14:05:36 +0000 (22:05 +0800)
ses_core.h
ses_step_dc_input.c
ses_step_va_diode.c
ses_steps.c

index 5327c49f1cd8481ba5a499d4a7c9fa0d2a63cc6c..6ebf8c56d0eea79722683e452920c8ef382b019e 100644 (file)
@@ -11,14 +11,6 @@ typedef struct ses_edge_s    ses_edge_t;
 typedef struct ses_info_s    ses_info_t;
 typedef struct ses_ctx_s     ses_ctx_t;
 
-struct ses_info_s
-{
-       int i;
-       int j;
-       int n_diodes;
-       int n_NPNs;
-};
-
 struct ses_edge_s
 {
        ScfEline*      el0;
@@ -52,6 +44,14 @@ struct ses_flow_s
 #define SES_PATH_BRANCH  1
 #define SES_PATH_BRIDGE  2
 
+struct ses_info_s
+{
+       int            i;
+       int            j;
+       int            n_diodes;
+       int            n_NPNs;
+};
+
 struct ses_path_s
 {
        scf_vector_t*  pins;
index 5b6fb05c1cd4b25b514c1468de332953054ad53e..ea0f5ab53b0abba9b9803adcd82ac1ddc7eabdc4 100644 (file)
@@ -22,7 +22,7 @@ static int _dc_input_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx
                if (!(SCF_EDA_PIN_IN & el->flags))
                        continue;
 
-               k   = SCF_EDA_Battery_POS;
+               k   = 0;
                el2 = f->elines[B->pins[k]->lid];
 
                el->v      = k * B->v;
index 5dee919150cb21bc5606287f6d00ff972220af4d..0b8e44419d273a247869ee76390b5e55431b981a 100644 (file)
@@ -202,6 +202,8 @@ void __ses_path_dr_reverse(ScfEfunction* f, ses_path_t* path, int i, int j, doub
 static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
 {
        ses_path_t*    child;
+       ses_info_t*    info;
+
        ScfEcomponent* c;
        ScfEline*      el;
        ScfEpin*       p;
@@ -212,7 +214,6 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
 
        int i;
        int j;
-       int k;
 
        p0 = path->pins->data[0];
        p1 = path->pins->data[path->pins->size - 1];
@@ -225,181 +226,93 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
        p1->v  = el->v;
        p1->jv = el->jv;
 
-       int i_diodes = 0;
-       int j_diodes = 0;
-       int i_NPNs   = 0;
-       int j_NPNs   = 0;
-
-       for (i = 0; i < path->pins->size; i++) {
-               pi =        path->pins->data[i];
-
-               el = f->elines    [pi->lid];
-               c  = f->components[pi->cid];
-
-               if (SCF_EDA_Diode == c->type) {
-                       i_diodes++;
-                       continue;
-               }
-
-               if (SCF_EDA_NPN != c->type)
-                       break;
+       double v  = p0->v   - p1->v;
+       double jv = p0->jv  - p1->jv;
 
-               if (SCF_EDA_NPN_C == pi->id)
-                       return 0;
+       double r  = 0;
+       double jr = 0;
 
-               i_NPNs++;
-       }
-
-       for (j = path->pins->size - 1; j >= i; j--) {
-               pj = path->pins->data[j];
+       double a;
+       double ja;
 
-               el = f->elines    [pj->lid];
-               c  = f->components[pj->cid];
+       i = 0;
 
-               if (SCF_EDA_Diode == c->type) {
-                       j_diodes++;
-                       continue;
-               }
+       for (j = 0; j < path->diodes->size; j++) {
+               info      = path->diodes->data[j];
+               pi        = path->pins->data[i];
+               pj        = path->pins->data[info->i];
 
-               if (SCF_EDA_NPN != c->type)
-                       break;
+               v  -= info->n_diodes * SCF_EDA_V_Diode_ON;
+               v  -= info->n_NPNs   * SCF_EDA_V_NPN_ON;
 
-               if (SCF_EDA_NPN_C == pj->id)
-                       return 0;
+               r  += pj->pr  - pj->r  - pi->pr;
+               jr += pj->jpr - pj->jr - pi->jpr;
 
-               j_NPNs++;
-       }
+               scf_logi("i: %d, info->i: %d, c%ldp%ld--c%ldp%ld, r: %lg, v: %lg\n", i, info->i, pi->cid, pi->id, pj->cid, pj->id, r, v);
 
-       if (j <= i) {
-               scf_loge("all components are Diode\n");
-               return -1;
+               i = info->j;
        }
 
-       i_diodes >>= 1;
-       j_diodes >>= 1;
-
-       i_NPNs   >>= 1;
-       j_NPNs   >>= 1;
-
-       double __vi = p0->v - SCF_EDA_V_Diode_ON * i_diodes - SCF_EDA_V_NPN_ON * i_NPNs;
-       double __vj = p1->v + SCF_EDA_V_Diode_ON * j_diodes + SCF_EDA_V_NPN_ON * j_NPNs;
-
-       scf_logd("i: %d, c%ldp%ld, __vi: %lg, i_diodes: %d, i_NPNs: %d\n", i, pi->cid, pi->id, __vi, i_diodes, i_NPNs);
-       scf_logd("j: %d, c%ldp%ld, __vj: %lg, j_diodes: %d, j_NPNs: %d\n", j, pj->cid, pj->id, __vj, j_diodes, j_NPNs);
-
-       pi->v = __vi;
-       pj->v = __vj;
+       if (i  < path->pins->size - 1) {
+               pi = path->pins->data[i];
 
-       if (j  < path->pins->size - 1)
-               pj = path->pins->data[++j];
-       pj->v = __vj;
+               r  += p1->sr  - p1->r  - pi->pr;
+               jr += p1->jsr - p1->jr - pi->jpr;
 
-       double v   = pi->v   - pj->v;
-       double jv  = pi->jv  - pj->jv;
-
-       double pr  = pj->pr  - pj->r  - pi->pr;
-       double jpr = pj->jpr - pj->jr - pi->jpr;
-
-       double sr  = pj->sr  - pj->r  - pi->sr;
-       double jsr = pj->jsr - pj->jr - pi->jsr;
-
-       double a;
-       double ja;
-
-       if (j == path->pins->size - 1
-                       && p1->sr  == p1->pr
-                       && p1->jsr == p1->jpr)
-               ses_ur_i(&a, &ja, v, jv, pr, jpr);
-       else
-               ses_ur_i(&a, &ja, v, jv, sr, jsr);
+               scf_logi("i: %d, info->i: %d, c%ldp%ld--c%ldp%ld, r: %lg, v: %lg\n", i, path->pins->size - 1, pi->cid, pi->id, p1->cid, p1->id, r, v);
+       }
 
-       c = f->components[pj->cid];
+       ses_ur_i(&a, &ja, v, jv, r, jr);
 
        path->a  = a;
        path->ja = ja;
 
-       scf_logd("i: %d, j: %d, c%ldp%ld--c%ldp%ld, a: %lg\n", i, j, pi->cid, pi->id, pj->cid, pj->id, a);
+       i = 0;
 
-       if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_POS == pj->id) {
+       for (j = 0; j < path->diodes->size; j++) {
+               info      = path->diodes->data[j];
+               pi        = path->pins->data[info->i];
+               pj        = path->pins->data[info->j];
 
-               el         = f->elines[pj->lid];
-               el->a      = a;
-               el->ja     = ja;
-               el->aconst = 1;
-
-               pj->a      = a;
-               pj->ja     = ja;
-
-               if (path->childs)
-                       __ses_path_split_i(f, path, j, path->pins->size - 1, a, ja, &pj->a, &pj->ja);
-
-               scf_loge("j: %d, c%ldp%ld--c%ldp%ld, v: %lg, pj->v: %lg, pj->a: %lg, pr: %lg, sr: %lg\n\n",
-                               j, pj->cid, pj->id, p1->cid, p1->id, v, pj->v, pj->a, pr, sr);
-
-               __ses_path_dr_forward(f, path, j, path->pins->size - 1, pj->a, pj->ja);
-
-       } else if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_B == pj->id) {
-
-               el         = f->elines[pj->lid];
-               el->a      = a;
-               el->ja     = ja;
-               el->aconst = 1;
-
-               pj->a      = a;
-               pj->ja     = ja;
+               c = f->components[pi->cid];
 
-               if (path->childs)
-                       __ses_path_split_i(f, path, j, path->pins->size - 1, a, ja, &pj->a, &pj->ja);
+               assert((SCF_EDA_Diode == c->type && SCF_EDA_Diode_POS == pi->id)
+                       || (SCF_EDA_NPN   == c->type && SCF_EDA_NPN_B     == pi->id));
 
-               scf_loge("j: %d, c%ldp%ld--c%ldp%ld, v: %lg, pj->v: %lg, pj->a: %lg, pr: %lg, sr: %lg\n\n",
-                               j, pj->cid, pj->id, p1->cid, p1->id, v, pj->v, pj->a, pr, sr);
+               pi->a  = a;
+               pi->ja = ja;
 
-               __ses_path_dr_forward(f, path, j, path->pins->size - 1, pj->a, pj->ja);
-       }
+               __ses_path_pr(f, path, i, info->i, NULL, &r, &jr);
 
-       if (i  > 0)
-               pi = path->pins->data[--i];
-       pi->v = __vi;
+               ses_ir_u(&v, &jv, a, ja, r, jr);
 
-       c = f->components[pi->cid];
+               pi->v  = p0->v  - v;
+               pi->jv = p0->jv - jv;
 
-       if (SCF_EDA_Diode == c->type && SCF_EDA_Diode_NEG == pi->id) {
+               pj->v  = pi->v  - info->n_diodes * SCF_EDA_V_Diode_ON - info->n_NPNs * SCF_EDA_V_NPN_ON;
+               pj->jv = pi->jv;
 
                el         = f->elines[pi->lid];
                el->a      = a;
                el->ja     = ja;
+               el->v      = pi->v;
+               el->jv     = pi->jv;
                el->aconst = 1;
 
-               pi->a      = a;
-               pi->ja     = ja;
-
-               if (path->childs)
-                       __ses_path_split_i(f, path, 0, i, a, ja, &pi->a, &pi->ja);
-
-               __ses_path_dr_reverse(f, path, 0, i, pi->a, pi->ja);
-
-               scf_loge("i: %d, c%ldp%ld--c%ldp%ld, v: %lg, pi->v: %lg, pi->a: %lg, pr: %lg, sr: %lg\n\n",
-                               i, p0->cid, p0->id, pi->cid, pi->id, v, pi->v, pi->a, pr, sr);
-
-       } else if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == pj->id) {
-
-               el         = f->elines[pi->lid];
+               el         = f->elines[pj->lid];
                el->a      = a;
                el->ja     = ja;
+               el->v      = pj->v;
+               el->jv     = pj->jv;
                el->aconst = 1;
 
-               pi->a      = a;
-               pi->ja     = ja;
-
                if (path->childs)
-                       __ses_path_split_i(f, path, 0, i, a, ja, &pi->a, &pi->ja);
-
-               p = c->pins[SCF_EDA_NPN_B];
+                       __ses_path_split_i(f, path, info->i, info->j, a, ja, &pi->a, &pi->ja);
 
-               __ses_path_dr_reverse(f, path, 0, i, pi->a, pi->ja);
+               scf_loge("info->i: %d, info->j: %d, c%ldp%ld--c%ldp%ld, pi->v: %lg, pj->v: %lg, pi->a: %lg\n\n",
+                               info->i, info->j, pi->cid, pi->id, pj->cid, pj->id, pi->v, pj->v, pi->a);
 
-               scf_loge("i: %d, c%ldp%ld--c%ldp%ld, v: %lg, pi->v: %lg, pi->a: %lg, pr: %lg, sr: %lg\n\n",
-                               i, p0->cid, p0->id, pi->cid, pi->id, v, pi->v, pi->a, pr, sr);
+               __ses_path_dr_forward(f, path, info->i, info->j, pi->a, pi->ja);
        }
 
        return 0;
index 901c5ddfcb7ac1d17dbd0c984e6eeb1412bbc818..177965dcd478abae2fe3064b7215dedaeae59780 100644 (file)
@@ -141,7 +141,7 @@ int ses_steps_analyse(ScfEfunction* f, int64_t ns, int64_t count)
                        return ret;
 
                int j;
-               for (j = 0; j < 2; j++) {
+               for (j = 0; j < 1; j++) {
                        printf("\n\033[33m%s(), %d(), j: %d\033[0m\n", __func__, __LINE__, j);
 
                        ret = __ses_steps_analyse(f, ns, i, ctx);