My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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: pac.cpp 1825 2011-03-11 20:42:14Z ela $
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 pac::pac () : circuit (2) {
33  type = CIR_PAC;
34  setISource (true);
35 }
36 
37 void pac::calcSP (nr_double_t) {
38  nr_double_t z = getPropertyDouble ("Z") / z0;
39  setS (NODE_1, NODE_1, z / (z + 2));
40  setS (NODE_2, NODE_2, z / (z + 2));
41  setS (NODE_1, NODE_2, 2 / (z + 2));
42  setS (NODE_2, NODE_1, 2 / (z + 2));
43 }
44 
45 void pac::calcNoiseSP (nr_double_t) {
46  nr_double_t r = getPropertyDouble ("Z");
47  nr_double_t T = getPropertyDouble ("Temp");
48  nr_double_t f = kelvin (T) * 4.0 * r * z0 / sqr (2.0 * z0 + r) / T0;
49  setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f);
50  setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f);
51 }
52 
53 void pac::calcDC (void) {
54  nr_double_t g = 1.0 / getPropertyDouble ("Z");
55  clearI ();
56  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
57  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
58 }
59 
60 void pac::calcAC (nr_double_t) {
61  nr_double_t p = getPropertyDouble ("P");
62  nr_double_t r = getPropertyDouble ("Z");
63  nr_double_t i = sqrt (8 * p / r);
64  calcDC ();
65  setI (NODE_1, +i); setI (NODE_2, -i);
66 }
67 
68 void pac::calcNoiseAC (nr_double_t) {
69  nr_double_t r = getPropertyDouble ("Z");
70  nr_double_t T = getPropertyDouble ("Temp");
71  nr_double_t f = kelvin (T) / T0 * 4.0 / r;
72  setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f);
73  setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f);
74 }
75 
76 void pac::calcTR (nr_double_t t) {
77  nr_double_t p = getPropertyDouble ("P");
78  nr_double_t r = getPropertyDouble ("Z");
79  nr_double_t f = getPropertyDouble ("f");
80  nr_double_t i = sqrt (8 * p / r) * sin (2 * M_PI * f * t);
81  calcDC ();
82  setI (NODE_1, +i); setI (NODE_2, -i);
83 }
84 
85 void pac::initHB (void) {
87  allocMatrixMNA ();
89  nr_double_t g = 1.0 / getPropertyDouble ("Z");
90  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
91  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
92 }
93 
94 void pac::calcHB (nr_double_t frequency) {
95  nr_double_t f = getPropertyDouble ("f");
96  if (f == frequency) {
97  nr_double_t p = getPropertyDouble ("P");
98  nr_double_t r = getPropertyDouble ("Z");
99  nr_double_t u = sqrt (4 * p * r);
100  setE (VSRC_1, u);
101  }
102  else {
103  setE (VSRC_1, 0);
104  }
105 }
106 
107 // properties
108 PROP_REQ [] = {
109  { "f", PROP_REAL, { 1e9, PROP_NO_STR }, PROP_POS_RANGE },
110  { "Z", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGEX },
111  { "Num", PROP_INT, { 1, PROP_NO_STR }, PROP_RNGII (1, MAX_PORTS) },
112  PROP_NO_PROP };
113 PROP_OPT [] = {
114  { "P", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
115  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
116  PROP_NO_PROP };
117 struct define_t pac::cirdef =