Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
22  *
23  */
24 
32 #if HAVE_CONFIG_H
33 # include <config.h>
34 #endif
35 
36 #include "component.h"
37 #include "capacitor.h"
38 
39 using namespace qucs;
40 
42 capacitor::capacitor () : circuit (2) {
43  type = CIR_CAPACITOR;
44  setISource (true);
45 }
46 
60 void capacitor::calcSP (nr_double_t frequency) {
61  nr_double_t c = getPropertyDouble ("C") * z0;
62  nr_complex_t y = 2.0 * nr_complex_t (0, 2.0 * M_PI * frequency * c);
63  setS (NODE_1, NODE_1, 1.0 / (1.0 + y));
64  setS (NODE_2, NODE_2, 1.0 / (1.0 + y));
65  setS (NODE_1, NODE_2, y / (1.0 + y));
66  setS (NODE_2, NODE_1, y / (1.0 + y));
67 }
68 
69 /*\brief Init DC simulation of capacitor */
70 void capacitor::initDC (void) {
71  allocMatrixMNA ();
72 }
73 
87 void capacitor::calcAC (nr_double_t frequency) {
88  nr_double_t c = getPropertyDouble ("C");
89  nr_complex_t y = nr_complex_t (0, 2.0 * M_PI * frequency * c);
90  setY (NODE_1, NODE_1, +y); setY (NODE_2, NODE_2, +y);
91  setY (NODE_1, NODE_2, -y); setY (NODE_2, NODE_1, -y);
92 }
93 
95 void capacitor::initAC (void) {
96  allocMatrixMNA ();
97 }
98 
99 #define qState 0 // charge state
100 #define cState 1 // current state
101 
102 void capacitor::initTR (void) {
103  setStates (2);
104  initDC ();
105 }
106 
107 void capacitor::calcTR (nr_double_t) {
108 
109  /* if this is a controlled capacitance then do nothing here */
110  if (hasProperty ("Controlled")) return;
111 
112  nr_double_t c = getPropertyDouble ("C");
113  nr_double_t g, i;
114  nr_double_t v = real (getV (NODE_1) - getV (NODE_2));
115 
116  /* apply initial condition if requested */
117  if (getMode () == MODE_INIT && isPropertyGiven ("V")) {
118  v = getPropertyDouble ("V");
119  }
120 
121  setState (qState, c * v);
122  integrate (qState, c, g, i);
123  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
124  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
125  setI (NODE_1 , -i);
126  setI (NODE_2 , +i);
127 }
128 
129 void capacitor::initHB (void) {
130  initAC ();
131 }
132 
133 void capacitor::calcHB (nr_double_t frequency) {
134  calcAC (frequency);
135 }
136 
137 // properties
138 PROP_REQ [] = {
139  { "C", PROP_REAL, { 1e-12, PROP_NO_STR }, PROP_NO_RANGE },
140  PROP_NO_PROP };
141 PROP_OPT [] = {
142  { "V", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
143  PROP_NO_PROP };
144 struct define_t capacitor::cirdef =
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
#define NODE_2
Definition: circuit.h:35
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
void setISource(bool i)
Definition: circuit.h:194
#define PROP_DEF
Definition: netdefs.h:189
void integrate(int, nr_double_t, nr_double_t &, nr_double_t &)
Definition: integrator.cpp:67
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
void calcTR(nr_double_t)
Definition: capacitor.cpp:107
void calcSP(nr_double_t)
Compute S parameters.
Definition: capacitor.cpp:60
#define PROP_REAL
Definition: netdefs.h:174
void setStates(int n)
Definition: states.h:52
int getMode(void)
Definition: integrator.h:55
#define PROP_NO_PROP
Definition: netdefs.h:122
#define PROP_NO_RANGE
Definition: netdefs.h:126
bool hasProperty(const char *)
Definition: object.cpp:206
#define PROP_NO_STR
Definition: netdefs.h:125
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
bool isPropertyGiven(const char *)
Definition: object.cpp:213
i
Definition: parse_mdl.y:516
void calcAC(nr_double_t)
AC model.
Definition: capacitor.cpp:87
void initAC(void)
Init AC model of capacitor.
Definition: capacitor.cpp:95
#define PROP_COMPONENT
Definition: netdefs.h:116
PROP_REQ[]
Definition: capacitor.cpp:138
PROP_OPT[]
Definition: capacitor.cpp:141
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
#define qState
Definition: capacitor.cpp:99
void setI(int, nr_complex_t)
Definition: circuit.cpp:397
void calcHB(nr_double_t)
Definition: capacitor.cpp:133
void setY(int, int, nr_complex_t)
Definition: circuit.cpp:452
v
Definition: parse_zvr.y:141
void allocMatrixMNA(void)
Definition: circuit.cpp:267
nr_double_t getV(int, nr_double_t)
Definition: circuit.cpp:941
y
Definition: parse_mdl.y:499
#define NODE_1
Definition: circuit.h:34
void initHB(void)
Definition: capacitor.cpp:129
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void setState(int, state_type_t, int n=0)
Definition: states.cpp:109
void initDC(void)
Definition: capacitor.cpp:70
void initTR(void)
Definition: capacitor.cpp:102
#define MODE_INIT
Definition: integrator.h:31