Qucs-core  0.0.19
iexp.cpp
Go to the documentation of this file.
00001 /*
00002  * iexp.cpp - exponential current source class implementation
00003  *
00004  * Copyright (C) 2007, 2008 Stefan Jahn <stefan@lkcc.org>
00005  * Copyright (C) 2007 Gunther Kraut <gn.kraut@t-online.de>
00006  *
00007  * This is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2, or (at your option)
00010  * any later version.
00011  *
00012  * This software is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this package; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00020  * Boston, MA 02110-1301, USA.
00021  *
00022  * $Id$
00023  *
00024  */
00025 
00026 #if HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029 
00030 #include "component.h"
00031 #include "iexp.h"
00032 
00033 using namespace qucs;
00034 
00035 iexp::iexp () : circuit (2) {
00036   type = CIR_IEXP;
00037   setISource (true);
00038 }
00039 
00040 void iexp::initSP (void) {
00041   allocMatrixS ();
00042   setS (NODE_1, NODE_1, 1.0);
00043   setS (NODE_1, NODE_2, 0.0);
00044   setS (NODE_2, NODE_1, 0.0);
00045   setS (NODE_2, NODE_2, 1.0);
00046 }
00047 
00048 void iexp::initDC (void) {
00049   nr_double_t i = getPropertyDouble ("I1");
00050   allocMatrixMNA ();
00051   setI (NODE_1, +i); setI (NODE_2, -i);
00052 }
00053 
00054 void iexp::initAC (void) {
00055   allocMatrixMNA ();
00056   clearI ();
00057 }
00058 
00059 void iexp::initTR (void) {
00060   initDC ();
00061 }
00062 
00063 void iexp::calcTR (nr_double_t t) {
00064   nr_double_t i1 = getPropertyDouble ("I1");
00065   nr_double_t i2 = getPropertyDouble ("I2");
00066   nr_double_t t1 = getPropertyDouble ("T1");
00067   nr_double_t t2 = getPropertyDouble ("T2");
00068   nr_double_t tr = getPropertyDouble ("Tr");
00069   nr_double_t tf = getPropertyDouble ("Tf");
00070   nr_double_t it = 0;
00071   nr_double_t s  = getNet()->getSrcFactor ();
00072 
00073   if (t <= t1) { // before pulse
00074     it = i1;
00075   }
00076   else if (t > t1 && t <= t2) { // rising edge
00077     it = i1 + (i2 - i1) * (1 - std::exp (-(t - t1) / tr));
00078   }
00079   else { // falling edge
00080     it += i1;
00081     it += (i2 - i1) * (1 - std::exp (-(t - t1) / tr));
00082     it -= (i2 - i1) * (1 - std::exp (-(t - t2) / tf));
00083   }
00084   setI (NODE_1, +it * s); setI (NODE_2, -it * s);
00085 }
00086 
00087 // properties
00088 PROP_REQ [] = {
00089   { "I1", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
00090   { "I2", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE },
00091   { "T1", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
00092   { "T2", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
00093   PROP_NO_PROP };
00094 PROP_OPT [] = {
00095   { "Tr", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
00096   { "Tf", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
00097   PROP_NO_PROP };
00098 struct define_t iexp::cirdef =
00099   { "Iexp", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };