/*$Id: d_cs.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 fixed current source * x = 0, y.f0 = nothing, ev = y.f1 = amps. */ //testing=script 2006.07.17 #include "l_dispatcher.h" #include "e_elemnt.h" extern DISPATCHER device_dispatcher; /*--------------------------------------------------------------------------*/ namespace { /*--------------------------------------------------------------------------*/ class DEV_CS : public ELEMENT { private: explicit DEV_CS(const DEV_CS& p) :ELEMENT(p) {} public: explicit DEV_CS() :ELEMENT() {} private: // override virtual char id_letter()const {return 'I';} const char* dev_type()const {return "isource";} int max_nodes()const {return 2;} int min_nodes()const {return 2;} int out_nodes()const {untested();return 2;} int matrix_nodes()const {return 2;} int net_nodes()const {return 2;} bool is_source()const {return true;} bool f_is_value()const {return true;} CARD* clone()const {return new DEV_CS(*this);} //void parse_spice(CS&); //ELEMENT //void print(OMSTREAM,LANGUAGE)const; //ELEMENT //void elabo1(); //COMPONENT //void map_nodes(); //ELEMENT void precalc(); void tr_iwant_matrix() {/* nothing */} void dc_begin(); void tr_begin() {dc_begin();} void tr_restore() {dc_begin();} //void dc_advance(); //CARD/nothing //void tr_advance(); //CARD/nothing //bool tr_needs_eval(); //ELEMENT //void tr_queue_eval(); //ELEMENT bool do_tr(); void tr_load() {tr_load_source();} //DPAIR tr_review(); //CARD/nothing //void tr_accept(); //CARD/nothing void tr_unload() {untested();tr_unload_source();} double tr_involts()const {return 0.;} //double tr_input()const //ELEMENT double tr_involts_limited()const {unreachable(); return 0.;} //double tr_input_limited()const //ELEMENT //double tr_amps()const //ELEMENT //double tr_probe_num(CS&)const;//ELEMENT void ac_iwant_matrix() {/* nothing */} void ac_begin() {_acg = _ev = 0.;} void do_ac(); void ac_load() {ac_load_source();} COMPLEX ac_involts()const {untested();return 0.;} COMPLEX ac_amps()const {return _acg;} //XPROBE ac_probe_ext(CS&)const;//ELEMENT }; /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/ void DEV_CS::precalc() { assert(_loss0 == 0.); assert(_loss1 == 0.); _y0.x = 0.; _y0.f0 = 0.; _y0.f1 = value(); _y1 = _y0; _m0.x = 0.; _m0.c0 = _y0.f1; _m0.c1 = 0.; _m1 = _m0; set_constant(!has_tr_eval()); set_converged(!has_tr_eval()); } /*--------------------------------------------------------------------------*/ void DEV_CS::dc_begin() { if (!using_tr_eval()) {untested(); assert(_loss0 == 0.); assert(_loss1 == 0.); assert(_y0.x == 0.); assert(_y0.f0 == 0.); assert(_y0.f1 == value()); assert(_m0.x == 0.); assert(_m0.c0 == _y0.f1); assert(_m0.c1 == 0.); assert(_m1 == _m0); }else{ } } /*--------------------------------------------------------------------------*/ bool DEV_CS::do_tr() { assert(_m0.x == 0.); if (using_tr_eval()) { _y0.x = SIM::time0; tr_eval(); store_values(); q_load(); _m0.c0 = _y0.f1; assert(_m0.c1 == 0.); }else{untested(); assert(_y0.x == 0.); assert(_y0.f0 == 0.); assert(_y0.f1 == value()); assert(_m0.x == 0.); assert(_m0.c0 == _y0.f1); assert(_m0.c1 == 0.); assert(_y1 == _y0); assert(converged()); } return converged(); } /*--------------------------------------------------------------------------*/ void DEV_CS::do_ac() { if (using_ac_eval()) { ac_eval(); _acg = _ev; }else{untested(); assert(_acg == 0.); } ac_load(); } /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/ DEV_CS p1; DISPATCHER::INSTALL d1(&device_dispatcher, "I,csource,isource", &p1); } /*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/