ses_step_va_diode.c
authoryu.dongliang <18588496441@163.com>
Wed, 6 Sep 2023 06:52:22 +0000 (14:52 +0800)
committeryu.dongliang <18588496441@163.com>
Wed, 6 Sep 2023 06:52:22 +0000 (14:52 +0800)
ses_step_va_diode.c
ses_step_va_transistor.c

index 7986b07cf8c8ab1c1b9df93fbe8176107ffab802..bcc433c226ee4404f80665013a626f8572cb77d5 100644 (file)
@@ -43,6 +43,8 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
        double r;
        double jr;
 
+       scf_logi("path->type: %d\n", path->type);
+
        for (i = 0; i < path->pins->size; i++) {
                p  =        path->pins->data[i];
 
@@ -72,6 +74,12 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
                        el->ja     = ja;
                        el->aconst = 1;
 
+                       scf_loge("i: %d, c%ldp%ld, v: %lg + j%lg, p->v: %lg + j%lg, r: %lg + j%lg, el->a: %lg + j%lg\n\n", i, p->cid, p->id,
+                                       v, jv, p->v, p->jv, r, jr, el->a, el->ja);
+
+                       v  = p->v  - p1->v;
+                       jv = p->jv - p1->jv;
+
                        if (path->childs) {
                                for (j    = 0; j < path->childs->size; j++) {
                                        child =        path->childs->data[j];
@@ -84,12 +92,18 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
 
                                        ses_split_i(&child->a, &child->ja, el->a, el->ja, child->r, child->jr, r, jr);
 
+                                       a  -= child->a;
+                                       ja -= child->ja;
+
+                                       scf_loge("j: %d, c%ldp%ld, v: %lg + j%lg, child->r: %lg + j%lg, child->a: %lg + j%lg\n\n", j, cp0->cid, cp0->id,
+                                                       v, jv, child->r, child->jr, child->a, child->ja);
+
+                                       cp0->a  = child->a;
+                                       cp0->ja = child->ja;
+
                                        double cr;
                                        double jcr;
 
-                                       v  = p->v  - p1->v;
-                                       jv = p->jv - p1->jv;
-
                                        ses_ui_r(&cr, &jcr, v, jv, child->a, child->ja);
 
                                        for (k = 0; k < child->pins->size; k++) {
@@ -106,6 +120,9 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
                                }
                        }
 
+                       p->a  = a;
+                       p->ja = ja;
+
                } else {
                        v  = p->v  - p1->v;
                        jv = p->jv - p1->jv;
@@ -116,16 +133,14 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
                        el->ja     = ja;
                        el->aconst = 1;
                }
-
        }
        printf("\n");
 
        return 0;
 }
 
-static int _va_diode_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
+static int _ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
 {
-       ses_path_t*    path;
        ScfEcomponent* B;
        ScfEpin*       p0;
        ScfEpin*       p1;
@@ -136,27 +151,49 @@ static int _va_diode_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx
        size_t j;
        size_t k;
 
+       if (path->pins->size < 2) {
+               scf_loge("\n");
+               return -EINVAL;
+       }
+
        B  = f->components[0];
        Bp = B->pins[SCF_EDA_Battery_POS];
        Bn = B->pins[SCF_EDA_Battery_NEG];
 
-       for (i = 0; i < ctx->paths->size; i++) {
-               path      = ctx->paths->data[i];
+       p0 = path->pins->data[0];
+       p1 = path->pins->data[path->pins->size - 1];
 
-               scf_logi("i: %ld, path->type: %d\n", i, path->type);
+       if (p0->lid != Bp->lid || p1->lid != Bn->lid)
+               return 0;
+
+       int ret = __ses_path_va_diode(f, path);
+       if (ret < 0)
+               return ret;
+
+       if (path->childs) {
+               for (j = 0; j < path->childs->size; j++) {
 
-               if (path->pins->size < 2) {
-                       scf_loge("\n");
-                       return -EINVAL;
+                       ret = _ses_path_va_diode(f, path->childs->data[j]);
+                       if (ret < 0)
+                               return ret;
                }
+       }
 
-               p0 = path->pins->data[0];
-               p1 = path->pins->data[path->pins->size - 1];
+       return 0;
+}
 
-               if (p0->lid != Bp->lid || p1->lid != Bn->lid)
-                       continue;
+static int _va_diode_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
+{
+       ses_path_t* path;
+
+       size_t i;
+
+       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_va_diode(f, path);
+               int ret = _ses_path_va_diode(f, path);
                if (ret < 0)
                        return ret;
 
index f773d588a6fc8871847bcbad55446f5bd80d1006..38118edc94a16f04fba8538b7f51a0a700a5e2d8 100644 (file)
@@ -86,7 +86,7 @@ static int _va_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, se
        B  = f->components[0];
        Bp = B->pins[SCF_EDA_Battery_POS];
        Bn = B->pins[SCF_EDA_Battery_NEG];
-
+#if 0
        for (i = 0; i < ctx->paths->size; i++) {
                path      = ctx->paths->data[i];
 
@@ -109,7 +109,7 @@ static int _va_transistor_handler(ScfEfunction* f, int64_t ns, int64_t count, se
 
                printf("\n");
        }
-
+#endif
        return 0;
 }