My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
circuit.h
Go to the documentation of this file.
1 /*
2  * circuit.h - circuit class definitions
3  *
4  * Copyright (C) 2003-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: circuit.h 1825 2011-03-11 20:42:14Z ela $
22  *
23  */
24 
25 #ifndef __CIRCUIT_H__
26 #define __CIRCUIT_H__
27 
38 };
39 
40 #define NODE_1 0
41 #define NODE_2 1
42 #define NODE_3 2
43 #define NODE_4 3
44 #define NODE_5 4
45 #define NODE_6 5
46 #define VSRC_1 0
47 #define VSRC_2 1
48 #define VSRC_3 2
49 #define VSRC_4 3
50 #define VSRC_5 4
51 
52 #define MODFLAG(val,bit) if (val) flag |= (bit); else flag &= ~(bit);
53 #define RETFLAG(bit) ((flag & (bit)) != 0)
54 
55 #define CREATOR(val) \
56  val (); \
57  static circuit * create (void) { return new val (); } \
58  static struct define_t cirdef; \
59  static struct define_t * definition (void) { return &cirdef; }
60 
61 class node;
62 class property;
63 class substrate;
64 class operatingpoint;
65 class characteristic;
66 class matrix;
67 class net;
68 class environment;
69 class history;
70 
71 #include "integrator.h"
72 #include "valuelist.h"
73 
74 class circuit : public object, public integrator
75 {
76  public:
77  // constructor and destructor set
78  circuit ();
79  circuit (int);
80  circuit (const circuit &);
81  ~circuit ();
82 
83  // functionality to be overloaded by real circuit implementations
84  virtual void initSP (void) { allocMatrixS (); }
85  virtual void calcSP (nr_double_t) { }
86  virtual void initDC (void) { allocMatrixMNA (); }
87  virtual void calcDC (void) { }
88  virtual void restartDC (void) { }
89  virtual void initNoiseSP (void) { allocMatrixN (); }
90  virtual void calcNoiseSP (nr_double_t) { }
91  virtual void initNoiseAC (void) { allocMatrixN (vsources); }
92  virtual void calcNoiseAC (nr_double_t) { }
93  virtual void initAC (void) { allocMatrixMNA (); }
94  virtual void calcAC (nr_double_t) { }
95  virtual void initTR (void) { allocMatrixMNA (); }
96  virtual void calcTR (nr_double_t) { }
97  virtual void initHB (void) { allocMatrixMNA (); }
98  virtual void calcHB (nr_double_t) { }
99  virtual void initHB (int) { allocMatrixMNA (); }
100  virtual void calcHB (int) { }
101  virtual void calcOperatingPoints (void) { }
102  virtual void saveOperatingPoints (void) { }
103  virtual void calcCharacteristics (nr_double_t) { }
104  virtual void saveCharacteristics (nr_double_t) { }
105 
106  // real basics
107  void setNode (int, const char *, int intern = 0);
108  node * getNode (int);
109  void setType (int t) { type = t; }
110  int getType (void) { return type; }
111  int getSize (void) { return size; }
112  void setSize (int);
113  bool isEnabled (void) { return RETFLAG (CIRCUIT_ENABLED); }
114  void setEnabled (bool e) { MODFLAG (e, CIRCUIT_ENABLED); }
115  bool isVariableSized (void) { return RETFLAG (CIRCUIT_VARSIZE); }
116  void setVariableSized (bool v) { MODFLAG (v, CIRCUIT_VARSIZE); }
117  bool isProbe (void) { return RETFLAG (CIRCUIT_PROBE); }
118  void setProbe (bool p) { MODFLAG (p, CIRCUIT_PROBE); }
119  void setNet (net * n) { subnet = n; }
120  net * getNet (void) { return subnet; }
121 
122  // subcircuitry
123  char * getSubcircuit (void) { return subcircuit; }
124  void setSubcircuit (char *);
125 
126  // environment specific
127  environment * getEnv (void) { return env; }
128  void setEnv (environment * e) { env = e; }
129 
130  // nodal analyses helpers
133  void setVoltageSource (int s) { vsource = s; }
134  int getVoltageSource (void) { return vsource; }
135  int getVoltageSources (void);
136  void setVoltageSources (int);
137  void voltageSource (int, int, int, nr_double_t value = 0.0);
138  bool isVSource (void) { return RETFLAG (CIRCUIT_VSOURCE); }
139  void setVSource (bool v) { MODFLAG (v, CIRCUIT_VSOURCE); }
140  bool isISource (void) { return RETFLAG (CIRCUIT_ISOURCE); }
141  void setISource (bool i) { MODFLAG (i, CIRCUIT_ISOURCE); }
142  int getNoiseSources (void);
143  void setNoiseSources (int);
144 
145  // transient analyses helpers
146  void transientCapacitance (int, int, int, nr_double_t, nr_double_t,
147  nr_double_t);
148  void transientCapacitance (int, int, nr_double_t, nr_double_t, nr_double_t);
149  void transientCapacitanceQ (int, int, int, nr_double_t);
150  void transientCapacitanceQ (int, int, nr_double_t);
151  void transientCapacitanceC (int, int, int, int, nr_double_t, nr_double_t);
152  void transientCapacitanceC (int, int, nr_double_t, nr_double_t);
153  void transientCapacitanceC2V (int, int, int, nr_double_t, nr_double_t);
154  void transientCapacitanceC2Q (int, int, int, nr_double_t, nr_double_t);
155  void setDelta (nr_double_t * d) { deltas = d; }
156  nr_double_t * getDelta (void) { return deltas; }
157 
158  // history specific functionality
159  bool hasHistory (void) { return RETFLAG (CIRCUIT_HISTORY); }
160  void setHistory (bool h) { MODFLAG (h, CIRCUIT_HISTORY); }
161  void initHistory (nr_double_t);
162  void deleteHistory (void);
163  void appendHistory (int, nr_double_t);
164  void applyHistory (history *);
165  nr_double_t getV (int, nr_double_t);
166  nr_double_t getJ (int, nr_double_t);
167  nr_double_t getHistoryAge (void);
168 
169  // s-parameter helpers
170  int getPort (void) { return pacport; }
171  void setPort (int p) { pacport = p; }
172  int getInserted (void) { return inserted; }
173  void setInserted (int i) { inserted = i; }
174  bool isOriginal (void) { return RETFLAG (CIRCUIT_ORIGINAL); }
175  void setOriginal (bool o) { MODFLAG (o, CIRCUIT_ORIGINAL); }
176 
177  // microstrip helpers
178  substrate * getSubstrate (void);
179  void setSubstrate (substrate *);
180 
181  // matrix entry modificators
182  nr_complex_t getS (int, int);
183  nr_complex_t getN (int, int);
184  nr_complex_t getY (int, int);
185  nr_complex_t getB (int, int);
186  nr_complex_t getC (int, int);
187  nr_complex_t getD (int, int);
188  nr_complex_t getQV (int, int);
189  nr_complex_t getGV (int);
190  nr_complex_t getCV (int);
191  nr_complex_t getE (int);
192  nr_complex_t getI (int);
193  nr_complex_t getJ (int);
194  nr_complex_t getV (int);
195  nr_complex_t getQ (int);
196  nr_double_t getG (int, int);
197  void setS (int, int, nr_complex_t);
198  void setN (int, int, nr_complex_t);
199  void setY (int, int, nr_complex_t);
200  void setB (int, int, nr_complex_t);
201  void setC (int, int, nr_complex_t);
202  void setD (int, int, nr_complex_t);
203  void setQV (int, int, nr_complex_t);
204  void setGV (int, nr_complex_t);
205  void setCV (int, nr_complex_t);
206  void setE (int, nr_complex_t);
207  void setI (int, nr_complex_t);
208  void setJ (int, nr_complex_t);
209  void setV (int, nr_complex_t);
210  void setQ (int, nr_complex_t);
211  void setG (int, int, nr_double_t);
212  void clearB (void);
213  void clearC (void);
214  void clearD (void);
215  void clearE (void);
216  void clearI (void);
217  void clearJ (void);
218  void clearV (void);
219  void clearY (void);
220  void addY (int, int, nr_complex_t);
221  void addY (int, int, nr_double_t);
222  void addI (int, nr_complex_t);
223  void addI (int, nr_double_t);
224 
225  // operating point functionality
226  void addOperatingPoint (const char *, nr_double_t);
227  nr_double_t getOperatingPoint (const char *);
228  void setOperatingPoint (const char *, nr_double_t);
229  int hasOperatingPoint (char *);
231 
232  // characteristics functionality
233  void addCharacteristic (const char *, nr_double_t);
234  nr_double_t getCharacteristic (char *);
235  void setCharacteristic (const char *, nr_double_t);
236  int hasCharacteristic (char *);
237  valuelist<characteristic> & getCharacteristics (void) { return charac; }
238 
239  // differentiate between linear and non-linear circuits
240  void setNonLinear (bool l) { MODFLAG (!l, CIRCUIT_LINEAR); }
241  bool isNonLinear (void) { return !RETFLAG (CIRCUIT_LINEAR); }
242 
243  // miscellaneous functionality
244  void print (void);
245  static char * createInternal (const char *, const char *);
246  void setInternalNode (int, const char *);
247 
248  // matrix operations
249  void allocMatrixS (void);
250  void allocMatrixN (int sources = 0);
251  void allocMatrixMNA (void);
252  void freeMatrixMNA (void);
253  void allocMatrixHB (void);
254  void freeMatrixHB (void);
255  void setMatrixS (matrix);
256  matrix getMatrixS (void);
257  void setMatrixN (matrix);
258  matrix getMatrixN (void);
259  void setMatrixY (matrix);
260  matrix getMatrixY (void);
261 
262  static const nr_double_t z0;
263 
264  protected:
265  int type;
266  int pol;
267 
268  private:
269  int size;
270  int pacport;
271  int vsource;
272  int vsources;
273  int nsources;
274  int inserted;
275  int flag;
276  nr_complex_t * MatrixS;
277  nr_complex_t * MatrixN;
278  nr_complex_t * MatrixY;
279  nr_complex_t * MatrixB;
280  nr_complex_t * MatrixC;
281  nr_complex_t * MatrixD;
282  nr_complex_t * VectorE;
283  nr_complex_t * VectorI;
284  nr_complex_t * VectorV;
285  nr_complex_t * VectorJ;
286  nr_complex_t * VectorQ;
287  nr_complex_t * MatrixQV;
288  nr_complex_t * VectorGV;
289  nr_complex_t * VectorCV;
290  char * subcircuit;
291  node * nodes;
292  substrate * subst;
295  net * subnet;
296  environment * env;
297  nr_double_t * deltas;
298  int nHistories;
299  history * histories;
300 };
301 
302 #endif /* __CIRCUIT_H__ */