interactive testing
[gnucap-felix.git] / src / e_adp.h
blobf017ac5a521d037a8007904ac90bfa9325d00f39
1 // vim:ts=8:sw=2:et:
2 #ifndef U_ADP_H
3 #define U_ADP_H
4 #include "s__.h"
5 #include "e_compon.h"
6 #include "e_node.h"
7 #include "u_time_pair.h"
8 #include "io_trace.h"
10 typedef int adp_region_t;
11 #define E_max 1.0001
12 #define E_min -0.0001
13 #define U_min -0.0001
14 #define U_max 1e5
16 /*--------------------------------------------------------------------------*/
17 class ADP_NODE_LIST;
18 class ADP_LIST;
19 class ADP_CARD;
20 class COMPONENT;
21 /*--------------------------------------------------------------------------*/
22 // collects transient (stress) data, sometimes extrapolates.
23 class ADP_NODE: public NODE_BASE { //
24 private:
25 friend class NODE_MAP;
26 explicit ADP_NODE( string name, const COMPONENT* owner );// don't use
27 explicit ADP_NODE( string name, const CARD_LIST* scope );// new one
28 public:
29 ~ADP_NODE( );
30 ADP_NODE( const ADP_NODE& );
31 void set_owner(const CARD* x){_owner=x;}
32 private:
33 // unsigned _number;
34 // unsigned _matrix_number;
35 protected:
36 void init( const COMPONENT* , std::string name_in2 );//
38 public:
39 std::string label() const {return long_label();}
40 uint_t order() const;
42 uint_t m_()const {
43 return _user_number;
46 double tr(double time, const double* tr0=0)const;
47 double tr_rel(double time)const;
49 hp_float_t& tr()const {
50 assert(m_() != INVALID_NODE);
51 assert(m_() < _sim->_adp_nodes);
52 assert (_sim->_tr);
53 return _sim->_tr[m_()];
55 hp_float_t tr1()const {
56 assert(m_() != INVALID_NODE);
57 assert(m_() < _sim->_adp_nodes);
58 assert (_sim->_tr1);
59 assert(this);
60 return _sim->_tr1[m_()];
62 hp_float_t tr2()const {
63 assert(m_() != INVALID_NODE);
64 assert(m_() <= _sim->_adp_nodes);
65 return _sim->_tr2[m_()];
67 hp_float_t tr3()const {
68 assert(m_() != INVALID_NODE);
69 assert(m_() <= _sim->_adp_nodes);
70 return _sim->_tr3[m_()];
73 hp_float_t tt1()const {
74 assert(m_() != INVALID_NODE);
75 assert(m_() <= _sim->_adp_nodes);
76 return _sim->_tt1[m_()];
78 hp_float_t& tt()const {
79 assert(m_() != INVALID_NODE);
80 assert(m_() < _sim->_adp_nodes);
81 assert (_sim->_tt);
82 return _sim->_tt[m_()];
84 //double TR2; //depr.
85 double* derivatives(double* c);
87 protected:
88 int dbg;
90 // history needs cleanup.
91 hp_float_t _delta_expect;
92 hp_float_t tr_value;
93 double tr_noise;
94 float tr_rel_low;
95 float tr_rel_high;
96 hp_float_t tr_value2, tr_dd12;
97 hp_float_t tr_value3, tr_dd23, tr_dd123;
98 hp_float_t tt_expect;
99 hp_float_t tt_value;
101 hp_float_t *_val_bef; // replce _val_bef[0] ...
102 hp_float_t *_val_aft;
103 hp_float_t *_der_aft;
104 hp_float_t *_delta;
106 // double tt_value3;
107 double tt_first_time;
108 double tt_first_value;
109 double _Time_delta_old;
110 double _abs_tt_err;
111 double _abs_tr_err;
112 double _rel_tt_err;
113 double _rel_tr_err;
114 double _wdT;
115 bool _positive;
116 double _sign;
119 double Time_delta() const
120 { return ( CKT_BASE::_sim->_dT0 ); }
122 double Time_delta_old()const { return CKT_BASE::_sim->_dT1 ;}
124 // absolute times. don't use!
125 double Time0()const { return ( CKT_BASE::_sim->_Time0 ); }
126 double Time1()const { return ( CKT_BASE::_sim->_Time0-dT0() ); }
127 double Time2()const { return ( CKT_BASE::_sim->_Time0-dT0()-dT1() ); }
128 double Time3()const { return Time2()-dT2(); }
130 double dT0()const { return ( CKT_BASE::_sim->_dT0 ); }
131 double dT1()const { return ( CKT_BASE::_sim->_dT1 ); }
132 double dT2()const { return ( CKT_BASE::_sim->_dT2 ); }
134 void tr_expect_();
135 virtual void tr_expect_1(){ tr_expect_1_const(); }
136 void tr_expect_1_const();
137 void tr_expect_1_exp();
139 virtual void tr_expect_2(){ tr_expect_2_linear(); }
140 void tr_expect_2_exp();
141 void tr_expect_2_linear();
142 void tr_expect_2_avg();
143 void tr_expect_2_square();
144 void tr_expect_2_something();
146 virtual void tr_expect_3(){ tr_expect_3_quadratic(); }
147 void tr_expect_3_quadratic();
148 void tr_expect_3_linear();
149 void tr_expect_3_something();
150 void tr_expect_3_exp();
151 void tr_expect_3_exp_fit();
153 double tt_integrate_( double );
155 virtual double tt_integrate_1( double x ) { return tt_integrate_1_const( x ); }
156 double tt_integrate_1_const( double );
157 double tt_integrate_1_exp( double );
158 double tt_integrate_1_linear( double );
160 virtual double tt_integrate_2( double x ) { return tt_integrate_2_exp( x ); }
161 double tt_integrate_2_exp(double);
162 double tt_integrate_2_exp_different(double);
163 double tt_integrate_2_linear(double);
164 double tt_integrate_2_linear2(double);
166 virtual double tt_integrate_3( double x ) { return tt_integrate_3_exp( x ); }
167 double tt_integrate_3_exp(double);
169 double tr_correct_3_exp( );
170 double tr_correct_2_exp( );
171 double tr_correct_1_exp( );
172 double tr_correct_1_const( );
173 double tr_correct_generic( );
175 hp_float_t _debug;
176 double (ADP_NODE::*_integrator)( double );
177 double (ADP_NODE::*_corrector)( );
178 int _region;
180 public:
181 double tt_integrate_2_poly(double offset=0) const;
182 double tt_integrate_3_poly() const;
183 void apply(); // ?
184 virtual int region() const;
185 virtual std::string type() const {return "basic";}
187 hp_float_t get_total() const;
189 hp_float_t get_tr_noise( ) {return tr_noise;}
192 hp_float_t get_tt( int i ) const {assert(i==1);
193 USE(i);
194 return( tt1() ); }
195 // hp_float_t get_tt() const { return tt(); }
197 hp_float_t get_aft_1()const;
198 hp_float_t tt_get_sum()const {return _val_bef[0] + _delta[0]; }
200 void tr_add( double x ) const;
201 void add_tr( hp_float_t x ) { tr_add(x);}
202 void set_tr( hp_float_t x );
203 void set_tt( hp_float_t x );
205 void set_tr_noise(double x ) {assert(is_number(x)); tr_noise = x;}
206 virtual TIME_PAIR tt_review( );
207 TIME_PAIR tt_preview( );
208 void reset();
209 void reset_tr();
211 //aliases
212 hp_float_t get( ) const { return tt();}
213 hp_float_t tr_get( ) const { return tr();}
214 void tt_set( double x) { set_tt(x);}
215 void tr_set( double x) { set_tr(x);}
216 double tr_get_old(){ return get_tr(1);}
217 hp_float_t get1()const { return tt1(); }
218 hp_float_t get_tr( int i ) const {assert(i==1);
219 USE(i);
220 return( tr1() ); }
221 hp_float_t get_tr( ) const { return tr();}
223 double tr_abs_err()const{ return _abs_tr_err; }
224 double tr_rel_err()const{ return _rel_tr_err; }
225 double tt_abs_err()const{ return _abs_tt_err; }
226 double tt_rel_err()const{ return _rel_tt_err; }
227 double tr_duration()const; //{ return _c->_sim->_last_time; }
228 // double wdT()const{ return _wdT; }
229 void tt_commit();
230 void tr_stress_last( );
231 void tt_reset();
232 void tt_commit_first();
233 void tt_accept_first();
234 void tt_advance();
235 void tt_regress();
236 void tt_last();
238 void tt_accept( );
239 void tt_clear( ) {
240 unreachable();
241 // tr_value = _delta[0] = _delta[1] = tr_value2 = 0;
242 // tt_value = _val_bef[0] = _val_bef[1] = _val_bef[2] = 0;
245 void print()
247 std::cerr << short_label() << ": " << tr_value << "\n";
250 private:
251 uint_t _order; // order used for extrapolation.
252 uint_t _new_order;
253 ADP_CARD* a;
254 void set_order(uint_t x) {_order=x;}
255 public:
256 virtual double debug();
257 void set_new_order(uint_t x) {_new_order=x;}
259 public: // temporary hacks
260 double tr_hi;
261 double tr_lo;
263 double trhack; // might once coincide with _tr. doesnt yet.
265 double State()const;
267 /*--------------------------------------------------------------------------*/
268 inline const ADP_NODE* node_t::a_()const {return dynamic_cast<const ADP_NODE*>(_nnn);}
269 inline ADP_NODE* node_t::a_() {return dynamic_cast<ADP_NODE*>(_nnn);}
270 /*--------------------------------------------------------------------------*/
271 class BTI_ADP : public ADP_NODE {
272 // nonsense ?
274 /*--------------------------------------------------------------------------*/
275 class ADP_NODE_UDC : public ADP_NODE {
276 public:
277 // explicit ADP_NODE_UDC( const COMPONENT* c);
278 // ADP_NODE_UDC( const ADP_NODE_UDC& );
279 // ADP_NODE_UDC( const ADP_NODE& );
281 // double get_udc() const {return udc;}
282 // void set_udc(double x) {udc=x;}
284 void tr_expect_1();
285 void tr_expect_2();
286 void tr_expect_3();
287 virtual std::string type() const {return "rcd";};
288 virtual TIME_PAIR tt_review( );
289 private:
290 double udc;
292 /*--------------------------------------------------------------------------*/
293 class ADP_NODE_RCD : public ADP_NODE {
294 public:
295 // explicit ADP_NODE_RCD( const COMPONENT* c);
296 // ADP_NODE_RCD( const ADP_NODE_RCD& );
297 // ADP_NODE_RCD( const ADP_NODE& );
299 double get_udc() const { assert(false); return udc;}
300 void set_udc(double x) { assert(false); udc=x;}
302 // virtual ADP_NODE(){ return ADP_NODE_RCD(*this); };
303 void tr_expect_1();
304 void tr_expect_2();
305 void tr_expect_3();
306 virtual std::string type() const {return "rcd";};
307 virtual TIME_PAIR tt_review( );
308 private:
309 double udc;
311 /*--------------------------------------------------------------------------*/
312 class ADP_CARD : public COMPONENT { // FIXME: is this a COMPONENT??
313 // manages stress data and stores device parameters.
314 private:
315 static int _tt_order;
316 double _wdT;
317 protected:
318 ADP_CARD(const ADP_CARD&);
319 public:
320 virtual ADP_CARD* clone() const=0;
321 virtual std::string port_name(uint_t)const { return "?"; }
322 explicit ADP_CARD( COMPONENT* c): _c(c) {
323 set_owner(c);
325 explicit ADP_CARD( COMPONENT* c, const std::string n): _c(c) {
326 set_label(n);
327 set_owner(c);
329 // explicit ADP_CARD();
330 virtual ~ADP_CARD() {}
331 const COMPONENT* _c; // subckt??
332 protected:
333 void init(const COMPONENT*, const std::string) {}
335 public:
336 virtual void tt_begin(){ };
337 bool do_tr(){ return true; };
339 virtual double tr_probe_num(const std::string& )const { unreachable(); return 888; }
340 virtual double tt_probe_num(const std::string& )const { unreachable(); return 888; }
341 virtual std::string value_name() const{ return "unknown";}
344 virtual void tt_prepare(){unreachable();}
345 virtual void tt_commit_first(){ }
346 virtual void tt_commit(){ }
347 virtual void tt_last(){ }
348 virtual void tt_accept_first(){ }
349 virtual void tr_commit_first(){ }
350 virtual void tr_accept()=0;
351 virtual void tt_accept(){ }
352 virtual void do_tt() {unreachable();}
353 virtual void apply(const COMPONENT*) {unreachable();}
354 // virtual double wdT() const {return 999;}
355 virtual TIME_PAIR tt_review(){ return TIME_PAIR(); }
356 virtual TIME_PAIR tt_preview( ){ unreachable(); return TIME_PAIR(); }
358 /*--------------------------------------------------------------------------*/
359 #endif