tmp
authoryu.dongliang <18588496441@163.com>
Wed, 6 Sep 2023 06:03:07 +0000 (14:03 +0800)
committeryu.dongliang <18588496441@163.com>
Wed, 6 Sep 2023 06:03:07 +0000 (14:03 +0800)
ses_core.h
ses_step_va_diode.c

index 92eebf9031b22942eb96d8a57bf39fa22cd3db3f..6a2e12d6822dbce9b7db232ac12fef9f12499b10 100644 (file)
@@ -116,4 +116,15 @@ static inline void ses_ir_u(double* v, double* jv, double a, double ja, double r
        *jv = ja * r  +  a * jr;
 }
 
+static inline void ses_split_i(double* a, double* ja, double ta, double jta, double r, double jr, double pr, double jpr)
+{
+       double R  = r * r + jr * jr;
+
+       double t  =  ta * pr - jta * jpr;
+       double jt = jta * pr +  ta * jpr;
+
+       *a  = ( t * r + jt * jr) / R;
+       *ja = (jt * r -  t * jr) / R;
+}
+
 #endif
index 4c163ebeb77f9b522e7e69a7bebe232f5d88faac..7986b07cf8c8ab1c1b9df93fbe8176107ffab802 100644 (file)
@@ -17,6 +17,7 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
        ScfEpin*       p0;
        ScfEpin*       p1;
        ScfEpin*       p2;
+       ScfEpin*       cp;
        ScfEpin*       cp0;
        ScfEpin*       cp1;
 
@@ -35,35 +36,87 @@ static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
        p1->v  = el->v;
        p1->jv = el->jv;
 
-       double v  = p0->v  - p1->v;
-       double jv = p0->jv - p1->jv;
-       double a  = 0;
-       double ja = 0;
+       double v;
+       double jv;
+       double a;
+       double ja;
+       double r;
+       double jr;
 
-       ses_ur_i(&a, &ja, v, jv, path->r, path->jr);
+       for (i = 0; i < path->pins->size; i++) {
+               p  =        path->pins->data[i];
 
-       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);
+               el = f->elines    [p->lid];
+               c  = f->components[p->cid];
 
-       double r   = 0;
-       double jr  = 0;
-       double dv  = 0;
-       double jdv = 0;
+               if (!el->vconst)
+                       continue;
 
-       for (i = 0; i < path->pins->size; i++) {
-               p  =        path->pins->data[i];
+               if (SCF_EDA_Diode != c->type)
+                       continue;
+
+               p->v  = el->v;
+               p->jv = el->jv;
+
+               if (SCF_EDA_Diode_POS == p->id) {
+
+                       v  = p0->v  - p->v;
+                       jv = p0->jv - p->jv;
+
+                       r  = p1->pr  - p->pr;
+                       jr = p1->jpr - p->jpr;
+
+                       ses_ur_i(&a, &ja, v, jv, p->pr, p->jpr);
+
+                       el->a      = a;
+                       el->ja     = ja;
+                       el->aconst = 1;
 
-               if (path->childs) {
-                       for (j    = 0; j < path->childs->size; j++) {
-                               child =        path->childs->data[j];
+                       if (path->childs) {
+                               for (j    = 0; j < path->childs->size; j++) {
+                                       child =        path->childs->data[j];
 
-                               cp0 = child->pins->data[0];
-                               cp1 = child->pins->data[child->pins->size - 1];
+                                       cp0 = child->pins->data[0];
+                                       cp1 = child->pins->data[child->pins->size - 1];
 
-                               int ret = __ses_path_va_diode(f, child);
-                               if (ret < 0)
-                                       return ret;
+                                       if (cp0->lid != p->lid || cp1->lid != p1->lid)
+                                               continue;
+
+                                       ses_split_i(&child->a, &child->ja, el->a, el->ja, child->r, child->jr, r, jr);
+
+                                       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++) {
+                                               cp =        child->pins->data[k];
+
+                                               c  = f->components[cp->cid];
+
+                                               if (SCF_EDA_Diode == c->type) {
+                                                       cp->dr  = cr  - child->r;
+                                                       cp->jdr = jcr - child->jr;
+                                                       break;
+                                               }
+                                       }
+                               }
                        }
+
+               } else {
+                       v  = p->v  - p1->v;
+                       jv = p->jv - p1->jv;
+
+                       ses_ur_i(&a, &ja, v, jv, p1->pr - p->pr, p1->jpr - p->jpr);
+
+                       el->a      = a;
+                       el->ja     = ja;
+                       el->aconst = 1;
                }
+
        }
        printf("\n");