Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pac.cpp
Go to the documentation of this file.
1 /*
2  * pac.cpp - AC power source class implementation
3  *
4  * Copyright (C) 2003, 2004, 2005, 2006 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 #if HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include "component.h"
30 #include "pac.h"
31 
32 using namespace qucs;
33 
34 pac::pac () : circuit (2) {
35  type = CIR_PAC;
36  setISource (true);
37 }
38 
39 void pac::calcSP (nr_double_t) {
40  nr_double_t z = getPropertyDouble ("Z") / z0;
41  setS (NODE_1, NODE_1, z / (z + 2));
42  setS (NODE_2, NODE_2, z / (z + 2));
43  setS (NODE_1, NODE_2, 2 / (z + 2));
44  setS (NODE_2, NODE_1, 2 / (z + 2));
45 }
46 
47 void pac::calcNoiseSP (nr_double_t) {
48  nr_double_t r = getPropertyDouble ("Z");
49  nr_double_t T = getPropertyDouble ("Temp");
50  nr_double_t f = kelvin (T) * 4.0 * r * z0 / qucs::sqr (2.0 * z0 + r) / T0;
51  setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f);
52  setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f);
53 }
54 
55 void pac::calcDC (void) {
56  nr_double_t g = 1.0 / getPropertyDouble ("Z");
57  clearI ();
58  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
59  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
60 }
61 
62 void pac::calcAC (nr_double_t) {
63  nr_double_t p = getPropertyDouble ("P");
64  nr_double_t r = getPropertyDouble ("Z");
65  nr_double_t i = std::sqrt (8 * p / r);
66  calcDC ();
67  setI (NODE_1, +i); setI (NODE_2, -i);
68 }
69 
70 void pac::calcNoiseAC (nr_double_t) {
71  nr_double_t r = getPropertyDouble ("Z");
72  nr_double_t T = getPropertyDouble ("Temp");
73  nr_double_t f = kelvin (T) / T0 * 4.0 / r;
74  setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f);
75  setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f);
76 }
77 
78 void pac::calcTR (nr_double_t t) {
79  nr_double_t p = getPropertyDouble ("P");
80  nr_double_t r = getPropertyDouble ("Z");
81  nr_double_t f = getPropertyDouble ("f");
82  nr_double_t i = std::sqrt (8 * p / r) * std::sin (2 * M_PI * f * t);
83  calcDC ();
84  setI (NODE_1, +i); setI (NODE_2, -i);
85 }
86 
87 void pac::initHB (void) {
89  allocMatrixMNA ();
91  nr_double_t g = 1.0 / getPropertyDouble ("Z");
92  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
93  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
94 }
95 
96 void pac::calcHB (nr_double_t frequency) {
97  nr_double_t f = getPropertyDouble ("f");
98  if (f == frequency) {
99  nr_double_t p = getPropertyDouble ("P");
100  nr_double_t r = getPropertyDouble ("Z");
101  nr_double_t u = std::sqrt (4 * p * r);
102  setE (VSRC_1, u);
103  }
104  else {
105  setE (VSRC_1, 0);
106  }
107 }
108 
109 // properties
110 PROP_REQ [] = {
111  { "f", PROP_REAL, { 1e9, PROP_NO_STR }, PROP_POS_RANGE },
112  { "Z", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGEX },
113  { "Num", PROP_INT, { 1, PROP_NO_STR }, PROP_RNGII (1, MAX_PORTS) },
114  PROP_NO_PROP };
115 PROP_OPT [] = {
116  { "P", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
117  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
118  PROP_NO_PROP };
119 struct define_t pac::cirdef =
#define PROP_POS_RANGE
Definition: netdefs.h:129
#define NODE_2
Definition: circuit.h:35
#define T0
standard temperature
Definition: constants.h:61
#define PROP_RNGII(f, t)
Definition: netdefs.h:138
#define kelvin(x)
Definition: constants.h:108
Definition: pac.cpp:119
void setISource(bool i)
Definition: circuit.h:194
#define PROP_DEF
Definition: netdefs.h:189
#define MAX_PORTS
Definition: netdefs.h:113
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
#define PROP_REAL
Definition: netdefs.h:174
t
Definition: parse_vcd.y:290
#define PROP_NO_PROP
Definition: netdefs.h:122
void setVoltageSources(int)
Definition: circuit.cpp:607
#define K
Absolute 0 in centigrade.
Definition: constants.h:59
#define PROP_NO_STR
Definition: netdefs.h:125
void calcHB(nr_double_t)
Definition: pac.cpp:96
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
r
Definition: parse_mdl.y:515
void calcAC(nr_double_t)
Definition: pac.cpp:62
#define PROP_INT
Definition: netdefs.h:173
void clearI(void)
Definition: circuit.cpp:730
#define VSRC_1
Definition: circuit.h:40
i
Definition: parse_mdl.y:516
nr_complex_t sqr(const nr_complex_t z)
Square of complex number.
Definition: complex.cpp:673
PROP_NO_SUBSTRATE
Definition: pac.cpp:120
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
void initHB(void)
Definition: pac.cpp:87
nr_complex_t sin(const nr_complex_t z)
Compute complex sine.
Definition: complex.cpp:66
PROP_OPT[]
Definition: pac.cpp:115
#define PROP_COMPONENT
Definition: netdefs.h:116
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
void calcTR(nr_double_t)
Definition: pac.cpp:78
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
PROP_REQ[]
Definition: pac.cpp:110
void calcDC(void)
Definition: pac.cpp:55
void calcNoiseSP(nr_double_t)
Definition: pac.cpp:47
void setI(int, nr_complex_t)
Definition: circuit.cpp:397
void setY(int, int, nr_complex_t)
Definition: circuit.cpp:452
#define PROP_MIN_VAL(k)
Definition: netdefs.h:133
void calcNoiseAC(nr_double_t)
Definition: pac.cpp:70
void allocMatrixMNA(void)
Definition: circuit.cpp:267
#define PROP_POS_RANGEX
Definition: netdefs.h:131
#define NODE_1
Definition: circuit.h:34
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void setN(int, int, nr_complex_t)
Definition: circuit.cpp:597
void calcSP(nr_double_t)
Definition: pac.cpp:39