Qucs-core
0.0.19
|
00001 /* 00002 * pac.cpp - AC power source class implementation 00003 * 00004 * Copyright (C) 2003, 2004, 2005, 2006 Stefan Jahn <stefan@lkcc.org> 00005 * 00006 * This is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2, or (at your option) 00009 * any later version. 00010 * 00011 * This software is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this package; see the file COPYING. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 * $Id$ 00022 * 00023 */ 00024 00025 #if HAVE_CONFIG_H 00026 # include <config.h> 00027 #endif 00028 00029 #include "component.h" 00030 #include "pac.h" 00031 00032 using namespace qucs; 00033 00034 pac::pac () : circuit (2) { 00035 type = CIR_PAC; 00036 setISource (true); 00037 } 00038 00039 void pac::calcSP (nr_double_t) { 00040 nr_double_t z = getPropertyDouble ("Z") / z0; 00041 setS (NODE_1, NODE_1, z / (z + 2)); 00042 setS (NODE_2, NODE_2, z / (z + 2)); 00043 setS (NODE_1, NODE_2, 2 / (z + 2)); 00044 setS (NODE_2, NODE_1, 2 / (z + 2)); 00045 } 00046 00047 void pac::calcNoiseSP (nr_double_t) { 00048 nr_double_t r = getPropertyDouble ("Z"); 00049 nr_double_t T = getPropertyDouble ("Temp"); 00050 nr_double_t f = celsius2kelvin (T) * 4.0 * r * z0 / qucs::sqr (2.0 * z0 + r) / T0; 00051 setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f); 00052 setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f); 00053 } 00054 00055 void pac::calcDC (void) { 00056 nr_double_t g = 1.0 / getPropertyDouble ("Z"); 00057 clearI (); 00058 setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g); 00059 setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g); 00060 } 00061 00062 void pac::calcAC (nr_double_t) { 00063 nr_double_t p = getPropertyDouble ("P"); 00064 nr_double_t r = getPropertyDouble ("Z"); 00065 nr_double_t i = std::sqrt (8 * p / r); 00066 calcDC (); 00067 setI (NODE_1, +i); setI (NODE_2, -i); 00068 } 00069 00070 void pac::calcNoiseAC (nr_double_t) { 00071 nr_double_t r = getPropertyDouble ("Z"); 00072 nr_double_t T = getPropertyDouble ("Temp"); 00073 nr_double_t f = celsius2kelvin (T) / T0 * 4.0 / r; 00074 setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f); 00075 setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f); 00076 } 00077 00078 void pac::calcTR (nr_double_t t) { 00079 nr_double_t p = getPropertyDouble ("P"); 00080 nr_double_t r = getPropertyDouble ("Z"); 00081 nr_double_t f = getPropertyDouble ("f"); 00082 nr_double_t i = std::sqrt (8 * p / r) * std::sin (2 * pi * f * t); 00083 calcDC (); 00084 setI (NODE_1, +i); setI (NODE_2, -i); 00085 } 00086 00087 void pac::initHB (void) { 00088 setVoltageSources (1); 00089 allocMatrixMNA (); 00090 voltageSource (VSRC_1, NODE_1, NODE_2); 00091 nr_double_t g = 1.0 / getPropertyDouble ("Z"); 00092 setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g); 00093 setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g); 00094 } 00095 00096 void pac::calcHB (nr_double_t frequency) { 00097 nr_double_t f = getPropertyDouble ("f"); 00098 if (f == frequency) { 00099 nr_double_t p = getPropertyDouble ("P"); 00100 nr_double_t r = getPropertyDouble ("Z"); 00101 nr_double_t u = std::sqrt (4 * p * r); 00102 setE (VSRC_1, u); 00103 } 00104 else { 00105 setE (VSRC_1, 0); 00106 } 00107 } 00108 00109 // properties 00110 PROP_REQ [] = { 00111 { "f", PROP_REAL, { 1e9, PROP_NO_STR }, PROP_POS_RANGE }, 00112 { "Z", PROP_REAL, { 50, PROP_NO_STR }, PROP_POS_RANGEX }, 00113 { "Num", PROP_INT, { 1, PROP_NO_STR }, PROP_RNGII (1, MAX_PORTS) }, 00114 PROP_NO_PROP }; 00115 PROP_OPT [] = { 00116 { "P", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE }, 00117 { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) }, 00118 PROP_NO_PROP }; 00119 struct define_t pac::cirdef = 00120 { "Pac", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };