Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bondwire.cpp
Go to the documentation of this file.
1 /*
2  * bondwire.cpp - bondwire class implementation
3  *
4  * Copyright (C) 2006 Bastien Roucaries <roucaries.bastien@gmail.com>
5  * Copyright (C) 2007, 2008 Stefan Jahn <stefan@lkcc.org>
6  *
7  * This is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this package; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  * $Id$
23  *
24  */
25 
49 #if HAVE_CONFIG_H
50 # include <config.h>
51 #endif
52 
53 #include "component.h"
54 #include "substrate.h"
55 #include "bondwire.h"
56 
57 using namespace qucs;
58 
59 bondwire::bondwire () : circuit (2) {
60  type = CIR_BONDWIRE;
61 }
62 
63 
65 #define TABLE(x) { #x, x }
66 
67 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
68 
74 };
75 
77 struct modeltable_t {
78  const char * name;
79  int model;
80 };
81 
83 static const modeltable_t modeltable[] = {
85  TABLE(MIRROR),
86 };
87 
88 
95  unsigned int i;
96 
97  R = 0;
98  l = getPropertyDouble ("L");
99  d = getPropertyDouble ("D");
100  h = getPropertyDouble ("H");
101  rho = getPropertyDouble ("rho");
102  mur = getPropertyDouble ("mur");
103 
104  /* model used */
105  char * Model = getPropertyString ("Model");
106  if (Model == NULL) {
107  model = FREESPACE;
108  logprint (LOG_STATUS, "Model is not specified force FREESPACE\n");
109  } else {
110  model = (enum bondwiremodel) -1;
111  for (i = 0 ; i < ARRAY_SIZE (modeltable); i++) {
112  if (!strcasecmp (modeltable[i].name, Model))
113  model = modeltable[i].model;
114  }
115 
116  if (model == -1)
117  /* XXXX: how to abort ? */
118  logprint (LOG_ERROR, "Model %s not defined\n", Model);
119  }
120 
121  /* For noise */
122  temp = getPropertyDouble ("Temp");
123 
124  /* how to get properties of the substrate, e.g. Er, H */
126  nr_double_t er = subst->getPropertyDouble ("er");
127  nr_double_t h = subst->getPropertyDouble ("h");
128  nr_double_t t = subst->getPropertyDouble ("t");
129 
130  /* Not yet used */
131  (void) er;
132  (void) h;
133  (void) t;
134 }
135 
143 static nr_double_t skindepth (const nr_double_t f,
144  const nr_double_t rho, const nr_double_t mur) {
145  return std::sqrt (rho / (M_PI * f * MU0 * mur));
146 }
147 
159 nr_double_t bondwire::resistance (const nr_double_t f) const {
160  nr_double_t delta, rout, rin;
161  rout = d / 2;
162  if (f > 0.0) {
163  delta = skindepth (f, rho, mur);
164  rin = rout - delta;
165  if (rin < 0.0)
166  rin = 0.0;
167  }
168  else
169  rin = 0.0;
170 
171  return (rho * M_1_PI * l) / (rout * rout - rin * rin);
172 }
173 
174 
198 static nr_double_t correctionfactor (const nr_double_t f,
199  const nr_double_t d,
200  const nr_double_t rho,
201  const nr_double_t mur) {
202  /* skin depth */
203  nr_double_t delta;
204 
205  if (f > 0.0 && rho > 0.0) {
206  delta = skindepth (f, rho, mur);
207  if (delta / d < 1e-2)
208  return delta / d;
209  else
210  return (mur / 4) * std::tanh ((4 * delta) / d);
211  }
212  return mur / 4;
213 }
214 
254 nr_double_t bondwire::Lfreespace (const nr_double_t f) const {
255  nr_double_t _2ld = (2.0 * l) / d;
256  nr_double_t d2l = d / (2.0 * l);
257  nr_double_t tmp;
258 
259  tmp = std::log (_2ld + std::sqrt (1 + _2ld * _2ld));
260  tmp += d2l - std::sqrt (1 + d2l * d2l);
261  tmp += correctionfactor (f, d, rho, mur);
262 
263  return MU0 * (M_1_PI / 2) * l * tmp;
264 }
265 
266 
297 nr_double_t bondwire::Lmirror (void) const {
298  nr_double_t tmp;
299 
300  /* compute \$\ln \frac{l+\sqrt{l^2+d^2/4}}{l+\sqrt{l^2+4h^2}}\$ */
301  tmp = std::log ((l + std::sqrt (l * l + d * d / 4)) / (l + std::sqrt (l * l + 4 * h * h)));
302  tmp += std::log (4 * h / d);
303  tmp += std::sqrt (1 + 4 * h * h / (l * l));
304  tmp -= std::sqrt (1 + d * d / (4 * l * l));
305  tmp -= 2 * h / l;
306  tmp += d / (2 * l);
307 
308  return MU0 * (M_1_PI / 2) * l * tmp;
309 }
310 
311 
314 matrix bondwire::calcMatrixY (const nr_double_t f) {
315  nr_double_t Lw;
316  L = 0;
317 
318  switch (model) {
319  case MIRROR:
320  L = Lmirror ();
321  R = resistance (f);
322  break;
323  case FREESPACE:
324  L = Lfreespace (f);
325  R = resistance (f);
326  break;
327  default:
328  break;
329  }
330 
331  Lw = L * 2 * M_PI * f;
332 
333  /* build Y-parameter matrix */
334  nr_complex_t yL = 1.0 / nr_complex_t (R, Lw);
335 
336  matrix Y (2);
337  Y.set (NODE_1, NODE_1, +yL);
338  Y.set (NODE_1, NODE_2, -yL);
339  Y.set (NODE_2, NODE_1, -yL);
340  Y.set (NODE_2, NODE_2, +yL);
341  return Y;
342 }
343 
345 void bondwire::initSP (void) {
346  allocMatrixS ();
347  getProperties ();
348 }
349 
353 void bondwire::calcSP (const nr_double_t frequency) {
354  setMatrixS (ytos (calcMatrixY (frequency)));
355 }
356 
358 void bondwire::saveCharacteristics (nr_double_t) {
359  setCharacteristic ("L", L);
360  setCharacteristic ("R", R);
361 }
362 
366 void bondwire::initDC (void) {
367  nr_double_t g;
368 
369  getProperties ();
370 
371  /* for non-zero resistances usual MNA entries */
372  if (rho != 0.0) {
373  g = 1.0 / resistance (0);
374  setVoltageSources (0);
375  allocMatrixMNA ();
376  setY (NODE_1, NODE_1, +g); setY (NODE_2, NODE_2, +g);
377  setY (NODE_1, NODE_2, -g); setY (NODE_2, NODE_1, -g);
378  }
379  /* for zero resistances create a zero voltage source */
380  else {
381  setVoltageSources (1);
383  allocMatrixMNA ();
384  clearY ();
386  }
387 }
388 
390 void bondwire::initAC (void) {
391  getProperties ();
392  setVoltageSources (0);
393  allocMatrixMNA ();
394 }
395 
399 void bondwire::calcAC (const nr_double_t frequency) {
400  setMatrixY (calcMatrixY (frequency));
401 }
402 
403 void bondwire::calcNoiseSP (nr_double_t) {
404  // calculate noise correlation matrix
405  nr_double_t T = getPropertyDouble ("Temp");
406  nr_double_t f = kelvin (T) * 4.0 * R * z0 / norm (4.0 * z0 + R) / T0;
407  setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f);
408  setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f);
409 }
410 
411 void bondwire::calcNoiseAC (nr_double_t) {
412  // calculate noise current correlation matrix
413  nr_double_t y = 1 / R;
414  nr_double_t T = getPropertyDouble ("Temp");
415  nr_double_t f = kelvin (T) / T0 * 4.0 * y;
416  setN (NODE_1, NODE_1, +f); setN (NODE_2, NODE_2, +f);
417  setN (NODE_1, NODE_2, -f); setN (NODE_2, NODE_1, -f);
418 }
419 
420 // properties
421 PROP_REQ [] = {
422  { "D", PROP_REAL, { 25e-6, PROP_NO_STR }, PROP_POS_RANGE },
423  { "L", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
424  { "H", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
425  { "mur", PROP_REAL, { 1, PROP_NO_STR }, PROP_RNGII (1, 100) },
426  { "rho", PROP_REAL, { 0.022e-6, PROP_NO_STR }, PROP_POS_RANGE },
427  { "Model", PROP_STR, { PROP_NO_VAL, "FREESPACE" },
428  PROP_RNG_STR3 ("FREESPACE", "MIRROR", "DESCHARLES") },
429  { "Subst", PROP_STR, { PROP_NO_VAL, "Subst1" }, PROP_NO_RANGE },
430  PROP_NO_PROP };
431 PROP_OPT [] = {
432  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
433  PROP_NO_PROP };
434 struct define_t bondwire::cirdef =
nr_double_t resistance(const nr_double_t f) const
Definition: bondwire.cpp:159
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
#define MU0
magnetic constant of vacuum ( )
Definition: constants.h:49
#define ARRAY_SIZE(x)
Definition: bondwire.cpp:67
#define PROP_POS_RANGE
Definition: netdefs.h:129
void clearY(void)
Definition: circuit.cpp:740
matrix ytos(matrix y, qucs::vector z0)
Admittance matrix to scattering parameters.
Definition: matrix.cpp:1133
#define NODE_2
Definition: circuit.h:35
#define T0
standard temperature
Definition: constants.h:61
#define PROP_RNGII(f, t)
Definition: netdefs.h:138
static const modeltable_t modeltable[]
Definition: bondwire.cpp:83
#define kelvin(x)
Definition: constants.h:108
substrate * subst
Definition: circuit.h:350
#define PROP_DEF
Definition: netdefs.h:189
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
nr_double_t d
Definition: bondwire.h:51
nr_double_t h
Definition: bondwire.h:52
#define PROP_REAL
Definition: netdefs.h:174
substrate * getSubstrate(void)
Definition: circuit.cpp:332
void setInternalVoltageSource(bool i)
Definition: circuit.h:184
t
Definition: parse_vcd.y:290
static nr_double_t correctionfactor(const nr_double_t f, const nr_double_t d, const nr_double_t rho, const nr_double_t mur)
Definition: bondwire.cpp:198
void calcNoiseSP(nr_double_t)
Definition: bondwire.cpp:403
#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 initDC(void)
Definition: bondwire.cpp:366
void allocMatrixS(void)
Definition: circuit.cpp:251
nr_double_t Lfreespace(const nr_double_t f) const
Definition: bondwire.cpp:254
#define PROP_LINEAR
Definition: netdefs.h:120
void calcSP(const nr_double_t)
Definition: bondwire.cpp:353
static const nr_double_t z0
Definition: circuit.h:320
PROP_OPT[]
Definition: bondwire.cpp:431
#define VSRC_1
Definition: circuit.h:40
i
Definition: parse_mdl.y:516
PROP_NO_SUBSTRATE
Definition: bondwire.cpp:435
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
Definition: complex.cpp:271
void initSP(void)
Definition: bondwire.cpp:345
nr_double_t temp
Definition: bondwire.h:57
void calcAC(nr_double_t)
Definition: bondwire.cpp:399
nr_complex_t tanh(const nr_complex_t z)
Compute complex hyperbolic tangent.
Definition: complex.cpp:153
void calcNoiseAC(nr_double_t)
Definition: bondwire.cpp:411
#define PROP_COMPONENT
Definition: netdefs.h:116
nr_double_t Lmirror() const
Definition: bondwire.cpp:297
void setMatrixY(matrix)
Definition: circuit.cpp:685
#define TABLE(x)
Definition: bondwire.cpp:65
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
nr_double_t L
Definition: bondwire.h:56
nr_double_t rho
Definition: bondwire.h:53
void setMatrixS(matrix)
Definition: circuit.cpp:643
bondwiremodel
Definition: bondwire.cpp:70
static nr_double_t skindepth(const nr_double_t f, const nr_double_t rho, const nr_double_t mur)
Definition: bondwire.cpp:143
void setY(int, int, nr_complex_t)
Definition: circuit.cpp:452
#define PROP_MIN_VAL(k)
Definition: netdefs.h:133
const char * name
Definition: bondwire.cpp:78
nr_double_t R
Definition: bondwire.h:56
int model
Definition: bondwire.h:55
void allocMatrixMNA(void)
Definition: circuit.cpp:267
PROP_REQ[]
Definition: bondwire.cpp:421
#define M_1_PI
Inverse of Archimedes' constant ( )
Definition: consts.h:59
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
nr_double_t l
Definition: bondwire.h:50
y
Definition: parse_mdl.y:499
void initAC(void)
Definition: bondwire.cpp:390
#define NODE_1
Definition: circuit.h:34
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
nr_double_t mur
Definition: bondwire.h:54
#define LOG_ERROR
Definition: logging.h:28
void setN(int, int, nr_complex_t)
Definition: circuit.cpp:597
#define PROP_NO_VAL
Definition: netdefs.h:124
#define LOG_STATUS
Definition: logging.h:29
qucs::matrix calcMatrixY(nr_double_t)
Definition: bondwire.cpp:314
char * name
Definition: object.h:87
#define PROP_RNG_STR3(s1, s2, s3)
Definition: netdefs.h:147
void setCharacteristic(const char *, nr_double_t)
Definition: circuit.cpp:566
char * getPropertyString(const char *)
Definition: object.cpp:159
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
void saveCharacteristics(nr_double_t)
Definition: bondwire.cpp:358
void getProperties(void)
Get properties from model. Get properties and fill the class.
Definition: bondwire.cpp:94