viminfo
[gnucap-felix.git] / apps / d_vcvs.cc
blob282b79aa97e4dac1eb71254486d3b8580525bd9b
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)
10 * any later version.
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
20 * 02110-1301, USA.
21 *------------------------------------------------------------------
22 * functions for vcvs
23 * temporary kluge: it has resistance
25 //testing=script,complete 2006.07.17
26 #include "globals.h"
27 #include "e_elemnt.h"
28 /*--------------------------------------------------------------------------*/
29 namespace {
30 /*--------------------------------------------------------------------------*/
31 class DEV_VCVS : public ELEMENT {
32 private:
33 explicit DEV_VCVS(const DEV_VCVS& p) :ELEMENT(p) {}
34 public:
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);}
46 void precalc_last();
47 void tr_iwant_matrix() {tr_iwant_matrix_extended();}
48 void tr_begin();
49 bool do_tr();
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();}
55 void ac_begin();
56 void do_ac();
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 {
61 assert(i >= 0);
62 assert(i < 4);
63 static std::string names[] = {"p", "n", "ps", "ns"};
64 return names[i];
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()
78 ELEMENT::tr_begin();
79 _loss1 = _loss0 = 1./OPT::shortckt;
80 _m0.x = 0.;
81 _m0.c1 = -_loss0 * _y[0].f1;
82 _m0.c0 = 0.;
83 _m1 = _m0;
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);
92 tr_eval();
93 assert(_y[0].f0 != LINEAR);
94 store_values();
95 q_load();
96 _m0 = CPOLY1(_y[0]);
97 _m0 *= -_loss0;
98 }else{
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]);
105 assert(converged());
107 return converged();
109 /*--------------------------------------------------------------------------*/
110 void DEV_VCVS::ac_begin()
112 _loss1 = _loss0 = 1./OPT::shortckt;
113 _ev = _y[0].f1;
114 _acg = -_loss0 * _ev;
116 /*--------------------------------------------------------------------------*/
117 void DEV_VCVS::do_ac()
119 if (using_ac_eval()) {
120 ac_eval();
121 _acg = -_loss0 * _ev;
122 }else{
123 assert(_ev == _y[0].f1);
124 assert(has_tr_eval() || _ev == double(value()));
127 /*--------------------------------------------------------------------------*/
128 /*--------------------------------------------------------------------------*/
129 DEV_VCVS p1;
130 DISPATCHER<CARD>::INSTALL d1(&device_dispatcher, "E|vcvs", &p1);
132 /*--------------------------------------------------------------------------*/
133 /*--------------------------------------------------------------------------*/
134 // vim:ts=8:sw=2:noet: