Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
msvia.cpp
Go to the documentation of this file.
1 /*
2  * msvia.cpp - microstrip via hole class implementation
3  *
4  * Copyright (C) 2004, 2005, 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 "substrate.h"
31 #include "msvia.h"
32 
33 using namespace qucs;
34 
35 msvia::msvia () : circuit (2) {
36  R = 0;
37  Z = 0;
38  type = CIR_MSVIA;
39 }
40 
41 void msvia::calcNoiseSP (nr_double_t) {
42  // calculate noise correlation matrix
43  nr_double_t T = getPropertyDouble ("Temp");
44  nr_double_t f = kelvin (T) * 4.0 * real (Z) * z0 / norm (4.0 * z0 + Z) / T0;
45  setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f);
46  setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f);
47 }
48 
49 void msvia::initSP (void) {
50  allocMatrixS ();
51  R = calcResistance ();
52 }
53 
54 void msvia::calcSP (nr_double_t frequency) {
55  // calculate s-parameters
56  Z = calcImpedance (frequency);
57  nr_complex_t z = Z / z0;
58  setS (NODE_1, NODE_1, z / (z + 2.0));
59  setS (NODE_2, NODE_2, z / (z + 2.0));
60  setS (NODE_1, NODE_2, 2.0 / (z + 2.0));
61  setS (NODE_2, NODE_1, 2.0 / (z + 2.0));
62 }
63 
64 nr_complex_t msvia::calcImpedance (nr_double_t frequency) {
65  // fetch substrate and component properties
67  nr_double_t h = subst->getPropertyDouble ("h");
68  nr_double_t t = subst->getPropertyDouble ("t");
69  nr_double_t rho = subst->getPropertyDouble ("rho");
70  nr_double_t r = getPropertyDouble ("D") / 2;
71 
72  // check frequency validity
73  if (frequency * h >= 0.03 * C0) {
74  logprint (LOG_ERROR, "WARNING: Model for microstrip via hole defined for "
75  "freq/C0*h < 0.03 (is %g)\n", frequency / C0 * h);
76  }
77 
78  // create Z-parameter
79  nr_double_t fs = M_PI * MU0 * sqr (t) / rho;
80  nr_double_t res = R * std::sqrt (1 + frequency * fs);
81  nr_double_t a = std::sqrt (sqr (r) + sqr (h));
82  nr_double_t ind = MU0 * (h * std::log ((h + a) / r) + 1.5 * (r - a));
83  return Z = nr_complex_t (res, frequency * ind);
84 }
85 
86 nr_double_t msvia::calcResistance (void) {
87  // fetch substrate and component properties
89  nr_double_t h = subst->getPropertyDouble ("h");
90  nr_double_t t = subst->getPropertyDouble ("t");
91  nr_double_t rho = subst->getPropertyDouble ("rho");
92  nr_double_t r = getPropertyDouble ("D") / 2;
93  nr_double_t v = h / M_PI / (sqr (r) - sqr (r - t));
94  return R = rho * v;
95 }
96 
97 void msvia::initDC (void) {
98  nr_double_t r = calcResistance ();
99 
100  // for non-zero resistances usual MNA entries
101  if (r != 0.0) {
102  nr_double_t g = 1.0 / r;
103  setVoltageSources (0);
104  allocMatrixMNA ();
105  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
106  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
107  }
108  // for zero resistances create a zero voltage source
109  else {
110  setVoltageSources (1);
112  allocMatrixMNA ();
113  clearY ();
115  }
116 }
117 
118 void msvia::initAC (void) {
119  setVoltageSources (0);
120  allocMatrixMNA ();
121  R = calcResistance ();
122 }
123 
124 void msvia::calcAC (nr_double_t frequency) {
125  nr_complex_t y = 1.0 / calcImpedance (frequency);
126  setY (NODE_1, NODE_1, +y); setY (NODE_2, NODE_2, +y);
127  setY (NODE_1, NODE_2, -y); setY (NODE_2, NODE_1, -y);
128 }
129 
130 void msvia::calcNoiseAC (nr_double_t) {
131  // calculate noise current correlation matrix
132  nr_double_t y = real (1.0 / Z);
133  nr_double_t T = getPropertyDouble ("Temp");
134  nr_double_t f = kelvin (T) / T0 * 4.0 * y;
135  setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f);
136  setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f);
137 }
138 
139 // properties
140 PROP_REQ [] = {
141  { "D", PROP_REAL, { 100e-6, PROP_NO_STR }, PROP_POS_RANGE },
142  { "Subst", PROP_STR, { PROP_NO_VAL, "Subst1" }, PROP_NO_RANGE },
143  PROP_NO_PROP };
144 PROP_OPT [] = {
145  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
146  PROP_NO_PROP };
147 struct define_t msvia::cirdef =
nr_complex_t Z
Definition: msvia.h:44
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
#define MU0
magnetic constant of vacuum ( )
Definition: constants.h:49
#define PROP_POS_RANGE
Definition: netdefs.h:129
void clearY(void)
Definition: circuit.cpp:740
#define NODE_2
Definition: circuit.h:35
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
#define T0
standard temperature
Definition: constants.h:61
#define kelvin(x)
Definition: constants.h:108
substrate * subst
Definition: circuit.h:350
nr_double_t calcResistance(void)
Definition: msvia.cpp:86
#define PROP_DEF
Definition: netdefs.h:189
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
#define PROP_REAL
Definition: netdefs.h:174
substrate * getSubstrate(void)
Definition: circuit.cpp:332
void setInternalVoltageSource(bool i)
Definition: circuit.h:184
Definition: msvia.cpp:147
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_RANGE
Definition: netdefs.h:126
#define PROP_NO_STR
Definition: netdefs.h:125
void allocMatrixS(void)
Definition: circuit.cpp:251
#define PROP_LINEAR
Definition: netdefs.h:120
static const nr_double_t z0
Definition: circuit.h:320
h
Definition: parse_vcd.y:214
r
Definition: parse_mdl.y:515
void calcSP(nr_double_t)
Definition: msvia.cpp:54
#define R(con)
#define VSRC_1
Definition: circuit.h:40
void initDC(void)
Definition: msvia.cpp:97
nr_complex_t sqr(const nr_complex_t z)
Square of complex number.
Definition: complex.cpp:673
nr_complex_t calcImpedance(nr_double_t)
Definition: msvia.cpp:64
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
void calcNoiseAC(nr_double_t)
Definition: msvia.cpp:130
nr_double_t R
Definition: msvia.h:43
void initAC(void)
Definition: msvia.cpp:118
PROP_OPT[]
Definition: msvia.cpp:144
#define PROP_COMPONENT
Definition: netdefs.h:116
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
PROP_NO_SUBSTRATE
Definition: msvia.cpp:148
void setY(int, int, nr_complex_t)
Definition: circuit.cpp:452
#define PROP_MIN_VAL(k)
Definition: netdefs.h:133
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: msvia.cpp:49
v
Definition: parse_zvr.y:141
void allocMatrixMNA(void)
Definition: circuit.cpp:267
nr_double_t norm(const nr_complex_t z)
Compute euclidian norm of complex number.
Definition: complex.cpp:283
#define PROP_STR
Definition: netdefs.h:175
y
Definition: parse_mdl.y:499
#define NODE_1
Definition: circuit.h:34
#define C0
speed of light in vacuum ( )
Definition: constants.h:47
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
void calcAC(nr_double_t)
Definition: msvia.cpp:124
#define LOG_ERROR
Definition: logging.h:28
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void setN(int, int, nr_complex_t)
Definition: circuit.cpp:597
#define PROP_NO_VAL
Definition: netdefs.h:124
void logprint(int level, const char *format,...)
Definition: logging.c:37
nr_complex_t log(const nr_complex_t z)
Compute principal value of natural logarithm of z.
Definition: complex.cpp:215
PROP_REQ[]
Definition: msvia.cpp:140
void calcNoiseSP(nr_double_t)
Definition: msvia.cpp:41