1 /*$Id: s_tr.h,v 26.131 2009/11/20 08:22:10 al Exp $ -*- C++ -*- 2 * Copyright (C) 2001 Albert Davis 3 * Author: Albert Davis <aldavis@gnu.org> 4 * 5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package 6 * 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. 11 * 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. 16 * 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 * Transient analysis 23 */ 24 //testing=script,complete 2006.07.14 25 #ifndef S_TR_H 26 #define S_TR_H 27 #include "u_parameter.h" 28 #include "s__.h" 29 /*--------------------------------------------------------------------------*/ 30 class TRANSIENT : public SIM { 31 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 32 protected: 33 enum STEP_CAUSE { 34 scUSER = 1, /* user requested */ 35 scEVENTQ = 2, /* an "event" from the queue */ 36 scSKIP = 3, /* effect of "skip" parameter */ 37 scITER_R = 4, /* iter count exceeds itl4 (reducing) */ 38 scITER_A = 5, /* iter count exceeds itl3 (holding) */ 39 scTE = 6, /* truncation error, or device stuff */ 40 scAMBEVENT = 7, /* ambiguous event */ 41 scADT = 8, /* by iter count limited by max(rdt, 2*adt) */ 42 scINITIAL = 9, /* initial guess */ 43 scREJECT = 10, /* rejected previous time step */ 44 scZERO = 20, /* fixed zero time step */ 45 scSMALL = 30, /* time step too small */ 46 scNO_ADVANCE= 100 /* after all that it still didn't advance */ 47 }; 48 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 49 public: TRANSIENT()50 explicit TRANSIENT(): 51 SIM(), 52 _skip_in(1), 53 _dtmax(0.), 54 _cold(false), 55 _cont(false), 56 _trace(tNONE), 57 _time_by_iteration_count(0.), 58 _time_by_user_request(0.), 59 _time_by_error_estimate(0.), 60 _time_by_ambiguous_event(0.), 61 _converged(false), 62 _accepted(false) 63 { 64 } ~TRANSIENT()65 ~TRANSIENT() {} 66 public: 67 void do_it(CS&, CARD_LIST* scope); 68 std::string status()const; 69 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 70 private: // s_tr_rev.cc 71 bool review(); 72 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 73 private: // s_tr_set.cc 74 void setup(CS&); 75 protected: 76 void options(CS&); 77 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 78 protected: // s_tr_swp.cc 79 void sweep(); 80 private: 81 void set_step_cause(STEP_CAUSE); 82 public: 83 int step_cause()const; 84 void first(); 85 bool next(); 86 void accept(); 87 void reject(); 88 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 89 private: is_step_rejected()90 bool is_step_rejected()const {return (step_cause() > scREJECT);} TRANSIENT(const TRANSIENT &)91 explicit TRANSIENT(const TRANSIENT&): SIM(),_skip_in(1) {unreachable(); incomplete();} 92 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 93 protected: 94 PARAMETER<double> _tstart; // sweep start time 95 PARAMETER<double> _tstop; // sweep stop time 96 PARAMETER<double> _tstep; // printed step size 97 PARAMETER<double> _dtratio_in;// ratio of max/min dt 98 PARAMETER<double> _dtmin_in; // min internal step size 99 PARAMETER<double> _dtmax_in; // max internal step size (user) 100 PARAMETER<int> _skip_in; // fixed step size: internal steps per external 101 double time1; /* time at previous time step */ 102 double _dtmax; // max internal step size (step / _skip) 103 bool _cold; // flag: start time=0, all voltages=0 104 bool _cont; // flag: continue from previous run 105 int _stepno; // count of visible (saved) steps 106 private: 107 TRACE _trace; // enum: show extended diagnostics 108 double _time_by_iteration_count; 109 double _time_by_user_request; 110 double _time_by_error_estimate; 111 double _time_by_ambiguous_event; 112 bool _converged; 113 bool _accepted; 114 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 115 private: 116 static int steps_accepted_; 117 static int steps_rejected_; 118 static int steps_total_; 119 public: steps_accepted()120 static int steps_accepted() {return steps_accepted_;} steps_rejected()121 static int steps_rejected() {return steps_rejected_;} steps_total()122 static int steps_total() {return steps_total_;} 123 }; 124 /*--------------------------------------------------------------------------*/ 125 /*--------------------------------------------------------------------------*/ 126 #endif 127