interactive testing
[gnucap-felix.git] / src / e_storag.h
blob164f55394b3b49dee15bca582978bf1b334aaffd
1 /*$Id: e_storag.h,v 1.3 2010-07-16 08:22:01 felix 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)
10 * any later version.
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
20 * 02110-1301, USA.
21 *------------------------------------------------------------------
22 * "base" class for energy storage elements (L & C)
24 //testing=script,complete 2007.07.13
25 #ifndef E_STORAGE_H
26 #define E_STORAGE_H
27 #include "e_elemnt.h"
28 /*--------------------------------------------------------------------------*/
29 //enum METHOD {mTRAPGEAR, mEULER, mTRAP, mGEAR, mTRAPEULER};
30 /*--------------------------------------------------------------------------*/
31 INTERFACE FPOLY1 differentiate(const FPOLY1* q, const FPOLY1* i, double* time,
32 METHOD method);
33 /*--------------------------------------------------------------------------*/
34 class INTERFACE STORAGE : public ELEMENT {
35 private:
36 protected:
37 explicit STORAGE()
38 :ELEMENT(), _method_u(meUNKNOWN), _method_a(mTRAPGEAR) {}
39 explicit STORAGE(const STORAGE& p)
40 :ELEMENT(p), _method_u(p._method_u), _method_a(p._method_a) {}
41 ~STORAGE() {}
42 public: // override virtual
43 //void precalc_first(); //ELEMENT
44 //void expand(); //COMPONENT
45 void precalc_last();
46 void tr_begin();
47 void tr_restore();
48 void tr_adapt();
49 virtual void tr_init(double) { unreachable(); }
50 void dc_advance();
51 void tr_advance();
52 void tr_regress();
53 bool tr_needs_eval()const;
54 //void tr_queue_eval() //ELEMENT
55 TIME_PAIR tr_review();
56 double tr_probe_num(const std::string&)const;
57 public:
58 double tr_c_to_g(double c, double g)const;
59 private:
60 int order()const {
61 const int o[] = {0, 1, 1, 2, 1, 1};
62 int ord = o[_method_a+1];
63 assert(ord < OPT::_keep_time_steps);
64 return min(ord,ELEMENT::order());
66 double error_factor()const {
67 const double f[]={1./2., 1./2., 1./12., 1./6., 1./2.};
68 return f[_method_a];
70 bool uic_now()const {return _sim->uic_now() && has_ic();}
71 public: // used by commons
72 method_t _method_u; /* method to use for this part per user */
73 METHOD _method_a; /* actual integration method (auto) */
74 protected:
75 FPOLY1 _i[OPT::_keep_time_steps]; /* deriv of _q */
76 protected:
77 static METHOD method_select[meNUM_METHODS][meNUM_METHODS];
78 void set_ic(double); // protected?? bug??
79 public:
80 double* set__ic();
81 bool has_memory(){return true;}
82 void keep_ic();
86 /*--------------------------------------------------------------------------*/
88 // storage should do. I might use this to be sure
89 class INTERFACE STORAGE_HEADLESS : public STORAGE {
90 public:
91 explicit STORAGE_HEADLESS()
92 :STORAGE() {}
93 explicit STORAGE_HEADLESS(const STORAGE_HEADLESS& p)
94 :STORAGE(p){}
95 ~STORAGE_HEADLESS() {}
99 /*--------------------------------------------------------------------------*/
100 /*--------------------------------------------------------------------------*/
101 #endif
102 // vim:ts=8:sw=2:noet: