Qucs-core  0.0.19
relais.cpp
Go to the documentation of this file.
00001 /*
00002  * relais.cpp - relais class implementation
00003  *
00004  * Copyright (C) 2006, 2008, 2009 Stefan Jahn <stefan@lkcc.org>
00005  *
00006  * This is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  *
00011  * This software is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this package; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  * $Id$
00022  *
00023  */
00024 
00025 #if HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028 
00029 #include "component.h"
00030 #include "relais.h"
00031 
00032 using namespace qucs;
00033 
00034 relais::relais () : circuit (4) {
00035   type = CIR_RELAIS;
00036   setVoltageSources (1);
00037 }
00038 
00039 void relais::initSP (void) {
00040   allocMatrixS ();
00041   setS (NODE_1, NODE_1, 1.0); setS (NODE_4, NODE_4, 1.0);
00042   setS (NODE_2, NODE_2, r / (r + 2));
00043   setS (NODE_3, NODE_3, r / (r + 2));
00044   setS (NODE_2, NODE_3, 2 / (r + 2));
00045   setS (NODE_3, NODE_2, 2 / (r + 2));
00046 }
00047 
00048 void relais::calcNoiseSP (nr_double_t) {
00049   nr_double_t T = getPropertyDouble ("Temp");
00050   nr_double_t f = celsius2kelvin (T) * 4.0 * r * z0 / qucs::sqr (2.0 * z0 + r) / T0;
00051   setN (NODE_2, NODE_2, +f); setN (NODE_3, NODE_3, +f);
00052   setN (NODE_2, NODE_3, -f); setN (NODE_3, NODE_2, -f);
00053 }
00054 
00055 void relais::calcNoiseAC (nr_double_t) {
00056   if (r > 0.0 || r < 0.0) {
00057     nr_double_t T = getPropertyDouble ("Temp");
00058     nr_double_t f = celsius2kelvin (T) / T0 * 4.0 / r;
00059     setN (NODE_2, NODE_2, +f); setN (NODE_3, NODE_3, +f);
00060     setN (NODE_2, NODE_3, -f); setN (NODE_3, NODE_2, -f);
00061   }
00062 }
00063 
00064 void relais::initDC (void) {
00065   allocMatrixMNA ();
00066   voltageSource (VSRC_1, NODE_2, NODE_3);
00067   state = 0;
00068   r = 0.0;
00069 }
00070 
00071 #define REAL_OFF 0
00072 #define REAL_ON  1
00073 #define HYST_OFF 2
00074 #define HYST_ON  3
00075 
00076 void relais::calcDC (void) {
00077   nr_double_t vt   = getPropertyDouble ("Vt");
00078   nr_double_t vh   = getPropertyDouble ("Vh");
00079   nr_double_t von  = vt + vh;
00080   nr_double_t voff = vt - vh;
00081   nr_double_t ron  = getPropertyDouble ("Ron");
00082   nr_double_t roff = getPropertyDouble ("Roff");
00083   nr_double_t v = real (getV (NODE_1) - getV (NODE_4));
00084   if (state == REAL_OFF) {
00085     if (v >= von) {
00086       state = REAL_ON;
00087     }
00088   } else if (state == REAL_ON) {
00089     if (v <= voff) {
00090       state = REAL_OFF;
00091     }
00092   }
00093   if (state == REAL_ON) {
00094     r = ron;
00095   } else if (state == REAL_OFF) {
00096     r = roff;
00097   }
00098   setD (VSRC_1, VSRC_1, -r);
00099 }
00100 
00101 void relais::saveOperatingPoints (void) {
00102   setOperatingPoint ("R", r);
00103 }
00104 
00105 void relais::initAC (void) {
00106   initDC ();
00107   setD (VSRC_1, VSRC_1, -r);
00108 }
00109 
00110 void relais::initTR (void) {
00111   initDC ();
00112 }
00113 
00114 void relais::calcTR (nr_double_t) {
00115   calcDC ();
00116 }
00117 
00118 // properties
00119 PROP_REQ [] = {
00120   { "Vt", PROP_REAL, { 0.5, PROP_NO_STR }, PROP_NO_RANGE },
00121   { "Vh", PROP_REAL, { 0.1, PROP_NO_STR }, PROP_POS_RANGE },
00122   PROP_NO_PROP };
00123 PROP_OPT [] = {
00124   { "Ron", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
00125   { "Roff", PROP_REAL, { 1e12, PROP_NO_STR }, PROP_POS_RANGE },
00126   { "Temp", PROP_REAL, { 26.85, PROP_NO_STR }, PROP_MIN_VAL (K) },
00127   PROP_NO_PROP };
00128 struct define_t relais::cirdef =
00129   { "Relais", 4, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_NONLINEAR, PROP_DEF };