Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
relais.cpp
Go to the documentation of this file.
1 /*
2  * relais.cpp - relais class implementation
3  *
4  * Copyright (C) 2006, 2008, 2009 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 "relais.h"
31 
32 using namespace qucs;
33 
34 relais::relais () : circuit (4) {
35  type = CIR_RELAIS;
37 }
38 
39 void relais::initSP (void) {
40  allocMatrixS ();
41  setS (NODE_1, NODE_1, 1.0); setS (NODE_4, NODE_4, 1.0);
42  setS (NODE_2, NODE_2, r / (r + 2));
43  setS (NODE_3, NODE_3, r / (r + 2));
44  setS (NODE_2, NODE_3, 2 / (r + 2));
45  setS (NODE_3, NODE_2, 2 / (r + 2));
46 }
47 
48 void relais::calcNoiseSP (nr_double_t) {
49  nr_double_t T = getPropertyDouble ("Temp");
50  nr_double_t f = kelvin (T) * 4.0 * r * z0 / qucs::sqr (2.0 * z0 + r) / T0;
51  setN (NODE_2, NODE_2, +f); setN (NODE_3, NODE_3, +f);
52  setN (NODE_2, NODE_3, -f); setN (NODE_3, NODE_2, -f);
53 }
54 
55 void relais::calcNoiseAC (nr_double_t) {
56  if (r > 0.0 || r < 0.0) {
57  nr_double_t T = getPropertyDouble ("Temp");
58  nr_double_t f = kelvin (T) / T0 * 4.0 / r;
59  setN (NODE_2, NODE_2, +f); setN (NODE_3, NODE_3, +f);
60  setN (NODE_2, NODE_3, -f); setN (NODE_3, NODE_2, -f);
61  }
62 }
63 
64 void relais::initDC (void) {
65  allocMatrixMNA ();
67  state = 0;
68  r = 0.0;
69 }
70 
71 #define REAL_OFF 0
72 #define REAL_ON 1
73 #define HYST_OFF 2
74 #define HYST_ON 3
75 
76 void relais::calcDC (void) {
77  nr_double_t vt = getPropertyDouble ("Vt");
78  nr_double_t vh = getPropertyDouble ("Vh");
79  nr_double_t von = vt + vh;
80  nr_double_t voff = vt - vh;
81  nr_double_t ron = getPropertyDouble ("Ron");
82  nr_double_t roff = getPropertyDouble ("Roff");
83  nr_double_t v = real (getV (NODE_1) - getV (NODE_4));
84  if (state == REAL_OFF) {
85  if (v >= von) {
86  state = REAL_ON;
87  }
88  } else if (state == REAL_ON) {
89  if (v <= voff) {
90  state = REAL_OFF;
91  }
92  }
93  if (state == REAL_ON) {
94  r = ron;
95  } else if (state == REAL_OFF) {
96  r = roff;
97  }
98  setD (VSRC_1, VSRC_1, -r);
99 }
100 
102  setOperatingPoint ("R", r);
103 }
104 
105 void relais::initAC (void) {
106  initDC ();
107  setD (VSRC_1, VSRC_1, -r);
108 }
109 
110 void relais::initTR (void) {
111  initDC ();
112 }
113 
114 void relais::calcTR (nr_double_t) {
115  calcDC ();
116 }
117 
118 // properties
119 PROP_REQ [] = {
120  { "Vt", PROP_REAL, { 0.5, PROP_NO_STR }, PROP_NO_RANGE },
121  { "Vh", PROP_REAL, { 0.1, PROP_NO_STR }, PROP_POS_RANGE },
122  PROP_NO_PROP };
123 PROP_OPT [] = {
124  { "Ron", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
125  { "Roff", PROP_REAL, { 1e12, PROP_NO_STR }, PROP_POS_RANGE },
126  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
127  PROP_NO_PROP };
128 struct define_t relais::cirdef =
#define PROP_POS_RANGE
Definition: netdefs.h:129
#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
#define PROP_DEF
Definition: netdefs.h:189
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
#define REAL_ON
Definition: relais.cpp:72
#define PROP_NO_PROP
Definition: netdefs.h:122
void setVoltageSources(int)
Definition: circuit.cpp:607
void calcNoiseSP(nr_double_t)
Definition: relais.cpp:48
void saveOperatingPoints(void)
Definition: relais.cpp:101
#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
#define REAL_OFF
Definition: relais.cpp:71
void allocMatrixS(void)
Definition: circuit.cpp:251
static const nr_double_t z0
Definition: circuit.h:320
PROP_REQ[]
Definition: relais.cpp:119
#define NODE_4
Definition: circuit.h:37
#define VSRC_1
Definition: circuit.h:40
nr_complex_t sqr(const nr_complex_t z)
Square of complex number.
Definition: complex.cpp:673
void calcNoiseAC(nr_double_t)
Definition: relais.cpp:55
nr_double_t r
Definition: relais.h:44
#define PROP_COMPONENT
Definition: netdefs.h:116
PROP_OPT[]
Definition: relais.cpp:123
#define NODE_3
Definition: circuit.h:36
void calcTR(nr_double_t)
Definition: relais.cpp:114
void calcDC(void)
Definition: relais.cpp:76
#define PROP_MIN_VAL(k)
Definition: netdefs.h:133
v
Definition: parse_zvr.y:141
void allocMatrixMNA(void)
Definition: circuit.cpp:267
nr_double_t getV(int, nr_double_t)
Definition: circuit.cpp:941
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: relais.cpp:39
#define NODE_1
Definition: circuit.h:34
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
void initDC(void)
Definition: relais.cpp:64
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
void setN(int, int, nr_complex_t)
Definition: circuit.cpp:597
void setOperatingPoint(const char *, nr_double_t)
Definition: circuit.cpp:533
int state
Definition: relais.h:43
void initTR(void)
Definition: relais.cpp:110
#define PROP_NONLINEAR
Definition: netdefs.h:119
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118
void initAC(void)
Definition: relais.cpp:105