Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
digisource.cpp
Go to the documentation of this file.
1 /*
2  * digisource.cpp - digital source class implementation
3  *
4  * Copyright (C) 2005, 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 
25 #if HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include "component.h"
30 #include "digisource.h"
31 
32 using namespace qucs;
33 
34 digisource::digisource () : circuit (1) {
36  setVSource (true);
37  setVoltageSources (1);
38 }
39 
40 void digisource::initSP (void) {
41  allocMatrixS ();
42  setS (NODE_1, NODE_1, -1.0);
43 }
44 
45 void digisource::initDC (void) {
46  char * init = getPropertyString ("init");
47  nr_double_t v = getPropertyDouble ("V");
48  bool lo = !strcmp (init, "low");
49  allocMatrixMNA ();
50  setC (VSRC_1, NODE_1, 1.0);
51  setB (NODE_1, VSRC_1, 1.0);
52  setD (VSRC_1, VSRC_1, 0.0);
53  setE (VSRC_1, lo ? 0 : v);
54 }
55 
56 void digisource::initAC (void) {
57  initDC ();
58  setE (VSRC_1, 0);
59 }
60 
61 void digisource::initTR (void) {
62  qucs::vector * values = getPropertyVector ("times");
63  T = real (sum (*values));
64  initDC ();
65 }
66 
67 void digisource::calcTR (nr_double_t t) {
68  char * init = getPropertyString ("init");
69  nr_double_t v = getPropertyDouble ("V");
70  qucs::vector * values = getPropertyVector ("times");
71  bool lo = !strcmp (init, "low");
72  nr_double_t ti = 0;
73 
74  t = t - T * qucs::floor (t / T);
75  for (int i = 0; i < values->getSize (); i++) {
76  ti += real (values->get (i));
77  if (t >= ti) lo = !lo; else break;
78  }
79 
80  setE (VSRC_1, lo ? 0 : v);
81 }
82 
83 // properties
84 PROP_REQ [] = {
85  { "init", PROP_STR, { PROP_NO_VAL, "low" }, PROP_RNG_STR2 ("low", "high") },
86  { "times", PROP_LIST, { 1e-9, PROP_NO_STR }, PROP_POS_RANGE },
87  PROP_NO_PROP };
88 PROP_OPT [] = {
89  { "V", PROP_REAL, { 1, PROP_NO_STR }, PROP_POS_RANGE }, PROP_NO_PROP };
90 struct define_t digisource::cirdef =
91  { "DigiSource",
#define PROP_POS_RANGE
Definition: netdefs.h:129
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
int getSize(void) const
Definition: vector.cpp:192
#define PROP_DEF
Definition: netdefs.h:189
#define PROP_RNG_STR2(s1, s2)
Definition: netdefs.h:145
PROP_OPT[]
Definition: acsolver.cpp:232
#define PROP_REAL
Definition: netdefs.h:174
nr_complex_t sum(vector)
Definition: vector.cpp:251
t
Definition: parse_vcd.y:290
#define PROP_NO_PROP
Definition: netdefs.h:122
#define PROP_NO_STR
Definition: netdefs.h:125
#define PROP_LINEAR
Definition: netdefs.h:120
#define VSRC_1
Definition: circuit.h:40
i
Definition: parse_mdl.y:516
#define PROP_COMPONENT
Definition: netdefs.h:116
void initAC(void)
Definition: digisource.cpp:56
nr_complex_t floor(const nr_complex_t z)
Complex floor.
Definition: complex.cpp:623
void calcTR(nr_double_t)
Definition: digisource.cpp:67
void initTR(void)
Definition: digisource.cpp:61
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: digisource.cpp:40
type
Definition: parse_vcd.y:164
v
Definition: parse_zvr.y:141
#define PROP_STR
Definition: netdefs.h:175
#define NODE_1
Definition: circuit.h:34
void initDC(void)
Definition: digisource.cpp:45
#define PROP_NO_VAL
Definition: netdefs.h:124
#define PROP_LIST
Definition: netdefs.h:176
values
Definition: parse_spice.y:223
PROP_REQ[]
Definition: acsolver.cpp:229
nr_complex_t get(int)
Definition: vector.cpp:179