Qucs-core  0.0.19
hbsolver.h
Go to the documentation of this file.
00001 /*
00002  * hbsolver.h - harmonic balance solver class definitions
00003  *
00004  * Copyright (C) 2005, 2006, 2007, 2008 Stefan Jahn <stefan@lkcc.org>
00005  *
00006  * This is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  *
00011  * This software is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this package; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  * $Id$
00022  *
00023  */
00024 
00025 #ifndef __HBSOLVER_H__
00026 #define __HBSOLVER_H__
00027 
00028 #include <vector>
00029 
00030 #include "ptrlist.h"
00031 #include "tvector.h"
00032 
00033 namespace qucs {
00034 
00035 class vector;
00036 class strlist;
00037 class circuit;
00038 
00039 class hbsolver : public analysis
00040 {
00041  public:
00042   ACREATOR (hbsolver);
00043   hbsolver (char *);
00044   hbsolver (hbsolver &);
00045   ~hbsolver ();
00046   int  solve (void);
00047   void initHB (void);
00048   void initDC (void);
00049   static void calc (hbsolver *);
00050   void collectFrequencies (void);
00051   int  checkBalance (void);
00052 
00053   void splitCircuits (void);
00054   void expandFrequencies (nr_double_t, int);
00055   bool isExcitation (circuit *);
00056   strlist * circuitNodes (ptrlist<circuit>);
00057   void getNodeLists (void);
00058   int  assignVoltageSources (ptrlist<circuit>);
00059   int  assignNodes (ptrlist<circuit>, strlist *, int offset = 0);
00060   void prepareLinear (void);
00061   void createMatrixLinearA (void);
00062   void fillMatrixLinearA (tmatrix<nr_complex_t> *, int);
00063   void invertMatrix (tmatrix<nr_complex_t> *, tmatrix<nr_complex_t> *);
00064   void createMatrixLinearY (void);
00065   void saveResults (void);
00066   void calcConstantCurrent (void);
00067   nr_complex_t excitationZ (tvector<nr_complex_t> *, circuit *, int);
00068   void finalSolution (void);
00069   void fillMatrixNonLinear (tmatrix<nr_complex_t> *, tmatrix<nr_complex_t> *,
00070                             tvector<nr_complex_t> *, tvector<nr_complex_t> *,
00071                             tvector<nr_complex_t> *, tvector<nr_complex_t> *,
00072                             int);
00073   void prepareNonLinear (void);
00074   void solveHB (void);
00075   void loadMatrices (void);
00076   void VectorFFT (tvector<nr_complex_t> *, int isign = 1);
00077   void VectorIFFT (tvector<nr_complex_t> *, int isign = 1);
00078   int  calcOrder (int);
00079   void MatrixFFT (tmatrix<nr_complex_t> *);
00080   void calcJacobian (void);
00081   void solveVoltages (void);
00082   tvector<nr_complex_t> expandVector (tvector<nr_complex_t>, int);
00083   tmatrix<nr_complex_t> expandMatrix (tmatrix<nr_complex_t>, int);
00084   tmatrix<nr_complex_t> extendMatrixLinear (tmatrix<nr_complex_t>, int);
00085   void fillMatrixLinearExtended (tmatrix<nr_complex_t> *,
00086                                  tvector<nr_complex_t> *);
00087   void saveNodeVoltages (circuit *, int);
00088 
00089  private:
00090   std::vector<nr_double_t> negfreqs;    // full frequency set
00091   std::vector<nr_double_t> posfreqs;    // full frequency set but positive
00092   std::vector<nr_double_t> rfreqs;      // real positive frequency set
00093   int * ndfreqs;                    // number of frequencies for each dimension
00094   std::vector<nr_double_t> dfreqs;      // base frequencies for each dimension
00095   nr_double_t frequency;
00096   strlist * nlnodes, * lnnodes, * banodes, * nanodes, * exnodes;
00097   ptrlist<circuit> excitations;
00098   ptrlist<circuit> nolcircuits;
00099   ptrlist<circuit> lincircuits;
00100 
00101   tmatrix<nr_complex_t> * Y;  // transadmittance matrix of linear network
00102   tmatrix<nr_complex_t> * A;  // MNA-matrix of linear network
00103   tmatrix<nr_complex_t> * Z;  // transimpedance matrix of linear network
00104 
00105   tmatrix<nr_complex_t> * YV; // linear transadmittance matrix
00106   tmatrix<nr_complex_t> * NA; // MNA-matrix of complete network
00107 
00108   tmatrix<nr_complex_t> * JQ; // C-Jacobian in t and f
00109   tmatrix<nr_complex_t> * JG; // G-Jacobian in t and f
00110   tmatrix<nr_complex_t> * JF; // full Jacobian for non-linear balancing
00111   tvector<nr_complex_t> * IG; // currents in t and f
00112   tvector<nr_complex_t> * FQ; // charges in t and f
00113   tvector<nr_complex_t> * VS;
00114   tvector<nr_complex_t> * VP;
00115   tvector<nr_complex_t> * FV; // error vector F(V) of HB equation
00116   tvector<nr_complex_t> * IL; // currents into linear network
00117   tvector<nr_complex_t> * IN; // currents into non-linear network
00118 
00119   tvector<nr_complex_t> * IR;
00120   tvector<nr_complex_t> * QR;
00121   tvector<nr_complex_t> * RH;
00122   tvector<nr_complex_t> * OM;
00123 
00124   tvector<nr_complex_t> * IC; // source currents into balanced nodes
00125   tvector<nr_complex_t> * IS; // currents through sources themselves
00126   tvector<nr_complex_t> * x;
00127   tvector<nr_complex_t> * vs;
00128 
00129   int runs;
00130   int lnfreqs;
00131   int nlfreqs;
00132   int nnlvsrcs;
00133   int nlnvsrcs;
00134   //int nlnnodes;
00135   int nnanodes;
00136   int nexnodes;
00137   int nbanodes;
00138 };
00139 
00140 } // namespace qucs
00141 
00142 #endif /* __HBSOLVER_H__ */