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)
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 *------------------------------------------------------------------
22 * functions for fixed voltage sources
23 * temporary kluge: it has resistance
25 //testing=script 2006.07.17
28 /*--------------------------------------------------------------------------*/
30 /*--------------------------------------------------------------------------*/
31 class DEV_VS
: public ELEMENT
{
33 explicit DEV_VS(const DEV_VS
& p
) :ELEMENT(p
) {}
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);}
50 void tr_iwant_matrix() {tr_iwant_matrix_passive();}
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.;}
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 {
67 static std::string names
[] = {"p", "n"};
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()
83 _y1
.f0
= _y
[0].f0
= 0.; // override
84 _loss1
= _loss0
= 1./OPT::shortckt
;
86 _m0
.c0
= -_loss0
* _y
[0].f1
;
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());
95 //BUG// don't set limit
100 /*--------------------------------------------------------------------------*/
104 if (using_tr_eval()) {
105 _y
[0].x
= _sim
->_time0
;
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
);
112 //BUG// don't set limit
116 _m0
.c0
= -_loss0
* _y
[0].f1
;
117 assert(_m0
.c1
== 0.);
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());
124 assert(conchk(_m0
.c0
, -_loss0
* _y
[0].f1
));
125 assert(_m0
.c1
== 0.);
126 assert(_y1
== _y
[0]);
131 /*--------------------------------------------------------------------------*/
134 if (using_ac_eval()) {
136 _acg
= -_loss0
* _ev
;
141 /*--------------------------------------------------------------------------*/
142 /*--------------------------------------------------------------------------*/
144 DISPATCHER
<CARD
>::INSTALL
d1(&device_dispatcher
, "V|vsource", &p1
);
146 /*--------------------------------------------------------------------------*/
147 /*--------------------------------------------------------------------------*/
148 // vim:ts=8:sw=2:noet: