Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vpm.cpp
Go to the documentation of this file.
1 /*
2  * vpm.cpp - PM modulated AC voltage source class implementation
3  *
4  * Copyright (C) 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 
25 #if HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include "component.h"
30 #include "vpm.h"
31 
32 using namespace qucs;
33 
34 vpm::vpm () : circuit (3) {
35  type = CIR_VPM;
36  setVSource (true);
38 }
39 
40 void vpm::initSP (void) {
41  allocMatrixS ();
42  setS (NODE_1, NODE_2, 1.0);
43  setS (NODE_2, NODE_1, 1.0);
44  setS (NODE_3, NODE_3, 1.0);
45 }
46 
47 void vpm::initDC (void) {
48  allocMatrixMNA ();
50 }
51 
52 void vpm::initAC (void) {
53  initDC ();
54  nr_double_t a = getPropertyDouble ("U");
55  nr_double_t p = getPropertyDouble ("Phase");
56  setE (VSRC_1, qucs::polar (a, rad (p)));
57 }
58 
59 void vpm::initTR (void) {
60  initDC ();
61 }
62 
63 void vpm::calcTR (nr_double_t t) {
64  nr_double_t f = getPropertyDouble ("f");
65  nr_double_t p = getPropertyDouble ("Phase");
66  nr_double_t d = getPropertyDouble ("M") * 2 * M_PI;
67  nr_double_t a = getPropertyDouble ("U");
68  nr_double_t v = real (getV (NODE_3));
69  nr_double_t b = 2 * M_PI * f * t + rad (p) + v * d;
70  nr_double_t u = a * std::sin (b);
71  nr_double_t g = a * std::cos (b) * d;
72  setE (VSRC_1, g * v - u);
73  setC (VSRC_1, NODE_3, g);
74 }
75 
76 // properties
77 PROP_REQ [] = {
78  { "U", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE },
79  { "f", PROP_REAL, { 1e9, PROP_NO_STR }, PROP_POS_RANGE },
80  { "M", PROP_REAL, { 1, PROP_NO_STR }, PROP_RNGII (0, 1) },
81  PROP_NO_PROP };
82 PROP_OPT [] = {
83  { "Phase", PROP_REAL, { 0, PROP_NO_STR }, PROP_RNGII (-360, 360) },
84  PROP_NO_PROP };
85 struct define_t vpm::cirdef =
Definition: vpm.cpp:85
#define PROP_POS_RANGE
Definition: netdefs.h:129
#define NODE_2
Definition: circuit.h:35
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
#define PROP_RNGII(f, t)
Definition: netdefs.h:138
#define PROP_DEF
Definition: netdefs.h:189
PROP_NO_SUBSTRATE
Definition: vpm.cpp:86
nr_double_t getPropertyDouble(const char *)
Definition: object.cpp:176
nr_complex_t cos(const nr_complex_t z)
Compute complex cosine.
Definition: complex.cpp:57
#define PROP_REAL
Definition: netdefs.h:174
t
Definition: parse_vcd.y:290
void calcTR(nr_double_t)
Definition: vpm.cpp:63
#define PROP_NO_PROP
Definition: netdefs.h:122
void setVoltageSources(int)
Definition: circuit.cpp:607
#define PROP_NO_RANGE
Definition: netdefs.h:126
#define PROP_NO_STR
Definition: netdefs.h:125
PROP_OPT[]
Definition: vpm.cpp:82
void allocMatrixS(void)
Definition: circuit.cpp:251
void initDC(void)
Definition: vpm.cpp:47
#define PROP_LINEAR
Definition: netdefs.h:120
#define VSRC_1
Definition: circuit.h:40
void initSP(void)
placehoder for S-Parameter initialisation function
Definition: vpm.cpp:40
nr_complex_t sin(const nr_complex_t z)
Compute complex sine.
Definition: complex.cpp:66
PROP_REQ[]
Definition: vpm.cpp:77
#define PROP_COMPONENT
Definition: netdefs.h:116
void setE(int, nr_complex_t)
Definition: circuit.cpp:385
void setVSource(bool v)
Definition: circuit.h:192
#define NODE_3
Definition: circuit.h:36
#define M_PI
Archimedes' constant ( )
Definition: consts.h:47
#define rad(x)
Convert degree to radian.
Definition: constants.h:118
v
Definition: parse_zvr.y:141
void allocMatrixMNA(void)
Definition: circuit.cpp:267
nr_double_t getV(int, nr_double_t)
Definition: circuit.cpp:941
#define NODE_1
Definition: circuit.h:34
void voltageSource(int, int, int, nr_double_t value=0.0)
Definition: circuit.cpp:748
void initTR(void)
Definition: vpm.cpp:59
void setS(int, int, nr_complex_t)
Definition: circuit.cpp:587
nr_complex_t polar(const nr_double_t mag, const nr_double_t ang)
Construct a complex number using polar notation.
Definition: complex.cpp:551
void setC(int, int, nr_complex_t)
Definition: circuit.cpp:361
void initAC(void)
Definition: vpm.cpp:52