My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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: vpm.cpp 1825 2011-03-11 20:42:14Z ela $
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 vpm::vpm () : circuit (3) {
33  type = CIR_VPM;
34  setVSource (true);
36 }
37 
38 void vpm::initSP (void) {
39  allocMatrixS ();
40  setS (NODE_1, NODE_2, 1.0);
41  setS (NODE_2, NODE_1, 1.0);
42  setS (NODE_3, NODE_3, 1.0);
43 }
44 
45 void vpm::initDC (void) {
46  allocMatrixMNA ();
48 }
49 
50 void vpm::initAC (void) {
51  initDC ();
52  nr_double_t a = getPropertyDouble ("U");
53  nr_double_t p = getPropertyDouble ("Phase");
54  setE (VSRC_1, polar (a, rad (p)));
55 }
56 
57 void vpm::initTR (void) {
58  initDC ();
59 }
60 
61 void vpm::calcTR (nr_double_t t) {
62  nr_double_t f = getPropertyDouble ("f");
63  nr_double_t p = getPropertyDouble ("Phase");
64  nr_double_t d = getPropertyDouble ("M") * 2 * M_PI;
65  nr_double_t a = getPropertyDouble ("U");
66  nr_double_t v = real (getV (NODE_3));
67  nr_double_t b = 2 * M_PI * f * t + rad (p) + v * d;
68  nr_double_t u = a * sin (b);
69  nr_double_t g = a * cos (b) * d;
70  setE (VSRC_1, g * v - u);
71  setC (VSRC_1, NODE_3, g);
72 }
73 
74 // properties
75 PROP_REQ [] = {
76  { "U", PROP_REAL, { 1, PROP_NO_STR }, PROP_NO_RANGE },
77  { "f", PROP_REAL, { 1e9, PROP_NO_STR }, PROP_POS_RANGE },
78  { "M", PROP_REAL, { 1, PROP_NO_STR }, PROP_RNGII (0, 1) },
79  PROP_NO_PROP };
80 PROP_OPT [] = {
81  { "Phase", PROP_REAL, { 0, PROP_NO_STR }, PROP_RNGII (-360, 360) },
82  PROP_NO_PROP };
83 struct define_t vpm::cirdef =