Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 using namespace qucs;
33 
34 resistor::resistor () : circuit (2) {
35  type = CIR_RESISTOR;
36 }
37 
38 void resistor::initSP (void) {
39  initModel ();
40  allocMatrixS ();
41 }
42 
43 void resistor::calcSP (nr_double_t) {
44  // calculate S-parameters
45  nr_double_t z = getScaledProperty ("R") / z0;
46  setS (NODE_1, NODE_1, z / (z + 2));
47  setS (NODE_2, NODE_2, z / (z + 2));
48  setS (NODE_1, NODE_2, 2 / (z + 2));
49  setS (NODE_2, NODE_1, 2 / (z + 2));
50 }
51 
52 void resistor::calcNoiseSP (nr_double_t) {
53  // calculate noise correlation matrix
54  nr_double_t r = getScaledProperty ("R");
55  nr_double_t T = getPropertyDouble ("Temp");
56  nr_double_t f = kelvin (T) * 4.0 * r * z0 / sqr (2.0 * z0 + r) / T0;
57  setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f);
58  setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f);
59 }
60 
61 void resistor::calcNoiseAC (nr_double_t) {
62  // calculate noise current correlation matrix
63  nr_double_t r = getScaledProperty ("R");
64  if (r > 0.0 || r < 0.0) {
65  nr_double_t T = getPropertyDouble ("Temp");
66  nr_double_t f = kelvin (T) / T0 * 4.0 / r;
67  setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f);
68  setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f);
69  }
70 }
71 
72 void resistor::initModel (void) {
73  /* if this is a controlled resistor then do nothing here */
74  if (hasProperty ("Controlled")) return;
75 
76  nr_double_t T = getPropertyDouble ("Temp");
77  nr_double_t Tn = getPropertyDouble ("Tnom");
78  nr_double_t R = getPropertyDouble ("R");
79  nr_double_t DT = T - Tn;
80 
81  // compute R temperature dependency
82  nr_double_t Tc1 = getPropertyDouble ("Tc1");
83  nr_double_t Tc2 = getPropertyDouble ("Tc2");
84  R = R * (1 + DT * (Tc1 + Tc2 * DT));
85  setScaledProperty ("R", R);
86 }
87 
88 void resistor::initDC (void) {
89  initModel ();
90  nr_double_t r = getScaledProperty ("R");
91 
92  // for non-zero resistances usual MNA entries
93  if (r != 0.0) {
94  nr_double_t g = 1.0 / r;
96  allocMatrixMNA ();
97  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
98  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
99  }
100  // for zero resistances create a zero voltage source
101  else {
102  setVoltageSources (1);
104  allocMatrixMNA ();
106  }
107 }
108 
109 /* The calcDC() function is here partly implemented again because the
110  circuit can be used to simulate controlled non-zero resistances. */
111 void resistor::calcDC (void) {
112  nr_double_t r = getScaledProperty ("R");
113 
114  // for non-zero resistances usual MNA entries
115  if (r != 0.0) {
116  nr_double_t g = 1.0 / r;
117  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
118  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
119  }
120 }
121 
122 void resistor::initAC (void) {
123  initDC ();
124 }
125 
126 void resistor::calcAC (nr_double_t) {
127  calcDC ();
128 }
129 
130 void resistor::initTR (void) {
131  initDC ();
132 }
133 
134 void resistor::calcTR (nr_double_t) {
135  calcDC ();
136 }
137 
138 // Initialize computation of MNA matrix entries for HB.
139 void resistor::initHB (void) {
140  initModel ();
141  nr_double_t r = getScaledProperty ("R");
142  setVoltageSources (1);
144  allocMatrixMNA ();
146  setD (VSRC_1, VSRC_1, -r);
147 }
148 
149 // properties
150 PROP_REQ [] = {
151  { "R", PROP_REAL, { 50, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
152 PROP_OPT [] = {
153  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
154  { "Tc1", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
155  { "Tc2", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
156  { "Tnom", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
157  PROP_NO_PROP };
158 struct define_t resistor::cirdef =
#define NODE_2
Definition: circuit.h:35
#define T0
standard temperature
Definition: constants.h:61
#define kelvin(x)
Definition: constants.h:108
#define PROP_DEF
Definition: netdefs.h:189
void calcNoiseAC(nr_double_t)
Definition: resistor.cpp:61
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
void setD(int, int, nr_complex_t)
Definition: circuit.cpp:373
#define PROP_REAL
Definition: netdefs.h:174
void initDC(void)
Definition: resistor.cpp:88
void calcSP(nr_double_t)
Definition: resistor.cpp:43
void setInternalVoltageSource(bool i)
Definition: circuit.h:184
#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_RANGE
Definition: netdefs.h:126
bool hasProperty(const char *)
Definition: object.cpp:206
#define PROP_NO_STR
Definition: netdefs.h:125
nr_double_t getScaledProperty(const char *)
Definition: object.cpp:185
void allocMatrixS(void)
Definition: circuit.cpp:251
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
r
Definition: parse_mdl.y:515
void setScaledProperty(const char *, nr_double_t)
Definition: object.cpp:133
void calcDC(void)
Definition: resistor.cpp:111
#define VSRC_1
Definition: circuit.h:40
PROP_OPT[]
Definition: resistor.cpp:152
nr_complex_t sqr(const nr_complex_t z)
Square of complex number.
Definition: complex.cpp:673
#define PROP_COMPONENT
Definition: netdefs.h:116
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: resistor.cpp:38
void initModel(void)
Definition: resistor.cpp:72
void initAC(void)
Definition: resistor.cpp:122
void setY(int, int, nr_complex_t)
Definition: circuit.cpp:452
#define PROP_MIN_VAL(k)
Definition: netdefs.h:133
void calcTR(nr_double_t)
Definition: resistor.cpp:134
void allocMatrixMNA(void)
Definition: circuit.cpp:267
void calcNoiseSP(nr_double_t)
Definition: resistor.cpp:52
void initTR(void)
Definition: resistor.cpp:130
#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 calcAC(nr_double_t)
Definition: resistor.cpp:126
PROP_REQ[]
Definition: resistor.cpp:150
void initHB(void)
Definition: resistor.cpp:139
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118