54 using namespace fourier;
60 nlnodes = lnnodes = banodes = nanodes = NULL;
62 NA = YV = JQ = JG = JF = NULL;
63 OM = IR = QR = RH = IG = FQ = VS = VP = FV = IL = IN = IC = IS = NULL;
140 #define VS_(r) (*VS) (r)
141 #define OM_(r) (*OM) (r)
147 int iterations = 0, done = 0;
176 fprintf (stderr,
"YV -- transY in f:\n");
YV->
print ();
177 fprintf (stderr,
"IC -- constant current in f:\n");
IC->
print ();
185 fprintf (stderr,
"\n -- iteration step: %d\n", iterations);
186 fprintf (stderr,
"vs -- voltage in t:\n");
vs->
print ();
193 fprintf (stderr,
"FQ -- charge in t:\n");
FQ->
print ();
194 fprintf (stderr,
"IG -- current in t:\n");
IG->
print ();
208 fprintf (stderr,
"VS -- voltage in f:\n");
VS->
print ();
209 fprintf (stderr,
"FQ -- charge in f:\n");
FQ->
print ();
210 fprintf (stderr,
"IG -- current in f:\n");
IG->
print ();
211 fprintf (stderr,
"IR -- corrected Jacobi current in f:\n");
IR->
print ();
218 fprintf (stderr,
"FV -- error vector F(V) in f:\n");
FV->
print ();
219 fprintf (stderr,
"IL -- linear currents in f:\n");
IL->
print ();
220 fprintf (stderr,
"IN -- non-linear currents in f:\n");
IN->
print ();
221 fprintf (stderr,
"RH -- right-hand side currents in f:\n");
RH->
print ();
231 fprintf (stderr,
"JG -- G-Jacobian in t:\n");
JG->
print ();
232 fprintf (stderr,
"JQ -- C-Jacobian in t:\n");
JQ->
print ();
242 fprintf (stderr,
"JQ -- dQ/dV C-Jacobian in f:\n");
JQ->
print ();
243 fprintf (stderr,
"JG -- dI/dV G-Jacobian in f:\n");
JG->
print ();
250 fprintf (stderr,
"JF -- full Jacobian in f:\n");
JF->
print ();
257 fprintf (stderr,
"VS -- next voltage in f:\n");
VS->
print ();
264 while (!done && iterations < MaxIterations);
266 if (iterations >= MaxIterations) {
268 e->
setText (
"no convergence in %s analysis after %d iterations",
301 c->calcHB (self->frequency);
340 for (i = 0; i <= n + 1; i++) {
341 for (k = 0; k < len; k++) {
345 for (i = -n; i < 0; i++) {
346 for (k = 0; k < len; k++) {
350 for (i = 0; i <= 2 * n + 1; i++) {
351 for (k = 0; k < len; k++) {
360 for (i = 0; i <= 2 * n + 1; i++)
posfreqs.
add (i * f);
366 int o, order = n * 2;
367 for (o = 1; o < order; o <<= 1) ;
419 fprintf (stderr,
"]\n");
424 if ((f =
negfreqs (n)) < 0.0)
continue;
432 for (n = i = 0; n <
nlfreqs; n++, i++)
440 if (
c->isNonLinear ()) {
462 if (strcmp (n,
"gnd")) {
496 nanodes->append (*it);
499 if (!nanodes->contains (*it))
500 nanodes->append (*it);
507 fprintf (stderr,
" nanodes nodes: [ %s ]\n", nanodes->toString ());
529 for (
int nr = 0; nr < nodes->
length (); nr++) {
530 char * nn = nodes->
get (nr);
577 (*it)->calcHB (freq);
589 #define A_(r,c) (*A) ((r)*lnfreqs+f,(c)*lnfreqs+f)
590 #define G_(r,c) A_(r,c)
591 #define B_(r,c) A_(r,c+N)
592 #define C_(r,c) A_(r+N,c)
593 #define D_(r,c) A_(r+N,c+N)
607 for (r = 0; r <
s; r++) {
609 for (c = 0; c <
s; c++) {
611 G_(nr, nc) += cir->
getY (r, c);
619 for (r = 0; r <
s; r++) {
621 for (c = 0; c <
v; c++) {
623 B_(nr, nc) += cir->
getB (r, nc);
628 for (r = 0; r <
v; r++) {
630 for (c = 0; c <
s; c++) {
632 C_(nr, nc) += cir->
getC (nr, c);
637 for (r = 0; r <
v; r++) {
639 for (c = 0; c <
v; c++) {
641 D_(nr, nc) += cir->
getD (nr, nc);
672 for (
int c = 0;
c <
N;
c++) {
684 #define V_(r) (*V) (r)
685 #define I_(r) (*I) (r)
687 #define A_(r,c) (*A) (r,c)
689 #define Z_(r,c) (*Z) (r,c)
690 #define Y_(r,c) (*Y) (r,c)
692 #define ZVU_(r,c) Z_(r,c)
693 #define ZVL_(r,c) Z_((r)*lnfreqs+f+sn,c)
694 #define ZCU_(r,c) Z_(r,(c)*lnfreqs+f+sn)
695 #define ZCL_(r,c) Z_((r)*lnfreqs+f+sn,(c)*lnfreqs+f+sn)
697 #define YV_(r,c) (*YV) (r,c)
698 #define NA_(r,c) (*NA) (r,c)
699 #define JF_(r,c) (*JF) (r,c)
739 for (c = 0; c < sv *
lnfreqs; c++)
A_(c, c) += 0.01;
747 for (f = 0; f <
lnfreqs; f++) {
748 int pn = (pnode - 1) * lnfreqs + f;
749 int nn = (nnode - 1) * lnfreqs + f;
750 if (pnode)
A_(pn, pn) += 0.01;
751 if (nnode)
A_(nn, nn) += 0.01;
752 if (pnode && nnode) {
762 eqns.passEquationSys (
A, V, I);
775 for (c = 0; c < sn; c++) {
778 eqns.passEquationSys (
A, V, I);
783 for (r = 0; r < sn; r++)
ZVU_(r, c) =
V_(r);
790 for (f = 0; f <
lnfreqs; f++) {
805 for (f = 0; f <
lnfreqs; f++) {
806 int pn = (pnode - 1) * lnfreqs + f;
807 int nn = (nnode - 1) * lnfreqs + f;
809 if (pnode)
I_(pn) = +1.0;
810 if (nnode)
I_(nn) = -1.0;
811 eqns.passEquationSys (
A, V, I);
816 for (r = 0; r < sn; r++) {
840 for (c = 0; c < sy *
lnfreqs; c++)
Y_(c, c) -= 0.01;
863 if (pnode) z +=
V_((pnode - 1) *
lnfreqs + f);
864 if (nnode) z -=
V_((nnode - 1) *
lnfreqs + f);
883 nr_double_t freq =
rfreqs (f);
894 for (r = 0; r < sn; r++) {
896 for (c = 0; c < se; c++) {
897 i +=
Y_(r, c + sn) * VC (c);
900 if (f != 0 && f != lnfreqs - 1) i /= 2;
911 for (r = 0; r < se; r++) {
913 for (c = 0; c < se; c++) {
914 i +=
Y_(r + sn, c + sn) * VC (c);
930 for (n = 0; n < len; n++) {
933 nr_double_t v_rel =
abs (
VS->
get (n));
934 if (v_abs >= vabstol + reltol * v_rel)
return 0;
939 nr_double_t i_abs =
abs (il + in);
940 nr_double_t i_rel =
abs ((il + in) / (il - in));
941 if (i_abs >= iabstol && 2.0 * i_rel >= reltol)
return 0;
950 #define G_(r,c) (*jg) ((r)*nlfreqs+f,(c)*nlfreqs+f)
951 #define C_(r,c) (*jq) ((r)*nlfreqs+f,(c)*nlfreqs+f)
954 #define FI_(r) (*ig) ((r)*nlfreqs+f)
955 #define FQ_(r) (*fq) ((r)*nlfreqs+f)
956 #define IR_(r) (*ir) ((r)*nlfreqs+f)
957 #define QR_(r) (*qr) ((r)*nlfreqs+f)
974 for (r = 0; r <
s; r++) {
977 for (c = 0; c <
s; c++) {
979 G_(nr, nc) += cir->
getY (r, c);
980 C_(nr, nc) += cir->
getQV (r, c);
1060 for (r = 0; r <
s; r++) {
1079 for (
int f = 0; f <
nlfreqs; f++) {
1097 nr_double_t *
d = (nr_double_t *) V->
getData ();
1101 for (k = i = 0; i <
nodes; i++, k += 2 *
n) {
1102 nr_double_t * dst = &d[k];
1104 if (isign > 0)
for (r = 0; r < 2 *
n; r++) *dst++ /= n;
1109 for (k = i = 0; i <
nodes; i++, k += 2 *
n) {
1110 nr_double_t * dst = &d[k];
1112 if (isign > 0)
for (r = 0; r < 2 *
n; r++) *dst++ /=
ndfreqs[0];
1150 for (fc = 0; fc <
nlfreqs; fc++) V (fc) = M->
get (nr + fc, nc + fc);
1153 for (fc = 0; fc <
nlfreqs; fc++) {
1154 for (fi = nlfreqs - 1 - fc, fr = 0; fr <
nlfreqs; fr++) {
1155 if (++fi >= nlfreqs) fi = 0;
1156 M->
set (nr + fr, nc + fc, V (fi));
1177 for (
int f = 0; f <
nlfreqs; f++,
r++) {
1205 int c,
r, fc, fr, rt, ct;
1210 for (fc = 0; fc <
nlfreqs; fc++, ct++) {
1213 for (fr = 0; fr <
nlfreqs; fr++, rt++) {
1228 for (r = 0; r <
nodes; r++) {
1232 for (ff = 0; ff <
lnfreqs; ff++, rf++, rt++) {
1236 for (rf -= 2; ff <
nlfreqs; ff++, rf--, rt++) {
1237 res (rt) =
conj (V (rf));
1248 int r,
c, rf, rt, cf, ct, ff;
1249 for (r = 0; r <
nodes; r++) {
1250 for (c = 0; c <
nodes; c++) {
1256 for (ff = 0; ff <
lnfreqs; ff++, cf++, ct++, rf++, rt++) {
1257 res (rt, ct) =
M (rf, cf);
1260 for (cf -= 2, rf -= 2; ff <
nlfreqs; ff++, cf--, ct++, rf--, rt++) {
1261 res (rt, ct) =
conj (M (rf, cf));
1303 for (
int r = 0;
r < no;
r++) {
1304 for (
int c = 0;
c < no;
c++) {
1305 res (
r,
c) =
M (
r,
c);
1325 for (
int f = 0; f <
lnfreqs; f++, sc++) {
1327 nr_double_t freq =
rfreqs (f);
1331 int pn = (pnode - 1) * lnfreqs + f;
1332 int nn = (nnode - 1) * lnfreqs + f;
1366 for (
int f = 0; f <
lnfreqs; f++) {
1368 if (f != 0 && f != lnfreqs - 1) i *= 2;
1369 I_(
n * lnfreqs + f) =
i;
1395 if ((f =
data->findDependency (
"hbfrequency")) == NULL) {
1396 f =
new vector (
"hbfrequency");
1397 data->addDependency (f);
1406 int l = strlen (*it);
1407 char *
n = (
char *) malloc (l + 4);
1408 sprintf (n,
"%s.Vb", *it);
std::complex< nr_double_t > nr_complex_t
void _fft_1d(nr_double_t *, int, int isign=1)
tmatrix< nr_complex_t > * YV
bool isExcitation(circuit *)
matrix real(matrix a)
Real part matrix.
matrix abs(matrix a)
Computes magnitude of each matrix element.
tmatrix< nr_complex_t > * Y
void saveVariable(const char *, nr_complex_t, qucs::vector *)
Save variable into analysis dataset.
int assignVoltageSources(ptrlist< circuit >)
void setRow(int, tvector< nr_type_t >)
nr_double_t getPropertyDouble(const char *)
void set(int, int, nr_type_t)
void VectorFFT(tvector< nr_complex_t > *, int isign=1)
tvector< nr_complex_t > * FQ
void MatrixFFT(tmatrix< nr_complex_t > *)
tvector< nr_complex_t > * RH
void collectFrequencies(void)
tmatrix< nr_complex_t > * NA
tvector< nr_complex_t > * IR
tvector< nr_complex_t > * IL
int getPropertyInteger(const char *)
void calcConstantCurrent(void)
tvector< nr_complex_t > * vs
int getVoltageSource(void)
void passEquationSys(tmatrix< nr_type_t > *, tvector< nr_type_t > *, tvector< nr_type_t > *)
tvector< nr_complex_t > * FV
#define catch_exception()
void setVoltageSource(int s)
tvector< nr_complex_t > * IC
int getSize(void)
Get the number of ports the circuit element has.
#define throw_exception(e)
void VectorIFFT(tvector< nr_complex_t > *, int isign=1)
tvector< nr_type_t > getRow(int)
void invertMatrix(tmatrix< nr_complex_t > *, tmatrix< nr_complex_t > *)
int getVoltageSources(void)
void expandFrequencies(nr_double_t, int)
tmatrix< nr_complex_t > * JF
ptrlist< circuit > nolcircuits
nr_complex_t getC(int, int)
virtual void calcHB(nr_double_t)
int assignNodes(ptrlist< circuit >, strlist *, int offset=0)
tmatrix< nr_complex_t > * JG
strlist * circuitNodes(ptrlist< circuit >)
base class for qucs circuit elements.
static void calc(hbsolver *)
tvector< nr_double_t > posfreqs
void setCol(int, tvector< nr_type_t >)
tvector< nr_double_t > dfreqs
void fillMatrixLinearExtended(tmatrix< nr_complex_t > *, tvector< nr_complex_t > *)
int solve(void)
placehoder for solution function
The analysis class header file.
void createMatrixLinearY(void)
void prepareNonLinear(void)
void print(const char *prefix=NULL)
#define M_PI
Archimedes' constant ( )
tvector< nr_double_t > rfreqs
void saveNodeVoltages(circuit *, int)
tmatrix< nr_complex_t > * Z
The circuit class header file.
nr_complex_t getD(int, int)
tvector< nr_complex_t > * VS
tvector< nr_complex_t > * x
void _fft_nd(nr_double_t *, int[], int, int isign=1)
tvector< nr_complex_t > * VP
void print(bool realonly=false)
tmatrix< nr_complex_t > expandMatrix(tmatrix< nr_complex_t >, int)
char * toString(const char *concat=" ")
tvector< nr_complex_t > * QR
nr_complex_t getB(int, int)
tvector< nr_complex_t > * IS
void fillMatrixLinearA(tmatrix< nr_complex_t > *, int)
tvector< nr_type_t > getCol(int)
virtual void initHB(void)
nr_complex_t getQV(int, int)
void fillMatrixNonLinear(tmatrix< nr_complex_t > *, tmatrix< nr_complex_t > *, tvector< nr_complex_t > *, tvector< nr_complex_t > *, tvector< nr_complex_t > *, tvector< nr_complex_t > *, int)
tvector< nr_complex_t > expandVector(tvector< nr_complex_t >, int)
void setText(const char *,...)
tvector< nr_complex_t > * IG
tvector< nr_complex_t > * IN
nr_complex_t excitationZ(tvector< nr_complex_t > *, circuit *, int)
matrix conj(matrix a)
Conjugate complex matrix.
ptrlist< circuit > excitations
tmatrix< nr_complex_t > * JQ
tvector< nr_double_t > negfreqs
nr_complex_t getY(int, int)
void createMatrixLinearA(void)
void logprint(int level, const char *format,...)
tmatrix< nr_complex_t > extendMatrixLinear(tmatrix< nr_complex_t >, int)
ptrlist< circuit > lincircuits
tmatrix< nr_complex_t > * A
int contains(nr_type_t, nr_double_t eps=NR_EPSI)
nr_type_t * getData(void)
tvector< nr_complex_t > * OM
void setV(int, nr_complex_t)