1 /*$Id: d_vcvs.cc,v 26.137 2010/04/10 02:37:05 al Exp $ -*- C++ -*-
2 * Copyright (C) 2001 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
7 * This program 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 3, or (at your option)
12 * This program 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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 *------------------------------------------------------------------
23 * temporary kluge: it has resistance
25 //testing=script,complete 2006.07.17
28 /*--------------------------------------------------------------------------*/
30 /*--------------------------------------------------------------------------*/
31 class DEV_VCVS
: public ELEMENT
{
33 explicit DEV_VCVS(const DEV_VCVS
& p
) :ELEMENT(p
) {}
35 explicit DEV_VCVS() :ELEMENT() {}
36 private: // override virtual
37 char id_letter()const {return 'E';}
38 std::string
value_name()const {return "gain";}
39 std::string
dev_type()const {return "vcvs";}
40 int max_nodes()const {return 4;}
41 int min_nodes()const {return 4;}
42 int matrix_nodes()const {return 4;}
43 int net_nodes()const {return 4;}
44 bool use_obsolete_callback_parse()const {return true;}
45 CARD
* clone()const {return new DEV_VCVS(*this);}
47 void tr_iwant_matrix() {tr_iwant_matrix_extended();}
50 void tr_load() {tr_load_shunt(); tr_load_active();}
51 void tr_unload() {untested();tr_unload_active();}
52 double tr_involts()const {return dn_diff(_n
[IN1
].v0(), _n
[IN2
].v0());}
53 double tr_involts_limited()const {return volts_limited(_n
[IN1
],_n
[IN2
]);}
54 void ac_iwant_matrix() {ac_iwant_matrix_extended();}
57 void ac_load() {ac_load_shunt(); ac_load_active();}
58 COMPLEX
ac_involts()const {return _n
[IN1
]->vac() - _n
[IN2
]->vac();}
60 std::string
port_name(int i
)const {
63 static std::string names
[] = {"p", "n", "ps", "ns"};
67 /*--------------------------------------------------------------------------*/
68 /*--------------------------------------------------------------------------*/
69 void DEV_VCVS::precalc_last()
71 ELEMENT::precalc_last();
72 set_constant(!has_tr_eval());
73 set_converged(!has_tr_eval());
75 /*--------------------------------------------------------------------------*/
76 void DEV_VCVS::tr_begin()
79 _loss1
= _loss0
= 1./OPT::shortckt
;
81 _m0
.c1
= -_loss0
* _y
[0].f1
;
85 /*--------------------------------------------------------------------------*/
86 bool DEV_VCVS::do_tr()
88 if (using_tr_eval()) {
89 _y
[0].x
= _m0
.x
= tr_involts_limited();
90 //_y[0].x = tr_input_limited();
91 //assert(_y[0].x == _m0.x);
93 assert(_y
[0].f0
!= LINEAR
);
99 assert(conchk(_loss0
, 1./OPT::shortckt
));
100 assert(_y
[0].f0
== LINEAR
);
101 assert(_y
[0].f1
== value());
102 assert(conchk(_m0
.c1
, -_loss0
* _y
[0].f1
));
103 assert(_m0
.c0
== 0.);
104 assert(_y1
== _y
[0]);
109 /*--------------------------------------------------------------------------*/
110 void DEV_VCVS::ac_begin()
112 _loss1
= _loss0
= 1./OPT::shortckt
;
114 _acg
= -_loss0
* _ev
;
116 /*--------------------------------------------------------------------------*/
117 void DEV_VCVS::do_ac()
119 if (using_ac_eval()) {
121 _acg
= -_loss0
* _ev
;
123 assert(_ev
== _y
[0].f1
);
124 assert(has_tr_eval() || _ev
== double(value()));
127 /*--------------------------------------------------------------------------*/
128 /*--------------------------------------------------------------------------*/
130 DISPATCHER
<CARD
>::INSTALL
d1(&device_dispatcher
, "E|vcvs", &p1
);
132 /*--------------------------------------------------------------------------*/
133 /*--------------------------------------------------------------------------*/
134 // vim:ts=8:sw=2:noet: