My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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: relais.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 "relais.h"
31 
32 relais::relais () : circuit (4) {
33  type = CIR_RELAIS;
34  setVoltageSources (1);
35 }
36 
37 void relais::initSP (void) {
38  allocMatrixS ();
39  setS (NODE_1, NODE_1, 1.0); setS (NODE_4, NODE_4, 1.0);
40  setS (NODE_2, NODE_2, r / (r + 2));
41  setS (NODE_3, NODE_3, r / (r + 2));
42  setS (NODE_2, NODE_3, 2 / (r + 2));
43  setS (NODE_3, NODE_2, 2 / (r + 2));
44 }
45 
46 void relais::calcNoiseSP (nr_double_t) {
47  nr_double_t T = getPropertyDouble ("Temp");
48  nr_double_t f = kelvin (T) * 4.0 * r * z0 / sqr (2.0 * z0 + r) / T0;
49  setN (NODE_2, NODE_2, +f); setN (NODE_3, NODE_3, +f);
50  setN (NODE_2, NODE_3, -f); setN (NODE_3, NODE_2, -f);
51 }
52 
53 void relais::calcNoiseAC (nr_double_t) {
54  if (r > 0.0 || r < 0.0) {
55  nr_double_t T = getPropertyDouble ("Temp");
56  nr_double_t f = kelvin (T) / T0 * 4.0 / r;
57  setN (NODE_2, NODE_2, +f); setN (NODE_3, NODE_3, +f);
58  setN (NODE_2, NODE_3, -f); setN (NODE_3, NODE_2, -f);
59  }
60 }
61 
62 void relais::initDC (void) {
63  allocMatrixMNA ();
65  state = 0;
66  r = 0.0;
67 }
68 
69 #define REAL_OFF 0
70 #define REAL_ON 1
71 #define HYST_OFF 2
72 #define HYST_ON 3
73 
74 void relais::calcDC (void) {
75  nr_double_t vt = getPropertyDouble ("Vt");
76  nr_double_t vh = getPropertyDouble ("Vh");
77  nr_double_t von = vt + vh;
78  nr_double_t voff = vt - vh;
79  nr_double_t ron = getPropertyDouble ("Ron");
80  nr_double_t roff = getPropertyDouble ("Roff");
81  nr_double_t v = real (getV (NODE_1) - getV (NODE_4));
82  if (state == REAL_OFF) {
83  if (v >= von) {
84  state = REAL_ON;
85  }
86  } else if (state == REAL_ON) {
87  if (v <= voff) {
88  state = REAL_OFF;
89  }
90  }
91  if (state == REAL_ON) {
92  r = ron;
93  } else if (state == REAL_OFF) {
94  r = roff;
95  }
96  setD (VSRC_1, VSRC_1, -r);
97 }
98 
100  setOperatingPoint ("R", r);
101 }
102 
103 void relais::initAC (void) {
104  initDC ();
105  setD (VSRC_1, VSRC_1, -r);
106 }
107 
108 void relais::initTR (void) {
109  initDC ();
110 }
111 
112 void relais::calcTR (nr_double_t) {
113  calcDC ();
114 }
115 
116 // properties
117 PROP_REQ [] = {
118  { "Vt", PROP_REAL, { 0.5, PROP_NO_STR }, PROP_NO_RANGE },
119  { "Vh", PROP_REAL, { 0.1, PROP_NO_STR }, PROP_POS_RANGE },
120  PROP_NO_PROP };
121 PROP_OPT [] = {
122  { "Ron", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
123  { "Roff", PROP_REAL, { 1e12, PROP_NO_STR }, PROP_POS_RANGE },
124  { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
125  PROP_NO_PROP };
126 struct define_t relais::cirdef =