Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
22  *
23  */
24 
31 #ifndef __CIRCUIT_H__
32 #define __CIRCUIT_H__
33 
34 #define NODE_1 0
35 #define NODE_2 1
36 #define NODE_3 2
37 #define NODE_4 3
38 #define NODE_5 4
39 #define NODE_6 5
40 #define VSRC_1 0
41 #define VSRC_2 1
42 #define VSRC_3 2
43 #define VSRC_4 3
44 #define VSRC_5 4
45 
46 #define MODFLAG(val,bit) if (val) flag |= (bit); else flag &= ~(bit);
47 #define RETFLAG(bit) ((flag & (bit)) != 0)
48 
49 #define CREATOR(val) \
50  val (); \
51  static qucs::circuit * create (void) { return new val (); } \
52  static struct define_t cirdef; \
53  static struct define_t * definition (void) { return &cirdef; }
54 
55 #include <map>
56 #include "integrator.h"
57 #include "valuelist.h"
58 
59 namespace qucs {
60 
71 };
72 
73 class node;
74 class property;
75 class substrate;
76 class operatingpoint;
77 class characteristic;
78 class matrix;
79 class net;
80 class environment;
81 class history;
82 
92 class circuit : public object, public integrator
93 {
94  public:
95  // constructor and destructor set
96  circuit ();
97  circuit (int);
98  circuit (const circuit &);
99  ~circuit ();
100 
101  // functionality to be overloaded by real, derived circuit element
102  // implementations
111  virtual void initSP (void) { allocMatrixS (); }
112  virtual void calcSP (nr_double_t) { }
113  virtual void initDC (void) { allocMatrixMNA (); }
114  virtual void calcDC (void) { }
115  virtual void restartDC (void) { }
116  virtual void initNoiseSP (void) { allocMatrixN (); }
117  virtual void calcNoiseSP (nr_double_t) { }
118  virtual void initNoiseAC (void) { allocMatrixN (vsources); }
119  virtual void calcNoiseAC (nr_double_t) { }
120  virtual void initAC (void) { allocMatrixMNA (); }
121  virtual void calcAC (nr_double_t) { }
122  virtual void initTR (void) { allocMatrixMNA (); }
123  virtual void calcTR (nr_double_t) { }
124  virtual void initHB (void) { allocMatrixMNA (); }
125  virtual void calcHB (nr_double_t) { }
126  virtual void initHB (int) { allocMatrixMNA (); }
127  virtual void calcHB (int) { }
128  virtual void calcOperatingPoints (void) { }
129  virtual void saveOperatingPoints (void) { }
130  virtual void calcCharacteristics (nr_double_t) { }
131  virtual void saveCharacteristics (nr_double_t) { }
132 
133  // basic circuit element functionality
134  void setNode (int, const char *, int intern = 0);
135  node * getNode (int);
136  void setType (int t) { type = t; }
137  int getType (void) { return type; }
143  int getSize (void) { return size; }
153  void setSize (int);
160  bool isEnabled (void) { return RETFLAG (CIRCUIT_ENABLED); }
167  void setEnabled (bool e) { MODFLAG (e, CIRCUIT_ENABLED); }
168  bool isVariableSized (void) { return RETFLAG (CIRCUIT_VARSIZE); }
170  bool isProbe (void) { return RETFLAG (CIRCUIT_PROBE); }
171  void setProbe (bool p) { MODFLAG (p, CIRCUIT_PROBE); }
172  void setNet (net * n) { subnet = n; }
173  net * getNet (void) { return subnet; }
174 
175  // subcircuitry
176  char * getSubcircuit (void) { return subcircuit; }
177  void setSubcircuit (char *);
178 
179  // environment specific
180  environment * getEnv (void) { return env; }
181  void setEnv (environment * e) { env = e; }
182 
183  // nodal analyses helpers
186  void setVoltageSource (int s) { vsource = s; }
187  int getVoltageSource (void) { return vsource; }
188  int getVoltageSources (void);
189  void setVoltageSources (int);
190  void voltageSource (int, int, int, nr_double_t value = 0.0);
191  bool isVSource (void) { return RETFLAG (CIRCUIT_VSOURCE); }
192  void setVSource (bool v) { MODFLAG (v, CIRCUIT_VSOURCE); }
193  bool isISource (void) { return RETFLAG (CIRCUIT_ISOURCE); }
194  void setISource (bool i) { MODFLAG (i, CIRCUIT_ISOURCE); }
195  int getNoiseSources (void);
196  void setNoiseSources (int);
197 
198  // transient analyses helpers
199  void transientCapacitance (int, int, int, nr_double_t, nr_double_t,
200  nr_double_t);
201  void transientCapacitance (int, int, nr_double_t, nr_double_t, nr_double_t);
202  void transientCapacitanceQ (int, int, int, nr_double_t);
203  void transientCapacitanceQ (int, int, nr_double_t);
204  void transientCapacitanceC (int, int, int, int, nr_double_t, nr_double_t);
205  void transientCapacitanceC (int, int, nr_double_t, nr_double_t);
206  void transientCapacitanceC2V (int, int, int, nr_double_t, nr_double_t);
207  void transientCapacitanceC2Q (int, int, int, nr_double_t, nr_double_t);
208  void setDelta (nr_double_t * d) { deltas = d; }
209  nr_double_t * getDelta (void) { return deltas; }
210 
211  // history specific functionality
212  bool hasHistory (void) { return RETFLAG (CIRCUIT_HISTORY); }
213  void setHistory (bool h) { MODFLAG (h, CIRCUIT_HISTORY); }
214  void initHistory (nr_double_t);
215  void deleteHistory (void);
216  void truncateHistory (nr_double_t);
217  void appendHistory (int, nr_double_t);
218  void applyHistory (history *);
219  nr_double_t getV (int, nr_double_t);
220  nr_double_t getV (int, int);
221  nr_double_t getJ (int, nr_double_t);
222  nr_double_t getHistoryAge (void);
223  void setHistoryAge (nr_double_t);
224  int getHistorySize (void);
225  nr_double_t getHistoryTFromIndex (int);
226 
227  // s-parameter helpers
228  int getPort (void) { return pacport; }
229  void setPort (int p) { pacport = p; }
230  int getInserted (void) { return inserted; }
231  void setInserted (int i) { inserted = i; }
232  bool isOriginal (void) { return RETFLAG (CIRCUIT_ORIGINAL); }
233  void setOriginal (bool o) { MODFLAG (o, CIRCUIT_ORIGINAL); }
234 
235  // microstrip helpers
236  substrate * getSubstrate (void);
237  void setSubstrate (substrate *);
238 
239  // matrix entry modificators
240  nr_complex_t getS (int, int);
241  nr_complex_t getN (int, int);
242  nr_complex_t getY (int, int);
243  nr_complex_t getB (int, int);
244  nr_complex_t getC (int, int);
245  nr_complex_t getD (int, int);
246  nr_complex_t getQV (int, int);
247  nr_complex_t getGV (int);
248  nr_complex_t getCV (int);
249  nr_complex_t getE (int);
250  nr_complex_t getI (int);
251  nr_complex_t getJ (int);
252  nr_complex_t getV (int);
253  nr_complex_t getQ (int);
254  nr_double_t getG (int, int);
255  void setS (int, int, nr_complex_t);
256  void setN (int, int, nr_complex_t);
257  void setY (int, int, nr_complex_t);
258  void setB (int, int, nr_complex_t);
259  void setC (int, int, nr_complex_t);
260  void setD (int, int, nr_complex_t);
261  void setQV (int, int, nr_complex_t);
262  void setGV (int, nr_complex_t);
263  void setCV (int, nr_complex_t);
264  void setE (int, nr_complex_t);
265  void setI (int, nr_complex_t);
266  void setJ (int, nr_complex_t);
267  void setV (int, nr_complex_t);
268  void setQ (int, nr_complex_t);
269  void setG (int, int, nr_double_t);
270  void clearB (void);
271  void clearC (void);
272  void clearD (void);
273  void clearE (void);
274  void clearI (void);
275  void clearJ (void);
276  void clearV (void);
277  void clearY (void);
278  void addY (int, int, nr_complex_t);
279  void addY (int, int, nr_double_t);
280  void addI (int, nr_complex_t);
281  void addI (int, nr_double_t);
282 
283  // operating point functionality
284  void addOperatingPoint (const char *, nr_double_t);
285  nr_double_t getOperatingPoint (const char *);
286  void setOperatingPoint (const char *, nr_double_t);
287  int hasOperatingPoint (char *);
289 
290  // characteristics functionality
291  void addCharacteristic (const char *, nr_double_t);
292  nr_double_t getCharacteristic (char *);
293  void setCharacteristic (const char *, nr_double_t);
294  int hasCharacteristic (char *);
296 
297  // differentiate between linear and non-linear circuits
298  void setNonLinear (bool l) { MODFLAG (!l, CIRCUIT_LINEAR); }
299  bool isNonLinear (void) { return !RETFLAG (CIRCUIT_LINEAR); }
300 
301  // miscellaneous functionality
302  void print (void);
303  static char * createInternal (const char *, const char *);
304  void setInternalNode (int, const char *);
305 
306  // matrix operations
307  void allocMatrixS (void);
308  void allocMatrixN (int sources = 0);
309  void allocMatrixMNA (void);
310  void freeMatrixMNA (void);
311  void allocMatrixHB (void);
312  void freeMatrixHB (void);
313  void setMatrixS (matrix);
314  matrix getMatrixS (void);
315  void setMatrixN (matrix);
316  matrix getMatrixN (void);
317  void setMatrixY (matrix);
318  matrix getMatrixY (void);
319 
320  static const nr_double_t z0;
321 
322  protected:
323  int type;
324  int pol;
325 
326  private:
327  int size;
328  int pacport;
329  int vsource;
330  int vsources;
331  int nsources;
332  int inserted;
333  int flag;
348  char * subcircuit;
355  nr_double_t * deltas;
358 };
359 
360 } // namespace qucs
361 
362 // typedef to make it easier to set up our factory
364 // function typdefs to make it easier to set up our factories
366 typedef struct define_t *defs_t();
367 
368 // our global factories defined in module.cpp
369 extern "C" {
370  extern std::map<std::string, creator_t *, std::less<std::string> > factorycreate;
371  extern std::map<std::string, defs_t *, std::less<std::string> > factorydef;
372 
373 }
374 
375 #endif /* __CIRCUIT_H__ */
nr_double_t getG(int, int)
Definition: circuit.cpp:469
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
nr_double_t getOperatingPoint(const char *)
Definition: circuit.cpp:525
std::map< std::string, defs_t *, std::less< std::string > > factorydef
Definition: module.cpp:58
void addCharacteristic(const char *, nr_double_t)
Definition: circuit.cpp:550
void setHistory(bool h)
Definition: circuit.h:213
l
Definition: parse_vcd.y:213
void clearY(void)
Definition: circuit.cpp:740
void freeMatrixMNA(void)
Definition: circuit.cpp:284
nr_complex_t * MatrixC
Definition: circuit.h:338
virtual void calcCharacteristics(nr_double_t)
Definition: circuit.h:130
char * subcircuit
Definition: circuit.h:348
bool hasHistory(void)
Definition: circuit.h:212
void setDelta(nr_double_t *d)
Definition: circuit.h:208
void setSubcircuit(char *)
Definition: circuit.cpp:312
substrate * subst
Definition: circuit.h:350
void setISource(bool i)
Definition: circuit.h:194
void setOriginal(bool o)
Definition: circuit.h:233
void allocMatrixN(int sources=0)
Definition: circuit.cpp:260
void setQ(int, nr_complex_t)
Definition: circuit.cpp:418
struct define_t * defs_t()
Definition: circuit.h:366
void clearC(void)
Definition: circuit.cpp:710
void setD(int, int, nr_complex_t)
Definition: circuit.cpp:373
valuelist< operatingpoint > & getOperatingPoints(void)
Definition: circuit.h:288
int hasOperatingPoint(char *)
Definition: circuit.cpp:544
substrate * getSubstrate(void)
Definition: circuit.cpp:332
void setEnabled(bool e)
Set a circuit element to be enabled or diabled.
Definition: circuit.h:167
virtual void initHB(int)
Definition: circuit.h:126
void appendHistory(int, nr_double_t)
Definition: circuit.cpp:906
void setInternalVoltageSource(bool i)
Definition: circuit.h:184
t
Definition: parse_vcd.y:290
nr_double_t * deltas
Definition: circuit.h:355
bool isInternalVoltageSource(void)
Definition: circuit.h:185
void setVoltageSources(int)
Definition: circuit.cpp:607
nr_complex_t * VectorI
Definition: circuit.h:341
int nsources
Definition: circuit.h:331
int getVoltageSource(void)
Definition: circuit.h:187
nr_complex_t * VectorJ
Definition: circuit.h:343
int getHistorySize(void)
Definition: circuit.cpp:917
void setProbe(bool p)
Definition: circuit.h:171
void setType(int t)
Definition: circuit.h:136
void setB(int, int, nr_complex_t)
Definition: circuit.cpp:349
Houses the settings for netlist evaluation.
Definition: environment.h:51
void clearE(void)
Definition: circuit.cpp:720
void allocMatrixS(void)
Definition: circuit.cpp:251
#define MODFLAG(val, bit)
Definition: circuit.h:46
void setVoltageSource(int s)
Definition: circuit.h:186
n
Definition: parse_citi.y:147
void transientCapacitanceQ(int, int, int, nr_double_t)
Definition: circuit.cpp:790
static const nr_double_t z0
Definition: circuit.h:320
h
Definition: parse_vcd.y:214
nr_complex_t getN(int, int)
Definition: circuit.cpp:592
void transientCapacitanceC2Q(int, int, int, nr_double_t, nr_double_t)
Definition: circuit.cpp:846
void clearD(void)
Definition: circuit.cpp:715
void setJ(int, nr_complex_t)
Definition: circuit.cpp:430
virtual void initDC(void)
Definition: circuit.h:113
matrix getMatrixY(void)
Definition: circuit.cpp:696
int getInserted(void)
Definition: circuit.h:230
void applyHistory(history *)
Definition: circuit.cpp:929
int getSize(void)
Get the number of ports the circuit element has.
Definition: circuit.h:143
void clearI(void)
Definition: circuit.cpp:730
void addY(int, int, nr_complex_t)
Definition: circuit.cpp:458
matrix getMatrixN(void)
Definition: circuit.cpp:675
i
Definition: parse_mdl.y:516
void clearJ(void)
Definition: circuit.cpp:725
int getVoltageSources(void)
Definition: circuit.cpp:602
virtual void initNoiseAC(void)
Definition: circuit.h:118
nr_complex_t * MatrixY
Definition: circuit.h:336
void addOperatingPoint(const char *, nr_double_t)
Definition: circuit.cpp:517
virtual void initAC(void)
Definition: circuit.h:120
void setPort(int p)
Definition: circuit.h:229
bool isEnabled(void)
Reports if circuit element is enabled.
Definition: circuit.h:160
nr_complex_t getC(int, int)
Definition: circuit.cpp:355
void transientCapacitance(int, int, int, nr_double_t, nr_double_t, nr_double_t)
Definition: circuit.cpp:759
virtual void saveOperatingPoints(void)
Definition: circuit.h:129
virtual void calcHB(nr_double_t)
Definition: circuit.h:125
nr_double_t getHistoryAge(void)
Definition: circuit.cpp:911
void clearB(void)
Definition: circuit.cpp:705
base class for qucs circuit elements.
Definition: circuit.h:92
virtual void restartDC(void)
Definition: circuit.h:115
nr_double_t getJ(int, nr_double_t)
Definition: circuit.cpp:951
void transientCapacitanceC2V(int, int, int, nr_double_t, nr_double_t)
Definition: circuit.cpp:833
int getType(void)
Definition: circuit.h:137
char * getSubcircuit(void)
Definition: circuit.h:176
virtual void calcNoiseAC(nr_double_t)
Definition: circuit.h:119
nr_complex_t getI(int)
Definition: circuit.cpp:391
void setSize(int)
Set the number of ports the circuit element has.
Definition: circuit.cpp:195
void deleteHistory(void)
Definition: circuit.cpp:886
virtual void initSP(void)
placehoder for S-Parameter initialisation function
Definition: circuit.h:111
void setCV(int, nr_complex_t)
Definition: circuit.cpp:511
void allocMatrixHB(void)
Definition: circuit.cpp:227
net * getNet(void)
Definition: circuit.h:173
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
void print(void)
valuelist< characteristic > charac
Definition: circuit.h:352
nr_complex_t * MatrixS
Definition: circuit.h:334
bool isNonLinear(void)
Definition: circuit.h:299
void addI(int, nr_complex_t)
Definition: circuit.cpp:403
environment * getEnv(void)
Definition: circuit.h:180
environment * env
Definition: circuit.h:354
void setMatrixY(matrix)
Definition: circuit.cpp:685
std::map< std::string, creator_t *, std::less< std::string > > factorycreate
Definition: module.cpp:56
void setVSource(bool v)
Definition: circuit.h:192
int hasCharacteristic(char *)
Definition: circuit.cpp:577
nr_complex_t getE(int)
Definition: circuit.cpp:379
void setInserted(int i)
Definition: circuit.h:231
nr_complex_t * MatrixB
Definition: circuit.h:337
value
Definition: parse_vcd.y:315
virtual void calcAC(nr_double_t)
Definition: circuit.h:121
void setNet(net *n)
Definition: circuit.h:172
generic object class.
Definition: object.h:52
void setI(int, nr_complex_t)
Definition: circuit.cpp:397
virtual void initTR(void)
Definition: circuit.h:122
nr_complex_t * MatrixQV
Definition: circuit.h:345
bool isISource(void)
Definition: circuit.h:193
static char * createInternal(const char *, const char *)
Definition: circuit.cpp:626
bool isProbe(void)
Definition: circuit.h:170
nr_complex_t getD(int, int)
Definition: circuit.cpp:367
void truncateHistory(nr_double_t)
Definition: circuit.cpp:896
nr_complex_t getGV(int)
Definition: circuit.cpp:493
void setMatrixS(matrix)
Definition: circuit.cpp:643
matrix getMatrixS(void)
Definition: circuit.cpp:654
int getPort(void)
Definition: circuit.h:228
void setY(int, int, nr_complex_t)
Definition: circuit.cpp:452
virtual void calcOperatingPoints(void)
Definition: circuit.h:128
void setInternalNode(int, const char *)
Definition: circuit.cpp:635
void setEnv(environment *e)
Definition: circuit.h:181
v
Definition: parse_zvr.y:141
int vsources
Definition: circuit.h:330
nr_double_t getCharacteristic(char *)
Definition: circuit.cpp:558
void allocMatrixMNA(void)
Definition: circuit.cpp:267
void transientCapacitanceC(int, int, int, int, nr_double_t, nr_double_t)
Definition: circuit.cpp:819
nr_complex_t getB(int, int)
Definition: circuit.cpp:343
nr_complex_t * MatrixN
Definition: circuit.h:335
Definition: net.h:39
virtual void calcSP(nr_double_t)
Definition: circuit.h:112
bool isVariableSized(void)
Definition: circuit.h:168
virtual void initNoiseSP(void)
Definition: circuit.h:116
void setNonLinear(bool l)
Definition: circuit.h:298
valuelist< operatingpoint > oper
Definition: circuit.h:351
virtual void initHB(void)
Definition: circuit.h:124
history * histories
Definition: circuit.h:357
void setNode(int, const char *, int intern=0)
Definition: circuit.cpp:299
nr_double_t getV(int, nr_double_t)
Definition: circuit.cpp:941
nr_complex_t getQV(int, int)
Definition: circuit.cpp:481
nr_complex_t * VectorQ
Definition: circuit.h:344
virtual void calcHB(int)
Definition: circuit.h:127
nr_double_t getHistoryTFromIndex(int)
Definition: circuit.cpp:922
void setVariableSized(bool v)
Definition: circuit.h:169
node * nodes
Definition: circuit.h:349
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
void setMatrixN(matrix)
Definition: circuit.cpp:664
void setQV(int, int, nr_complex_t)
Definition: circuit.cpp:487
void setNoiseSources(int)
Definition: circuit.cpp:618
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
node * getNode(int)
Definition: circuit.cpp:307
node
void setN(int, int, nr_complex_t)
Definition: circuit.cpp:597
circuit_flag
Definition: circuit.h:61
void setOperatingPoint(const char *, nr_double_t)
Definition: circuit.cpp:533
net * subnet
Definition: circuit.h:353
#define RETFLAG(bit)
Definition: circuit.h:47
void setC(int, int, nr_complex_t)
Definition: circuit.cpp:361
nr_complex_t * VectorGV
Definition: circuit.h:346
nr_complex_t getQ(int)
Definition: circuit.cpp:413
nr_complex_t getY(int, int)
Definition: circuit.cpp:446
qucs::circuit * maker_t()
Definition: circuit.h:363
void setCharacteristic(const char *, nr_double_t)
Definition: circuit.cpp:566
int getNoiseSources(void)
Definition: circuit.cpp:613
virtual void calcDC(void)
Definition: circuit.h:114
void initHistory(nr_double_t)
Definition: circuit.cpp:869
nr_complex_t * VectorCV
Definition: circuit.h:347
qucs::circuit * creator_t()
Definition: circuit.h:365
valuelist< characteristic > & getCharacteristics(void)
Definition: circuit.h:295
void setHistoryAge(nr_double_t)
Definition: circuit.cpp:876
void setGV(int, nr_complex_t)
Definition: circuit.cpp:499
virtual void calcNoiseSP(nr_double_t)
Definition: circuit.h:117
int inserted
Definition: circuit.h:332
nr_complex_t getS(int, int)
Definition: circuit.cpp:582
bool isOriginal(void)
Definition: circuit.h:232
void setG(int, int, nr_double_t)
Definition: circuit.cpp:475
int nHistories
Definition: circuit.h:356
void setSubstrate(substrate *)
Definition: circuit.cpp:337
void clearV(void)
Definition: circuit.cpp:735
virtual void saveCharacteristics(nr_double_t)
Definition: circuit.h:131
bool isVSource(void)
Definition: circuit.h:191
nr_complex_t * VectorV
Definition: circuit.h:342
void freeMatrixHB(void)
Definition: circuit.cpp:219
nr_double_t * getDelta(void)
Definition: circuit.h:209
nr_complex_t * MatrixD
Definition: circuit.h:339
nr_complex_t * VectorE
Definition: circuit.h:340
void setV(int, nr_complex_t)
Definition: circuit.cpp:440
nr_complex_t getCV(int)
Definition: circuit.cpp:505
virtual void calcTR(nr_double_t)
Definition: circuit.h:123