pa-243
This commit is contained in:
parent
01c1a472c5
commit
5197222fbf
|
|
@ -853,13 +853,17 @@ int snp2va_convert(const char *snpfile, const char *vafile, const char *module,
|
|||
fprintf(fo, "// Generated by pre_snp from %s\n", snpfile);
|
||||
fprintf(fo, "// %d-port, %d common poles; structured realization (%d laplace_nd filters, AC + transient).\n",
|
||||
N, Np, nfilt);
|
||||
/* E-243: an explicit `ref` reference terminal (last port), so every branch is
|
||||
* V(pi,ref)/I(pi,ref) and the instance line -- `N1 p1..pN ref model` -- is
|
||||
* IDENTICAL to the native `nport` device (tie ref to 0 for a ground-referenced
|
||||
* Touchstone block). */
|
||||
fprintf(fo, "module %s(", module);
|
||||
for (i = 0; i < N; i++) fprintf(fo, "%sp%d", i?", ":"", i+1);
|
||||
fprintf(fo, ");\n inout ");
|
||||
fprintf(fo, ", ref);\n inout ");
|
||||
for (i = 0; i < N; i++) fprintf(fo, "%sp%d", i?", ":"", i+1);
|
||||
fprintf(fo, ";\n electrical ");
|
||||
fprintf(fo, ", ref;\n electrical ");
|
||||
for (i = 0; i < N; i++) fprintf(fo, "%sp%d", i?", ":"", i+1);
|
||||
fprintf(fo, ";\n");
|
||||
fprintf(fo, ", ref;\n");
|
||||
/* variable declarations */
|
||||
for (c = 0; c < nchan; c++) {
|
||||
if (chMx[c]==0.0) continue;
|
||||
|
|
@ -881,20 +885,20 @@ int snp2va_convert(const char *snpfile, const char *vafile, const char *module,
|
|||
int first=1; fprintf(fo, " g%d_%d = ", c, m);
|
||||
for (j=0;j<N;j++){ double v=chV[c][j*ch_r[c]+m];
|
||||
if (fabs(v)>1e-30){ term_sep(fo,&first);
|
||||
if (ch_kind[c]==0) fprintf(fo,"(%.12g)*V(p%d)",v,j+1); else fprintf(fo,"(%.12g)*ddt(V(p%d))",v,j+1); } }
|
||||
if (ch_kind[c]==0) fprintf(fo,"(%.12g)*V(p%d,ref)",v,j+1); else fprintf(fo,"(%.12g)*ddt(V(p%d,ref))",v,j+1); } }
|
||||
if (first) fprintf(fo,"0.0"); fprintf(fo,";\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
int sc=ch_sec[c], kk=sc_pole[sc];
|
||||
if (!ch_lr[c]) { /* dense: one laplace_nd per input port */
|
||||
for (j=0;j<N;j++){ fprintf(fo," w%d_%d = laplace_nd(V(p%d), ", c, j, j+1);
|
||||
for (j=0;j<N;j++){ fprintf(fo," w%d_%d = laplace_nd(V(p%d,ref), ", c, j, j+1);
|
||||
emit_filter(fo, P[kk], sc_kind[sc]); fprintf(fo,");\n"); }
|
||||
} else { /* low-rank: r combined inputs, each filtered once */
|
||||
for (m=0;m<ch_r[c];m++){
|
||||
int first=1; fprintf(fo," u%d_%d = ", c, m);
|
||||
for (j=0;j<N;j++){ double v=chV[c][j*ch_r[c]+m];
|
||||
if (fabs(v)>1e-30){ term_sep(fo,&first); fprintf(fo,"(%.12g)*V(p%d)",v,j+1); } }
|
||||
if (fabs(v)>1e-30){ term_sep(fo,&first); fprintf(fo,"(%.12g)*V(p%d,ref)",v,j+1); } }
|
||||
if (first) fprintf(fo,"0.0"); fprintf(fo,";\n");
|
||||
fprintf(fo," h%d_%d = laplace_nd(u%d_%d, ", c, m, c, m);
|
||||
emit_filter(fo, P[kk], sc_kind[sc]); fprintf(fo,");\n");
|
||||
|
|
@ -903,7 +907,7 @@ int snp2va_convert(const char *snpfile, const char *vafile, const char *module,
|
|||
}
|
||||
/* output currents */
|
||||
for (i = 0; i < N; i++) {
|
||||
int first = 1; fprintf(fo, " I(p%d) <+ ", i+1);
|
||||
int first = 1; fprintf(fo, " I(p%d,ref) <+ ", i+1);
|
||||
for (c = 0; c < nchan; c++) {
|
||||
if (chMx[c]==0.0) continue;
|
||||
if (ch_lr[c]) {
|
||||
|
|
@ -914,8 +918,8 @@ int snp2va_convert(const char *snpfile, const char *vafile, const char *module,
|
|||
double thr = tol_drop*chMx[c];
|
||||
for (j=0;j<N;j++){ double w=chW[c][i*N+j];
|
||||
if (fabs(w)>thr){ term_sep(fo,&first);
|
||||
if (ch_kind[c]==0) fprintf(fo,"(%.12g)*V(p%d)",w,j+1);
|
||||
else if (ch_kind[c]==1) fprintf(fo,"(%.12g)*ddt(V(p%d))",w,j+1);
|
||||
if (ch_kind[c]==0) fprintf(fo,"(%.12g)*V(p%d,ref)",w,j+1);
|
||||
else if (ch_kind[c]==1) fprintf(fo,"(%.12g)*ddt(V(p%d,ref))",w,j+1);
|
||||
else fprintf(fo,"(%.12g)*w%d_%d",w,c,j); } }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -853,13 +853,17 @@ int snp2va_convert(const char *snpfile, const char *vafile, const char *module,
|
|||
fprintf(fo, "// Generated by pre_snp from %s\n", snpfile);
|
||||
fprintf(fo, "// %d-port, %d common poles; structured realization (%d laplace_nd filters, AC + transient).\n",
|
||||
N, Np, nfilt);
|
||||
/* E-243: an explicit `ref` reference terminal (last port), so every branch is
|
||||
* V(pi,ref)/I(pi,ref) and the instance line -- `N1 p1..pN ref model` -- is
|
||||
* IDENTICAL to the native `nport` device (tie ref to 0 for a ground-referenced
|
||||
* Touchstone block). */
|
||||
fprintf(fo, "module %s(", module);
|
||||
for (i = 0; i < N; i++) fprintf(fo, "%sp%d", i?", ":"", i+1);
|
||||
fprintf(fo, ");\n inout ");
|
||||
fprintf(fo, ", ref);\n inout ");
|
||||
for (i = 0; i < N; i++) fprintf(fo, "%sp%d", i?", ":"", i+1);
|
||||
fprintf(fo, ";\n electrical ");
|
||||
fprintf(fo, ", ref;\n electrical ");
|
||||
for (i = 0; i < N; i++) fprintf(fo, "%sp%d", i?", ":"", i+1);
|
||||
fprintf(fo, ";\n");
|
||||
fprintf(fo, ", ref;\n");
|
||||
/* variable declarations */
|
||||
for (c = 0; c < nchan; c++) {
|
||||
if (chMx[c]==0.0) continue;
|
||||
|
|
@ -881,20 +885,20 @@ int snp2va_convert(const char *snpfile, const char *vafile, const char *module,
|
|||
int first=1; fprintf(fo, " g%d_%d = ", c, m);
|
||||
for (j=0;j<N;j++){ double v=chV[c][j*ch_r[c]+m];
|
||||
if (fabs(v)>1e-30){ term_sep(fo,&first);
|
||||
if (ch_kind[c]==0) fprintf(fo,"(%.12g)*V(p%d)",v,j+1); else fprintf(fo,"(%.12g)*ddt(V(p%d))",v,j+1); } }
|
||||
if (ch_kind[c]==0) fprintf(fo,"(%.12g)*V(p%d,ref)",v,j+1); else fprintf(fo,"(%.12g)*ddt(V(p%d,ref))",v,j+1); } }
|
||||
if (first) fprintf(fo,"0.0"); fprintf(fo,";\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
int sc=ch_sec[c], kk=sc_pole[sc];
|
||||
if (!ch_lr[c]) { /* dense: one laplace_nd per input port */
|
||||
for (j=0;j<N;j++){ fprintf(fo," w%d_%d = laplace_nd(V(p%d), ", c, j, j+1);
|
||||
for (j=0;j<N;j++){ fprintf(fo," w%d_%d = laplace_nd(V(p%d,ref), ", c, j, j+1);
|
||||
emit_filter(fo, P[kk], sc_kind[sc]); fprintf(fo,");\n"); }
|
||||
} else { /* low-rank: r combined inputs, each filtered once */
|
||||
for (m=0;m<ch_r[c];m++){
|
||||
int first=1; fprintf(fo," u%d_%d = ", c, m);
|
||||
for (j=0;j<N;j++){ double v=chV[c][j*ch_r[c]+m];
|
||||
if (fabs(v)>1e-30){ term_sep(fo,&first); fprintf(fo,"(%.12g)*V(p%d)",v,j+1); } }
|
||||
if (fabs(v)>1e-30){ term_sep(fo,&first); fprintf(fo,"(%.12g)*V(p%d,ref)",v,j+1); } }
|
||||
if (first) fprintf(fo,"0.0"); fprintf(fo,";\n");
|
||||
fprintf(fo," h%d_%d = laplace_nd(u%d_%d, ", c, m, c, m);
|
||||
emit_filter(fo, P[kk], sc_kind[sc]); fprintf(fo,");\n");
|
||||
|
|
@ -903,7 +907,7 @@ int snp2va_convert(const char *snpfile, const char *vafile, const char *module,
|
|||
}
|
||||
/* output currents */
|
||||
for (i = 0; i < N; i++) {
|
||||
int first = 1; fprintf(fo, " I(p%d) <+ ", i+1);
|
||||
int first = 1; fprintf(fo, " I(p%d,ref) <+ ", i+1);
|
||||
for (c = 0; c < nchan; c++) {
|
||||
if (chMx[c]==0.0) continue;
|
||||
if (ch_lr[c]) {
|
||||
|
|
@ -914,8 +918,8 @@ int snp2va_convert(const char *snpfile, const char *vafile, const char *module,
|
|||
double thr = tol_drop*chMx[c];
|
||||
for (j=0;j<N;j++){ double w=chW[c][i*N+j];
|
||||
if (fabs(w)>thr){ term_sep(fo,&first);
|
||||
if (ch_kind[c]==0) fprintf(fo,"(%.12g)*V(p%d)",w,j+1);
|
||||
else if (ch_kind[c]==1) fprintf(fo,"(%.12g)*ddt(V(p%d))",w,j+1);
|
||||
if (ch_kind[c]==0) fprintf(fo,"(%.12g)*V(p%d,ref)",w,j+1);
|
||||
else if (ch_kind[c]==1) fprintf(fo,"(%.12g)*ddt(V(p%d,ref))",w,j+1);
|
||||
else fprintf(fo,"(%.12g)*w%d_%d",w,c,j); } }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue