ses_flow_t
authoryu.dongliang <18588496441@163.com>
Thu, 14 Sep 2023 17:13:21 +0000 (01:13 +0800)
committeryu.dongliang <18588496441@163.com>
Thu, 14 Sep 2023 17:13:21 +0000 (01:13 +0800)
ses_core.h
ses_step_va_balance.c
ses_steps.c

index 36a6f49be39b12a4aa0d35735ceca4aff50aedc5..35a095be125544115917053342624392f9be8f19 100644 (file)
@@ -6,6 +6,7 @@
 
 typedef struct ses_step_s    ses_step_t;
 typedef struct ses_path_s    ses_path_t;
+typedef struct ses_flow_s    ses_flow_t;
 typedef struct ses_edge_s    ses_edge_t;
 typedef struct ses_ctx_s     ses_ctx_t;
 
@@ -19,6 +20,25 @@ struct ses_edge_s
        ScfEpin*       p1;
 };
 
+struct ses_flow_s
+{
+       scf_vector_t*  paths;
+
+       scf_vector_t*  ppins;
+       scf_vector_t*  npins;
+
+       ScfEpin*       vip;
+
+       double         r;
+       double         jr;
+
+       double         v;
+       double         jv;
+
+       double         a;
+       double         ja;
+};
+
 #define SES_PATH_MAIN    0
 #define SES_PATH_BRANCH  1
 #define SES_PATH_BRIDGE  2
@@ -64,6 +84,10 @@ ses_path_t* ses_path_alloc();
 void        ses_path_free (ses_path_t* path);
 void        ses_path_print(ses_path_t* path);
 
+ses_flow_t* ses_flow_alloc();
+void        ses_flow_free (ses_flow_t* flow);
+void        ses_flow_print(ses_flow_t* flow);
+
 ses_ctx_t*  ses_ctx_alloc();
 void        ses_ctx_free (ses_ctx_t* ctx);
 
index 70edea655d6e718c873be9387afb01a54ae1140b..9e99bd2aa0afcc8d53e82f5a43827aeaf696ba78 100644 (file)
@@ -1,48 +1,13 @@
 #include"ses_core.h"
 
-void ses_route_print(scf_vector_t* route)
+int ses_paths_find_flow(ses_flow_t* flow, scf_vector_t* paths, ScfEpin* vip, ses_path_t* bridge)
 {
-       if (!route || route->size <= 0)
-               return;
-
        ses_path_t* path;
-       ScfEpin*    p2;
        ScfEpin*    p;
 
        int i;
        int j;
 
-       p2 = route->data[0];
-
-       printf("route->size: %d, c%ldp%ld, ", route->size, p2->cid, p2->id);
-
-       for (i   = 0; i < route->size - 1; i++) {
-               path =        route->data[i];
-
-               for (j = 0; j < path->pins->size; j++) {
-                       p  =        path->pins->data[j];
-
-                       printf("c%ldp%ld ", p->cid, p->id);
-
-                       if (p->lid == p2->lid) {
-                               p2 = path->pins->data[0];
-                               break;
-                       }
-               }
-               printf(", ");
-       }
-
-       printf("\n");
-}
-
-int ses_paths_find_route(scf_vector_t* __route, scf_vector_t* paths, ScfEpin* p, ses_path_t* bridge)
-{
-       ses_path_t* path;
-       ScfEpin*    p2;
-
-       int i;
-       int j;
-
        for (i = 0; i < paths->size; i++) {
                path      = paths->data[i];
 
@@ -50,14 +15,12 @@ int ses_paths_find_route(scf_vector_t* __route, scf_vector_t* paths, ScfEpin* p,
                        continue;
 
                for (j = 0; j < path->pins->size; j++) {
-                       p2 =        path->pins->data[j];
+                       p  =        path->pins->data[j];
 
-                       if (p2->lid == p->lid) {
-       
-                               if (scf_vector_add(__route, p2) < 0)
-                                       return -1;
+                       if (vip ->lid == p->lid) {
+                               flow->vip  = p;
 
-                               if (scf_vector_add(__route, path) < 0)
+                               if (scf_vector_add(flow->paths, path) < 0)
                                        return -1;
                                return 1;
                        }
@@ -66,12 +29,12 @@ int ses_paths_find_route(scf_vector_t* __route, scf_vector_t* paths, ScfEpin* p,
                if (!path->childs)
                        continue;
 
-               int ret = ses_paths_find_route(__route, path->childs, p, bridge);
+               int ret = ses_paths_find_flow(flow, path->childs, p, bridge);
                if (ret < 0)
                        return ret;
 
                if (1 == ret) {
-                       if (scf_vector_add(__route, path) < 0)
+                       if (scf_vector_add(flow->paths, path) < 0)
                                return -1;
                        return 1;
                }
@@ -80,9 +43,9 @@ int ses_paths_find_route(scf_vector_t* __route, scf_vector_t* paths, ScfEpin* p,
        return 0;
 }
 
-static int __ses_path_va_balance(ScfEfunction* f, ses_path_t* bridge, scf_vector_t* route0, scf_vector_t* route1)
+static int __ses_path_va_balance(ScfEfunction* f, ses_path_t* bridge, ses_flow_t* flow0, ses_flow_t* flow1)
 {
-       if (!bridge)
+       if (!bridge || !flow0 || !flow1)
                return -EINVAL;
 
        if (bridge->pins->size < 2) {
@@ -90,23 +53,25 @@ static int __ses_path_va_balance(ScfEfunction* f, ses_path_t* bridge, scf_vector
                return -EINVAL;
        }
 
-       ses_path_t*    child;
        ScfEcomponent* c;
        ScfEline*      el;
        ScfEpin*       p;
-       ScfEpin*       p0;
-       ScfEpin*       p1;
-       ScfEpin*       p2;
-       ScfEpin*       rp0;
-       ScfEpin*       rp1;
+       ScfEpin*       p0    = bridge->pins->data[0];
+       ScfEpin*       p1    = bridge->pins->data[bridge->pins->size - 1];
+
+       ses_path_t*    path0 = flow0->paths->data[flow0->paths->size - 1];
+       ses_path_t*    path1 = flow1->paths->data[flow1->paths->size - 1];
+
+       ScfEpin*       r0p0  = path0->pins->data[0];
+       ScfEpin*       r0p1  = flow0->vip;
+
+       ScfEpin*       r1p0  = path1->pins->data[0];
+       ScfEpin*       r1p1  = flow1->vip;
 
        int i;
        int j;
        int k;
 
-       p0  = bridge->pins->data[0];
-       p1  = bridge->pins->data[bridge->pins->size - 1];
-
        el     = f->elines[p0->lid];
        p0->v  = el->v;
        p0->jv = el->jv;
@@ -117,26 +82,23 @@ static int __ses_path_va_balance(ScfEfunction* f, ses_path_t* bridge, scf_vector
 
        scf_loge("p0: %lg + j%lg, p1: %lg + j%lg, bridge->r: %lg + j%lg\n", p0->v, p0->jv, p1->v, p1->jv, bridge->r, bridge->jr);
 
-       rp0 = route0->data[0];
-       rp1 = route1->data[0];
+       if (p0->v > p1->v) {
 
-       scf_loge("rp0->pr: %lg + j%lg, rp1->pr: %lg + j%lg\n", rp0->pr, rp0->jpr, rp1->pr, rp1->jpr);
+               double v   = r0p0->v   - p1->v;
+               double jv  = r0p0->jv  - p1->jv;
 
-       if (p0->v > p1->v) {
+               double r0  = r0p1->pr  - r0p0->pr;
+               double jr0 = r0p1->jpr - r0p0->jpr;
 
-               for (i = 0; i < bridge->pins->size; i++) {
-                       p  =        bridge->pins->data[i];
+               double r   = r0  + bridge->r;
+               double jr  = jr0 + bridge->jr;
 
-                       c  = f->components[p->cid];
+               double a;
+               double ja;
 
-                       if (SCF_EDA_Diode == c->type) {
+               ses_ur_i(&a, &ja, v, jv, r, jr);
 
-                               if (SCF_EDA_Diode_NEG == p->id || p0->v - p1->v < SCF_EDA_V_Diode_OFF)
-                                       c->status = SCF_EDA_Status_OFF;
-                               else
-                                       c->status = SCF_EDA_Status_ON;
-                       }
-               }
+               scf_loge("r->pr: %lg + j%lg, v: %lg + j%lg, a: %lg + j%lg\n", r, jr, v, jv, a, ja);
 
        } else {
 
@@ -147,10 +109,10 @@ static int __ses_path_va_balance(ScfEfunction* f, ses_path_t* bridge, scf_vector
 
 static int _va_balance_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_ctx_t* ctx)
 {
-       scf_vector_t*  route0;
-       scf_vector_t*  route1;
-
+       ses_flow_t*    flow0;
+       ses_flow_t*    flow1;
        ses_path_t*    bridge;
+
        ScfEcomponent* B;
        ScfEpin*       p0;
        ScfEpin*       p1;
@@ -163,13 +125,13 @@ static int _va_balance_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_c
 
        printf("\n*******************\n");
 
-       route0 = scf_vector_alloc();
-       if (!route0)
+       flow0 = ses_flow_alloc();
+       if (!flow0)
                return -ENOMEM;
 
-       route1 = scf_vector_alloc();
-       if (!route1) {
-               scf_vector_free(route0);
+       flow1 = ses_flow_alloc();
+       if (!flow1) {
+               ses_flow_free(flow0);
                return -ENOMEM;
        }
 
@@ -193,32 +155,32 @@ static int _va_balance_handler(ScfEfunction* f, int64_t ns, int64_t count, ses_c
 
                ses_path_print(bridge);
 
-               route0->size = 0;
-               route1->size = 0;
+               flow0->paths->size = 0;
+               flow1->paths->size = 0;
 
-               int ret = ses_paths_find_route(route0, ctx->paths, p0, bridge);
+               int ret = ses_paths_find_flow(flow0, ctx->paths, p0, bridge);
                if (ret < 0)
                        return ret;
 
-               ret = ses_paths_find_route(route1, ctx->paths, p1, bridge);
+               ret = ses_paths_find_flow(flow1, ctx->paths, p1, bridge);
                if (ret < 0)
                        return ret;
 
-               ses_route_print(route0);
+               ses_flow_print(flow0);
                printf("\n");
 
-               ses_route_print(route1);
+               ses_flow_print(flow1);
                printf("\n");
 
-               ret = __ses_path_va_balance(f, bridge, route0, route1);
+               ret = __ses_path_va_balance(f, bridge, flow0, flow1);
                if (ret < 0)
                        return ret;
 
                printf("\n");
        }
 
-       scf_vector_free(route0);
-       scf_vector_free(route1);
+       ses_flow_free(flow0);
+       ses_flow_free(flow1);
        return 0;
 }
 
index 8306c207a4d43a27adc34fa399e63f089bc01261..04c434808b87b2e2105f7847dd514655189b3d77 100644 (file)
@@ -45,6 +45,107 @@ static ses_step_t*  ses_steps[] =
        &ses_step_output,
 };
 
+ses_flow_t* ses_flow_alloc()
+{
+       ses_flow_t* flow = calloc(1, sizeof(ses_flow_t));
+       if (!flow)
+               return NULL;
+
+       flow->paths = scf_vector_alloc();
+       if (!flow->paths)
+               goto _paths_error;
+
+       flow->ppins = scf_vector_alloc();
+       if (!flow->ppins)
+               goto _ppins_error;
+
+       flow->npins = scf_vector_alloc();
+       if (!flow->npins)
+               goto _npins_error;
+
+       return flow;
+
+_npins_error:
+       scf_vector_free(flow->ppins);
+_ppins_error:
+       scf_vector_free(flow->paths);
+_paths_error:
+       free(flow);
+       return NULL;
+}
+
+void ses_flow_free(ses_flow_t* flow)
+{
+       if (flow) {
+               if (flow->paths)
+                       scf_vector_free(flow->paths);
+
+               if (flow->ppins)
+                       scf_vector_free(flow->ppins);
+
+               if (flow->npins)
+                       scf_vector_free(flow->npins);
+
+               free(flow);
+       }
+}
+
+void ses_flow_print(ses_flow_t* flow)
+{
+       if (!flow || !flow->paths || !flow->vip)
+               return;
+
+       ses_path_t* path;
+       ScfEpin*    p;
+       ScfEpin*    vip = flow->vip;
+
+       int i;
+       int j;
+
+       for (i   = 0; i < flow->paths->size; i++) {
+               path =        flow->paths->data[i];
+
+               for (j = 0; j < path->pins->size; j++) {
+                       p  =        path->pins->data[j];
+
+                       printf("c%ldp%ld ", p->cid, p->id);
+
+                       if (p->lid == vip->lid) {
+                               vip = path->pins->data[0];
+                               break;
+                       }
+               }
+               printf(", ");
+       }
+
+       printf(";\n");
+
+       vip = flow->vip;
+
+       for (i   = 0; i < flow->paths->size; i++) {
+               path =        flow->paths->data[i];
+
+               int flag = 0;
+
+               for (j = 0; j < path->pins->size; j++) {
+                       p  =        path->pins->data[j];
+
+                       if (!flag && p->lid == vip->lid) {
+                               flag = 1;
+                               continue;
+                       }
+
+                       printf("c%ldp%ld ", p->cid, p->id);
+               }
+
+               printf(", ");
+
+               vip = path->pins->data[j - 1];
+       }
+
+       printf(".\n");
+}
+
 ses_path_t* ses_path_alloc()
 {
        ses_path_t* path = calloc(1, sizeof(ses_path_t));