Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ecvs.cpp
Go to the documentation of this file.
1 /*
2  * ecvs.cpp - ecvs class implementation
3  *
4  * Copyright (C) 2003, 2004, 2006, 2008 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$
22  *
23  */
24 
34 #if HAVE_CONFIG_H
35 # include <config.h>
36 #endif
37 
38 #include "component.h"
39 #include "ecvs.h"
40 
41 using namespace qucs;
42 
43 ecvs::ecvs () : circuit (2) {
44  type = CIR_ECVS;
45  setVSource (true);
46  setVoltageSources (1);
47 }
48 
49 void ecvs::initSP (void) {
50  allocMatrixS ();
51  setS (NODE_1, NODE_1, 0.0);
52  setS (NODE_1, NODE_2, 1.0);
53  setS (NODE_2, NODE_1, 1.0);
54  setS (NODE_2, NODE_2, 0.0);
55 }
56 
57 void ecvs::initDC (void) {
58  allocMatrixMNA ();
59  voltageSource (VSRC_1, NODE_1, NODE_2);
60  setE (VSRC_1, 0);
61 }
62 
63 void ecvs::initAC (void) {
64  initDC ();
65  setE (VSRC_1, 0);
66 }
67 
68 void ecvs::initTR (void) {
69  initDC ();
70  // we need to store a history of time values
71  // for interpolation, initialise the history here
72  deleteHistory ();
73  setHistory (true);
74  initHistory (0);
75 }
76 
77 void ecvs::calcTR (nr_double_t t) {
78  nr_double_t V = 0;
79  nr_double_t y0 = 0;
80  nr_double_t Tlast;
81  int hsize = getHistorySize ();
82  // choose the voltage at the current time by interpolating
83  // at the current time, using the previous values of the
84  // voltage and the value of the voltage at the specified
85  // next time in Tnext
86  nr_double_t y1 = getPropertyDouble ("U");
87  if (hsize < 1)
88  {
89  Tlast = t;
90  y0 = y1;
91  }
92  else
93  {
94  Tlast = getHistoryTFromIndex (hsize-1);
95  y0 = (getV (NODE_1, hsize-1) - getV (NODE_2, hsize-1));
96  }
97  nr_double_t Tnext = getPropertyDouble ("Tnext");
98  // do the interpolation
99  nr_double_t tdiff = t - Tlast;
100  if (tdiff <= 0)
101  {
102  V = y0;
103  }
104  else
105  {
106  V = y0 + (y1 - y0) * (tdiff / (Tnext - Tlast));
107  }
108 #ifdef DEBUG
109  printf ("ECVS -- t: %e, V: %e\n", t, V);
110 #endif
111  // set the voltage source value
112  setE (VSRC_1, V);
113 }
114 
115 // properties
116 PROP_REQ [] = {
117  { "U", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE }, PROP_NO_PROP };
118 PROP_OPT [] = {
119  { "Interpolator", PROP_STR, { PROP_NO_VAL, "linear" },
120  PROP_RNG_STR3 ("hold", "linear", "cubic") },
121  { "Tnext", PROP_REAL, { 0, PROP_NO_STR }, PROP_NO_RANGE },
122  PROP_NO_PROP };
123 struct define_t ecvs::cirdef =
The externally controlled voltage source component implementation file.
#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
t
Definition: parse_vcd.y:290
#define PROP_NO_PROP
Definition: netdefs.h:122
#define PROP_NO_RANGE
Definition: netdefs.h:126
#define PROP_NO_STR
Definition: netdefs.h:125
#define PROP_LINEAR
Definition: netdefs.h:120
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: ecvs.cpp:49
#define VSRC_1
Definition: circuit.h:40
#define PROP_COMPONENT
Definition: netdefs.h:116
#define V(con)
Definition: evaluate.cpp:63
void initAC(void)
Definition: ecvs.cpp:63
void calcTR(nr_double_t)
Definition: ecvs.cpp:77
Definition: ecvs.cpp:123
void initTR(void)
Definition: ecvs.cpp:68
#define PROP_STR
Definition: netdefs.h:175
void initDC(void)
Definition: ecvs.cpp:57
#define NODE_1
Definition: circuit.h:34
#define PROP_NO_VAL
Definition: netdefs.h:124
PROP_NO_SUBSTRATE
Definition: ecvs.cpp:124
PROP_REQ[]
Definition: acsolver.cpp:229
#define PROP_RNG_STR3(s1, s2, s3)
Definition: netdefs.h:147