viminfo
[gnucap-felix.git] / apps / d_vs.cc
blob005f56c5789cdbb34fc18855dcc6b130ea56f894
1 /*$Id: d_vs.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 fixed voltage sources
23 * temporary kluge: it has resistance
25 //testing=script 2006.07.17
26 #include "globals.h"
27 #include "e_elemnt.h"
28 /*--------------------------------------------------------------------------*/
29 namespace {
30 /*--------------------------------------------------------------------------*/
31 class DEV_VS : public ELEMENT {
32 private:
33 explicit DEV_VS(const DEV_VS& p) :ELEMENT(p) {}
34 public:
35 explicit DEV_VS() :ELEMENT() {}
36 private: // override virtual
37 char id_letter()const {return 'V';}
38 std::string value_name()const {return "dc";}
39 std::string dev_type()const {return "vsource";}
40 int max_nodes()const {return 2;}
41 int min_nodes()const {return 2;}
42 int matrix_nodes()const {return 2;}
43 int net_nodes()const {return 2;}
44 bool is_source()const {return true;}
45 bool f_is_value()const {return true;}
46 bool has_iv_probe()const {return true;}
47 bool use_obsolete_callback_parse()const {return true;}
48 CARD* clone()const {return new DEV_VS(*this);}
49 void precalc_last();
50 void tr_iwant_matrix() {tr_iwant_matrix_passive();}
51 void tr_begin();
52 bool do_tr();
53 void tr_load() {tr_load_shunt(); tr_load_source();}
54 void tr_unload() {untested();tr_unload_source();}
55 double tr_involts()const {return 0.;}
56 double tr_involts_limited()const {unreachable(); return 0.;}
57 void ac_iwant_matrix() {ac_iwant_matrix_passive();}
58 void ac_begin() {_loss1 = _loss0 = 1./OPT::shortckt; _acg = _ev = 0.;}
59 void do_ac();
60 void ac_load() {ac_load_shunt(); ac_load_source();}
61 COMPLEX ac_involts()const {return 0.;}
62 COMPLEX ac_amps()const {return (_acg + ac_outvolts()*_loss0);}
64 std::string port_name(int i)const {
65 assert(i >= 0);
66 assert(i < 2);
67 static std::string names[] = {"p", "n"};
68 return names[i];
71 /*--------------------------------------------------------------------------*/
72 /*--------------------------------------------------------------------------*/
73 void DEV_VS::precalc_last()
75 ELEMENT::precalc_last();
76 set_constant(!has_tr_eval());
77 set_converged(!has_tr_eval());
79 /*--------------------------------------------------------------------------*/
80 void DEV_VS::tr_begin()
82 ELEMENT::tr_begin();
83 _y1.f0 = _y[0].f0 = 0.; // override
84 _loss1 = _loss0 = 1./OPT::shortckt;
85 _m0.x = 0.;
86 _m0.c0 = -_loss0 * _y[0].f1;
87 _m0.c1 = 0.;
88 _m1 = _m0;
89 if (!using_tr_eval()) {
90 if (_n[OUT2].m_() == 0) {
91 _sim->set_limit(value());
92 }else if (_n[OUT1].m_() == 0) {untested();
93 _sim->set_limit(-value());
94 }else{untested();
95 //BUG// don't set limit
97 }else{
100 /*--------------------------------------------------------------------------*/
101 bool DEV_VS::do_tr()
103 assert(_m0.x == 0.);
104 if (using_tr_eval()) {
105 _y[0].x = _sim->_time0;
106 tr_eval();
107 if (_n[OUT2].m_() == 0) {
108 _sim->set_limit(_y[0].f1);
109 }else if (_n[OUT1].m_() == 0) {
110 _sim->set_limit(-_y[0].f1);
111 }else{
112 //BUG// don't set limit
114 store_values();
115 q_load();
116 _m0.c0 = -_loss0 * _y[0].f1;
117 assert(_m0.c1 == 0.);
118 }else{itested();
119 assert(conchk(_loss0, 1./OPT::shortckt));
120 assert(_y[0].x == 0.);
121 assert(_y[0].f0 == 0.);
122 assert(_y[0].f1 == value());
123 assert(_m0.x == 0.);
124 assert(conchk(_m0.c0, -_loss0 * _y[0].f1));
125 assert(_m0.c1 == 0.);
126 assert(_y1 == _y[0]);
127 assert(converged());
129 return converged();
131 /*--------------------------------------------------------------------------*/
132 void DEV_VS::do_ac()
134 if (using_ac_eval()) {
135 ac_eval();
136 _acg = -_loss0 * _ev;
137 }else{itested();
138 assert(_acg == 0.);
141 /*--------------------------------------------------------------------------*/
142 /*--------------------------------------------------------------------------*/
143 DEV_VS p1;
144 DISPATCHER<CARD>::INSTALL d1(&device_dispatcher, "V|vsource", &p1);
146 /*--------------------------------------------------------------------------*/
147 /*--------------------------------------------------------------------------*/
148 // vim:ts=8:sw=2:noet: