/*$Id: d_ccvs.cc,v 26.14 2007/02/07 09:06:48 al Exp $ -*- C++ -*- * Copyright (C) 2001 Albert Davis * Author: Albert Davis * * This file is part of "Gnucap", the Gnu Circuit Analysis Package * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. *------------------------------------------------------------------ * functions for ccvs * It is really voltage controlled, taking into account the sense element. * Then adjust the gain to account for the sense element. */ //testing=script 2006.07.17 #include "l_dispatcher.h" #include "e_ccsrc.h" extern DISPATCHER device_dispatcher; /*--------------------------------------------------------------------------*/ namespace { /*--------------------------------------------------------------------------*/ class DEV_CCVS : public CCSRC_BASE { private: explicit DEV_CCVS(const DEV_CCVS& p) :CCSRC_BASE(p) {} public: explicit DEV_CCVS() :CCSRC_BASE() {} private: // override virtual char id_letter()const {return 'H';} const char* dev_type()const {return "ccvs";} //int max_nodes()const //CCSRC_BASE=4 //int num_nodes()const //CCSRC_BASE=4 //int min_nodes()const //CCSRC_BASE=4 //int out_nodes()const //CCSRC_BASE=2 //int matrix_nodes()const //CCSRC_BASE=4 //int net_nodes()const //CCSRC_BASE=2 CARD* clone()const {return new DEV_CCVS(*this);} //void parse_spice(CS&); //ELEMENT //void print(OMSTREAM,LANGUAGE)const; //CCSRC_BASE //void elabo1(); //CCSRC_BASE //void map_nodes(); //ELEMENT void precalc(); void tr_iwant_matrix() {tr_iwant_matrix_extended();} void dc_begin(); void tr_begin() {dc_begin();} void tr_restore() {untested();dc_begin();} //void dc_advance(); //CARD/nothing //void tr_advance(); //CARD/nothing //bool tr_needs_eval(); //CCSRC_BASE //void tr_queue_eval(); //ELEMENT bool do_tr(); void tr_load() {tr_load_loss(); tr_load_active();} //DPAIR tr_review(); //CARD/nothing //void tr_accept(); //CARD/nothing //void tr_unload(); //CCSRC_BASE //double tr_involts()const; //CCSRC_BASE //double tr_input()const //CCSRC_BASE //double tr_involts_limited()const; //CCSRC_BASE //double tr_input_limited()const //CCSRC_BASE //double tr_amps()const //ELEMENT //double tr_probe_num(CS&)const;//ELEMENT void ac_iwant_matrix() {ac_iwant_matrix_extended();} void ac_begin() {_loss1=_loss0=1./OPT::shortckt; _ev = _y0.f1;} void do_ac(); void ac_load() {unreachable(); incomplete(); /*fake*/} //COMPLEX ac_involts()const; //CCSRC_BASE COMPLEX ac_amps()const {untested(); return ELEMENT::ac_amps();} //XPROBE ac_probe_ext(CS&)const;//ELEMENT }; /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/ void DEV_CCVS::precalc() { _loss1 = _loss0 = 1./OPT::shortckt; _y0.f0 = LINEAR; _y0.f1 = value(); _m0.c1 = -_loss0 * value(); _m0.c0 = 0.; _m1 = _m0; set_converged(); assert(!is_constant()); /* because of incomplete analysis */ } /*--------------------------------------------------------------------------*/ void DEV_CCVS::dc_begin() { _loss1 = _loss0 = 1./OPT::shortckt; if (!using_tr_eval()) { assert(_y0.f0 == LINEAR); assert(_y0.f1 == value()); } } /*--------------------------------------------------------------------------*/ bool DEV_CCVS::do_tr() { assert(_input); if (using_tr_eval()) { _m0.x = tr_involts_limited(); _y0.x = tr_input_limited(); tr_eval(); _m0.c0 = _y0.f0 - _y0.x * _y0.f1; }else{ assert(_y0.f0 == LINEAR); assert(_y0.f1 == value()); _m0.c0 = 0.; assert(converged()); } _m0.c0 += _y0.f1 * _input->_m0.c0; _m0.c1 = _y0.f1 * (_input->_loss0 + _input->_m0.c1); _m0 *= -_loss0; store_values(); q_load(); return converged(); } /*--------------------------------------------------------------------------*/ void DEV_CCVS::do_ac() { assert(_input); if (!_input->evaluated()) {untested(); ELEMENT* input = const_cast(_input); input->do_ac(); //BUG// premature load of sense element } ac_load_loss(); if (using_ac_eval()) {untested(); ac_eval(); }else{ assert(_ev == _y0.f1); assert(has_tr_eval() || _ev == double(value())); } if (_input->is_source()) { _acg = -_loss0 * _ev * _input->_acg; ac_load_source(); _acg = -_loss0 * _ev * _input->_loss0; }else{ _acg = -_loss0 * _ev * _input->_acg; } ac_load_active(); } /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/ DEV_CCVS p1; DISPATCHER::INSTALL d1(&device_dispatcher, "H,ccvs", &p1); } /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/