double parent_r1;
double parent_jr1;
- double r0;
- double jr0;
-
- double a0;
- double ja0;
-
double r;
double jr;
double a;
double ja;
+ double a0;
+ double ja0;
+
double da;
double dja;
int ses_paths_find_flow(ses_flow_t* flow, scf_vector_t* paths, ScfEpin* vip, ses_path_t* bridge);
-void __ses_path_split_i(ScfEfunction* f, ses_path_t* path, int i, int j, double la, double jla, double* a, double* ja);
-int __ses_status_check(ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe);
-int __ses_topo_paths (ScfEfunction* f, scf_vector_t* paths);
+int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path);
+void __ses_path_split_i (ScfEfunction* f, ses_path_t* path, int i, int j, double la, double jla, double* a, double* ja);
+int __ses_status_check (ScfEfunction* f, ScfEcomponent* c, ScfEpin* pb, ScfEpin* pe);
+int __ses_topo_paths (ScfEfunction* f, scf_vector_t* paths);
int __ses_path_jr (ScfEfunction* f, ses_path_t* path);
void __ses_path_pr (ScfEfunction* f, ses_path_t* path, int i, int j, ScfEpin* cp1, double* r, double* jr);
pb->dr = pb->r * (SCF_EDA_V_NPN_ON - SCF_EDA_V_NPN_OFF) / (v - SCF_EDA_V_NPN_OFF + 0.001);
else
pb->dr = 1e12;
-
- scf_loge("v: %lg, pb->dr: %lg\n", v, pb->dr);
}
int __ses_path_da(ScfEfunction* f, ses_path_t* path, int* changed, double da, double dja)
}
}
- scf_loge("path: %d, r: %lg, r0: %lg\n\n", path->index, path->r, path->r0);
+ scf_loge("path: %d, r: %lg\n\n", path->index, path->r);
return 0;
}
int i;
int j;
- path->bridges = scf_vector_alloc();
- if (!path->bridges)
- return -ENOMEM;
+ if (!path->bridges) {
+ path->bridges = scf_vector_alloc();
+ if (!path->bridges)
+ return -ENOMEM;
+ }
for (i = 0; i < path->childs->size - 1; ) {
sp0 = path->childs->data[i];
int i;
int j;
+ scf_vector_clear(path->diodes, ( void (*)(void*) )free);
+ path->n_diodes = 0;
+
for (i = 0; i < path->pins->size; i++) {
p = path->pins->data[i];
if (SCF_EDA_Diode_NEG == p->id) {
info->n_diodes++;
+ path->n_diodes++;
if (__ses_branch_exist(path, i)) {
j = i;
}
info->n_NPNs++;
+ path->n_diodes++;
continue;
} else if (SCF_EDA_NPN_E == p->id) {
Bp = B->pins[SCF_EDA_Battery_POS];
Bn = B->pins[SCF_EDA_Battery_NEG];
- for (i = 0; i < paths->size; i++) {
- child = paths->data[i];
- child->index = i;
- }
-
for (i = paths->size - 1; i >= 1; i--) {
child = paths->data[i];
int ret = _topo_path_bridges(f, child);
if (ret < 0)
return ret;
-
- ret = _topo_path_diodes(f, child);
- if (ret < 0)
- return ret;
}
return 0;
int i;
+ path->n_diodes = 0;
+
for (i = 0; i < path->pins->size; i++) {
p = path->pins->data[i];
path = NULL;
}
+ for (i = 0; i < paths->size; i++) {
+ path = paths->data[i];
+
+ path->index = i;
+ }
+
return 0;
}
ScfEcomponent* B;
ScfEline* el;
- size_t i;
-
_topo_clear(f);
scf_vector_clear(ctx->paths, ( void (*)(void*) )ses_path_free);
int ret = _topo_paths(f, el, ctx->paths);
if (ret < 0)
return ret;
-#if 0
- ret = _topo_path_completes(f, ctx->paths);
- if (ret < 0)
- return ret;
-#endif
+
+ int size;
+ int i;
+
+ do {
+ size = ctx->paths->size;
+
+ for (i = 0; i < ctx->paths->size; i++) {
+ path = ctx->paths->data[i];
+
+ ret = _topo_diodes(f, path);
+ if (ret < 0)
+ return ret;
+ }
+
+ ret = _topo_layers(f, ctx->paths);
+ if (ret < 0)
+ return ret;
+
+ ret = _topo_path_completes(f, ctx->paths);
+ if (ret < 0)
+ return ret;
+ } while (size > ctx->paths->size);
+
for (i = 0; i < ctx->paths->size; i++) {
path = ctx->paths->data[i];
- scf_vector_clear(path->diodes, ( void (*)(void*) )free);
-
- ret = _topo_diodes(f, path);
+ ret = _topo_path_diodes(f, path);
if (ret < 0)
return ret;
}
- ret = _topo_layers(f, ctx->paths);
- if (ret < 0)
- return ret;
-
_topo_print(ctx->paths);
return 0;
}
#include"ses_core.h"
-int _ses_path_cmp(const void* v0, const void* v1);
-
static int __ses_path_split_a(ScfEfunction* f, ses_path_t* path, int i, double* a, double *ja, int* changed)
{
ses_path_t* child;
return -EINVAL;
}
- double _r = p2->pr - p->pr;
- double _jr = p2->jpr - p->jpr;
+ double r;
+ double jr;
- double _v = 0;
- double _jv = 0;
- double _a = 0;
- double _ja = 0;
+ double v;
+ double jv;
- __ses_path_pr(f, path, i, k, cp1, &_r, &_jr);
+ __ses_path_pr(f, path, i, k, cp1, &r, &jr);
- ses_ir_u(&_v, &_jv, *a, *ja, _r, _jr);
+ ses_ir_u(&v, &jv, *a, *ja, r, jr);
- scf_logw("child: %d, c%ldp%ld-c%ldp%ld (c%ldp%ld-c%ldp%ld), _v: %lg, a: %lg, _r: %lg, p->pr: %lg, p->dr: %lg, p2->pr: %lg\n",
- child->index, p->cid, p->id, p2->cid, p2->id, cp0->cid, cp0->id, cp1->cid, cp1->id, _v, *a, _r, p->pr, p->dr, p2->pr);
+ scf_logw("child: %d, c%ldp%ld-c%ldp%ld (c%ldp%ld-c%ldp%ld, n_diodes: %d), v: %lg, a: %lg, r: %lg\n",
+ child->index, p->cid, p->id, p2->cid, p2->id, cp0->cid, cp0->id, cp1->cid, cp1->id, child->n_diodes, v, *a, r);
- ses_ur_i(&_a, &_ja, _v, _jv, child->r, child->jr);
+ ses_ur_i(&child->a0, &child->ja0, v, jv, child->r, child->jr);
- *a -= _a;
- *ja -= _ja;
+ *a -= child->a0;
+ *ja -= child->ja0;
el = f->elines[p2->lid];
- el->v = p->v - _v;
- el->jv = p->jv - _jv;
+ el->v = p->v - v;
+ el->jv = p->jv - jv;
- scf_loge("child: %d, c%ldp%ld, c%ldp%ld, p->v: %lg, el->v: %lg, _v: %lg\n",
- child->index, p->cid, p->id, p2->cid, p2->id, p->v, el->v, _v);
+ if (child->n_diodes > 0) {
+ __ses_path_va_diode(f, child);
+ __ses_path_jr (f, child);
+ }
int ret = __ses_path_va(f, child, changed);
if (ret < 0)
return ret;
+ scf_loge("child: %d, c%ldp%ld-c%ldp%ld (c%ldp%ld-c%ldp%ld, n_diodes: %d), p->v: %lg, v: %lg, child->a0: %lg, child->a: %lg\n\n",
+ child->index, p->cid, p->id, p2->cid, p2->id, cp0->cid, cp0->id, cp1->cid, cp1->id, child->n_diodes, p->v, v, child->a0, child->a);
+
n++;
}
ses_ur_i(&path->a, &path->ja, v, jv, path->r, path->jr);
- scf_loge("path: %d, v: %lg, r: %lg, a: %lg\n\n", path->index, v, path->r, path->a);
+ scf_loge("path: %d, c%ldp%ld-c%ldp%ld, v: %lg, r: %lg, a: %lg\n\n",
+ path->index, p0->cid, p0->id, p1->cid, p1->id, v, path->r, path->a);
double a = path->a;
double ja = path->ja;
for (i = 0; i < path->pins->size; i++) {
p = path->pins->data[i];
- if (!(i & 0x1) && path->childs) {
-
- __ses_path_split_v(f, path, i0, i, a, ja);
+ __ses_path_split_v(f, path, i0, i, a, ja);
+ if (!(i & 0x1) && path->childs) {
int ret = __ses_path_split_a(f, path, i, &a, &ja, changed);
if (ret < 0)
return ret;
i0 = i;
scf_logd("i: %d, p0: c%ldp%ld\n", i, p0->cid, p0->id);
}
- } else
- __ses_path_split_v(f, path, i0, i, a, ja);
+ }
el = f->elines[p->lid];
el->v = p->v;
cp1 = child->pins->data[child->pins->size - 1];
if (p->lid == cp1->lid) {
- a += child->a;
- ja += child->ja;
-
- scf_logd("path: %d, i: %d, c%ldp%ld, child->a: %lg + j%lg\n", child->index, i, cp1->cid, cp1->id, child->a, child->ja);
+ a += child->a0;
+ ja += child->ja0;
}
}
}
ses_ir_u(&v, &jv, da_vip, dja_vip, r, jr);
}
- if (p->v - v < Bp->lid) {
+ el = f->elines[p->lid];
+
+ if (p->lid != Bp->lid && p->v - v < Bp->lid) {
p->v -= v;
p->jv -= jv;
- el = f->elines[p->lid];
el->v = p->v;
el->jv = p->jv;
}
int i;
int j;
- ses_ur_i(&da, &dja, dv_vip, djv_vip, flow->neg_r, flow->neg_jr);
-
for (i = 0; i < flow->paths->size; i++) {
path = flow->paths->data[i];
p = path->pins->data[j];
if (j0 < 0) {
- if (!(j & 0x1) && p->lid == vip->lid)
+ if (!(j & 0x1) && p->lid == vip->lid) {
j0 = j;
- else
+
+ ses_ur_i(&da, &dja, vip->v, vip->jv, flow->neg_r, flow->neg_jr);
+
+ da -= p->a;
+ dja -= p->ja;
+ } else
continue;
}
ses_ir_u(&v, &jv, da, dja, r, jr);
}
- if (p->v + v > Bn->lid) {
+ el = f->elines[p->lid];
+
+ if (p->lid != Bn->lid && p->v + v > Bn->lid) {
p->v += v;
p->jv += jv;
- el = f->elines[p->lid];
el->v = p->v;
el->jv = p->jv;
}
p->a += da;
p->ja += dja;
- scf_logw("c%ldp%ld->v: %lg, p->a: %lg, r: %lg, v: %lg, l%ld->v: %lg\n", p->cid, p->id, p->v, p->a, r, v, el->id, el->v);
+ scf_logw("c%ldp%ld->v: %lg, p->a: %lg, r: %lg, v: %lg, da: %lg\n", p->cid, p->id, p->v, p->a, r, v, da);
if (j & 0x1) {
if (SCF_EDA_Diode == c->type) {
*changed += __ses_status_check(f, c, p2, p);
__ses_pn_dr(c, p2, p);
+
}
} else if (SCF_EDA_NPN == c->type) {
double ja = 0;
double Eta = 0.001;
+ int __changed = 0;
+
int k = 0;
do {
scf_logw("k: %d, ****************\n", k);
p1->v = el->v;
p1->jv = el->jv;
- ret = __ses_path_va(f, bridge, changed);
+ if (bridge->n_diodes > 0) {
+ __ses_path_va_diode(f, bridge);
+ __ses_path_jr (f, bridge);
+ }
+
+ __changed = 0;
+
+ ret = __ses_path_va(f, bridge, &__changed);
if (ret < 0)
return ret;
- __ses_path_jr(f, bridge);
-
da = bridge->a - a;
dja = bridge->ja - ja;
v = flow->vip->v;
jv = flow->vip->jv;
- ret = __ses_flow_a_pos(f, flow, Eta * da, Eta * dja, changed);
+ ret = __ses_flow_a_pos(f, flow, Eta * da, Eta * dja, &__changed);
if (ret < 0)
return ret;
scf_logi("dv: %lg, v: %lg - %lg ----------------\n", dv, flow->vip->v, v);
- ret = __ses_flow_v_neg(f, flow, dv, djv, changed);
+ ret = __ses_flow_v_neg(f, flow, dv, djv, &__changed);
if (ret < 0)
return ret;
- __ses_path_jr(f, fpath);
- ses_flow_jr(flow, f);
-
scf_logw("flow vip: c%ldp%ld->a: %lg, vip_n: c%ldp%ld->a: %lg, bridge->a: %lg, diff: %lg\n\n",
flow->vip->cid, flow->vip->id, flow->vip->a,
flow->vip_n->cid, flow->vip_n->id, flow->vip_n->a,
bridge->a,
flow->vip->a - flow->vip_n->a - bridge->a);
+ ses_flow_jr(flow, f);
k++;
- } while (fabs(flow->vip->a - flow->vip_n->a - bridge->a) > 1e-4);
+ } while (0 == __changed && fabs(flow->vip->a - flow->vip_n->a - bridge->a) > 1e-4);
v = p0->v - p1->v;
jv = p0->jv - p1->jv;
- scf_loge("bridge: %d, c%ldp%ld--c%ldp%ld, v: %lg, p0->v: %lg, p1->v: %lg, n_diodes: %d, p0->a: %lg, p1->a: %lg\n",
- bridge->index, p0->cid, p0->id, p1->cid, p1->id, v, p0->v, p1->v, bridge->n_diodes, p0->a, p1->a);
+ changed += __changed;
+
+ scf_loge("bridge: %d, c%ldp%ld--c%ldp%ld, __changed: %d, v: %lg, p0->v: %lg, p1->v: %lg, n_diodes: %d, p0->a: %lg, p1->a: %lg\n",
+ bridge->index, p0->cid, p0->id, p1->cid, p1->id, __changed, v, p0->v, p1->v, bridge->n_diodes, p0->a, p1->a);
return 0;
}
return ret;
if (path->bridges) {
+ scf_vector_t* vec = scf_vector_clone(path->childs);
+ if (!vec)
+ return -ENOMEM;
+
+ ret = scf_vector_add(vec, path);
+ if (ret < 0) {
+ scf_vector_free(vec);
+ return ret;
+ }
+
for (j = 0; j < path->bridges->size; j++) {
child = path->bridges->data[j];
- ret = ses_path_va_bridge(f, child, changed, paths);
- if (ret < 0)
+ ret = ses_path_va_bridge(f, child, changed, vec);
+ if (ret < 0) {
+ scf_vector_free(vec);
return ret;
+ }
}
+
+ scf_vector_free(vec);
+ vec = NULL;
}
return 0;
#include"ses_core.h"
-static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path);
-
void __ses_path_split_i(ScfEfunction* f, ses_path_t* path, int i, int j, double la, double jla, double* a, double* ja)
{
ScfEcomponent* c;
scf_loge("c%ldp%ld--c%ldp%ld, r: %lg, v: %lg, a: %lg\n\n", p0->cid, p0->id, p1->cid, p1->id, r, v, *a);
}
-static int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
+int __ses_path_va_diode(ScfEfunction* f, ses_path_t* path)
{
ses_path_t* child;
ses_info_t* info;
return 1;
}
-static int __ses_status_change(ScfEfunction* f, ScfEline* el)
-{
- ScfEcomponent* c;
- ScfEcomponent* B;
- ScfEpin* Bp;
- ScfEpin* Bn;
- ScfEpin* p;
- ScfEpin* pe;
-
- size_t j;
- int changed = 0;
-
- B = f->components[0];
- Bp = B->pins[SCF_EDA_Battery_POS];
- Bn = B->pins[SCF_EDA_Battery_NEG];
-
- for (j = 0; j + 1 < el->n_pins; j += 2) {
-
- c = f->components[el->pins[j]];
- p = c->pins [el->pins[j + 1]];
-
- if (SCF_EDA_NPN == c->type) {
- if (SCF_EDA_NPN_B == p->id) {
-
- pe = c->pins[SCF_EDA_NPN_E];
- changed += __ses_status_check(f, c, p, pe);
- }
-
- } else if (SCF_EDA_Diode == c->type) {
-
- if (SCF_EDA_Diode_POS == p->id) {
-
- pe = c->pins[SCF_EDA_Diode_NEG];
- changed += __ses_status_check(f, c, p, pe);
- }
- }
- }
-
- return changed;
-}
-
static int __ses_path_va_transistor(ScfEfunction* f, ses_path_t* path)
{
ses_path_t* parent = path->parent;
&ses_step_dc_diode,
&ses_step_dc_transistor,
-// &ses_step_simplify,
&ses_step_topo,
&ses_step_jr,
&ses_step_va_diode,
&ses_step_va_transistor,
-#if 1
+
&ses_step_jr,
&ses_step_va,
&ses_step_va_bridge,
-// &ses_step_va_balance,
-#endif
};
static ses_step_t* ses_steps_2[] =
return ret;
int j;
- for (j = 0; j < 3; j++) {
+ for (j = 0; j < 2; j++) {
printf("\n\033[33m%s(), %d(), j: %d\033[0m\n", __func__, __LINE__, j);
ret = __ses_steps_analyse(f, ns, i, ctx);
break;
if (ret < 0)
- return ret;
+ break;
}
ret = __ses_steps_output(f, ns, i, ctx);
if (vip ->lid == p->lid) {
- if (j + 1 >= path->pins->size) {
- scf_loge("ses_paths_find_flow error\n");
- return -1;
- }
+ if (j + 1 >= path->pins->size)
+ break;
flow->vip = p;
flow->vip_n = path->pins->data[j + 1];;
if (SCF_EDA_NPN == c->type && SCF_EDA_NPN_E == p->id) {
p = path->pins->data[j - 1];
- if (p == p0) {
+ if (p->lid == p0->lid) {
flow->neg_r += p->r + p->dr;
flow->neg_jr += p->jr + p->jdr;
} else {
flow->neg_r += p->pr - p0->pr;
flow->neg_jr += p->jpr - p0->jpr;
}
-
scf_loge("flow->neg_r: %lg, c%ldp%ld->sr: %lg, p0 c%ldp%ld->pr: %lg\n",
flow->neg_r, p->cid, p->id, p->sr, p0->cid, p0->id, p0->pr);