My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
capacitor.cpp
Go to the documentation of this file.
1 /*
2  * capacitor.cpp - capacitor class implementation
3  *
4  * Copyright (C) 2003, 2004, 2005, 2006, 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: capacitor.cpp 1825 2011-03-11 20:42:14Z ela $
22  *
23  */
24 
32 #if HAVE_CONFIG_H
33 # include <config.h>
34 #endif
35 
36 #include "component.h"
37 #include "capacitor.h"
38 
40 capacitor::capacitor () : circuit (2) {
41  type = CIR_CAPACITOR;
42  setISource (true);
43 }
44 
58 void capacitor::calcSP (nr_double_t frequency) {
59  nr_double_t c = getPropertyDouble ("C") * z0;
60  nr_complex_t y = 2.0 * rect (0, 2.0 * M_PI * frequency * c);
61  setS (NODE_1, NODE_1, 1.0 / (1.0 + y));
62  setS (NODE_2, NODE_2, 1.0 / (1.0 + y));
63  setS (NODE_1, NODE_2, y / (1.0 + y));
64  setS (NODE_2, NODE_1, y / (1.0 + y));
65 }
66 
67 /*\brief Init DC simulation of capacitor */
68 void capacitor::initDC (void) {
69  allocMatrixMNA ();
70 }
71 
85 void capacitor::calcAC (nr_double_t frequency) {
86  nr_double_t c = getPropertyDouble ("C");
87  nr_complex_t y = rect (0, 2.0 * M_PI * frequency * c);
88  setY (NODE_1, NODE_1, +y); setY (NODE_2, NODE_2, +y);
89  setY (NODE_1, NODE_2, -y); setY (NODE_2, NODE_1, -y);
90 }
91 
93 void capacitor::initAC (void) {
94  allocMatrixMNA ();
95 }
96 
97 #define qState 0 // charge state
98 #define cState 1 // current state
99 
100 void capacitor::initTR (void) {
101  setStates (2);
102  initDC ();
103 }
104 
105 void capacitor::calcTR (nr_double_t) {
106 
107  /* if this is a controlled capacitance then do nothing here */
108  if (hasProperty ("Controlled")) return;
109 
110  nr_double_t c = getPropertyDouble ("C");
111  nr_double_t g, i;
112  nr_double_t v = real (getV (NODE_1) - getV (NODE_2));
113 
114  /* apply initial condition if requested */
115  if (getMode () == MODE_INIT && isPropertyGiven ("V")) {
116  v = getPropertyDouble ("V");
117  }
118 
119  setState (qState, c * v);
120  integrate (qState, c, g, i);
121  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
122  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
123  setI (NODE_1 , -i);
124  setI (NODE_2 , +i);
125 }
126 
127 void capacitor::initHB (void) {
128  initAC ();
129 }
130 
131 void capacitor::calcHB (nr_double_t frequency) {
132  calcAC (frequency);
133 }
134 
135 // properties
136 PROP_REQ [] = {
137  { "C", PROP_REAL, { 1e-12, PROP_NO_STR }, PROP_NO_RANGE },
138  PROP_NO_PROP };
139 PROP_OPT [] = {
140  { "V", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
141  PROP_NO_PROP };
142 struct define_t capacitor::cirdef =