Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vexp.cpp
Go to the documentation of this file.
1 /*
2  * vexp.cpp - exponential voltage source class implementation
3  *
4  * Copyright (C) 2007, 2008 Stefan Jahn <stefan@lkcc.org>
5  * Copyright (C) 2007 Gunther Kraut <gn.kraut@t-online.de>
6  *
7  * This is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this package; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  * $Id$
23  *
24  */
25 
26 #if HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29 
30 #include "component.h"
31 #include "vexp.h"
32 
33 using namespace qucs;
34 
35 vexp::vexp () : circuit (2) {
36  type = CIR_VEXP;
37  setVSource (true);
38  setVoltageSources (1);
39 }
40 
41 void vexp::initSP (void) {
42  allocMatrixS ();
43  setS (NODE_1, NODE_1, 0.0);
44  setS (NODE_1, NODE_2, 1.0);
45  setS (NODE_2, NODE_1, 1.0);
46  setS (NODE_2, NODE_2, 0.0);
47 }
48 
49 void vexp::initDC (void) {
50  allocMatrixMNA ();
51  voltageSource (VSRC_1, NODE_1, NODE_2);
52  setE (VSRC_1, getPropertyDouble ("U1"));
53 }
54 
55 void vexp::initAC (void) {
56  initDC ();
57  setE (VSRC_1, 0);
58 }
59 
60 void vexp::initTR (void) {
61  initDC ();
62 }
63 
64 void vexp::calcTR (nr_double_t t) {
65  nr_double_t u1 = getPropertyDouble ("U1");
66  nr_double_t u2 = getPropertyDouble ("U2");
67  nr_double_t t1 = getPropertyDouble ("T1");
68  nr_double_t t2 = getPropertyDouble ("T2");
69  nr_double_t tr = getPropertyDouble ("Tr");
70  nr_double_t tf = getPropertyDouble ("Tf");
71  nr_double_t ut = 0;
72  nr_double_t s = getNet()->getSrcFactor ();
73 
74  if (t <= t1) { // before pulse
75  ut = u1;
76  }
77  else if (t > t1 && t <= t2) { // rising edge
78  ut = u1 + (u2 - u1) * (1 - std::exp (-(t - t1) / tr));
79  }
80  else { // falling edge
81  ut += u1;
82  ut += (u2 - u1) * (1 - std::exp (-(t - t1) / tr));
83  ut -= (u2 - u1) * (1 - std::exp (-(t - t2) / tf));
84  }
85  setE (VSRC_1, ut * s);
86 }
87 
88 // properties
89 PROP_REQ [] = {
90  { "U1", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
91  { "U2", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE },
92  { "T1", PROP_REAL, { 0, PROP_NO_STR }, PROP_POS_RANGE },
93  { "T2", PROP_REAL, { 1e-3, PROP_NO_STR }, PROP_POS_RANGE },
94  PROP_NO_PROP };
95 PROP_OPT [] = {
96  { "Tr", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
97  { "Tf", PROP_REAL, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
98  PROP_NO_PROP };
99 struct define_t vexp::cirdef =
#define PROP_POS_RANGE
Definition: netdefs.h:129
#define NODE_2
Definition: circuit.h:35
#define PROP_DEF
Definition: netdefs.h:189
PROP_OPT[]
Definition: acsolver.cpp:232
#define PROP_REAL
Definition: netdefs.h:174
void initAC(void)
Definition: vexp.cpp:55
t
Definition: parse_vcd.y:290
#define PROP_NO_PROP
Definition: netdefs.h:122
#define PROP_NO_RANGE
Definition: netdefs.h:126
void initDC(void)
Definition: vexp.cpp:49
#define PROP_NO_STR
Definition: netdefs.h:125
#define PROP_LINEAR
Definition: netdefs.h:120
#define VSRC_1
Definition: circuit.h:40
#define PROP_COMPONENT
Definition: netdefs.h:116
void calcTR(nr_double_t)
Definition: vexp.cpp:64
void initTR(void)
Definition: vexp.cpp:60
type
Definition: parse_vcd.y:164
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: vexp.cpp:41
#define NODE_1
Definition: circuit.h:34
nr_complex_t exp(const nr_complex_t z)
Compute complex exponential.
Definition: complex.cpp:205
PROP_REQ[]
Definition: acsolver.cpp:229
Definition: vexp.cpp:99
#define PROP_NO_SUBSTRATE
Definition: netdefs.h:118