Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nasolver.h
Go to the documentation of this file.
1 /*
2  * nasolver.h - nodal analysis solver class definitions
3  *
4  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Stefan Jahn <stefan@lkcc.org>
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this package; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  * $Id$
22  *
23  */
24 
25 #ifndef __NASOLVER_H__
26 #define __NASOLVER_H__
27 
28 #include "qucs_typedefs.h"
29 #include "tvector.h"
30 #include "tmatrix.h"
31 #include "eqnsys.h"
32 #include "nasolution.h"
33 #include "analysis.h"
34 
35 // Convergence helper definitions.
36 #define CONV_None 0
37 #define CONV_Attenuation 1
38 #define CONV_LineSearch 2
39 #define CONV_SteepestDescent 3
40 #define CONV_GMinStepping 4
41 #define CONV_SourceStepping 5
42 
43 namespace qucs {
44 
45 class analysis;
46 class circuit;
47 class nodelist;
48 class vector;
49 
50 template <class nr_type_t>
51 class nasolver : public analysis
52 {
53 public:
54  nasolver ();
55  nasolver (char *);
56  nasolver (nasolver &);
57  ~nasolver ();
58  int solve_once (void);
59  int solve_nonlinear (void);
62  int solve_linear (void);
63  void solve_pre (void);
64  void solve_post (void);
65  void setDescription (const char * n) { desc = n; }
66  const char * getDescription (void) { return desc; }
67  void saveResults (const char *, const char *, int, qucs::vector * f = NULL);
68  typedef void (* calculate_func_t) (nasolver<nr_type_t> *);
70  void calculate (void)
71  {
72  if (calculate_func) (*calculate_func) (this);
73  }
74  const char * getHelperDescription (void);
75 
76  //interface convenience functions
78  int getN ();
80  int getM ();
81 
82 protected:
83  void restartNR (void);
84  void savePreviousIteration (void);
85  void restorePreviousIteration (void);
86  int countNodes (void);
87  int getNodeNr (char *);
88  int findAssignedNode (circuit *, int);
89  int countVoltageSources (void);
90  void saveSolution (void);
91  circuit * findVoltageSource (int);
92  void applyNodeset (bool nokeep = true);
93  void createNoiseMatrix (void);
94  void runMNA (void);
95  void createMatrix (void);
96  void storeSolution (void);
97  void recallSolution (void);
98  int checkConvergence (void);
99 
100 private:
101  void assignVoltageSources (void);
102  void createGMatrix (void);
103  void createBMatrix (void);
104  void createCMatrix (void);
105  void createDMatrix (void);
106  void createIVector (void);
107  void createEVector (void);
108  void createZVector (void);
109  void applyAttenuation (void);
110  void lineSearch (void);
111  void steepestDescent (void);
112  char * createV (int, const char *, int);
113  char * createI (int, const char *, int);
114  char * createOP (const char *, const char *);
115  void saveNodeVoltages (void);
116  void saveBranchCurrents (void);
117  nr_type_t MatValX (nr_complex_t, nr_complex_t *);
118  nr_type_t MatValX (nr_complex_t, nr_double_t *);
119 
120 protected:
129  int fixpoint;
130  int eqnAlgo;
132  nr_double_t gMin, srcFactor;
133  const char * desc;
135 
136 private:
138  nr_double_t reltol;
139  nr_double_t abstol;
140  nr_double_t vntol;
142 
143 private:
144 
146 };
147 
148 } // namespace qucs
149 
150 #include "nasolver.cpp"
151 
152 #endif /* __NASOLVER_H__ */
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
void createMatrix(void)
Definition: nasolver.cpp:536
int updateMatrix
Definition: nasolver.h:131
void recallSolution(void)
Definition: nasolver.cpp:1282
int getN()
Returns the number of node voltages in the circuit.
Definition: nasolver.cpp:1435
nodelist * nlist
Definition: nasolver.h:134
void applyNodeset(bool nokeep=true)
Definition: nasolver.cpp:247
nr_double_t vntol
Definition: nasolver.h:140
int solve_nonlinear_continuation_gMin(void)
Definition: nasolver.cpp:275
void calculate(void)
Definition: nasolver.h:70
void restorePreviousIteration(void)
Definition: nasolver.cpp:1188
char * createV(int, const char *, int)
Definition: nasolver.cpp:1392
void createGMatrix(void)
Definition: nasolver.cpp:706
void runMNA(void)
Definition: nasolver.cpp:987
int countNodes(void)
Definition: nasolver.cpp:912
eqnsys< nr_type_t > * eqns
Definition: nasolver.h:137
n
Definition: parse_citi.y:147
tmatrix< nr_type_t > * A
Definition: nasolver.h:125
tmatrix< nr_type_t > * C
Definition: nasolver.h:126
void setDescription(const char *n)
Definition: nasolver.h:65
void storeSolution(void)
Definition: nasolver.cpp:1258
nr_type_t MatValX(nr_complex_t, nr_complex_t *)
Definition: nasolver.cpp:580
void createCMatrix(void)
Definition: nasolver.cpp:640
base class for qucs circuit elements.
Definition: circuit.h:92
void createIVector(void)
Definition: nasolver.cpp:855
void solve_pre(void)
Definition: nasolver.cpp:213
tvector< nr_type_t > * zprev
Definition: nasolver.h:124
nasolution< nr_type_t > solution
Definition: nasolver.h:141
void saveResults(const char *, const char *, int, qucs::vector *f=NULL)
Definition: nasolver.cpp:1308
void createEVector(void)
Definition: nasolver.cpp:885
void setCalculation(calculate_func_t f)
Definition: nasolver.h:69
int solve_once(void)
Definition: nasolver.cpp:138
tvector< nr_type_t > * z
Definition: nasolver.h:121
The analysis class header file.
void applyAttenuation(void)
Definition: nasolver.cpp:1017
circuit * findVoltageSource(int)
Definition: nasolver.cpp:953
int solve_linear(void)
Definition: nasolver.cpp:525
int solve_nonlinear(void)
Definition: nasolver.cpp:449
const char * desc
Definition: nasolver.h:133
calculate_func_t calculate_func
Definition: nasolver.h:145
tvector< nr_type_t > * xprev
Definition: nasolver.h:123
int countVoltageSources(void)
Definition: nasolver.cpp:944
void saveNodeVoltages(void)
Definition: nasolver.cpp:1210
const char * getHelperDescription(void)
Definition: nasolver.cpp:422
void createDMatrix(void)
Definition: nasolver.cpp:674
void saveBranchCurrents(void)
Definition: nasolver.cpp:1235
void lineSearch(void)
Definition: nasolver.cpp:1044
const char * getDescription(void)
Definition: nasolver.h:66
void createNoiseMatrix(void)
Definition: nasolver.cpp:741
char * createI(int, const char *, int)
Definition: nasolver.cpp:1405
int checkConvergence(void)
Definition: nasolver.cpp:1132
void assignVoltageSources(void)
Definition: nasolver.cpp:969
nr_double_t srcFactor
Definition: nasolver.h:132
char * createOP(const char *, const char *)
Definition: nasolver.cpp:1382
int getM()
Returns the number of branch currents in the circuit.
Definition: nasolver.cpp:1442
void solve_post(void)
Definition: nasolver.cpp:205
void saveSolution(void)
Definition: nasolver.cpp:1250
nr_double_t reltol
Definition: nasolver.h:138
void savePreviousIteration(void)
Definition: nasolver.cpp:1173
tvector< nr_type_t > * x
Definition: nasolver.h:122
void createZVector(void)
Definition: nasolver.cpp:904
int getNodeNr(char *)
Definition: nasolver.cpp:919
void restartNR(void)
Definition: nasolver.cpp:1197
int findAssignedNode(circuit *, int)
Definition: nasolver.cpp:927
void(* calculate_func_t)(nasolver< nr_type_t > *)
Definition: nasolver.h:68
void createBMatrix(void)
Definition: nasolver.cpp:600
void steepestDescent(void)
Definition: nasolver.cpp:1097
int solve_nonlinear_continuation_Source(void)
Definition: nasolver.cpp:343
nr_double_t gMin
Definition: nasolver.h:132
nr_double_t abstol
Definition: nasolver.h:139