Qucs-core
0.0.19
|
00001 /* 00002 * vexp.cpp - exponential voltage 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 "vexp.h" 00032 00033 using namespace qucs; 00034 00035 vexp::vexp () : circuit (2) { 00036 type = CIR_VEXP; 00037 setVSource (true); 00038 setVoltageSources (1); 00039 } 00040 00041 void vexp::initSP (void) { 00042 allocMatrixS (); 00043 setS (NODE_1, NODE_1, 0.0); 00044 setS (NODE_1, NODE_2, 1.0); 00045 setS (NODE_2, NODE_1, 1.0); 00046 setS (NODE_2, NODE_2, 0.0); 00047 } 00048 00049 void vexp::initDC (void) { 00050 allocMatrixMNA (); 00051 voltageSource (VSRC_1, NODE_1, NODE_2); 00052 setE (VSRC_1, getPropertyDouble ("U1")); 00053 } 00054 00055 void vexp::initAC (void) { 00056 initDC (); 00057 setE (VSRC_1, 0); 00058 } 00059 00060 void vexp::initTR (void) { 00061 initDC (); 00062 } 00063 00064 void vexp::calcTR (nr_double_t t) { 00065 nr_double_t u1 = getPropertyDouble ("U1"); 00066 nr_double_t u2 = getPropertyDouble ("U2"); 00067 nr_double_t t1 = getPropertyDouble ("T1"); 00068 nr_double_t t2 = getPropertyDouble ("T2"); 00069 nr_double_t tr = getPropertyDouble ("Tr"); 00070 nr_double_t tf = getPropertyDouble ("Tf"); 00071 nr_double_t ut = 0; 00072 nr_double_t s = getNet()->getSrcFactor (); 00073 00074 if (t <= t1) { // before pulse 00075 ut = u1; 00076 } 00077 else if (t > t1 && t <= t2) { // rising edge 00078 ut = u1 + (u2 - u1) * (1 - std::exp (-(t - t1) / tr)); 00079 } 00080 else { // falling edge 00081 ut += u1; 00082 ut += (u2 - u1) * (1 - std::exp (-(t - t1) / tr)); 00083 ut -= (u2 - u1) * (1 - std::exp (-(t - t2) / tf)); 00084 } 00085 setE (VSRC_1, ut * s); 00086 } 00087 00088 // properties 00089 PROP_REQ [] = { 00090 { "U1", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE }, 00091 { "U2", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE }, 00092 { "T1", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE }, 00093 { "T2", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE }, 00094 PROP_NO_PROP }; 00095 PROP_OPT [] = { 00096 { "Tr", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE }, 00097 { "Tf", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE }, 00098 PROP_NO_PROP }; 00099 struct define_t vexp::cirdef = 00100 { "Vexp", 2, PROP_COMPONENT, PROP_NO_SUBSTRATE, PROP_LINEAR, PROP_DEF };