My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
resistor.cpp
Go to the documentation of this file.
1 /*
2  * resistor.cpp - resistor 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: resistor.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 "resistor.h"
31 
32 resistor::resistor () : circuit (2) {
33  type = CIR_RESISTOR;
34 }
35 
36 void resistor::initSP (void) {
37  initModel ();
38  allocMatrixS ();
39 }
40 
41 void resistor::calcSP (nr_double_t) {
42  // calculate S-parameters
43  nr_double_t z = getScaledProperty ("R") / z0;
44  setS (NODE_1, NODE_1, z / (z + 2));
45  setS (NODE_2, NODE_2, z / (z + 2));
46  setS (NODE_1, NODE_2, 2 / (z + 2));
47  setS (NODE_2, NODE_1, 2 / (z + 2));
48 }
49 
50 void resistor::calcNoiseSP (nr_double_t) {
51  // calculate noise correlation matrix
52  nr_double_t r = getScaledProperty ("R");
53  nr_double_t T = getPropertyDouble ("Temp");
54  nr_double_t f = kelvin (T) * 4.0 * r * z0 / sqr (2.0 * z0 + r) / T0;
55  setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f);
56  setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f);
57 }
58 
59 void resistor::calcNoiseAC (nr_double_t) {
60  // calculate noise current correlation matrix
61  nr_double_t r = getScaledProperty ("R");
62  if (r > 0.0 || r < 0.0) {
63  nr_double_t T = getPropertyDouble ("Temp");
64  nr_double_t f = kelvin (T) / T0 * 4.0 / r;
65  setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f);
66  setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f);
67  }
68 }
69 
70 void resistor::initModel (void) {
71  /* if this is a controlled resistor then do nothing here */
72  if (hasProperty ("Controlled")) return;
73 
74  nr_double_t T = getPropertyDouble ("Temp");
75  nr_double_t Tn = getPropertyDouble ("Tnom");
76  nr_double_t R = getPropertyDouble ("R");
77  nr_double_t DT = T - Tn;
78 
79  // compute R temperature dependency
80  nr_double_t Tc1 = getPropertyDouble ("Tc1");
81  nr_double_t Tc2 = getPropertyDouble ("Tc2");
82  R = R * (1 + DT * (Tc1 + Tc2 * DT));
83  setScaledProperty ("R", R);
84 }
85 
86 void resistor::initDC (void) {
87  initModel ();
88  nr_double_t r = getScaledProperty ("R");
89 
90  // for non-zero resistances usual MNA entries
91  if (r != 0.0) {
92  nr_double_t g = 1.0 / r;
94  allocMatrixMNA ();
95  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
96  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
97  }
98  // for zero resistances create a zero voltage source
99  else {
100  setVoltageSources (1);
102  allocMatrixMNA ();
104  }
105 }
106 
107 /* The calcDC() function is here partly implemented again because the
108  circuit can be used to simulate controlled non-zero resistances. */
109 void resistor::calcDC (void) {
110  nr_double_t r = getScaledProperty ("R");
111 
112  // for non-zero resistances usual MNA entries
113  if (r != 0.0) {
114  nr_double_t g = 1.0 / r;
115  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
116  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
117  }
118 }
119 
120 void resistor::initAC (void) {
121  initDC ();
122 }
123 
124 void resistor::calcAC (nr_double_t) {
125  calcDC ();
126 }
127 
128 void resistor::initTR (void) {
129  initDC ();
130 }
131 
132 void resistor::calcTR (nr_double_t) {
133  calcDC ();
134 }
135 
136 // Initialize computation of MNA matrix entries for HB.
137 void resistor::initHB (void) {
138  initModel ();
139  nr_double_t r = getScaledProperty ("R");
140  setVoltageSources (1);
142  allocMatrixMNA ();
144  setD (VSRC_1, VSRC_1, -r);
145 }
146 
147 // properties
148 PROP_REQ [] = {
149  { "R", PROP_REAL, { 50, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
150 PROP_OPT [] = {
151  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
152  { "Tc1", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
153  { "Tc2", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
154  { "Tnom", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
155  PROP_NO_PROP };
156 struct define_t resistor::cirdef =